From c1e3ed6c1fa6b65c193c9c1af0f69dbb07e468d7 Mon Sep 17 00:00:00 2001 From: danij Date: Mon, 27 Feb 2012 15:14:36 +0000 Subject: [PATCH] Homepage: Added a short summary of the latest build events Display a summary of the three most recent build events and a link to the builds rss feed on the homepage. Events within the past two days are automatically highlighted with a NEW label. --- web/classes/feed.class.php | 106 +++++++++++++++++++------- web/classes/frontcontroller.class.php | 35 ++++++++- web/style.css | 8 +- 3 files changed, 118 insertions(+), 31 deletions(-) diff --git a/web/classes/feed.class.php b/web/classes/feed.class.php index bfb6202cc4..324b2fda58 100644 --- a/web/classes/feed.class.php +++ b/web/classes/feed.class.php @@ -32,22 +32,45 @@ class Feed implements Visual, Iterator, Countable { public static $name = 'pages'; - private static $_displayOptions = 0; + private static $displayOptions = 0; - private $_maxItems; - private $_feedURL; - private $_rss; - private $_position; + private $maxItems; + private $feedUri; + private $feed; + private $position; + + private $title = 'Untitled'; + private $labelSpanClass = NULL; + + // Callback to make when generating HTML for a feed item. + private $func_genElementHTML = NULL; public function __construct($feedURL, $maxItems=5) { - $this->_feedURL = $feedURL; + $this->_feedUri = $feedURL; $this->_maxItems = intval($maxItems); - $this->_rss = fetch_rss($this->_feedURL); + $this->_feed = fetch_rss($this->_feedUri); + $this->_feedFormat = 'RSS'; $this->_position = 0; } + public function setTitle($title, $labelSpanClass=NULL) + { + $this->_title = "$title"; + if(!is_null($labelSpanClass)) + $this->_labelSpanClass = "$labelSpanClass"; + } + + public function setGenerateElementHTMLCallback($funcName) + { + $funcName = "$funcName"; + if(!is_callable($funcName)) return FALSE; + + $this->func_genElementHTML = $funcName; + return TRUE; + } + /** * Implements Visual. */ @@ -56,33 +79,60 @@ public function displayOptions() return $this->_displayOptions; } + private function generateElementHTML(&$item) + { + if(!is_array($item)) + throw new Exception('Received invalid item, array expected.'); + + if(!is_null($this->func_genElementHTML)) + { + return call_user_func($this->func_genElementHTML, $item); + } + + $html = ''. htmlspecialchars($item['title']) .''; + return $html; + } + public function generateHTML() { if(count($this) > 0) { -?> - Latest Project News -_feedURL; + return $this->_feedUri; } /** @@ -90,8 +140,8 @@ public function url() */ public function count() { - if(is_object($this->_rss) && is_array($this->_rss->items)) - return sizeof($this->_rss->items); + if(is_object($this->_feed) && is_array($this->_feed->items)) + return sizeof($this->_feed->items); return 0; } @@ -100,13 +150,13 @@ public function count() */ public function rewind() { - reset($this->_rss->items); - $this->_position = key($this->_rss->items); + reset($this->_feed->items); + $this->_position = key($this->_feed->items); } public function current() { - return $this->_rss->items[$this->_position]; + return $this->_feed->items[$this->_position]; } public function key() @@ -116,12 +166,12 @@ public function key() public function next() { - next($this->_rss->items); - $this->_position = key($this->_rss->items); + next($this->_feed->items); + $this->_position = key($this->_feed->items); } public function valid() { - return isset($this->_rss->items[$this->_position]); + return isset($this->_feed->items[$this->_position]); } } diff --git a/web/classes/frontcontroller.class.php b/web/classes/frontcontroller.class.php index d62d5dda8b..b4bdfcddc3 100644 --- a/web/classes/frontcontroller.class.php +++ b/web/classes/frontcontroller.class.php @@ -207,8 +207,37 @@ private function outputNewsFeed() { require_once(DIR_CLASSES.'/feed.class.php'); - $NewsFeed = new Feed('http://dengine.net/forums/rss.php?mode=news'); - $NewsFeed->generateHTML(); + $feed = new Feed('http://dengine.net/forums/rss.php?mode=news', 5); + $feed->setTitle('Project News via RSS', 'projectnews-label'); + $feed->generateHTML(); + } + + /** + * Feed item HTML generator for formatting the customised output used + * with the Builds feed. + */ + static public function generateBuildFeedItemHtml(&$item) + { + $html = ''. htmlspecialchars($item['title']) .' complete'; + + if(time() < strtotime('+2 days', $item['date_timestamp'])) + { + $html .= ' NEW'; + } + + return $html; + } + + private function outputBuildsFeed() + { + require_once(DIR_CLASSES.'/feed.class.php'); + + $feed = new Feed('http://code.iki.fi/builds/events.rss', 3); + $feed->setTitle('Build News via RSS', 'projectnews-label'); + $feed->setGenerateElementHTMLCallback('FrontController::generateBuildFeedItemHtml'); + $feed->generateHTML(); } private function outputServerStatus() @@ -340,6 +369,8 @@ public function endPage() $this->outputNewsFeed(); + $this->outputBuildsFeed(); + ?>