topmostfriend-website/public/downloads.php
2023-11-19 16:57:31 +00:00

81 lines
3 KiB
PHP

<?php
$_curr_page = 'downloads';
$title = 'Downloads';
$description = 'This page lists all version of Top Most Friend available for download, with the latest version at the top.';
$files = glob('dl/*/TopMostFriend.exe');
rsort($files);
$indent = "\r\n ";
$body = "{$indent}<h2>{$title}</h2>"
. "{$indent}<p>{$description}</p>"
. "{$indent}<p>Microsoft Windows XP Service Pack 3 and newer are supported, provided <a class=\"tmf-external\" href=\"https://www.microsoft.com/download/details.aspx?id=17851\" target=\"_blank\" rel=\"noopener\">.NET Framework 4.0</a> is installed.</p>"
. "{$indent}<span id=\"latest\"></span>";
foreach($files as $fileName) {
$folderName = dirname($fileName);
$changlogName = $folderName . DIRECTORY_SEPARATOR . 'changelog.txt';
$changelog = fopen($changlogName, 'rb');
if(!$changelog)
continue;
$versionInfo = fgets($changelog);
fclose($changelog);
if($versionInfo === false)
continue;
$versionInfo = trim($versionInfo);
if(empty($versionInfo))
continue;
$buttonClasses = [];
if(empty($hadLatest)) {
$hadLatest = true;
$isLatest = true;
$latestText = ' <a href="#latest">Latest!</a>';
$buttonClasses[] = 'tmf-button-latest';
} else {
$isLatest = false;
$latestText = '';
}
[$version, $date] = explode(' - ', $versionInfo, 2);
$versionId = $version;
$date = strtotime($date);
$sourceArchive = $folderName . '/topmostfriend-' . substr($version, 1) . '.zip';
$sha256File = $fileName . '.sha256';
$sha256Hash = is_file($sha256File) ? trim(file_get_contents($sha256File)) : '';
$body .= sprintf('%s<h3 id="%s"><a href="#%s">%s &mdash; <time datetime="%s">%s</time></a>%s</h3>', $indent, $versionId, $versionId, $version, date('c', $date), date('Y-m-d', $date), $latestText);
if(empty($sha256Hash))
$body .= '<p>SHA256 hash is missing.</p>';
else {
$sha256HashFile = hash_file('sha256', $fileName);
$sha256HashMatches = hash_equals($sha256Hash, $sha256HashFile) ? '' : ' <b>(does not match with actual file)</b>';
$body .= sprintf('<p>SHA256: <code>%s</code>%s</p>', $sha256Hash, $sha256HashMatches);
}
$body .= $indent . '<ul class="tmf-buttons' . (empty($buttonClasses) ? '' : (' ' . implode(' ', $buttonClasses))) .'">';
$indent .= ' ';
$body .= sprintf('%s<li class="tmf-button tmf-button-major"><a href="./%s">Download %s</a></li>', $indent, $fileName, $version);
$body .= sprintf('%s<li class="tmf-button"><a href="./changelog.php#%s">Changelog</a></li>', $indent, $version);
if(is_file($sourceArchive))
$body .= sprintf('%s<li class="tmf-button"><a href="./%s">Source Code (.zip)</a></li>', $indent, $sourceArchive);
$indent = substr($indent, 0, -4);
$body .= $indent . '</ul>'
. $indent . '<div class="tmf-clear"></div>';
}
$indent = substr($indent, 0, -4);
$body .= $indent;
require_once __DIR__ . '/_inc/out.php';