<?php
/********************************************************************************
 * File: rss.php
 * Desc: Returns RSS v0.92 feed for last 20 flickr photos.
 * 
 * Change   Date        By          Description
 * 1        05/13/2007  mcarruth    Created
 ********************************************************************************/
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
echo "<rss version='0.92'>";

require_once('photo.php');
require_once('user.php');

$photos = $photo->get_user_photos(null, null, null, null, 10, 1);          	
$userInfo = $user->get_info();

//
// Boiler-plate RSS info
//
echo "
<channel>
   <title>" . htmlspecialchars(SITE_TITLE , ENT_QUOTES) . "</title>
   <link>" . htmlspecialchars(SITE_URL, ENT_QUOTES) . "</link>
   <description>" . htmlspecialchars(SITE_DESCRIPTION, ENT_QUOTES) . "</description>
   <pubDate>" . date(DATE_RFC2822) . "</pubDate>
   <lastBuildDate>" . date(DATE_RFC2822) . "</lastBuildDate>
   <image>
      <url>http://farm" . $userInfo['iconfarm'] . ".static.flickr.com/" . $userInfo['iconserver']. "/buddyicons/" . $userInfo['nsid'] . ".jpg</url>
      <title>" . htmlspecialchars(SITE_TITLE, ENT_QUOTES) . "</title>
      <link>" . htmlspecialchars(SITE_URL, ENT_QUOTES) . "</link>
   </image>";

//
// Generate items for the last 10 photos
//
foreach ($photos['photo'] as $p) {
	$photoInfo = $photo->get_photo_info( $p['id'] );
	$date = $photo->get_dateposted( $p['id'] );
	$photoURL = htmlentities("<a href='" . SITE_URL . "/index.php?photoId=" . $p['id'] . "'>");
	$photoURL .= htmlentities($photo->get_img($p['id'], "Medium"));
	$photoURL .= htmlentities("</a>");

	echo "
   <item>
      <title>" . $photo->get_title( $p['id'] ) . "</title>
      <link>" . SITE_URL . "/index.php?photoId=" . $p['id'] . "</link>
      <description>" . $photoURL . "&lt;p&gt;" . $photo->get_description( $p['id'] ) . "&lt;/p&gt;&lt;p&gt;" . $date . "&lt;/p&gt;</description>
   </item>";
}

echo "
</channel>
</rss>";

?>