<?php // $Id: index.php,v 1.2 2004/02/04 01:35:19 jerrett Exp $
header("Content-type: text/xml");
require_once(".get_userinfo.php");

if (file_exists($data_path.'feed.rss'))
{
	readfile($data_path.'feed.rss');
}
else
{
	ob_start();
 	echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>

<rss version="2.0">
 <channel>
	<title><![CDATA[<?= strip_tags($App->Client->GetOption('title')); ?>]]></title>
	<link>http://<?= $_SERVER["HTTP_HOST"]; ?></link>
	<ttl>30</ttl>
	<description><![CDATA[<?= strip_tags($App->Client->GetOption('description')); ?>]]></description>
	<generator>Bravenet Web Journal</generator>
<?

// get entries from db
$sql = "select *, UNIX_TIMESTAMP(posted) as utimestamp from journal_entries where usernum = '".$App->Client->GetValue('usernum')."' order by posted desc limit 0, 10";
$res = $App->DB->Select($sql);

// build array of journal entries & their data
while ($row = $App->DB->FArray($res,MYSQL_ASSOC))
{

?>
	<item>
		<title><![CDATA[<?=  $App->Filter->Run($row['title'],array('striphtml' => true)); ?>]]></title>
		<link>http://<?= $_SERVER["HTTP_HOST"]; ?>/entry/<?= $row['id']; ?>/</link>
		<description><![CDATA[<?= $App->Filter->Run($row['content'],array('striphtml' => true, 'truncate' => array('length' => 180, 'endchar' => '...'))); ?>]]></description>
		<pubDate><?=  gmdate('r',($row['utimestamp']+($App->Client->userinfo['tzone']*3600))); ?></pubDate>
	</item>
<?	
	
	$entries[$row['id']] = array
	(
		'date'				=> $row['formated_date'],
		'time'				=> $row['formated_time'].$time_extra,
		'title'				=> $row['title'],
		'content'			=> nl2br($row['content']),
		'num_comments'		=> number_format($row['num_comments']),
		'response1'			=> $row['response1'],
		'response2'			=> $row['response2'],
		'response3'			=> $row['response3'],
		'response4'			=> $row['response4'],
		'comment_privacy'	=> $row['comment_privacy'],
		'showItems'			=> (($row['response1'] && $App->Client->GetOption('custom1')) || ($row['response2'] && $App->Client->GetOption('custom2')) || ($row['response3'] && $App->Client->GetOption('custom3')) || ($row['response4'] && $App->Client->GetOption('custom4'))) ? true : false
	);	
}
?>
 </channel>
</rss>
<?
	$rss = ob_get_contents();
	ob_clean();
	
	// Journal Object
	$journalObj = $App->CreateObject('BN_Journal');
	$journalObj->updateCachedFeed($rss);
	
	#FIXME Remove from file
	/*$out = fopen($data_path.'feed.rss','w+');
	fwrite($out,$rss);
	fclose($out);*/		
	
	echo $rss;
}
?>