<?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<rss version="2.0">
	<channel>
		<title>Final Fantasy Union</title>
		<link>http://www.finalfantasyunion.com/</link>
		<description>Final Fantasy Union is the ultimate Final Fantasy resource. Whether you're looking for up to date news or awesome features, you won't find more detailed information anywhere else.</description>
		<language>en-us</language>
<?php
// connect to database
include 'includes/database.php';

// grab the latest news articles
$query = mysqli_query("SELECT * FROM `news` WHERE live = 1 ORDER BY timestamp DESC LIMIT 20") or die(mysqli_error());

while($data = mysqli_fetch_array($query, MYSQL_ASSOC)) {
	$pubdate = date('D, j M Y H:i:s T', $data['timestamp']);
	$title = htmlentities($data['title']);
	$url = $data['url'];
	
	// [content]
	$description = preg_replace('/(\<)(?!br(\s|\/|\>))(.*?\>)/', '', $data['content']);
	
	if(strpos($description, '<br />') === false)
		$length = strlen($description);
	else
		$length = strpos($description, '<br />');
	
	// [img]
	$customimg = $data['customimg'];
	$img = $data['url'];
	
	if($customimg == 1)
		$img = $url;
	
	// [url]
	$type = $data['type'];
	
	if($type == 'podcast')
		$url = 'http://www.finalfantasyunion.com'.$data['exteurl'];
	else
		$url = 'http://www.finalfantasyunion.com/'.$data['type'].'/'.$data['id'].'/'.$data['url'].'/';
?>	
		<item>
			<title><?php=$title?></title>
			<link><?php=$url?></link>
			<guid><?php=$url?></guid>
			<pubDate><?php=$pubdate?></pubDate>			
			<description><![CDATA[<img style="border: 1px solid #a2a2a2; float: left; height: 70px; margin: 0px 11px 1px 0px;" src="http://www.finalfantasyunion.com/newsimg/<?=$img?>.jpg" /><?=str_replace('&', '&amp;', substr($description, 0, $length))?>]]></description>
		</item>
<? } ?>
	</channel>
</rss>