]> git.wh0rd.org - tt-rss.git/commitdiff
Determine language for atom entry without a loop.
authorTobias Kappé <tobias.kappe@gmail.com>
Sun, 12 Aug 2018 15:17:13 +0000 (16:17 +0100)
committerTobias Kappé <tobias.kappe@gmail.com>
Sun, 12 Aug 2018 15:17:13 +0000 (16:17 +0100)
classes/feeditem/atom.php

index 6e7a904f8c7d4153460eec7cbf67a73f155a2b7a..ee55917577e77234c00c580fdb4437a75e8cbb37 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 class FeedItem_Atom extends FeedItem_Common {
+       const NS_XML = "http://www.w3.org/XML/1998/namespace";
 
        function get_id() {
                $id = $this->elem->getElementsByTagName("id")->item(0);
@@ -198,12 +199,13 @@ class FeedItem_Atom extends FeedItem_Common {
        }
 
        function get_language() {
-               $elem = $this->elem;
-               do {
-                       $lang = $elem->getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang");
-                       $elem = $elem->parentNode;
-               } while (empty($lang) && $elem instanceof DOMElement);
+               $lang = $this->elem->getAttributeNS(self::NS_XML, "lang");
 
-               return $lang;
+               if (!empty($lang)) {
+                       return $lang;
+               } else {
+                       // Fall back to the language declared on the feed, if any.
+                       return $this->doc->firstChild->getAttributeNS(self::NS_XML, "lang");
+               }
        }
 }