rss: choose between description and content:encoded based on which one is longer because publishers are idiots and can't use tags properly

This commit is contained in:
Andrew Dolgov 2013-12-19 13:19:30 +04:00
parent 416a9b1c9c
commit f6c61b2d55
1 changed files with 11 additions and 6 deletions

View File

@ -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;
}
}