koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha opac/opac-search.pl koha-tmpl/opac-tmpl/pr...


From: paul poulain
Subject: [Koha-cvs] koha opac/opac-search.pl koha-tmpl/opac-tmpl/pr...
Date: Wed, 09 May 2007 10:09:40 +0000

CVSROOT:        /sources/koha
Module name:    koha
Changes by:     paul poulain <tipaul>   07/05/09 10:09:40

Modified files:
        opac           : opac-search.pl 
        koha-tmpl/opac-tmpl/prog/en/includes: doc-head-close.inc 
        C4             : Search.pm 
Added files:
        opac           : opac-rss.pl 

Log message:
        NEW feature : RSS feeds. See POD & koha-devel for details

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-search.pl?cvsroot=koha&r1=1.41&r2=1.42
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-rss.pl?cvsroot=koha&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc?cvsroot=koha&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Search.pm?cvsroot=koha&r1=1.138&r2=1.139

Patches:
Index: opac/opac-search.pl
===================================================================
RCS file: /sources/koha/koha/opac/opac-search.pl,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- opac/opac-search.pl 24 Apr 2007 13:54:29 -0000      1.41
+++ opac/opac-search.pl 9 May 2007 10:09:40 -0000       1.42
@@ -3,7 +3,7 @@
 # Script to perform searching
 # For documentation try 'perldoc /path/to/search'
 #
-# $Header: /sources/koha/koha/opac/opac-search.pl,v 1.41 2007/04/24 13:54:29 
hdl Exp $
+# $Header: /sources/koha/koha/opac/opac-search.pl,v 1.42 2007/05/09 10:09:40 
tipaul Exp $
 #
 # Copyright 2006 LibLime
 #
@@ -440,16 +440,15 @@
 my @results_array;
 my $results_hashref;
 
-eval {
-
-    ( $error, $results_hashref, $facets ) = getRecords(
-        $koha_query,     $federated_query,  address@hidden,
-        address@hidden,       $results_per_page, $offset,
-        $expanded_facet, $branches,         $query_type,
-        $scan
-    );
-
-};
+if (C4::Context->preference('NoZebra')) {
+    eval {
+        ($error, $results_hashref, $facets) = 
NZgetRecords($koha_query,$federated_query,address@hidden,address@hidden,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
+    };
+} else {
+    eval {
+        ($error, $results_hashref, $facets) = 
getRecords($koha_query,$federated_query,address@hidden,address@hidden,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
+    };
+}
 if ( $@ || $error ) {
     $template->param( query_error => $error . $@ );
 
@@ -550,6 +549,9 @@
 if (C4::Context->preference("RequestOnOpac")) {
        $RequestOnOpac = 1;
 }
+# get site URL (for RSS link)
+$cgi->url() =~ /(.*)\/(.*)/;
+my $site_url = $1;
 
 $template->param(
 
@@ -563,6 +565,8 @@
     scan_use     => $scan,
     search_error => $error,
     RequestOnOpac       => $RequestOnOpac,
+    RSS=> 1,
+    site_url => $site_url,
 );
 ## Now let's find out if we have any supplemental data to show the user
 #  and in the meantime, save the current query for statistical purposes, etc.

Index: koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc
===================================================================
RCS file: 
/sources/koha/koha/koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc     9 Mar 2007 
14:53:34 -0000       1.2
+++ koha-tmpl/opac-tmpl/prog/en/includes/doc-head-close.inc     9 May 2007 
10:09:40 -0000       1.3
@@ -1,5 +1,8 @@
 </title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<!-- TMPL_IF name="RSS" -->
+    <link rel="alternate" type="application/rss+xml" title="VNUNet.fr - 
Actualit&eacute;s" href="<!-- TMPL_VAR name="site_url"-->/opac-rss.pl?q=<!-- 
TMPL_VAR name="searchdesc"-->">
+<!-- /TMPL_IF -->
 <!-- TMPL_IF name="opacstylesheet" -->
         <style type="text/css"> 
             @import url(<!-- TMPL_VAR NAME="opacstylesheet" -->);

Index: C4/Search.pm
===================================================================
RCS file: /sources/koha/koha/C4/Search.pm,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -b -r1.138 -r1.139
--- C4/Search.pm        4 May 2007 16:26:16 -0000       1.138
+++ C4/Search.pm        9 May 2007 10:09:40 -0000       1.139
@@ -25,7 +25,7 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.138 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.139 $' =~ /\d+/g;
     shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
 };
 
@@ -183,10 +183,6 @@
     my $query   = shift;
     if (C4::Context->preference('NoZebra')) {
         my $result = NZorder(NZanalyse($query))->{'biblioserver'}->{'RECORDS'};
-        use Data::Dumper;
-        foreach (@$result) {
-            warn "$query :"address@hidden;
-        }
         return (undef,$result);
     } else {
         my @servers = @_;
@@ -272,7 +268,6 @@
             $query_to_use = $federated_query;
         }
 
-        #          warn "HERE : $query_type => $query_to_use";
         # check if we've got a query_type defined
         eval {
             if ($query_type)
@@ -500,8 +495,6 @@
             }
         }
     }
-    use Data::Dumper;
-    warn Dumper($results_hashref);
     return ( undef, $results_hashref, address@hidden );
 }
 

