]> 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 dfac714..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);
@@ -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->nodeValue;
+                       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->nodeValue;
+                       return $this->subtree_or_text($content);
                }
 
        }
@@ -137,65 +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();
-
-                       $enc->type = $enclosure->getAttribute("type");
-                       $enc->link = $enclosure->getAttribute("url");
-                       $enc->length = $enclosure->getAttribute("length");
-                       $enc->height = $enclosure->getAttribute("height");
-                       $enc->width = $enclosure->getAttribute("width");
-
-                       $desc = $this->xpath->query("media:description", $enclosure)->item(0);
-                       if ($desc) $enc->title = strip_tags($desc->nodeValue);
-
-                       array_push($encs, $enc);
-               }
-
-
-               $enclosures = $this->xpath->query("media:group", $this->elem);
-
-               foreach ($enclosures as $enclosure) {
-                       $enc = new FeedEnclosure();
-
-                       $content = $this->xpath->query("media:content", $enclosure)->item(0);
+               return $encs;
+       }
 
-                       if ($content) {
-                               $enc->type = $content->getAttribute("type");
-                               $enc->link = $content->getAttribute("url");
-                               $enc->length = $content->getAttribute("length");
-                               $enc->height = $content->getAttribute("height");
-                               $enc->width = $content->getAttribute("width");
+       function get_language() {
+               $lang = $this->elem->getAttributeNS(self::NS_XML, "lang");
 
-                               $desc = $this->xpath->query("media:description", $content)->item(0);
-                               if ($desc) {
-                                       $enc->title = strip_tags($desc->nodeValue);
-                               } else {
-                                       $desc = $this->xpath->query("media:description", $enclosure)->item(0);
-                                       if ($desc) $enc->title = strip_tags($desc->nodeValue);
+               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");
                                }
-
-                               array_push($encs, $enc);
                        }
                }
-
-               $enclosures = $this->xpath->query("media:thumbnail", $this->elem);
-
-               foreach ($enclosures as $enclosure) {
-                       $enc = new FeedEnclosure();
-
-                       $enc->type = "image/generic";
-                       $enc->link = $enclosure->getAttribute("url");
-                       $enc->height = $enclosure->getAttribute("height");
-                       $enc->width = $enclosure->getAttribute("width");
-
-                       array_push($encs, $enc);
-               }
-
-               return $encs;
        }
-
 }
-?>