当前位置: 首页>>代码示例>>PHP>>正文


PHP textlib::asort方法代码示例

本文整理汇总了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;
}
开发者ID:nicusX,项目名称:moodle,代码行数:92,代码来源:locallib.php


注:本文中的textlib::asort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。