<?php
ob_start();session_start();

//include("include/db_con.php");
require_once(dirname(__FILE__).'/includes/db_connect.php');

//Include Configuration file
require_once(dirname(__FILE__).'/includes/configuration.php');

//Include Configuration file
require_once(dirname(__FILE__).'/includes/functions.php');

$url = SITEPATH;
class RSSFeed {
// VARIABLES
    // channel vars
    var $channel_url;
    var $channel_title;
    var $channel_description;
    var $channel_lang;
    var $channel_copyright;
    var $channel_date;
    var $channel_creator;
    var $channel_subject;   
    // image
    var $image_url;
    // items
    var $items = array();
    var $nritems;
    
// FUNCTIONS
    // constructor
    function RSSFeed() {
         $this->nritems=0;
        $this->channel_url='';
        $this->channel_title='';
        $this->channel_description='';
        $this->channel_lang='';
        $this->channel_copyright='';
        $this->channel_date='';
        $this->channel_creator='';
        $this->channel_subject='';
        $this->image_url='';
    }   
    // set channel vars
    function SetChannel($url, $title, $description, $lang, $copyright, $creator, $subject) {
        $this->channel_url=$url;
        $this->channel_title=$title;
        $this->channel_description=$description;
        $this->channel_lang=$lang;
        $this->channel_copyright=$copyright;
        $this->channel_date=date("Y-m-d").'T'.date("H:i:s").'+01:00';
		$this->channel_pubdate="Wed, 04 Jun 2008 01:23:52 +0000";
        $this->channel_generator=$creator;
        $this->channel_subject=$subject;
    }
    // set image
    function SetImage($url) {
        $this->image_url=$url;  
    }
    // set item
    function SetItem($url, $title, $description,$pubDate,$dccreator,$category,$guid,$content_encoded,$wfwcommentrss) {
        $this->items[$this->nritems]['url']=$url;
        $this->items[$this->nritems]['title']=$title;
        $this->items[$this->nritems]['description']=$description;
		$this->items[$this->nritems]['comments']=$url;
		$this->items[$this->nritems]['pubDate']=$pubDate;
		$this->items[$this->nritems]['dccreator']=$dccreator;
		$this->items[$this->nritems]['category']=$category;
		$this->items[$this->nritems]['guid']=$guid;
		$this->items[$this->nritems]['content_encoded']=$content_encoded;
		$this->items[$this->nritems]['wfwcommentrss']=$wfwcommentrss;
		
        $this->nritems++;   
    }
    // output feed
    function Output() {
        $output =  '<?xml version="1.0" encoding="iso-8859-1"?>'."\n";
		$output .=  '<rss version="2.0"'."\n";
		$output .=  'xmlns:content="http://purl.org/rss/1.0/modules/content/"'."\n";
		$output .=  'xmlns:wfw="http://wellformedweb.org/CommentAPI/"'."\n";
		$output .=  'xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
		$output .=  '>'."\n";
		
        $output .= '<channel>'."\n";
        $output .= '<title>'.$this->channel_title.'</title>'."\n";
        $output .= '<link>'.$this->channel_url.'</link>'."\n";
		$output .= '<description>'.$this->channel_description.'</description>'."\n";
		$output .= '<pubDate>'.$this->channel_pubdate.'</pubDate>'."\n";
        $output .= '<generator>'.$this->channel_generator.'</generator>'."\n";
        $output .= '<language>en</language>'."\n";
		
		for($k=0; $k<$this->nritems; $k++) {
            $output .= '<item>'."\n";
            $output .= '<title>'.$this->items[$k]['title'].'</title>'."\n";
            $output .= '<link>'.$this->items[$k]['url'].'</link>'."\n";
			/*$output .= '<comments>'.$this->items[$k]['url'].'</comments>'."\n";*/
			$output .= '<pubDate>'.$this->items[$k]['pubDate'].'</pubDate>'."\n";
			$output .= '<dc:creator><![CDATA['.$this->items[$k]['dccreator'].']]></dc:creator>'."\n";
			$output .= '<category><![CDATA['.$this->items[$k]['category'].']]></category>'."\n";
			$output .= '<guid isPermaLink="false">'.$this->items[$k]['guid'].'</guid>'."\n";
            $output .= '<description><![CDATA['.$this->items[$k]['description'].']]></description>'."\n";
			$output .= '<content:encoded><![CDATA['.$this->items[$k]['content_encoded'].']]></content:encoded>'."\n";
			$output .= '<wfw:commentRss>'.$this->items[$k]['wfwcommentrss'].'</wfw:commentRss>'."\n";
            $output .= '</item>'."\n";  
        };

		$output .= '</channel>'."\n";
		$output .= '</rss>'."\n";
        return $output;
    }
};


$myfeed = new RSSFeed();
$myfeed->SetChannel("$url/rssfeed.xml",
          'Bronx Locksmiths Articles',
                  '',
          'en-us',
          'My copyright text',
                  $url,
          'News Feed');
		  
$myfeed->SetImage("$url/images/logo.jpg");

//$qry_rss = mysql_query("select DATE_FORMAT(updatedon, '%D %M %Y') as up,tbl_resource_title.* from tbl_resource_title order by resourceid asc");
$qry_rss = mysql_query("select DATE_FORMAT(news_date, '%D %M %Y') as up,lock_news.* from lock_news order by id desc");

while($row_rss = mysql_fetch_array($qry_rss)) 
{
 
$rss_id = $row_rss["id"];
$rss_url = "$url/newsdetails-locksmiths.php?newsid=".base64_encode($rss_id);
$published_date = $row_rss["news_date"]; 
$author_name = "";
$CaseCategoryName = $row_rss["news_heading"];
$description = strip_tags($row_rss["meta_description"]);
//$title = str_replace(" ","_",htmlspecialchars($row_rss["CaseTitle"]));
$title =  trim($row_rss["news_heading"]);

	$myfeed->SetItem($rss_url, $title, $description, $published_date, $author_name,$CaseCategoryName,$rss_url, $html_description1,$url.'/rssfeed.xml');
 
}

//header('Content-Type: text/html; charset=iso-8859-1');
//header('Content-Type: text/html; charset=utf-8');
$rss_data = $myfeed->output();
//exit;
$fp=fopen("rssfeed.xml","w");
fwrite($fp,$rss_data);
fclose($fp); 

/*echo $rss_data = $myfeed->output();*///header("Location:xml.rss");

ob_flush();
header('Content-Type: text/xml');
echo $rss_data;
?>