]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RssFeed.php
Activated Revision substitution for Subversion
[SourceForge/phpwiki.git] / lib / plugin / RssFeed.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /*
4  Copyright 2003 Arnaud Fontaine
5
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 */
22 /**
23  * @author: Arnaud Fontaine
24  */
25 include("lib/RssParser.php");
26
27 class WikiPlugin_RssFeed
28 extends WikiPlugin
29 {
30     // Five required functions in a WikiPlugin.
31     function getName () {
32         return _("RssFeed");
33     }
34
35     function getDescription () {
36         return _("Simple RSS Feed aggregator Plugin");
37
38     }
39
40     function getVersion() {
41         return preg_replace("/[Revision: $]/", '',
42                             "\$Revision$");
43     }
44
45     // Establish default values for each of this plugin's arguments.
46     function getDefaultArguments() {
47         return array('feed'             => "",
48                      'description'      => "",
49                      'url'              => "", //"http://phpwiki.org/RecentChanges?format=rss",
50                      'maxitem'          => 0,
51                      'debug'            => false,
52                      );
53    }
54
55     function run($dbi, $argstr, &$request, $basepage) {
56         extract($this->getArgs($argstr, $request));
57
58         $rss_parser = new RSSParser();
59         if (!empty($url))
60             $rss_parser->parse_url( $url, $debug );
61
62         if (!empty($rss_parser->channel['title'])) $feed = $rss_parser->channel['title'];
63         if (!empty($rss_parser->channel['link']))  $url  = $rss_parser->channel['link'];
64         if (!empty($rss_parser->channel['description'])) 
65             $description = $rss_parser->channel['description'];
66         
67         if (!empty($feed)) {
68             if (!empty($url)) {
69                 $titre = HTML::span(HTML::a(array('href'=>$rss_parser->channel['link']),
70                                             $rss_parser->channel['title'])); 
71             } else {
72                 $titre = HTML::span($rss_parser->channel['title']);
73             }
74             $th = HTML::div(array('class'=> 'feed'), $titre);
75             if (!empty($description))
76                 $th->pushContent(HTML::p(array('class' => 'chandesc'),
77                                          HTML::raw($description)));
78         } else {
79             $th = HTML();
80         }
81
82         if (!empty($rss_parser->channel['date']))
83             $th->pushContent(HTML::raw("<!--".$rss_parser->channel['date']."-->"));
84         $html = HTML::div(array('class'=> 'rss'), $th);
85         if ($rss_parser->items) { 
86             // only maxitem's
87             if ( $maxitem > 0 )
88                 $rss_parser->items = array_slice($rss_parser->items, 0, $maxitem);
89             foreach ($rss_parser->items as $item) {
90                 $cell = HTML::div(array('class'=> 'rssitem'));
91                 if ($item['link'] and empty($item['title']))
92                     $item['title'] = $item['link'];
93                 $cell_title = HTML::div(array('class'=> 'itemname'),
94                                         HTML::a(array('href'=>$item['link']),
95                                                 HTML::raw($item['title'])));
96                 $cell->pushContent($cell_title);
97                 if (!empty($item['description']))
98                     $cell->pushContent(HTML::div(array('class'=> 'itemdesc'),
99                                                  HTML::raw($item['description'])));
100                 $html->pushContent($cell);
101             }
102         } else {
103             $html = HTML::div(array('class'=> 'rss'), HTML::em(_("no RSS items")));
104         }
105         if (!check_php_version(5))
106             $rss_parser->__destruct();
107         return $html;
108     }
109
110     function box($args=false, $request=false, $basepage=false) {
111         if (!$request) $request =& $GLOBALS['request'];
112         extract($args);
113         if (empty($title)) $title = _("RssFeed");
114         if (empty($url))   $url = 'http://phpwiki.sourceforge.net/phpwiki/RecentChanges?format=rss';
115         $argstr = "url=$url";
116         if (isset($maxitem) and is_numeric($maxitem)) $argstr .=  " maxitem=$maxitem";
117         return $this->makeBox($title,
118                               $this->run($request->_dbi, $argstr, $request, $basepage));
119     }
120
121 };
122
123 // $Log: not supported by cvs2svn $
124 // Revision 1.9  2004/11/03 16:34:10  rurban
125 // proper msg if rss connection is broken or no items found
126 //
127 // Revision 1.8  2004/07/08 20:30:07  rurban
128 // plugin->run consistency: request as reference, added basepage.
129 // encountered strange bug in AllPages (and the test) which destroys ->_dbi
130 //
131 // Revision 1.7  2004/06/08 21:03:20  rurban
132 // updated RssParser for XmlParser quirks (store parser object params in globals)
133 //
134 // Revision 1.6  2004/05/24 17:36:06  rurban
135 // new interface
136 //
137 // Revision 1.5  2004/05/18 16:18:37  rurban
138 // AutoSplit at subpage seperators
139 // RssFeed stability fix for empty feeds or broken connections
140 //
141 // Revision 1.4  2004/04/18 01:11:52  rurban
142 // more numeric pagename fixes.
143 // fixed action=upload with merge conflict warnings.
144 // charset changed from constant to global (dynamic utf-8 switching)
145 //
146
147 // For emacs users
148 // Local Variables:
149 // mode: php
150 // tab-width: 8
151 // c-basic-offset: 4
152 // c-hanging-comment-ender-p: nil
153 // indent-tabs-mode: nil
154 // End:
155 ?>