1<?php
2
3/**
4 * Description of iCal
5 *
6 * @author Tomas Zaruba
7 */
8
9/**
10 * Noticeboard Plugin - iCal 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_ICal extends DokuWiki_Plugin{
27    private $category;
28    private $parentId;
29    private $noticeList;
30
31
32    public function helper_plugin_noticeboard_ICal($id){
33        $this->parentId = $id;
34        $this->noticeList = new helper_plugin_noticeboard_NoticeList($this->parentId);
35         //set category filter
36        if($_SESSION['noticeboard_list_category']){
37            $this->noticeList->setCategoryFilter($_SESSION['noticeboard_list_category']);
38        }else{
39            $this->noticeList->setCategoryFilter(8);
40        }
41
42        //set time filter
43        if($_SESSION['noticeboard_show_time']){
44            $this->noticeList->setTimeFilter($_SESSION['noticeboard_show_time']);
45        }else{
46            $this->noticeList->setTimeFilter(1);
47        }
48
49    }
50
51    public function generateOutput(){
52        Global $conf;
53        header("Content-Type: text/calendar; charset=UTF-8");
54        header('Content-Disposition: attachment; filename="calendar.ics"');
55        $out;
56        $out .= $this->getHeader();
57        $out .= $this->getBody();
58        $out .= $this->getFooter();
59        echo $out;
60    }
61
62    private function getHeader(){
63        Global $conf;
64
65        $out .= "BEGIN:VCALENDAR\r\n";
66        $out .= "VERSION:2.0\r\n";
67        $out .= "PRODID:-//Dokuwiki//Wiki//EN\r\n";
68        $out .= "CALSCALE:GREGORIAN\r\n";
69        $out .= "METHOD:PUBLISH\r\n";
70        //$out .= "X-WR-TIMEZONE:Europe/Moscow\r\n";
71
72        return $out;
73
74    }
75
76    private function getBody(){
77        $link = "http://".$_SERVER['SERVER_NAME'];
78
79        $arrayList = $this->noticeList->getNoticeList(0,50);   //last 50 msges
80        while(($arrayList && $arrayList->hasNext())){
81            $notice = $arrayList->next();
82            $out .= "BEGIN:VEVENT\r\n";
83            $out .= "TRANSP:TRANSPARENT\r\n";
84            $out .= "LOCATION:".$notice->getPlace()."\r\n";
85            $out .= "SUMMARY:".$notice->getName()."\r\n";
86            $out .= "DTSTART:".date("Ymd\THis\Z",$notice->getStartTime())."\r\n";
87            if($notice->getHasEnd()){
88                $out .= "DTEND:".date("Ymd\THis\Z",$notice->getEndTime())."\r\n";
89            }else{
90                $out .= "DTEND:".date("Ymd\THis\Z",$notice->getStartTime())."\r\n";
91            }
92            $out .= "END:VEVENT\r\n";
93
94            if($notice->getDeadline()){
95                $out .= "BEGIN:VEVENT\r\n";
96                $out .= "TRANSP:TRANSPARENT\r\n";
97                $out .= "LOCATION:".$notice->getPlace()."\r\n";
98                $out .= "SUMMARY:".$notice->getName()." - Deadline\r\n";
99                $out .= "DTSTART:".date("Ymd\THis\Z",$notice->getDeadline())."\r\n";
100                $out .= "DTEND:".date("Ymd\THis\Z",$notice->getDeadline())."\r\n";
101                $out .= "END:VEVENT\r\n";
102            }
103        }
104        return $out;
105    }
106
107
108
109
110    private function getFooter(){
111        $out;
112        $out .="END:VCALENDAR\r\n";
113        return $out;
114    }
115
116}
117
118
119?>
120