lib/PurpleWiki/Syndication/Rss.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 71 CC 2 SCAR 10.6
CC
2
Cov
0%
new
6.0
getRSS
2.0
_getWikiHTML
2.0
CRAP 2.9
1 # PurpleWiki::Syndication::Rss.pm
2 # vi:ai:sm:et:sw=4:ts=4
3 #
4 # $Id: Rss.pm 448 2004-08-06 11:25:09Z eekim $
5 #
6 # Copyright (c) Blue Oxen Associates 2002-2003. All rights reserved.
7 #
8 # This file is part of PurpleWiki. PurpleWiki is derived from:
9 #
10 # UseModWiki v0.92 (c) Clifford A. Adams 2000-2001
11 # AtisWiki v0.3 (c) Markus Denker 1998
12 # CVWiki CVS-patches (c) Peter Merel 1997
13 # The Original WikiWikiWeb (c) Ward Cunningham
14 #
15 # PurpleWiki is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
19 #
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the
27 # Free Software Foundation, Inc.
28 # 59 Temple Place, Suite 330
29 # Boston, MA 02111-1307 USA
30  
31 package PurpleWiki::Syndication::Rss;
32  
33 # PurpleWiki Rss generation
34 #
35 # FIXME: Replace getRecentChanges with the Idiom code when it is done,
36 # from whence much of this is stolen.
37  
38 use strict;
39 use XML::RSS;
40 use PurpleWiki::Database;
41 use PurpleWiki::Database::Page;
42 use PurpleWiki::Parser::WikiText;
43  
44 our $VERSION;
45 $VERSION = sprintf("%d", q$Id: Rss.pm 448 2004-08-06 11:25:09Z eekim $ =~ /\s(\d+)\s/);
46  
47 sub new {
48 my $proto = shift;
49 my $self = { @_ };
50 my $class = ref($proto) || $proto;
51 $self->{config} = PurpleWiki::Config->instance();
52 die "No config object found" if not defined $self->{config};
53 bless($self, $class);
54 return $self;
55 }
56  
57 sub getRSS {
58 my $self = shift;
59 my $count = shift || 15;
60 my $string;
61  
62 my $rcRef = PurpleWiki::Database::recentChanges($self->{config});
63 my @recentChanges = @{$rcRef};
64  
65 my $rss = new XML::RSS;
66 $rss->channel (
67 title => $self->{config}->SiteName,
68 # FIXME: this isn't good enough as it might not be set
69 # to a full URL. FullURL is optional though, so?
70 link => $self->{config}->ScriptName,
71 );
72  
73 # FIXME: depending on the wrong variable here, probably better
74 # to loop on the array
75 while ($count-- > 0) {
76 my $recentChange = shift(@recentChanges) || last;
77  
78 my $bodyText = $self->_getWikiHTML($recentChange->{id});
79  
80 $rss->add_item(
81 title => $recentChange->{pageName},
82 link => $self->{config}->ScriptName . '?' .$recentChange->{id},
83 dc => {
84 creator => $recentChange->{userName},
85 },
86 description => "<![CDATA[$bodyText]]>\n",
87 );
88 }
89  
90 return $rss->as_string;
91 }
92  
93 sub _getWikiHTML {
94 my $self = shift;
95 my $id = shift;
96  
97 my $url = $self->{config}->ScriptName . '?' . $id;
98 my $page = new PurpleWiki::Database::Page(id => $id);
99 $page->openPage();
100 my $parser = PurpleWiki::Parser::WikiText->new();
101 my $wiki = $parser->parse($page->getText()->getText(),
102 add_node_ids => 0,
103 url => $url,
104 );
105 return $wiki->view('wikihtml', url => $url);
106 }
107  
108 1;
109 __END__