From: hickert Date: Wed, 30 Jun 2010 12:28:52 +0000 (+0000) Subject: Updated feed list X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5989464e7e70c71fe4c0b646515f16ef057bc106;p=gosa.git Updated feed list -Fixed sorting git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18884 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc b/gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc index d9e9fc978..707447cbb 100644 --- a/gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc +++ b/gosa-core/plugins/generic/dashBoard/dbInformation/class_dbInformation.inc @@ -10,10 +10,10 @@ class dbInformation extends plugin $this->feedList = new sortableListing(); $this->feedList->setDeleteable(false); $this->feedList->setEditable(false); -# $this->feedList->setColspecs(array('30px','120px','*','100px')); -# $this->feedList->setHeader(array('?',_("Name"),_("Descriptio"),_("Status"))); + #$this->feedList->setColspecs(array('130px','*')); + #$this->feedList->setHeader(array(_("Date"),_("Description"))); $this->feedList->setWidth("100%"); -# $this->feedList->setDefaultSortColumn(1); + #$this->feedList->setDefaultSortColumn(0); $this->feedList->setHeight("200px"); $this->feedList->setAcl("rwcdm"); } @@ -21,13 +21,16 @@ class dbInformation extends plugin function execute() { $smarty = get_smarty(); - $feeds = rssReader::feadToArray('http://www.computerbild.de/rssfeed_2261.html?node=10'); - + $feeds = rssReader::feadToArray(array( + 'http://www.computerbild.de/rssfeed_2261.html?node=10', + 'http://www.charts-portal.de/games/Computerspiele.xml')); + $feeds = rssReader::sortFeedResultBy($feeds, 'timestamp'); $data = $lData = array(); foreach($feeds as $key => $feed){ $data[$key] = $feed; - $lData[$key] = array('data'=> array(date('H:i:s', $feed['timestamp']),$feed['title'])); + $lData[$key] = array('data'=> array($feed['title'])); } + $this->feedList->setListData($data, $lData); $this->feedList->update(); $smarty->assign('feedList', $this->feedList->render()); diff --git a/gosa-core/plugins/generic/dashBoard/dbInformation/class_rssReader.inc b/gosa-core/plugins/generic/dashBoard/dbInformation/class_rssReader.inc index 11e8a7942..54d9cad99 100644 --- a/gosa-core/plugins/generic/dashBoard/dbInformation/class_rssReader.inc +++ b/gosa-core/plugins/generic/dashBoard/dbInformation/class_rssReader.inc @@ -2,24 +2,74 @@ class rssReader{ - static function feadToArray($url) - { + public static $attributes = array( + 'title','link','description','language','copyright','skipHours','timestamp', + 'managingEditor','webMaster','pubDate','lastBuildDate','category', + 'generator','docs','cloud','ttl','image','rating','textInput','skipDays'); - $doc = new DOMDocument(); - $doc->load($url); + public static function feadToArray($urls) + { $entries = array(); - foreach ($doc->getElementsByTagName('item') as $item) { - $entry = array ( - 'title' => $item->getElementsByTagName('title')->item(0)->nodeValue, - 'desc' => $item->getElementsByTagName('description')->item(0)->nodeValue, - 'link' => $item->getElementsByTagName('link')->item(0)->nodeValue, - 'date' => $item->getElementsByTagName('pubDate')->item(0)->nodeValue, - 'timestamp' => strtotime($item->getElementsByTagName('pubDate')->item(0)->nodeValue) - ); - $entries[$entry['timestamp']."-".$entry['date']] = $entry; + + // 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) { + + // 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); + } + } ?>