From c4d76d37c4f3d8e078d059e28b5ad1a203a01b24 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 30 Jun 2010 13:57:22 +0000 Subject: [PATCH] Updated RRS feed parser to support feeds from source git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18886 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../dbInformation/class_dbInformation.inc | 6 +- .../dbInformation/class_rssReader.inc | 71 +++++++++++++------ 2 files changed, 49 insertions(+), 28 deletions(-) diff --git a/gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc b/gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc index e393a3535..36c02ddf4 100644 --- a/gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc +++ b/gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc @@ -31,11 +31,7 @@ class dbInformation extends plugin } // Read Feeds and sort the results - $feeds = rssReader::feadToArray(array( - 'http://www.uweschwanz.com/de/rss/', - 'http://www.aviationpower.de/rss_de.php', - 'http://www.computerbild.de/rssfeed_2261.html?node=10', - 'http://www.charts-portal.de/games/Computerspiele.xml')); + $feeds = rssReader::parseFeedFromUrl(array('http://www.uweschwanz.com/de/rss/')); $feeds = rssReader::sortFeedResultBy($feeds, 'timestamp'); // Append the results to the list. diff --git a/gosa-core/plugins/generic/dashBoard/dbInformation/class_rssReader.inc b/gosa-core/plugins/generic/dashBoard/dbInformation/class_rssReader.inc index 54d9cad99..770789449 100644 --- a/gosa-core/plugins/generic/dashBoard/dbInformation/class_rssReader.inc +++ b/gosa-core/plugins/generic/dashBoard/dbInformation/class_rssReader.inc @@ -7,39 +7,64 @@ class rssReader{ 'managingEditor','webMaster','pubDate','lastBuildDate','category', 'generator','docs','cloud','ttl','image','rating','textInput','skipDays'); - public static function feadToArray($urls) + public static function parseFeedFromUrl($urls) { - $entries = array(); - // We support multiple urls at once. if(!is_array($urls)) $urls = array($urls); - foreach($urls as $url){ $doc = new DOMDocument(); - $doc->load($url); - foreach ($doc->getElementsByTagName('item') as $item) { + $res = $doc->load($url); + if(!$res){ + trigger_error("Failed to load feed '{$url}'!"); + }else{ + return(self::docToFeedEntries($doc, $url)); + } + } + return(array()); + } + + public static function parseFeedFromSource($sources) + { + // We support multiple urls at once. + if(!is_array($sources)) $urls = array($sources); + foreach($sources as $source){ + $doc = new DOMDocument(); + $res = $doc->loadHTML($source); + if(!$res){ + trigger_error("Failed to load feed '{$source}'!"); + }else{ + return(self::docToFeedEntries($doc, 'from source')); + } + } + return(array()); + } - // Collect data from feed - $entry = array(); - $entry['url'] = $url; - foreach(self::$attributes as $attr){ - $entry[$attr] =NULL; - $obj = $item->getElementsByTagName($attr); - if(is_object($obj->item(0))){ - $entry[$attr] = $obj->item(0)->nodeValue; - } - } - // Fake timestamp in none is given. - if($entry['pubDate'] == NULL){ - $entry['timestamp'] = NULL; - }else{ + private static function docToFeedEntries($doc, $url) + { + $entries = array(); + foreach ($doc->getElementsByTagName('item') as $item) { - // Create an entry timestamp - $entry['timestamp'] = strtotime($entry['pubDate']); + // Collect data from feed + $entry = array(); + $entry['url'] = $url; + foreach(self::$attributes as $attr){ + $entry[$attr] =NULL; + $obj = $item->getElementsByTagName($attr); + if(is_object($obj->item(0))){ + $entry[$attr] = $obj->item(0)->nodeValue; } - $entries[] = $entry; + } + + // Fake timestamp in none is given. + if($entry['pubDate'] == NULL){ + $entry['timestamp'] = NULL; + }else{ + + // Create an entry timestamp + $entry['timestamp'] = strtotime($entry['pubDate']); } + $entries[] = $entry; } return($entries); } -- 2.30.2