|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* @copyright Copyright (c) 2017, Georg Ehrke |
|
5
|
|
|
* |
|
6
|
|
|
* @author Thomas Müller <[email protected]> |
|
7
|
|
|
* @author Georg Ehrke <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @license AGPL-3.0 |
|
10
|
|
|
* |
|
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
13
|
|
|
* as published by the Free Software Foundation. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
namespace OCA\DAV\CalDAV; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
use Sabre\VObject\Component; |
|
30
|
|
|
use Sabre\VObject\Property; |
|
31
|
|
|
use Sabre\VObject\Reader; |
|
32
|
|
|
|
|
33
|
|
|
class CalendarObject extends \Sabre\CalDAV\CalendarObject { |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @inheritdoc |
|
37
|
|
|
*/ |
|
38
|
|
|
function get() { |
|
|
|
|
|
|
39
|
|
|
$data = parent::get(); |
|
40
|
|
|
|
|
41
|
|
|
if (!$this->isShared()) { |
|
42
|
|
|
return $data; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$vObject = Reader::read($data); |
|
46
|
|
|
|
|
47
|
|
|
// remove VAlarms if calendar is shared read-only |
|
48
|
|
|
if (!$this->canWrite()) { |
|
49
|
|
|
$this->removeVAlarms($vObject); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
// shows as busy if event is declared confidential |
|
53
|
|
|
if ($this->objectData['classification'] === CalDavBackend::CLASSIFICATION_CONFIDENTIAL) { |
|
54
|
|
|
$this->createConfidentialObject($vObject); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $vObject->serialize(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
View Code Duplication |
protected function isShared() { |
|
61
|
|
|
if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param Component\VCalendar $vObject |
|
70
|
|
|
* @return void |
|
71
|
|
|
*/ |
|
72
|
|
|
private static function createConfidentialObject(Component\VCalendar $vObject) { |
|
73
|
|
|
/** @var Component $vElement */ |
|
74
|
|
|
$vElement = null; |
|
75
|
|
|
if(isset($vObject->VEVENT)) { |
|
76
|
|
|
$vElement = $vObject->VEVENT; |
|
77
|
|
|
} |
|
78
|
|
|
if(isset($vObject->VJOURNAL)) { |
|
79
|
|
|
$vElement = $vObject->VJOURNAL; |
|
80
|
|
|
} |
|
81
|
|
|
if(isset($vObject->VTODO)) { |
|
82
|
|
|
$vElement = $vObject->VTODO; |
|
83
|
|
|
} |
|
84
|
|
|
if(!is_null($vElement)) { |
|
85
|
|
|
foreach ($vElement->children() as &$property) { |
|
|
|
|
|
|
86
|
|
|
/** @var Property $property */ |
|
87
|
|
|
switch($property->name) { |
|
88
|
|
|
case 'CREATED': |
|
89
|
|
|
case 'DTSTART': |
|
90
|
|
|
case 'RRULE': |
|
91
|
|
|
case 'DURATION': |
|
92
|
|
|
case 'DTEND': |
|
93
|
|
|
case 'CLASS': |
|
94
|
|
|
case 'UID': |
|
95
|
|
|
break; |
|
96
|
|
|
case 'SUMMARY': |
|
97
|
|
|
$property->setValue('Busy'); |
|
98
|
|
|
break; |
|
99
|
|
|
default: |
|
100
|
|
|
$vElement->__unset($property->name); |
|
101
|
|
|
unset($property); |
|
102
|
|
|
break; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param Component\VCalendar $vObject |
|
110
|
|
|
* @return void |
|
111
|
|
|
*/ |
|
112
|
|
|
private function removeVAlarms(Component\VCalendar $vObject) { |
|
113
|
|
|
$subcomponents = $vObject->getComponents(); |
|
114
|
|
|
|
|
115
|
|
|
foreach($subcomponents as $subcomponent) { |
|
116
|
|
|
unset($subcomponent->VALARM); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return bool |
|
122
|
|
|
*/ |
|
123
|
|
|
private function canWrite() { |
|
124
|
|
|
if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
125
|
|
|
return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
126
|
|
|
} |
|
127
|
|
|
return true; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.