Skip to content

Commit

Permalink
Homepage: Added a short summary of the latest build events
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danij-deng committed Feb 27, 2012
1 parent a287e5b commit c1e3ed6
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 31 deletions.
106 changes: 78 additions & 28 deletions web/classes/feed.class.php
Expand Up @@ -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.
*/
Expand All @@ -56,42 +79,69 @@ 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 = '<a href="'. preg_replace('/(&)/', '&amp;', $item['link'])
.'" title="'. date("m/d/y", $item['date_timestamp']) .' - '. htmlspecialchars($item['title'])
.'">'. htmlspecialchars($item['title']) .'</a>';
return $html;
}

public function generateHTML()
{
if(count($this) > 0)
{
?>
<a href="<?php echo preg_replace('/(&)/', '&amp;', $this->_feedURL); ?>" class="link-rss" title="Project News, via RSS"><span class="hidden">RSS</span></a>&nbsp;<span id="projectnews-label">Latest Project News </span>
<ul>
<?php

?><a href="<?php echo preg_replace('/(&)/', '&amp;', $this->_feedUri); ?>" class="link-rss" title="<?php echo htmlspecialchars($this->_title); ?>"><span class="hidden"><?php echo htmlspecialchars($this->_feedFormat); ?></span></a><?php

if(!is_null($this->_labelSpanClass))
{
?>&nbsp;<span class="<?php echo $this->_labelSpanClass; ?>"><?php
}

echo htmlspecialchars($this->_title);

if(!is_null($this->_labelSpanClass))
{
?></span><?php
}

?><ul><?php

$n = (integer) 0;
foreach($this as $item)
{
?>
<li><a href="<?php echo preg_replace('/(&)/', '&amp;', $item['link']); ?>" title="<?php echo date("m/d/y", $item['date_timestamp']); ?> - <?php echo htmlspecialchars($item['title']); ?>"><?php echo htmlspecialchars($item['title']); ?></a></li>
<?php
if(++$n >= $this->_maxItems)
break;
$elementHtml = $this->generateElementHTML($item);

?><li><?php echo $elementHtml; ?></li><?php

if(++$n >= $this->_maxItems) break;
}
}
?>
</ul>
<?php

?></ul><?php
}

public function url()
{
return $this->_feedURL;
return $this->_feedUri;
}

/**
* Implements Countable.
*/
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;
}

Expand All @@ -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()
Expand All @@ -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]);
}
}
35 changes: 33 additions & 2 deletions web/classes/frontcontroller.class.php
Expand Up @@ -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 = '<a href="'. preg_replace('/(&)/', '&amp;', $item['link'])
.'" title="'. ('Read more about '. htmlspecialchars($item['title']) .', completed on '. date("m/d/y", $item['date_timestamp']))
.'">'. htmlspecialchars($item['title']) .' complete</a>';

if(time() < strtotime('+2 days', $item['date_timestamp']))
{
$html .= '<span class="new-label">&nbsp;NEW</span>';
}

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()
Expand Down Expand Up @@ -340,6 +369,8 @@ public function endPage()

$this->outputNewsFeed();

$this->outputBuildsFeed();

?> </div><?php

?> <div id="servers"><?php
Expand Down
8 changes: 7 additions & 1 deletion web/style.css
Expand Up @@ -475,7 +475,7 @@ p.legal a {

/*---------------------- NewsFeed ---------------------*/

#projectnews-label {
.projectnews-label {
color: #ffffff;
font-weight: bold;
min-height: 139px;
Expand Down Expand Up @@ -508,8 +508,14 @@ p.legal a {
color: #ff8a00;
}

#projectnews .new-label {
color: white;
font-weight: bold;
}

#projectnews a:hover, #projectnews a:visited:hover {
color: #ffffff;
font-size: x-small;
}

/*-------------------- GameServers -------------------*/
Expand Down

0 comments on commit c1e3ed6

Please sign in to comment.