Made my own RSS Feed - useful?

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.php

As 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

  • trisweb Administrator
    Should just be another theme page, am I right? With a different output XML, but still just grabbing and looping stuff like a normal theme?

    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. :)
  • Again, I'll be honest and admit that I'm not too sure what goes on in the themes and so forth. My method was to just order the zen_images by ID - the highest numbers are the newest images. Grab the top fifteen rows from there and you're away.

    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
  • Starting up RSS feeds again would be cool Trisweb. I have rudimentary RSS working based on other forum posts, and code patches posted on the wiki. But it lacks extensibility, in the form of latest image feeds, latest album feeds, etc.

    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. ;)
  • One thing I am going to suggest as you move forward in development of Zenphoto RSS capability Trisweb, is that it would be nice to include latest album and images RSS feeds.

    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.
  • Will-

    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.
  • I sent this already through email, but for the benefit of anyone who's interested I'll repeat it here:

    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&gt;

    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&gt; <description> <img src='http://www.bridgetothestars.net/fanart/$albumtitle/image/thumb/$filename'></img&gt; </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.
  • With Will's help, I managed to get it to work pretty well. So now I have a working implementation of a per album RSS feed, and a latest image feed.

    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.
  • One thing Will noticed with my RSS feed. It always comes up as "index.php". Please see the attached code. I call it from a link to the specific page (http://www.thinkdreams.com/zenphoto/index.php?p=latest), so I can potentially see that it being called as a PHP file, but could anyone shed light on why it's working that way? My goal is to have it work within a browser. The feed validates OK, it just won't display in a browser.

    `<?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['title'] .'' . $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 } ?>





    `

  • Looks like I answered my own question. I changed the header designation to:

    header ('Content-Type: text/xml');

    And it works.

    Guess it didn't like the application/rss+xml header type for some reason...
  • I think this is because a lot of modern browsers still don't recognise xHTML media types.
  • Hi thinkdreams
    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?
  • I am, but I haven't gotten around to updating it yet. As soon as the EXIF stuff is in progress, I was going to put what I have up there for Tristan to review so he start incorporating that as well. RSS feeds are in for the 1.1 version I believe.

    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.
  • Note also that my solution requires database parameters within the page, so I would want to figure out a better way to handle this from within Zenphoto.
  • I just tested it,

    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['title'] .'

    ' . $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/">Creative Commons License]]>

    <?php echo '<![CDATA[http://www.bushwoodworking.com/zenphoto/index.php?album='.$a['folder'].'&image='.$r['filename'] . ']]>';?>



    <?php } ?>



    `
  • The code didn't paste so well, so if anyone has issues, let me know.
  • OK. I updated the RSS feed ticket with comments and the code above if any one is interested.
  • Hey, thanks a lot! Just one question: is it safe to store password and username in this file?
    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 believe someone would have to have access to the web server to download the PHP code to get that info, as it's compiled during web requests, you won't ever see the user/pass in the page source. There may be other ways to get it but it's fairly secure.
  • Hey guys! Check this out.

    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'].'">image

    ' . $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).
  • Oh yea… Put this on the templates, inside the <head> tags.

    ``

    This will allow the feed autodiscovery for browsers.
  • Just an tip for the FeedBurners. Edit the .htaccess to include this:

    `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.
  • acrylian Administrator, Developer
    I did a little expanding modification that might be useful. The RSS generator is now capable to generate a newsfeed for any album now, too.

    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'].'">image

    ' . $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 } ?>





    `
  • acrylian Administrator, Developer
    Sorry seems the forum does not like when I am posting...the usage part gets mangled.

    So just download here:
    rss-for-gallery-and-albums
  • Works for me. Good replacement for what I had been using, as it uses the db settings from the zp_config, rather than duplicating them in the rss.php file.
  • acrylian,

    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?
Sign In or Register to comment.