if(isset($_GET['logout']))
{
logout();
}
// Logout Function -->
function logout(){
session_destroy();
header("Location: ../");
exit();
}
// Template admin header
function template_admin_header($title, $selected = 'dashboard', $selected_child = '') {
// Admin HTML links
$admin_links = '
Dashboard
Files
Settings
';
// Indenting the below code may cause an error
echo <<
$title
EOT;
}
// Template admin footer
function template_admin_footer() {
// Indenting the below code may cause an error
echo <<
EOT;
}
// Convert date to elapsed string function
function time_elapsed_string($datetime, $full = false) {
$now = new DateTime;
$ago = new DateTime($datetime);
$diff = $now->diff($ago);
$diff->w = floor($diff->d / 7);
$diff->d -= $diff->w * 7;
$string = ['y' => 'year','m' => 'month','w' => 'week','d' => 'day','h' => 'hour','i' => 'minute','s' => 'second'];
foreach ($string as $k => &$v) {
if ($diff->$k) {
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
} else {
unset($string[$k]);
}
}
if (!$full) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' ago' : 'just now';
}
const GITHUB_SOURCE_API = 'https://api.github.com/repos/Supernova3339/anonfiles/releases';
function checkForUpdates(Request $request, Response $response): Response
{
$jsonResponse = [
'status' => 'OK',
'message' => 'Already Latest Version',
'upgrade' => false,
];
$acceptPrerelease = param($request, 'prerelease', 'false') === 'true';
try {
$json = $this->getApiJson();
foreach ($json as $release) {
if (
$release->prerelease === $acceptPrerelease &&
version_compare($release->tag_name, PLATFORM_VERSION, '>') &&
version_compare($release->tag_name, 'prerelease', '<')
) {
$jsonResponse['message'] = 'New version available!', [$release->tag_name]);
$jsonResponse['upgrade'] = true;
break;
}
if (version_compare($release->tag_name, PLATFORM_VERSION, '<=')) {
break;
}
}
} catch (RuntimeException $e) {
$jsonResponse['status'] = 'ERROR';
$jsonResponse['message'] = $e->getMessage();
}
return json($response, $jsonResponse);
}
function getApiJson()
{
$opts = [
'http' => [
'method' => 'GET',
'header' => [
'User-Agent: AnonFiles-App',
'Accept: application/vnd.github.v3+json',
],
],
];
$data = @file_get_contents(self::GITHUB_SOURCE_API, false, stream_context_create($opts));
if ($data === false) {
throw new RuntimeException('Cannot contact the Github API. Try again.');
}
return json_decode($data);
}
?>