<?php

	error_reporting(E_ALL|E_STRICT);
	date_default_timezone_set('Europe/London');
	
	// Define path to application directory
	defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));

	// Define application environment
	defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
	
	
	require_once 'Zend/Application.php';

	// Create application, bootstrap, and run
	$application = new Zend_Application(
    	APPLICATION_ENV, 
    	APPLICATION_PATH . '/configs/application.ini'
	);
	
	$aConfig = $application->getOptions();
	
	$stevegriffDb = Zend_Db::factory($aConfig['stevegriffDatabase']['adapter'], $aConfig['stevegriffDatabase']['params']);
	Zend_Registry::set('stevegriffDb', $stevegriffDb);
			
	$articleTable = new SteveGriffDotCom_Article(array('db' => 'stevegriffDb'));
			
	$reviews = $articleTable->getArticleNames();
	
	$rssEntries = array();
	
	foreach($reviews as $review) {
	
		$linkName = strtolower(str_replace(' ', '-', $review->name));
		$dateObject = new Zend_Date($review->publishDate, 'yyyy-MM-dd HH:mm:ss');
		$link = 'http://www.stevegriff.com/cigars/reviews/' . $dateObject->toString('yyyy') . '/' . $dateObject->toString('MM') . '/' . $dateObject->toString('dd') . '/' . $linkName . '/';
	
		$entry = array(
			'title'		=> 'Cigar Review: ' . $review->name,
			'link'		=> $link,
			'category'  => array(array('term' => 'Cigars')),
			'pubDate'	=> date(DATE_RSS),
			//$dateObject->get(Zend_Date::RSS),
			'description' => $review->description
		);
		
		array_push($rssEntries, $entry);
	
	}

	$rss = array(
		'title' 	=> 'Reviews, Articles and Blog Entries from SteveGriff.com',
		'link'		=> 'http://www.stevegriff.com/rss/site.xml',
		'charset'	=> 'UTF-8',
		'generator' => 'Zend Framework Using Zend_Feed',
		'description' => 'Welcome to my personal website. Here you will find articles, reviews and opinions about <strong>Quality Assurance</strong>, <strong>Linux</strong>, <strong>Web Technology</strong>, <strong>Music</strong> &amp; <strong>Cuban Cigars</strong>.',
		'entries'	=> $rssEntries
	);
	
	$feed = Zend_Feed::importArray($rss, 'rss');
	
	$rssFeed = $feed->saveXML();
	
	echo $rssFeed;

?>