Skip to content

Commit

Permalink
add lists to relevant other torrents
Browse files Browse the repository at this point in the history
  • Loading branch information
Spine authored and itismadness committed Oct 4, 2021
1 parent c9ca1eb commit da5dda4
Show file tree
Hide file tree
Showing 14 changed files with 278 additions and 200 deletions.
53 changes: 50 additions & 3 deletions app/Torrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,8 @@ public function peerlistTotal() {

public function peerlistPage(int $userId, int $limit, int $offset) {
$key = sprintf(self::CACHE_KEY_PEERLIST_PAGE, $this->id, $offset);
if (($list = $this->cache->get_value($key)) === false) {
$list = $this->cache->get_value($key);
if ($list === false) {
// force flush the next page of results
$this->cache->delete_value(sprintf(self::CACHE_KEY_PEERLIST_PAGE, $this->id, $offset + $limit));
$this->db->prepared_query("
Expand All @@ -647,7 +648,9 @@ public function peerlistPage(int $userId, int $limit, int $offset) {
xfu.ip AS ipv4addr,
xfu.uid AS user_id,
t.Size AS size,
sx.name AS seedbox
sx.name AS seedbox,
EXISTS(SELECT 1 FROM users_downloads ud WHERE ud.UserID = xfu.uid AND ud.TorrentID = xfu.fid) AS is_download,
EXISTS(SELECT 1 FROM xbt_snatched xs WHERE xs.uid = xfu.uid AND xs.fid = xfu.fid) AS is_snatched
FROM xbt_files_users AS xfu
INNER JOIN users_main AS um ON (um.ID = xfu.uid)
INNER JOIN torrents AS t ON (t.ID = xfu.fid)
Expand All @@ -658,9 +661,53 @@ public function peerlistPage(int $userId, int $limit, int $offset) {
LIMIT ? OFFSET ?
", $userId, $this->id, $userId, $limit, $offset
);
$list = $this->db->to_array(false, MYSQLI_ASSOC);
$list = $this->db->to_array(false, MYSQLI_ASSOC, false);
$this->cache->cache_value($key, $list, 300);
}
return $list;
}

public function downloadTotal(): int {
return $this->db->scalar("
SELECT count(*) FROM users_downloads WHERE TorrentID = ?
", $this->id
);
}

public function downloadPage(int $limit, int $offset): array {
$this->db->prepared_query("
SELECT ud.UserID AS user_id,
ud.Time AS timestamp,
EXISTS(SELECT 1 FROM xbt_snatched xs WHERE xs.uid = ud.UserID AND xs.fid = ud.TorrentID) AS is_snatched,
EXISTS(SELECT 1 FROM xbt_files_users xfu WHERE xfu.uid = ud.UserID AND xfu.fid = ud.TorrentID) AS is_seeding
FROM users_downloads ud
WHERE ud.TorrentID = ?
ORDER BY ud.Time DESC, ud.UserID
LIMIT ? OFFSET ?
", $this->id, $limit, $offset
);
return $this->db->to_array(false, MYSQLI_ASSOC, false);
}

public function snatchTotal(): int {
return $this->db->scalar("
SELECT count(*) FROM xbt_snatched WHERE fid = ?
", $this->id
);
}

public function snatchPage(int $limit, int $offset): array {
$this->db->prepared_query("
SELECT xs.uid AS user_id,
from_unixtime(xs.tstamp) AS timestamp,
EXISTS(SELECT 1 FROM users_downloads ud WHERE ud.UserID = xs.uid AND ud.TorrentID = xs.fid) AS is_download,
EXISTS(SELECT 1 FROM xbt_files_users xfu WHERE xfu.uid = xs.uid AND xfu.fid = xs.fid) AS is_seeding
FROM xbt_snatched xs
WHERE xs.fid = ?
ORDER BY xs.tstamp DESC
LIMIT ? OFFSET ?
", $this->id, $limit, $offset
);
return $this->db->to_array(false, MYSQLI_ASSOC, false);
}
}
4 changes: 4 additions & 0 deletions app/Util/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function total(): int {
return $this->total;
}

public function pages(): int {
return (int)ceil($this->total / $this->perPage);
}

public function setAnchor(string $anchor) {
$this->anchor = '#' . $anchor;
return $this;
Expand Down
1 change: 1 addition & 0 deletions classes/config.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
define('ICON_NONE', "\xf0\x9f\x9a\xab");
define('ICON_TOGGLE', "\xf0\x9f\x94\x81");
define('ICON_PADLOCK', "\xF0\x9F\x94\x92");
define('ICON_STAR', "\xE2\x98\x85");

define('COLLAGE', [
0 => 'Personal',
Expand Down
20 changes: 10 additions & 10 deletions sections/reportsv2/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
</tr>";

foreach ($Reports as $Report) {
if (check_perms('admin_reports')) {
if ($Viewer->permitted('admin_reports')) {
$ReporterID = $Report['ReporterID'];
$ReporterName = $userMan->findById($ReporterID)->username();
$ReportLinks = "<a href=\"user.php?id=$ReporterID\">$ReporterName</a> <a href=\"reportsv2.php?view=report&amp;id={$Report['ID']}\">reported it</a>";
Expand All @@ -187,8 +187,8 @@
$ReportInfo .= "\n\t\t</table>";
}

$CanEdit = (check_perms('torrents_edit') || (($UserID == $Viewer->id() && !$Viewer->disableWiki()) && !($Remastered && !$RemasterYear)));
$RegenLink = check_perms('users_mod') ? ' <a href="torrents.php?action=regen_filelist&amp;torrentid=' . $TorrentID . '" class="brackets">Regenerate</a>' : '';
$CanEdit = ($Viewer->permitted('torrents_edit') || (($UserID == $Viewer->id() && !$Viewer->disableWiki()) && !($Remastered && !$RemasterYear)));
$RegenLink = $Viewer->permitted('users_mod') ? ' <a href="torrents.php?action=regen_filelist&amp;torrentid=' . $TorrentID . '" class="brackets">Regenerate</a>' : '';
$FileTable = '
<table class="filelist_table">
<tr class="colhead_dark">
Expand Down Expand Up @@ -296,7 +296,7 @@
'key' => $Viewer->announceKey(),
't' => $TorrentList,
'edit' => $CanEdit,
'remove' => check_perms('torrents_delete') || $UserID == $Viewer->id(),
'remove' => $Viewer->permitted('torrents_delete') || $UserID == $Viewer->id(),
'pl' => true,
]) ?>
&raquo; <a href="#" onclick="$('#torrent_<?=($TorrentID)?>').gtoggle(); return false;"><?=($ExtraInfo)?></a>
Expand Down Expand Up @@ -327,18 +327,18 @@
}
?>
</blockquote>
<?php if (check_perms('site_moderate_requests')) { ?>
<?php if ($Viewer->permitted('site_moderate_requests')) { ?>
<div class="linkbox">
<a href="torrents.php?action=masspm&amp;id=<?=($GroupID)?>&amp;torrentid=<?=($TorrentID)?>" class="brackets">Mass PM snatchers</a>
</div>
<?php } ?>
<div class="linkbox">
<a href="#" class="brackets" onclick="show_peers('<?=($TorrentID)?>', 0); return false;">View peer list</a>
<?php if (check_perms('site_view_torrent_snatchlist')) { ?>
<a href="#" class="brackets tooltip" onclick="show_downloads('<?=($TorrentID)?>', 0); return false;" title="View the list of users that have clicked the &quot;DL&quot; button.">View download list</a>
<a href="#" class="brackets tooltip" onclick="show_snatches('<?=($TorrentID)?>', 0); return false;" title="View the list of users that have reported a snatch to the tracker.">View snatch list</a>
<?php if ($Viewer->permitted('site_view_torrent_snatchlist')) { ?>
<a href="#" class="brackets tooltip" onclick="show_downloads('<?=($TorrentID)?>', 0); return false;" title="View the list of users that have clicked the &quot;DL&quot; button.">View downloaders</a>
<a href="#" class="brackets tooltip" onclick="show_snatches('<?=($TorrentID)?>', 0); return false;" title="View the list of users that have reported a snatch to the tracker.">View snatchers</a>
<?php } ?>
<a href="#" class="brackets" onclick="show_files('<?=($TorrentID)?>'); return false;">View file list</a>
<a href="#" class="brackets" onclick="show_peers('<?=($TorrentID)?>', 0); return false;">View seeders</a>
<a href="#" class="brackets" onclick="show_files('<?=($TorrentID)?>'); return false;">View contents</a>
<?php if ($Reported) { ?>
<a href="#" class="brackets" onclick="show_reported('<?=($TorrentID)?>'); return false;">View report information</a>
<?php } ?>
Expand Down
74 changes: 67 additions & 7 deletions sections/reportsv2/static.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
tg.CategoryID,
t.Time,
t.Description,
t.FileList,
t.Remastered,
t.RemasterTitle,
t.RemasterYear,
Expand All @@ -159,6 +158,8 @@
t.HasLogDB,
t.LogScore,
t.LogChecksum,
t.FileList,
t.FilePath,
tls.last_action,
t.UserID AS UploaderID
FROM $tables
Expand All @@ -172,7 +173,7 @@
);
$Reports = $DB->to_array(false, MYSQLI_NUM);

View::show_header('Reports V2', ['js' => 'reportsv2,bbcode,torrent']);
View::show_header('Reports V2', ['js' => 'reportsv2,bbcode,browse,torrent']);
?>
<div class="header">
<h2><?=$Title?></h2>
Expand Down Expand Up @@ -202,9 +203,9 @@
[$ReportID, $ReporterID, $TorrentID, $Type, $UserComment, $ResolverID,
$Status, $ReportedTime, $LastChangeTime, $ModComment, $Tracks, $Images,
$ExtraIDs, $Links, $LogMessage, $GroupName, $GroupID, $ArtistID, $ArtistName, $Year,
$CategoryID, $Time, $Description, $FileList, $Remastered, $RemasterTitle, $RemasterYear,
$CategoryID, $Time, $Description, $Remastered, $RemasterTitle, $RemasterYear,
$Media, $Format, $Encoding, $Size, $HasLog, $HasCue, $HasLogDB, $LogScore, $LogChecksum,
$LastAction, $UploaderID
$FileList, $FilePath, $LastAction, $UploaderID
] = $Report;
$reporterName = (int)$ReporterID ? $userMan->findById((int)$ReporterID)->username() : 'System';
$uploaderName = (int)$UploaderID ? $userMan->findById((int)$UploaderID)->username() : 'System';
Expand Down Expand Up @@ -275,7 +276,35 @@
<a href="log.php?search=Torrent+<?=$TorrentID?>"><?=$TorrentID?></a> (Deleted)
<?php } else { ?>
<?=$LinkName?>
<a href="torrents.php?action=download&amp;id=<?=$TorrentID?>&amp;torrent_pass=<?= $Viewer->announceKey() ?>" title="Download" class="brackets tooltip">DL</a>
<br /><a href="torrents.php?action=download&amp;id=<?=$TorrentID?>&amp;torrent_pass=<?= $Viewer->announceKey() ?>" title="Download" class="brackets tooltip">DL</a>
<a href="#" class="brackets tooltip" onclick="show_downloads('<?=($TorrentID)?>', 0); return false;" title="View the list of users that have clicked the &quot;DL&quot; button.">Downloaders</a>
<a href="#" class="brackets tooltip" onclick="show_snatches('<?=($TorrentID)?>', 0); return false;" title="View the list of users that have reported a snatch to the tracker.">Snatchers</a>
<a href="#" class="brackets" onclick="show_peers('<?=($TorrentID)?>', 0); return false;">Seeders</a>
<a href="#" class="brackets" onclick="show_files('<?=($TorrentID)?>'); return false;">Contents</a>
<div id="viewlog_<?=$TorrentID?>" class="hidden"></div>
<div id="peers_<?=$TorrentID?>" class="hidden"></div>
<div id="downloads_<?=$TorrentID?>" class="hidden"></div>
<div id="snatches_<?=$TorrentID?>" class="hidden"></div>
<div id="files_<?=$TorrentID?>" class="hidden">
<table class="filelist_table">
<tr class="colhead_dark">
<td>
<div class="filelist_title" style="float: left;">File Names</div>
<div class="filelist_path" style="float: right;"><?= $FilePath ? "/$FilePath/" : '' ?></div>
</td>
<td class="nobr" style="text-align: right">
<strong>Size</strong>
</td>
</tr>
<?php
$file = explode("\n", $FileList);
foreach ($file as $f) {
$info = $torMan->splitMetaFilename($f);
?>
<tr><td><?= $info['name'] ?></td><td class="number_column nobr"><?= Format::get_size($info['size']) ?></td></tr>
<?php } ?>
</table>
</div>
<br /><span class="report_reporter">reported by <a href="user.php?id=<?=$ReporterID?>"><?= $reporterName ?></a> <?=time_diff($ReportedTime)?> for the reason: <strong><?=$ReportType['title']?></strong></span>
<br />uploaded by <a href="user.php?id=<?=$UploaderID?>"><?= $uploaderName ?></a> on <span title="<?= time_diff($Time, 3, false) ?>"><?= $Time ?></span>
<br />Last action: <?= $LastAction ?: 'Never' ?>
Expand Down Expand Up @@ -396,6 +425,7 @@
t.Time,
t.Description,
t.Filelist,
t.FilePath,
t.Remastered,
t.RemasterTitle,
t.RemasterYear,
Expand All @@ -421,7 +451,7 @@
);

[$ExtraGroupName, $ExtraGroupID, $ExtraArtistID, $ExtraArtistName,
$ExtraYear, $ExtraTime, $ExtraDescription, $ExtraFileList, $ExtraRemastered,
$ExtraYear, $ExtraTime, $ExtraDescription, $ExtraFileList, $ExtraFilePath, $ExtraRemastered,
$ExtraRemasterTitle, $ExtraRemasterYear, $ExtraMedia, $ExtraFormat,
$ExtraEncoding, $ExtraSize, $ExtraHasCue, $ExtraHasLog, $ExtraLogScore,
$ExtraLastAction, $ExtraUploaderID, $ExtraUploaderName]
Expand All @@ -446,7 +476,35 @@
?>
<?=($First ? '' : '<br />')?>
<?=$ExtraLinkName?>
<a href="torrents.php?action=download&amp;id=<?=$ExtraID?>&amp;torrent_pass=<?php $Viewer->announceKey() ?>" title="Download" class="brackets tooltip">DL</a>
<br /><a href="torrents.php?action=download&amp;id=<?= $ExtraID ?>&amp;torrent_pass=<?= $Viewer->announceKey() ?>" title="Download" class="brackets tooltip">DL</a>
<a href="#" class="brackets tooltip" onclick="show_downloads('<?= $ExtraID ?>', 0); return false;" title="View the list of users that have clicked the &quot;DL&quot; button.">Downloaders</a>
<a href="#" class="brackets tooltip" onclick="show_snatches('<?= $ExtraID ?>', 0); return false;" title="View the list of users that have reported a snatch to the tracker.">Snatchers</a>
<a href="#" class="brackets" onclick="show_peers('<?= $ExtraID ?>', 0); return false;">Seeders</a>
<a href="#" class="brackets" onclick="show_files('<?= $ExtraID ?>'); return false;">Contents</a>
<div id="viewlog_<?= $ExtraID ?>" class="hidden"></div>
<div id="peers_<?= $ExtraID ?>" class="hidden"></div>
<div id="downloads_<?= $ExtraID ?>" class="hidden"></div>
<div id="snatches_<?= $ExtraID ?>" class="hidden"></div>
<div id="files_<?= $ExtraID ?>" class="hidden">
<table class="filelist_table">
<tr class="colhead_dark">
<td>
<div class="filelist_title" style="float: left;">File Names</div>
<div class="filelist_path" style="float: right;"><?= $ExtraFilePath ? "/$ExtraFilePath/" : '' ?></div>
</td>
<td class="nobr" style="text-align: right">
<strong>Size</strong>
</td>
</tr>
<?php
$file = explode("\n", $ExtraFileList);
foreach ($file as $f) {
$info = $torMan->splitMetaFilename($f);
?>
<tr><td><?= $info['name'] ?></td><td class="number_column nobr"><?= Format::get_size($info['size']) ?></td></tr>
<?php } ?>
</table>
</div>
<br />uploaded by <a href="user.php?id=<?=$ExtraUploaderID?>"><?=$ExtraUploaderName?></a> on <span title="<?=
time_diff($ExtraTime, 3, false) ?>"><?= $ExtraTime ?> (<?=
strtotime($ExtraTime) < strtotime($Time) ? 'older upload' : 'more recent upload' ?>)</span>
Expand Down Expand Up @@ -658,6 +716,8 @@
);
} elseif (isset($ReportType['extra_log'])) {
$Value = $ReportType['extra_log'];
} else {
$Value = '';
}
?>
<input type="text" name="log_message" id="log_message<?=$ReportID?>" size="40" value="<?= trim($Value) ?>" />
Expand Down
Loading

0 comments on commit da5dda4

Please sign in to comment.