示例#1
0
function get_tree($path = '.', $clean_path = '', $title = '', $first = true, $language = null)
{
    $options = get_options();
    $tree = array();
    $ignore = get_ignored();
    $dh = @opendir($path);
    $index = 0;
    // Build array of paths
    $paths = array();
    while (false !== ($file = readdir($dh))) {
        $paths[$file] = $file;
    }
    // Close the directory handle
    closedir($dh);
    // Sort paths
    sort($paths);
    if ($first && $language !== null) {
        $language_path = $language . "/";
    } else {
        $language_path = "";
    }
    // Loop through the paths
    // while(false !== ($file = readdir($dh))){
    foreach ($paths as $file) {
        // Check that this file or folder is not to be ignored
        if (!in_array($file, $ignore) && $file[0] !== '.') {
            $full_path = "{$path}/{$file}";
            $clean_sort = clean_sort($file);
            // If clean_urls is set to false and this is the first branch of the tree, append index.php to the clean_path.
            if ($options['clean_urls'] == false) {
                if ($first) {
                    $url = $clean_path . '/' . $language_path . 'index.php/' . $clean_sort;
                } else {
                    $url = $clean_path . '/' . $language_path . $clean_sort;
                }
            } else {
                $url = $clean_path . '/' . $language_path . $clean_sort;
            }
            $clean_name = clean_name($clean_sort);
            // Title
            if (empty($title)) {
                $full_title = $clean_name;
            } else {
                $full_title = $title . ': ' . $clean_name;
            }
            if (is_dir("{$path}/{$file}")) {
                // Directory
                $tree[$clean_sort] = array('type' => 'folder', 'name' => $clean_name, 'title' => $full_title, 'path' => $full_path, 'clean' => $clean_sort, 'url' => $url, 'tree' => get_tree($full_path, $url, $full_title, false, $language));
            } else {
                // File
                $tree[$clean_sort] = array('type' => 'file', 'name' => $clean_name, 'title' => $full_title, 'path' => $full_path, 'clean' => $clean_sort, 'url' => $url);
            }
        }
        $index++;
    }
    return $tree;
}
示例#2
0
function get_tree($path = '.', $clean_path = '', $title = '')
{
    $tree = array();
    $ignore = array('config.json', 'cgi-bin', '.', '..');
    $dh = @opendir($path);
    $index = 0;
    // Build array of paths
    $paths = array();
    while (false !== ($file = readdir($dh))) {
        $paths[$file] = $file;
    }
    // Close the directory handle
    closedir($dh);
    // Sort paths
    sort($paths);
    // Loop through the paths
    // while(false !== ($file = readdir($dh))){
    foreach ($paths as $file) {
        // Check that this file is not to be ignored
        if (!in_array($file, $ignore)) {
            $full_path = "{$path}/{$file}";
            $clean_sort = clean_sort($file);
            $url = $clean_path . '/' . $clean_sort;
            $clean_name = clean_name($clean_sort);
            // Title
            if (empty($title)) {
                $full_title = $clean_name;
            } else {
                $full_title = $title . ': ' . $clean_name;
            }
            if (is_dir("{$path}/{$file}")) {
                // Directory
                $tree[$clean_sort] = array('type' => 'folder', 'name' => $clean_name, 'title' => $full_title, 'path' => $full_path, 'clean' => $clean_sort, 'url' => $url, 'tree' => get_tree($full_path, $url, $full_title));
            } else {
                // File
                $tree[$clean_sort] = array('type' => 'file', 'name' => $clean_name, 'title' => $full_title, 'path' => $full_path, 'clean' => $clean_sort, 'url' => $url);
            }
        }
        $index++;
    }
    return $tree;
}