<?php
header('Content-type: text/xml'); 

{
$todays_date=date('D, d M Y H:i:s'); 
}

### Include necessary files
# Include the site's config file
include "../includes/config.php"; 


### Include file to connect to the database
include("$dbconnect_directory/$dbconnect/$dbconnect_file");

### Query the blog information

$blog_query = "SELECT b.id,b.title,b.date,b.text,b.image,b.caption,b.alt_tag,a.id,a.author,a.email FROM blog b, blog_authors a WHERE b.author = a.id AND b.active = 'yes' AND a.active = '1' AND b.date <= '$today'  ORDER BY date DESC LIMIT 20";

$blog_list = '';

$blog_result = mysql_query("$blog_query",$db);
while ($blog_array = mysql_fetch_row($blog_result)) {
	$blog_id = $blog_array[0];
	$blog_title = $blog_array[1];
	$blog_date = $blog_array[2];
	$blog_text = $blog_array[3];
	$blog_image = $blog_array[4];
	$blog_caption = $blog_array[5];
	$blog_alt_tag = $blog_array[6];
	$blog_author_id = $blog_array[7];
	$blog_author_name = $blog_array[8];
	$blog_author_email = $blog_array[9];

### Make sure text fields insert line breaks at returns
$blog_text = nl2br($blog_text);

### Remove line breaks from lists
$blog_text = str_replace("<UL><br />", "<UL>",$blog_text);

$blog_text = str_replace("<br />\r\n<LI>", "<LI>",$blog_text);

$blog_text = str_replace("<br />\r\n</UL>", "</UL>",$blog_text);

### Add headline tags
$blog_text = str_replace('<subh>', '<span class="subh">',$blog_text);

### Add close headline tags
$blog_text = str_replace('</subh>', '</span>',$blog_text);

$blog_text = $blog_text.'<br /><br />[<a href="http://greenbeltmovement.org/blog/entry.php?id='.$blog_id.'#comments">Read and post comments at greenbeltmovement.org</a>]';

if ($blog_caption != '') {
$blog_caption_display = '<br>['.$blog_caption.']';
}
else {
$blog_caption_display = '';
}

//format date for printing
list($blog_split_date,$blog_split_time) = split(' ',$blog_date); 
list($blog_year,$blog_month,$blog_day) = split('-',$blog_split_date); 
list($blog_hour,$blog_minute,$blog_second) = split(':',$blog_split_time); 

/* START DAYLIGHT SAVINGS TIME HACK */
if ( ($blog_month >= 4) AND ($blog_month <= 11)) {
$blog_hour = ($blog_hour + 1);
}
/* END DAYLIGHT SAVINGS TIME HACK */

//Remove the '-' from the standar MySQL sate format
$stampeddate = mktime($blog_hour,$blog_minute,$blog_second,$blog_month,$blog_day,$blog_year); 
//Create a UNIX style timestamp from the result
$blog_date = date("D, d M Y H:i:s T",$stampeddate); 

if ($blog_image != '') {


list($blog_image_width, $blog_image_height, $image_type, $image_w) = getimagesize('/home/booklight/www/greenbeltmovement.org/blog/images/'.$blog_image);

$image_code = '
<p>
<img src="http://greenbeltmovement.org/blog/images/'.$blog_image.'" alt="'.$blog_alt_tag.'" height="'.$blog_image_height.'" width="'.$blog_image_width.'" />
'.$blog_caption_display.'</p>';
}
else {
$image_code = '';
}

	$blog_list = $blog_list.'<item>
<title><![CDATA[
'.$blog_title.'
]]></title>

<description><![CDATA[
'.$image_code.$blog_text.'
]]></description>
<pubDate>'.$blog_date.'</pubDate>
<author>'.$blog_author_email.' ('.$blog_author_name.')</author>
<guid isPermaLink="true"><![CDATA[
http://www.greenbeltmovement.org/blog/entry.php?id='.$blog_id.'
]]></guid>
<link><![CDATA[
http://www.greenbeltmovement.org/blog/entry.php?id='.$blog_id.'
]]></link>
</item>';
	
	
	}
	$blog_list = $blog_list;
?>

<rss version="2.0">
<channel>
 
<title>The Green Belt Movement Blog</title>
<link>http://www.greenbeltmovement.org/</link>
<description>The Green Belt Movement blog.</description>
<language>en-us</language>
<lastBuildDate><?php echo $todays_date; ?> -0500</lastBuildDate>
<copyright>Copyright The Green Belt Movement</copyright>

<image>
<title>The Green Belt Movement Blog</title>
<url>http://www.greenbeltmovement.org/images/minicon.gif</url>
<link>http://www.greenbeltmovement.org/</link>
<width>16</width>
<height>16</height>
</image>
<?php
echo $blog_list;
?>
</channel>
</rss>
