]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RssFeed.php
getName should not translate
[SourceForge/phpwiki.git] / lib / plugin / RssFeed.php
1 <?php
2
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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22 /**
23  * @author: Arnaud Fontaine
24  */
25 include 'lib/RssParser.php';
26
27 class WikiPlugin_RssFeed
28     extends WikiPlugin
29 {
30     function getDescription()
31     {
32         return _("Simple RSS Feed aggregator.");
33     }
34
35     // Establish default values for each of this plugin's arguments.
36     function getDefaultArguments()
37     {
38         return array('feed' => "",
39             'description' => "",
40             'url' => "", //"http://phpwiki.org/RecentChanges?format=rss",
41             'maxitem' => 0,
42             'titleonly' => false,
43             'debug' => false,
44         );
45     }
46
47     function run($dbi, $argstr, &$request, $basepage)
48     {
49         extract($this->getArgs($argstr, $request));
50
51         $rss_parser = new RSSParser();
52
53         if (!empty($url))
54             $rss_parser->parse_url($url, $debug);
55
56         if (!empty($rss_parser->channel['title'])) $feed = $rss_parser->channel['title'];
57         if (!empty($rss_parser->channel['link'])) $url = $rss_parser->channel['link'];
58         if (!empty($rss_parser->channel['description']))
59             $description = $rss_parser->channel['description'];
60
61         if (!empty($feed)) {
62             if (!empty($url)) {
63                 $titre = HTML::span(HTML::a(array('href' => $rss_parser->channel['link']),
64                     $rss_parser->channel['title']));
65             } else {
66                 $titre = HTML::span($rss_parser->channel['title']);
67             }
68             $th = HTML::div(array('class' => 'feed'), $titre);
69             if (!empty($description))
70                 $th->pushContent(HTML::p(array('class' => 'chandesc'),
71                     HTML::raw($description)));
72         } else {
73             $th = HTML();
74         }
75
76         if (!empty($rss_parser->channel['date']))
77             $th->pushContent(HTML::raw("<!--" . $rss_parser->channel['date'] . "-->"));
78         $html = HTML::div(array('class' => 'rss'), $th);
79         if ($rss_parser->items) {
80             // only maxitem's
81             if ($maxitem > 0)
82                 $rss_parser->items = array_slice($rss_parser->items, 0, $maxitem);
83             foreach ($rss_parser->items as $item) {
84                 $cell = HTML::div(array('class' => 'rssitem'));
85                 if ($item['link'] and empty($item['title']))
86                     $item['title'] = $item['link'];
87                 $cell_title = HTML::div(array('class' => 'itemname'),
88                     HTML::a(array('href' => $item['link']),
89                         HTML::raw($item['title'])));
90                 $cell->pushContent($cell_title);
91                 $cell_author = HTML::raw($item['author']);
92                 $cell_pubDate = HTML::raw($item['pubDate']);
93                 $cell_authordate = HTML::div(array('class' => 'authordate'),
94                     $cell_author, HTML::raw(" - "), $cell_pubDate);
95                 $cell->pushContent($cell_authordate);
96                 if ((!$titleonly) && (!empty($item['description'])))
97                     $cell->pushContent(HTML::div(array('class' => 'itemdesc'),
98                         HTML::raw($item['description'])));
99                 $html->pushContent($cell);
100             }
101         } else {
102             $html = HTML::div(array('class' => 'rss'), HTML::em(_("no RSS items")));
103         }
104         return $html;
105     }
106
107     function box($args = false, $request = false, $basepage = false)
108     {
109         if (!$request) $request =& $GLOBALS['request'];
110         extract($args);
111         if (empty($title)) $title = _("RssFeed");
112         if (empty($url)) $url = 'http://phpwiki.sourceforge.net/phpwiki/RecentChanges?format=rss';
113         $argstr = "url=$url";
114         if (isset($maxitem) and is_numeric($maxitem)) $argstr .= " maxitem=$maxitem";
115         return $this->makeBox($title,
116             $this->run($request->_dbi, $argstr, $request, $basepage));
117     }
118
119 }
120
121 // Local Variables:
122 // mode: php
123 // tab-width: 8
124 // c-basic-offset: 4
125 // c-hanging-comment-ender-p: nil
126 // indent-tabs-mode: nil
127 // End: