Code

Updated dash board stuff
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 30 Jun 2010 14:36:18 +0000 (14:36 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 30 Jun 2010 14:36:18 +0000 (14:36 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18887 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/generic/dashBoard/class_rssReader.inc [new file with mode: 0644]
gosa-core/plugins/generic/dashBoard/dbAdvices/class_dbAdvices.inc
gosa-core/plugins/generic/dashBoard/dbAdvices/contents.tpl
gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc
gosa-core/plugins/generic/dashBoard/dbInformation/class_rssReader.inc [deleted file]

diff --git a/gosa-core/plugins/generic/dashBoard/class_rssReader.inc b/gosa-core/plugins/generic/dashBoard/class_rssReader.inc
new file mode 100644 (file)
index 0000000..7707894
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+
+class rssReader{
+
+    public static $attributes = array( 
+            'title','link','description','language','copyright','skipHours','timestamp',
+            'managingEditor','webMaster','pubDate','lastBuildDate','category',
+            'generator','docs','cloud','ttl','image','rating','textInput','skipDays');
+
+    public static function parseFeedFromUrl($urls)
+    {
+        // We support multiple urls at once. 
+        if(!is_array($urls)) $urls = array($urls);
+        foreach($urls as $url){ 
+            $doc = new DOMDocument();
+            $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());
+    }
+
+
+    private static function docToFeedEntries($doc, $url)
+    {
+        $entries = array();
+        foreach ($doc->getElementsByTagName('item') as $item) {
+
+            // 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{
+
+                // Create an entry timestamp 
+                $entry['timestamp'] = strtotime($entry['pubDate']);
+            }
+            $entries[] = $entry;
+        }
+        return($entries);
+    }
+
+    public static function sortFeedResultBy($feedRes , $sortBy = 'timestamp')
+    {
+
+        // Do not try to sort for invalid attributes.
+        if(!in_array($sortBy, self::$attributes)){
+            trigger_error("Invalid sortby attribute '{$sortBy}'!");
+            return($feedRes);
+        }
+
+        // Prepare feeds to be sorted, put them in an array indexed by the 'sortBy' attribute.
+        $data = array();
+        foreach($feedRes as $feed){
+            $key = "{$feed[$sortBy]}";
+            $c = '1';
+            while(empty($key) || isset($data[$key])){
+                $key = "{$c}_{$feed[$sortBy]}";
+                $c++;
+            }
+            $data[$key] = $feed;
+        }
+
+        // Sort the natural way and return the results.
+        uksort($data, 'strnatcasecmp');
+        return($data);
+    }
+
+} 
+
+?>
index d79af4cf0ca306b3441cd3930b24a9bb6d6cedc1..461363fe856fe7fb8eb30ce92da50ee9f5406787 100644 (file)
@@ -5,32 +5,44 @@ class dbAdvices extends plugin
     function __construct($config)
     {
         parent::__construct($config, NULL);
+
+        // Construct the plugin list.
+        $this->adviceList = new sortableListing();
+        $this->adviceList->setDeleteable(false);
+        $this->adviceList->setEditable(false);
+        $this->adviceList->setWidth("100%");
+        $this->adviceList->setHeight("200px");
+        $this->adviceList->setAcl("rwcdm");
     }
 
     function execute()
     {
+        // Get logs as RSS feed.
+        $source = file_get_contents('http://10.3.65.162/gosa/gosa-all/gosa/html/index.html');
+
+        // Read Feeds and sort the results 
+        $feeds = rssReader::parseFeedFromSource(array($source));
+        $feeds = rssReader::sortFeedResultBy($feeds, 'timestamp');
+
+        // Append the results to the list.
+        $data = $lData = array();
+        foreach($feeds as $key => $feed){
+            $data[$key] = $feed;
+            $lData[$key] = array('data'=> array(htmlentities($feed['title'],ENT_QUOTES,'UTF-8')));
+        }
+        $this->adviceList->setListData($data, $lData);
+        $this->adviceList->update();
+
+        // Generate the HTML content
         $smarty = get_smarty();
+        $smarty->assign('adviceList', $this->adviceList->render());
         return($smarty->fetch(get_template_path('dbAdvices/contents.tpl', TRUE)));
     }
 
     function save_object()
     {
         parent::save_object();
-    }
-
-    function save()
-    {
-        parent::save();
-    }
-
-    function check()
-    {
-        return(parent::check());
-    }
-
-    function remove_from_parent()
-    {
-        parent::remove_from_parent();
+        $this->adviceList->save_object();
     }
 }
 
index 345e6aef713208c8d50cdea23b85e6ad831f0449..72926473d4e14bb9a807470577a2b7f3487beef5 100644 (file)
@@ -1 +1 @@
-Test
+{$adviceList}
index 36c02ddf4df104e3e56735c89432d8e1156d9e74..48b60b6f43b1a0b03a176247401f5aa693c70030 100644 (file)
@@ -54,21 +54,6 @@ class dbInformation extends plugin
         parent::save_object();
         $this->feedList->save_object();
     }
-
-    function save()
-    {
-        parent::save();
-    }
-
-    function check()
-    {
-        return(parent::check());
-    }
-
-    function remove_from_parent()
-    {
-        parent::remove_from_parent();
-    }
 }
 
 ?>
diff --git a/gosa-core/plugins/generic/dashBoard/dbInformation/class_rssReader.inc b/gosa-core/plugins/generic/dashBoard/dbInformation/class_rssReader.inc
deleted file mode 100644 (file)
index 7707894..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-
-class rssReader{
-
-    public static $attributes = array( 
-            'title','link','description','language','copyright','skipHours','timestamp',
-            'managingEditor','webMaster','pubDate','lastBuildDate','category',
-            'generator','docs','cloud','ttl','image','rating','textInput','skipDays');
-
-    public static function parseFeedFromUrl($urls)
-    {
-        // We support multiple urls at once. 
-        if(!is_array($urls)) $urls = array($urls);
-        foreach($urls as $url){ 
-            $doc = new DOMDocument();
-            $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());
-    }
-
-
-    private static function docToFeedEntries($doc, $url)
-    {
-        $entries = array();
-        foreach ($doc->getElementsByTagName('item') as $item) {
-
-            // 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{
-
-                // Create an entry timestamp 
-                $entry['timestamp'] = strtotime($entry['pubDate']);
-            }
-            $entries[] = $entry;
-        }
-        return($entries);
-    }
-
-    public static function sortFeedResultBy($feedRes , $sortBy = 'timestamp')
-    {
-
-        // Do not try to sort for invalid attributes.
-        if(!in_array($sortBy, self::$attributes)){
-            trigger_error("Invalid sortby attribute '{$sortBy}'!");
-            return($feedRes);
-        }
-
-        // Prepare feeds to be sorted, put them in an array indexed by the 'sortBy' attribute.
-        $data = array();
-        foreach($feedRes as $feed){
-            $key = "{$feed[$sortBy]}";
-            $c = '1';
-            while(empty($key) || isset($data[$key])){
-                $key = "{$c}_{$feed[$sortBy]}";
-                $c++;
-            }
-            $data[$key] = $feed;
-        }
-
-        // Sort the natural way and return the results.
-        uksort($data, 'strnatcasecmp');
-        return($data);
-    }
-
-} 
-
-?>