<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

$VERSION = '1.00';

# XAlbum2Rss - Generate RSS Feed from Photo Album XML, (see XPhotoAlbum.pl)
# Version 1.00
#
# Get docs and newest version from
#       http://www.neystadt.org/XPhotoAlbum/
#
# Copyright (c) 2005, John Neystadt &lt;http://www.neystadt.org/john/&gt;
# You may install this script on your site for free
# To obtain permision for redistribution or any other usage
#       contact john@neystadt.org.
#
# Drop me a line if you deploy this script on your site.

=head1 NAME

XAlbum2Rss.pl v1.00 - XML Photo Album Script RSS Feed Generator

=cut

use XML::DOM;
use XML::RSS;
use Image::ExifTool;
use File::stat;
use POSIX;

my ($DateFormat) = '%Y-%m-%dT%H:%M:%S+02:00'; # '%a, %d %b %Y %H:%M:%S GMT+2';
my ($FeedSize) = 100;

if ($#ARGV &lt; 1) {
	print STDERR "Usage: $0 &lt;album.xml&gt; &lt;picture root&gt;
	Will print RSS feed on the output\n.";

	die 1;
}

my ($IndexFile, $PictureRoot) = @ARGV;
$PictureRoot .= '/'
	if !($PictureRoot =~ q|/$|);

my $parser = new XML::DOM::Parser;
my $doc = $parser-&gt;parsefile ($IndexFile);
my $album = $doc-&gt;getChildNodes ()-&gt;item (0);

die "Can't load XML file $IndexFile" if (!$doc || !$album);

my $PicturePath = $album-&gt;getAttribute ('PATH');
$PicturePath .= '/'
	if !($PicturePath =~ q|/$|);

my $children = $album-&gt;getChildNodes ();
my $anno;
for (0..$children-&gt;getLength ()-1) {
	my $child = $children-&gt;item ($_);
	if ($child-&gt;getNodeName eq 'ANNOTATION') {
		$anno = $child-&gt;getFirstChild ()-&gt;getData ();
		last;
	}
}

my $rss = new XML::RSS (version =&gt; '1.0');

$rss-&gt;channel(
   title        =&gt; $album-&gt;getAttribute ('TITLE'),
   link         =&gt; $album-&gt;getAttribute ('LINK'),
   description  =&gt; $anno,
   dc =&gt; {
     date       =&gt; getNowTime(),
     subject    =&gt; $album-&gt;getAttribute ('TITLE'),
     creator    =&gt; $album-&gt;getAttribute ('AUTHOR'),
     publisher  =&gt; $album-&gt;getAttribute ('AUTHOR'),
     rights     =&gt; $album-&gt;getAttribute ('COPYRIGHT'),
     language   =&gt; 'en-us',
   },
   syn =&gt; {
     updatePeriod     =&gt; "hourly",
     updateFrequency  =&gt; "1",
     updateBase       =&gt; "1901-01-01T00:00+00:00",
   },
 );

$rss-&gt;image(
	title  =&gt; "Album Logo",
	url    =&gt; $album-&gt;getAttribute ('ICON'),
	link   =&gt; $album-&gt;getAttribute ('LINK'),
);

my @images = sortAlbumImages ($doc);
for (@images [0..$FeedSize-1]) {
	last if !$_;
	image2Rss ($rss, $_, $album);
}

print $rss-&gt;as_string;

## END OF MAIN ##

sub image2Rss {
	my ($rss, $image, $album) = @_;

	my $link = $PicturePath . $image-&gt;getAttribute ('HREF');


	# Enumerate through parent folders to prepend folder titles
	my $elem = $image;
        
	my $title = $image-&gt;getFirstChild ()-&gt;getData ();
        while ($elem) {
		$elem = $elem-&gt;getParentNode ();
		last if $elem-&gt;getNodeName () ne 'FOLDER';
		$title = $elem-&gt;getAttribute ('TITLE') . ' : ' . $title;
	}

	my $desc = &lt;&lt;EOD;
&lt;span&gt;$title&lt;/span&gt;&lt;p/&gt;&lt;img src="$link" alt="$title"/&gt;
EOD

	$rss-&gt;add_item (
		title		=&gt;	$title,
		link		=&gt;	$link,
		description	=&gt;	$desc,
		dc =&gt; {
			subject	=&gt; $album-&gt;getAttribute ('TITLE'),
			creator	=&gt; $album-&gt;getAttribute ('AUTHOR'),
			date	=&gt; $image-&gt;getAttribute ('DATE'),
   		},
	);
}

