Mercurial > hg > cmmr2012-drupal-site
comparison vendor/zendframework/zend-feed/src/Writer/Renderer/Entry/Atom.php @ 2:5311817fb629
Theme updates
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 13:19:18 +0000 |
parents | c75dbcec494b |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
1:0b0e5f3b1e83 | 2:5311817fb629 |
---|---|
54 $this->_setCategories($this->dom, $entry); | 54 $this->_setCategories($this->dom, $entry); |
55 | 55 |
56 foreach ($this->extensions as $ext) { | 56 foreach ($this->extensions as $ext) { |
57 $ext->setType($this->getType()); | 57 $ext->setType($this->getType()); |
58 $ext->setRootElement($this->getRootElement()); | 58 $ext->setRootElement($this->getRootElement()); |
59 $ext->setDOMDocument($this->getDOMDocument(), $entry); | 59 $ext->setDomDocument($this->getDomDocument(), $entry); |
60 $ext->render(); | 60 $ext->render(); |
61 } | 61 } |
62 | 62 |
63 return $this; | 63 return $this; |
64 } | 64 } |
69 * @param DOMDocument $dom | 69 * @param DOMDocument $dom |
70 * @param DOMElement $root | 70 * @param DOMElement $root |
71 * @return void | 71 * @return void |
72 * @throws Writer\Exception\InvalidArgumentException | 72 * @throws Writer\Exception\InvalidArgumentException |
73 */ | 73 */ |
74 // @codingStandardsIgnoreStart | |
74 protected function _setTitle(DOMDocument $dom, DOMElement $root) | 75 protected function _setTitle(DOMDocument $dom, DOMElement $root) |
75 { | 76 { |
76 if (!$this->getDataContainer()->getTitle()) { | 77 // @codingStandardsIgnoreEnd |
78 if (! $this->getDataContainer()->getTitle()) { | |
77 $message = 'Atom 1.0 entry elements MUST contain exactly one' | 79 $message = 'Atom 1.0 entry elements MUST contain exactly one' |
78 . ' atom:title element but a title has not been set'; | 80 . ' atom:title element but a title has not been set'; |
79 $exception = new Writer\Exception\InvalidArgumentException($message); | 81 $exception = new Writer\Exception\InvalidArgumentException($message); |
80 if (!$this->ignoreExceptions) { | 82 if (! $this->ignoreExceptions) { |
81 throw $exception; | 83 throw $exception; |
82 } else { | 84 } else { |
83 $this->exceptions[] = $exception; | 85 $this->exceptions[] = $exception; |
84 return; | 86 return; |
85 } | 87 } |
96 * | 98 * |
97 * @param DOMDocument $dom | 99 * @param DOMDocument $dom |
98 * @param DOMElement $root | 100 * @param DOMElement $root |
99 * @return void | 101 * @return void |
100 */ | 102 */ |
103 // @codingStandardsIgnoreStart | |
101 protected function _setDescription(DOMDocument $dom, DOMElement $root) | 104 protected function _setDescription(DOMDocument $dom, DOMElement $root) |
102 { | 105 { |
103 if (!$this->getDataContainer()->getDescription()) { | 106 // @codingStandardsIgnoreEnd |
107 if (! $this->getDataContainer()->getDescription()) { | |
104 return; // unless src content or base64 | 108 return; // unless src content or base64 |
105 } | 109 } |
106 $subtitle = $dom->createElement('summary'); | 110 $subtitle = $dom->createElement('summary'); |
107 $root->appendChild($subtitle); | 111 $root->appendChild($subtitle); |
108 $subtitle->setAttribute('type', 'html'); | 112 $subtitle->setAttribute('type', 'html'); |
118 * @param DOMDocument $dom | 122 * @param DOMDocument $dom |
119 * @param DOMElement $root | 123 * @param DOMElement $root |
120 * @return void | 124 * @return void |
121 * @throws Writer\Exception\InvalidArgumentException | 125 * @throws Writer\Exception\InvalidArgumentException |
122 */ | 126 */ |
127 // @codingStandardsIgnoreStart | |
123 protected function _setDateModified(DOMDocument $dom, DOMElement $root) | 128 protected function _setDateModified(DOMDocument $dom, DOMElement $root) |
124 { | 129 { |
125 if (!$this->getDataContainer()->getDateModified()) { | 130 // @codingStandardsIgnoreEnd |
131 if (! $this->getDataContainer()->getDateModified()) { | |
126 $message = 'Atom 1.0 entry elements MUST contain exactly one' | 132 $message = 'Atom 1.0 entry elements MUST contain exactly one' |
127 . ' atom:updated element but a modification date has not been set'; | 133 . ' atom:updated element but a modification date has not been set'; |
128 $exception = new Writer\Exception\InvalidArgumentException($message); | 134 $exception = new Writer\Exception\InvalidArgumentException($message); |
129 if (!$this->ignoreExceptions) { | 135 if (! $this->ignoreExceptions) { |
130 throw $exception; | 136 throw $exception; |
131 } else { | 137 } else { |
132 $this->exceptions[] = $exception; | 138 $this->exceptions[] = $exception; |
133 return; | 139 return; |
134 } | 140 } |
147 * | 153 * |
148 * @param DOMDocument $dom | 154 * @param DOMDocument $dom |
149 * @param DOMElement $root | 155 * @param DOMElement $root |
150 * @return void | 156 * @return void |
151 */ | 157 */ |
158 // @codingStandardsIgnoreStart | |
152 protected function _setDateCreated(DOMDocument $dom, DOMElement $root) | 159 protected function _setDateCreated(DOMDocument $dom, DOMElement $root) |
153 { | 160 { |
154 if (!$this->getDataContainer()->getDateCreated()) { | 161 // @codingStandardsIgnoreEnd |
162 if (! $this->getDataContainer()->getDateCreated()) { | |
155 return; | 163 return; |
156 } | 164 } |
157 $el = $dom->createElement('published'); | 165 $el = $dom->createElement('published'); |
158 $root->appendChild($el); | 166 $root->appendChild($el); |
159 $text = $dom->createTextNode( | 167 $text = $dom->createTextNode( |
167 * | 175 * |
168 * @param DOMDocument $dom | 176 * @param DOMDocument $dom |
169 * @param DOMElement $root | 177 * @param DOMElement $root |
170 * @return void | 178 * @return void |
171 */ | 179 */ |
180 // @codingStandardsIgnoreStart | |
172 protected function _setAuthors(DOMDocument $dom, DOMElement $root) | 181 protected function _setAuthors(DOMDocument $dom, DOMElement $root) |
173 { | 182 { |
183 // @codingStandardsIgnoreEnd | |
174 $authors = $this->container->getAuthors(); | 184 $authors = $this->container->getAuthors(); |
175 if ((!$authors || empty($authors))) { | 185 if ((! $authors || empty($authors))) { |
176 /** | 186 /** |
177 * This will actually trigger an Exception at the feed level if | 187 * This will actually trigger an Exception at the feed level if |
178 * a feed level author is not set. | 188 * a feed level author is not set. |
179 */ | 189 */ |
180 return; | 190 return; |
206 * | 216 * |
207 * @param DOMDocument $dom | 217 * @param DOMDocument $dom |
208 * @param DOMElement $root | 218 * @param DOMElement $root |
209 * @return void | 219 * @return void |
210 */ | 220 */ |
221 // @codingStandardsIgnoreStart | |
211 protected function _setEnclosure(DOMDocument $dom, DOMElement $root) | 222 protected function _setEnclosure(DOMDocument $dom, DOMElement $root) |
212 { | 223 { |
224 // @codingStandardsIgnoreEnd | |
213 $data = $this->container->getEnclosure(); | 225 $data = $this->container->getEnclosure(); |
214 if ((!$data || empty($data))) { | 226 if ((! $data || empty($data))) { |
215 return; | 227 return; |
216 } | 228 } |
217 $enclosure = $this->dom->createElement('link'); | 229 $enclosure = $this->dom->createElement('link'); |
218 $enclosure->setAttribute('rel', 'enclosure'); | 230 $enclosure->setAttribute('rel', 'enclosure'); |
219 if (isset($data['type'])) { | 231 if (isset($data['type'])) { |
224 } | 236 } |
225 $enclosure->setAttribute('href', $data['uri']); | 237 $enclosure->setAttribute('href', $data['uri']); |
226 $root->appendChild($enclosure); | 238 $root->appendChild($enclosure); |
227 } | 239 } |
228 | 240 |
241 // @codingStandardsIgnoreStart | |
229 protected function _setLink(DOMDocument $dom, DOMElement $root) | 242 protected function _setLink(DOMDocument $dom, DOMElement $root) |
230 { | 243 { |
231 if (!$this->getDataContainer()->getLink()) { | 244 // @codingStandardsIgnoreEnd |
245 if (! $this->getDataContainer()->getLink()) { | |
232 return; | 246 return; |
233 } | 247 } |
234 $link = $dom->createElement('link'); | 248 $link = $dom->createElement('link'); |
235 $root->appendChild($link); | 249 $root->appendChild($link); |
236 $link->setAttribute('rel', 'alternate'); | 250 $link->setAttribute('rel', 'alternate'); |
244 * @param DOMDocument $dom | 258 * @param DOMDocument $dom |
245 * @param DOMElement $root | 259 * @param DOMElement $root |
246 * @return void | 260 * @return void |
247 * @throws Writer\Exception\InvalidArgumentException | 261 * @throws Writer\Exception\InvalidArgumentException |
248 */ | 262 */ |
263 // @codingStandardsIgnoreStart | |
249 protected function _setId(DOMDocument $dom, DOMElement $root) | 264 protected function _setId(DOMDocument $dom, DOMElement $root) |
250 { | 265 { |
251 if (!$this->getDataContainer()->getId() | 266 // @codingStandardsIgnoreEnd |
252 && !$this->getDataContainer()->getLink()) { | 267 if (! $this->getDataContainer()->getId() |
268 && ! $this->getDataContainer()->getLink()) { | |
253 $message = 'Atom 1.0 entry elements MUST contain exactly one ' | 269 $message = 'Atom 1.0 entry elements MUST contain exactly one ' |
254 . 'atom:id element, or as an alternative, we can use the same ' | 270 . 'atom:id element, or as an alternative, we can use the same ' |
255 . 'value as atom:link however neither a suitable link nor an ' | 271 . 'value as atom:link however neither a suitable link nor an ' |
256 . 'id have been set'; | 272 . 'id have been set'; |
257 $exception = new Writer\Exception\InvalidArgumentException($message); | 273 $exception = new Writer\Exception\InvalidArgumentException($message); |
258 if (!$this->ignoreExceptions) { | 274 if (! $this->ignoreExceptions) { |
259 throw $exception; | 275 throw $exception; |
260 } else { | 276 } else { |
261 $this->exceptions[] = $exception; | 277 $this->exceptions[] = $exception; |
262 return; | 278 return; |
263 } | 279 } |
264 } | 280 } |
265 | 281 |
266 if (!$this->getDataContainer()->getId()) { | 282 if (! $this->getDataContainer()->getId()) { |
267 $this->getDataContainer()->setId( | 283 $this->getDataContainer()->setId( |
268 $this->getDataContainer()->getLink() | 284 $this->getDataContainer()->getLink() |
269 ); | 285 ); |
270 } | 286 } |
271 if (!Uri::factory($this->getDataContainer()->getId())->isValid() | 287 if (! Uri::factory($this->getDataContainer()->getId())->isValid() |
272 && !preg_match( | 288 && ! preg_match( |
273 "#^urn:[a-zA-Z0-9][a-zA-Z0-9\-]{1,31}:([a-zA-Z0-9\(\)\+\,\.\:\=\@\;\$\_\!\*\-]|%[0-9a-fA-F]{2})*#", | 289 "#^urn:[a-zA-Z0-9][a-zA-Z0-9\-]{1,31}:([a-zA-Z0-9\(\)\+\,\.\:\=\@\;\$\_\!\*\-]|%[0-9a-fA-F]{2})*#", |
274 $this->getDataContainer()->getId() | 290 $this->getDataContainer()->getId() |
275 ) | 291 ) |
276 && !$this->_validateTagUri($this->getDataContainer()->getId()) | 292 && ! $this->_validateTagUri($this->getDataContainer()->getId()) |
277 ) { | 293 ) { |
278 throw new Writer\Exception\InvalidArgumentException('Atom 1.0 IDs must be a valid URI/IRI'); | 294 throw new Writer\Exception\InvalidArgumentException('Atom 1.0 IDs must be a valid URI/IRI'); |
279 } | 295 } |
280 $id = $dom->createElement('id'); | 296 $id = $dom->createElement('id'); |
281 $root->appendChild($id); | 297 $root->appendChild($id); |
287 * Validate a URI using the tag scheme (RFC 4151) | 303 * Validate a URI using the tag scheme (RFC 4151) |
288 * | 304 * |
289 * @param string $id | 305 * @param string $id |
290 * @return bool | 306 * @return bool |
291 */ | 307 */ |
308 // @codingStandardsIgnoreStart | |
292 protected function _validateTagUri($id) | 309 protected function _validateTagUri($id) |
293 { | 310 { |
311 // @codingStandardsIgnoreEnd | |
294 if (preg_match( | 312 if (preg_match( |
295 '/^tag:(?P<name>.*),(?P<date>\d{4}-?\d{0,2}-?\d{0,2}):(?P<specific>.*)(.*:)*$/', | 313 '/^tag:(?P<name>.*),(?P<date>\d{4}-?\d{0,2}-?\d{0,2}):(?P<specific>.*)(.*:)*$/', |
296 $id, | 314 $id, |
297 $matches | 315 $matches |
298 )) { | 316 )) { |
323 * @param DOMDocument $dom | 341 * @param DOMDocument $dom |
324 * @param DOMElement $root | 342 * @param DOMElement $root |
325 * @return void | 343 * @return void |
326 * @throws Writer\Exception\InvalidArgumentException | 344 * @throws Writer\Exception\InvalidArgumentException |
327 */ | 345 */ |
346 // @codingStandardsIgnoreStart | |
328 protected function _setContent(DOMDocument $dom, DOMElement $root) | 347 protected function _setContent(DOMDocument $dom, DOMElement $root) |
329 { | 348 { |
349 // @codingStandardsIgnoreEnd | |
330 $content = $this->getDataContainer()->getContent(); | 350 $content = $this->getDataContainer()->getContent(); |
331 if (!$content && !$this->getDataContainer()->getLink()) { | 351 if (! $content && ! $this->getDataContainer()->getLink()) { |
332 $message = 'Atom 1.0 entry elements MUST contain exactly one ' | 352 $message = 'Atom 1.0 entry elements MUST contain exactly one ' |
333 . 'atom:content element, or as an alternative, at least one link ' | 353 . 'atom:content element, or as an alternative, at least one link ' |
334 . 'with a rel attribute of "alternate" to indicate an alternate ' | 354 . 'with a rel attribute of "alternate" to indicate an alternate ' |
335 . 'method to consume the content.'; | 355 . 'method to consume the content.'; |
336 $exception = new Writer\Exception\InvalidArgumentException($message); | 356 $exception = new Writer\Exception\InvalidArgumentException($message); |
337 if (!$this->ignoreExceptions) { | 357 if (! $this->ignoreExceptions) { |
338 throw $exception; | 358 throw $exception; |
339 } else { | 359 } else { |
340 $this->exceptions[] = $exception; | 360 $this->exceptions[] = $exception; |
341 return; | 361 return; |
342 } | 362 } |
343 } | 363 } |
344 if (!$content) { | 364 if (! $content) { |
345 return; | 365 return; |
346 } | 366 } |
347 $element = $dom->createElement('content'); | 367 $element = $dom->createElement('content'); |
348 $element->setAttribute('type', 'xhtml'); | 368 $element->setAttribute('type', 'xhtml'); |
349 $xhtmlElement = $this->_loadXhtml($content); | 369 $xhtmlElement = $this->_loadXhtml($content); |
354 } | 374 } |
355 | 375 |
356 /** | 376 /** |
357 * Load a HTML string and attempt to normalise to XML | 377 * Load a HTML string and attempt to normalise to XML |
358 */ | 378 */ |
379 // @codingStandardsIgnoreStart | |
359 protected function _loadXhtml($content) | 380 protected function _loadXhtml($content) |
360 { | 381 { |
382 // @codingStandardsIgnoreEnd | |
361 if (class_exists('tidy', false)) { | 383 if (class_exists('tidy', false)) { |
362 $tidy = new \tidy; | 384 $tidy = new \tidy; |
363 $config = [ | 385 $config = [ |
364 'output-xhtml' => true, | 386 'output-xhtml' => true, |
365 'show-body-only' => true, | 387 'show-body-only' => true, |
389 * | 411 * |
390 * @param DOMDocument $dom | 412 * @param DOMDocument $dom |
391 * @param DOMElement $root | 413 * @param DOMElement $root |
392 * @return void | 414 * @return void |
393 */ | 415 */ |
416 // @codingStandardsIgnoreStart | |
394 protected function _setCategories(DOMDocument $dom, DOMElement $root) | 417 protected function _setCategories(DOMDocument $dom, DOMElement $root) |
395 { | 418 { |
419 // @codingStandardsIgnoreEnd | |
396 $categories = $this->getDataContainer()->getCategories(); | 420 $categories = $this->getDataContainer()->getCategories(); |
397 if (!$categories) { | 421 if (! $categories) { |
398 return; | 422 return; |
399 } | 423 } |
400 foreach ($categories as $cat) { | 424 foreach ($categories as $cat) { |
401 $category = $dom->createElement('category'); | 425 $category = $dom->createElement('category'); |
402 $category->setAttribute('term', $cat['term']); | 426 $category->setAttribute('term', $cat['term']); |
417 * | 441 * |
418 * @param DOMDocument $dom | 442 * @param DOMDocument $dom |
419 * @param DOMElement $root | 443 * @param DOMElement $root |
420 * @return void | 444 * @return void |
421 */ | 445 */ |
446 // @codingStandardsIgnoreStart | |
422 protected function _setSource(DOMDocument $dom, DOMElement $root) | 447 protected function _setSource(DOMDocument $dom, DOMElement $root) |
423 { | 448 { |
449 // @codingStandardsIgnoreEnd | |
424 $source = $this->getDataContainer()->getSource(); | 450 $source = $this->getDataContainer()->getSource(); |
425 if (!$source) { | 451 if (! $source) { |
426 return; | 452 return; |
427 } | 453 } |
428 $renderer = new Renderer\Feed\AtomSource($source); | 454 $renderer = new Renderer\Feed\AtomSource($source); |
429 $renderer->setType($this->getType()); | 455 $renderer->setType($this->getType()); |
430 $element = $renderer->render()->getElement(); | 456 $element = $renderer->render()->getElement(); |