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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. declare(strict_types = 1);
  3. class Feed
  4. {
  5. /**
  6. * open_feed
  7. */
  8. public function open_feed()
  9. {
  10. header('Content-Type: application/xml; charset=utf-8');
  11. echo "<?xml version='1.0' encoding='utf-8'?>",
  12. "<rss xmlns:dc='http://purl.org/dc/elements/1.1/' version='2.0'><channel>";
  13. }
  14. /**
  15. * close_feed
  16. */
  17. public function close_feed()
  18. {
  19. echo "</channel></rss>";
  20. }
  21. /**
  22. * channel
  23. */
  24. public function channel($Title, $Description, $Section = '')
  25. {
  26. $ENV = ENV::go();
  27. $Site = site_url();
  28. # echo commas because <<<XML would copy whitespace
  29. echo "<title>$Title $ENV->SEP $ENV->SITE_NAME</title>",
  30. "<link>$Site$Section</link>",
  31. "<description>$Description</description>",
  32. "<language>en-us</language>",
  33. "<lastBuildDate>".date('r')."</lastBuildDate>",
  34. "<docs>http://blogs.law.harvard.edu/tech/rss</docs>",
  35. "<generator>Gazelle Feed Class</generator>";
  36. }
  37. /**
  38. * item
  39. */
  40. public function item($Title, $Description, $Page, $Creator, $Comments = '', $Category = '', $Date = '')
  41. {
  42. $Site = site_url();
  43. if ($Date === '') {
  44. $Date = date('r');
  45. } else {
  46. $Date = date('r', strtotime($Date));
  47. }
  48. // Escape with CDATA, otherwise the feed breaks.
  49. $Item = "<item>";
  50. $Item .= "<title><![CDATA[$Title]]></title>";
  51. $Item .= "<description><![CDATA[$Description]]></description>";
  52. $Item .= "<pubDate>$Date</pubDate>";
  53. $Item .= "<link>$Site$Page</link>";
  54. $Item .= "<guid>$Site$Page</guid>";
  55. if ($Comments !== '') {
  56. $Item .= "<comments>$Site$Comments</comments>";
  57. }
  58. if ($Category !== '') {
  59. $Item .= "<category><![CDATA[$Category]]></category>";
  60. }
  61. $Item .= "<dc:creator>$Creator</dc:creator></item>";
  62. return $Item;
  63. }
  64. /**
  65. * retrieve
  66. */
  67. public function retrieve($CacheKey, $AuthKey, $PassKey)
  68. {
  69. global $Cache;
  70. $Entries = $Cache->get_value($CacheKey);
  71. if (!$Entries) {
  72. $Entries = [];
  73. } else {
  74. foreach ($Entries as $Item) {
  75. echo str_replace(
  76. array('[[PASSKEY]]', '[[AUTHKEY]]'),
  77. array(display_str($PassKey), display_str($AuthKey)),
  78. $Item
  79. );
  80. }
  81. }
  82. }
  83. /**
  84. * populate
  85. */
  86. public function populate($CacheKey, $Item)
  87. {
  88. global $Cache;
  89. $Entries = $Cache->get_value($CacheKey, true);
  90. if (!$Entries) {
  91. $Entries = [];
  92. } else {
  93. if (count($Entries) >= 50) {
  94. array_pop($Entries);
  95. }
  96. }
  97. array_unshift($Entries, $Item);
  98. $Cache->cache_value($CacheKey, $Entries, 0); // inf cache
  99. }
  100. }