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.

subscriptions.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. #declare(strict_types=1);
  3. /**
  4. * User subscription page
  5. */
  6. if (isset($LoggedUser['PostsPerPage'])) {
  7. $PerPage = $LoggedUser['PostsPerPage'];
  8. } else {
  9. $PerPage = POSTS_PER_PAGE;
  10. }
  11. list($Page, $Limit) = Format::page_limit($PerPage);
  12. View::show_header('Subscriptions', 'subscriptions');
  13. $ShowUnread = (!isset($_GET['showunread']) && !isset($HeavyInfo['SubscriptionsUnread']) || isset($HeavyInfo['SubscriptionsUnread']) && !!$HeavyInfo['SubscriptionsUnread'] || isset($_GET['showunread']) && !!$_GET['showunread']);
  14. $ShowCollapsed = (!isset($_GET['collapse']) && !isset($HeavyInfo['SubscriptionsCollapse']) || isset($HeavyInfo['SubscriptionsCollapse']) && !!$HeavyInfo['SubscriptionsCollapse'] || isset($_GET['collapse']) && !!$_GET['collapse']);
  15. // The monster sql query:
  16. /*
  17. * Fields:
  18. * Page (artist, collages, requests, torrents or forums)
  19. * PageID (ArtistID, CollageID, RequestID, GroupID, TopicID)
  20. * PostID (of the last read post)
  21. * ForumID
  22. * ForumName
  23. * Name (for artists and collages; carries the topic title for forum subscriptions)
  24. * LastPost (PostID of the last post)
  25. * LastPostTime
  26. * LastReadBody
  27. * LastReadEditedTime
  28. * LastReadUserID
  29. * LastReadUsername
  30. * LastReadAvatar
  31. * LastReadEditedUserID
  32. */
  33. $DB->prepared_query("
  34. (SELECT
  35. SQL_CALC_FOUND_ROWS
  36. s.`Page`,
  37. s.`PageID`,
  38. lr.`PostID`,
  39. null AS ForumID,
  40. null AS ForumName,
  41. IF(s.`Page` = 'artist', a.`Name`, co.`Name`) AS Name,
  42. c.`ID` AS LastPost,
  43. c.`AddedTime` AS LastPostTime,
  44. c_lr.`Body` AS LastReadBody,
  45. c_lr.`EditedTime` AS LastReadEditedTime,
  46. um.`ID` AS LastReadUserID,
  47. um.`Username` AS LastReadUsername,
  48. ui.`Avatar` AS LastReadAvatar,
  49. c_lr.`EditedUserID` AS LastReadEditedUserID
  50. FROM `users_subscriptions_comments` AS s
  51. LEFT JOIN `users_comments_last_read` AS lr ON lr.`UserID` = $LoggedUser[ID] AND lr.`Page` = s.`Page` AND lr.`PageID` = s.`PageID`
  52. LEFT JOIN `artists_group` AS a ON s.`Page` = 'artist' AND a.`ArtistID` = s.`PageID`
  53. LEFT JOIN `collages` AS co ON s.`Page` = 'collages' AND co.`ID` = s.`PageID`
  54. LEFT JOIN `comments` AS c ON c.`ID` = (
  55. SELECT MAX(`ID`)
  56. FROM `comments`
  57. WHERE `Page` = s.`Page`
  58. AND `PageID` = s.`PageID`
  59. )
  60. LEFT JOIN `comments` AS c_lr ON c_lr.`ID` = lr.`PostID`
  61. LEFT JOIN `users_main` AS um ON um.`ID` = c_lr.`AuthorID`
  62. LEFT JOIN `users_info` AS ui ON ui.`UserID` = um.`ID`
  63. WHERE s.`UserID` = $LoggedUser[ID] AND s.`Page` IN ('artist', 'collages', 'requests', 'torrents') AND (s.`Page` != 'collages' OR co.`Deleted` = '0')" . ($ShowUnread ? ' AND c.`ID` > IF(lr.`PostID` IS NULL, 0, lr.`PostID`)' : '') . "
  64. GROUP BY s.`PageID`)
  65. UNION ALL
  66. (SELECT 'forums', s.`TopicID`, lr.`PostID`, f.`ID`, f.`Name`, t.`Title`, p.`ID`, p.`AddedTime`, p_lr.`Body`, p_lr.`EditedTime`, um.`ID`, um.`Username`, ui.`Avatar`, p_lr.`EditedUserID`
  67. FROM `users_subscriptions` AS s
  68. LEFT JOIN `forums_last_read_topics` AS lr ON lr.`UserID` = $LoggedUser[ID] AND s.`TopicID` = lr.`TopicID`
  69. LEFT JOIN `forums_topics` AS t ON t.`ID` = s.`TopicID`
  70. LEFT JOIN `forums` AS f ON f.`ID` = t.`ForumID`
  71. LEFT JOIN `forums_posts` AS p ON p.`ID` = (
  72. SELECT MAX(`ID`)
  73. FROM `forums_posts`
  74. WHERE `TopicID` = s.`TopicID`
  75. )
  76. LEFT JOIN `forums_posts` AS p_lr ON p_lr.`ID` = lr.`PostID`
  77. LEFT JOIN `users_main` AS um ON um.`ID` = p_lr.`AuthorID`
  78. LEFT JOIN `users_info` AS ui ON ui.`UserID` = um.`ID`
  79. WHERE s.`UserID` = $LoggedUser[ID]" .
  80. ($ShowUnread ? " AND p.`ID` > IF(t.`IsLocked` = '1' AND t.`IsSticky` = '0'" . ", p.`ID`, IF(lr.`PostID` IS NULL, 0, lr.`PostID`))" : '') .
  81. ' AND ' . Forums::user_forums_sql() . "
  82. GROUP BY t.`ID`)
  83. ORDER BY `LastPostTime` DESC
  84. LIMIT $Limit");
  85. $Results = $DB->to_array(false, MYSQLI_ASSOC, false);
  86. $DB->prepared_query('SELECT FOUND_ROWS()');
  87. list($NumResults) = $DB->next_record();
  88. $Debug->log_var($Results, 'Results');
  89. $TorrentGroups = $Requests = [];
  90. foreach ($Results as $Result) {
  91. if ($Result['Page'] === 'torrents') {
  92. $TorrentGroups[] = $Result['PageID'];
  93. } elseif ($Result['Page'] === 'requests') {
  94. $Requests[] = $Result['PageID'];
  95. }
  96. }
  97. $TorrentGroups = Torrents::get_groups($TorrentGroups, true, true, false);
  98. $Requests = Requests::get_requests($Requests);
  99. ?>
  100. <div>
  101. <div class="header">
  102. <h2>Subscriptions<?=$ShowUnread ? ' with unread posts' . ($NumResults ? ' (' . $NumResults . ' new)' : '') : ''?>
  103. </h2>
  104. <div class="linkbox">
  105. <?php
  106. if (!$ShowUnread) {
  107. ?>
  108. <br /><br />
  109. <a href="userhistory.php?action=subscriptions&amp;showunread=1" class="brackets">Only display subscriptions with
  110. unread replies</a>&nbsp;&nbsp;&nbsp;
  111. <?php
  112. } else {
  113. ?>
  114. <br /><br />
  115. <a href="userhistory.php?action=subscriptions&amp;showunread=0" class="brackets">Show all
  116. subscriptions</a>&nbsp;&nbsp;&nbsp;
  117. <?php
  118. }
  119. if ($NumResults) {
  120. ?>
  121. <a href="#" onclick="Collapse(); return false;" id="collapselink" class="brackets"><?=$ShowCollapsed ? 'Show' : 'Hide' ?>
  122. post bodies</a>&nbsp;&nbsp;&nbsp;
  123. <?php
  124. }
  125. ?>
  126. <a href="userhistory.php?action=catchup&amp;auth=<?=$LoggedUser['AuthKey']?>"
  127. class="brackets">Catch up</a>&nbsp;&nbsp;&nbsp;
  128. <a href="userhistory.php?action=posts&amp;userid=<?=$LoggedUser['ID']?>"
  129. class="brackets">Go to post history</a>&nbsp;&nbsp;&nbsp;
  130. <a href="userhistory.php?action=quote_notifications" class="brackets">Quote notifications</a>&nbsp;&nbsp;&nbsp;
  131. </div>
  132. </div>
  133. <?php
  134. if (!$NumResults) {
  135. ?>
  136. <div class="center">
  137. No subscriptions<?=$ShowUnread ? ' with unread posts' : ''?>
  138. </div>
  139. <?php
  140. } else {
  141. ?>
  142. <div class="linkbox">
  143. <?php
  144. $Pages = Format::get_pages($Page, $NumResults, $PerPage, 11);
  145. echo $Pages; ?>
  146. </div>
  147. <?php
  148. foreach ($Results as $Result) {
  149. switch ($Result['Page']) {
  150. case 'artist':
  151. $Links = 'Artist: <a href="artist.php?id=' . $Result['PageID'] . '">' . display_str($Result['Name']) . '</a>';
  152. $JumpLink = 'artist.php?id=' . $Result['PageID'] . '&amp;postid=' . $Result['PostID'] . '#post' . $Result['PostID'];
  153. break;
  154. case 'collages':
  155. $Links = 'Collage: <a href="collages.php?id=' . $Result['PageID'] . '">' . display_str($Result['Name']) . '</a>';
  156. $JumpLink = 'collages.php?action=comments&collageid=' . $Result['PageID'] . '&amp;postid=' . $Result['PostID'] . '#post' . $Result['PostID'];
  157. break;
  158. case 'requests':
  159. if (!isset($Requests[$Result['PageID']])) {
  160. continue;
  161. }
  162. $Request = $Requests[$Result['PageID']];
  163. $CategoryName = $Categories[$CategoryID - 1];
  164. $Links = 'Request: ';
  165. $Links .= '<a href="requests.php?action=view&amp;id=' . $Result['PageID'] . '">' . $Request['Title'] . "</a>";
  166. $JumpLink = 'requests.php?action=view&amp;id=' . $Result['PageID'] . '&amp;postid=' . $Result['PostID'] . '#post' . $Result['PostID'];
  167. break;
  168. case 'torrents':
  169. if (!isset($TorrentGroups[$Result['PageID']])) {
  170. continue;
  171. }
  172. $GroupInfo = $TorrentGroups[$Result['PageID']];
  173. $Links = 'Torrent: ' . Artists::display_artists($GroupInfo['ExtendedArtists']) . '<a href="torrents.php?id=' . $GroupInfo['id'] . '" dir="ltr">' . $GroupInfo['title'] . '</a>';
  174. if ($GroupInfo['year'] > 0) {
  175. $Links .= " [" . $GroupInfo['year'] . "]";
  176. }
  177. $JumpLink = 'torrents.php?id=' . $GroupInfo['ID'] . '&amp;postid=' . $Result['PostID'] . '#post' . $Result['PostID'];
  178. break;
  179. case 'forums':
  180. $Links = 'Forums: <a href="forums.php?action=viewforum&amp;forumid=' . $Result['ForumID'] . '">' . display_str($Result['ForumName']) . '</a> &gt; ' .
  181. '<a href="forums.php?action=viewthread&amp;threadid=' . $Result['PageID'] .
  182. '" class="tooltip" title="' . display_str($Result['Name']) . '">' .
  183. display_str(Format::cut_string($Result['Name'], 75)) .
  184. '</a>';
  185. $JumpLink = 'forums.php?action=viewthread&amp;threadid=' . $Result['PageID'] . '&amp;postid=' . $Result['PostID'] . '#post' . $Result['PostID'];
  186. break;
  187. default:
  188. error(0);
  189. } ?>
  190. <table
  191. class="forum_post box vertical_margin<?=(!Users::has_avatars_enabled() ? ' noavatar' : '')?>">
  192. <colgroup>
  193. <?php if (Users::has_avatars_enabled()) { ?>
  194. <col class="col_avatar" />
  195. <?php } ?>
  196. <col class="col_post_body" />
  197. </colgroup>
  198. <tr
  199. class="colhead_dark notify_<?=$Result['Page']?>">
  200. <td colspan="<?=Users::has_avatars_enabled() ? 2 : 1 ?>">
  201. <span class="float_left">
  202. <?=$Links . ($Result['PostID'] < $Result['LastPost'] ? ' <span class="new">(New!)</span>' : '')?>
  203. </span>
  204. <a class="tooltip last_read" title="Jump to last read"
  205. href="<?=$JumpLink?>">
  206. &rarr;
  207. <!--
  208. <svg width="15" height="11">
  209. <polygon points="0,3 0,8 8,8 8,11 15,5.5 8,0 8,3" /></svg>
  210. -->
  211. </a>
  212. <?php if ($Result['Page'] === 'forums') { ?>
  213. <span id="bar<?=$Result['PostID'] ?>"
  214. class="float_right">
  215. <a href="#"
  216. onclick="Subscribe(<?=$Result['PageID']?>); return false;"
  217. id="subscribelink<?=$Result['PageID']?>"
  218. class="brackets">Unsubscribe</a>
  219. <?php } else { ?>
  220. <span
  221. id="bar_<?=$Result['Page'] . $Result['PostID'] ?>"
  222. class="float_right">
  223. <a href="#"
  224. onclick="SubscribeComments('<?=$Result['Page']?>', <?=$Result['PageID']?>); return false;"
  225. id="subscribelink_<?=$Result['Page'] . $Result['PageID']?>"
  226. class="brackets">Unsubscribe</a>
  227. <?php } ?>
  228. &nbsp;
  229. <a href="#">&uarr;</a>
  230. </span>
  231. </td>
  232. </tr>
  233. <?php if (!empty($Result['LastReadBody'])) { // if a user is subscribed to a topic/comments but hasn't accessed the site ever, LastReadBody will be null - in this case we don't display a post.?>
  234. <tr
  235. class="row<?=$ShowCollapsed ? ' hidden' : '' ?>">
  236. <?php if (Users::has_avatars_enabled()) { ?>
  237. <td class="avatar" valign="top">
  238. <?=Users::show_avatar($Result['LastReadAvatar'], $Result['LastReadUserID'], $Result['LastReadUsername'], $HeavyInfo['DisableAvatars'])?>
  239. </td>
  240. <?php } ?>
  241. <td class="body" valign="top">
  242. <div class="content3">
  243. <?=Text::full_format($Result['LastReadBody']) ?>
  244. <?php if ($Result['LastReadEditedUserID']) { ?>
  245. <br /><br />
  246. Last edited by <?=Users::format_username($Result['LastReadEditedUserID'], false, false, false) ?>
  247. <?=time_diff($Result['LastReadEditedTime'])?>
  248. <?php } ?>
  249. </div>
  250. </td>
  251. </tr>
  252. <?php } ?>
  253. </table>
  254. <?php
  255. } ?>
  256. <div class="linkbox">
  257. <?=$Pages?>
  258. </div>
  259. <?php
  260. }?>
  261. </div>
  262. <?php View::show_footer();