]> git.wh0rd.org - tt-rss.git/blobdiff - classes/feeditem/atom.php
fix previous to not crash if document first child is not a DOMElement or whatever
[tt-rss.git] / classes / feeditem / atom.php
index 7990a61c985dff0fac4d1ef160a8cd9a7aeed356..8c3e0f8a748b029b8c81b9df86cce89269efabdd 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);
@@ -69,13 +70,13 @@ class FeedItem_Atom extends FeedItem_Common {
                                                $child = $content->childNodes->item($i);
 
                                                if ($child->hasChildNodes()) {
-                                                       return $this->doc->saveXML($child);
+                                                       return $this->doc->saveHTML($child);
                                                }
                                        }
                                }
                        }
 
-                       return $content->c14n();
+                       return $this->subtree_or_text($content);
                }
        }
 
@@ -89,13 +90,13 @@ class FeedItem_Atom extends FeedItem_Common {
                                                $child = $content->childNodes->item($i);
 
                                                if ($child->hasChildNodes()) {
-                                                       return $this->doc->saveXML($child);
+                                                       return $this->doc->saveHTML($child);
                                                }
                                        }
                                }
                        }
 
-                       return $content->c14n();
+                       return $this->subtree_or_text($content);
                }
 
        }
@@ -197,5 +198,18 @@ class FeedItem_Atom extends FeedItem_Common {
                return $encs;
        }
 
+       function get_language() {
+               $lang = $this->elem->getAttributeNS(self::NS_XML, "lang");
+
+               if (!empty($lang)) {
+                       return $lang;
+               } else {
+                       // Fall back to the language declared on the feed, if any.
+                       foreach ($this->doc->childNodes as $child) {
+                               if (method_exists($child, "getAttributeNS")) {
+                                       return $child->getAttributeNS(self::NS_XML, "lang");
+                               }
+                       }
+               }
+       }
 }
-?>