findById((int)($_GET['id'] ?? 0)); if (is_null($User)) { error(404); } if (!$User->propertyVisible($Viewer, 'torrentcomments')) { error(403); } } $UserID = $User->id(); $Username = $User->username(); if ($Viewer->id() == $UserID) { $ownProfile = true; $linkId = ''; } else { $ownProfile = false; $linkId = "&id=$UserID"; } $Action = $_REQUEST['action'] ?? 'torrents'; $Type = $_REQUEST['type'] ?? 'default'; $BaseLink = "comments.php?action=$Action$linkId"; // SQL components $condArgs = []; $condition = []; $Join = []; $joinArgs = []; $TypeLinks = []; switch ($Action) { case 'artist': $Title = '%s › Artist comments'; $table = 'artists_group AS ag'; $idField = 'ag.ArtistID'; $nameField = 'ag.Name'; $condition[] = "C.AuthorID = ?"; $condArgs[] = $UserID; break; case 'collages': $table = 'collages AS cl'; $idField = 'cl.ID'; $nameField = 'cl.Name'; $condition[] = "cl.Deleted = '0'"; switch ($Type) { case 'created': $Title = "%s › Comments on their collages"; $condition[] = "cl.UserID = ?"; $condition[] = "C.AuthorID != ?"; $condArgs[] = $UserID; $condArgs[] = $UserID; $TypeLinks = [ [$BaseLink, "$Username › Collage comments"], ["$BaseLink&type=contributed", "$Username › Contributed collage comments"], ]; break; case 'contributed': $Title = '%s › Contributed collage comments'; $condition[] = "C.AuthorID != ? AND cl.ID IN ( SELECT DISTINCT CollageID FROM collages_torrents ct WHERE ct.UserID = ? UNION ALL SELECT DISTINCT CollageID FROM collages_artists ca WHERE ca.UserID = ?)"; $condArgs = array_merge($condArgs, [$UserID, $UserID, $UserID]); $TypeLinks = [ [$BaseLink, "$Username › Collage comments"], ["$BaseLink&type=created", "$Username › Comments on their collages"], ]; break; default: $Title = "%s › Collage comments"; $condition[] = "C.AuthorID = ?"; $condArgs[] = $UserID; $TypeLinks = [ ["$BaseLink&type=contributed", "$Username › Contributed collage comments"], ["$BaseLink&type=created", "$Username › Comments on their collages"], ]; break; } break; case 'requests': $table = 'requests AS r'; $idField = 'r.ID'; $nameField = 'r.Title'; switch($Type) { case 'created': $Title = "%s › Comments on their requests"; $condition[] = "r.UserID = ?"; $condition[] = "C.AuthorID != ?"; $condArgs[] = $UserID; $condArgs[] = $UserID; $TypeLinks = [ [$BaseLink, "$Username › Request comments"], ["$BaseLink&type=contributed", "$Username › Voted-on request comments"], ]; break; case 'voted': $Title = "%s › Comments on voted-on requests"; $Join[] = 'INNER JOIN requests_votes rv ON (rv.RequestID = r.ID)'; $condition[] = "rv.UserID = ?"; $condition[] = "C.AuthorID != ?"; $condArgs[] = $UserID; $condArgs[] = $UserID; $TypeLinks = [ [$BaseLink, "$Username › Request comments"], ["$BaseLink&type=created", "$Username › Created request comments"], ]; break; default: $Title = "%s › Request comments"; $condition[] = "C.AuthorID = ?"; $condArgs[] = $UserID; $TypeLinks = $ownProfile ? [ ["$BaseLink&type=created", "Comments on your created requests"], ["$BaseLink&type=contributed", "Your comments on requests"], ] : [ ["$BaseLink&type=created", "$Username › Created request comments"], ["$BaseLink&type=contributed", "$Username › Request comments"], ]; break; } break; case 'torrents': $table = 'torrents_group AS tg'; $idField = 'tg.ID'; $nameField = 'tg.Name'; switch($Type) { case 'uploaded': $Title = "%s › Comments on their uploads"; $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, $ownProfile ? "Your torrent comments" : "$Username › Torrent comments" ]; break; default: $Title = "%s › Torrent comments"; $condition[] = "C.AuthorID = ?"; $condArgs[] = $UserID; $TypeLinks[] = [ "$BaseLink&type=uploaded", $ownProfile ? "Comments on your uploads" : "$Username › Comments on their uploads" ]; break; } 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) : ''; // Posts per page limit stuff $paginator = new Gazelle\Util\Paginator($Viewer->postsPerPage(), (int)($_GET['page'] ?? 1)); $paginator->setTotal( $DB->scalar(" SELECT count(DISTINCT(C.ID)) FROM $table $Join $cond", ...array_merge($joinArgs, $condArgs) ) ); $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 GROUP BY C.ID ORDER BY C.ID DESC LIMIT ? OFFSET ? ", ...[...$joinArgs, ...$condArgs, $paginator->limit(), $paginator->offset()] ); $requestList = []; $tgroupList = []; if ($Action == 'requests') { $requestMan = new Gazelle\Manager\Request; foreach (array_flip(array_flip($DB->collect('PageID'))) as $id) { $requestList[$id] = $requestMan->findById($id); } } elseif ($Action == 'torrents') { $tgMan = new Gazelle\Manager\TGroup; foreach (array_flip(array_flip($DB->collect('PageID'))) as $id) { $tgroupList[$id] = $tgMan->findById($id); } } $Links = implode(' ', // show links to the other types of pages having comments array_map(fn ($a) => "" . ucfirst(rtrim($a, 's')) . ' comments', array_filter(['artist', 'collages', 'requests', 'torrents'], fn ($a) => $a != $Action) ) ); if ($TypeLinks) { // and any extra links for this page type $Links .= '
' . implode(' ', array_map( fn ($link) => sprintf('%s', $link[0], $link[1]), $TypeLinks )); } View::show_header(sprintf($Title, $Username), ['js' => 'bbcode,comments']); ?>

link()) ?>

total()) { ?>
No results.
linkbox(); $commentMan = new Gazelle\Manager\Comment; $DB->set_query_id($Comments); while ([$AuthorID, $Page, $PageID, $Name, $PostID, $Body, $AddedTime, $EditedTime, $EditedUserID] = $DB->next_record()) { $author = new Gazelle\User($AuthorID); echo $Twig->render('comment/comment.twig', [ 'added_time' => $AddedTime, 'author' => $author, 'avatar' => $userMan->avatarMarkup($Viewer, $author), 'body' => $Body, 'editor' => $userMan->findById((int)$EditedUserID), 'edit_time' => $EditedTime, 'id' => $PostID, 'heading' => match($Page) { 'artist' => "$Name", 'collages' => "$Name", 'requests' => $requestList[$PageID]->smartLink(), 'torrents' => $tgroupList[$PageID]->link(), }, 'page' => $Action, 'url' => $commentMan->findById($PostID)->url(), 'viewer' => $Viewer, ]); $DB->set_query_id($Comments); } echo $paginator->linkbox(); } ?>