[Koha-patches] [PATCH] bug 2864 [1/2]: restore rss/rss.pl

Galen Charlton galen.charlton at liblime.com
Mon Dec 15 16:58:46 CET 2008


Restored basic functionality of rss/rss.pl:

[1] Reverted "Add support for itemtypes. Still need to hardcode 'reservable'"
    Revert commit e7575b00edd6098a869425a69856916108e84914, which had
    replace the script with one of its templates.

[2] Minor fixes to update it, including using HTML::Template::Pro instead
    of HTML::Template, perltidy, and turning on warnings.
---
 rss/lastAcquired-1.0.conf |    2 +-
 rss/lastAcquired-2.0.conf |    2 +-
 rss/lastAcquired.conf     |    2 +-
 rss/rss.pl                |  147 ++++++++++++++++++++++++++++++++++-----------
 4 files changed, 115 insertions(+), 38 deletions(-)
 mode change 100644 => 100755 rss/rss.pl

diff --git a/rss/lastAcquired-1.0.conf b/rss/lastAcquired-1.0.conf
index 9c985f7..44036d8 100644
--- a/rss/lastAcquired-1.0.conf
+++ b/rss/lastAcquired-1.0.conf
@@ -11,4 +11,4 @@ description=Koha, the worlds best Open Source Library System
 config
 tmpl=lastAcquired-1.0.tmpl
 output=lastAcquired-1.0.xml
-query=select biblio.title as title, biblio.author as author, biblio.biblionumber as bibid, biblio.notes as notes, biblioitems.place as place, biblioitems.publishercode as publishercode, biblioitems.publicationyear as publicationyear, biblioitems.pages as pages, biblioitems.illus as illus, biblioitems.size as size 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
\ No newline at end of file
+query=select biblio.title as title, biblio.author as author, biblio.biblionumber, biblio.notes as notes, biblioitems.place as place, biblioitems.publishercode as publishercode, biblioitems.publicationyear as publicationyear, biblioitems.pages as pages, biblioitems.illus as illus, biblioitems.size as size 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
diff --git a/rss/lastAcquired-2.0.conf b/rss/lastAcquired-2.0.conf
index 5048fa6..5e6a1b5 100644
--- a/rss/lastAcquired-2.0.conf
+++ b/rss/lastAcquired-2.0.conf
@@ -13,4 +13,4 @@ height=31
 config
 tmpl=lastAcquired-2.0.tmpl
 output=lastAcquired-2.0.xml
-query=select biblio.title as title, biblio.author as author, biblio.biblionumber as bibid, biblio.notes as notes, biblioitems.place as place, biblioitems.publishercode as publishercode, biblioitems.publicationyear as publicationyear, biblioitems.pages as pages, biblioitems.illus as illus, biblioitems.size as size 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
\ No newline at end of file
+query=select biblio.title as title, biblio.author as author, biblio.biblionumber, biblio.notes as notes, biblioitems.place as place, biblioitems.publishercode as publishercode, biblioitems.publicationyear as publicationyear, biblioitems.pages as pages, biblioitems.illus as illus, biblioitems.size as size 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
diff --git a/rss/lastAcquired.conf b/rss/lastAcquired.conf
index 9f3cc94..4ae696a 100644
--- a/rss/lastAcquired.conf
+++ b/rss/lastAcquired.conf
@@ -11,5 +11,5 @@ link=http://www.koha.org
 config
 tmpl=lastAcquired.tmpl
 output=lastAcquired.xml
-query=select biblio.title as title, biblio.author as author, biblio.biblionumber as bibid 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
+query=select biblio.title as title, biblio.author as author, biblio.biblionumber 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
 
