]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AtomFeed.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / plugin / AtomFeed.php
1 <?php // -*-php-*-
2 /*
3  * Copyright 2010 Sébastien Le Callonnec
4  *
5  * This file is part of PhpWiki.
6  *
7  * PhpWiki is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * PhpWiki is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21 /**
22  * @author: Sébastien Le Callonnec
23  */
24 require_once 'lib/WikiPlugin.php';
25 require_once 'lib/AtomParser.php';
26
27 class WikiPlugin_AtomFeed
28 extends WikiPlugin
29 {
30     function getName() {
31         return _('AtomFeed');
32     }
33
34     function getDescription() {
35         return _('Atom Aggregator Plugin');
36     }
37
38     function getDefaultArguments() {
39         return array(
40            'feed' => "",
41            'description' => "",
42            'url' => "",
43            'maxitem' => 0,
44            'titleonly' => false
45         );
46     }
47
48     function run($dbi, $argstr, &$request, $basepage) {
49         extract($this->getArgs($argstr, $request));
50         $parser = new AtomParser();
51
52         assert(!empty($url));
53         $parser->parse_url($url);
54
55         $html = '';
56
57         $items = HTML::dl();
58         foreach ($parser->feed as $feed) {
59             $title = HTML::h3(HTML::a(array('href' => $feed["links"]["0"]["href"]), $feed["title"]));
60             $counter = 1;
61             foreach($parser->entries as $entry) {
62                 $item = HTML::dt(HTML::a(array('href' => $entry["links"]["0"]["href"]), $entry["title"]));
63                 $items->pushContent($item);
64
65                 if (!$titleonly) {
66                     $description = HTML::dd(HTML::raw(html_entity_decode($entry["content"])));
67                 } else {
68                     $description = HTML::dd();
69                 }
70                 $items->pushContent($description);
71
72                 if ($maxitem > 0 && $counter >= $maxitem) {
73                     break;
74                 }
75                 $counter++;
76             }
77             $html = HTML::div(array('class'=> 'rss'), $title);
78             $html->pushContent($items);
79         }
80
81         return $html;
82     }
83 }