From 719c5a62d21759386eea2fb0db473af0b0766fb8 Mon Sep 17 00:00:00 2001 From: speedie Date: Sat, 16 Sep 2023 16:15:48 +0200 Subject: [PATCH] Add lister --- .htaccess | 2 + packages/index.php | 7 +- packages/lister.php | 233 +++++++++++++++++++++++++++++++++++++ packages/lister/lister.css | 144 +++++++++++++++++++++++ 4 files changed, 381 insertions(+), 5 deletions(-) create mode 100644 packages/lister.php create mode 100644 packages/lister/lister.css diff --git a/.htaccess b/.htaccess index f4ac509..44bc113 100644 --- a/.htaccess +++ b/.htaccess @@ -1,3 +1,5 @@ RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?) RewriteRule ^ /%1 [R=301,L] +RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)lister\.php($|\ |\?) +RewriteRule ^ /%1 [R=301,L] diff --git a/packages/index.php b/packages/index.php index 3a90d99..da6deee 100644 --- a/packages/index.php +++ b/packages/index.php @@ -148,11 +148,8 @@ function main() { print "\t\t\t\t

Then simply pacman -Syu to sync the repositories. Then you can install any of my packages in the same way you install official packages.

\n"; print "\t\t

How do I use this site?

\n"; print "\t\t\t

You can search for packages using the input box in the navbar. Then you can select a package to view details about it. You can press 'Home' in the navbar to go back to this page, or 'All' to display all available packages.

\n"; - print "\t\t

FAQ

\n"; - print "\t\t\t\n"; + print "\t\t

Directory listing

\n"; + print "\t\t\t

See this page for more information.

\n"; } else if ($request == "view" && $query != '') { $packageCount = 0; $packageVersions = array(); diff --git a/packages/lister.php b/packages/lister.php new file mode 100644 index 0000000..f830e54 --- /dev/null +++ b/packages/lister.php @@ -0,0 +1,233 @@ + $file, 'isdir' => $isdir, 'size' => $isdir ? 0 : filesize($path . $file), 'time' => filemtime($path . $file)); + if ($isdir) $ls_d[] = $item; else $ls[] = $item; + $_total++; + $_total_size += $item['size']; + } + return array_merge($ls_d, $ls); + } + + // Get the list of files + $items = ls('.' . (empty($_browse) ? '' : '/' . $_browse), $showDirectories, $showHiddenFiles); + + // Sort it + function sortByName($a, $b) { global $showDirectoriesFirst; return ($a['isdir'] == $b['isdir'] || !$showDirectoriesFirst ? strtolower($a['name']) > strtolower($b['name']) : $a['isdir'] < $b['isdir']) ? 1 : -1; } + function sortBySize($a, $b) { return ($a['isdir'] == $b['isdir'] ? $a['size'] > $b['size'] : $a['isdir'] < $b['isdir']) ? 1 : -1; } + function sortByTime($a, $b) { return ($a['time'] > $b['time']) ? 1 : -1; } + switch (@$_GET['s']) { + case 'size': $_sort = 'size'; usort($items, 'sortBySize'); break; + case 'time': $_sort = 'time'; usort($items, 'sortByTime'); break; + default : $_sort = 'name'; usort($items, 'sortByName'); break; + } + + // Reverse? + $_sort_reverse = (@$_GET['r'] == '1'); + if ($_sort_reverse) $items = array_reverse($items); + + // Add parent + if ($showParent && $_path != '/' && empty($_browse)) array_unshift($items, array( + 'name' => '..', + 'isparent' => true, + 'isdir' => true, + 'size' => 0, + 'time' => 0 + )); + + // Add parent in case of browsing a sub-folder + if (!empty($_browse)) array_unshift($items, array( + 'name' => '..', + 'isparent' => false, + 'isdir' => true, + 'size' => 0, + 'time' => 0 + )); + + // 37.6 MB is better than 39487001 + function humanizeFilesize($val, $round = 0) { + $unit = array('','K','M','G','T','P','E','Z','Y'); + do { $val /= 1024; array_shift($unit); } while ($val >= 1000); + return sprintf('%.'.intval($round).'f', $val) . ' ' . array_shift($unit) . 'B'; + } + + // Titles parser + function getTitleHTML($title, $breadcrumbs = false) { + global $_path, $_browse, $_total, $_total_size, $sizeDecimals; + $title = htmlentities(str_replace(array('{{files}}', '{{size}}'), array($_total, humanizeFilesize($_total_size, $sizeDecimals)), $title)); + $path = htmlentities($_path); + if ($breadcrumbs) $path = sprintf('%s', htmlentities(buildLink(array('b' => ''))), $path); + if (!empty($_browse)) { + if ($_path != '/') $path .= '/'; + $browseArray = explode('/', trim($_browse, '/')); + foreach ($browseArray as $i => $part) { + if ($breadcrumbs) { + $path .= sprintf('%s', htmlentities(buildLink(array('b' => implode('/', array_slice($browseArray, 0, $i + 1))))), htmlentities($part)); + } else { + $path .= htmlentities($part); + } + if (count($browseArray) > ($i + 1)) $path .= '/'; + } + } + return str_replace('{{path}}', $path, $title); + } + + // Link builder + function buildLink($changes) { + global $_self; + $params = $_GET; + foreach ($changes as $k => $v) if (is_null($v)) unset($params[$k]); else $params[$k] = $v; + foreach ($params as $k => $v) $params[$k] = urlencode($k) . '=' . urlencode($v); + return empty($params) ? $_self : $_self . '?' . implode('&', $params); + } + +?> + + + + + + + + <?php echo getTitleHTML($title) ?> + + + +> + +
+ +

+

+ + + + + + + + + + +
+ + + diff --git a/packages/lister/lister.css b/packages/lister/lister.css new file mode 100644 index 0000000..aa66a55 --- /dev/null +++ b/packages/lister/lister.css @@ -0,0 +1,144 @@ +* { + margin: 0; + padding: 0; + border: none; +} + +body { + text-align: center; + font-family: monospace; + font-size: 16px; + color: #ffffff; + background-color: #212121; +} + +body#left { + text-align: left; +} + +h1 { + font-size: 20px; + padding: 0 10px; + text-align: center; + margin: 5px 5 5; + background-color: #363636; + position: sticky; + top: 0; + font-weight: bold; +} + +h2 { + font-size: 16px; + padding: 0 10px; + margin: 10px 0 0; + color: #ccccff; + font-weight: normal; +} + +a { + color: #89bfff; + text-decoration: none; +} + +a:hover { + color: #89bfff; + text-decoration: underline; +} + +ul li { + display: block; + list-style-type: none; + overflow: hidden; + padding: 10px; +} + +ul li:hover { + background-color: #222222; +} + +ul li .date, ul li .size { + font-size: 16px; + display: block; + color: #ccccff; +} + +ul#header li { + font-size: 16px; + font-weight: bold; + border-bottom: 1px solid #cccccc; +} + +ul#header li:hover { + background-color: transparent; +} + +ul#header li * { + color: #777777; + font-size: 16px; +} + +ul#header li a:hover { + color: #ffffff; +} + +ul#header li .asc span, ul#header li .desc span { + padding-right: 15px; + background-position: right center; + background-repeat: no-repeat; + color: #ffffff; +} + +ul#header li .asc span { + background-image: url('?i=asc'); +} + +ul#header li .desc span { + background-image: url('?i=desc'); +} + +ul li.item { + border-top: 1px solid #f3f3f3; +} + +ul li.item:first-child { + border-top: none; +} + +ul li.item .name { + font-weight: bold; +} + +ul li.item .directory, ul li.item .file { + padding-left: 20px; + background-position: left center; + background-repeat: no-repeat; +} + +ul li.item .directory { + background-image: url('?i=directory'); +} + +ul li.item .file { + background-image: url('?i=file'); +} + +#footer { + color: #cccccc; + font-size: 20px; + margin-top: 40px; + margin-bottom: 20px; + padding: 0 30px; + text-align: center; +} + +#links { + color: #89bfff; + font-weight: bold; + text-decoration: none; + transition: 0.1s; + text-align: center; +} + +#footer a:hover { + color: #ccccff; +}