From 758851a92291fa989db6c4f3fb6ffaf3b280092e Mon Sep 17 00:00:00 2001 From: kados Date: Fri, 3 Aug 2007 18:42:47 -0500 Subject: [PATCH] perltidy opac-rss.pl --- opac/opac-rss.pl | 101 +++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 42 deletions(-) diff --git a/opac/opac-rss.pl b/opac/opac-rss.pl index eb4fb891e2..ae8e69869a 100755 --- a/opac/opac-rss.pl +++ b/opac/opac-rss.pl @@ -68,78 +68,95 @@ my $query = $cgi->param('q'); $query =~ s/:/=/g; # the number of lines to retrieve -my $size=$cgi->param('size') || 50; +my $size = $cgi->param('size') || 50; # the filename of the cached rdf file. my $filename = md5_base64($query); -my $rss = new XML::RSS (version => '1.0'); +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 $short_url = $1; -my $RDF_update_needed=1; - my ($year,$month,$day, $hour,$min,$sec) = Today_and_Now(); +my $RDF_update_needed = 1; +my ( $year, $month, $day, $hour, $min, $sec ) = Today_and_Now(); -if (-e "rss/$filename") { +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 + +# 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 more 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; + my ( + $stamp_year, $stamp_month, $stamp_day, + $stamp_hour, $stamp_min, $stamp_sec + ) = ( $1, $2, $3, $4, $5, $6 ); + +# if more 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"; + + # 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"), - }, + 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 ( $error, $marcresults ) = SimpleSearch($query); + my $hits = scalar @$marcresults; - $hits=$size if $hits > $size; + $hits = $size if $hits > $size; my @results; - for(my $i=0;$i<$hits;$i++) { + 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; + 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', + 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"); +else { + + # warn "RDF CACHE used" +} +print $cgi->header( -type => "application/rss+xml" ); print $rss->as_string; -- 2.39.5