summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--providers/Rss.php30
-rw-r--r--providers/Youtube.php30
2 files changed, 30 insertions, 30 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;
}
diff --git a/providers/Youtube.php b/providers/Youtube.php
index 03d0e27..4230c09 100644
--- a/providers/Youtube.php
+++ b/providers/Youtube.php
@@ -25,36 +25,6 @@ class Youtube extends Rss {
return '../cache/youtube.%s';
}
- protected function _mapRssItem($item) {
- $itemObj = parent::_mapRssItem($item);
- if (array_key_exists('descriptionlink', $this->_options)) {
- $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) {
- $itemObj->Link = $textLinks[$linkIndex];
- }
- }
- }
- return $itemObj;
- }
-
private function _getVideoMetadata($ids) {
$cacheFile = sprintf($this->_getCachePath() . '.metadata', $this->_feed);
$cacheData = [];