Files
supercardinality-website/index.php
T

176 lines
5.2 KiB
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>
<title>Supercardinality</title>
<meta name="robots" content="noindex" />
<meta name="description" content="If mid doesn't exist you can't run it down." />
<meta name="author" content="Thayol" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="favicon/128.png">
<link rel="icon" type="image/png" sizes="64x64" href="favicon/64.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon/32.png">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div></div>
<main>
<div class="divider">
<div class="divider-gem"></div>
</div>
<h1>
Supercardinality
</h1>
<p class="divider subtitle">
NO MID NO FEED
</p>
<?php if (empty($options[$os_guess]["download_path"])): ?>
<a class="recommended build disabled">
<div>
Download unavailable
</div>
</a>
<?php else: ?>
<a class="recommended build" href="<?= $options[$os_guess]["download_path"] ?>" download="<?= $options[$os_guess]["download_filename"] ?>">
<div>
Download for <?= $options[$os_guess]["name"] ?>
</div>
</a>
<?php endif; ?>
<?php if ($display_other_builds): ?>
<ul class="other-builds">
<p>Other builds</p>
<?php foreach($options as $os => $target): ?>
<?php
if (empty($target["download_path"])) {
continue;
}
?>
<li>
<a class="other build" href="<?= $target["download_path"] ?>" download="<?= $target["download_filename"] ?>">
<?= $target["name"] ?><span class="architecture"><?= $target["architecture"] ?></span>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</main>
<footer>
<p>
Online services are <a class="blend" href="<?= $online_services_source_url ?>">open source</a>.
<br>
In case of any questions, message <a href="<?= $contact_link ?>"><?= $contact_name ?></a>.
</p>
<?php if (!empty($version)): ?>
<p>
<?= $version ?>
<?php if (!empty($version_timestamp)): ?>
・ built <?= $version_timestamp_in_words ?>
<?php endif; ?>
</p>
<?php endif; ?>
</footer>
</body>
</html>