annotate vendor/sabre/vobject/lib/Property/Text.php @ 7:430dbd5346f7

vendor sabre as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:06:10 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject\Property;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 use
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 Sabre\VObject\Property,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 Sabre\VObject\Component,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 Sabre\VObject\Parser\MimeDir,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 Sabre\VObject\Document;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 * Text property
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 * This object represents TEXT values.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 * @author Evert Pot (http://evertpot.com/)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 * @license http://sabre.io/license/ Modified BSD License
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 class Text extends Property {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 * In case this is a multi-value property. This string will be used as a
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 * delimiter.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 * @var string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 public $delimiter = ',';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 * List of properties that are considered 'structured'.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 protected $structuredValues = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 // vCard
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37 'N',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 'ADR',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39 'ORG',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 'GENDER',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 // iCalendar
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 'REQUEST-STATUS',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 * Some text components have a minimum number of components.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 * N must for instance be represented as 5 components, separated by ;, even
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 * if the last few components are unused.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 protected $minimumPropertyValues = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 'N' => 5,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 'ADR' => 7,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60 * Creates the property.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 * You can specify the parameters either in key=>value syntax, in which case
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 * parameters will automatically be created, or you can just pass a list of
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 * Parameter objects.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66 * @param Component $root The root document
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 * @param string $name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 * @param string|array|null $value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 * @param array $parameters List of parameters
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70 * @param string $group The vcard property group
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73 public function __construct(Component $root, $name, $value = null, array $parameters = array(), $group = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75 // There's two types of multi-valued text properties:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 // 1. multivalue properties.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 // 2. structured value properties
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79 // The former is always separated by a comma, the latter by semi-colon.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80 if (in_array($name, $this->structuredValues)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 $this->delimiter = ';';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 parent::__construct($root, $name, $value, $parameters, $group);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90 * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92 * This has been 'unfolded', so only 1 line will be passed. Unescaping is
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93 * not yet done, but parameters are not included.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95 * @param string $val
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98 public function setRawMimeDirValue($val) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100 $this->setValue(MimeDir::unescapeValue($val, $this->delimiter));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
103
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
104 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
105 * Sets the value as a quoted-printable encoded string.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
106 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
107 * @param string $val
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
108 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
109 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
110 public function setQuotedPrintableValue($val) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
111
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
112 $val = quoted_printable_decode($val);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
113
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
114 // Quoted printable only appears in vCard 2.1, and the only character
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
115 // that may be escaped there is ;. So we are simply splitting on just
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
116 // that.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
117 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
118 // We also don't have to unescape \\, so all we need to look for is a ;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
119 // that's not preceeded with a \.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
120 $regex = '# (?<!\\\\) ; #x';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
121 $matches = preg_split($regex, $val);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
122 $this->setValue($matches);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
123
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
124 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
125
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
126 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
127 * Returns a raw mime-dir representation of the value.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
128 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
129 * @return string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
130 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
131 public function getRawMimeDirValue() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
132
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
133 $val = $this->getParts();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
134
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
135 if (isset($this->minimumPropertyValues[$this->name])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
136 $val = array_pad($val, $this->minimumPropertyValues[$this->name], '');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
137 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
138
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
139 foreach($val as &$item) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
140
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
141 if (!is_array($item)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
142 $item = array($item);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
143 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
144
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
145 foreach($item as &$subItem) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
146 $subItem = strtr(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
147 $subItem,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
148 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
149 '\\' => '\\\\',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
150 ';' => '\;',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
151 ',' => '\,',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
152 "\n" => '\n',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
153 "\r" => "",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
154 )
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
155 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
156 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
157 $item = implode(',', $item);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
158
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
159 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
160
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
161 return implode($this->delimiter, $val);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
162
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
163 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
164
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
165 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
166 * Returns the value, in the format it should be encoded for json.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
167 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
168 * This method must always return an array.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
169 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
170 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
171 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
172 public function getJsonValue() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
173
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
174 // Structured text values should always be returned as a single
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
175 // array-item. Multi-value text should be returned as multiple items in
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
176 // the top-array.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
177 if (in_array($this->name, $this->structuredValues)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
178 return array($this->getParts());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
179 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
180 return $this->getParts();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
181 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
182
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
183 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
184
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
185 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
186 * Returns the type of value.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
187 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
188 * This corresponds to the VALUE= parameter. Every property also has a
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
189 * 'default' valueType.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
190 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
191 * @return string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
192 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
193 public function getValueType() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
194
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
195 return "TEXT";
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
196
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
197 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
198
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
199 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
200 * Turns the object back into a serialized blob.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
201 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
202 * @return string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
203 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
204 public function serialize() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
205
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
206 // We need to kick in a special type of encoding, if it's a 2.1 vcard.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
207 if ($this->root->getDocumentType() !== Document::VCARD21) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
208 return parent::serialize();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
209 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
210
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
211 $val = $this->getParts();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
212
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
213 if (isset($this->minimumPropertyValues[$this->name])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
214 $val = array_pad($val, $this->minimumPropertyValues[$this->name], '');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
215 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
216
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
217 // Imploding multiple parts into a single value, and splitting the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
218 // values with ;.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
219 if (count($val)>1) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
220 foreach($val as $k=>$v) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
221 $val[$k] = str_replace(';','\;', $v);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
222 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
223 $val = implode(';', $val);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
224 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
225 $val = $val[0];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
226 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
227
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
228 $str = $this->name;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
229 if ($this->group) $str = $this->group . '.' . $this->name;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
230 foreach($this->parameters as $param) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
231
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
232 if ($param->getValue() === 'QUOTED-PRINTABLE') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
233 continue;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
234 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
235 $str.=';' . $param->serialize();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
236
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
237 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
238
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
239
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
240
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
241 // If the resulting value contains a \n, we must encode it as
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
242 // quoted-printable.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
243 if (strpos($val,"\n") !== false) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
244
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
245 $str.=';ENCODING=QUOTED-PRINTABLE:';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
246 $lastLine=$str;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
247 $out = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
248
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
249 // The PHP built-in quoted-printable-encode does not correctly
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
250 // encode newlines for us. Specifically, the \r\n sequence must in
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
251 // vcards be encoded as =0D=OA and we must insert soft-newlines
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
252 // every 75 bytes.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
253 for($ii=0;$ii<strlen($val);$ii++) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
254 $ord = ord($val[$ii]);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
255 // These characters are encoded as themselves.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
256 if ($ord >= 32 && $ord <=126) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
257 $lastLine.=$val[$ii];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
258 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
259 $lastLine.='=' . strtoupper(bin2hex($val[$ii]));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
260 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
261 if (strlen($lastLine)>=75) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
262 // Soft line break
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
263 $out.=$lastLine. "=\r\n ";
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
264 $lastLine = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
265 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
266
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
267 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
268 if (!is_null($lastLine)) $out.= $lastLine . "\r\n";
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
269 return $out;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
270
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
271 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
272 $str.=':' . $val;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
273 $out = '';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
274 while(strlen($str)>0) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
275 if (strlen($str)>75) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
276 $out.= mb_strcut($str,0,75,'utf-8') . "\r\n";
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
277 $str = ' ' . mb_strcut($str,75,strlen($str),'utf-8');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
278 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
279 $out.=$str . "\r\n";
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
280 $str='';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
281 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
282 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
283 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
284
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
285 return $out;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
286
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
287
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
288 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
289
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
290 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
291
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
292 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
293 * Validates the node for correctness.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
294 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
295 * The following options are supported:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
296 * - Node::REPAIR - If something is broken, and automatic repair may
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
297 * be attempted.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
298 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
299 * An array is returned with warnings.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
300 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
301 * Every item in the array has the following properties:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
302 * * level - (number between 1 and 3 with severity information)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
303 * * message - (human readable message)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
304 * * node - (reference to the offending node)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
305 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
306 * @param int $options
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
307 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
308 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
309 public function validate($options = 0) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
310
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
311 $warnings = parent::validate($options);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
312
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
313 if (isset($this->minimumPropertyValues[$this->name])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
314
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
315 $minimum = $this->minimumPropertyValues[$this->name];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
316 $parts = $this->getParts();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
317 if (count($parts) < $minimum) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
318 $warnings[] = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
319 'level' => 1,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
320 'message' => 'This property must have at least ' . $minimum . ' components. It only has ' . count($parts),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
321 'node' => $this,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
322 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
323 if ($options & self::REPAIR) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
324 $parts = array_pad($parts, $minimum, '');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
325 $this->setParts($parts);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
326 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
327 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
328
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
329 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
330 return $warnings;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
331
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
332 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
333 }