diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-11-05 05:16:26 +0000 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-11-05 05:16:26 +0000 |
commit | b1c691519fe3e094ddddde14372f7d1756b4d6fa (patch) | |
tree | 7de341d892d565da9be0b80ed46726ef595c7b06 | |
parent | 59eaebe0bae3d04d283be95de3837c243962461f (diff) |
clean up directory classification
-rw-r--r-- | index.php | 51 | ||||
-rw-r--r-- | style.css | 7 |
2 files changed, 37 insertions, 21 deletions
@@ -5,12 +5,14 @@ # as published by Sam Hocevar. See the ./COPYING file for more details. // Configuration -$repos_arch_project = [ 'core', 'extra', 'staging', 'testing', 'gnome-unstable', 'kde-unstable' ]; -$repos_arch_community = [ 'community', 'community-staging', 'community-testing', - 'multilib', 'multilib-staging', 'multilib-testing' ]; -$repos_para_project = [ 'libre', 'libre-testing', - 'libre-multilib', 'libre-multilib-testing' ]; -$repos_para_community = [ 'cross', 'java', 'kernels', 'nonprism', 'pcr' ]; +$repos = [ + 'packages' => [ 'core', 'extra', 'staging', 'testing', 'gnome-unstable', 'kde-unstable' ], + 'community' => [ 'community', 'multilib' ], + 'parabola' => [ 'libre', + 'libre-multilib', + 'cross', 'java', 'kernels', 'nonprism', 'pcr' ], + 'testing' => ['gnome-unstable', 'kde-unstable'] +]; // Automatic configuration $asseturl = dirname($_SERVER["SCRIPT_NAME"]); @@ -36,13 +38,21 @@ function is_root($root, $dirname) { return (normalize($path) === normalize($root)); } +function has_suffix($str, $suffix) { + return substr($str, -strlen($suffix)) === $suffix; +} + +function trim_suffix($str, $suffix) { + return has_suffix($str, $suffix) ? substr($str, 0, -strlen($suffix)) : $str; +} + function s_is_type($mode, $mask) { return ($mode & 0170000/*<sys/stat.h>:S_IFMT*/) === $mask; } // <sys/stat.h>:__S_ISTYPE function stat_is_dir( $stat) { return s_is_type($stat['mode'], 0040000/*<sys/stat.h>:S_IFDIR*/); } function stat_is_file($stat) { return s_is_type($stat['mode'], 0100000/*<sys/stat.h>:S_IFREG*/); } function stat_is_link($stat) { return s_is_type($stat['mode'], 0120000/*<sys/stat.h>:S_IFLNK*/); } function classify($root, $dirname, $filename) { - global $repos_arch_project, $repos_arch_community, $repos_para_project, $repos_para_community; + global $repos; list ($dirname, $parts) = normalizeN($dirname); $filepath = $root.'/'.$dirname.'/'.$filename; @@ -63,18 +73,23 @@ function classify($root, $dirname, $filename) { // in the top-level if (stat_is_dir($stat) && is_dir($filepath.'/os')) { array_push($classes, 'repo'); - if (in_array($filename, $repos_arch_project )) { array_push($classes, 'arch'); } - if (in_array($filename, $repos_para_project )) { array_push($classes, 'para'); } - if (in_array($filename, $repos_arch_community)) { array_push($classes, 'arch', 'community'); } - if (in_array($filename, $repos_para_community)) { array_push($classes, 'para', 'community'); } - if ($filename[0] === '~' ) { array_push($classes, 'para', 'community'); } - } - } elseif ($dirname == "pool" || $dirname == "sources") { - switch($filename) { - case "packages": array_push($classes, 'pool', 'arch' ); break; - case "community": array_push($classes, 'pool', 'arch', 'community'); break; - case "parabola": array_push($classes, 'pool', 'para' ); break; + foreach (array_keys($repos) as $category) { + if (in_array($filename, $repos[$category])) { + array_push($classes, $category); + } + if (in_array(trim_suffix($filename, "-staging"), $repos[$category])) { + array_push($classes, $category); + } + if (in_array(trim_suffix($filename, "-testing"), $repos[$category])) { + array_push($classes, $category); + } + } + if (has_suffix($filename, "staging")) { array_push($classes, 'staging'); } + if (has_suffix($filename, "testing")) { array_push($classes, 'testing'); } + if ($filename[0] === '~') { array_push($classes, 'parabola'); } } + } elseif ($dirname == "/pool" || $dirname == "/sources") { + array_push($classes, 'pool', $filename); } if ($filename[0] === '.' || substr($filename, -1) === '~') { $classes[] = 'hidden'; } if (stat_is_dir( $stat)) { $classes[] = 'dir'; } @@ -42,9 +42,10 @@ tr.link td:first-of-type { background-image: url("link.png"); } tr.file td:first-of-type { background-image: url("file.png"); } /* domain-specific information -------------------------------------- */ tr.dir.repo td:first-of-type { background-image: url("repo.png"); } -tr.arch td { background-color:#7fc3e5; } -tr.para td { background-color:#9fa6e3; } -tr.community { /* TODO: we should indicate this somehow */ } +tr.packages td { background-color:#7fc3e5; } +tr.community td { background-color:#7fc3e5; } /* TODO: differentiate this from 'packages' somehow */ +tr.parabola td { background-color:#9fa6e3; } +tr.alarm td { background-color:#a5d7eb; } /* file extension information --------------------------------------- */ tr.file.pkg.tar td:first-of-type { background-image: url("pkg.png"); } tr.file.iso td:first-of-type { background-image: url("iso.png"); } |