Browse Source

parser: fix failing on empty media:group tags

Andrew Dolgov 6 years ago
parent
commit
2ab7ccb695
2 changed files with 28 additions and 24 deletions
  1. 14 12
      classes/feeditem/atom.php
  2. 14 12
      classes/feeditem/rss.php

+ 14 - 12
classes/feeditem/atom.php

@@ -160,19 +160,21 @@ class FeedItem_Atom extends FeedItem_Common {
 
 			$content = $this->xpath->query("media:content", $enclosure)->item(0);
 
-			$enc->type = $content->getAttribute("type");
-			$enc->link = $content->getAttribute("url");
-			$enc->length = $content->getAttribute("length");
-
-			$desc = $this->xpath->query("media:description", $content)->item(0);
-			if ($desc) {
-				$enc->title = strip_tags($desc->nodeValue);
-			} else {
-				$desc = $this->xpath->query("media:description", $enclosure)->item(0);
-				if ($desc) $enc->title = strip_tags($desc->nodeValue);
-			}
+			if ($content) {
+				$enc->type = $content->getAttribute("type");
+				$enc->link = $content->getAttribute("url");
+				$enc->length = $content->getAttribute("length");
+
+				$desc = $this->xpath->query("media:description", $content)->item(0);
+				if ($desc) {
+					$enc->title = strip_tags($desc->nodeValue);
+				} else {
+					$desc = $this->xpath->query("media:description", $enclosure)->item(0);
+					if ($desc) $enc->title = strip_tags($desc->nodeValue);
+				}
 
-			array_push($encs, $enc);
+				array_push($encs, $enc);
+			}
 		}
 
 		$enclosures = $this->xpath->query("media:thumbnail", $this->elem);

+ 14 - 12
classes/feeditem/rss.php

@@ -140,19 +140,21 @@ class FeedItem_RSS extends FeedItem_Common {
 
 			$content = $this->xpath->query("media:content", $enclosure)->item(0);
 
-			$enc->type = $content->getAttribute("type");
-			$enc->link = $content->getAttribute("url");
-			$enc->length = $content->getAttribute("length");
-
-			$desc = $this->xpath->query("media:description", $content)->item(0);
-			if ($desc) {
-				$enc->title = strip_tags($desc->nodeValue);
-			} else {
-				$desc = $this->xpath->query("media:description", $enclosure)->item(0);
-				if ($desc) $enc->title = strip_tags($desc->nodeValue);
+			if ($content) {
+				$enc->type = $content->getAttribute("type");
+				$enc->link = $content->getAttribute("url");
+				$enc->length = $content->getAttribute("length");
+
+				$desc = $this->xpath->query("media:description", $content)->item(0);
+				if ($desc) {
+					$enc->title = strip_tags($desc->nodeValue);
+				} else {
+					$desc = $this->xpath->query("media:description", $enclosure)->item(0);
+					if ($desc) $enc->title = strip_tags($desc->nodeValue);
+				}
+
+				array_push($encs, $enc);
 			}
-
-			array_push($encs, $enc);
 		}
 
 		$enclosures = $this->xpath->query("media:thumbnail", $this->elem);