From: Andrew Dolgov Date: Thu, 19 Dec 2013 09:19:30 +0000 (+0400) Subject: rss: choose between description and content:encoded based on which one is longer... X-Git-Tag: 1.12~128 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=f6c61b2d55ff70819bc1582791fdc8df149eb22f;p=tt-rss.git rss: choose between description and content:encoded based on which one is longer because publishers are idiots and can't use tags properly --- diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php index f632d3bb..7d445a6c 100644 --- a/classes/feeditem/rss.php +++ b/classes/feeditem/rss.php @@ -59,16 +59,21 @@ class FeedItem_RSS extends FeedItem_Common { } function get_content() { - $content = $this->xpath->query("content:encoded", $this->elem)->item(0); + $contentA = $this->xpath->query("content:encoded", $this->elem)->item(0); + $contentB = $this->elem->getElementsByTagName("description")->item(0); - if ($content) { - return $content->nodeValue; + if ($contentA && !$contentB) { + return $contentA->nodeValue; } - $content = $this->elem->getElementsByTagName("description")->item(0); - if ($content) { - return $content->nodeValue; + if ($contentB && !$contentA) { + return $contentB->nodeValue; + } + + if ($contentA && $contentB) { + return mb_strlen($contentA->nodeValue) > mb_strlen($contentB->nodeValue) ? + $contentA->nodeValue : $contentB->nodeValue; } }