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.

add.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. declare(strict_types = 1);
  3. authorize();
  4. if (!Bookmarks::can_bookmark($_GET['type'])) {
  5. error(404);
  6. }
  7. include SERVER_ROOT.'/classes/feed.class.php'; // RSS feeds
  8. $Feed = new Feed;
  9. $Type = $_GET['type'];
  10. list($Table, $Col) = Bookmarks::bookmark_schema($Type);
  11. if (!is_number($_GET['id'])) {
  12. error(0);
  13. }
  14. $PageID = $_GET['id'];
  15. $DB->query("
  16. SELECT
  17. `UserID`
  18. FROM
  19. $Table
  20. WHERE
  21. `UserID` = '$LoggedUser[ID]' AND $Col = $PageID
  22. ");
  23. if (!$DB->has_results()) {
  24. if ($Type === 'torrent') {
  25. $DB->query("
  26. SELECT
  27. MAX(`Sort`)
  28. FROM
  29. `bookmarks_torrents`
  30. WHERE
  31. `UserID` = $LoggedUser[ID]
  32. ");
  33. list($Sort) = $DB->next_record();
  34. if (!$Sort) {
  35. $Sort = 0;
  36. }
  37. $Sort += 1;
  38. $DB->query("
  39. INSERT IGNORE
  40. INTO $Table(`UserID`, $Col, `Time`, `Sort`)
  41. VALUES(
  42. '$LoggedUser[ID]',
  43. $PageID,
  44. NOW(),
  45. $Sort
  46. )
  47. ");
  48. } else {
  49. $DB->query("
  50. INSERT IGNORE
  51. INTO $Table(`UserID`, $Col, `Time`)
  52. VALUES(
  53. '$LoggedUser[ID]',
  54. $PageID,
  55. NOW()
  56. )
  57. ");
  58. }
  59. $Cache->delete_value('bookmarks_'.$Type.'_'.$LoggedUser['ID']);
  60. if ($Type === 'torrent') {
  61. $Cache->delete_value("bookmarks_group_ids_$UserID");
  62. $DB->query("
  63. SELECT
  64. `title`,
  65. `year`,
  66. `description`,
  67. `tag_list`
  68. FROM
  69. `torrents_group`
  70. WHERE
  71. `id` = $PageID
  72. ");
  73. list($GroupTitle, $Year, $Body, $TagList) = $DB->next_record();
  74. $TagList = str_replace('_', '.', $TagList);
  75. $DB->prepare_query("
  76. SELECT
  77. `ID`,
  78. `Media`,
  79. `FreeTorrent`,
  80. `UserID`,
  81. `Anonymous`
  82. FROM
  83. `torrents`
  84. WHERE
  85. `GroupID` = '$PageID'
  86. ");
  87. $DB->exec_prepared_query();
  88. // RSS feed stuff
  89. while ($Torrent = $DB->next_record()) {
  90. $Title = $GroupTitle;
  91. list($TorrentID, $Media, $Freeleech, $UploaderID, $Anonymous) = $Torrent;
  92. $UploaderInfo = Users::user_info($UploaderID);
  93. $Item = $Feed->item(
  94. $Title,
  95. Text::strip_bbcode($Body),
  96. 'torrents.php?action=download&amp;authkey=[[AUTHKEY]]&amp;torrent_pass=[[PASSKEY]]&amp;id='.$TorrentID,
  97. ($Anonymous === 0 ? $UploaderInfo['Username'] : 'Anonymous'),
  98. "torrents.php?id=$PageID",
  99. trim($TagList)
  100. );
  101. $Feed->populate('torrents_bookmarks_t_'.$LoggedUser['torrent_pass'], $Item);
  102. }
  103. } elseif ($Type === 'request') {
  104. $DB->query("
  105. SELECT
  106. `UserID`
  107. FROM
  108. $Table
  109. WHERE
  110. $Col = '".db_string($PageID)."'
  111. ");
  112. if ($DB->record_count() < 100) {
  113. // Sphinx doesn't like huge MVA updates. Update sphinx_requests_delta
  114. // and live with the <= 1 minute delay if we have more than 100 bookmarkers
  115. $Bookmarkers = implode(',', $DB->collect('UserID'));
  116. $SphQL = new SphinxqlQuery();
  117. $SphQL->raw_query("
  118. UPDATE
  119. `requests`,
  120. `requests_delta`
  121. SET
  122. `bookmarker` = ($Bookmarkers)
  123. WHERE
  124. `id` = $PageID
  125. ");
  126. } else {
  127. Requests::update_sphinx_requests($PageID);
  128. }
  129. }
  130. }