sub sortAlbumImages {
	my ($doc) = @_;

	my @images = $doc-&gt;getElementsByTagName ('PICTURE');
	my ($f);

	foreach (@images) {
		my $file = $PictureRoot . $_-&gt;getAttribute ('HREF');
		my $date = getImageTime ($file);

		$f = 0;
		if (!$date) {
			$f = 1;
			$date = getFileTime ($file);
		}
		$_-&gt;setAttribute ('DATE', $date);

		print STDERR "$date\t";
		if ($f) { print STDERR "FILE"; } else { print STDERR "EXIF"; }
		print STDERR "\t$file\n";
	}

	sub ByImageDate { 
		$b-&gt;getAttribute ('DATE') cmp $a-&gt;getAttribute ('DATE');
	}

	return sort ByImageDate @images;
}

sub getImageTime {
	my ($file) = @_;

	my $exifTool = new Image::ExifTool;
	$exifTool-&gt;Options(Group0 =&gt; ['EXIF'], Unknown =&gt; 0, DateFormat =&gt; $DateFormat);

	my $info = $exifTool-&gt;ImageInfo($file);

	return udef if !$info;

	if (exists $info-&gt;{'DateTimeOriginal'}) {
		return $info-&gt;{'DateTimeOriginal'};
	} elsif (exists $info-&gt;{'ModifyDate'}) {
		return $info-&gt;{'ModifyDate'};
	}

	return undef;
}

sub getFileTime {
	my ($file) = @_;

	my $info = stat($file);
	die "Can't access referenced file $image!" if !$info;

	return POSIX::strftime ($DateFormat, gmtime ($info-&gt;mtime));
}

sub getNowTime {
	return POSIX::strftime ($DateFormat, gmtime ());
}

__END__

=head1 DESCRIPTION

This simple script can be used to generate RSS feed out of the album file, which you created for XPhotoAlbum.pl. The script can be used for off-Line
RSS generation - add it to your schedule tasks or crontab.

Once you created RSS feed, your friends may add your album to their RSS Reader (http://www.bradsoft.com/feeddemon/), http://www.LiveJournal.com friend lent, or http://my.yahoo.com 
personalized portal. Each time you ad a photo, they will instantly see it in their news feed.

=head1 USAGE

I&lt;XAlbum2Rss.pl album.xml pictures-path&gt;
       
Will print RSS feed on the output. You can redirect this into album.rdf file, and use it for RSS feed.

=head1 XML Index File Format

Please see the examples below to understand the format of the files.

=head1 CAVEATS

You need to add few new attributes to you album XML file, which will be used for RSS meta-data:

=over

=item 1

LINK - URL of the full album

=item 2

AUTHOR - Your name

=item 3

COPYRIGHT - Copyright text

=back

For example:

... LINK="http://www.neystadt.org/john/album/" AUTHOR="John Neystadt" COPYRIGHT="John Neystadt" ...

=head1 TIPS AND TRICKS

Send your feedback...

=head1 EXAMPLES

Please see http://www.neystadt.org/ for three instances of the albums using this technology.
Particulary examples of the XML index files are located at:

    http://www.neystadt.org/john/album/index.rdf
    http://www.neystadt.org/john/family-album/index.rdf

=head1 PREREQUISITES

This script requires the C&lt;XML::DOM&gt;, C&lt;XML::RSS&gt; and C&lt;Image::ExifTool&gt; modules available from CPAN (http://www.cpan.org)

=pod OSNAMES

All UNIXes, Windows NT

=pod SCRIPT CATEGORIES

Web

=pod README

This simple script can be used to generate RSS feed out of the album file, which you created for XPhotoAlbum.pl. The script can be used for off-Line
RSS generation - add it to your schedule tasks or crontab. 

See http://www.neystadt.org/XPhotoAlbum/ for additional details.

=cut
</pre></body></html>