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.

notifications.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. # todo: Go through line by line
  3. if (!check_perms('site_torrents_notify')) {
  4. json_die('failure');
  5. }
  6. define('NOTIFICATIONS_PER_PAGE', 50);
  7. list($Page, $Limit) = Format::page_limit(NOTIFICATIONS_PER_PAGE);
  8. $Results = $DB->query("
  9. SELECT
  10. SQL_CALC_FOUND_ROWS
  11. unt.TorrentID,
  12. unt.UnRead,
  13. unt.FilterID,
  14. unf.Label,
  15. t.GroupID
  16. FROM users_notify_torrents AS unt
  17. JOIN torrents AS t ON t.ID = unt.TorrentID
  18. LEFT JOIN users_notify_filters AS unf ON unf.ID = unt.FilterID
  19. WHERE unt.UserID = $LoggedUser[ID]".
  20. ((!empty($_GET['filterid']) && is_number($_GET['filterid']))
  21. ? " AND unf.ID = '$_GET[filterid]'"
  22. : '')."
  23. ORDER BY TorrentID DESC
  24. LIMIT $Limit");
  25. $GroupIDs = array_unique($DB->collect('GroupID'));
  26. $DB->query('SELECT FOUND_ROWS()');
  27. list($TorrentCount) = $DB->next_record();
  28. if (count($GroupIDs)) {
  29. $TorrentGroups = Torrents::get_groups($GroupIDs);
  30. $DB->query("
  31. UPDATE users_notify_torrents
  32. SET UnRead = '0'
  33. WHERE UserID = $LoggedUser[ID]");
  34. $Cache->delete_value("notifications_new_$LoggedUser[ID]");
  35. }
  36. $DB->set_query_id($Results);
  37. $JsonNotifications = [];
  38. $NumNew = 0;
  39. $FilterGroups = [];
  40. while ($Result = $DB->next_record(MYSQLI_ASSOC)) {
  41. if (!$Result['FilterID']) {
  42. $Result['FilterID'] = 0;
  43. }
  44. if (!isset($FilterGroups[$Result['FilterID']])) {
  45. $FilterGroups[$Result['FilterID']] = [];
  46. $FilterGroups[$Result['FilterID']]['FilterLabel'] = ($Result['Label'] ? $Result['Label'] : false);
  47. }
  48. array_push($FilterGroups[$Result['FilterID']], $Result);
  49. }
  50. unset($Result);
  51. foreach ($FilterGroups as $FilterID => $FilterResults) {
  52. unset($FilterResults['FilterLabel']);
  53. foreach ($FilterResults as $Result) {
  54. $TorrentID = $Result['TorrentID'];
  55. // $GroupID = $Result['GroupID'];
  56. $GroupInfo = $TorrentGroups[$Result['GroupID']];
  57. extract(Torrents::array_group($GroupInfo)); // all group data
  58. $TorrentInfo = $GroupInfo['Torrents'][$TorrentID];
  59. if ($Result['UnRead'] == 1) {
  60. $NumNew++;
  61. }
  62. $JsonNotifications[] = array(
  63. 'torrentId' => (int)$TorrentID,
  64. 'groupId' => (int)$GroupID,
  65. 'groupName' => $GroupName,
  66. 'groupCategoryId' => (int)$GroupCategoryID,
  67. 'wikiImage' => $WikiImage,
  68. 'torrentTags' => $TagList,
  69. 'size' => (float)$TorrentInfo['Size'],
  70. 'fileCount' => (int)$TorrentInfo['FileCount'],
  71. 'format' => $TorrentInfo['Format'],
  72. 'encoding' => $TorrentInfo['Encoding'],
  73. 'media' => $TorrentInfo['Media'],
  74. 'scene' => $TorrentInfo['Scene'] == 1,
  75. 'groupYear' => (int)$GroupYear,
  76. 'remasterYear' => (int)$TorrentInfo['RemasterYear'],
  77. 'remasterTitle' => $TorrentInfo['RemasterTitle'],
  78. 'snatched' => (int)$TorrentInfo['Snatched'],
  79. 'seeders' => (int)$TorrentInfo['Seeders'],
  80. 'leechers' => (int)$TorrentInfo['Leechers'],
  81. 'notificationTime' => $TorrentInfo['Time'],
  82. 'hasLog' => $TorrentInfo['HasLog'] == 1,
  83. 'hasCue' => $TorrentInfo['HasCue'] == 1,
  84. 'logScore' => (float)$TorrentInfo['LogScore'],
  85. 'freeTorrent' => $TorrentInfo['FreeTorrent'] == 1,
  86. 'logInDb' => $TorrentInfo['HasLog'] == 1,
  87. 'unread' => $Result['UnRead'] == 1
  88. );
  89. }
  90. }
  91. json_die('success', array(
  92. 'currentPages' => intval($Page),
  93. 'pages' => ceil($TorrentCount / NOTIFICATIONS_PER_PAGE),
  94. 'numNew' => $NumNew,
  95. 'results' => $JsonNotifications
  96. ));