annotate plugins/libcalendaring/lib/Sabre/VObject/Property.php @ 4:888e774ee983

libcalendar plugin as distributed
author Charlie Root
date Sat, 13 Jan 2018 08:57:56 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1 <?php
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
2
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
5 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
6 * VObject Property
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 * A property in VObject is usually in the form PARAMNAME:paramValue.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 * An example is : SUMMARY:Weekly meeting
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 * Properties can also have parameters:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 * SUMMARY;LANG=en:Weekly meeting.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 * Parameters can be accessed using the ArrayAccess interface.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 * @author Evert Pot (http://evertpot.com/)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20 class Property extends Node {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23 * Propertyname
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25 * @var string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27 public $name;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30 * Group name
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
32 * This may be something like 'HOME' for vcards.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
33 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
34 * @var string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36 public $group;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39 * Property parameters
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
41 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
42 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
43 public $parameters = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46 * Property value
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 * @var string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50 public $value;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 * If properties are added to this map, they will be automatically mapped
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54 * to their respective classes, if parsed by the reader or constructed with
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55 * the 'create' method.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57 * @var array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59 static public $classMap = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60 'COMPLETED' => 'Sabre\\VObject\\Property\\DateTime',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 'CREATED' => 'Sabre\\VObject\\Property\\DateTime',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62 'DTEND' => 'Sabre\\VObject\\Property\\DateTime',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63 'DTSTAMP' => 'Sabre\\VObject\\Property\\DateTime',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
64 'DTSTART' => 'Sabre\\VObject\\Property\\DateTime',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
65 'DUE' => 'Sabre\\VObject\\Property\\DateTime',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
66 'EXDATE' => 'Sabre\\VObject\\Property\\MultiDateTime',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67 'LAST-MODIFIED' => 'Sabre\\VObject\\Property\\DateTime',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68 'RECURRENCE-ID' => 'Sabre\\VObject\\Property\\DateTime',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
69 'TRIGGER' => 'Sabre\\VObject\\Property\\DateTime',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
70 'N' => 'Sabre\\VObject\\Property\\Compound',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
71 'ORG' => 'Sabre\\VObject\\Property\\Compound',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
72 'ADR' => 'Sabre\\VObject\\Property\\Compound',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
73 'CATEGORIES' => 'Sabre\\VObject\\Property\\Compound',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
74 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
75
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
76 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
77 * Creates the new property by name, but in addition will also see if
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
78 * there's a class mapped to the property name.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
79 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
80 * Parameters can be specified with the optional third argument. Parameters
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
81 * must be a key->value map of the parameter name, and value. If the value
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
82 * is specified as an array, it is assumed that multiple parameters with
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
83 * the same name should be added.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
84 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
85 * @param string $name
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
86 * @param string $value
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
87 * @param array $parameters
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
88 * @return Property
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
89 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
90 static public function create($name, $value = null, array $parameters = array()) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
91
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
92 $name = strtoupper($name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
93 $shortName = $name;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
94 $group = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
95 if (strpos($shortName,'.')!==false) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
96 list($group, $shortName) = explode('.', $shortName);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
97 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
98
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
99 if (isset(self::$classMap[$shortName])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
100 return new self::$classMap[$shortName]($name, $value, $parameters);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
101 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
102 return new self($name, $value, $parameters);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
103 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
104
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
105 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
106
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
107 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
108 * Creates a new property object
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
109 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
110 * Parameters can be specified with the optional third argument. Parameters
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
111 * must be a key->value map of the parameter name, and value. If the value
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
112 * is specified as an array, it is assumed that multiple parameters with
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
113 * the same name should be added.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
114 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
115 * @param string $name
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
116 * @param string $value
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
117 * @param array $parameters
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
118 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
119 public function __construct($name, $value = null, array $parameters = array()) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
120
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
121 if (!is_scalar($value) && !is_null($value)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
122 throw new \InvalidArgumentException('The value argument must be scalar or null');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
123 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
124
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
125 $name = strtoupper($name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
126 $group = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
127 if (strpos($name,'.')!==false) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
128 list($group, $name) = explode('.', $name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
129 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
130 $this->name = $name;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
131 $this->group = $group;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
132 $this->setValue($value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
133
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
134 foreach($parameters as $paramName => $paramValues) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
135
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
136 if (!is_array($paramValues)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
137 $paramValues = array($paramValues);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
138 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
139
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
140 foreach($paramValues as $paramValue) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
141 $this->add($paramName, $paramValue);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
142 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
143
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
144 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
145
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
146 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
147
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
148 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
149 * Updates the internal value
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
150 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
151 * @param string $value
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
152 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
153 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
154 public function setValue($value) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
155
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
156 $this->value = $value;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
157
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
158 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
159
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
160 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
161 * Returns the internal value
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
162 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
163 * @param string $value
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
164 * @return string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
165 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
166 public function getValue() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
167
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
168 return $this->value;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
169
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
170 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
171
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
172 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
173 * Turns the object back into a serialized blob.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
174 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
175 * @return string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
176 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
177 public function serialize() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
178
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
179 $str = $this->name;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
180 if ($this->group) $str = $this->group . '.' . $this->name;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
181
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
182 foreach($this->parameters as $param) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
183
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
184 $str.=';' . $param->serialize();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
185
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
186 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
187
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
188 $src = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
189 '\\',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
190 "\n",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
191 "\r",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
192 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
193 $out = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
194 '\\\\',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
195 '\n',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
196 '',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
197 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
198
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
199 // avoid double-escaping of \, and \; from Compound properties
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
200 if (method_exists($this, 'setParts')) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
201 $src[] = '\\\\,';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
202 $out[] = '\\,';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
203 $src[] = '\\\\;';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
204 $out[] = '\\;';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
205 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
206
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
207 $str.=':' . str_replace($src, $out, $this->value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
208
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
209 $out = '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
210 while(strlen($str)>0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
211 if (strlen($str)>75) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
212 $out.= mb_strcut($str,0,75,'utf-8') . "\r\n";
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
213 $str = ' ' . mb_strcut($str,75,strlen($str),'utf-8');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
214 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
215 $out.=$str . "\r\n";
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
216 $str='';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
217 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
218 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
219 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
220
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
221 return $out;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
222
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
223 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
224
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
225 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
226 * Adds a new componenten or element
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
227 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
228 * You can call this method with the following syntaxes:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
229 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
230 * add(Parameter $element)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
231 * add(string $name, $value)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
232 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
233 * The first version adds an Parameter
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
234 * The second adds a property as a string.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
235 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
236 * @param mixed $item
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
237 * @param mixed $itemValue
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
238 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
239 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
240 public function add($item, $itemValue = null) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
241
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
242 if ($item instanceof Parameter) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
243 if (!is_null($itemValue)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
244 throw new \InvalidArgumentException('The second argument must not be specified, when passing a VObject');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
245 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
246 $item->parent = $this;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
247 $this->parameters[] = $item;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
248 } elseif(is_string($item)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
249
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
250 $parameter = new Parameter($item,$itemValue);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
251 $parameter->parent = $this;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
252 $this->parameters[] = $parameter;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
253
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
254 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
255
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
256 throw new \InvalidArgumentException('The first argument must either be a Node a string');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
257
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
258 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
259
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
260 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
261
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
262 /* ArrayAccess interface {{{ */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
263
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
264 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
265 * Checks if an array element exists
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
266 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
267 * @param mixed $name
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
268 * @return bool
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
269 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
270 public function offsetExists($name) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
271
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
272 if (is_int($name)) return parent::offsetExists($name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
273
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
274 $name = strtoupper($name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
275
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
276 foreach($this->parameters as $parameter) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
277 if ($parameter->name == $name) return true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
278 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
279 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
280
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
281 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
282
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
283 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
284 * Returns a parameter, or parameter list.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
285 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
286 * @param string $name
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
287 * @return Node
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
288 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
289 public function offsetGet($name) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
290
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
291 if (is_int($name)) return parent::offsetGet($name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
292 $name = strtoupper($name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
293
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
294 $result = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
295 foreach($this->parameters as $parameter) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
296 if ($parameter->name == $name)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
297 $result[] = $parameter;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
298 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
299
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
300 if (count($result)===0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
301 return null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
302 } elseif (count($result)===1) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
303 return $result[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
304 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
305 $result[0]->setIterator(new ElementList($result));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
306 return $result[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
307 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
308
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
309 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
310
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
311 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
312 * Creates a new parameter
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
313 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
314 * @param string $name
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
315 * @param mixed $value
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
316 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
317 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
318 public function offsetSet($name, $value) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
319
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
320 if (is_int($name)) parent::offsetSet($name, $value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
321
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
322 if (is_scalar($value)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
323 if (!is_string($name))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
324 throw new \InvalidArgumentException('A parameter name must be specified. This means you cannot use the $array[]="string" to add parameters.');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
325
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
326 $this->offsetUnset($name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
327 $parameter = new Parameter($name, $value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
328 $parameter->parent = $this;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
329 $this->parameters[] = $parameter;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
330
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
331 } elseif ($value instanceof Parameter) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
332 if (!is_null($name))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
333 throw new \InvalidArgumentException('Don\'t specify a parameter name if you\'re passing a \\Sabre\\VObject\\Parameter. Add using $array[]=$parameterObject.');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
334
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
335 $value->parent = $this;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
336 $this->parameters[] = $value;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
337 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
338 throw new \InvalidArgumentException('You can only add parameters to the property object');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
339 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
340
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
341 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
342
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
343 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
344 * Removes one or more parameters with the specified name
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
345 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
346 * @param string $name
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
347 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
348 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
349 public function offsetUnset($name) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
350
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
351 if (is_int($name)) parent::offsetUnset($name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
352 $name = strtoupper($name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
353
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
354 foreach($this->parameters as $key=>$parameter) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
355 if ($parameter->name == $name) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
356 $parameter->parent = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
357 unset($this->parameters[$key]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
358 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
359
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
360 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
361
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
362 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
363
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
364 /* }}} */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
365
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
366 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
367 * Called when this object is being cast to a string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
368 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
369 * @return string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
370 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
371 public function __toString() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
372
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
373 return (string)$this->value;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
374
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
375 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
376
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
377 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
378 * This method is automatically called when the object is cloned.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
379 * Specifically, this will ensure all child elements are also cloned.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
380 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
381 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
382 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
383 public function __clone() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
384
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
385 foreach($this->parameters as $key=>$child) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
386 $this->parameters[$key] = clone $child;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
387 $this->parameters[$key]->parent = $this;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
388 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
389
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
390 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
391
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
392 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
393 * Validates the node for correctness.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
394 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
395 * The following options are supported:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
396 * - Node::REPAIR - If something is broken, and automatic repair may
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
397 * be attempted.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
398 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
399 * An array is returned with warnings.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
400 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
401 * Every item in the array has the following properties:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
402 * * level - (number between 1 and 3 with severity information)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
403 * * message - (human readable message)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
404 * * node - (reference to the offending node)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
405 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
406 * @param int $options
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
407 * @return array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
408 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
409 public function validate($options = 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
410
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
411 $warnings = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
412
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
413 // Checking if our value is UTF-8
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
414 if (!StringUtil::isUTF8($this->value)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
415 $warnings[] = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
416 'level' => 1,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
417 'message' => 'Property is not valid UTF-8!',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
418 'node' => $this,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
419 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
420 if ($options & self::REPAIR) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
421 $this->value = StringUtil::convertToUTF8($this->value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
422 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
423 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
424
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
425 // Checking if the propertyname does not contain any invalid bytes.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
426 if (!preg_match('/^([A-Z0-9-]+)$/', $this->name)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
427 $warnings[] = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
428 'level' => 1,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
429 'message' => 'The propertyname: ' . $this->name . ' contains invalid characters. Only A-Z, 0-9 and - are allowed',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
430 'node' => $this,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
431 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
432 if ($options & self::REPAIR) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
433 // Uppercasing and converting underscores to dashes.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
434 $this->name = strtoupper(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
435 str_replace('_', '-', $this->name)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
436 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
437 // Removing every other invalid character
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
438 $this->name = preg_replace('/([^A-Z0-9-])/u', '', $this->name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
439
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
440 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
441
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
442 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
443
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
444 // Validating inner parameters
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
445 foreach($this->parameters as $param) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
446 $warnings = array_merge($warnings, $param->validate($options));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
447 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
448
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
449 return $warnings;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
450
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
451 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
452
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
453 }