<? 
	header('Content-type: text/xml'); 
	require("common/lib_common.php");
	$upcoming_events_array = getEvents($db_events,'upcoming','15');
	
	$pub_date = time();
?>
<rss version="2.0">
<channel>
<title>Harvard Book Store Events</title>
<description>Harvard Book Store is a privately-owned, independent bookstore serving the university and neighborhood community since 1932.</description>
<link>http://www.harvard.com/events/</link>
<copyright>Copyright 1999-2006, Harvard Book Store Inc.</copyright>
<?
for ($j=0;$j<count($upcoming_events_array);$j++) {
	$upcoming_event = new Event();
	$upcoming_event->load($db_events,$upcoming_events_array[$j]);
	$book = new Title();
	$book->load($db_inventory,$upcoming_event->getISBN1());
		
	if ($upcoming_event->getTitle()) {
		$title = $upcoming_event->getEventDate().": ".$upcoming_event->getTitle();								
	}
	else {
		$title = $upcoming_event->getEventDate().": ".getAuthorName($db_inventory,$upcoming_event->getAuthor1_ID(),0);
		
	}
	if ($upcoming_event->getShortDescription()) {
		$description = shorten(trim($upcoming_event->getShortDescription()),20)."...";
		$description = preg_replace('/’/',"'",$description);								
	}
	else {
		$description = $book->getTitle();
		
	}
?>
 	<item> 
        <title><?=htmlentities(strip_tags($title)); ?></title> 
        <description><?=htmlentities(strip_tags($description));?></description> 
        <link>http://www.harvard.com/events/press_release.php?id=<?=$upcoming_event->getID();?></link> 
        <pubDate><?=strftime( "%a, %d %b %Y %T %Z" , $pub_date); ?></pubDate> 
     </item> 
<?	 
			
	unset($upcoming_event);
}
?>
</channel>
</rss>
<?
function shorten($paragraph, $limit) {
	$tok = strtok($paragraph, " ");
	while($tok) {
	   $text .= " $tok";
	   $words++;
	   if(($words >= $limit)||(substr($tok, -1) == "."))
		   break;
	   $tok = strtok(" ");
	}
	return ltrim($text);
} 
?>