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

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