<?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);
$base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link);
if ($base)
- return rewrite_relative_url($base, $link->getAttribute("href"));
+ return rewrite_relative_url($base, trim($link->getAttribute("href")));
else
- return $link->getAttribute("href");
+ return trim($link->getAttribute("href"));
}
}
$title = $this->elem->getElementsByTagName("title")->item(0);
if ($title) {
- return $title->nodeValue;
+ return trim($title->nodeValue);
}
}
$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);
}
}
$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);
}
}
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;
$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);
$content = $this->xpath->query("media:content", $enclosure)->item(0);
- $enc->type = $content->getAttribute("type");
- $enc->link = $content->getAttribute("url");
- $enc->length = $content->getAttribute("length");
+ 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");
+
+ $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);
+ }
- $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);
+ 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;
}
+ 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");
+ }
+ }
+ }
+ }
}
-?>