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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 * FROM (
  50. SELECT t.*,
  51. (SELECT Name from artists_group ag WHERE ag.ArtistID=ta.ArtistID) AS ArtistName,
  52. tg.Name AS GroupName,
  53. tg.WikiBody AS WikiBody
  54. FROM `torrents` t
  55. LEFT JOIN torrents_artists ta ON t.GroupID=ta.GroupID
  56. LEFT JOIN torrents_group tg ON tg.ID=ta.GroupID
  57. ORDER BY id DESC
  58. LIMIT 20
  59. ) sub
  60. ORDER BY id ASC");
  61. while ($torrent = $DB->next_record()) {
  62. $Title = $torrent['ArtistName'].' - '.$torrent['GroupName'].' - '.$torrent['Recorded'].' | '.$torrent['Codec'].' / '.$torrent['Media'].' / '.$torrent['Container'].' / '.$torrent['Resolution'].' / '.$torrent['AudioFormat'];
  63. $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']);
  64. self::populate('torrents_all', $Item);
  65. echo str_replace(array('[[PASSKEY]]', '[[AUTHKEY]]'), array(display_str($PassKey), display_str($AuthKey)), $Item);
  66. }
  67. } else {
  68. foreach ($Entries as $Item) {
  69. echo str_replace(array('[[PASSKEY]]', '[[AUTHKEY]]'), array(display_str($PassKey), display_str($AuthKey)), $Item);
  70. }
  71. }
  72. }
  73. function populate($CacheKey, $Item) {
  74. global $Cache;
  75. $Entries = $Cache->get_value($CacheKey, true);
  76. if (!$Entries) {
  77. $Entries = [];
  78. } else {
  79. if (count($Entries) >= 50) {
  80. array_pop($Entries);
  81. }
  82. }
  83. array_unshift($Entries, $Item);
  84. $Cache->cache_value($CacheKey, $Entries, 0); //inf cache
  85. }
  86. }