remoteXML = 'http://del.icio.us/rss/darcy/1000camels'; * $stream->localXML = 'lib/rss_feeds/1000camels.rss'; * $stream->xslFile = 'style/1000camels.xsl'; * * echo $stream->getStream(); * */ Class RSSStream { var $remoteXML; var $localXML; var $xmlData; var $xalFile; var $content; /** * Constructor */ function RSSStream() { } function getStream() { if(file_exists($this->localXML) && time() < (filemtime($this->localXML)+86400) && !isset($_REQUEST['r'])) { // get local feed $this->xmlData = file_get_contents($this->localXML); } else { // get remote feed $this->xmlData = file_get_contents($this->remoteXML); if(!is_writable(dirname($this->localXML))) { return $this->localXML.' is not writable'; } if (!$handle = fopen($this->localXML, 'w')) { return "Cannot open file, ".$filename." for writing"; } // Write $somecontent to our opened file. if (fwrite($handle, $this->xmlData) === FALSE) { return "Cannot write to file: ".$this->localXML; } fclose($handle); $this->content = '

retrieving remote feed

'; } // load xml $document = new DOMDocument(); $document->loadXML($this->xmlData); // load xsl if(file_exists($this->xslFile) && !empty($this->xslFile)) { $xsldoc = new DOMDocument(); $xsldoc->load($this->xslFile); $xsl = new XSLTProcessor(); $xsl->importStyleSheet($xsldoc); $this->content .= $xsl->transformToXML($document); } else { $this->content .= '[no stylesheet defined]'; } return $this->content; } } ?>