]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RssFeed.php
Use HTML 5 DOCTYPE; force CHARSET=utf-8
[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         $rss_parser = new RSSParser();
58
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                 $cell_author = HTML::raw($item['author']);
98                 $cell_pubDate = HTML::raw($item['pubDate']);
99                 $cell_authordate = HTML::div(array('class' => 'authordate'),
100                     $cell_author, HTML::raw(" - "), $cell_pubDate);
101                 $cell->pushContent($cell_authordate);
102                 if ((!$titleonly) && (!empty($item['description'])))
103                     $cell->pushContent(HTML::div(array('class' => 'itemdesc'),
104                         HTML::raw($item['description'])));
105                 $html->pushContent($cell);
106             }
107         } else {
108             $html = HTML::div(array('class' => 'rss'), HTML::em(_("no RSS items")));
109         }
110         return $html;
111     }
112
113     function box($args = false, $request = false, $basepage = false)
114     {
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 // Local Variables:
128 // mode: php
129 // tab-width: 8
130 // c-basic-offset: 4
131 // c-hanging-comment-ender-p: nil
132 // indent-tabs-mode: nil
133 // End: