Collapse most files into index.php
This commit is contained in:
@@ -1,4 +1,96 @@
|
||||
<?php require "script.php"; ?>
|
||||
<?php
|
||||
|
||||
require "config.php";
|
||||
|
||||
function timestamp_in_words($timestamp) {
|
||||
if (!is_numeric($timestamp) || $timestamp < 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$seconds = time() - $timestamp;
|
||||
$future = $seconds < 0;
|
||||
$seconds = abs($seconds);
|
||||
|
||||
$minutes = round($seconds / 60);
|
||||
$hours = round($seconds / 3600);
|
||||
$days = round($seconds / 86400);
|
||||
$months = round($seconds / 2592000);
|
||||
$years = round($seconds / 31536000);
|
||||
|
||||
if ($seconds < 60) { $w = 'less than a minute'; }
|
||||
elseif ($seconds < 90) { $w = 'about a minute'; }
|
||||
elseif ($minutes < 50) { $w = "$minutes minutes"; }
|
||||
elseif ($hours < 2) { $w = 'about an hour'; }
|
||||
elseif ($hours < 24) { $w = "$hours hours"; }
|
||||
elseif ($days < 2) { $w = 'a day'; }
|
||||
elseif ($days < 30) { $w = "$days days"; }
|
||||
elseif ($days < 45) { $w = 'about a month'; }
|
||||
elseif ($days < 365) { $w = "$months months"; }
|
||||
elseif ($years < 2) { $w = 'about a year'; }
|
||||
else { $w = "$years years"; }
|
||||
|
||||
return $future ? "$w from now" : "$w ago";
|
||||
}
|
||||
|
||||
function guess_os() {
|
||||
$os_guess = 'linux';
|
||||
$user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
|
||||
if (stripos($user_agent, 'Android') !== false) {}
|
||||
elseif (stripos($user_agent, 'iPhone') !== false) {}
|
||||
elseif (stripos($user_agent, 'iPad') !== false) {}
|
||||
elseif (stripos($user_agent, 'CrOS') !== false) { $os_guess = 'linux'; }
|
||||
elseif (stripos($user_agent, 'Windows') !== false) { $os_guess = 'windows'; }
|
||||
elseif (stripos($user_agent, 'Macintosh') !== false) {}
|
||||
elseif (stripos($user_agent, 'Linux') !== false) { $os_guess = 'linux'; }
|
||||
elseif (stripos($user_agent, 'FreeBSD') !== false) {}
|
||||
|
||||
return $os_guess;
|
||||
}
|
||||
|
||||
$options = [
|
||||
"linux" => [
|
||||
"name" => "Linux",
|
||||
"architecture" => "x86-64",
|
||||
"download_path" => "",
|
||||
"download_filename" => "supercardinality",
|
||||
],
|
||||
"windows" => [
|
||||
"name" => "Windows",
|
||||
"architecture" => "x86-64",
|
||||
"download_path" => "",
|
||||
"download_filename" => "supercardinality.exe",
|
||||
],
|
||||
];
|
||||
|
||||
$os_guess = guess_os();
|
||||
|
||||
$latest = json_decode(file_get_contents('releases/latest.json'), true);
|
||||
$version = empty($latest["version"]) ? "" : $latest["version"];
|
||||
$version_timestamp = empty($latest["timestamp"]) ? -1 : $latest["timestamp"];
|
||||
$version_timestamp_in_words = timestamp_in_words($version_timestamp);
|
||||
|
||||
if (!empty($latest["linux_path"])) {
|
||||
$options["linux"]["download_path"] = $latest["linux_path"];
|
||||
if (!str_contains($latest["linux_path"], "://")) {
|
||||
$options["linux"]["download_path"] = "releases/" . $options["linux"]["download_path"];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($latest["windows_path"])) {
|
||||
$options["windows"]["download_path"] = $latest["windows_path"];
|
||||
if (!str_contains($latest["windows_path"], "://")) {
|
||||
$options["windows"]["download_path"] = "releases/" . $options["windows"]["download_path"];
|
||||
}
|
||||
}
|
||||
|
||||
$display_other_builds = false;
|
||||
foreach($options as $os => $target) {
|
||||
if (!empty($target["download_path"])) {
|
||||
$display_other_builds = true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
Reference in New Issue
Block a user