@@ -, +, @@ --- misc/cronjobs/rss/README | 35 ++++++++++++++--------------- misc/cronjobs/rss/rss.pl | 53 ++++++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 45 deletions(-) --- a/misc/cronjobs/rss/README +++ a/misc/cronjobs/rss/README @@ -21,7 +21,7 @@ is invoked like this (in the case of lastAcquired): The basic process is that rss reads the config file (lastAcquired.conf) to determine RSS header information, the SQL query -used to generate the results, and the HTML::Template style used to +used to generate the results, and the Template Tookit style used to format the output. Since you'll likely to want to create your own RSS content, or at least modify the ones present here, let's review the config file and the template file. @@ -51,16 +51,15 @@ title=Koha, the worlds best Open Source Library System url=http://www.koha-community.org/images/foo.jpg link=http://www.koha-community.org config -tmpl=lastAcquired.tmpl +tmpl=lastAcquired.tt output=lastAcquired.xml query=select biblioitems.isbn as isbn, biblio.title as title, biblio.author as author from biblio, biblioitems, items where biblioitems.biblionumber = items.biblionumber and biblio.biblionumber = items.biblionumber and items.dateaccessioned is not NULL order by items.dateaccessioned desc This data (and the data acquired from the query) are then used to fill in the template. Most of the template is boilerplate and should not -be edited. The section within the -... is the part which can be modified to create your own -RSS content. +be edited. The section within the [% FOREACH i IN ITEMS %] ... [% END %] +is the part which can be modified to create your own RSS content. Here's the lastAcquired.tmpl file: @@ -72,25 +71,24 @@ Here's the lastAcquired.tmpl file: - <TMPL_VAR CHANNELTITLE> - - - - + [% CHANNELTITLE %] + [% CHANNELLINK %] + [% CHANNELDESC %] + [% CHANNELLANG %] + [% CHANNELLASTBUILD %] - <TMPL_VAR IMAGETITLE> - - + [% IMAGETITLE %] + [% IMAGEURL %] + [% IMAGELINK %] - +[% FOREACH i IN ITEMS %] - <TMPL_VAR TITLE>, by <TMPL_VAR AUTHOR> - http://opac.library.org.nz/cgi-bin/koha/opac-searchresults.pl?isbn= - + [% i.TITLE %], by [% i.AUTHOR %] + http://opac.library.org.nz/cgi-bin/koha/opac-searchresults.pl?isbn=[% i.ISBN %] - +[% END %] @@ -100,3 +98,4 @@ Originally written by Pat Eyler (pate@eylerfamily.org), suggestions, advice, and help came from 'Content Syndication with RSS', Chris Cormack, Mike Hansen, Steve Tonnesen and a variety of folks on #koha at irc.katipo.co.nz. +Updated for use with Template Toolkit by Kyle M Hall, ByWater Solutions --- a/misc/cronjobs/rss/rss.pl +++ a/misc/cronjobs/rss/rss.pl @@ -8,6 +8,7 @@ # # Copyright 2003 Katipo Communications +# Copyright 2014 ByWater Solutions # # This file is part of Koha. # @@ -24,10 +25,9 @@ # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -use strict; -use warnings; +use Modern::Perl; -use HTML::Template::Pro; +use Template; use C4::Context; use Time::Local; use POSIX; @@ -36,35 +36,32 @@ my $dbh = C4::Context->dbh; my $file = $ARGV[0]; my %config = getConf("config"); my $outFile = $config{"output"}; -my $feed = HTML::Template::Pro->new( filename => $config{"tmpl"} ); +my $feed = Template->new(); my %channel = getConf("channel"); -$feed->param( CHANNELTITLE => $channel{'title'} ); -$feed->param( CHANNELLINK => $channel{'link'} ); -$feed->param( CHANNELDESC => $channel{'desc'} ); -$feed->param( CHANNELLANG => $channel{'lang'} ); -$feed->param( CHANNELLASTBUILD => getDate() ); +my %image = getConf("image"); +my $vars = { + CHANNELTITLE => $channel{'title'}, + CHANNELLINK => $channel{'link'}, + CHANNELDESC => $channel{'desc'}, + CHANNELLANG => $channel{'lang'}, + CHANNELLASTBUILD => getDate(), -my %image = getConf("image"); -$feed->param( IMAGETITLE => $image{'title'} ); -$feed->param( IMAGEURL => $image{'url'} ); -$feed->param( IMAGELINK => $image{'link'} ); -$feed->param( IMAGEDESCRIPTION => $image{'description'} ); -$feed->param( IMAGEWIDTH => $image{'width'} ); -$feed->param( IMAGEHEIGHT => $image{'height'} ); + IMAGETITLE => $image{'title'}, + IMAGEURL => $image{'url'}, + IMAGELINK => $image{'link'}, + IMAGEDESCRIPTION => $image{'description'}, + IMAGEWIDTH => $image{'width'}, + IMAGEHEIGHT => $image{'height'}, -# -# handle the items -# -$feed->param( ITEMS => getItems( $config{'query'} ) ); + ITEMS => getItems( $config{'query'} ) +}; -open( FILE, ">$outFile" ) or die "can't open $outFile"; -print FILE $feed->output(); -close FILE; +my $template_path = $config{"tmpl"}; +open( my $fh, "<", $template_path ) or die "cannot open $template_path : $!"; +$feed->process( $fh, $vars, $outFile ); sub getDate { - - # my $date = localtime(timelocal(localtime)); my $date = strftime( "%a, %d %b %Y %T %Z", localtime ); return $date; } @@ -80,12 +77,14 @@ sub getConf { my @line = split( /=/, $_, 2 ); unless ( $line[1] ) { $inSection = 0; - } else { + } + else { my ( $key, $value ) = @line; chomp $value; $return{$key} = $value; } - } else { + } + else { if ( $_ eq "$section\n" ) { $inSection = 1 } } } --