channel->item ?: $feed->entry; $items = []; foreach ($feedItems as $item) { $items[] = $item->asXML(); } return $items; } protected function _parseRssItem($contentString) { $itemString = str_replace(['content:encoded>', '', '<', '_options['descriptionlink']); $linkDomain = NULL; if (!is_numeric($linkConfig[0])) { $linkDomain = array_shift($linkConfig); if (!$linkConfig) { $linkConfig = ['1']; } } $linkIndex = intval($linkConfig[0]) - 1; $textLinks = []; if (preg_match_all('#(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-&?=%.]+#', $itemObj->Text, $textLinks)) { $textLinks = $textLinks[0]; if ($linkDomain) { $textLinks = array_values(array_filter($textLinks, function($link) use($linkDomain) { if($linkParts = parse_url($link)) { return $linkParts['host'] == $linkDomain; } })); } if (count($textLinks) > $linkIndex) { return $textLinks[$linkIndex]; } } return $itemObj->Link; } protected function _mapRssItem($item) { $itemObject = new Item(); $itemObject->ID = strval($item->id ?: $item->guid) ?: ltrim(parse_url(strval($item->link))['path'], '/'); $itemObject->Title = strval($item->title); $itemObject->Time = strval($item->published ?: $item->pubDate ?: $item->updated); $itemObject->Text = strval($item->summary ?: $item->description ?: $item->content ?: $item->group->description); $itemObject->Link = strval(isset($item->link['href']) ? $item->link->attributes()['href'] : $item->link); $itemObject->Author = strval($item->creator ? $item->creator : (is_string($item->author) ? $item->author : $item->author->name)); if (array_key_exists('descriptionlink', $this->_options)) { $itemObject->Link = $this->_getDescriptionLink($itemObject); } return $itemObject; } protected function _mapItems($content) { $items = []; foreach ($content as $contentString) { $item = $this->_parseRssItem($contentString); $items[] = $this->_mapRssItem($item); } return $items; } public function title() { $cacheFile = sprintf($this->_getCachePath() . '.title', $this->_feed); if (!file_exists($cacheFile)) { $this->_fetchItems(); } if ($this->_feedXml) { $title = strval($this->_feedXml->title ?: $this->_feedXml->channel->title); file_put_contents($cacheFile, $title); return $title; } else { return file_get_contents($cacheFile); } } } ?>