From 55acf661b9f456669be1e501ac3306582ac356a0 Mon Sep 17 00:00:00 2001
From: Niehztog <Niehztog@users.noreply.github.com>
Date: Fri, 25 Mar 2022 00:30:14 +0100
Subject: [PATCH] =?UTF-8?q?add=20support=20for=20more=20media=20types=20as?=
 =?UTF-8?q?=20enclosures,=20handle=20result=20of=20/tex=E2=80=A6=20(#2324)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/XPathAbstract.php | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/XPathAbstract.php b/lib/XPathAbstract.php
index 540b98af..7a56050d 100644
--- a/lib/XPathAbstract.php
+++ b/lib/XPathAbstract.php
@@ -344,7 +344,7 @@ abstract class XPathAbstract extends BridgeAbstract {
 	protected function provideFeedIcon(DOMXPath $xpath) {
 		$icon = $xpath->query($this->getParam('feed_icon'));
 		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
 	 */
 	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
 	 */
-	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) {
 			return;
 		}
@@ -551,6 +552,8 @@ abstract class XPathAbstract extends BridgeAbstract {
 				return trim($item->nodeValue);
 			} elseif ($item instanceof DOMAttr) {
 				return trim($item->value);
+			} elseif ($item instanceof DOMText) {
+				return trim($item->wholeText);
 			}
 		} elseif(is_string($typedResult) && strlen($typedResult) > 0) {
 			return trim($typedResult);