blob: 5d8c3970d9b0dce6ae0b5a3e0c8079cd3f4e7207 [file] [log] [blame]
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/xml_sax_parsing.php");
function & get_news($file_name) {
$news_file = $file_name . ".rss";
$file_name = $_SERVER['DOCUMENT_ROOT'] . $news_file;
$handler = new RssFileHandler();
parse_xml_file($file_name, $handler);
return $handler->feed;
}
function rss_to_html($file_name) {
$rss = get_news($file_name);
ob_start();
?>
<div class="news box">
<?
foreach ($rss->channel as $channel)
{
?>
<div class="boxHeader">Related News</div>
<div class="boxBody">
<ul class="newsItems">
<?
$count = 3;
foreach ($channel->item as $item)
{
if ($count == 0) break;
$now = strtotime("now");
$then = $item->pubDate;
$stringDate = date("M d, Y H:i:s e I", $now);
$difference = $now - $then;
switch ($difference) {
case $difference > 86400:
$ago = floor($difference / 84600);
$ago = "posted $ago days ago";
break;
case $difference > 3600;
$ago = floor($difference / 3600);
$ago = "posted $ago hours ago";
break;
case $difference > 0:
$ago = floor($difference / 60);
$ago = "posted $ago minutes ago";
break;
}
?>
<li><div class="newsItem"><a href="<?=$item->link;?>"><span class="newsTitle"><?=$item->title;?></span></a></div>
<div class="newsDate"><?=$ago;?></div>
</li>
<?
$count--;
}
?>
</ul>
<div class="newsMore"><a href="submitnews.php">Submit Content</a> - <a href="whatsnew.php">Read More</a></div>
</div>
<?
}
?>
</div>
<?
$html = ob_get_contents();
ob_end_clean();
return $html;
}
function rss_to_html_verbose($file_name, $count=3, $category="") {
$rss = get_news($file_name);
ob_start();
foreach ($rss->channel as $channel)
{
?>
<h3><a href="/community/whatsnew.rss"></a>Europa News</h3><br/>
<ul>
<?
foreach ($channel->item as $item)
{
if ($count == 0) break;
$then = $item->pubDate;
$stringDate = date("M d, Y", $then);
foreach ($item->categories as $categoryIterator)
{
if ($categoryIterator == $category)
{
?>
<li>
<a href="<?=$item->link;?>"><?=$item->title;?></a> posted <?=$stringDate;?><br/><br/><?=$item->description;?><br/><br/>
</li>
<?
}
}
$count--;
}
?>
</ul><?
}
$html = ob_get_contents();
ob_end_clean();
return $html;
}
function rss_to_sideitem_html($file_name, $count=3, $category="") {
$rss = get_news($file_name);
ob_start();
foreach ($rss->channel as $channel)
{
?>
<div class="homeitem noMarginRight">
<h3><?=ucfirst($category);?> News <a href="europanews.php"><img src="/images/more.gif"></a></h3>
<ul>
<?
foreach ($channel->item as $item)
{
if ($count == 0) break;
$then = $item->pubDate;
$now = strtotime("now");
$stringDate = date("M d, Y H:i:s e I", $now);
$difference = $now - $then;
switch ($difference) {
case $difference > 86400:
$ago = floor($difference / 84600);
$ago = "posted $ago days ago";
break;
case $difference > 3600;
$ago = floor($difference / 3600);
$ago = "posted $ago hours ago";
break;
case $difference > 0:
$ago = floor($difference / 60);
$ago = "posted $ago minutes ago";
break;
}
foreach ($item->categories as $categoryIterator)
{
if ($categoryIterator == $category)
{
?><li><a href="<?=$item->link;?>"><?=$item->title;?></a> <?=$ago;?></li><?
$count--;
}
}
}
?>
</ul>
</div>
<?
}
$html = ob_get_contents();
ob_end_clean();
return $html;
}
/* Instances of the Feed class represent an RSS file.
*/
class Feed {
var $channel;
function Feed() {
$this->channel = array();
}
function add_channel(&$channel) {
array_push($this->channel, $channel);
}
}
/*
* Instances of the Channel class represent a channel in the RSS file.
*/
class Channel {
var $title;
var $link;
var $description;
var $image;
var $item;
function Channel() {
$this->item = array();
}
function add_item(&$item) {
array_push($this->item, $item);
}
}
/*
* Instances of the Image class represent an image (presumably) on an
* image. We don't currently use this information.
*/
class Image {
var $url;
var $title;
var $link;
}
/*
* Instances of the Item class represent an item in a channel.
*/
class Item {
var $title;
var $link;
var $description;
var $pubDate;
var $categories = array();
}
/*
* The rest of the code in this file is concerned with reading XML
* into an object format. Once we update to PHP 5, we can get rid of
* all of this junk and just use the simpleXML apis.
*/
/*
* The RssFileHandler represents the file being parsed. It does
* only one thing: provides a handler for the contents of the
* the file.
*/
class RssFileHandler extends XmlFileHandler {
var $feed;
/*
* This method returns the root handler for a RSS file
* The root handler essentially represents the file itself
* rather than any actual element in the file. The returned
* element handler will deal with any elements that may occur
* in the root of the XML file.
*/
function get_root_element_handler() {
$retVal = new RssRootHandler();
return $retVal;
}
function end_root_element_handler($handler) {
$this->feed = & $handler->feed;
}
}
/*
* The RssRootHandler class takes care of the root element
* in the file. This handler doesn't correspond to any particular
* element that may occur in the XML file. It represents the file
* itself and must deal with any elements that occur at the root
* level in that file.
*/
class RssRootHandler extends XmlElementHandler {
var $feed;
/*
* This method handles the <rss>...</rss> element.
*/
function & get_rss_handler($attributes) {
$retVal = new RssHandler();
return $retVal;
}
function end_rss_handler($handler) {
$this->feed = & $handler->feed;
}
}
/*
* The FeedHandler class takes care of the root element in the file.
*/
class RssHandler extends XmlElementHandler {
var $feed;
function RssHandler() {
$this->feed = new Feed();
}
/*
* This method handles the <channel>...</channel> element.
*/
function & get_channel_handler($attributes) {
$retVal = new ChannelHandler();
return $retVal;
}
function end_channel_handler($handler) {
$this->feed->add_channel($handler->channel);
}
}
class ChannelHandler extends XmlElementHandler {
var $channel;
function ChannelHandler() {
$this->channel = new Channel();
}
/*
* This method handles the <title>...</title> element.
*/
function & get_title_handler($attributes) {
$retVal = new SimplePropertyHandler($this->channel, "title");
return $retVal;
}
/*
* This method handles the <link>...</link> element.
*/
function & get_link_handler($attributes) {
$retVal = new SimplePropertyHandler($this->channel, "link");
return $retVal;
}
/*
* This method handles the <description>...</description> element.
*/
function & get_description_handler($attributes) {
$retVal = new SimplePropertyHandler($this->channel, "description");
return $retVal;
}
/*
* This method handles the <title>...</title> element.
*/
function & get_item_handler($attributes) {
$retVal = new ItemHandler();
return $retVal;
}
function end_item_handler($handler) {
$this->channel->add_item($handler->item);
}
/*
* This method handles the <image>...</image> element.
*/
function & get_image_handler($attributes) {
$retVal = new ImageHandler();
return $retVal;
}
function end_image_handler($handler) {
$this->channel->image = $handler->image;
}
}
class ItemHandler extends XmlElementHandler {
var $item;
function ItemHandler() {
$this->item = new Item();
}
/*
* This method handles the <title>...</title> element.
*/
function & get_title_handler($attributes) {
$retVal = new SimplePropertyHandler($this->item, "title");
return $retVal;
}
/*
* This method handles the <link>...</link> element.
*/
function & get_link_handler($attributes) {
$retVal = new SimplePropertyHandler($this->item, "link");
return $retVal;
}
/*
* This method handles the <description>...</description> element.
*/
function & get_description_handler($attributes) {
$retVal = new SimplePropertyHandler($this->item, "description");
return $retVal;
}
/*
* This method handles the <category>...</category> element.
*/
function & get_category_handler($attributes) {
$retVal = new SimpleTextHandler();
return $retVal;
}
function end_category_handler(& $handler) {
array_push($this->item->categories, $handler->text);
}
/*
* This method handles the <pubDate>...</pubDate> element.
*/
function & get_pubdate_handler($attributes) {
$retVal = new SimpleTextHandler();
return $retVal;
}
function end_pubdate_handler($handler) {
$value = trim($handler->text);
if (strlen($value)>0) {
$this->item->pubDate = strtotime($value);
}
}
}
class ImageHandler extends XmlElementHandler {
var $image;
function ImageHander() {
$this->image = new Image();
}
/*
* This method handles the <title>...</title> element.
*/
function & get_title_handler($attributes) {
$retVal = new SimplePropertyHandler($this->image, "title");
return $retVal;
}
/*
* This method handles the <url>...</url> element.
*/
function & get_url_handler($attributes) {
$retVal = new SimplePropertyHandler($this->image, "url");
return $retVal;
}
/*
* This method handles the <link>...</link> element.
*/
function & get_link_handler($attributes) {
$retVal = new SimplePropertyHandler($this->image, "link");
return $retVal;
}
}
?>