<?php 
// ------------------------------------------------------------------------ //
// Coppermine Photo Gallery - RSS Feed                                      //
// ------------------------------------------------------------------------ //
// Copyright (C) Dr. Tarique Sani                                           //
// http://tariquesani.net/                                                  //
// modifications by versus7 - www.oixalia.gr - oixalia@oixalia.gr           //
// further modifications by Brent Gerig                                     //
// ported to cpg 1.5 by Kevin Robnett                                       //
// 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.                                      //
// Modfied by FF to be used with Kodak W1020 - incomplete
// ------------------------------------------------------------------------ //
// Plugin will install in main Coppermine directory                         //
// ------------------------------------------------------------------------ //

define('IN_COPPERMINE', true);
define('INDEX_PHP', true);

global $CONFIG,$ALBUM_SET,$META_ALBUM_SET,$CURRENT_CAT_NAME,$FORBIDDEN_SET_DATA,$lang_plugin_easyrss;
require('include/init.inc.php');
require('plugins/easy_rss/include/init.inc.php');
$superCage = Inspekt::makeSuperCage();

//How many items you want to show in RSS feed
$thumb_per_page = $CONFIG[plugin_easyrss_num];

$thumb_count = 0;
$lower_limit = 0;

if(count($FORBIDDEN_SET_DATA2) > 0 ){
    $forbidden_set_string =" AND aid NOT IN (".implode(",", $FORBIDDEN_SET_DATA).")";
} else {
    $forbidden_set_string = '';
}

if ($superCage->get->keyExists('album')) {
    $album = $superCage->get->getEscaped('album');
}

//If it is a numeric album get the name and set variables
if ((is_numeric($album))){
     $album_name_keyword = get_album_name($album);
     $CURRENT_CAT_NAME = $album_name_keyword['title'];
     $META_ALBUM_SET = "AND aid IN (".(int)$album.")".$ALBUM_SET;

     //Set the album to last uploaded
     $album = 'lastup';
}

//If the album is not set set it to lastup - this is the default
if(!isset($album)){
     $album = 'lastup';
}


if ($superCage->get->keyExists('cat') && ($superCage->get->getEscaped('cat') > 0)){ 
     $cat = $superCage->get->getEscaped('cat');
     $album_name_keyword = easyrss_get_cat_name($cat);
     $CURRENT_CAT_NAME = $album_name_keyword['name'];
     
     get_meta_album_set($cat,$META_ALBUM_SET);
}


if ($superCage->get->keyExists('cat') && ($superCage->get->getEscaped('cat') < 0)){ 
     $cat = $superCage->get->getEscaped('cat');
     $album_name_keyword = get_album_name(-$cat);
     $CURRENT_CAT_NAME = $album_name_keyword['title'];
     
     $META_ALBUM_SET = "AND aid IN (".-$cat.")".$ALBUM_SET;
}

//Changes these to point to your site if the following is not giving correct results.
$link_url = $CONFIG['ecards_more_pic_target']."displayimage.php?pos=-";
$image_url = $CONFIG['ecards_more_pic_target']."albums/";

$META_ALBUM_SET .= $forbidden_set_string;

$data = get_pic_data($album, $thumb_count, $album_name, $lower_limit, $thumb_per_page);

header ("content-type: text/xml");
//maybe you must change the encoding to iso-8859-1.
$rssHeader = <<<EOT
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
    <title>$CONFIG[gallery_name]: $CONFIG[gallery_description] - $album_name</title>
    <link>$CONFIG[ecards_more_pic_target]</link>
    <description>$CONFIG[gallery_description] - $album_name</description>
    <generator>$CONFIG[ecards_more_pic_target]rss.php</generator>
<ttl>5</ttl>
EOT;
echo $rssHeader;

foreach($data AS $picture) {

    $titlefield = $CONFIG[plugin_easyrss_titlefield];
    $caption_text = "<br>".$picture[hits]." ".$lang_plugin_easyrss['views'];
    $caption_text .= "<br>".date('M d, Y',$picture[ctime]);
    
    $thumb_url = "$image_url$picture[filepath]$CONFIG[normal_pfx]$picture[filename]";
    $keywords = explode(" ",trim($picture[keywords]));
    $category_string = "";
    foreach($keywords as $keyword){
         $category_string .= "<category>$keyword</category>";
    }
    $pubDate = gmdate("D, d M Y H:i:s", $picture[ctime]);
    
    $item = '<item><media:content url="' . $thumb_url. '" type="image/jpeg"> </media:content></item>';

    echo $item;
}

$rssFooter = <<<EOT
</channel>
</rss>
EOT;
echo $rssFooter;

?>
