]> git.mxchange.org Git - friendica-addons.git/blob - dav/wdcal_cal_source_friendicaevents.inc.php
Merge remote branch 'upstream/master'
[friendica-addons.git] / dav / wdcal_cal_source_friendicaevents.inc.php
1 <?php
2
3 class FriendicaCalSourceEvents extends AnimexxCalSource
4 {
5
6         /**
7          * @return int
8          */
9         public static function getNamespace()
10         {
11                 return CALDAV_NAMESPACE_FRIENDICA_NATIVE;
12         }
13
14         /**
15          * @param int $user
16          * @return array
17          */
18         public function getPermissionsCalendar($user)
19         {
20                 if ($user == $this->calendarDb->uid) return array("read"=> true, "write"=> false);
21                 return array("read"=> false, "write"=> false);
22         }
23
24         /**
25          * @param int $user
26          * @param string $item_uri
27          * @param string $recurrence_uri
28          * @param null|array $item_arr
29          * @return array
30          */
31         public function getPermissionsItem($user, $item_uri, $recurrence_uri, $item_arr = null)
32         {
33                 $cal_perm = $this->getPermissionsCalendar($user);
34                 if (!$cal_perm["read"]) return array("read"=> false, "write"=> false);
35                 return array("read"=> true, "write"=> false);
36         }
37
38
39         /**
40          * @param string $uri
41          * @param array $start
42          * @param array $end
43          * @param string $subject
44          * @param bool $allday
45          * @param string $description
46          * @param string $location
47          * @param null $color
48          * @param string $timezone
49          * @param bool $notification
50          * @param null $notification_type
51          * @param null $notification_value
52          * @throws Sabre_DAV_Exception_MethodNotAllowed
53          */
54         public function updateItem($uri, $start, $end, $subject = "", $allday = false, $description = "", $location = "", $color = null, $timezone = "", $notification = true, $notification_type = null, $notification_value = null)
55         {
56                 throw new Sabre_DAV_Exception_MethodNotAllowed();
57         }
58
59         /**
60          * @param array $start
61          * @param array $end
62          * @param string $subject
63          * @param bool $allday
64          * @param string $description
65          * @param string $location
66          * @param null $color
67          * @param string $timezone
68          * @param bool $notification
69          * @param null $notification_type
70          * @param null $notification_value
71          * @throws Sabre_DAV_Exception_MethodNotAllowed
72          * @return array|string
73          */
74         public function addItem($start, $end, $subject, $allday = false, $description = "", $location = "", $color = null,
75                                                         $timezone = "", $notification = true, $notification_type = null, $notification_value = null)
76         {
77                 throw new Sabre_DAV_Exception_MethodNotAllowed();
78         }
79
80         /**
81          * @param array $row
82          * @return array
83          */
84         private function virtualData2wdcal($row) {
85                 $end = wdcal_mySql2PhpTime($row["data_end"]);
86                 if ($row["data_allday"]) $end--;
87                 $start = wdcal_mySql2PhpTime($row["data_start"]);
88                 $a = get_app();
89                 $arr             = array(
90                         "uri"               => $row["data_uri"],
91                         "subject"           => escape_tags($row["data_subject"]),
92                         "start"             => $start,
93                         "end"               => $end,
94                         "is_allday"         => ($row["data_allday"] == 1),
95                         "is_moredays"       => (date("Ymd", $start) != date("Ymd", $end)),
96                         "is_recurring"      => ($row["data_type"] == "birthday"),
97                         "color"             => "#ff0000",
98                         "is_editable"       => false,
99                         "is_editable_quick" => false,
100                         "location"          => $row["data_location"],
101                         "attendees"         => '',
102                         "has_notification"  => false,
103                         "url_detail"        => $a->get_baseurl() . "/dav/wdcal/" . $row["data_uri"] . "/",
104                         "url_edit"          => "",
105                         "special_type"      => ($row["data_type"] == "birthday" ? "birthday" : ""),
106                 );
107                 return $arr;
108         }
109
110         /**
111          * @param string $sd
112          * @param string $ed
113          * @param string $base_path
114          * @return array
115          */
116         public function listItemsByRange($sd, $ed, $base_path)
117         {
118                 $usr_id = IntVal($this->calendarDb->uid);
119
120                 $evs =  FriendicaVirtualCalSourceBackend::getItemsByTime($usr_id, $this->namespace_id, $sd, $ed);
121                 $events = array();
122                 foreach ($evs as $row) $events[] = $this->virtualData2wdcal($row);
123
124                 return $events;
125         }
126
127         /**
128          * @param string $uri
129          * @throws Sabre_DAV_Exception_MethodNotAllowed
130          * @return void
131          */
132         public function removeItem($uri) {
133                 throw new Sabre_DAV_Exception_MethodNotAllowed();
134         }
135
136         /**
137          * @param string $uri
138          * @return array
139          */
140         public function getItemByUri($uri)
141         {
142                 $usr_id = IntVal($this->calendarDb->uid);
143                 $row = FriendicaVirtualCalSourceBackend::getItemsByUri($usr_id, $uri);
144                 return $this->virtualData2wdcal($row);
145         }
146
147         /**
148          * @param string $uri
149          * @return string
150          */
151         public function getItemDetailRedirect($uri) {
152                 $x = explode("@", $uri);
153                 $y = explode("-", $x[0]);
154                 $a = get_app();
155                 if (count($y) != 3) {
156                         goaway($a->get_baseurl() . "/dav/wdcal/");
157                         killme();
158                 }
159                 $a = get_app();
160                 $item = q("SELECT `id` FROM `item` WHERE `event-id` = %d AND `uid` = %d AND deleted = 0", IntVal($y[2]), $a->user["uid"]);
161                 if (count($item) == 0) return "/events/";
162                 return "/display/" . $a->user["nickname"] . "/" . IntVal($item[0]["id"]);
163         }
164 }