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.1KB

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