-
Notifications
You must be signed in to change notification settings - Fork 4
/
iCalendar_parameters.php
221 lines (203 loc) · 7.43 KB
/
iCalendar_parameters.php
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
211
212
213
214
215
216
217
218
219
220
221
<?php
// $Id: iCalendar_parameters.php,v 1.7 2005/07/21 23:17:21 defacer Exp $
class IcalendarParameter
{
public function multipleValuesAllowed($parameter)
{
switch ($parameter) {
case 'DELEGATED-FROM':
case 'DELEGATED-TO':
case 'MEMBER':
return true;
default:
return false;
}
}
public function defaultValueICal($parameter)
{
switch ($parameter) {
case 'CUTYPE': return 'INDIVIDUAL';
case 'FBTYPE': return 'BUSY';
case 'PARTSTAT': return 'NEEDS-ACTION';
case 'RELATED': return 'START';
case 'RELTYPE': return 'PARENT';
case 'ROLE': return 'REQ-PARTICIPANT';
case 'RSVP': return 'false';
default: return null;
}
}
public function isValidValue(\IcalendarProperty &$parent_property, $parameter, $value)
{
switch ($parameter) {
// These must all be a URI
case 'ALTREP':
case 'DIR':
return \ICalendarRfc::rfc2445IsValidValue($value, RFC2445_TYPE_URI);
break;
// These must be CAL-ADDRESS, which is equivalent to URI
case 'DELEGATED-FROM':
case 'DELEGATED-TO':
case 'MEMBER':
case 'SENT-BY':
return \ICalendarRfc::rfc2445IsValidValue($value, RFC2445_TYPE_CAL_ADDRESS);
break;
// These are textual parameters, so the MUST NOT contain double quotes
case 'CN':
return strpos($value, '"') === false;
break;
// These have enumerated legal values
case 'CUTYPE':
$value = strtoupper($value);
return $value == 'INDIVIDUAL' || $value == 'GROUP' || $value == 'RESOURCE' || $value == 'ROOM' || $value == 'UNKNOWN' || \ICalendarRfc::rfc2445IsXname($value);
break;
case 'ENCODING':
$value = strtoupper($value);
return $value == '8BIT' || $value == 'BASE64' || \ICalendarRfc::rfc2445_is_xname($value);
break;
case 'FBTYPE':
$value = strtoupper($value);
return $value == 'FREE' || $value == 'BUSY' || $value == 'BUSY-UNAVAILABLE' || $value == 'BUSY-TENTATIVE' || \ICalendarRfc::rfc2445IsXname($value);
break;
case 'FMTTYPE':
$fmttypes = [
'TEXT' => ['PLAIN', 'RICHTEXT', 'ENRICHED', 'TAB-SEPARATED-VALUES', 'HTML', 'SGML',
'VND.LATEX-Z', 'VND.FMI.FLEXSTOR', ],
'MULTIPART' => ['MIXED', 'ALTERNATIVE', 'DIGEST', 'PARALLEL', 'APPLEDOUBLE', 'HEADER-SET',
'FORM-DATA', 'RELATED', 'REPORT', 'VOICE-MESSAGE', 'SIGNED', 'ENCRYPTED',
'BYTERANGES', ],
'MESSAGE' => ['RFC822', 'PARTIAL', 'EXTERNAL-BODY', 'NEWS', 'HTTP'],
'APPLICATION' => ['OCTET-STREAM', 'POSTSCRIPT', 'ODA', 'ATOMICMAIL', 'ANDREW-INSET', 'SLATE',
'WITA', 'DEC-DX', 'DCA-RFT', 'ACTIVEMESSAGE', 'RTF', 'APPLEFILE',
'MAC-BINHEX40', 'NEWS-MESSAGE-ID', 'NEWS-TRANSMISSION', 'WORDPERFECT5.1',
'PDF', 'ZIP', 'MACWRITEII', 'MSWORD', 'REMOTE-PRINTING', 'MATHEMATICA',
'CYBERCASH', 'COMMONGROUND', 'IGES', 'RISCOS', 'ESHOP', 'X400-BP', 'SGML',
'CALS-1840', 'PGP-ENCRYPTED', 'PGP-SIGNATURE', 'PGP-KEYS', 'VND.FRAMEMAKER',
'VND.MIF', 'VND.MS-EXCEL', 'VND.MS-POWERPOINT', 'VND.MS-PROJECT',
'VND.MS-WORKS', 'VND.MS-TNEF', 'VND.SVD', 'VND.MUSIC-NIFF', 'VND.MS-ARTGALRY',
'VND.TRUEDOC', 'VND.KOAN', 'VND.STREET-STREAM', 'VND.FDF',
'SET-PAYMENT-INITIATION', 'SET-PAYMENT', 'SET-REGISTRATION-INITIATION',
'SET-REGISTRATION', 'VND.SEEMAIL', 'VND.BUSINESSOBJECTS',
'VND.MERIDIAN-SLINGSHOT', 'VND.XARA', 'SGML-OPEN-CATALOG', 'VND.RAPID',
'VND.ENLIVEN', 'VND.JAPANNET-REGISTRATION-WAKEUP',
'VND.JAPANNET-VERIFICATION-WAKEUP', 'VND.JAPANNET-PAYMENT-WAKEUP',
'VND.JAPANNET-DIRECTORY-SERVICE', 'VND.INTERTRUST.DIGIBOX', 'VND.INTERTRUST.NNCP', ],
'IMAGE' => ['JPEG', 'GIF', 'IEF', 'G3FAX', 'TIFF', 'CGM', 'NAPLPS', 'VND.DWG', 'VND.SVF',
'VND.DXF', 'PNG', 'VND.FPX', 'VND.NET-FPX', ],
'AUDIO' => ['BASIC', '32KADPCM', 'VND.QCELP'],
'VIDEO' => ['MPEG', 'QUICKTIME', 'VND.VIVO', 'VND.MOTOROLA.VIDEO', 'VND.MOTOROLA.VIDEOP'],
];
$value = strtoupper($value);
if (\ICalendarRfc::rfc2445_is_xname($value)) {
return true;
}
list($type, $subtype) = explode('/', $value);
if (empty($type) || empty($subtype)) {
return false;
}
if (!isset($fmttypes[$type]) || !in_array($subtype, $fmttypes[$type])) {
return false;
}
return true;
break;
case 'LANGUAGE':
$value = strtoupper($value);
$parts = explode('-', $value);
foreach ($parts as $part) {
if (empty($part)) {
return false;
}
if (strspn($part, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') != strlen($part)) {
return false;
}
}
return true;
break;
case 'PARTSTAT':
$value = strtoupper($value);
switch ($parent_property->parent_component) {
case 'VEVENT':
return $value == 'NEEDS-ACTION' || $value == 'ACCEPTED' || $value == 'DECLINED' || $value == 'TENTATIVE' || $value == 'DELEGATED' || \ICalendarRfc::rfc2445IsXname($value);
break;
case 'VTODO':
return $value == 'NEEDS-ACTION' || $value == 'ACCEPTED' || $value == 'DECLINED' || $value == 'TENTATIVE' || $value == 'DELEGATED' || $value == 'COMPLETED' || $value == 'IN-PROCESS' || \ICalendarRfc::rfc2445IsXname($value);
break;
case 'VJOURNAL':
return $value == 'NEEDS-ACTION' || $value == 'ACCEPTED' || $value == 'DECLINED' || \ICalendarRfc::rfc2445IsXname($value);
break;
}
return false;
break;
case 'RANGE':
$value = strtoupper($value);
return $value == 'THISANDPRIOR' || $value == 'THISANDFUTURE';
break;
case 'RELATED':
$value = strtoupper($value);
return $value == 'START' || $value == 'END';
break;
case 'RELTYPE':
$value = strtoupper($value);
return $value == 'PARENT' || $value == 'CHILD' || $value == 'SIBLING' || \ICalendarRfc::rfc2445IsXname($value);
break;
case 'ROLE':
$value = strtoupper($value);
return $value == 'CHAIR' || $value == 'REQ-PARTICIPANT' || $value == 'OPT-PARTICIPANT' || $value == 'NON-PARTICIPANT' || \ICalendarRfc::rfc2445IsXname($value);
break;
case 'RSVP':
$value = strtoupper($value);
return $value == 'true' || $value == 'false';
break;
case 'TZID':
if (empty($value)) {
return false;
}
return strcspn($value, '";:,') == strlen($value);
break;
case 'VALUE':
$value = strtoupper($value);
return $value == 'BINARY' || $value == 'BOOLEAN' || $value == 'CAL-ADDRESS' || $value == 'DATE' ||
$value == 'DATE-TIME' || $value == 'DURATION' || $value == 'FLOAT' || $value == 'INTEGER' ||
$value == 'PERIOD' || $value == 'RECUR' || $value == 'TEXT' || $value == 'TIME' ||
$value == 'URI' || $value == 'UTC-OFFSET' || \ICalendarRfc::rfc2445IsXname($value);
break;
}
}
public function doValueFormatting($parameter, $value)
{
switch ($parameter) {
// Parameters of type CAL-ADDRESS or URI MUST be double-quoted
case 'ALTREP':
case 'DIR':
case 'DELEGATED-FROM':
case 'DELEGATED-TO':
case 'MEMBER':
case 'SENT-BY':
return '"' . $value . '"';
break;
// Textual parameter types must be double quoted if they contain COLON, SEMICOLON
// or COMMA. Quoting always sounds easier and standards-conformant though.
case 'CN':
return '"' . $value . '"';
break;
// Parameters with enumerated legal values, just make them all caps
case 'CUTYPE':
case 'ENCODING':
case 'FBTYPE':
case 'FMTTYPE':
case 'LANGUAGE':
case 'PARTSTAT':
case 'RANGE':
case 'RELATED':
case 'RELTYPE':
case 'ROLE':
case 'RSVP':
case 'VALUE':
return strtoupper($value);
break;
// Parameters we shouldn't be messing with
case 'TZID':
return $value;
break;
}
}
}