Exemple #1
0
 /**
  * Write an ItemInterface into the feed
  *
  * @param \Nekland\Bundle\FeedBundle\XML\XMLManager     $xml
  * @param \Nekland\Bundle\FeedBundle\Item\ItemInterface $item
  * @return void
  */
 private function writeItem(XMLManager $xml, ItemInterface $item)
 {
     $nodeItem = $this->createItem($xml);
     $xml->addTextNode('title', $item->getFeedTitle(), $nodeItem);
     $xml->addTextNode('description', $item->getFeedDescription(), $nodeItem);
     $id = $item->getFeedId();
     if (empty($id)) {
         throw new \InvalidArgumentException('The method « getFeedId » MUST return a not empty value.');
     }
     $xml->addTextNode('guid', $id, $nodeItem);
     $xml->addTextNode('link', $this->getRoute($item), $nodeItem);
     $xml->addTextNode('pubDate', $item->getFeedDate()->format(\DateTime::RSS), $nodeItem);
     if ($this->itemHas($item, 'getFeedAuthor')) {
         if ($author = $this->getAuthor($item)) {
             $xml->addTextNode('author', $author, $nodeItem);
         }
     }
     if ($this->itemHas($item, 'getFeedCategory')) {
         $xml->addTextNode('category', $item->getFeedCategory(), $nodeItem);
     }
     if ($this->itemHas($item, 'getFeedCommentRoute')) {
         if ($comments = $this->getComments($item)) {
             $xml->addTextNode('comments', $comments, $nodeItem);
         }
     }
     if ($this->itemHas($item, 'getFeedEnclosure')) {
         if ($enclosure = $this->getEnclosure($item, $xml)) {
             $nodeItem->appendChild($enclosure);
         }
     }
 }
Exemple #2
0
 /**
  * Write an ItemInterface into the feed
  *
  * @param \Nekland\Bundle\FeedBundle\XML\XMLManager     $xml
  * @param \Nekland\Bundle\FeedBundle\Item\ItemInterface $item
  * @return void
  */
 private function writeItem(XMLManager $xml, ItemInterface $item)
 {
     $nodeItem = $this->createItem($xml);
     $xml->addTextNode('title', $item->getFeedTitle(), $nodeItem);
     $type = $this->itemHas($item, 'getAtomContentType') ? $item->getAtomContentType() : null;
     $content = $xml->addTextNode('content', $type === 'xhtml' ? $item->getFeedDescription() : htmlentities($item->getFeedDescription(), ENT_COMPAT, 'UTF-8'), $nodeItem);
     if (!empty($type)) {
         $content->setAttribute('type', $type);
     }
     if ($this->itemHas($item, 'getAtomContentLanguage')) {
         $content->setAttribute('xml:lang', $item->getAtomContentLanguage());
     }
     $id = $item->getFeedId();
     if (empty($id)) {
         throw new \InvalidArgumentException('The method « getFeedId » CAN\'T return an empty value.');
     }
     $xml->addTextNode('id', $id, $nodeItem);
     $xml->addTextNode('published', $item->getFeedDate()->format(\DateTime::ATOM), $nodeItem);
     $date = new \DateTime();
     $xml->addTextNode('updated', $item->getFeedDate()->format(\DateTime::ATOM), $nodeItem);
     if ($this->itemHas($item, 'getFeedAuthor')) {
         if ($author = $item->getFeedAuthor()) {
             $authorNode = $this->createAuthor($xml, $author);
             $nodeItem->appendChild($authorNode);
         }
     }
     if ($this->itemHas($item, 'getSummary')) {
         $type = $this->itemHas($item, 'getAtomSummaryType') ? $item->getAtomSummaryType() : null;
         $summary = $xml->addTextNode('category', $type === 'xhtml' ? $item->getFeedDescription() : htmlentities($item->getFeedSummary(), ENT_COMPAT, 'UTF-8'), $nodeItem);
         if (!empty($type)) {
             $summary->setAttribute('type', $type);
         }
     }
     if ($this->itemHas($item, 'getAtomContributors')) {
         if ($contributors = $item->getAtomContributors($item)) {
             foreach ($contributors as $contributor) {
                 $contribNode = $this->createContributor($xml, $contributor);
                 $nodeItem->appendChild($contribNode);
             }
         }
     }
     $routes = $item->getFeedRoutes();
     foreach ($routes as $route) {
         $linkNode = $this->createLink($xml, $route);
         $nodeItem->appendChild($linkNode);
     }
 }