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