AtomItemBuilder.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace PicoFeed\Syndication;
  3. use DOMElement;
  4. /**
  5. * Atom Item Builder
  6. *
  7. * @package PicoFeed\Syndication
  8. * @author Frederic Guillot
  9. */
  10. class AtomItemBuilder extends ItemBuilder
  11. {
  12. /**
  13. * @var DOMElement
  14. */
  15. protected $itemElement;
  16. /**
  17. * @var AtomHelper
  18. */
  19. protected $helper;
  20. /**
  21. * Build item
  22. *
  23. * @access public
  24. * @return DOMElement
  25. */
  26. public function build()
  27. {
  28. $this->itemElement = $this->feedBuilder->getDocument()->createElement('entry');
  29. $this->helper = new AtomHelper($this->feedBuilder->getDocument());
  30. if (!empty($this->itemId)) {
  31. $this->helper->buildId($this->itemElement, $this->itemId);
  32. } else {
  33. $this->helper->buildId($this->itemElement, $this->itemUrl);
  34. }
  35. $this->helper
  36. ->buildTitle($this->itemElement, $this->itemTitle)
  37. ->buildLink($this->itemElement, $this->itemUrl)
  38. ->buildDate($this->itemElement, $this->itemUpdatedDate, 'updated')
  39. ->buildDate($this->itemElement, $this->itemPublishedDate, 'published')
  40. ->buildAuthor($this->itemElement, $this->authorName, $this->authorEmail, $this->authorUrl)
  41. ;
  42. if (!empty($this->itemSummary)) {
  43. $this->helper->buildNode($this->itemElement, 'summary', $this->itemSummary);
  44. }
  45. if (!empty($this->itemContent)) {
  46. $node = $this->feedBuilder->getDocument()->createElement('content');
  47. $node->setAttribute('type', 'html');
  48. $node->appendChild($this->feedBuilder->getDocument()->createCDATASection($this->itemContent));
  49. $this->itemElement->appendChild($node);
  50. }
  51. return $this->itemElement;
  52. }
  53. }