blob: 4ab9cfc010ea360a5c383880ea3c32c3b49803b4 [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'] . "/callisto/scripts/" . $news_file;
$handler = new RssFileHandler();
parse_xml_file($file_name, $handler);
return $handler->feed;
}
function rss_to_html($file_name, $count=3) {
$rss = get_news($file_name);
ob_start();
foreach ($rss->channel as $channel)
{
?>
<div class="homeitem noMarginRight">
<h3><?=$channel->title;?>
<a href="news.php"><img src="/images/more.gif"></a></h3>
<ul>
<?
foreach ($channel->item as $item)
{
if ($count == 0) break;
$then = $item->pubDate;
$stringDate = date("M d, Y", $then);
?>
<li><a href="<?=$item->link;?>"><?=$item->title;?></a></li>
<?
$count--;
}
?> </div><?
}
$html = ob_get_contents();
ob_end_clean();
return $html;
}
function rss_to_html_verbose($file_name, $count=3) {
$rss = get_news($file_name);
ob_start();
foreach ($rss->channel as $channel)
{
?>
<h3><a href="/callisto/scripts/whatsnew.rss"><img src="/images/rss.gif" align="right" title="RSS Feed" alt="[RSS]" /></a><?=$channel->title;?></h3><br/>
<ul>
<?
foreach ($channel->item as $item)
{
if ($count == 0) break;
$then = $item->pubDate;
$stringDate = date("M d, Y", $then);
?>
<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;
}
/*
* 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;
}
/*
* 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() {
return new RssRootHandler();
}
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 <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;
}
}
?>