annotate vendor/zendframework/zend-feed/src/Reader/Extension/Atom/Entry.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 7a779792577d
children
rev   line source
Chris@0 1 <?php
Chris@0 2 /**
Chris@0 3 * Zend Framework (http://framework.zend.com/)
Chris@0 4 *
Chris@0 5 * @link http://github.com/zendframework/zf2 for the canonical source repository
Chris@0 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
Chris@0 7 * @license http://framework.zend.com/license/new-bsd New BSD License
Chris@0 8 */
Chris@0 9
Chris@0 10 namespace Zend\Feed\Reader\Extension\Atom;
Chris@0 11
Chris@0 12 use DateTime;
Chris@0 13 use DOMDocument;
Chris@0 14 use DOMElement;
Chris@0 15 use stdClass;
Chris@0 16 use Zend\Feed\Reader;
Chris@0 17 use Zend\Feed\Reader\Collection;
Chris@0 18 use Zend\Feed\Reader\Extension;
Chris@0 19 use Zend\Feed\Uri;
Chris@0 20
Chris@0 21 class Entry extends Extension\AbstractEntry
Chris@0 22 {
Chris@0 23 /**
Chris@0 24 * Get the specified author
Chris@0 25 *
Chris@0 26 * @param int $index
Chris@0 27 * @return string|null
Chris@0 28 */
Chris@0 29 public function getAuthor($index = 0)
Chris@0 30 {
Chris@0 31 $authors = $this->getAuthors();
Chris@0 32
Chris@0 33 if (isset($authors[$index])) {
Chris@0 34 return $authors[$index];
Chris@0 35 }
Chris@0 36
Chris@0 37 return;
Chris@0 38 }
Chris@0 39
Chris@0 40 /**
Chris@0 41 * Get an array with feed authors
Chris@0 42 *
Chris@0 43 * @return Collection\Author
Chris@0 44 */
Chris@0 45 public function getAuthors()
Chris@0 46 {
Chris@0 47 if (array_key_exists('authors', $this->data)) {
Chris@0 48 return $this->data['authors'];
Chris@0 49 }
Chris@0 50
Chris@0 51 $authors = [];
Chris@0 52 $list = $this->getXpath()->query($this->getXpathPrefix() . '//atom:author');
Chris@0 53
Chris@12 54 if (! $list->length) {
Chris@0 55 /**
Chris@0 56 * TODO: Limit query to feed level els only!
Chris@0 57 */
Chris@0 58 $list = $this->getXpath()->query('//atom:author');
Chris@0 59 }
Chris@0 60
Chris@0 61 if ($list->length) {
Chris@0 62 foreach ($list as $author) {
Chris@0 63 $author = $this->getAuthorFromElement($author);
Chris@12 64 if (! empty($author)) {
Chris@0 65 $authors[] = $author;
Chris@0 66 }
Chris@0 67 }
Chris@0 68 }
Chris@0 69
Chris@0 70 if (count($authors) == 0) {
Chris@0 71 $authors = new Collection\Author();
Chris@0 72 } else {
Chris@0 73 $authors = new Collection\Author(
Chris@0 74 Reader\Reader::arrayUnique($authors)
Chris@0 75 );
Chris@0 76 }
Chris@0 77
Chris@0 78 $this->data['authors'] = $authors;
Chris@0 79 return $this->data['authors'];
Chris@0 80 }
Chris@0 81
Chris@0 82 /**
Chris@0 83 * Get the entry content
Chris@0 84 *
Chris@0 85 * @return string
Chris@0 86 */
Chris@0 87 public function getContent()
Chris@0 88 {
Chris@0 89 if (array_key_exists('content', $this->data)) {
Chris@0 90 return $this->data['content'];
Chris@0 91 }
Chris@0 92
Chris@0 93 $content = null;
Chris@0 94
Chris@0 95 $el = $this->getXpath()->query($this->getXpathPrefix() . '/atom:content');
Chris@0 96 if ($el->length > 0) {
Chris@0 97 $el = $el->item(0);
Chris@0 98 $type = $el->getAttribute('type');
Chris@0 99 switch ($type) {
Chris@0 100 case '':
Chris@0 101 case 'text':
Chris@0 102 case 'text/plain':
Chris@0 103 case 'html':
Chris@0 104 case 'text/html':
Chris@0 105 $content = $el->nodeValue;
Chris@0 106 break;
Chris@0 107 case 'xhtml':
Chris@0 108 $this->getXpath()->registerNamespace('xhtml', 'http://www.w3.org/1999/xhtml');
Chris@0 109 $xhtml = $this->getXpath()->query(
Chris@0 110 $this->getXpathPrefix() . '/atom:content/xhtml:div'
Chris@0 111 )->item(0);
Chris@0 112 $d = new DOMDocument('1.0', $this->getEncoding());
Chris@0 113 $deep = version_compare(PHP_VERSION, '7', 'ge') ? 1 : true;
Chris@0 114 $xhtmls = $d->importNode($xhtml, $deep);
Chris@0 115 $d->appendChild($xhtmls);
Chris@0 116 $content = $this->collectXhtml(
Chris@0 117 $d->saveXML(),
Chris@0 118 $d->lookupPrefix('http://www.w3.org/1999/xhtml')
Chris@0 119 );
Chris@0 120 break;
Chris@0 121 }
Chris@0 122 }
Chris@0 123
Chris@12 124 if (! $content) {
Chris@0 125 $content = $this->getDescription();
Chris@0 126 }
Chris@0 127
Chris@0 128 $this->data['content'] = trim($content);
Chris@0 129
Chris@0 130 return $this->data['content'];
Chris@0 131 }
Chris@0 132
Chris@0 133 /**
Chris@0 134 * Parse out XHTML to remove the namespacing
Chris@0 135 *
Chris@0 136 * @param $xhtml
Chris@0 137 * @param $prefix
Chris@0 138 * @return mixed
Chris@0 139 */
Chris@0 140 protected function collectXhtml($xhtml, $prefix)
Chris@0 141 {
Chris@12 142 if (! empty($prefix)) {
Chris@0 143 $prefix = $prefix . ':';
Chris@0 144 }
Chris@0 145 $matches = [
Chris@0 146 "/<\?xml[^<]*>[^<]*<" . $prefix . "div[^<]*/",
Chris@0 147 "/<\/" . $prefix . "div>\s*$/"
Chris@0 148 ];
Chris@0 149 $xhtml = preg_replace($matches, '', $xhtml);
Chris@12 150 if (! empty($prefix)) {
Chris@0 151 $xhtml = preg_replace("/(<[\/]?)" . $prefix . "([a-zA-Z]+)/", '$1$2', $xhtml);
Chris@0 152 }
Chris@0 153 return $xhtml;
Chris@0 154 }
Chris@0 155
Chris@0 156 /**
Chris@0 157 * Get the entry creation date
Chris@0 158 *
Chris@0 159 * @return string
Chris@0 160 */
Chris@0 161 public function getDateCreated()
Chris@0 162 {
Chris@0 163 if (array_key_exists('datecreated', $this->data)) {
Chris@0 164 return $this->data['datecreated'];
Chris@0 165 }
Chris@0 166
Chris@0 167 $date = null;
Chris@0 168
Chris@0 169 if ($this->getAtomType() === Reader\Reader::TYPE_ATOM_03) {
Chris@0 170 $dateCreated = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:created)');
Chris@0 171 } else {
Chris@0 172 $dateCreated = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:published)');
Chris@0 173 }
Chris@0 174
Chris@0 175 if ($dateCreated) {
Chris@0 176 $date = new DateTime($dateCreated);
Chris@0 177 }
Chris@0 178
Chris@0 179 $this->data['datecreated'] = $date;
Chris@0 180
Chris@0 181 return $this->data['datecreated'];
Chris@0 182 }
Chris@0 183
Chris@0 184 /**
Chris@0 185 * Get the entry modification date
Chris@0 186 *
Chris@0 187 * @return string
Chris@0 188 */
Chris@0 189 public function getDateModified()
Chris@0 190 {
Chris@0 191 if (array_key_exists('datemodified', $this->data)) {
Chris@0 192 return $this->data['datemodified'];
Chris@0 193 }
Chris@0 194
Chris@0 195 $date = null;
Chris@0 196
Chris@0 197 if ($this->getAtomType() === Reader\Reader::TYPE_ATOM_03) {
Chris@0 198 $dateModified = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:modified)');
Chris@0 199 } else {
Chris@0 200 $dateModified = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:updated)');
Chris@0 201 }
Chris@0 202
Chris@0 203 if ($dateModified) {
Chris@0 204 $date = new DateTime($dateModified);
Chris@0 205 }
Chris@0 206
Chris@0 207 $this->data['datemodified'] = $date;
Chris@0 208
Chris@0 209 return $this->data['datemodified'];
Chris@0 210 }
Chris@0 211
Chris@0 212 /**
Chris@0 213 * Get the entry description
Chris@0 214 *
Chris@0 215 * @return string
Chris@0 216 */
Chris@0 217 public function getDescription()
Chris@0 218 {
Chris@0 219 if (array_key_exists('description', $this->data)) {
Chris@0 220 return $this->data['description'];
Chris@0 221 }
Chris@0 222
Chris@0 223 $description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:summary)');
Chris@0 224
Chris@12 225 if (! $description) {
Chris@0 226 $description = null;
Chris@0 227 }
Chris@0 228
Chris@0 229 $this->data['description'] = $description;
Chris@0 230
Chris@0 231 return $this->data['description'];
Chris@0 232 }
Chris@0 233
Chris@0 234 /**
Chris@0 235 * Get the entry enclosure
Chris@0 236 *
Chris@0 237 * @return string
Chris@0 238 */
Chris@0 239 public function getEnclosure()
Chris@0 240 {
Chris@0 241 if (array_key_exists('enclosure', $this->data)) {
Chris@0 242 return $this->data['enclosure'];
Chris@0 243 }
Chris@0 244
Chris@0 245 $enclosure = null;
Chris@0 246
Chris@0 247 $nodeList = $this->getXpath()->query($this->getXpathPrefix() . '/atom:link[@rel="enclosure"]');
Chris@0 248
Chris@0 249 if ($nodeList->length > 0) {
Chris@0 250 $enclosure = new stdClass();
Chris@0 251 $enclosure->url = $nodeList->item(0)->getAttribute('href');
Chris@0 252 $enclosure->length = $nodeList->item(0)->getAttribute('length');
Chris@0 253 $enclosure->type = $nodeList->item(0)->getAttribute('type');
Chris@0 254 }
Chris@0 255
Chris@0 256 $this->data['enclosure'] = $enclosure;
Chris@0 257
Chris@0 258 return $this->data['enclosure'];
Chris@0 259 }
Chris@0 260
Chris@0 261 /**
Chris@0 262 * Get the entry ID
Chris@0 263 *
Chris@0 264 * @return string
Chris@0 265 */
Chris@0 266 public function getId()
Chris@0 267 {
Chris@0 268 if (array_key_exists('id', $this->data)) {
Chris@0 269 return $this->data['id'];
Chris@0 270 }
Chris@0 271
Chris@0 272 $id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:id)');
Chris@0 273
Chris@12 274 if (! $id) {
Chris@0 275 if ($this->getPermalink()) {
Chris@0 276 $id = $this->getPermalink();
Chris@0 277 } elseif ($this->getTitle()) {
Chris@0 278 $id = $this->getTitle();
Chris@0 279 } else {
Chris@0 280 $id = null;
Chris@0 281 }
Chris@0 282 }
Chris@0 283
Chris@0 284 $this->data['id'] = $id;
Chris@0 285
Chris@0 286 return $this->data['id'];
Chris@0 287 }
Chris@0 288
Chris@0 289 /**
Chris@0 290 * Get the base URI of the feed (if set).
Chris@0 291 *
Chris@0 292 * @return string|null
Chris@0 293 */
Chris@0 294 public function getBaseUrl()
Chris@0 295 {
Chris@0 296 if (array_key_exists('baseUrl', $this->data)) {
Chris@0 297 return $this->data['baseUrl'];
Chris@0 298 }
Chris@0 299
Chris@0 300 $baseUrl = $this->getXpath()->evaluate(
Chris@0 301 'string('
Chris@0 302 . $this->getXpathPrefix()
Chris@0 303 . '/@xml:base[1]'
Chris@0 304 . ')'
Chris@0 305 );
Chris@0 306
Chris@12 307 if (! $baseUrl) {
Chris@0 308 $baseUrl = $this->getXpath()->evaluate('string(//@xml:base[1])');
Chris@0 309 }
Chris@0 310
Chris@12 311 if (! $baseUrl) {
Chris@0 312 $baseUrl = null;
Chris@0 313 }
Chris@0 314
Chris@0 315 $this->data['baseUrl'] = $baseUrl;
Chris@0 316
Chris@0 317 return $this->data['baseUrl'];
Chris@0 318 }
Chris@0 319
Chris@0 320 /**
Chris@0 321 * Get a specific link
Chris@0 322 *
Chris@0 323 * @param int $index
Chris@0 324 * @return string
Chris@0 325 */
Chris@0 326 public function getLink($index = 0)
Chris@0 327 {
Chris@12 328 if (! array_key_exists('links', $this->data)) {
Chris@0 329 $this->getLinks();
Chris@0 330 }
Chris@0 331
Chris@0 332 if (isset($this->data['links'][$index])) {
Chris@0 333 return $this->data['links'][$index];
Chris@0 334 }
Chris@0 335
Chris@0 336 return;
Chris@0 337 }
Chris@0 338
Chris@0 339 /**
Chris@0 340 * Get all links
Chris@0 341 *
Chris@0 342 * @return array
Chris@0 343 */
Chris@0 344 public function getLinks()
Chris@0 345 {
Chris@0 346 if (array_key_exists('links', $this->data)) {
Chris@0 347 return $this->data['links'];
Chris@0 348 }
Chris@0 349
Chris@0 350 $links = [];
Chris@0 351
Chris@0 352 $list = $this->getXpath()->query(
Chris@0 353 $this->getXpathPrefix() . '//atom:link[@rel="alternate"]/@href' . '|' .
Chris@0 354 $this->getXpathPrefix() . '//atom:link[not(@rel)]/@href'
Chris@0 355 );
Chris@0 356
Chris@0 357 if ($list->length) {
Chris@0 358 foreach ($list as $link) {
Chris@0 359 $links[] = $this->absolutiseUri($link->value);
Chris@0 360 }
Chris@0 361 }
Chris@0 362
Chris@0 363 $this->data['links'] = $links;
Chris@0 364
Chris@0 365 return $this->data['links'];
Chris@0 366 }
Chris@0 367
Chris@0 368 /**
Chris@0 369 * Get a permalink to the entry
Chris@0 370 *
Chris@0 371 * @return string
Chris@0 372 */
Chris@0 373 public function getPermalink()
Chris@0 374 {
Chris@0 375 return $this->getLink(0);
Chris@0 376 }
Chris@0 377
Chris@0 378 /**
Chris@0 379 * Get the entry title
Chris@0 380 *
Chris@0 381 * @return string
Chris@0 382 */
Chris@0 383 public function getTitle()
Chris@0 384 {
Chris@0 385 if (array_key_exists('title', $this->data)) {
Chris@0 386 return $this->data['title'];
Chris@0 387 }
Chris@0 388
Chris@0 389 $title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/atom:title)');
Chris@0 390
Chris@12 391 if (! $title) {
Chris@0 392 $title = null;
Chris@0 393 }
Chris@0 394
Chris@0 395 $this->data['title'] = $title;
Chris@0 396
Chris@0 397 return $this->data['title'];
Chris@0 398 }
Chris@0 399
Chris@0 400 /**
Chris@0 401 * Get the number of comments/replies for current entry
Chris@0 402 *
Chris@0 403 * @return int
Chris@0 404 */
Chris@0 405 public function getCommentCount()
Chris@0 406 {
Chris@0 407 if (array_key_exists('commentcount', $this->data)) {
Chris@0 408 return $this->data['commentcount'];
Chris@0 409 }
Chris@0 410
Chris@0 411 $count = null;
Chris@0 412
Chris@0 413 $this->getXpath()->registerNamespace('thread10', 'http://purl.org/syndication/thread/1.0');
Chris@0 414 $list = $this->getXpath()->query(
Chris@0 415 $this->getXpathPrefix() . '//atom:link[@rel="replies"]/@thread10:count'
Chris@0 416 );
Chris@0 417
Chris@0 418 if ($list->length) {
Chris@0 419 $count = $list->item(0)->value;
Chris@0 420 }
Chris@0 421
Chris@0 422 $this->data['commentcount'] = $count;
Chris@0 423
Chris@0 424 return $this->data['commentcount'];
Chris@0 425 }
Chris@0 426
Chris@0 427 /**
Chris@0 428 * Returns a URI pointing to the HTML page where comments can be made on this entry
Chris@0 429 *
Chris@0 430 * @return string
Chris@0 431 */
Chris@0 432 public function getCommentLink()
Chris@0 433 {
Chris@0 434 if (array_key_exists('commentlink', $this->data)) {
Chris@0 435 return $this->data['commentlink'];
Chris@0 436 }
Chris@0 437
Chris@0 438 $link = null;
Chris@0 439
Chris@0 440 $list = $this->getXpath()->query(
Chris@0 441 $this->getXpathPrefix() . '//atom:link[@rel="replies" and @type="text/html"]/@href'
Chris@0 442 );
Chris@0 443
Chris@0 444 if ($list->length) {
Chris@0 445 $link = $list->item(0)->value;
Chris@0 446 $link = $this->absolutiseUri($link);
Chris@0 447 }
Chris@0 448
Chris@0 449 $this->data['commentlink'] = $link;
Chris@0 450
Chris@0 451 return $this->data['commentlink'];
Chris@0 452 }
Chris@0 453
Chris@0 454 /**
Chris@0 455 * Returns a URI pointing to a feed of all comments for this entry
Chris@0 456 *
Chris@0 457 * @param string $type
Chris@0 458 * @return string
Chris@0 459 */
Chris@0 460 public function getCommentFeedLink($type = 'atom')
Chris@0 461 {
Chris@0 462 if (array_key_exists('commentfeedlink', $this->data)) {
Chris@0 463 return $this->data['commentfeedlink'];
Chris@0 464 }
Chris@0 465
Chris@0 466 $link = null;
Chris@0 467
Chris@0 468 $list = $this->getXpath()->query(
Chris@0 469 $this->getXpathPrefix() . '//atom:link[@rel="replies" and @type="application/' . $type.'+xml"]/@href'
Chris@0 470 );
Chris@0 471
Chris@0 472 if ($list->length) {
Chris@0 473 $link = $list->item(0)->value;
Chris@0 474 $link = $this->absolutiseUri($link);
Chris@0 475 }
Chris@0 476
Chris@0 477 $this->data['commentfeedlink'] = $link;
Chris@0 478
Chris@0 479 return $this->data['commentfeedlink'];
Chris@0 480 }
Chris@0 481
Chris@0 482 /**
Chris@0 483 * Get all categories
Chris@0 484 *
Chris@0 485 * @return Collection\Category
Chris@0 486 */
Chris@0 487 public function getCategories()
Chris@0 488 {
Chris@0 489 if (array_key_exists('categories', $this->data)) {
Chris@0 490 return $this->data['categories'];
Chris@0 491 }
Chris@0 492
Chris@0 493 if ($this->getAtomType() == Reader\Reader::TYPE_ATOM_10) {
Chris@0 494 $list = $this->getXpath()->query($this->getXpathPrefix() . '//atom:category');
Chris@0 495 } else {
Chris@0 496 /**
Chris@0 497 * Since Atom 0.3 did not support categories, it would have used the
Chris@0 498 * Dublin Core extension. However there is a small possibility Atom 0.3
Chris@0 499 * may have been retrofitted to use Atom 1.0 instead.
Chris@0 500 */
Chris@0 501 $this->getXpath()->registerNamespace('atom10', Reader\Reader::NAMESPACE_ATOM_10);
Chris@0 502 $list = $this->getXpath()->query($this->getXpathPrefix() . '//atom10:category');
Chris@0 503 }
Chris@0 504
Chris@0 505 if ($list->length) {
Chris@0 506 $categoryCollection = new Collection\Category;
Chris@0 507 foreach ($list as $category) {
Chris@0 508 $categoryCollection[] = [
Chris@0 509 'term' => $category->getAttribute('term'),
Chris@0 510 'scheme' => $category->getAttribute('scheme'),
Chris@0 511 'label' => $category->getAttribute('label')
Chris@0 512 ];
Chris@0 513 }
Chris@0 514 } else {
Chris@0 515 return new Collection\Category;
Chris@0 516 }
Chris@0 517
Chris@0 518 $this->data['categories'] = $categoryCollection;
Chris@0 519
Chris@0 520 return $this->data['categories'];
Chris@0 521 }
Chris@0 522
Chris@0 523 /**
Chris@0 524 * Get source feed metadata from the entry
Chris@0 525 *
Chris@0 526 * @return Reader\Feed\Atom\Source|null
Chris@0 527 */
Chris@0 528 public function getSource()
Chris@0 529 {
Chris@0 530 if (array_key_exists('source', $this->data)) {
Chris@0 531 return $this->data['source'];
Chris@0 532 }
Chris@0 533
Chris@0 534 $source = null;
Chris@0 535 // TODO: Investigate why _getAtomType() fails here. Is it even needed?
Chris@0 536 if ($this->getType() == Reader\Reader::TYPE_ATOM_10) {
Chris@0 537 $list = $this->getXpath()->query($this->getXpathPrefix() . '/atom:source[1]');
Chris@0 538 if ($list->length) {
Chris@0 539 $element = $list->item(0);
Chris@0 540 $source = new Reader\Feed\Atom\Source($element, $this->getXpathPrefix());
Chris@0 541 }
Chris@0 542 }
Chris@0 543
Chris@0 544 $this->data['source'] = $source;
Chris@0 545 return $this->data['source'];
Chris@0 546 }
Chris@0 547
Chris@0 548 /**
Chris@0 549 * Attempt to absolutise the URI, i.e. if a relative URI apply the
Chris@0 550 * xml:base value as a prefix to turn into an absolute URI.
Chris@0 551 *
Chris@0 552 * @param $link
Chris@0 553 * @return string
Chris@0 554 */
Chris@0 555 protected function absolutiseUri($link)
Chris@0 556 {
Chris@12 557 if (! Uri::factory($link)->isAbsolute()) {
Chris@0 558 if ($this->getBaseUrl() !== null) {
Chris@0 559 $link = $this->getBaseUrl() . $link;
Chris@12 560 if (! Uri::factory($link)->isValid()) {
Chris@0 561 $link = null;
Chris@0 562 }
Chris@0 563 }
Chris@0 564 }
Chris@0 565 return $link;
Chris@0 566 }
Chris@0 567
Chris@0 568 /**
Chris@0 569 * Get an author entry
Chris@0 570 *
Chris@0 571 * @param DOMElement $element
Chris@0 572 * @return string
Chris@0 573 */
Chris@0 574 protected function getAuthorFromElement(DOMElement $element)
Chris@0 575 {
Chris@0 576 $author = [];
Chris@0 577
Chris@0 578 $emailNode = $element->getElementsByTagName('email');
Chris@0 579 $nameNode = $element->getElementsByTagName('name');
Chris@0 580 $uriNode = $element->getElementsByTagName('uri');
Chris@0 581
Chris@0 582 if ($emailNode->length && strlen($emailNode->item(0)->nodeValue) > 0) {
Chris@0 583 $author['email'] = $emailNode->item(0)->nodeValue;
Chris@0 584 }
Chris@0 585
Chris@0 586 if ($nameNode->length && strlen($nameNode->item(0)->nodeValue) > 0) {
Chris@0 587 $author['name'] = $nameNode->item(0)->nodeValue;
Chris@0 588 }
Chris@0 589
Chris@0 590 if ($uriNode->length && strlen($uriNode->item(0)->nodeValue) > 0) {
Chris@0 591 $author['uri'] = $uriNode->item(0)->nodeValue;
Chris@0 592 }
Chris@0 593
Chris@0 594 if (empty($author)) {
Chris@0 595 return;
Chris@0 596 }
Chris@0 597 return $author;
Chris@0 598 }
Chris@0 599
Chris@0 600 /**
Chris@0 601 * Register the default namespaces for the current feed format
Chris@0 602 */
Chris@0 603 protected function registerNamespaces()
Chris@0 604 {
Chris@0 605 switch ($this->getAtomType()) {
Chris@0 606 case Reader\Reader::TYPE_ATOM_03:
Chris@0 607 $this->getXpath()->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_03);
Chris@0 608 break;
Chris@0 609 default:
Chris@0 610 $this->getXpath()->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_10);
Chris@0 611 break;
Chris@0 612 }
Chris@0 613 }
Chris@0 614
Chris@0 615 /**
Chris@0 616 * Detect the presence of any Atom namespaces in use
Chris@0 617 *
Chris@0 618 * @return string
Chris@0 619 */
Chris@0 620 protected function getAtomType()
Chris@0 621 {
Chris@0 622 $dom = $this->getDomDocument();
Chris@0 623 $prefixAtom03 = $dom->lookupPrefix(Reader\Reader::NAMESPACE_ATOM_03);
Chris@0 624 $prefixAtom10 = $dom->lookupPrefix(Reader\Reader::NAMESPACE_ATOM_10);
Chris@0 625 if ($dom->isDefaultNamespace(Reader\Reader::NAMESPACE_ATOM_03)
Chris@12 626 || ! empty($prefixAtom03)) {
Chris@0 627 return Reader\Reader::TYPE_ATOM_03;
Chris@0 628 }
Chris@0 629 if ($dom->isDefaultNamespace(Reader\Reader::NAMESPACE_ATOM_10)
Chris@12 630 || ! empty($prefixAtom10)) {
Chris@0 631 return Reader\Reader::TYPE_ATOM_10;
Chris@0 632 }
Chris@0 633 }
Chris@0 634 }