<?php
//
// 	Coppermine RSS 2.0 Generator (1.0)
//	displays latest photo via RSS 2.0 feed.
// 	Compatible with : Coppermine 1.3.x
//
//	Hacked at : 22 October 2005, 0400 +0800
//
//	Copyright (C) 2005 Mohammad Hafiz bin Ismail (mypapit)
//
//	This program is free software; you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation; either version 2 of the License, or
//	(at your option) any later version.
//
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with this program; if not, write to the Free Software
//	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//
//	Report problems and direct all questions to:
//
//	<mypapit@gmail.com>
//
//	For latest version of this software, please visit :
//
//	http://mypapit.net/pproject
//	http://blog.mypapit.net/
//
//	authors email : mypapit@gmail.com, papit01@lycos.com
//
//
//	Modified by Wieland E. Kublun www.kublun.com on 29/September/2006
//
//	Now this mod displays the album's title and description

$upperlimit = 6; //default = 6


define('INC_COMMENT_TIMES', false);
define('FILEDUMP', false);
define('GZ_COMPRESS', false);
// [0.0 <= priority <= 1.0]
define('P_DISPLAYIMAGE', 0.5);
define('P_ALBUM', 0.5);
define('P_CATEGORY', 0.5);

// [changefreq = always || hourly || daily || weekly || monthly || yearly || never]
define('CF_DISPLAYIMAGE', 'unspecified');
define('CF_ALBUM', 'unspecified');
define('CF_CATEGORY', 'unspecified');

define('IN_COPPERMINE', true);
require('include/init.inc.php');

// This should work as it is, but hardcode if necessary.
define('CPG14', version_compare(COPPERMINE_VERSION, "1.4.0", ">="));
define('PHP5', version_compare(phpversion(), "5", ">="));
$base = rtrim($CONFIG['ecards_more_pic_target'], '/');
$albumpath = "$base/" . $CONFIG['fullpath'];

function lmdate($timestamp)
{
	if (PHP5){
		return date('c', $timestamp);
	} else {
		return date('D, d M Y H:i:s +0800', $timestamp - date('Z'));
	}
}

// No user servicable parts below here

header("Content-type: text/xml; charset=utf-8");
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
print "<rss version=\"2.0\">";
print "<channel>\n";
print "<title>{$CONFIG['gallery_name']}</title>\n";
print "<link>$base</link>\n";
print "<description>{$CONFIG['gallery_description']}</description>";
print "<language>es-MX</language>\n";
print "<lastBuildDate>"  . lmdate(time()) . "</lastBuildDate>\n";
print "<generator>Coppermine RSS 2.0 Generator (1.0)</generator>\n";
    
    

$result = mysql_query("SELECT  tb.pid,tb.aid,ta.aid,ta.description,tb.ctime,ta.title,tb.keywords,tb.filepath,tb.filename FROM {$CONFIG['TABLE_PICTURES']} tb LEFT OUTER JOIN {$CONFIG['TABLE_ALBUMS']} ta ON tb.aid = ta.aid ORDER BY tb.pid DESC LIMIT 0,$upperlimit");
while (list($pid, $aid,$aaid,$desc, $ctime, $title, $keywords,$filepath,$filename) = mysql_fetch_row($result)) {
	print "\t<item>\n";
	print "\t\t<title> $title </title>\n";
	print "\t\t<link>$base/displayimage.php?pos=-$pid</link>\n";
	print "\t\t<author>{$CONFIG['gallery_admin_email']}</author>\n";
        print "\t\t<pubDate>" . lmdate($ctime) . "</pubDate>\n";
        print "\t\t<description>";
        echo  htmlentities("<p><a href=\"$base/displayimage.php?pos=-$pid\"><img src=\"$albumpath$filepath" . "thumb_$filename\" alt=\"\" border=\"0px\" /></a></p>"); echo "<a href=\"$base/displayimage.php?pos=-$pid\">$title</a><br/><br/><br/>$desc<p>$keywords</p>";
        print "</description>\n";
	print "\t</item>\n";
	print "\n";
}
print "</channel>";
print "</rss>";