]> git.wh0rd.org Git - tt-rss.git/commitdiff
parser: properly support tag subtrees instead of text content for article content
authorAndrew Dolgov <noreply@fakecake.org>
Fri, 22 Jan 2016 22:48:32 +0000 (01:48 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Fri, 22 Jan 2016 22:48:32 +0000 (01:48 +0300)
classes/feeditem/atom.php
classes/feeditem/common.php
classes/feeditem/rss.php

index dfac7149f6cb4981cd6d768dd36e3600b80dd438..e132789ba3c33700d7a0a413811f6f011db78d86 100644 (file)
@@ -75,7 +75,7 @@ class FeedItem_Atom extends FeedItem_Common {
                                }
                        }
 
-                       return $content->nodeValue;
+                       return $this->subtree_or_text($content);
                }
        }
 
@@ -95,7 +95,7 @@ class FeedItem_Atom extends FeedItem_Common {
                                }
                        }
 
-                       return $content->nodeValue;
+                       return $this->subtree_or_text($content);
                }
 
        }
index 80bebf8fb9db5674d40870e69d227af745af0e3f..070692d7f872c2f32874ef379233ffbc06829294 100644 (file)
@@ -70,6 +70,17 @@ abstract class FeedItem_Common extends FeedItem {
                }
        }
 
+       function count_children($node) {
+               return $node->getElementsByTagName("*")->length;
+       }
+
+       function subtree_or_text($node) {
+               if ($this->count_children($node) == 0) {
+                       return $node->nodeValue;
+               } else {
+                       return $node->c14n();
+               }
+       }
 
 }
 ?>
index 27a364b812b90bb708b09b7f24d2e0803e06c40a..080e4083ab971743fcbfb874bdca888b3ac34729 100644 (file)
@@ -71,17 +71,19 @@ class FeedItem_RSS extends FeedItem_Common {
                $contentB = $this->elem->getElementsByTagName("description")->item(0);
 
                if ($contentA && !$contentB) {
-                       return $contentA->nodeValue;
+                       return $this->subtree_or_text($contentA);
                }
 
 
                if ($contentB && !$contentA) {
-                       return $contentB->nodeValue;
+                       return $this->subtree_or_text($contentB);
                }
 
                if ($contentA && $contentB) {
-                       return mb_strlen($contentA->nodeValue) > mb_strlen($contentB->nodeValue) ?
-                               $contentA->nodeValue : $contentB->nodeValue;
+                       $resultA = $this->subtree_or_text($contentA);
+                       $resultB = $this->subtree_or_text($contentB);
+
+                       return mb_strlen($resultA) > mb_strlen($resultB) ? $resultA : $resultB;
                }
        }