Files
elwig-www/www/files/index.php

97 lines
3.1 KiB
PHP

<?php
require "../format.inc";
$TITLE = 'Downloads';
global $getProd;
global $getVers;
$getProd = null;
$getVers = null;
$info = explode('/', $_SERVER['PATH_INFO']);
if ($info[1] === 'elwig' || $info[1] === 'winziprint') {
$getProd = $info[1];
$getVers = $info[2];
if (sizeof($info) > 3) {
header('Status: 404');
header('Content-Length: 0');
exit();
}
} else if ($_SERVER['PATH_INFO'] !== '') {
header('Status: 404');
header('Content-Length: 0');
exit();
}
$files = [];
foreach (scandir('.') as $file) {
if (str_starts_with($file, ".") || str_ends_with($file, ".php")) continue;
$files[$file] = [filesize($file), filemtime($file), filectime($file)];
}
$entities = [];
foreach ($files as $name => [$size, $mtime, $ctime]) {
$p1 = strrpos($name, '-') + 1;
$p2 = strrpos($name, '.');
$vers = substr($name, $p1, $p2 - $p1);
$url = "https://www.necronda.net/elwig/files/$name";
$mod = date(DATE_ATOM, $mtime);
$cre = date(DATE_ATOM, $ctime);
$prod = strtolower(substr($name, 0, $p1 - 1));
$entities[$name] = [
$prod,
$vers,
$url,
$size,
$mtime,
$ctime,
$mod,
$cre
];
}
$versions = [];
if ($getVers === 'latest') {
foreach ($entities as $name => [$prod, $vers, $url, $size, $mtime, $ctime, $mod, $cre]) {
$versions[$prod] = $vers;
}
}
$entities = array_filter($entities, function($e) {
global $getProd;
global $getVers;
return (empty($getProd) || $getProd === $e[0]) && (empty($getVers) || $getVers === $e[1]);
});
$format = get_fmt();
if ($format === 'json') {
header('Content-Type: application/json; charset=UTF-8');
echo "{\"status\": \"success\", \"data\": [\n";
$first = true;
foreach ($entities as $name => [$prod, $vers, $url, $size, $mtime, $ctime, $mod, $cre]) {
if (!$first) echo ",\n";
echo " {\"product\": \"$prod\", \"version\": \"$vers\", \"name\": \"$name\", \"url\": \"$url\", \"size\": $size, \"created\": \"$cre\", \"modified\": \"$mod\"}";
$first = false;
}
echo "\n]}\n";
} else if ($format === 'text') {
header('Content-Type: text/plain; charset=UTF-8');
foreach ($entities as $name => [$prod, $vers, $url, $size, $mtime, $ctime, $mod, $cre]) {
echo "$name\t" . number_format($size / 1024 / 1024, 1) . " MB\n";
}
} else if ($format === 'html') {
if (isset($getProd) && isset($getVers) && sizeof($entities) === 1) {
header('Status: 303');
header('Location: ' . $entities[array_key_first($entities)][2]);
exit();
}
header('Content-Type: text/html; charset=UTF-8');
require "../header.inc"; ?>
<h1>Downloads</h1>
<table>
<thead><tr><th>Name</th><th>Größe</th></tr></thead>
<tbody>
<?php foreach ($entities as $name => [$prod, $vers, $url, $size, $mtime, $ctime, $mod, $cre]) {
echo " <tr><td><a href='files/$name'>$name</a></td><td>" . number_format($size / 1024 / 1024, 1) . " MB</td></tr>\n";
} ?>
</tbody>
</table>
<p><a href="files?format=json">JSON-Format</a></p>
<?php require "../footer.inc"; }