<?php require_once('../Connections/conn.php'); ?>
<?php
  
  include("FeedWriter.php");
  
  //Creating an instance of FeedWriter class. 
  //The constant RSS2 is passed to mention the version
  $TestFeed = new FeedWriter(RSS2);
  
  //Setting the channel elements
  //Use wrapper functions for common channel elements
  $TestFeed->setTitle('Baroda Online');
  $TestFeed->setLink('http://www.Baroda.com/');
  $TestFeed->setDescription('Baroda News');
  
  //Image title and link must match with the 'title' and 'link' channel elements for RSS 2.0
  //$TestFeed->setImage('Testing the RSS writer class','http://www.ajaxray.com/projects/rss','http://www.rightbrainsolution.com/images/logo.gif');
  
  //Use core setChannelElement() function for other optional channels
  $TestFeed->setChannelElement('language', 'en-us');
  $TestFeed->setChannelElement('pubDate', date(DATE_RSS, time()));
  
  //Adding a feed. Genarally this portion will be in a loop and add all feeds.
  
  //Create an empty FeedItem
 // $newItem = $TestFeed->createNewItem();
  
  //Add elements to the feed item
  //Use wrapper functions to add common feed elements
  //$newItem->setTitle('The first feed');
 //$newItem->setLink('http://www.yahoo.com');
  //The parameter is a timestamp for setDate() function
  //$newItem->setDate(time());
 // $newItem->setDescription('This is test of adding CDATA Encoded description by the php <b>Universal Feed Writer</b> class');
  //$newItem->setEncloser('http://www.attrtest.com', '1283629', 'audio/mpeg');
  //Use core addElement() function for other supported optional elements
  //$newItem->addElement('author', 'admin@ajaxray.com (Anis uddin Ahmad)');
  //Attributes have to passed as array in 3rd parameter
 // $newItem->addElement('guid', 'http://www.ajaxray.com',array('isPermaLink'=>'true'));
  
  //Now add the feed item
  //$TestFeed->addItem($newItem);
  
  //Another method to add feeds from array()
  //Elements which have attribute cannot be added by this way
  
  function convert_smart_quotes($string) 
	{ 
		$search = array(chr(145), 
						chr(146), 
						chr(147), 
						chr(148), 
						chr(151),
						"�"); 
	
		$replace = array("'", 
						 "'", 
						 '"', 
						 '"', 
						 '-',
						 '-'); 
	
		$count=1;
		//$string=iconv("UTF-8", "ISO-8859-1//IGNORE", $string);
		$string=str_replace('  ', ' ', $string,$count);
		return str_replace($search, $replace, $string); 
	}
  
  mysql_select_db($database_conn, $conn);

	$sql = "SELECT title, news_desc as description, id, upload_date,bn_ib  FROM news where active=1 ORDER BY ord ASC,upload_date DESC";

	$article_array = mysql_query($sql) or die(mysql_error());;


$barodanews_page_limit=30;
$indianbriefs_page_limit=20;

$barodanews_index=1;
$indianbriefs_index=1;

while ($articleInfo = mysql_fetch_object($article_array))
{
	if($articleInfo->bn_ib=='Baroda News')
	{
		if($barodanews_index<=$barodanews_page_limit)
		{
			$page_name="barodanews.php";
		}
		else
		{
			$page_name="barodanews_archive.php";
		}
		$barodanews_index++;	
	}
	else
	{
		if($indianbriefs_index<=$indianbriefs_page_limit)
		{
			$page_name="indianbriefs.php";
		}
		else
		{
			$page_name="indianbriefs_archive.php";
		}
		$indianbriefs_index++;	
	}
	
	$newItem = $TestFeed->createNewItem();
	$newItem->setDate($articleInfo->upload_date);
  $newItem->addElementArray(array('title'=>convert_smart_quotes($articleInfo->title), 'link'=>"http://www.baroda.com/".$page_name."#".	$articleInfo->id, 'description'=>convert_smart_quotes($articleInfo->description)));
  $TestFeed->addItem($newItem);
} 
  
  
  //OK. Everything is done. Now genarate the feed.
 $TestFeed->genarateFeed();

  
?>
