%s comments',
$action, $id, ucfirst($match[1])
);
}
function createdBy(int $ownProfile, string $user, string $objects): string {
return $ownProfile ? "your $objects" : "$objects created by $user";
}
// who is it?
if (!isset($_GET['id'])) {
$UserID = $LoggedUser['ID'];
$Username = $LoggedUser['Username'];
} else {
$UserID = (int)$_GET['id'];
if ($UserID < 1) {
error(404);
}
$UserInfo = Users::user_info($UserID);
$Perms = Permissions::get_permissions($UserInfo['PermissionID']);
if (!check_paranoia('torrentcomments', $UserInfo['Paranoia'], $Perms['Class'], $UserID)) {
error(403);
}
$Username = $UserInfo['Username'];
}
if ($LoggedUser['ID'] == $UserID) {
$ownProfile = true;
$linkId = '';
$have = 'you have';
$who = 'you';
$whoHas = 'you have';
} else {
$ownProfile = false;
$linkId = "&id=$UserID";
$have = "$Username has";
$who = $Username;
$whoHas = Users::format_username($UserID, false, false, false) . ' has';
}
$Action = $_REQUEST['action'] ?? 'torrents';
$Type = $_REQUEST['type'] ?? 'default';
$BaseLink = "comments.php?action=$Action$linkId";
// SQL components
$condArgs = [];
$condition = [];
$Join = [];
$joinArgs = [];
$ActionLinks = [];
$TypeLinks = [];
switch ($Action) {
case 'artist':
$Header = 'Artist comments left by %s';
$Title = 'Artist comments left by ' . $who;
$table = 'artists_group AS ag';
$idField = 'ag.ArtistID';
$nameField = 'ag.Name';
$condition[] = "C.AuthorID = ?";
$condArgs[] = $UserID;
$ActionLinks = [
linkBuild($linkId, 'collages'),
linkBuild($linkId, 'requests'),
linkBuild($linkId, 'torrents'),
];
break;
case 'collages':
switch ($Type) {
case 'created':
$Header = 'Comments left on collages %s created';
$Title = 'Comments left on collages ' . $who . ' created';
$condition[] = "cl.UserID = ?";
$condition[] = "C.AuthorID != ?";
$condArgs[] = $UserID;
$condArgs[] = $UserID;
$TypeLinks = [
[$BaseLink, "Display comments left on collages $have made"],
[$BaseLink . "&type=contributed", "Display comments left on collages $have contributed to"],
];
break;
case 'contributed':
$Header = 'Comments left on collages %s contributed to';
$Title = 'Comments left on collages ' . $have . ' contributed to';
$Join[] = "LEFT JOIN collages_torrents ct ON (ct.CollageID = cl.ID AND ct.UserID = ?)";
$Join[] = "LEFT JOIN collages_artists ca ON (ca.CollageID = cl.ID AND ca.UserID = ?)";
$joinArgs[] = $UserID;
$joinArgs[] = $UserID;
$condition[] = 'IF(cl.CategoryID = '
. array_search('Artists', $CollageCats)
. ', ca.ArtistID, ct.GroupID) IS NOT NULL';
$condition[] = "C.AuthorID != ?";
$condArgs[] = $UserID;
$TypeLinks = [
[$BaseLink, "Display comments left on collages $have made"],
["$BaseLink&type=created", "Display comments left on " . createdBy($ownProfile, $Username, 'collages')],
];
break;
default:
$Header = 'Collage comments left by %s';
$Title = 'Collage comments left by ' . $who;
$condition[] = "C.AuthorID = ?";
$condArgs[] = $UserID;
$TypeLinks = [
["$BaseLink&type=contributed", "Display comments left on collages $have contributed to"],
["$BaseLink&type=created", "Display comments left on " . createdBy($ownProfile, $Username, 'collages')],
];
break;
}
$table = 'collages AS cl';
$idField = 'cl.ID';
$nameField = 'cl.Name';
$condition[] = "cl.Deleted = '0'";
$ActionLinks = [
linkBuild($linkId, 'artist'),
linkBuild($linkId, 'requests'),
linkBuild($linkId, 'torrents'),
];
break;
case 'requests':
switch($Type) {
case 'created':
$Header = 'Comments left on requests %s created';
$Title = 'Comments left on requests ' . $who . ' created';
$condition[] = "r.UserID = ?";
$condition[] = "C.AuthorID != ?";
$condArgs[] = $UserID;
$condArgs[] = $UserID;
$TypeLinks = [
[$BaseLink, "Display comments left on requests $have made"],
["$BaseLink&type=voted", "Display comments left on requests $have voted on"],
];
break;
case 'voted':
$Header = 'Comments left on requests %s voted on';
$Title = 'Comments left on requests ' . $who . ' voted on';
$Join[] = 'INNER JOIN requests_votes rv ON (rv.RequestID = r.ID)';
$condition[] = "rv.UserID = ?";
$condition[] = "C.AuthorID != ?";
$condArgs[] = $UserID;
$condArgs[] = $UserID;
$TypeLinks = [
[$BaseLink, "Display comments left on requests $have made"],
["$BaseLink&type=created", "Display comments left on requests $have created"],
];
break;
default:
$Header = 'Request comments left by %s';
$Title = 'Request comments left by ' . $who;
$condition[] = "C.AuthorID = ?";
$condArgs[] = $UserID;
$TypeLinks = [
["$BaseLink&type=created", "Display comments left on requests $have created"],
["$BaseLink&type=voted", "Display comments left on requests $have voted on"],
];
break;
}
$table = 'requests AS r';
$idField = 'r.ID';
$nameField = 'r.Title';
$ActionLinks = [
linkBuild($linkId, 'artist'),
linkBuild($linkId, 'collages'),
linkBuild($linkId, 'torrents'),
];
break;
case 'torrents':
switch($Type) {
case 'uploaded':
$Header = 'Comments left on torrents %s uploaded';
$Title = 'Comments left on torrents ' . $who . ' uploaded';
$Join[] = 'INNER JOIN torrents t ON (t.GroupID = tg.ID)';
$condition[] = 'C.AddedTime > t.Time';
$condition[] = "C.AuthorID != ?";
$condition[] = "t.UserID = ?";
$condArgs[] = $UserID;
$condArgs[] = $UserID;
$TypeLinks[] = [$BaseLink, "Display comments $have made on torrents"];
break;
default:
$Header = 'Torrent comments left by %s';
$Title = 'Torrent comments left by ' . $who;
$condition[] = "C.AuthorID = ?";
$condArgs[] = $UserID;
$TypeLinks[] = ["$BaseLink&type=uploaded", "Display comments left on torrents $have uploaded"];
break;
}
$table = 'torrents_group AS tg';
$idField = 'tg.ID';
$nameField = 'tg.Name';
$ActionLinks = [
linkBuild($linkId, 'artist'),
linkBuild($linkId, 'collages'),
linkBuild($linkId, 'requests'),
];
break;
}
$Join[] = "INNER JOIN comments C ON (C.Page = ? AND C.PageID = $idField)";
$joinArgs[] = $Action;
$Join = implode("\n", $Join);
$cond = $condition ? 'WHERE ' . implode(" AND ", $condition) : '';
$Results = $DB->scalar("
SELECT count(*)
FROM $table
$Join
$cond
", ...array_merge($joinArgs, $condArgs)
);
// Posts per page limit stuff
$PerPage = $LoggedUser['PostsPerPage'] ?? POSTS_PER_PAGE;
[$Page, $Limit] = Format::page_limit($PerPage);
$Comments = $DB->prepared_query("
SELECT
C.AuthorID,
C.Page,
C.PageID,
$nameField,
C.ID,
C.Body,
C.AddedTime,
C.EditedTime,
C.EditedUserID
FROM $table
$Join
$cond
ORDER BY C.ID DESC
LIMIT ?
", ...array_merge($joinArgs, $condArgs, [$Limit])
);
$Count = $DB->record_count();
$Pages = Format::get_pages($Page, $Results, $PerPage, 11);
if ($Action == 'requests') {
$RequestIDs = array_flip(array_flip($DB->collect('PageID')));
$Artists = [];
foreach ($RequestIDs as $RequestID) {
$Artists[$RequestID] = Requests::get_artists($RequestID);
}
$DB->set_query_id($Comments);
} elseif ($Action == 'torrents') {
$GroupIDs = array_flip(array_flip($DB->collect('PageID')));
$Artists = Artists::get_artists($GroupIDs);
$DB->set_query_id($Comments);
}
$Links = implode(' ', $ActionLinks)
. ($TypeLinks
? '
' . implode(' ', array_map(
function ($x) {
return sprintf('%s', $x[0], $x[1]);
}, $TypeLinks
))
: ''
);
View::show_header(sprintf($Title, 'bbcode,comments'));
?>