<?php
// $Id: rss.php,v 1.7 2004/04/07 11:56:02 rcastley Exp $
/**
* RSS Newsfeed code
* @package Mambo Open Source
* @Copyright (C) 2000 - 2003 Miro International Pty Ltd
* @ All rights reserved
* @ Mambo Open Source is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version $Revision: 1.7 $
**/

// ensure this file is being included by a parent file
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

global $database, $mainframe, $my, $Itemid;

	$now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 );

	$menu= new mosMenu( $database );
	$menu->load( 1 );
	$params = mosParseParams( $menu->params );

	$count = isset( $params->count ) ? $params->count : 6;
	$intro = isset( $params->intro ) ? $params->intro : 3;
	$orderby = @$params->orderby;

	switch (strtolower( $orderby )) {
		case 'date':
			$orderby = "a.created";
			break;
		case 'rdate':
			$orderby = "a.created DESC";
			break;
		default:
			$orderby = "f.ordering, a.ordering ASC, a.catid, a.sectionid";
			break;
	}
	
$database->setQuery( "SELECT a.*, u.name AS author, u.usertype"
. "\nFROM #__content AS a"
. "\nINNER JOIN #__content_frontpage AS f ON f.content_id = a.id"
. "\nLEFT JOIN #__users AS u ON u.id = a.created_by"
. "\nWHERE a.state='1'"
//	. "\n	AND a.access <= $gid"
. "\n	AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now')"
. "\n	AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now')"
. "\nORDER BY $orderby"
. ($count ? " LIMIT $count" : "")
);
$rows = $database->loadObjectList();

header('Content-type: application/xml');
$encoding = split("=", _ISO);
echo "<?xml version=\"1.0\" encoding=\"".$encoding[1]."\"?>"; ?>
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"
	"http://my.netscape.com/publish/formats/rss-0.91.dtd">
<!-- Mambo Open Source 4.5 RSS Generator Version 2.07 (12/10/2003) - Robert Castley -->
<!-- Copyright (C) 2000-2003 - <?php echo $mosConfig_sitename; ?> -->
<rss version="0.91">
<channel>
<title><?php echo htmlspecialchars($mosConfig_sitename); ?></title>
<link><?php echo $mosConfig_live_site; ?></link>
<description><?php echo $option ?></description>
<language>en-us</language>
<lastBuildDate><?php $date = date("r"); echo "$date";?></lastBuildDate>
	<image>
	<title>Powered by Mambo Open Source 4.5</title>
	<url><?php echo $mosConfig_live_site; ?>/images/M_images/mos_rss.png</url>
	<link><?php echo $mosConfig_live_site; ?></link>
	<width>88</width>
	</image>
<?php
foreach ($rows as $row) {
	echo ("<item>");
	echo ("<title>".htmlspecialchars($row->title)."</title>"."\n");
	echo "<link>";
	if ($mosConfig_sef == "1"){
		echo sefRelToAbs("index.php?option=content&amp;task=view&amp;id=".$row->id);
	} else {
		echo $mosConfig_live_site . "/index.php?option=content&amp;task=view&amp;id=" . $row->id;
	}
	echo "</link>\n";
	$words = $row->introtext;
	$words = preg_replace("'<script[^>]*>.*?</script>'si","",$words);
	$words = preg_replace('/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is','\2 (\1)', $words);
	$words = preg_replace('/<!--.+?-->/','',$words);
	$words = preg_replace('/{.+?}/','',$words);
	$words = preg_replace('/&nbsp;/',' ',$words);
	$words = preg_replace('/&amp;/',' ',$words);
	$words = preg_replace('/&quot;/',' ',$words);
	$words = strip_tags($words);
	$words = htmlspecialchars($words);
	echo ("<description>".substr($words,0,100)."...</description>"."\n");
	echo ("</item>"."\n");
}
?>
</channel>
</rss>
