summaryrefslogtreecommitdiff
path: root/utils/rss.php
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rss.php')
-rw-r--r--utils/rss.php112
1 files changed, 112 insertions, 0 deletions
diff --git a/utils/rss.php b/utils/rss.php
new file mode 100644
index 0000000..e6aa83f
--- /dev/null
+++ b/utils/rss.php
@@ -0,0 +1,112 @@
+<?php
+
+include_once("convert.php");
+
+class RSSEntry {
+ public $title;
+ public $time;
+ public $description;
+ public $category;
+
+ /*
+ public function show()
+ {
+ echo "<div class=\"news_entry\">\n";
+ echo " <div class=\"news_title\">" .
+ htmlspecialchars_decode($this->title, ENT_QUOTES) . "</div>\n";
+ echo " <div class=\"news_time\">" . date("D M jS Y G:i", $this->time) . "</div>\n";
+ echo " <div class=\"news_description\">" .
+ htmlspecialchars_decode($this->description, ENT_QUOTES) . "</div>\n";
+ echo "</div>\n";
+ }
+ */
+ public function RSSEntry($title, $time, $category, $description)
+ {
+ $this->title = $title;
+ $this->time = $time;
+ $this->category = $category;
+ $this->description = $description;
+ }
+}
+
+class RSS {
+
+ private $newsfile;
+ private $rssfile;
+ private $news = array();
+
+ public function add($newsentry) {
+ $key = $newsentry->time;
+ $this->news[$key] = $newsentry;
+ }
+
+ private function date($time) {
+ return date("r", $time);
+ }
+
+ public function write()
+ {
+ $fp = fopen($this->rssfile, "w");
+ fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+ fwrite($fp, "<rss version=\"2.0\">\n");
+ fwrite($fp, " <channel>\n");
+ fwrite($fp, " <title>DIE News</title>\n");
+ fwrite($fp, " <link>http://www.executionroom.com</link>\n");
+ fwrite($fp, " <description>DIE - News from ExecutionRoom.com</description>\n");
+ fwrite($fp, " <language>en-us</language>\n");
+ fwrite($fp, " <pubDate>".$this->date(time())."</pubDate>\n");
+ fwrite($fp, " <lastBuildDate>".$this->date(time())."</lastBuildDate>\n");
+ fwrite($fp, " <docs>http://blogs.law.harvard.edu/tech/rss</docs>\n");
+ fwrite($fp, " <generator>ExecutionRoom CMS</generator>\n");
+ fwrite($fp, " <managingEditor>info@executionroom.com</managingEditor>\n");
+ fwrite($fp, " <webMaster>info@executionroom.com</webMaster>\n");
+
+ $i = 0;
+ foreach($this->news as $newsentry) {
+ fwrite($fp, " <item>\n");
+ fwrite($fp, " <title>".$newsentry->title."</title>\n");
+ fwrite($fp, " <link>http://www.executionroom.com/?page=news&amp;id=".$newsentry->time."</link>\n");
+ fwrite($fp, " <description>".$newsentry->description."</description>\n");
+ fwrite($fp, " <pubDate>".$this->date($newsentry->time)."</pubDate>\n");
+ fwrite($fp, " <guid>http://www.executionroom.com/?page=news&amp;id=".$newsentry->time."</guid>\n");
+ fwrite($fp, " </item>\n");
+ $i++;
+ if($i > 6) break;
+ }
+
+ fwrite($fp, " </channel>\n");
+ fwrite($fp, "</rss>\n");
+
+ fclose($fp);
+ }
+
+ private function read()
+ {
+
+ $dom = new DomDocument;
+ $dom->preserveWhiteSpace = FALSE;
+ $dom->load($this->newsfile);
+ $params = $dom->getElementsByTagName('newsentry');
+
+ foreach ($params as $param) {
+ $rssentry = new RSSEntry($param->getAttribute('title'),
+ $param->getAttribute('time'),
+ $param->getAttribute('category'),
+ $param->getAttribute('description'));
+ $this->add($rssentry);
+ }
+
+ // Key sort
+ krsort($this->news);
+ }
+
+ public function RSS($newsfile, $rssfile)
+ {
+ $this->newsfile = $newsfile;
+ $this->rssfile = $rssfile;
+ $this->read();
+ }
+
+}
+
+?>