<?php global $MODULE_DIR, $UTIL_DIR; include_once($UTIL_DIR . "/convert.php"); include_once($UTIL_DIR . "/markdown.php"); include_once($MODULES_DIR . "/rss.php"); class RSSEntry { public $title; public $time; public $description; public $category; public function RSSEntry($title, $time, $category, $description) { $this->title = $title; $this->time = $time; $this->category = $category; $this->description = $description; } } class RSS { private $configfile; private $config; private $newsfile; private $news = array(); private $newspage; 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->config->target, "w"); fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); fwrite($fp, "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n"); fwrite($fp, " <channel>\n"); fwrite($fp, " <title>".$this->config->title."</title>\n"); fwrite($fp, " <atom:link href=\"".$this->config->url."/rss.xml\" rel=\"self\" type=\"application/rss+xml\" />\n"); fwrite($fp, " <link>".$this->config->url."</link>\n"); fwrite($fp, " <description>".$this->config->description."</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>".$this->config->editoremail."</managingEditor>\n"); fwrite($fp, " <webMaster>".$this->config->webmasteremail."</webMaster>\n"); $i = 0; foreach($this->news as $newsentry) { fwrite($fp, " <item>\n"); fwrite($fp, " <title>".$newsentry->title."</title>\n"); fwrite($fp, " <link>".$this->config->url."/?page=".$this->newspage."&newsid=".$newsentry->time."</link>\n"); $content = htmlspecialchars(Markdown(htmlspecialchars_decode($newsentry->description), true)); fwrite($fp, " <description>".$content."</description>\n"); fwrite($fp, " <pubDate>".$this->date($newsentry->time)."</pubDate>\n"); fwrite($fp, " <guid>".$this->config->url."/?page=".$this->newspage."&newsid=".$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() { $this->config = new RSSConfig($this->configfile); $dom = new DomDocument; $dom->preserveWhiteSpace = FALSE; $dom->load($this->newsfile); $n = $dom->documentElement; $this->newspage = $n->getAttribute('newspage'); $params = $dom->getElementsByTagName('newsentry'); foreach ($params as $param) { $rssentry = new RSSEntry($param->getAttribute('title'), $param->getAttribute('time'), $param->getAttribute('category'), $param->textContent); $this->add($rssentry); } // Key sort krsort($this->news); } public function RSS($newsfile, $configfile) { $this->newsfile = $newsfile; $this->configfile = $configfile; $this->read(); } } ?>