seria/public/available.php
2022-07-03 23:44:11 +00:00

62 lines
1.5 KiB
PHP

<?php
require_once __DIR__ . '/../seria.php';
if(isset($_GET['name'])) {
$aUserName = (string)filter_input(INPUT_GET, 'name');
try {
$aUserInfo = SeriaUser::byName($pdo, $aUserName);
} catch(SeriaUserNotFoundException $ex) {
http_response_code(404);
die('User not found.');
}
} else $aUserInfo = null;
if($aUserInfo !== null)
$aPageTitle = 'Downloads submitted by ' . $aUserInfo->getName();
else
$aPageTitle = 'Available Downloads';
$tPageTitle = $aPageTitle;
$aPageUrl = '/available.php?';
if($aUserInfo !== null)
$aPageUrl .= 'name=' . $aUserInfo->getName() . '&amp;';
$aStartAt = -1;
$aTake = 20;
if(isset($_GET['start']))
$aStartAt = (int)filter_input(INPUT_GET, 'start', FILTER_SANITIZE_NUMBER_INT);
$aTorrents = SeriaTorrent::all($pdo, !$sUserInfo->isLoggedIn(), true, $aUserInfo, $aStartAt, $aTake);
require_once __DIR__ . '/_header.php';
echo '<div class="downloads">';
echo '<div class="downloads-header">' . $aPageTitle . '</div>';
echo '<div class="downloads-listing">';
$aShowMore = false;
$aLastId = 0;
if(empty($aTorrents)) {
echo '<div class="downloads-nothing">Sorry, nothing.</div>';
} else {
foreach($aTorrents as $torrent) {
echo $torrent->toHTML($sUserInfo, 'downloads-item');
$aLastId = $torrent->getId();
}
$aShowMore = count($aTorrents) === $aTake;
}
echo '</div>';
if($aShowMore)
echo '<div class="downloads-more"><a href="' . $aPageUrl . 'start=' . $aLastId . '">View more</a></div>';
echo '</div>';
require_once __DIR__ . '/_footer.php';