diff options
Diffstat (limited to 'providers/Rss.php')
| -rw-r--r-- | providers/Rss.php | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/providers/Rss.php b/providers/Rss.php index 9ef7286..a6145d9 100644 --- a/providers/Rss.php +++ b/providers/Rss.php @@ -34,6 +34,33 @@ class Rss extends \Providers\XmlFeed { return $item; } + protected function _getDescriptionLink($itemObj) { + $linkConfig = explode(':', $this->_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'], '/'); @@ -42,6 +69,9 @@ class Rss extends \Providers\XmlFeed { $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; } |
