|
The system automatically generates various RSS XML feeds for web albums published by users and the album index page of each user. Web album visitors can subscribe to these feeds in their RSS news readers or web browsers to get notifications about updates.
As a developer, you can take advantage of these feeds to build interesting applications like image “tickers”, screen savers, automatic desktop background changers, etc. You can also create your own web album skins or integrate photos directly into your own web site, The following will give some examples, how to create such scripts.
Web Album Index Site
There is one feed per user which lists all publicly published web albums for this user. The feed URL is referenced from the user’s index page at http://www.snapmania.com/users/username/. An example feed URL is http://www.snapmania.com/users/username/?mode=rss2
A easy way to incorporate the list of public listed albums, is by XSLT and a script language like perl or php. The idea behind, is to get the RSS feed with the script from snapmanias server and transform it then with XSLT to HTML. A snippet which you can embed into your own web site would look similar to this:
The PHP 5 code could be: (Substitute “username” with yours)
<?php
/* Load the two XML sources */
$xml = new DomDocument;
$xml->load("http://www.snapmania.com/users/username/?mode=rss2");
$xsl = new DomDocument;
$xsl->load('rss2html.xslt');
/* Configure the transformer */
$proc = new xsltprocessor;
$proc->importStyleSheet($xsl);
$html = $proc->transformToXML($xml);
echo(utf8_decode($html));
?>
Save this XSLT as “rss2html.xslt” in the same directory as the script above:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<xsl:apply-templates select="/rss/channel"/>
</xsl:template>
<xsl:template match="/rss/channel">
<h1><xsl:value-of select="title"/></h1>
<a href="{link}">Web albums</a>
<xsl:apply-templates select="item"/>
</xsl:template>
<xsl:template match="/rss/channel/item">
<div class="reference">
<p class="reftitle">
<xsl:value-of select="title"/>
</p>
<p class="reftext">
<xsl:value-of disable-output-escaping="yes" select="description"/>
</p>
</div>
</xsl:template>
</xsl:stylesheet>
Depending on how you like to embed the links in your web site, you will have to adopt the scripts above and define some CSS classes.
Web Album Feeds
There is another feed for each web album. This feed contains a list of the images in the web album. The little RSS icon next to an album’s link on the album index page leads to a list of the available formats (Atom, RSS etc.). An exapmle feed URL is http://www.snapmania.com/feed/rss/CID-u0063992-2
A simple application would load the RSS Feed of an album and show it. A small example in PHP 5 with the same XSLT from above and the RSS 2 feed:
<html>
<head>
<title>
Album
</title>
<style>
h1 {
font-size: 16px;
font-weight: bold;
color: #323232;
}
.reference {
border: 1px;
border-style: dotted;
border-color: #323232;
background-color: #cccccc;
color: #323232;
padding: 2px;
margin: 5px;
height: 140px;
width: 80%;
align: center;
}
</style>
</head>
<body>
<?php
/* Get the RSS Feed from the paramters:
http://foo.bar/this_script.php?url=http://www.snapmania.com/feed/rss2/CID-u00001-01
*/
$url = $_GET["url"];
$xml = new DomDocument;
$xml->load($url);
$xsl = new DomDocument;
$xsl->load('album2html.xslt');
/* Configure the transformer */
$proc = new xsltprocessor;
$proc->importStyleSheet($xsl);
$html = $proc->transformToXML($xml);
echo(utf8_decode($html));
?>
</body>
</html>
You can change the feed format by substituting the string “rss2” with one of the following: atom, cast, rss, rdf. Just adopt the XSLT to fit your needs.
In Perl:
#!/usr/bin/perl
use strict;
use XML::XSLT;
use LWP::Simple;
use CGI;
my $cgi = CGI->new();
my $url = $cgi->param("url");
my $xsl = "rss2html.xslt";
my $rss = get($url);
my $xslt = XML::XSLT->new($xsl, warnings => 1);
$xslt->transform ($rss);
print $cgi->header();
print $cgi->start_html( -style=>{'src'=>'my.css'});
print $xslt->toString;
print $cgi->end_html();
$xslt->dispose();
|