add support for more media types as enclosures, handle result of /tex… (#2324)

This commit is contained in:
Niehztog 2022-03-25 00:30:14 +01:00 committed by GitHub
parent 3a9e528301
commit 55acf661b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

@ -344,7 +344,7 @@ abstract class XPathAbstract extends BridgeAbstract {
protected function provideFeedIcon(DOMXPath $xpath) { protected function provideFeedIcon(DOMXPath $xpath) {
$icon = $xpath->query($this->getParam('feed_icon')); $icon = $xpath->query($this->getParam('feed_icon'));
if(count($icon) === 1) { if(count($icon) === 1) {
return $this->cleanImageUrl($this->getItemValueOrNodeValue($icon)); return $this->cleanMediaUrl($this->getItemValueOrNodeValue($icon));
} }
} }
@ -511,7 +511,7 @@ abstract class XPathAbstract extends BridgeAbstract {
* @return array * @return array
*/ */
protected function formatItemEnclosures($value) { protected function formatItemEnclosures($value) {
return array($this->cleanImageUrl($value)); return array($this->cleanMediaUrl($value));
} }
/** /**
@ -527,12 +527,13 @@ abstract class XPathAbstract extends BridgeAbstract {
} }
/** /**
* @param $imageUrl * @param $mediaUrl
* @return string|void * @return string|void
*/ */
protected function cleanImageUrl($imageUrl) protected function cleanMediaUrl($mediaUrl)
{ {
$result = preg_match('~(?:http(?:s)?:)?[\/a-zA-Z0-9\-_\.]+\.(?:jpg|gif|png|jpeg|ico){1}~', $imageUrl, $matches); $pattern = '~(?:http(?:s)?:)?[\/a-zA-Z0-9\-_\.\%]+\.(?:jpg|gif|png|jpeg|ico|mp3){1}~i';
$result = preg_match($pattern, $mediaUrl, $matches);
if(1 !== $result) { if(1 !== $result) {
return; return;
} }
@ -551,6 +552,8 @@ abstract class XPathAbstract extends BridgeAbstract {
return trim($item->nodeValue); return trim($item->nodeValue);
} elseif ($item instanceof DOMAttr) { } elseif ($item instanceof DOMAttr) {
return trim($item->value); return trim($item->value);
} elseif ($item instanceof DOMText) {
return trim($item->wholeText);
} }
} elseif(is_string($typedResult) && strlen($typedResult) > 0) { } elseif(is_string($typedResult) && strlen($typedResult) > 0) {
return trim($typedResult); return trim($typedResult);