1<?php
2
3/**
4 * Description of rss
5 *
6 * @author Tomas Zaruba
7 */
8
9/**
10 * Noticeboard Plugin - RSS GENERATE
11 *
12 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
13 * @author  Zaruba Tomas <zatomik@gmail.com>
14 */
15
16// must be run within Dokuwiki
17if(!defined('DOKU_INC')) die();
18if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
19
20require_once(DOKU_PLUGIN."noticeboard/classes/NoticeList.php");
21/**
22 * Rss class
23 *
24 * @author Tomas Zaruba
25 */
26class helper_plugin_noticeboard_Rss extends DokuWiki_Plugin{
27    private $category;
28    private $parentId;
29    private $noticeList;
30
31
32    public function helper_plugin_noticeboard_Rss($category,$parentId){
33        $this->category = $category;
34        $this->parentId = $parentId;
35
36        $this->noticeList = new helper_plugin_noticeboard_NoticeList($this->parentId);
37        $this->noticeList->setCategoryFilter($category);
38        $this->noticeList->setTimeFilter(3);
39        $this->noticeList->setSortFilter(1);
40
41    }
42
43    public function generateOutput(){
44        Global $conf;
45        header("Content-Type: application/xml; charset=UTF-8");
46        $out;
47        $out .= $this->getHeader();
48        $out .= $this->getBody();
49        $out .= $this->getFooter();
50        echo $out;
51    }
52
53    private function getHeader(){
54        Global $conf;
55        $link = "http://".$_SERVER['SERVER_NAME'];
56
57        $out  = '';
58        $out .= "<?xml version='1.0' encoding='UTF-8' ?>";
59        $out .= "<rss version='2.0'>";
60        $out .= "<channel>";
61        $out .= "<title>".$conf['title']." - ".$this->parentId."</title>";
62        $out .= "<language>".$conf['lang']."</language>";
63        $out .= "<description>".$this->getLang('rssDesc')."</description>";
64        $out .= "<link>".$link .wl($this->parentId, array('do' => 'show'))."</link>";
65        return $out;
66
67    }
68
69    private function getBody(){
70        $link = "http://".$_SERVER['SERVER_NAME'];
71        $out;
72        $arrayList = $this->noticeList->getNoticeList(0,50);   //last 50 msges
73        while(($arrayList && $arrayList->hasNext())){
74            $notice = $arrayList->next();
75            $out .= "<item>";
76            $out .= "<title>".$notice->getName()."</title>";
77            $out .= "<link>".$link .wl($notice->getId(), array('do' => 'show'))."</link>";
78            $out .= "<description>";
79            $out .= $this->getLang('startTime').": ";
80            if($notice->hasStartTime()){
81                $out .= date("d.m.Y H:i",$notice->getStartTime());
82            }else{
83                $out .= date("d.m.Y",$notice->getStartTime());
84            }
85            $out .= " <br />";
86            $out .= $this->getLang('category').": ".$this->getLang($notice->getCategory());
87            $out .= " <br />";
88            if($notice->getEndTime()){
89                $out .= $this->getLang('endTime').": ";
90                if($notice->hasEndTime()){
91                    $out .= date("d.m.Y H:i",$notice->getEndTime());
92                }else{
93                    $out .= date("d.m.Y",$notice->getEndTime());
94                }
95                $out .= " <br />";
96            }
97             if($notice->getDeadline()){
98                 $out .= $this->getLang('deadline').": ";
99                 $out .= date("d.m.Y",$notice->getDeadline());
100                 $out .= " <br />";
101            }
102
103            if($notice->getPlace()){
104                 $out .= $this->getLang('place').": ";
105                 $out .= $notice->getPlace();
106                 $out .= " <br />";
107            }
108            $out .= $this->getLang('moreInfo').": <a href='".$link .wl($notice->getId(), array('do' => 'show'))."'>".$notice->getName()."</a>";
109
110            $out .= "</description>";
111            $out .= "<pubDate>".date(DATE_RFC822,$notice->getStartTime())."</pubDate>";
112            $out .= "</item>";
113
114            if($notice->getDeadline()){
115                $out .= "<item>";
116                $out .= "<title>".$notice->getName()." Deadline</title>";
117                $out .= "<link>".$link .wl($notice->getId(), array('do' => 'show'))."</link>";
118                $out .= "<description>";
119                $out .= $this->getLang('startTime').": ";
120                if($notice->hasStartTime()){
121                    $out .= date("d.m.Y H:i",$notice->getStartTime());
122                }else{
123                    $out .= date("d.m.Y",$notice->getStartTime());
124                }
125                $out .= " <br />";
126                 if($notice->getDeadline()){
127                     $out .= $this->getLang('deadline').": ";
128                     $out .= date("d.m.Y",$notice->getDeadline());
129                     $out .= "<br />";
130                }
131                $out .= "<a href='".$link .wl($notice->getId(), array('do' => 'show'))."'>".$this->getLang('moreInfo')."</a>";
132
133                $out .= "</description>";
134                $out .= "<pubDate>".date(DATE_RFC822,$notice->getDeadline())."</pubDate>";
135                $out .= "</item>";
136            }
137        }
138        return $out;
139    }
140
141
142
143
144    private function getFooter(){
145        $out;
146        $out .="</channel></rss>";
147        return $out;
148    }
149
150}
151
152
153?>
154