Missing charset declarations. Needed for translations generated by the
[koha.git] / rss / rss.pl
1 #!/usr/bin/perl -w 
2
3 # This script can be used to generate rss 0.91 files for syndication.
4
5
6 # it should be run from cron like:
7 #
8 #    rss.pl config.conf
9 #
10
11 # Copyright 2003 Katipo Communications
12 #
13 # This file is part of Koha.
14 #
15 # Koha is free software; you can redistribute it and/or modify it under the
16 # terms of the GNU General Public License as published by the Free Software
17 # Foundation; either version 2 of the License, or (at your option) any later
18 # version.
19 #
20 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
21 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
22 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License along with
25 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
26 # Suite 330, Boston, MA  02111-1307 USA
27
28
29 use strict;
30 use HTML::Template;
31 use C4::Context;
32 use Time::Local;
33
34 my $file = $ARGV[0];
35 my %config = getConf("config");
36 my $outFile = $config{"output"};
37 my $feed = HTML::Template->new(filename => $config{"tmpl"});
38
39 my %channel = getConf("channel");
40 $feed->param(CHANNELTITLE => $channel{'title'});
41 $feed->param(CHANNELLINK => $channel{'link'});
42 $feed->param(CHANNELDESC => $channel{'desc'});
43 $feed->param(CHANNELLANG => $channel{'lang'});
44 $feed->param(CHANNELLASTBUILD => getDate());
45
46 my %image = getConf("image");
47 $feed->param(IMAGETITLE => $image{'title'});
48 $feed->param(IMAGEURL => $image{'url'});
49 $feed->param(IMAGELINK => $image{'link'});
50
51 #
52 # handle the items
53 #
54 $feed->param(ITEMS => getItems($config{'query'}));
55
56 open(FILE, ">$outFile") or die "can't open $outFile";
57 print FILE $feed->output();
58 close FILE;
59
60 sub getDate {
61     my $date = localtime(timelocal(localtime));
62     return $date;
63 }
64
65 sub getConf {
66     my $section = shift;
67     my %return;
68     my $inSection = 0;
69
70     open(FILE,$file) or die "can't open $file";
71     while (<FILE>) {
72         if ($inSection) {
73             my @line = split(/=/,$_,2);
74             unless ($line[1]) {
75                 $inSection=0;
76             } else {
77                 my ($key, $value) = @line;
78                 chomp $value;
79                 $return{$key} = $value;
80             }
81         } else {
82             if ($_ eq "$section\n") { $inSection = 1 }
83         }
84     }
85     return %return;
86 }
87 sub getItems {
88     my $query = shift;
89     $query .= " limit 15";
90     my $dbh = C4::Context->dbh;
91     my $sth=$dbh->prepare($query);
92     $sth->execute;
93     my @return;
94     while (my $data = $sth->fetchrow_hashref) {
95         foreach my $key (keys %$data) {
96             my $value=$data->{$key};
97             $value=~s/\&/\&amp;/g and $data->{$key}=$value;
98         }
99         push @return, $data;
100     }
101     $sth->finish;
102     return \@return;
103 }
104
105
106
107
108
109