# HG changeset patch # User nanaya # Date 1491311843 -32400 # Node ID d0b3c58c27819218fbdb5961d87853fe415f9f99 # Parent 5d49d4039727e4b9e2d012bb234c1486e4ebbb5b Style cleanup diff -r 5d49d4039727 -r d0b3c58c2781 index.php --- a/index.php Mon Aug 24 21:44:50 2015 +0900 +++ b/index.php Tue Apr 04 22:17:23 2017 +0900 @@ -1,264 +1,295 @@ ' . h($title) . ""); } - - function human_size($size) { - $thousand_units = array("ko", "Mo", "Go", "To", "Po"); - - $return_format = "%d %s"; + if (http_response_code() !== 200) { + exit; + } - if ($size === 1) { - $return_unit = "octet"; - } elseif ($size < 1000) { - $return_unit = "octets"; - } else { - $size /= 1000; - for ($i = 0; $size >= 1000 && $i < count($thousand_units); $i++) { $size /= 1000; } - $return_format = "%.2f %s"; - $return_unit = $thousand_units[$i]; + $dir_handle = opendir($dir); + $files = array(); + $dirs = array(); + while (($file = readdir($dir_handle)) !== false) { + if ($file === "." || $file === "..") { + continue; + } elseif (!(isset($_SERVER["DL_SHOWALL"]) && $_SERVER["DL_SHOWALL"] === "1") && substr($file, 0, 1) === ".") { + continue; + } elseif (is_dir($dir . $file)) { + $dirs[] = $file; + } else { + $files[] = $file; + } } - return sprintf($return_format, $size, $return_unit); - } + sort($files); + sort($dirs); - function hidden_data($data = "", $is_dir = false) { - return " " . ($is_dir === true ? 0 : 1) . " " . $data . " "; - } - // END UTILITY - - function tree_link($uri) { - $uri_array = explode("/", trim($uri, "/")); - - $tree_path = "/"; - $tree_link = link_to($tree_path, "[root]"); - $tree_link .= "/"; - - foreach ($uri_array as $p) { - if ($p === "") { continue; } - $tree_path .= $p . "/"; - $tree_link .= link_to($tree_path, $p) . "/"; + // BEGIN UTILITY + function h($string) + { + return htmlspecialchars($string, ENT_QUOTES, "UTF-8"); + } + function a($string) + { + return preg_replace("#(%2F)+#", "/", rawurlencode($string)); + } + function link_to($target, $title) + { + return('' . h($title) . ""); } - return $tree_link; - } + function human_size($size) + { + $thousand_units = array("ko", "Mo", "Go", "To", "Po"); + + $return_format = "%d %s"; - function up_link($uri) { - if ($uri !== "/") { - return "" . link_to(dirname($uri) . "/", "[up]") . ""; + if ($size === 1) { + $return_unit = "octet"; + } elseif ($size < 1000) { + $return_unit = "octets"; + } else { + $size /= 1000; + for ($i = 0; $size >= 1000 && $i < count($thousand_units); $i++) { + $size /= 1000; + } + $return_format = "%.2f %s"; + $return_unit = $thousand_units[$i]; + } + return sprintf($return_format, $size, $return_unit); } - } - function file_rows($dir, $files, $is_dir) { - $file_suffix = ""; - if ($is_dir) { $file_suffix = "/"; } + function hidden_data($data = "", $is_dir = false) + { + return " " . ($is_dir === true ? 0 : 1) . " " . $data . " "; + } + // END UTILITY + + function tree_link($uri) + { + $uri_array = explode("/", trim($uri, "/")); - $file_rows = ""; - foreach($files as $file) { - $file_path = $dir."/".$file; + $tree_path = "/"; + $tree_link = link_to($tree_path, "[root]"); + $tree_link .= "/"; - if (!file_exists($file_path)) { continue; } - $file_stat = stat($file_path); + foreach ($uri_array as $p) { + if ($p === "") { + continue; + } + $tree_path .= $p . "/"; + $tree_link .= link_to($tree_path, $p) . "/"; + } - $file_rows .= - "". - "". - hidden_data("", $is_dir). - link_to($file.$file_suffix, $file.$file_suffix). - "". - "". - hidden_data($file_stat["size"], $is_dir). - ($is_dir ? "[dir]" : human_size($file_stat["size"])). - "". - "". - hidden_data("", $is_dir).$columns["date"]. - h(strftime("%Y-%m-%d %H:%M %Z", $file_stat["mtime"])). - "". - ""; + return $tree_link; + } + + function up_link($uri) + { + if ($uri !== "/") { + return "" . link_to(dirname($uri) . "/", "[up]") . ""; + } } - return $file_rows; - } + + function file_rows($dir, $files, $is_dir) + { + $file_suffix = ""; + if ($is_dir) { + $file_suffix = "/"; + } + + $file_rows = ""; + foreach ($files as $file) { + $file_path = $dir."/".$file; + + if (!file_exists($file_path)) { + continue; + } + $file_stat = stat($file_path); + + $file_rows .= + "". + "". + hidden_data("", $is_dir). + link_to($file.$file_suffix, $file.$file_suffix). + "". + "". + hidden_data($file_stat["size"], $is_dir). + ($is_dir ? "[dir]" : human_size($file_stat["size"])). + "". + "". + hidden_data("", $is_dir).$columns["date"]. + h(strftime("%Y-%m-%d %H:%M %Z", $file_stat["mtime"])). + "". + ""; + } + return $file_rows; + } + + header('Content-Type: text/html; charset=utf-8'); ?> - - - Index of <?php echo h($uri); ?> - - - + @media (max-width: 767px) { + table { + border-spacing: 0 10px; + } + th { display: none; } + tr { + background: #eee; + } + td { + display: inline-block; + } + td:first-child { + background: #ddd; + padding: 5px; + } + table a { + font-size: 18px; + display: block; + } + input { font-size: 18px; } + } + -

Index of

+

Index of

- + - - - - - - - - - - - - - -
FileSizeDate
+ + + + + + + + + + + + + +
FileSizeDate
- + - - - + + + - + $("tbody td:nth-child(3n + 1)").addClass("filename") + $("tbody td:nth-child(3n + 2)").addClass("size") + $("tbody td:nth-child(3n + 3)").addClass("date") + + new List("files", { + valueNames: ["filename", "size", "date"], + page: + }) +