]> 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 532c599..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);
@@ -30,36 +31,8 @@ class FeedItem_Atom extends FeedItem_Common {
                        return strtotime($date->nodeValue);
                }
        }
-       
-       function rel2abs($rel, $base)
-       {
-           /* return if already absolute URL */
-           if (parse_url($rel, PHP_URL_SCHEME) != '') return $rel;
-       
-           /* queries and anchors */
-           if ($rel[0]=='#' || $rel[0]=='?') return $base.$rel;
-       
-           /* parse base URL and convert to local variables:
-              $scheme, $host, $path */
-           extract(parse_url($base));
-       
-           /* remove non-directory element from path */
-           $path = preg_replace('#/[^/]*$#', '', $path);
-       
-           /* destroy path if relative url points to root */
-           if ($rel[0] == '/') $path = '';
-       
-           /* dirty absolute URL */
-           $abs = "$host$path/$rel";
-       
-           /* replace '//' or '/./' or '/foo/../' with '/' */
-           $re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#');
-           for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {}
-
-           /* absolute URL is ready! */
-           return $scheme.'://'.$abs;
-       }
-       
+
+
        function get_link() {
                $links = $this->elem->getElementsByTagName("link");
 
@@ -68,8 +41,13 @@ class FeedItem_Atom extends FeedItem_Common {
                                (!$link->hasAttribute("rel")
                                        || $link->getAttribute("rel") == "alternate"
                                        || $link->getAttribute("rel") == "standout")) {
-                               $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)",$link);
-                               return $this->rel2abs($link->getAttribute("href"), $base);
+                               $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link);
+
+                               if ($base)
+                                       return rewrite_relative_url($base, trim($link->getAttribute("href")));
+                               else
+                                       return trim($link->getAttribute("href"));
+
                        }
                }
        }
@@ -78,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);
                }
        }
 
@@ -92,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);
                }
        }
 
@@ -112,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);
                }
 
        }
@@ -129,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;
@@ -160,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;
        }
-
 }
-?>