jsMiniTable(); } else { ?> feeds(); foreach ($feeds as $url => $cache){ print "

trying $url:
"; $test = new rssClient($url,$cache); print $test->miniTable(); } } else { print "random feed
"; print $test->miniTable(); } } } class rssClient { function rssClient ($url = "", $cacheName = ""){ if (!$url){ srand((float) microtime() * 10000000); $feeds = $this->feeds(); $url = array_rand($feeds); $cacheName = $feeds[$url]; } if (!$cacheName){ $cacheName = preg_replace("/\//","-",$url); } $this->url = $url; $this->cacheFile = "cache/" . $cacheName; $this->getContents(); } function refreshCache(){ $this->fileContents = array(); $fp = @fopen ($this->url, "r"); if ($fp){ socket_set_timeout($fp, 5); $cache = @fopen($this->cacheFile, "w"); if ($cache){ while (!feof ($fp)) { $line = fgets($fp); array_push($this->fileContents, $line); fwrite($cache, $line); } fclose($cache); } } else { $this->fileContents = array(); } } function getContents(){ $cacheAge = time() - @filemtime($this->cacheFile); if($cacheAge > 15*60) { $this->age = 0; $this->ageMessage = "Just Refreshed"; $this->refreshCache(); } else { $this->age = $cacheAge; $this->ageMessage = "cached " . round($cacheAge/60) . " minutes ago"; $this->fileContents = @file($this->cacheFile); } if (!$this->fileContents){ $this->fileContents = array(); } } function title(){ if (!$this->title){ $blob = join($this->fileContents,""); preg_match("/]*>[^<]*]*>([^<]*)<\/title>/s",$blob,$matches); $this->title = $matches[1]; } return $this->title; } function items(){ if (!$this->items){ if (!($temp = $this->fileContents)){ return array(); } $blob = join($temp,""); preg_match("/^(.*?)(items = array(); if ($blob){ $items = split("",$blob); foreach ($items as $item){ preg_match("/]*>([^<]*)<\/title>/s",$item,$matches); $temp["title"] = $matches[1]; preg_match("/]*>([^<]*)<\/link>/s",$item,$matches); $temp["link"] = $matches[1]; preg_match("/]*>([^<]*)<\/description>/s",$item,$matches); $temp["description"] = $matches[1]; array_push($this->items,$temp); } } } return $this->items; } function miniTable($limit=0) { $ret .= ""; $items = $this->items(); if ($items){ if ($limit){ $items = array_slice($items,$limit); } foreach ($items as $item){ $ret .= "\n"; } } else { $ret .= "\n"; } $ret .= "
"; $ret .= $this->title(); $ret .= "
(" . $this->ageMessage . ")
"; $ret .= "" . $item["title"] . "
"; $ret .= "No items at this time.
"; return $ret; } function jsMiniTable($limit=0) { $ret .= $this->writeWrap(""); $items = $this->items(); if ($items){ if ($limit){ $items = array_slice($items,$limit); } foreach ($items as $item){ $ret .= $this->writeWrap("\n"); } } else { $ret .= $this->writeWrap("\n"); } $ret .= $this->writeWrap("
"); $ret .= $this->writeWrap($this->title()); $ret .= $this->writeWrap("
(" . $this->ageMessage . ")
"); $ret .= $this->writeWrap("" . $item["title"] . "
"); $ret .= $this->writeWrap("No items at $this time.
"); return $ret; } function writeWrap($string){ $string = str_replace('"', "'",$string); $string = str_replace("\n", " ",$string); return "document.write(\"$string\");\n\n"; } function feeds () { return array( "http://slashdot.org/slashdot.rdf" => "slashdot.rdf", "http://freshmeat.net/backend/fm.rdf" => "freshmeat.rdf", "http://www.artofthemix.org/xml/rss.asp" => "artOfMix.rdf", "http://safari.oreilly.com/NewOnSafari.asp" => "safari.rdf", "http://www.syndic8.com/boxrss.php?Box=RecentFeeds&N=5" => "s8-recent.rdf", "http://www.adamwalker.34sp.com/b2/b2rss.php" => "b2-mods.rdf", "http://veen.com/jeff/rss.xml" => "veen.rdf", ); } }//end class ?>