Code

Updated RRS feed parser to support feeds from source
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 30 Jun 2010 13:57:22 +0000 (13:57 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 30 Jun 2010 13:57:22 +0000 (13:57 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18886 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc
gosa-core/plugins/generic/dashBoard/dbInformation/class_rssReader.inc

index e393a3535f6309f2e7b43f8390c6e1af9b5c6e39..36c02ddf4df104e3e56735c89432d8e1156d9e74 100644 (file)
@@ -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.
index 54d9cad99cd22ed39f9fc810c92002a34f3d7b32..7707894492b56e337f1127adf62c334eedd8475f 100644 (file)
@@ -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);
     }