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

154 lines
5.9 KiB
PHP

<?php
require_once __DIR__ . '/../seria.php';
$dTorrentId = (string)filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
try {
$dTorrentInfo = SeriaTorrent::byId($pdo, $dTorrentId);
} catch(SeriaTorrentNotFoundException $ex) {
http_response_code(404);
die('Download not found.');
}
$dCanDownload = $dTorrentInfo->canDownload($sUserInfo);
if($dCanDownload !== '') {
http_response_code(403);
switch($dCanDownload) {
case 'inactive':
die('This download is inactive.');
case 'private':
die('You must be logged in for this download.');
case 'pending':
die('This download is pending approval.');
default:
die($dCanDownload);
}
}
if(isset($_GET['action'])) {
if(empty($_GET['boob']) || !hash_equals($sVerification, (string)filter_input(INPUT_GET, 'boob'))) {
header('Location: /info.php?id=' . $dTorrentInfo->getId());
exit;
}
switch(filter_input(INPUT_GET, 'action')) {
case 'recalculate-info-hash':
if($sUserInfo->canRecalculateInfoHash()) {
$builder = SeriaTorrentBuilder::import($dTorrentInfo);
$dTorrentInfo->setHash($builder->calculateInfoHash());
$dTorrentInfo->update();
}
header('Location: /info.php?id=' . $dTorrentInfo->getId());
exit;
case 'approve':
if($sUserInfo->canApproveTorrents()) {
$dTorrentInfo->approve();
$dTorrentInfo->update();
}
header('Location: /info.php?id=' . $dTorrentInfo->getId());
exit;
case 'deny':
if($sUserInfo->canApproveTorrents())
$dTorrentInfo->nuke();
header('Location: /pending.php');
exit;
}
}
$tPageTitle = $dTorrentInfo->getName();
require_once __DIR__ . '/_header.php';
echo '<div class="info">';
echo '<div class="info-header">';
echo '<h2>' . htmlspecialchars($dTorrentInfo->getName()) . '</h2>';
echo '<ul>';
echo '<li><a href="/download.php?id=' . $dTorrentInfo->getId() . '"><img src="//static.flash.moe/images/silk/link.png" alt="" /> Download</a></li>';
if($sUserInfo->canRecalculateInfoHash())
echo '<li><a href="/info.php?id=' . $dTorrentInfo->getId() . '&amp;action=recalculate-info-hash&amp;boob=' . $sVerification . '"><img src="//static.flash.moe/images/silk/calculator.png" alt="" /> Recalculate Info Hash</a></li>';
echo '</ul>';
echo '</div>';
echo '<div class="info-stats">';
echo '<div class="info-stats-item info-stats-submitted">';
echo '<div class="info-stats-item-title">Submitted on</div>';
echo '<div class="info-stats-item-value"><time datetime="' . date('c', $dTorrentInfo->getCreatedTime()) . '">' . date('Y-m-d H:i:s e', $dTorrentInfo->getCreatedTime()) . '</time></div>';
echo '</div>';
if($sUserInfo->canApproveTorrents() && $dTorrentInfo->isApproved()) {
echo '<div class="info-stats-item info-stats-approved">';
echo '<div class="info-stats-item-title">Approved on</div>';
echo '<div class="info-stats-item-value"><time datetime="' . date('c', $dTorrentInfo->getApprovedTime()) . '">' . date('Y-m-d H:i:s e', $dTorrentInfo->getApprovedTime()) . '</time></div>';
echo '</div>';
}
echo '<div class="info-stats-item info-stats-size" style="border-color: ' . seria_size_colour($dTorrentInfo->getSize()) . '">';
echo '<div class="info-stats-item-title">Total size</div>';
echo '<div class="info-stats-item-value">' . byte_symbol($dTorrentInfo->getSize()) . ' (' . number_format($dTorrentInfo->getSize()) . ' bytes)</div>';
echo '</div>';
echo '<div class="info-stats-item info-stats-uploading">';
echo '<div class="info-stats-item-title">Uploading</div>';
echo '<div class="info-stats-item-value">' . number_format($dTorrentInfo->getCompletePeers()) . '</div>';
echo '</div>';
echo '<div class="info-stats-item info-stats-downloading">';
echo '<div class="info-stats-item-title">Downloading</div>';
echo '<div class="info-stats-item-value">' . number_format($dTorrentInfo->getIncompletePeers()) . '</div>';
echo '</div>';
if($dTorrentInfo->isPrivate()) {
echo '<div class="info-stats-item info-stats-visibility">';
echo '<div class="info-stats-item-title">Visibility</div>';
echo '<div class="info-stats-item-value">Private</div>';
echo '</div>';
}
echo '</div>';
if($dTorrentInfo->hasUser()) {
try {
$dUserInfo = SeriaUser::byId($pdo, $dTorrentInfo->getUserId());
echo '<div class="info-user" style="--user-colour:' . (string)$dUserInfo->getColour() . '">';
echo '<div class="info-user-uploaded">Submitted by</div>';
echo '<div class="avatar info-user-avatar"><a href="/profile.php?name=' . $dUserInfo->getName() . '"><img src="' . sprintf(SERIA_AVATAR_FORMAT_RES, $dUserInfo->getId(), 40) . '" alt="" width="20" height="20" /></a></div>';
echo '<div class="info-user-name"><a href="/profile.php?name=' . $dUserInfo->getName() . '">' . $dUserInfo->getName() . '</a></div>';
echo '</div>';
} catch(SeriaUserNotFoundException $ex) {}
}
if(!$dTorrentInfo->isApproved() && $sUserInfo->canApproveTorrents()) {
echo '<div class="info-pending">';
echo '<div class="info-pending-text">This torrent is pending approval.</div>';
echo '<a class="info-pending-approve" href="/info.php?id=' . $dTorrentInfo->getId() . '&amp;action=approve&amp;boob=' . $sVerification . '">APPROVE</a>';
echo '<a class="info-pending-deny" href="/info.php?id=' . $dTorrentInfo->getId() . '&amp;action=deny&amp;boob=' . $sVerification . '">DENY</a>';
echo '</div>';
}
$dComment = $dTorrentInfo->getComment();
if(!empty($dComment)) {
echo '<div class="info-comment">';
echo '<div class="info-comment-header">Description</div>';
echo '<div class="info-comment-content"><pre>';
echo htmlspecialchars($dComment);
echo '</pre></div>';
echo '</div>';
}
echo '</div>';
require_once __DIR__ . '/_footer.php';