To be honest I don't really understand RSS - I just use it with Live Bookmarks in Firefox, not with an outside feed reader.
That said, I made this simple feed for the part of my site that uses zenphoto:
http://www.bridgetothestars.net/fanart/rss.phpAs far as I'm aware the only thing it doesn't include is the publication date, which I don't see in Live Bookmarks anyway, so it doesn't concern me!
If it's not absolute rubbish and might be of use to someone then ask here and I'll explain how I went about making it.
Comments
We've got the workings of RSS in SVN, but it was really buggy for the separate feeds and such we were trying to do, so we delayed. Hopefully we can start it up again.
I've been following your progress on RSS, but I got the impression that you'd been stalled by more complex things like publication dates and multiple albums/feeds etc. Thought I'd just make my own one, since my art area is simple enough. Good luck hammering out all the more difficult parts.
Made a cute latest page too: http://bridgetothestars.net/fanart/latest.php
I simplified the RSS to the point where it validates as a 2.0 RSS feed, and it seems to work well. The images are inserted in the item description tag in the XML using zenphoto functions. I'm fairly happy with it.
http://www.thinkdreams.com/zenphoto is the link to peruse if anyone is interested. Please be gentle. I'm learning.
What I'm wrangling with at the moment is the ability to adapt the RSS feed function I "borrowed" from the forums to display latest images. I'm having a bit of a struggle with it. If anyone has any suggestions that would be cool. What I'm having trouble with right now is where to actually place the feed so it hits the right context to pull images.
I'm thinking you should be able to pass "latest.rss" to the browser, and then it should direct to the zenphoto code where to go in the "rss" theme folder. My code is a bit of adaptation from the latest images code on the forums and the RSS code I use for the albums. I'm just not sure how to put it together to make it work properly without screwing up the context.
If you don't mind me asking, can I see a copy of your code to see how it was done? Your latest functionality is exactly what I'm trying to do, and I would like to see how yours differs. If you like I'll post my code here so you can do the same.
Bear in mind this is done totally outside of the themes and functions of zenphoto since I felt like writing my own. The RSS feed is styless of course, but you can include the style sheet if you want a latest page with the same aesthetics as your gallery. Let us begin..
First the RSS stuff:
<?php header("Content-type: text/xml"); ?>
<rss version='2.0'>
<channel>
<title>Your Art from Your Site</title>
<language>en-us</language>
<link>http://www.homepage.com/art</link>
Then open up your images database however you usually do within php - most of this is done with php btw. We select everything from the zen_images table. The fact that it's ordered by descending ID means that the newest images - which have the highest ID - will be at the top.
$query="SELECT * FROM zen_images ORDER BY `id` DESC";
$result=mysql_query($query);
mysql_close();
Put any number you want by the i; that's how many images will be in the RSS. (see later for how this can be used quite flexibly)
$i=0;
while ($i < NUMBER) {
$albumid=mysql_result($result,$i,"albumid");
$filename=mysql_result($result,$i,"filename");
$title=mysql_result($result,$i,"title");
$desc=mysql_result($result,$i,"desc");
Now I had to use a bit of trickery at this point. From the zen_images table we can get that above information for a piece of art - filename, title and desc. I don't know about you, but I just use the 'desc' field for the artist's name; it's rather unfathomable there's no space for it in zenphoto.. Anyway, you can see we're missing the album that the piece of art is in - all we have is the album ID.
I'm sure there's a way to cross-reference this with the zen_albums table and get the album title from the album ID, but I couldn't be arsed. I just cheated and put in at this point:
if ($albumid==1) {$albumtitle=lyra; }
if ($albumid==2) {$albumtitle=witches; }
etc. I only have 20 albums, so that's pretty easy - stuck the ifs in an include to get it out the way as well. It depends if you change albums around a lot; if you do it'd be much better to find the album title properly, using the zen_albums table.
So to finish and give the output:
echo "<item> <title> $title | by $desc </title> <link>http://www.bridgeothestars.net/fanart/$albumtitle/$filename</link> <description> <img src='http://www.bridgetothestars.net/fanart/$albumtitle/image/thumb/$filename'></img> </description> <guid isPermaLink='true'> http://www.bridgeothestars.net/fanart/$albumtitle/$filename </guid> </item>";
$i++;
}
?>
Very basic RSS XML - no publication date or anything. It works just fine however.
What I've done with this latest-images code is get most of it in includes so the pages it's displayed on are very simple. On my home page for example, where I just want to show the latest image, the code for that is simply:
<?
$number = "1";
include "/home/user/includes/fanart_latest.inc";
?>
Quite cute.
Here is the link to the latest image feed:
http://www.thinkdreams.com/zenphoto/index.php?p=latest
in case anyone wishes to take a look. If you are interested in seeing the code, let me know, and I'll share it here.
`<?php</p>
if (!defined('WEBPATH')) die();
header ('Content-Type: application/rss+xml; charset=' . zp_conf('charset'));
require ('joshuaink.php');
?>
<?php echo "<?xml version=\"1.0\" ?>\n"; ?>
Latest Images
http://www.thinkdreams.com/zenphoto
Latest Images From Thinkdreams
en-us
<?php $iw = $cw = 300;<br />
$ih = $ch = 300;
$user="";
$password="";
$database="";
mysql_connect("databaseserver",$user,$password);
mysql_select_db($database) or die( "Unable to select database");
$sql = "SELECT * FROM ". prefix("images") ." ORDER BY id DESC LIMIT 5";
$result = mysql_query($sql);
while($r = mysql_fetch_array($result)) {
$id=$r['albumid'];
$sql="SELECT * FROM ". prefix("albums") ." WHERE id = $id";
$album = mysql_query($sql);
$a = mysql_fetch_array($album);
?>
<?php echo $r['title'] ?>
<?php echo '<![CDATA[http://www.thinkdreams.com/zenphoto/index.php?album='.$a['folder'].'&image='.$r['filename'] . ']]>';?>
<?php echo '<![CDATA[<a title="'.$r['title'].' in ['.$a['title'].']" href="http://www.thinkdreams.com/zenphoto/index.php?album='.$a['folder'].'&image='.$r['filename'].'">' . $r['desc'] . ']]>';?>
<?php if($exif['datetime']) {<br />
echo '<![CDATA[Date: ' . $exif['datetime'] . ']]>';
}
?>
<?php echo '<![CDATA[http://www.thinkdreams.com/zenphoto/index.php?album='.$a['folder'].'&image='.$r['filename'] . ']]>';?>
<?php } ?>
`
header ('Content-Type: text/xml');
And it works.
Guess it didn't like the application/rss+xml header type for some reason...
Are you still using an RSS feed for your site?
I'm interested in incorporating RSS with the latest release of ZenPhoto and I'm wondering if your code above will work for this version?
My solution was basically a separate page that grabs the images from the DB and displays them. I'm sure there is a more elegant solution. At one time I also had an albums RSS feed, but it required mods to core zenphoto files, and I would rather not have modded the core code too much.
Right now, all that is wrong with the code above that I posted is that it may not use the new method for grabbing images from the cache in the newer version of zenphoto. I'll see about updating that to work better when I get a moment.
http://www.bushwoodworking.com/zenphoto/page/latest
and it works fine with SVN rev 418 (latest version on the repo)
so it should be just fine. I'm sure there is some tweaking that can be done.
I'll put my code up as a ticket attached to the 1.1 milestone, in case Tristan can utilize it for his RSS work.
I think the major issue with the current code, is everything is hardcoded, it is placed within the theme (i.e. not universal to all themes) and it requires it's own database username/password parameters, which shouldn't be necessary. Maybe Tristan can take a look and maybe make some suggestions.
You'll need to change the title, url, and link for the rss channel and image tags, and hardcode the links under the item tag for your specific install:
`<?php<br />
if (!defined('WEBPATH')) die();
header ('Content-Type: application/xml');
require ('customfunctions.php');
?>
<?php echo "<?xml version="1.0" ?>n"; ?>
Latest Images http://www.bushwoodworking.com/zenphoto
Latest Images From Bushwood
Copyright <?php echo date("Y"); ?> Bushwoodworking.com http://www.creativecommons.org/licenses/by-nc-nd/2.5
en-us
Bushwoodworking RSS Feed for Latest Images http://www.bushwoodworking.com/zenphoto/themes/effervescence/images/rss.png http://www.bushwoodworking.com/zenphoto
16
16
<?php $iw = $cw = 300;<br />
$ih = $ch = 300;
$user="yourDBuserhere"; $password="yourDBpasswordhere";
$database="yourDBhere";
mysql_connect("localhost",$user,$password);
mysql_select_db($database) or die( "Unable to select database");
$sql = "SELECT * FROM ". prefix("images") ." ORDER BY id DESC LIMIT 5";
$result = mysql_query($sql);
while($r = mysql_fetch_array($result)) {
$id=$r['albumid'];
$sql="SELECT * FROM ". prefix("albums") ." WHERE id = $id";
$album = mysql_query($sql);
$a = mysql_fetch_array($album);
?>
<?php echo $r['title'] ?>
<?php echo '<![CDATA[http://www.bushwoodworking.com/zenphoto/index.php?album='.$a['folder'].'&image='.$r['filename'] . ']]>';?>
<?php echo '<![CDATA[<a title="'.$r['title'].' in ['.$a['title'].']" href="http://www.bushwoodworking.com/zenphoto/index.php?album='.$a['folder'].'&image='.$r['filename'].'">
' . $r['desc'] . '
]]>';?> <?php if($exif['datetime']) { echo '<![CDATA[Date: ' . $exif['datetime'] . '<br />
]]>'; } ?> <![CDATA[<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.5/">]]>
<?php echo '<![CDATA[http://www.bushwoodworking.com/zenphoto/index.php?album='.$a['folder'].'&image='.$r['filename'] . ']]>';?>
<?php } ?>
`
I mean, I don't know nothing about php but I just wanted to make sure I'm not putting my domain at risk.
I've tuned the thinkdreams RSS generator to make it more friendly. It works by just puting it in the ZenPhoto directory. No need to set password, e-mail, gallery name, etc — as you already setted it in the zp-config.php — not even the URLs — as PHP can figure it out alone.
Just save the code as rss.php at the root of the ZenPhoto, put a link to it on your template and you're ready to go.
`<?php<br />
header('Content-Type: application/xml');
require_once("zen/template-functions.php");
$themepath = 'themes';
require_once("zen/zp-config.php");
?>
<?php echo $conf['gallery_title']; ?>
<?php echo "http://".$_SERVER["HTTP_HOST"].WEBPATH; ?>
<?php echo $conf['gallery_title']; ?>
en-us
<?php echo date("r", time()); ?>
` <lastBuildDate><?php echo date("r", time()); ?></lastBuildDate>`
http://blogs.law.harvard.edu/tech/rss
Alenônimo's ZenPhoto RSS Generator - Based on ThinkDreams Generator
<?php echo $conf['admin_email']; ?>
<?php echo $conf['admin_email']; ?>
<?php <br />
$iw = $cw = 300; // Image Width
$ih = $ch = 300; // Image Height
$items = 10; // # of Items displayed on the feed
mysql_connect($conf['mysql_host'],$conf['mysql_user'],$conf['mysql_pass']);
mysql_select_db($conf['mysql_database']) or die( "Unable to select database");
$sql = "SELECT * FROM ". prefix("images") ." ORDER BY id DESC LIMIT ".$items;
$result = mysql_query($sql);
while($r = mysql_fetch_array($result)) {
$id=$r['albumid'];
$sql="SELECT * FROM ". prefix("albums") ." WHERE id = $id";
$album = mysql_query($sql);
$a = mysql_fetch_array($album);
?>
<?php echo $r['title'] ?>
<?php echo '<![CDATA[http://'.$_SERVER["HTTP_HOST"].WEBPATH.'/index.php?album='.$a['folder'].'&image='.$r['filename'] . ']]>';?>
<?php echo '<![CDATA[<a title="'.$r['title'].' in '.$a['title'].'" href="http://'.$_SERVER["HTTP_HOST"].WEBPATH.'/index.php?album='.$a['folder'].'&image='.$r['filename'].'">
' . $r['desc'] . '
]]>';?> <?php if($exif['datetime']) { echo '<![CDATA[Date: ' . $exif['datetime'] . '<br />
]]>'; } ?>
<?php echo '<![CDATA[http://'.$_SERVER["HTTP_HOST"].WEBPATH.'/index.php?album='.$a['folder'].'&image='.$r['filename'] . ']]>';?>
<?php } ?>
`
Please test this code and make improvements so much as you want. Try to make it the more automated you can (grabbing data from zenphoto opposing to hand-editing it).
``
This will allow the feed autodiscovery for browsers.
`RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule ^rss.php$ http://feeds.feedburner.com/your-feedburner-feed [R,L]`
This will redirect people acessing your rss.php to your FeedBurner. Just won't redirect the FeedBurner itself.
Usage:
Save the code as "rss.php" within your theme folder then place the links into your themes:
1) On any theme file the common rss feed for the whole gallery:
`RSS`
2) On album.php and image.php the album rss feed for the currently selected album:
`&albumname=<?php printAlbumTitle(); ?>">RSS for this album`
Or you can place the rss.php within the zenphoto root in this thread:folder and called it via your theme like this:
`RSS`
or
`&albumname=<?php printAlbumTitle(); ?>">RSS for this album`
Here is the code:
`
<?php<br />
header('Content-Type: application/xml');
require_once("zen/template-functions.php");
$themepath = 'themes';
require_once("zen/zp-config.php");
$albumnr = $_GET[albumnr];
$albumname = $_GET[albumname];
if ($albumname != "")
{ $albumname = " - album: ".$_GET[albumname]; }
?>
<?php echo $conf['gallery_title']; ?><?php echo $albumname; ?>
<?php echo "http://".$_SERVER["HTTP_HOST"].WEBPATH; ?>
<?php echo $conf['gallery_title']; ?>
en-us
<?php echo date("r", time()); ?>
<?php echo date("r", time()); ?>
http://blogs.law.harvard.edu/tech/rss
Acrylian's ZenPhoto RSS Generator based on Alenônimo's ZenPhoto RSS Generator which is based on ThinkDreams' Generator...:-)
<?php echo $conf['admin_email']; ?>
<?php echo $conf['admin_email']; ?>
<?php<br />
$iw = $cw = 300; // Image Width
$ih = $ch = 300; // Image Height
$items = 10; // # of Items displayed on the feed
mysql_connect($conf['mysql_host'],$conf['mysql_user'],$conf['mysql_pass']);
mysql_select_db($conf['mysql_database']) or die( "Unable to select database");
if ($albumnr != "")
{ $sql = "SELECT * FROM ". prefix("images") ." WHERE albumid = $albumnr ORDER BY id DESC LIMIT ".$items;}
else
{ $sql = "SELECT * FROM ". prefix("images") ." ORDER BY id DESC LIMIT ".$items; }
$result = mysql_query($sql);
while($r = mysql_fetch_array($result)) {
$id=$r['albumid'];
if ($albumnr2 != "")
{ $sql="SELECT * FROM ". prefix("albums") ." WHERE id = $albumnr2"; }
else
{ $sql="SELECT * FROM ". prefix("albums") ." WHERE id = $id"; }
$album = mysql_query($sql);
$a = mysql_fetch_array($album);
?>
<?php echo $r['title'] ?>
<?php echo '<![CDATA[http://'.$_SERVER["HTTP_HOST"].WEBPATH.'/index.php?album='.$a['folder'].'&image='.$r['filename'] . ']]>';?>
<?php echo '<![CDATA[<a title="'.$r['title'].' in '.$a['title'].'">
' . $r['desc'] . '
]]>';?> <?php if($exif['datetime']) { echo '<![CDATA[Date: ' . $exif['datetime'] . '<br />
]]>'; } ?>
<?php echo '<![CDATA[http://'.$_SERVER["HTTP_HOST"].WEBPATH.'/index.php?album='.$a['folder'].'&image='.$r['filename'] . ']]>';?>
<?php } ?>
`
So just download here:
rss-for-gallery-and-albums
Your version is very good, but I have a suggestion to do. Could you put an `
` between the image and description at the feed items?
And the `getIDforAlbum()` function make some weird errors when I put it on my template. What could be causing it?