Oppaitime'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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. {
  26. //Escape with CDATA, otherwise the feed breaks.
  27. if ($Date == '') {
  28. $Date = date('r');
  29. } else {
  30. $Date = date('r', strtotime($Date));
  31. }
  32. $Site = site_url();
  33. $Item = "\t\t<item>\n";
  34. $Item .= "\t\t\t<title><![CDATA[$Title]]></title>\n";
  35. $Item .= "\t\t\t<description><![CDATA[$Description]]></description>\n";
  36. $Item .= "\t\t\t<pubDate>$Date</pubDate>\n";
  37. $Item .= "\t\t\t<link>$Site$Page</link>\n";
  38. $Item .= "\t\t\t<guid>$Site$Page</guid>\n";
  39. if ($Comments != '') {
  40. $Item .= "\t\t\t<comments>$Site$Comments</comments>\n";
  41. }
  42. if ($Category != '') {
  43. $Item .= "\t\t\t<category><![CDATA[$Category]]></category>\n";
  44. }
  45. $Item .= "\t\t\t<dc:creator>$Creator</dc:creator>\n\t\t</item>\n";
  46. return $Item;
  47. }
  48. public function retrieve($CacheKey, $AuthKey, $PassKey)
  49. {
  50. global $Cache;
  51. $Entries = $Cache->get_value($CacheKey);
  52. if (!$Entries) {
  53. $Entries = [];
  54. } else {
  55. foreach ($Entries as $Item) {
  56. echo str_replace(array('[[PASSKEY]]', '[[AUTHKEY]]'), array(display_str($PassKey), display_str($AuthKey)), $Item);
  57. }
  58. }
  59. }
  60. public function populate($CacheKey, $Item)
  61. {
  62. global $Cache;
  63. $Entries = $Cache->get_value($CacheKey, true);
  64. if (!$Entries) {
  65. $Entries = [];
  66. } else {
  67. if (count($Entries) >= 50) {
  68. array_pop($Entries);
  69. }
  70. }
  71. array_unshift($Entries, $Item);
  72. $Cache->cache_value($CacheKey, $Entries, 0); //inf cache
  73. }
  74. }