<?php header('Content-type: text/xml'); require_once('_includes/db.inc'); ?>
<rss version="2.0">
<channel>
<title>Missouri Press Association</title>
<description>Missouri Press Association News affecting newspapers from business, personnel, and advertising trends.</description>
<link>http://mopress.com</link>
<copyright>2009 Missouri Press Association</copyright>

<?php

$sql = "SELECT 'association.php' AS bloglink, title, date, body, blog_id FROM blog_association  
		UNION SELECT 'service.php' AS bloglink, title, date, body, blog_id FROM blog_service  
		UNION SELECT 'legal.php' AS bloglink, title, date, body, blog_id FROM blog_legal  
		UNION SELECT 'foundation.php' AS bloglink, title, date, body, blog_id FROM blog_foundation  
		UNION SELECT 'legislative.php' AS bloglink, title, date, body, blog_id FROM blog_legislative 
		UNION SELECT 'nienews.php' AS bloglink, title, date, body, blog_id FROM blog_nienews 
		ORDER BY date DESC LIMIT 20";

$rs = mysql_query($sql);

while ( $row = mysql_fetch_array($rs) ) {

	$body = $row['body'];
	$body = htmlentities(strip_tags($row['body'],'<br><a><p>'));
	$category = ucfirst(str_replace(".php", "", $row['bloglink']));
	$media ="";
	
	preg_match_all('/<img[^>]* src=[\'"]?([^\'"]+)["\']?[^>]*>/i', $row['body'], $matches, PREG_SET_ORDER);

	foreach ($matches as $val) {
		$media .= "<enclosure url='http://mopress.com/".$val[1]."'  type='image/jpeg' />";
	}

	 echo"	<item>
        		<title>".htmlentities(strip_tags($row['title']))."</title>
        		<description>$body</description>
        		<link>http://mopress.com/". $row['bloglink'] ."?blog_id=" . $row['blog_id'] ."</link>
        		<pubDate>". date("r", $row["date"])."</pubDate>
        		<category>$category</category>
        		$media
     		</item>"; 
} 
?>  
</channel>
</rss>
