]> git.wh0rd.org - tt-rss.git/blobdiff - classes/feeditem/atom.php
support disabling of e-mail digests entirely
[tt-rss.git] / classes / feeditem / atom.php
old mode 100644 (file)
new mode 100755 (executable)
index f82c582..2bae075
@@ -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);
@@ -42,7 +43,11 @@ class FeedItem_Atom extends FeedItem_Common {
                                        || $link->getAttribute("rel") == "standout")) {
                                $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link);
 
-                               return rewrite_relative_url($base, $link->getAttribute("href"));
+                               if ($base)
+                                       return rewrite_relative_url($base, trim($link->getAttribute("href")));
+                               else
+                                       return trim($link->getAttribute("href"));
+
                        }
                }
        }
@@ -51,7 +56,7 @@ class FeedItem_Atom extends FeedItem_Common {
                $title = $this->elem->getElementsByTagName("title")->item(0);
 
                if ($title) {
-                       return $title->nodeValue;
+                       return trim($title->nodeValue);
                }
        }
 
@@ -65,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->nodeValue;
+                       return $this->subtree_or_text($content);
                }
        }
 
@@ -85,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->nodeValue;
+                       return $this->subtree_or_text($content);
                }
 
        }
@@ -102,13 +107,13 @@ class FeedItem_Atom extends FeedItem_Common {
 
                foreach ($categories as $cat) {
                        if ($cat->hasAttribute("term"))
-                               array_push($cats, $cat->getAttribute("term"));
+                               array_push($cats, trim($cat->getAttribute("term")));
                }
 
                $categories = $this->xpath->query("dc:subject", $this->elem);
 
                foreach ($categories as $cat) {
-                       array_push($cats, $cat->nodeValue);
+                       array_push($cats, trim($cat->nodeValue));
                }
 
                return $cats;
@@ -133,20 +138,23 @@ class FeedItem_Atom extends FeedItem_Common {
                        }
                }
 
-               $enclosures = $this->xpath->query("media:content", $this->elem);
+               $encs = array_merge($encs, parent::get_enclosures());
 
-               foreach ($enclosures as $enclosure) {
-                       $enc = new FeedEnclosure();
+               return $encs;
+       }
 
-                       $enc->type = $enclosure->getAttribute("type");
-                       $enc->link = $enclosure->getAttribute("url");
-                       $enc->length = $enclosure->getAttribute("length");
+       function get_language() {
+               $lang = $this->elem->getAttributeNS(self::NS_XML, "lang");
 
-                       array_push($encs, $enc);
+               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");
+                               }
+                       }
                }
-
-               return $encs;
        }
-
 }
-?>