Bug 9000 [1] - Update rss.pl to use Template Toolkit
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> Tested using script with sample conf files RSS feeds generated are 'well formed' xml Some koha-qa errors fixed in followup Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
parent
6ad03cc15a
commit
80884faa22
2 changed files with 43 additions and 45 deletions
|
@ -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 <TMPL_LOOP NAME=ITEMS>
|
||||
... </TMPL_LOOP> 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:
|
|||
<rss version="0.91">
|
||||
|
||||
<channel>
|
||||
<title><TMPL_VAR CHANNELTITLE></title>
|
||||
<link><TMPL_VAR CHANNELLINK></link>
|
||||
<description><TMPL_VAR CHANNELDESC></description>
|
||||
<language><TMPL_VAR CHANNELLANG></language>
|
||||
<lastBuildDate><TMPL_VAR CHANNELLASTBUILD></lastBuildDate>
|
||||
<title>[% CHANNELTITLE %]</title>
|
||||
<link>[% CHANNELLINK %]</link>
|
||||
<description>[% CHANNELDESC %]</description>
|
||||
<language>[% CHANNELLANG %]</language>
|
||||
<lastBuildDate>[% CHANNELLASTBUILD %]</lastBuildDate>
|
||||
|
||||
<image>
|
||||
<title><TMPL_VAR IMAGETITLE></title>
|
||||
<url><TMPL_VAR IMAGEURL></url>
|
||||
<link><TMPL_VAR IMAGELINK></link>
|
||||
<title>[% IMAGETITLE %]</title>
|
||||
<url>[% IMAGEURL %]</url>
|
||||
<link>[% IMAGELINK %]</link>
|
||||
</image>
|
||||
|
||||
<TMPL_LOOP NAME=ITEMS>
|
||||
[% FOREACH i IN ITEMS %]
|
||||
<item>
|
||||
<title><TMPL_VAR TITLE>, by <TMPL_VAR AUTHOR></title>
|
||||
<link>http://opac.library.org.nz/cgi-bin/koha/opac-searchresults.pl?isbn=<TMPL_VAR ISBN></link>
|
||||
|
||||
<title>[% i.TITLE %], by [% i.AUTHOR %]</title>
|
||||
<link>http://opac.library.org.nz/cgi-bin/koha/opac-searchresults.pl?isbn=[% i.ISBN %]</link>
|
||||
</item>
|
||||
</TMPL_LOOP>
|
||||
[% END %]
|
||||
|
||||
</channel>
|
||||
</rss>
|
||||
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue