]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RssFeed.php
rcs_id no longer makes sense with Subversion global version number
[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     function getName () {
31         return _("RssFeed");
32     }
33
34     function getDescription () {
35         return _("Simple RSS Feed aggregator Plugin");
36
37     }
38
39     // Establish default values for each of this plugin's arguments.
40     function getDefaultArguments() {
41         return array('feed'        => "",
42                      'description' => "",
43                      'url'         => "", //"http://phpwiki.org/RecentChanges?format=rss",
44                      'maxitem'     => 0,
45                      'titleonly'   => false,
46                      'debug'       => false,
47                      );
48    }
49
50     function run($dbi, $argstr, &$request, $basepage) {
51         extract($this->getArgs($argstr, $request));
52
53         if (defined('CHARSET'))
54                 $rss_parser = new RSSParser(CHARSET);
55         else
56                 $rss_parser = new RSSParser();
57
58         if (!empty($url))
59             $rss_parser->parse_url( $url, $debug );
60
61         if (!empty($rss_parser->channel['title'])) $feed = $rss_parser->channel['title'];
62         if (!empty($rss_parser->channel['link']))  $url  = $rss_parser->channel['link'];
63         if (!empty($rss_parser->channel['description']))
64             $description = $rss_parser->channel['description'];
65
66         if (!empty($feed)) {
67             if (!empty($url)) {
68                 $titre = HTML::span(HTML::a(array('href'=>$rss_parser->channel['link']),
69                                             $rss_parser->channel['title']));
70             } else {
71                 $titre = HTML::span($rss_parser->channel['title']);
72             }
73             $th = HTML::div(array('class'=> 'feed'), $titre);
74             if (!empty($description))
75                 $th->pushContent(HTML::p(array('class' => 'chandesc'),
76                                          HTML::raw($description)));
77         } else {
78             $th = HTML();
79         }
80
81         if (!empty($rss_parser->channel['date']))
82             $th->pushContent(HTML::raw("<!--".$rss_parser->channel['date']."-->"));
83         $html = HTML::div(array('class'=> 'rss'), $th);
84         if ($rss_parser->items) {
85             // only maxitem's
86             if ( $maxitem > 0 )
87                 $rss_parser->items = array_slice($rss_parser->items, 0, $maxitem);
88             foreach ($rss_parser->items as $item) {
89                 $cell = HTML::div(array('class'=> 'rssitem'));
90                 if ($item['link'] and empty($item['title']))
91                     $item['title'] = $item['link'];
92                 $cell_title = HTML::div(array('class'=> 'itemname'),
93                                         HTML::a(array('href'=>$item['link']),
94                                                 HTML::raw($item['title'])));
95                 $cell->pushContent($cell_title);
96                 $cell_author = HTML::raw($item['author']);
97                 $cell_pubDate = HTML::raw($item['pubDate']);
98                 $cell_authordate = HTML::div(array('class'=> 'authordate'),
99                                              $cell_author, HTML::raw(" - "), $cell_pubDate);
100                 $cell->pushContent($cell_authordate);
101                 if ((!$titleonly) && (!empty($item['description'])))
102                     $cell->pushContent(HTML::div(array('class'=> 'itemdesc'),
103                                                  HTML::raw($item['description'])));
104                 $html->pushContent($cell);
105             }
106         } else {
107             $html = HTML::div(array('class'=> 'rss'), HTML::em(_("no RSS items")));
108         }
109         if (!check_php_version(5))
110             $rss_parser->__destruct();
111         return $html;
112     }
113
114     function box($args=false, $request=false, $basepage=false) {
115         if (!$request) $request =& $GLOBALS['request'];
116         extract($args);
117         if (empty($title)) $title = _("RssFeed");
118         if (empty($url))   $url = 'http://phpwiki.sourceforge.net/phpwiki/RecentChanges?format=rss';
119         $argstr = "url=$url";
120         if (isset($maxitem) and is_numeric($maxitem)) $argstr .=  " maxitem=$maxitem";
121         return $this->makeBox($title,
122                               $this->run($request->_dbi, $argstr, $request, $basepage));
123     }
124
125 };
126
127 // For emacs users
128 // Local Variables:
129 // mode: php
130 // tab-width: 8
131 // c-basic-offset: 4
132 // c-hanging-comment-ender-p: nil
133 // indent-tabs-mode: nil
134 // End:
135 ?>