/** * @param SimpleXMLElement $xmlBody * @param FeedInterface $feed * @param array $filters * * @return FeedInterface */ protected function parseBody(SimpleXMLElement $xmlBody, FeedInterface $feed, array $filters) { $namespaces = $xmlBody->getNamespaces(true); $feed->setPublicId($xmlBody->channel->link); $feed->setLink($xmlBody->channel->link); $feed->setTitle($xmlBody->channel->title); $feed->setDescription($xmlBody->channel->description); $latest = new \DateTime('@0'); $date = new \DateTime('now'); foreach ($xmlBody->channel->item as $xmlElement) { $item = $this->newItem(); if (isset($xmlElement->pubDate)) { $format = isset($format) ? $format : $this->guessDateFormat($xmlElement->pubDate); $date = self::convertToDateTime($xmlElement->pubDate, $format); } $item->setTitle($xmlElement->title)->setDescription($xmlElement->description)->setPublicId($xmlElement->guid)->setUpdated($date)->setLink($xmlElement->link)->setComment($xmlElement->comments)->setAuthor($xmlElement->author); if ($date > $latest) { $latest = $date; } $item->setAdditional($this->getAdditionalNamespacesElements($xmlElement, $namespaces)); $this->handleEnclosure($xmlElement, $item); $this->addValidItem($feed, $item, $filters); } $this->detectAndSetLastModified($xmlBody, $feed, $latest); return $feed; }
/** * @param SimpleXMLElement $xmlBody * @param FeedInterface $feed * * @throws ParserException */ protected function parseHeaders(SimpleXMLElement $xmlBody, FeedInterface $feed) { $feed->setPublicId($xmlBody->id); $feed->setLink(current($this->detectLink($xmlBody, 'self'))); $feed->setTitle($xmlBody->title); $feed->setDescription($xmlBody->subtitle); $format = $this->guessDateFormat($xmlBody->updated); $updated = self::convertToDateTime($xmlBody->updated, $format); $feed->setLastModified($updated); }
/** * @param SimpleXMLElement $xmlBody * @param FeedInterface $feed * @param array $filters * * @return FeedInInterface */ protected function parseBody(SimpleXMLElement $xmlBody, FeedInterface $feed, array $filters) { $feed->setPublicId($xmlBody->channel->link); $feed->setLink($xmlBody->channel->link); $feed->setTitle($xmlBody->channel->title); $feed->setDescription($xmlBody->channel->description); if (isset($xmlBody->channel->date)) { $date = $xmlBody->channel->children('dc', true); $updated = static::convertToDateTime($date[0], $this->guessDateFormat($date[0])); $feed->setLastModified($updated); } $format = null; foreach ($xmlBody->item as $xmlElement) { $item = $this->newItem(); $date = $xmlElement->children('dc', true); $format = !is_null($format) ? $format : $this->guessDateFormat($date[0]); $item->setTitle($xmlElement->title)->setDescription($xmlElement->description)->setUpdated(static::convertToDateTime($date[0], $format))->setLink($xmlElement->link); $this->addValidItem($feed, $item, $filters); } return $feed; }