public function makeItems(\SimpleXMLElement $xmlFeed) { $result = array(); if (isset($xmlFeed->channel->item)) { foreach ($xmlFeed->channel->item as $item) { $feedItem = FeedItem::create((string) $item->title)->setContent(FeedItemContent::create()->setBody((string) $item->description))->setPublished(Timestamp::create(strtotime((string) $item->pubDate)))->setLink((string) $item->link); if (isset($item->guid)) { $feedItem->setId($item->guid); } if (isset($item->category)) { $feedItem->setCategory((string) $item->category); } $result[] = $feedItem; } } return $result; }
private function makeFeedItemContent($content) { $feedItemContent = FeedItemContent::create(); if (isset($content->attributes()->type)) { switch ((string) $content->attributes()->type) { case 'text': $feedItemContent->setType(new FeedItemContentType(FeedItemContentType::TEXT)); break; case 'html': $feedItemContent->setType(new FeedItemContentType(FeedItemContentType::HTML)); break; case 'xhtml': $feedItemContent->setType(new FeedItemContentType(FeedItemContentType::XHTML)); break; } } return $feedItemContent->setBody((string) $content); }
public function makeItems(\SimpleXMLElement $xmlFeed) { $xmlFeed->registerXPathNamespace(YandexRssFeedFormat::YANDEX_NAMESPACE_PREFIX, YandexRssFeedFormat::YANDEX_NAMESPACE_URI); $fullTextList = $xmlFeed->xpath('//' . YandexRssFeedFormat::YANDEX_NAMESPACE_PREFIX . ':full-text'); $result = array(); $i = 0; if (isset($xmlFeed->channel->item)) { foreach ($xmlFeed->channel->item as $item) { $feedItem = YandexRssFeedItem::create((string) $item->title)->setContent(FeedItemContent::create()->setBody((string) $item->description))->setPublished(Timestamp::create(strtotime((string) $item->pubDate)))->setFullText((string) $fullTextList[$i++])->setLink((string) $item->link); if (isset($item->guid)) { $feedItem->setId($item->guid); } if (isset($item->category)) { $feedItem->setCategory((string) $item->category); } $result[] = $feedItem; } } return $result; }