Index: opac/opac-rss.pl
===================================================================
RCS file: opac/opac-rss.pl
diff -N opac/opac-rss.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ opac/opac-rss.pl    9 May 2007 10:09:40 -0000       1.1
@@ -0,0 +1,128 @@
+#!/usr/bin/perl
+
+use strict;    # always use
+
+use XML::RSS;
+use Digest::MD5 qw(md5_base64);
+use POSIX qw(ceil floor);
+use Date::Calc qw(Today_and_Now Delta_YMDHMS);
+use C4::Context;
+use C4::Search;
+use C4::Koha;
+use C4::Biblio;
+
+=head1 NAME
+
+opac-search.pl : script to have RSS feeds automatically on each OPAC search
+
+=head1 SYNOPSIS
+
+on each query (on OPAC), a link to this script is automatically added. The 
user can save it's queries as RSS feeds.
+This script :
+
+=over 4
+
+  - build the RDF file from the query
+  - save the RDF file in a opac/rss directory for caching : the RDF is 
calculated only once every 30mn, and the cache file name is calculated by a 
md5_base64 of the query (each user registering the same query will use the same 
cache : speed improvement)
+  - let the user specify it's query (q parameter : opac-rss.pl?q=ti:hugo)
+  - let the user specify the number of results returned (by default 20, but 
there are no limits : opac-rss.pl?q=ti:hugo&size=9999)
+
+This script auto calculates the website URL
+
+the RDF contains : 
+
+=over 4
+
+  - Koha: $query as RSS title
+  - Koha as subject
+  - LibraryName systempreference as RDF description and creator
+  - copyright currentyear
+  - biblio title as RSS "title" and biblio author as RSS description
+
+=cut
+
+# create a new CGI object
+# not sure undef_params option is working, need to test
+use CGI qw('-no_undef_params');
+my $cgi = new CGI;
+
+# the query to use
+my $query = $cgi->param('q');
+$query =~ s/:/=/g;
+
+# the number of lines to retrieve
+my $size=$cgi->param('size') || 20;
+
+# the filename of the cached rdf file.
+my $filename = md5_base64($query);
+my $rss = new XML::RSS (version => '1.0');
+
+# the site URL
+my $url = $cgi->url();
+$url =~ s/opac-rss\.pl.*//;
+$url =~ /(http:\/\/.*?)\//;
+my $short_url=$1;
+
+my $RDF_update_needed=1;
+    my ($year,$month,$day, $hour,$min,$sec) = Today_and_Now();
+
+if (-e "rss/$filename") {
+    $rss->parsefile("rss/$filename");
+    # check if we have to rebuild the RSS feed (once every 30mn), or just 
return the actual rdf
+    my $rdf_stamp = $rss->{'channel'}->{'dc'}->{'date'};
+    $rdf_stamp =~ /(.*)-(.*)-(.*):(.*):(.*):(.*)/;
+    my ($stamp_year,$stamp_month,$stamp_day,$stamp_hour,$stamp_min,$stamp_sec) 
= ($1,$2,$3,$4,$5,$6);
+    # if less than 30 mn since the last RDF update, rebuild the RDF. 
Otherwise, just return it
+    unless (($year-$stamp_year >0) or ($month-$stamp_month >0) or 
($day-$stamp_day >0) or ($hour-$stamp_hour >0) or ($min-$stamp_min >30)) {
+        $RDF_update_needed =0;
+    }
+}
+
+if ($RDF_update_needed) {
+#     warn "RDF update in progress";
+    $rss->channel(
+                title        => "Koha : $query",
+                description  => C4::Context->preference("LibraryName"),
+                link => $short_url,
+                dc => {
+                    date       => "$year-$month-$day:$hour:$min:$sec",
+                    subject    => "Koha",
+                    creator    => C4::Context->preference("LibraryName"),
+                    rights     => "Copyright $year" ,
+                    language   => C4::Context->preference("opaclanguages"),
+                },
+    );
+    
+    my $total;    # the total results for the whole set
+    my ($error, $marcresults) = SimpleSearch($query);
+    
+    my $hits = scalar @$marcresults;
+    $hits=$size if $hits > $size;
+    my @results;
+    for(my $i=0;$i<$hits;$i++) {
+        my %resultsloop;
+        my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
+        my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
+        # check if the entry is already in the feed. Otherwise, pop the $line 
th line and add this new one.
+        my $already_in_feed=0;
+        foreach (@{$rss->{'items'}}) {
+            if ($_->{'link'} =~ /biblionumber=$biblio->{'biblionumber'}/) {
+                $already_in_feed=1;
+            }
+        }
+        unless ($already_in_feed) {
+            pop(@{$rss->{'items'}}) if (@{$rss->{'items'}} >= $size);
+            $rss->add_item(title => $biblio->{'title'},
+                            description => $biblio->{'author'},
+                            link        => 
"$url/opac-detail.pl?biblionumber=".$biblio->{'biblionumber'},
+                            mode =>'insert',
+            );
+        }
+    }
+    # save the rss feed.
+    $rss->save("rss/$filename");
+} else {
+#     warn "RDF CACHE used"
+}
+print $cgi->header(-type => "application/rss+xml");
+print $rss->as_string;
\ No newline at end of file




reply via email to

[Prev in Thread] Current Thread [Next in Thread]