From: hickert Date: Wed, 30 Jun 2010 14:36:18 +0000 (+0000) Subject: Updated dash board stuff X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=25edab1176af1a56241a4bb0eda8ea3518db0271;p=gosa.git Updated dash board stuff git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18887 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/plugins/generic/dashBoard/class_rssReader.inc b/gosa-core/plugins/generic/dashBoard/class_rssReader.inc new file mode 100644 index 000000000..770789449 --- /dev/null +++ b/gosa-core/plugins/generic/dashBoard/class_rssReader.inc @@ -0,0 +1,100 @@ +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); + } + +} + +?> diff --git a/gosa-core/plugins/generic/dashBoard/dbAdvices/class_dbAdvices.inc b/gosa-core/plugins/generic/dashBoard/dbAdvices/class_dbAdvices.inc index d79af4cf0..461363fe8 100644 --- a/gosa-core/plugins/generic/dashBoard/dbAdvices/class_dbAdvices.inc +++ b/gosa-core/plugins/generic/dashBoard/dbAdvices/class_dbAdvices.inc @@ -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(); } } diff --git a/gosa-core/plugins/generic/dashBoard/dbAdvices/contents.tpl b/gosa-core/plugins/generic/dashBoard/dbAdvices/contents.tpl index 345e6aef7..72926473d 100644 --- a/gosa-core/plugins/generic/dashBoard/dbAdvices/contents.tpl +++ b/gosa-core/plugins/generic/dashBoard/dbAdvices/contents.tpl @@ -1 +1 @@ -Test +{$adviceList} diff --git a/gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc b/gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc index 36c02ddf4..48b60b6f4 100644 --- a/gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc +++ b/gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc @@ -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 index 770789449..000000000 --- a/gosa-core/plugins/generic/dashBoard/dbInformation/class_rssReader.inc +++ /dev/null @@ -1,100 +0,0 @@ -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); - } - -} - -?>