diff --git a/rss/rss.pl b/rss/rss.pl
old mode 100644
new mode 100755
index e6fcb6f..4cea230
--- a/rss/rss.pl
+++ b/rss/rss.pl
@@ -1,35 +1,112 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!DOCTYPE rss PUBLIC "-//Netscape Communications/DTD RSS 0.91/EN"
-          "http://my.netscape.com/publish/formats/rss-0.91.dtd">
-
-<rss version="0.91">
-
-<channel>
- <title><!-- TMPL_VAR name="CHANNELTITLE" --></title>
- <link><!-- TMPL_VAR name="CHANNELLINK" --></link>
- <description><!-- TMPL_VAR name="CHANNELDESC" --></description>
- <language><!-- TMPL_VAR name="CHANNELLANG" --></language>
- <lastBuildDate><!-- TMPL_VAR name="CHANNELLASTBUILD" --></lastBuildDate>
-
- <image>
-  <title><!-- TMPL_VAR name="IMAGETITLE" --></title>
-  <url><!-- TMPL_VAR name="IMAGEURL" --></url>
-  <link><!-- TMPL_VAR name="IMAGELINK" --></link>
- </image>
-
-<!-- TMPL_LOOP NAME="ITEMS" -->
- <item>
-  <title><!-- TMPL_VAR name="TITLE" --><!-- TMPL_IF NAME="SUBTITLE" --> <!-- TMPL_VAR name="SUBTITLE" --><!-- /TMPL_IF --><!-- TMPL_IF NAME="AUTHOR" -->, by <!-- TMPL_VAR name="AUTHOR" --><!-- /TMPL_IF --></title>
-        <category><!-- TMPL_VAR NAME="itemtype" --></category>
-        <description><![CDATA[Call Number: <!-- TMPL_VAR NAME="callno" --><br />
-        <!-- TMPL_IF NAME="notes" -->Notes: <!-- TMPL_VAR NAME="notes" --><br /><!-- /TMPL_IF -->
-<a href="https://libcat.nbbc.edu/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">View Details</a> <!-- TMPL_IF NAME="reservable" -->| <a href="https://libcat.nbbc.edu/cgi-bin/koha/opac-reserve.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">Reserve this Item</a><!-- /TMPL_IF -->]]>
-</description>
-  <link>https://libcat.nbbc.edu/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR name="biblionumber" --></link>
-
- </item>
-<!-- /TMPL_LOOP -->
-
-</channel>
-</rss>
+#!/usr/bin/perl
+
+# This script can be used to generate rss 0.91 files for syndication.
+
+# it should be run from cron like:
+#
+#    rss.pl config.conf
+#
+
+# Copyright 2003 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+use warnings;
+
+use HTML::Template::Pro;
+use C4::Context;
+use Time::Local;
+use POSIX;
+
+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 %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");
+$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'} );
+
+#
+# handle the items
+#
+$feed->param( ITEMS => getItems( $config{'query'} ) );
+
+open( FILE, ">$outFile" ) or die "can't open $outFile";
+print FILE $feed->output();
+close FILE;
+
+sub getDate {
+
+    #    my $date = localtime(timelocal(localtime));
+    my $date = strftime( "%a, %d %b %Y %T %Z", localtime );
+    return $date;
+}
+
+sub getConf {
+    my $section = shift;
+    my %return;
+    my $inSection = 0;
+
+    open( FILE, $file ) or die "can't open $file";
+    while (<FILE>) {
+        if ($inSection) {
+            my @line = split( /=/, $_, 2 );
+            unless ( $line[1] ) {
+                $inSection = 0;
+            } else {
+                my ( $key, $value ) = @line;
+                chomp $value;
+                $return{$key} = $value;
+            }
+        } else {
+            if ( $_ eq "$section\n" ) { $inSection = 1 }
+        }
+    }
+    close FILE;
+    return %return;
+}
+
+sub getItems {
+    my $query = shift;
+    $query .= " limit 15";
+    my $sth = $dbh->prepare($query);
+    $sth->execute;
+    my @return;
+    while ( my $data = $sth->fetchrow_hashref ) {
+        foreach my $key ( keys %$data ) {
+            my $value = $data->{$key};
+            $value = '' unless defined $value;
+            $value =~ s/\&/\&amp;/g and $data->{$key} = $value;
+        }
+        push @return, $data;
+    }
+    $sth->finish;
+    return \@return;
+}
-- 
1.5.5.GIT




More information about the Koha-patches mailing list