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

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