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.

feed.class.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. class Feed
  3. {
  4. public function open_feed()
  5. {
  6. header("Content-type: application/xml; charset=UTF-8");
  7. 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";
  8. }
  9. public function close_feed()
  10. {
  11. echo "\t</channel>\n</rss>";
  12. }
  13. public function channel($Title, $Description, $Section = '')
  14. {
  15. $Site = site_url();
  16. echo "\t\t<title>$Title :: ". SITE_NAME. "</title>\n";
  17. echo "\t\t<link>$Site$Section</link>\n";
  18. echo "\t\t<description>$Description</description>\n";
  19. echo "\t\t<language>en-us</language>\n";
  20. echo "\t\t<lastBuildDate>". date('r'). "</lastBuildDate>\n";
  21. echo "\t\t<docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
  22. echo "\t\t<generator>Gazelle Feed Class</generator>\n\n";
  23. }
  24. public function item($Title, $Description, $Page, $Creator, $Comments = '', $Category = '', $Date = '')
  25. { // Escape with CDATA, otherwise the feed breaks.
  26. if ($Date === '') {
  27. $Date = date('r');
  28. } else {
  29. $Date = date('r', strtotime($Date));
  30. }
  31. $Site = site_url();
  32. $Item = "\t\t<item>\n";
  33. $Item .= "\t\t\t<title><![CDATA[$Title]]></title>\n";
  34. $Item .= "\t\t\t<description><![CDATA[$Description]]></description>\n";
  35. $Item .= "\t\t\t<pubDate>$Date</pubDate>\n";
  36. $Item .= "\t\t\t<link>$Site$Page</link>\n";
  37. $Item .= "\t\t\t<guid>$Site$Page</guid>\n";
  38. if ($Comments !== '') {
  39. $Item .= "\t\t\t<comments>$Site$Comments</comments>\n";
  40. }
  41. if ($Category !== '') {
  42. $Item .= "\t\t\t<category><![CDATA[$Category]]></category>\n";
  43. }
  44. $Item .= "\t\t\t<dc:creator>$Creator</dc:creator>\n\t\t</item>\n";
  45. return $Item;
  46. }
  47. public function retrieve($CacheKey, $AuthKey, $PassKey)
  48. {
  49. global $Cache;
  50. $Entries = $Cache->get_value($CacheKey);
  51. if (!$Entries) {
  52. $Entries = [];
  53. } else {
  54. foreach ($Entries as $Item) {
  55. echo str_replace(array('[[PASSKEY]]', '[[AUTHKEY]]'), array(display_str($PassKey), display_str($AuthKey)), $Item);
  56. }
  57. }
  58. }
  59. public function populate($CacheKey, $Item)
  60. {
  61. global $Cache;
  62. $Entries = $Cache->get_value($CacheKey, true);
  63. if (!$Entries) {
  64. $Entries = [];
  65. } else {
  66. if (count($Entries) >= 50) {
  67. array_pop($Entries);
  68. }
  69. }
  70. array_unshift($Entries, $Item);
  71. $Cache->cache_value($CacheKey, $Entries, 0); // inf cache
  72. }
  73. }