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.

index.php 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. declare(strict_types = 1);
  3. // Main feeds page
  4. //
  5. // The feeds don't use script_start.php, their code resides entirely in feeds.php in the document root.
  6. // Bear this in mind when you try to use script_start functions.
  7. if (
  8. empty($_GET['feed'])
  9. || empty($_GET['authkey'])
  10. || empty($_GET['auth'])
  11. || empty($_GET['passkey'])
  12. || empty($_GET['user'])
  13. || !is_number($_GET['user'])
  14. || strlen($_GET['authkey']) !== 32
  15. || strlen($_GET['passkey']) !== 32
  16. || strlen($_GET['auth']) !== 32
  17. ) {
  18. $Feed->open_feed();
  19. $Feed->channel('Blocked', 'RSS feed.');
  20. $Feed->close_feed();
  21. error(400, $NoHTML = true);
  22. }
  23. # Initialize
  24. require_once 'classes/env.class.php';
  25. $ENV = ENV::go();
  26. $User = (int) $_GET['user'];
  27. if (!$Enabled = $Cache->get_value("enabled_$User")) {
  28. require_once SERVER_ROOT.'/classes/mysql.class.php';
  29. $DB = new DB_MYSQL; // Load the database wrapper
  30. $DB->query("
  31. SELECT
  32. `Enabled`
  33. FROM
  34. `users_main`
  35. WHERE
  36. `ID` = '$User'
  37. ");
  38. list($Enabled) = $DB->next_record();
  39. $Cache->cache_value("enabled_$User", $Enabled, 0);
  40. }
  41. # Check for RSS auth
  42. if (md5($User.$ENV->getPriv('RSS_HASH').$_GET['passkey']) !== $_GET['auth'] || (int) $Enabled !== 1) {
  43. $Feed->open_feed();
  44. $Feed->channel('Blocked', 'RSS feed.');
  45. $Feed->close_feed();
  46. error(400, $NoHTML = true);
  47. }
  48. # Start RSS stream
  49. require_once SERVER_ROOT.'/classes/text.class.php';
  50. $Feed->open_feed();
  51. /**
  52. * Torrent feeds
  53. * These depend on the correct cache key being set on upload_handle.php
  54. */
  55. /*
  56. $TorrentFeeds =
  57. array_map(
  58. 'strtolower',
  59. array_column(
  60. $ENV->toArray($ENV->CATS),
  61. 'Name'
  62. )
  63. );
  64. $Request = display_str($_GET['feed']);
  65. $Channel = array_search($Request, $TorrentFeeds);
  66. if ($Channel) {
  67. $Feed->retrieve($Request, $_GET['authkey'], $_GET['passkey']);
  68. }
  69. */
  70. switch ($_GET['feed']) {
  71. /**
  72. * News
  73. */
  74. case 'feed_news':
  75. $Feed->channel('News', 'RSS feed for site news.');
  76. if (!$News = $Cache->get_value('news')) {
  77. require_once SERVER_ROOT.'/classes/mysql.class.php'; // Require the database wrapper
  78. $DB = new DB_MYSQL; // Load the database wrapper
  79. $DB->query("
  80. SELECT
  81. `ID`,
  82. `Title`,
  83. `Body`,
  84. `Time`
  85. FROM
  86. `news`
  87. ORDER BY
  88. `Time`
  89. DESC
  90. LIMIT 10
  91. ");
  92. $News = $DB->to_array(false, MYSQLI_NUM, false);
  93. $Cache->cache_value('news', $News, 1209600);
  94. }
  95. $Count = 0;
  96. foreach ($News as $NewsItem) {
  97. list($NewsID, $Title, $Body, $NewsTime) = $NewsItem;
  98. if (strtotime($NewsTime) >= time()) {
  99. continue;
  100. }
  101. echo $Feed->item(
  102. $Title,
  103. Text::strip_bbcode($Body),
  104. "index.php#news$NewsID",
  105. "$ENV->SITE_NAME Staff",
  106. '',
  107. '',
  108. $NewsTime
  109. );
  110. if (++$Count > 4) {
  111. break;
  112. }
  113. }
  114. break;
  115. /**
  116. * Blog
  117. */
  118. case 'feed_blog':
  119. $Feed->channel('Blog', 'RSS feed for site blog.');
  120. if (!$Blog = $Cache->get_value('blog')) {
  121. require_once SERVER_ROOT.'/classes/mysql.class.php'; // Require the database wrapper
  122. $DB = new DB_MYSQL; // Load the database wrapper
  123. $DB->query("
  124. SELECT
  125. b.`ID`,
  126. um.`Username`,
  127. b.`UserID`,
  128. b.`Title`,
  129. b.`Body`,
  130. b.`Time`,
  131. b.`ThreadID`
  132. FROM
  133. `blog` AS b
  134. LEFT JOIN `users_main` AS um
  135. ON
  136. b.`UserID` = um.`ID`
  137. ORDER BY
  138. `Time`
  139. DESC
  140. LIMIT 20
  141. ");
  142. $Blog = $DB->to_array();
  143. $Cache->cache_value('blog', $Blog, 1209600);
  144. }
  145. foreach ($Blog as $BlogItem) {
  146. list($BlogID, $Author, $AuthorID, $Title, $Body, $BlogTime, $ThreadID) = $BlogItem;
  147. if ($ThreadID) {
  148. echo $Feed->item(
  149. $Title,
  150. Text::strip_bbcode($Body),
  151. "forums.php?action=viewthread&amp;threadid=$ThreadID",
  152. "$ENV->SITE_NAME Staff",
  153. '',
  154. '',
  155. $BlogTime
  156. );
  157. } else {
  158. echo $Feed->item(
  159. $Title,
  160. Text::strip_bbcode($Body),
  161. "blog.php#blog$BlogID",
  162. "$ENV->SITE_NAME Staff",
  163. '',
  164. '',
  165. $BlogTime
  166. );
  167. }
  168. }
  169. break;
  170. /**
  171. * ugh
  172. */
  173. case 'torrents_all':
  174. $Feed->channel('All New Torrents', 'RSS feed for all new torrent uploads.');
  175. $Feed->retrieve('torrents_all', $_GET['authkey'], $_GET['passkey']);
  176. break;
  177. case 'torrents_sequences':
  178. $Feed->channel('New Sequences Torrents', 'RSS feed for all new Sequences torrents.');
  179. $Feed->retrieve('torrents_sequences', $_GET['authkey'], $_GET['passkey']);
  180. break;
  181. case 'torrents_graphs':
  182. $Feed->channel('New Graphs Torrents', 'RSS feed for all new Graphs torrents.');
  183. $Feed->retrieve('torrents_graphs', $_GET['authkey'], $_GET['passkey']);
  184. break;
  185. case 'torrents_systems':
  186. $Feed->channel('New Systems Torrents', 'RSS feed for all new Systems torrents.');
  187. $Feed->retrieve('torrents_systems', $_GET['authkey'], $_GET['passkey']);
  188. break;
  189. case 'torrents_geometric':
  190. $Feed->channel('New Geometric Torrents', 'RSS feed for all new Geometric torrents.');
  191. $Feed->retrieve('torrents_geometric', $_GET['authkey'], $_GET['passkey']);
  192. break;
  193. # %2F
  194. case 'torrents_scalars/vectors':
  195. $Feed->channel('New Scalars/Vectors Torrents', 'RSS feed for all new Scalars/Vectors torrents.');
  196. $Feed->retrieve('torrents_scalars/vectors', $_GET['authkey'], $_GET['passkey']);
  197. break;
  198. case 'torrents_patterns':
  199. $Feed->channel('New Patterns Torrents', 'RSS feed for all new Patterns torrents.');
  200. $Feed->retrieve('torrents_patterns', $_GET['authkey'], $_GET['passkey']);
  201. break;
  202. case 'torrents_constraints':
  203. $Feed->channel('New Constraints Torrents', 'RSS feed for all new Constraints torrents.');
  204. $Feed->retrieve('torrents_constraints', $_GET['authkey'], $_GET['passkey']);
  205. break;
  206. case 'torrents_images':
  207. $Feed->channel('New Images Torrents', 'RSS feed for all new Images torrents.');
  208. $Feed->retrieve('torrents_images', $_GET['authkey'], $_GET['passkey']);
  209. break;
  210. case 'torrents_spatial':
  211. $Feed->channel('New Spatial Torrents', 'RSS feed for all new Spatial torrents.');
  212. $Feed->retrieve('torrents_spatial', $_GET['authkey'], $_GET['passkey']);
  213. break;
  214. case 'torrents_models':
  215. $Feed->channel('New Models Torrents', 'RSS feed for all new Models torrents.');
  216. $Feed->retrieve('torrents_models', $_GET['authkey'], $_GET['passkey']);
  217. break;
  218. case 'torrents_documents':
  219. $Feed->channel('New Documents Torrents', 'RSS feed for all new Documents torrents.');
  220. $Feed->retrieve('torrents_documents', $_GET['authkey'], $_GET['passkey']);
  221. break;
  222. # %20
  223. case 'torrents_machine data':
  224. $Feed->channel('New Machine Data Torrents', 'RSS feed for all new Machine Data torrents.');
  225. $Feed->retrieve('torrents_machine data', $_GET['authkey'], $_GET['passkey']);
  226. break;
  227. default:
  228. // Personalized torrents
  229. if (empty($_GET['name']) && substr($_GET['feed'], 0, 16) === 'torrents_notify_') {
  230. // All personalized torrent notifications
  231. $Feed->channel('Personalized torrent notifications', 'RSS feed for personalized torrent notifications.');
  232. $Feed->retrieve($_GET['feed'], $_GET['authkey'], $_GET['passkey']);
  233. } elseif (!empty($_GET['name']) && substr($_GET['feed'], 0, 16) === 'torrents_notify_') {
  234. // Specific personalized torrent notification channel
  235. $Feed->channel(display_str($_GET['name']), 'Personal RSS feed: '.display_str($_GET['name']));
  236. $Feed->retrieve($_GET['feed'], $_GET['authkey'], $_GET['passkey']);
  237. } elseif (!empty($_GET['name']) && substr($_GET['feed'], 0, 21) === 'torrents_bookmarks_t_') {
  238. // Bookmarks
  239. $Feed->channel('Bookmarked torrent notifications', 'RSS feed for bookmarked torrents.');
  240. $Feed->retrieve($_GET['feed'], $_GET['authkey'], $_GET['passkey']);
  241. } else {
  242. $Feed->channel('All Torrents', 'RSS feed for all new torrent uploads.');
  243. $Feed->retrieve('torrents_all', $_GET['authkey'], $_GET['passkey']);
  244. }
  245. }
  246. $Feed->close_feed();