]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AtomFeed.php
New FSF address
[SourceForge/phpwiki.git] / lib / plugin / AtomFeed.php
1 <?php // -*-php-*-
2 // $Id$
3 /*
4  * Copyright 2010 Sébastien Le Callonnec
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: Sébastien Le Callonnec
24  */
25 require_once('lib/WikiPlugin.php');
26 require_once('lib/AtomParser.php');
27
28 class WikiPlugin_AtomFeed
29 extends WikiPlugin
30 {
31     function getName() {
32         return _('AtomFeed');
33     }
34     
35     function getDescription() {
36         return _('Atom Aggregator Plugin');
37     }
38     
39     function getDefaultArguments() {
40         return array(
41            'feed' => "",
42            'description' => "",
43            'url' => "",
44            'maxitem' => 0,
45            'titleonly' => false
46         );
47     }
48    
49     function run($dbi, $argstr, &$request, $basepage) {
50         extract($this->getArgs($argstr, $request));
51         $parser = new AtomParser();
52         
53         assert(!empty($url));
54         $parser->parse_url($url);
55         
56         $html = '';
57         
58         $items = HTML::dl();
59         foreach ($parser->feed as $feed) {
60             $title = HTML::h3(HTML::a(array('href' => $feed["links"]["0"]["href"]), $feed["title"]));
61             $counter = 1;
62             foreach($parser->entries as $entry) {
63                 $item = HTML::dt(HTML::a(array('href' => $entry["links"]["0"]["href"]), $entry["title"]));
64                 $items->pushContent($item);
65                 
66                 if (!$titleonly) {
67                     $description = HTML::dd(HTML::raw(html_entity_decode($entry["content"])));
68                 } else {
69                     $description = HTML::dd();
70                 }
71                 $items->pushContent($description);
72                 
73                 if ($maxitem > 0 && $counter >= $maxitem) {
74                     break;
75                 }
76                 $counter++;
77             }
78             $html = HTML::div(array('class'=> 'rss'), $title);
79             $html->pushContent($items);
80         }
81
82         return $html;
83     }
84 }
85 ?>