本文整理匯總了PHP中textlib::asort方法的典型用法代碼示例。如果您正苦於以下問題:PHP textlib::asort方法的具體用法?PHP textlib::asort怎麽用?PHP textlib::asort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類textlib
的用法示例。
在下文中一共展示了textlib::asort方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: toolbook_importhtml_get_chapter_files
/**
* Returns all the html files (chapters) from a file package
*
* @param stored_file $package file to be processed
* @param string $type type of the package ('typezipdirs' or 'typezipfiles')
*
* @return array the html files found in the package
*/
function toolbook_importhtml_get_chapter_files($package, $type) {
$packer = get_file_packer('application/zip');
$files = $package->list_files($packer);
$tophtmlfiles = array();
$subhtmlfiles = array();
$topdirs = array();
foreach ($files as $file) {
if (empty($file->pathname)) {
continue;
}
if (substr($file->pathname, -1) === '/') {
if (substr_count($file->pathname, '/') !== 1) {
// skip subdirs
continue;
}
if (!isset($topdirs[$file->pathname])) {
$topdirs[$file->pathname] = array();
}
} else {
$mime = mimeinfo('icon', $file->pathname);
if ($mime !== 'html') {
continue;
}
$level = substr_count($file->pathname, '/');
if ($level === 0) {
$tophtmlfiles[$file->pathname] = $file;
} else if ($level === 1) {
$subhtmlfiles[$file->pathname] = $file;
$dir = preg_replace('|/.*$|', '', $file->pathname);
$topdirs[$dir][$file->pathname] = $file;
} else {
// lower levels are not interesting
continue;
}
}
}
// TODO: natural dir sorting would be nice here...
textlib::asort($tophtmlfiles);
textlib::asort($subhtmlfiles);
textlib::asort($topdirs);
$chapterfiles = array();
if ($type == 2) {
$chapterfiles = $tophtmlfiles;
} else if ($type == 1) {
foreach ($topdirs as $dir => $htmlfiles) {
if (empty($htmlfiles)) {
continue;
}
textlib::asort($htmlfiles);
if (isset($htmlfiles[$dir.'/index.html'])) {
$htmlfile = $htmlfiles[$dir.'/index.html'];
} else if (isset($htmlfiles[$dir.'/index.htm'])) {
$htmlfile = $htmlfiles[$dir.'/index.htm'];
} else if (isset($htmlfiles[$dir.'/Default.htm'])) {
$htmlfile = $htmlfiles[$dir.'/Default.htm'];
} else {
$htmlfile = reset($htmlfiles);
}
$chapterfiles[$htmlfile->pathname] = $htmlfile;
}
} else if ($type == 0) {
if ($tophtmlfiles) {
if (isset($tophtmlfiles['index.html'])) {
$htmlfile = $tophtmlfiles['index.html'];
} else if (isset($tophtmlfiles['index.htm'])) {
$htmlfile = $tophtmlfiles['index.htm'];
} else if (isset($tophtmlfiles['Default.htm'])) {
$htmlfile = $tophtmlfiles['Default.htm'];
} else {
$htmlfile = reset($tophtmlfiles);
}
} else {
$htmlfile = reset($subhtmlfiles);
}
$chapterfiles[$htmlfile->pathname] = $htmlfile;
}
return $chapterfiles;
}