Contributing back some bug fixes
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.

feed.class.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?
  2. class FEED {
  3. function open_feed() {
  4. header("Content-type: application/xml; charset=UTF-8");
  5. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n","<rss xmlns:dc=\"http://purl.org/dc/elements/1.1/\" version=\"2.0\">\n\t<channel>\n";
  6. }
  7. function close_feed() {
  8. echo "\t</channel>\n</rss>";
  9. }
  10. function channel($Title, $Description, $Section = '') {
  11. $Site = site_url();
  12. echo "\t\t<title>$Title :: ". SITE_NAME. "</title>\n";
  13. echo "\t\t<link>$Site$Section</link>\n";
  14. echo "\t\t<description>$Description</description>\n";
  15. echo "\t\t<language>en-us</language>\n";
  16. echo "\t\t<lastBuildDate>". date('r'). "</lastBuildDate>\n";
  17. echo "\t\t<docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
  18. echo "\t\t<generator>Gazelle Feed Class</generator>\n\n";
  19. }
  20. function item($Title, $Description, $Page, $Creator, $Comments = '', $Category = '', $Date = '') { //Escape with CDATA, otherwise the feed breaks.
  21. if ($Date == '') {
  22. $Date = date('r');
  23. } else {
  24. $Date = date('r', strtotime($Date));
  25. }
  26. $Site = site_url();
  27. $Item = "\t\t<item>\n";
  28. $Item .= "\t\t\t<title><![CDATA[$Title]]></title>\n";
  29. $Item .= "\t\t\t<description><![CDATA[$Description]]></description>\n";
  30. $Item .= "\t\t\t<pubDate>$Date</pubDate>\n";
  31. $Item .= "\t\t\t<link>$Site$Page</link>\n";
  32. $Item .= "\t\t\t<guid>$Site$Page</guid>\n";
  33. if ($Comments != '') {
  34. $Item .= "\t\t\t<comments>$Site$Comments</comments>\n";
  35. }
  36. if ($Category != '') {
  37. $Item .= "\t\t\t<category><![CDATA[$Category]]></category>\n";
  38. }
  39. $Item .= "\t\t\t<dc:creator>$Creator</dc:creator>\n\t\t</item>\n";
  40. return $Item;
  41. }
  42. function retrieve($CacheKey, $AuthKey, $PassKey) {
  43. global $Cache;
  44. $Entries = $Cache->get_value($CacheKey);
  45. if (!$Entries) {
  46. require(SERVER_ROOT.'/classes/mysql.class.php');
  47. $DB = NEW DB_MYSQL; //Load the database wrapper
  48. $DB->query("
  49. SELECT t.*,
  50. (SELECT Name from artists_group ag WHERE ag.ArtistID=ta.ArtistID) AS ArtistName,
  51. tg.Name AS GroupName,
  52. tg.WikiBody AS WikiBody
  53. FROM `torrents` t
  54. LEFT JOIN torrents_artists ta ON t.GroupID=ta.GroupID
  55. LEFT JOIN torrents_group tg ON tg.ID=ta.GroupID
  56. ORDER BY ID DESC
  57. LIMIT 50");
  58. while ($torrent = $DB->next_record()) {
  59. $Title = $torrent['ArtistName'].' - '.$torrent['GroupName'].' - '.$torrent['Recorded'].' | '.$torrent['Codec'].' / '.$torrent['Media'].' / '.$torrent['Container'].' / '.$torrent['Resolution'].' / '.$torrent['AudioFormat'];
  60. $Item = self::item($Title, Text::strip_bbcode($torrent['WikiBody']), 'torrents.php?action=download&amp;authkey=[[AUTHKEY]]&amp;torrent_pass=[[PASSKEY]]&amp;id='.$torrent['ID'], $torrent['UserID'], 'torrents.php?id='.$torrent['GroupID']);
  61. self::populate('torrents_all', $Item);
  62. echo str_replace(array('[[PASSKEY]]', '[[AUTHKEY]]'), array(display_str($PassKey), display_str($AuthKey)), $Item);
  63. }
  64. } else {
  65. foreach ($Entries as $Item) {
  66. echo str_replace(array('[[PASSKEY]]', '[[AUTHKEY]]'), array(display_str($PassKey), display_str($AuthKey)), $Item);
  67. }
  68. }
  69. }
  70. function populate($CacheKey, $Item) {
  71. global $Cache;
  72. $Entries = $Cache->get_value($CacheKey, true);
  73. if (!$Entries) {
  74. $Entries = [];
  75. } else {
  76. if (count($Entries) >= 50) {
  77. array_pop($Entries);
  78. }
  79. }
  80. array_unshift($Entries, $Item);
  81. $Cache->cache_value($CacheKey, $Entries, 0); //inf cache
  82. }
  83. }