BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

comments.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <?
  2. declare(strict_types=1);
  3. /**
  4. * $_REQUEST['action'] is artist, collages, requests or torrents (default torrents)
  5. * $_REQUEST['type'] depends on the page:
  6. * collages:
  7. * created = comments left on one's collages
  8. * contributed = comments left on collages one contributed to
  9. * requests:
  10. * created = comments left on one's requests
  11. * voted = comments left on requests one voted on
  12. * torrents:
  13. * uploaded = comments left on one's uploads
  14. * If missing or invalid, this defaults to the comments one made
  15. */
  16. // User ID
  17. if (isset($_GET['id']) && is_number($_GET['id'])) {
  18. $UserID = (int)$_GET['id'];
  19. $UserInfo = Users::user_info($UserID);
  20. $Username = $UserInfo['Username'];
  21. if ($LoggedUser['ID'] === $UserID) {
  22. $Self = true;
  23. } else {
  24. $Self = false;
  25. }
  26. $Perms = Permissions::get_permissions($UserInfo['PermissionID']);
  27. $UserClass = $Perms['Class'];
  28. if (!check_paranoia('torrentcomments', $UserInfo['Paranoia'], $UserClass, $UserID)) {
  29. error(403);
  30. }
  31. } else {
  32. $UserID = $LoggedUser['ID'];
  33. $Username = $LoggedUser['Username'];
  34. $Self = true;
  35. }
  36. // Posts per page limit stuff
  37. if (isset($LoggedUser['PostsPerPage'])) {
  38. $PerPage = $LoggedUser['PostsPerPage'];
  39. } else {
  40. $PerPage = POSTS_PER_PAGE;
  41. }
  42. list($Page, $Limit) = Format::page_limit($PerPage);
  43. if (!isset($_REQUEST['action'])) {
  44. $Action = 'torrents';
  45. } else {
  46. $Action = $_REQUEST['action'];
  47. }
  48. if (!isset($_REQUEST['type'])) {
  49. $Type = 'default';
  50. } else {
  51. $Type = $_REQUEST['type'];
  52. }
  53. // Construct the SQL query
  54. $Conditions = $Join = [];
  55. switch ($Action) {
  56. # artist comments
  57. case 'artist':
  58. $Field1 = '`artists_group`.`ArtistID`';
  59. $Field2 = '`artists_group`.`Name`';
  60. $Table = '`artists_group`';
  61. $Title = 'Artist comments left by ' . ($Self ? 'you' : $Username);
  62. $Header = 'Artist comments left by ' . ($Self ? 'you' : Users::format_username($UserID, false, false, false));
  63. $Conditions[] = "`comments`.`AuthorID` = $UserID";
  64. break;
  65. # collage comments
  66. case 'collages':
  67. $Field1 = '`collages`.`ID`';
  68. $Field2 = '`collages`.`Name`';
  69. $Table = '`collages`';
  70. $Conditions[] = "`collages`.`Deleted` = '0'";
  71. if ($Type == 'created') {
  72. $Conditions[] = "`collages`.`UserID` = $UserID";
  73. $Conditions[] = "`comments`.`AuthorID` != $UserID";
  74. $Title = 'Comments left on collages ' . ($Self ? 'you' : $Username) . ' created';
  75. $Header = 'Comments left on collages ' . ($Self ? 'you' : Users::format_username($UserID, false, false, false)) . ' created';
  76. } elseif ($Type == 'contributed') {
  77. $Conditions[] = 'IF(`collages`.`CategoryID` = ' . array_search('Artists', $CollageCats) . ', `collages_artists`.`ArtistID`, `collages_torrents`.`GroupID`) IS NOT NULL';
  78. $Conditions[] = "`comments`.`AuthorID` != $UserID";
  79. $Join[] = "LEFT JOIN `collages_torrents` ON `collages_torrents`.`CollageID` = `collages`.`ID` AND `collages_torrents`.`UserID` = $UserID";
  80. $Join[] = "LEFT JOIN `collages_artists` ON `collages_artists`.`CollageID` = `collages`.`ID` AND `collages_artists`.`UserID` = $UserID";
  81. $Title = 'Comments left on collages ' . ($Self ? 'you\'ve' : $Username . ' has') . ' contributed to';
  82. $Header = 'Comments left on collages ' . ($Self ? 'you\'ve' : Users::format_username($UserID, false, false, false).' has') . ' contributed to';
  83. } else {
  84. $Type = 'default';
  85. $Conditions[] = "`comments`.`AuthorID` = $UserID";
  86. $Title = 'Collage comments left by ' . ($Self ? 'you' : $Username);
  87. $Header = 'Collage comments left by ' . ($Self ? 'you' : Users::format_username($UserID, false, false, false));
  88. }
  89. break;
  90. # request comments
  91. case 'requests':
  92. $Field1 = '`requests`.`ID`';
  93. $Field2 = '`requests`.`Title`';
  94. $Table = 'requests';
  95. if ($Type == 'created') {
  96. $Conditions[] = "`requests`.`UserID` = $UserID";
  97. $Conditions[] = "`comments`.`AuthorID` != $UserID";
  98. $Title = 'Comments left on requests ' . ($Self ? 'you' : $Username) . ' created';
  99. $Header = 'Comments left on requests ' . ($Self ? 'you' : Users::format_username($UserID, false, false, false)) . ' created';
  100. } elseif ($Type == 'voted') {
  101. $Conditions[] = "`requests_votes`.`UserID` = $UserID";
  102. $Conditions[] = "`comments`.`AuthorID` != $UserID";
  103. $Join[] = 'JOIN `requests_votes` ON `requests_votes`.`RequestID` = `requests`.`ID`';
  104. $Title = 'Comments left on requests ' . ($Self ? 'you\'ve' : $Username . ' has') . ' voted on';
  105. $Header = 'Comments left on requests ' . ($Self ? 'you\'ve' : Users::format_username($UserID, false, false, false) . ' has') . ' voted on';
  106. } else {
  107. $Type = 'default';
  108. $Conditions[] = "`comments`.`AuthorID` = $UserID";
  109. $Title = 'Request comments left by ' . ($Self ? 'you' : $Username);
  110. $Header = 'Request comments left by ' . ($Self ? 'you' : Users::format_username($UserID, false, false, false));
  111. }
  112. break;
  113. # torrent comments
  114. case 'torrents':
  115. default:
  116. $Action = 'torrents';
  117. $Field1 = '`torrents`.`GroupID`';
  118. $Field2 = "COALESCE(NULLIF(tg.`title`,''),NULLIF(tg.`subject`,''),tg.`object`) AS Name";
  119. $Table = '`torrents`';
  120. $Join[] = 'JOIN `torrents_group` AS tg ON `torrents`.`GroupID` = tg.`id`';
  121. if ($Type == 'uploaded') {
  122. $Conditions[] = "`torrents`.`UserID` = $UserID";
  123. $Conditions[] = '`comments`.`AddedTime` > `torrents`.`Time`';
  124. $Conditions[] = "`comments`.`AuthorID` != $UserID";
  125. $Title = 'Comments left on torrents ' . ($Self ? 'you\'ve' : $Username . ' has') . ' uploaded';
  126. $Header = 'Comments left on torrents ' . ($Self ? 'you\'ve' : Users::format_username($UserID, false, false, false) . ' has') . ' uploaded';
  127. } else {
  128. $Type = 'default';
  129. $Conditions[] = "`comments`.`AuthorID` = $UserID";
  130. $Title = 'Torrent comments left by ' . ($Self ? 'you' : $Username);
  131. $Header = 'Torrent comments left by ' . ($Self ? 'you' : Users::format_username($UserID, false, false, false));
  132. }
  133. break;
  134. }
  135. # end SQL query constructor
  136. $Join[] = "JOIN `comments` ON `comments`.`Page` = '$Action' AND `comments`.`PageID` = $Field1";
  137. $Join = implode("\n\t\t", $Join);
  138. $Conditions = implode(" AND ", $Conditions);
  139. $Conditions = ($Conditions ? 'WHERE ' . $Conditions : '');
  140. $SQL = "
  141. SELECT
  142. SQL_CALC_FOUND_ROWS
  143. `comments`.`AuthorID`,
  144. `comments`.`Page`,
  145. `comments`.`PageID`,
  146. $Field2,
  147. `comments`.`ID`,
  148. `comments`.`Body`,
  149. `comments`.`AddedTime`,
  150. `comments`.`EditedTime`,
  151. `comments`.`EditedUserID`
  152. FROM $Table
  153. $Join
  154. $Conditions
  155. GROUP BY `comments`.`ID`
  156. ORDER BY `comments`.`ID` DESC
  157. LIMIT $Limit";
  158. $Comments = $DB->query($SQL);
  159. $Count = $DB->record_count();
  160. $DB->query("SELECT FOUND_ROWS()");
  161. list($Results) = $DB->next_record();
  162. $Pages = Format::get_pages($Page, $Results, $PerPage, 11);
  163. $DB->set_query_id($Comments);
  164. # Remove the weird comment headings on torrent and request comments
  165. /*
  166. if ($Action === 'requests') {
  167. $RequestIDs = array_flip(array_flip($DB->collect('PageID')));
  168. $Artists = [];
  169. foreach ($RequestIDs as $RequestID) {
  170. $Artists[$RequestID] = Requests::get_artists($RequestID);
  171. }
  172. $DB->set_query_id($Comments);
  173. } elseif ($Action === 'torrents') {
  174. $GroupIDs = array_flip(array_flip($DB->collect('PageID')));
  175. $Artists = Artists::get_artists($GroupIDs);
  176. $DB->set_query_id($Comments);
  177. }
  178. */
  179. # Replace the "shifting" main links with regular static ones
  180. # There are already shifting supplemental links for each type
  181. $ActionLinks[] = '<a href="comments.php?action=torrents' . $LinkID . '" class="brackets">Torrent comments</a>';
  182. $ActionLinks[] = '<a href="comments.php?action=collages' . $LinkID . '" class="brackets">Collections comments</a>';
  183. $ActionLinks[] = '<a href="comments.php?action=requests' . $LinkID . '" class="brackets">Request comments</a>';
  184. $ActionLinks[] = '<a href="comments.php?action=artist' . $LinkID . '" class="brackets">Artist comments</a>';
  185. /*
  186. $LinkID = (!$Self ? '&amp;id=' . $UserID : '');
  187. $ActionLinks = $TypeLinks = [];
  188. if ($Action !== 'artist') {
  189. $ActionLinks[] = '<a href="comments.php?action=artist' . $LinkID . '" class="brackets">Artist comments</a>';
  190. }
  191. if ($Action !== 'collages') {
  192. $ActionLinks[] = '<a href="comments.php?action=collages' . $LinkID . '" class="brackets">Collections comments</a>';
  193. }
  194. if ($Action !== 'requests') {
  195. $ActionLinks[] = '<a href="comments.php?action=requests' . $LinkID . '" class="brackets">Request comments</a>';
  196. }
  197. if ($Action !== 'torrents') {
  198. $ActionLinks[] = '<a href="comments.php?action=torrents' . $LinkID . '" class="brackets">Torrent comments</a>';
  199. }
  200. */
  201. switch ($Action) {
  202. case 'collages':
  203. $BaseLink = 'comments.php?action=collages' . $LinkID;
  204. if ($Type !== 'default') {
  205. $TypeLinks[] = '<a href="' . $BaseLink . '" class="brackets">Display collage comments ' . ($Self ? 'you\'ve' : $Username . ' has') . ' made</a>';
  206. }
  207. if ($Type !== 'created') {
  208. $TypeLinks[] = '<a href="' . $BaseLink . '&amp;type=created" class="brackets">Display comments left on ' . ($Self ? 'your collections' : 'collections created by ' .$Username) . '</a>';
  209. }
  210. if ($Type !== 'contributed') {
  211. $TypeLinks[] = '<a href="' . $BaseLink . '&amp;type=contributed" class="brackets">Display comments left on collections ' . ($Self ? 'you\'ve' : $Username . ' has') . ' contributed to</a>';
  212. }
  213. break;
  214. case 'requests':
  215. $BaseLink = 'comments.php?action=requests' . $LinkID;
  216. if ($Type !== 'default') {
  217. $TypeLinks[] = '<a href="' . $BaseLink . '" class="brackets">Display request comments you\'ve made</a>';
  218. }
  219. if ($Type !== 'created') {
  220. $TypeLinks[] = '<a href="' . $BaseLink . '&amp;type=created" class="brackets">Display comments left on your requests</a>';
  221. }
  222. if ($Type !== 'voted') {
  223. $TypeLinks[] = '<a href="' . $BaseLink . '&amp;type=voted" class="brackets">Display comments left on requests you\'ve voted on</a>';
  224. }
  225. break;
  226. case 'torrents':
  227. if ($Type !== 'default') {
  228. $TypeLinks[] = '<a href="comments.php?action=torrents' . $LinkID . '" class="brackets">Display comments you have made</a>';
  229. }
  230. if ($Type !== 'uploaded') {
  231. $TypeLinks[] = '<a href="comments.php?action=torrents' . $LinkID . '&amp;type=uploaded" class="brackets">Display comments left on your uploads</a>';
  232. }
  233. break;
  234. }
  235. $Links = implode(' ', $ActionLinks) . (count($TypeLinks) ? '<br />' . implode(' ', $TypeLinks) : '');
  236. View::show_header($Title, 'bbcode,comments');
  237. ?><div>
  238. <div class="header">
  239. <h2><?=$Header?></h2>
  240. <? if ($Links !== '') { ?>
  241. <div class="linkbox">
  242. <?=$Links?>
  243. </div>
  244. <? } ?>
  245. </div>
  246. <div class="linkbox">
  247. <?=$Pages?>
  248. </div>
  249. <?
  250. if ($Count > 0) {
  251. $DB->set_query_id($Comments);
  252. while (list($AuthorID, $Page, $PageID, $Name, $PostID, $Body, $AddedTime, $EditedTime, $EditedUserID) = $DB->next_record()) {
  253. $Link = Comments::get_url($Page, $PageID, $PostID);
  254. switch ($Page) {
  255. case 'artist':
  256. $Header = " on <a href=\"artist.php?id=$PageID\">$Name</a>";
  257. break;
  258. case 'collages':
  259. $Header = " on <a href=\"collages.php?id=$PageID\">$Name</a>";
  260. break;
  261. case 'requests':
  262. $Header = ' on ' . Artists::display_artists($Artists[$PageID]) . " <a href=\"requests.php?action=view&id=$PageID\">$Name</a>";
  263. break;
  264. case 'torrents':
  265. $Header = ' on ' . Artists::display_artists($Artists[$PageID]) . " <a href=\"torrents.php?id=$PageID\">$Name</a>";
  266. break;
  267. }
  268. CommentsView::render_comment($AuthorID, $PostID, $Body, $AddedTime, $EditedUserID, $EditedTime, $Link, false, $Header, false);
  269. }
  270. } else { ?>
  271. <h2 class="center">No results.</h2>
  272. <? } ?>
  273. <div class="linkbox">
  274. <?=$Pages?>
  275. </div>
  276. </div>
  277. <? View::show_footer();