From: Michael Wallner Date: Thu, 24 Sep 2015 15:24:31 +0000 (+0200) Subject: modularize X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;ds=inline;p=m6w6%2Freplicator modularize --- diff --git a/public/html.php b/public/html.php new file mode 100644 index 0000000..21c20fe --- /dev/null +++ b/public/html.php @@ -0,0 +1,153 @@ + + + + + + Replicator + + + + + + +
+
+

+ Replicator
+ Replicating PECL releases as pharext packages since 2015 +

+ Fork me on GitHub +
+
+
+ + + +

+ + + + + + + + + + + $phars) : ?> + + + + + list($phar, $date, $size, $pharext)) : ?> + + + + + + + + + + + + + +
PackageDatePharext
+ + + + ext.phar
+ +
+ + + "> + v +
+ + +

Available Packages

+ + + +
+ + + +send(); +?> \ No newline at end of file diff --git a/public/index.php b/public/index.php index 639f1e2..08e8513 100644 --- a/public/index.php +++ b/public/index.php @@ -1,210 +1,76 @@ - - - - - Replicator - - - - - - -
-
-

- Replicator
- Replicating PECL releases as pharext packages since 2015 -

- Fork me on GitHub -
-
-
- - - +use http\Env\Request; +use http\Env\Response; +use http\Header; -

- - - - - - - - - - - getMetadata(); - if ($meta) { - $release = $meta["release"]; - } else { - $release = substr($name, strlen($package)+1); - } - $versions[$release][$enc] = [$phar, $meta]; - uksort($versions[$release], function($a, $b) { - $al = strlen($a); - $bl = strlen($b); - if ($al < $bl) return -1; - if ($al > $bl) return 1; - return 0; - }); - } - uksort($versions, "version_compare"); - - ?> - $phars) : ?> +const UNITS = ["Bytes", "KB", "MB"]; - - - - list($phar, $meta)) : ?> - - - - - - - - - - - +$packages = array_map("basename", glob("phars/*", GLOB_NOSORT|GLOB_ONLYDIR)); +sort($packages, SORT_NATURAL|SORT_FLAG_CASE); - -
PackageDatePharext
- - - - ext.phar
- $d->modify("-$i days")->format("U")) { + switch ($i) { + case 1: + return "today"; + case 2: + return "yesterday"; + default: + return "$i days ago"; + } + } + } + return gmdate("Y-m-d", $t); +} - ?> -
- getMetadata(); + if ($meta) { + $release = $meta["release"]; + } else { + $release = substr($name, strlen($package)+1); + } - $time = time(); - $dsec = 86400; - $lmod = isset($meta["date"]) ? strtotime($meta["date"]) : filemtime($phar); - $days = [1 => "today", "yesterday"]; - do { - for ($i = 1; $i < 7; ++$i) { - if ($lmod > $time - $dsec * $i) { - switch ($i) { - case 1: - echo "today"; - break 3; - case 2: - echo "yesterday"; - break 3; - default: - echo "$i days ago"; - break 3; - } - } - } - echo date("Y-m-d", $lmod); - } while (false); - - ?> + $size = filesize($phar); + $date = isset($meta["date"]) ? strtotime($meta["date"]) : filemtime($phar); + $pharext = isset($meta["version"]) ? $meta["version"] : "2.0.1"; + $versions[$release][$enc] = compact("phar", "date", "size", "pharext"); + uksort($versions[$release], function($a, $b) { + $al = strlen($a); + $bl = strlen($b); + if ($al < $bl) return -1; + if ($al > $bl) return 1; + return 0; + }); + } + uksort($versions, "version_compare"); + return $versions; +} - - -
- +if (in_array($_SERVER["QUERY_STRING"], $packages, true)) { + $package = $_SERVER["QUERY_STRING"]; +} -

Available Packages

- - - -
- - - +if (!defined("INCLUDED")) { + if (($acc = $req->getHeader("Accept", Header::class))) { + $neg = basename($acc->negotiate(["text/html", "application/json"])); + } else { + $neg = "html"; + } + include_once "$neg.php"; +} \ No newline at end of file diff --git a/public/json.php b/public/json.php new file mode 100644 index 0000000..84f9c96 --- /dev/null +++ b/public/json.php @@ -0,0 +1,10 @@ +setContentType("application/json"); +$res->getBody()->append( + json_encode(empty($package) ? $packages : package_versions($package)) +); +$res->send();