// scan for files and folders $index = scan($folder); $comics = only_comic_files($index); usort($comics, function ($a, $b) { return strcmp("{$a->in_uri}/{$a->date}", "{$b->in_uri}/{$b->date}") < 0; }); $rss = array_slice($comics, 0, $rss_max); $random = $comics; shuffle($random); // write DB tables write_table($db, '', 'newest', current($comics)); write_atom($rss); write_table($db, '', 'comics', $comics); write_table($db, '', 'random', $random); write_table($db, 'nav', 'all', $index); write_table($db, 'nav', 'folders', only_folders($index)); write_table($db, 'nav', 'comics', only_comics($index)); /* missing indexes: by-uri */ /* flatten into comics-only listing */ function only_comic_files($index, $admin = false) { $files = array(); foreach ((array) $index as $k => $v) { if ($v->is_hidden) { continue; } if ($v->is_folder) { $files = array_merge($files, only_comic_files($v->files, $admin));
function tree($folder = null, $user = false, $folders_only = false, $recursive = false, $tree = null) { global $current_tree, $ids; if (!empty($current_tree) && !$folders_only && !$recursive) { return $current_tree; } $dir = array(); if (!$user) { $user = $_SESSION['login']; } if (!$tree) { $tree = regen_tree($user); } if (!empty($current_tree) && $folders_only) { $tree = only_folders($current_tree); } elseif ($folders_only) { $tree = only_folders($tree); } if (empty($folder)) { $folder = $_SESSION['upload_root_path'] . $_SESSION['upload_user_path'] . $_SESSION['current_path']; } if (!empty($tree)) { foreach ($tree as $id => $path) { if ($recursive) { $p = addslash_if_needed($path); $f = addslash_if_needed($folder); $match = strpos($p, $f) === 0; } else { $match = addslash_if_needed(dirname($path)) === addslash_if_needed($folder); } if (!empty($_SESSION['filter'])) { $match = $match && strpos(_basename($path), $_SESSION['filter']) !== false; } if ($match === true) { $dir[$id] = $path; } } } else { $dir = array(); } unset($_SESSION['filter']); return $dir; }