1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
<?php
/**
* Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
* Copyright (c) 2012 Georg Ehrke <georg@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*
* This class manages our app actions
*/
OC_Calendar_App::$l10n = new OC_L10N('calendar');
class OC_Calendar_App{
/*
* @brief: language object for calendar app
*/
public static $l10n;
/*
* @brief: returns informations about a calendar
* @param: int $id - id of the calendar
* @param: bool $security - check access rights or not
* @param: bool $shared - check if the user got access via sharing
* @return: mixed - bool / array
*/
public static function getCalendar($id, $security = true, $shared = false){
$calendar = OC_Calendar_Object::find($id);
if($shared === true){
if(OC_Calendar_Share::check_access(OC_User::getUser(), $id, OC_Calendar_Share::CALENDAR)){
return $calendar;
}
}
if($security === true){
if($calendar['userid'] != OC_User::getUser()){
return false;
}
}
if($calendar === false){
return false;
}
return OC_Calendar_Calendar::find($id);
}
/*
* @brief: returns informations about an event
* @param: int $id - id of the event
* @param: bool $security - check access rights or not
* @param: bool $shared - check if the user got access via sharing
* @return: mixed - bool / array
*/
public static function getEventObject($id, $security = true, $shared = false){
$event = OC_Calendar_Object::find($id);
if($shared === true){
if(OC_Calendar_Share::check_access(OC_User::getUser(), $id, OC_Calendar_Share::EVENT)){
return $calendar;
}
}
if($security === true){
$calendar = self::getCalendar($event['calendarid'], false);
if($calendar['userid'] != OC_User::getUser()){
return false;
}
}
if($event === false){
return false;
}
return $event;
}
/*
* @brief: returns the parsed calendar data
* @param: int $id - id of the event
* @param: bool $security - check access rights or not
* @return: mixed - bool / object
*/
public static function getVCalendar($id, $security = true){
$event_object = self::getEventObject($id, $security);
if($event_object === false){
return false;
}
$vobject = OC_VObject::parse($event_object['calendardata']);
if(is_null($vobject)){
return false;
}
return $vobject;
}
/*
*
*/
public static function isNotModified($vevent, $lastmodified){
$last_modified = $vevent->__get('LAST-MODIFIED');
if($last_modified && $lastmodified != $last_modified->getDateTime()->format('U')){
OC_JSON::error(array('modified'=>true));
exit;
}
}
/*
* THIS FUNCTION IS DEPRECATED AND WILL BE REMOVED SOON
* @brief: returns the valid categories
* @return: array - categories
*/
public static function getCategoryOptions(){
return OC_Calendar_Object::getCategoryOptions(self::$l10n);
}
/*
* @brief: returns the options for an repeating event
* @return: array - valid inputs for repeating events
*/
public static function getRepeatOptions(){
return OC_Calendar_Object::getRepeatOptions(self::$l10n);
}
/*
* @brief: returns the options for the end of an repeating event
* @return: array - valid inputs for the end of an repeating events
*/
public static function getEndOptions(){
return OC_Calendar_Object::getEndOptions(self::$l10n);
}
/*
* @brief: returns the options for an monthly repeating event
* @return: array - valid inputs for monthly repeating events
*/
public static function getMonthOptions(){
return OC_Calendar_Object::getMonthOptions(self::$l10n);
}
/*
* @brief: returns the options for an weekly repeating event
* @return: array - valid inputs for weekly repeating events
*/
public static function getWeeklyOptions(){
return OC_Calendar_Object::getWeeklyOptions(self::$l10n);
}
/*
* @brief: returns the options for an yearly repeating event
* @return: array - valid inputs for yearly repeating events
*/
public static function getYearOptions(){
return OC_Calendar_Object::getYearOptions(self::$l10n);
}
/*
* @brief: returns the options for an yearly repeating event which occurs on specific days of the year
* @return: array - valid inputs for yearly repeating events
*/
public static function getByYearDayOptions(){
return OC_Calendar_Object::getByYearDayOptions();
}
/*
* @brief: returns the options for an yearly repeating event which occurs on specific month of the year
* @return: array - valid inputs for yearly repeating events
*/
public static function getByMonthOptions(){
return OC_Calendar_Object::getByMonthOptions(self::$l10n);
}
/*
* @brief: returns the options for an yearly repeating event which occurs on specific week numbers of the year
* @return: array - valid inputs for yearly repeating events
*/
public static function getByWeekNoOptions(){
return OC_Calendar_Object::getByWeekNoOptions();
}
/*
* @brief: returns the options for an yearly or monthly repeating event which occurs on specific days of the month
* @return: array - valid inputs for yearly or monthly repeating events
*/
public static function getByMonthDayOptions(){
return OC_Calendar_Object::getByMonthDayOptions();
}
/*
* @brief: returns the options for an monthly repeating event which occurs on specific weeks of the month
* @return: array - valid inputs for monthly repeating events
*/
public static function getWeekofMonth(){
return OC_Calendar_Object::getWeekofMonth(self::$l10n);
}
/*
* @brief: returns the prepared output for the json calendar data
* @param: array $event - array with event informations (self::getEventObject)
* @return: array - prepared output
*/
public static function prepareForOutput($event){
if(isset($event['calendardata'])){
$object = self::getVCalendar($event['calendardata'], false);
$vevent = $object->VEVENT;
}else{
$vevent = $event['vevent'];
}$last_modified = $vevent->__get('LAST-MODIFIED');
if ($last_modified){
$lastmodified = $last_modified->getDateTime()->format('U');
}else{
$lastmodified = 0;
}
$last_modified = ($vevent->__get('LAST-MODIFIED'))?$last_modified->getDateTime()->format('U'):0;
$return = array('id'=>(int)$event['id'],
'title' => htmlspecialchars(($event['summary']!=NULL || $event['summary'] != '')?$event['summary']: self::$l10n->t('unnamed')),
'description' => isset($vevent->DESCRIPTION)?htmlspecialchars($vevent->DESCRIPTION->value):'',
'lastmodified'=>(int)$lastmodified);
return $return;
}
}
|