]>
git.wh0rd.org - tt-rss.git/blob - classes/feeditem/atom.php
2 class FeedItem_Atom
extends FeedItem_Common
{
3 const NS_XML
= "http://www.w3.org/XML/1998/namespace";
6 $id = $this->elem
->getElementsByTagName("id")->item(0);
11 return $this->get_link();
16 $updated = $this->elem
->getElementsByTagName("updated")->item(0);
19 return strtotime($updated->nodeValue
);
22 $published = $this->elem
->getElementsByTagName("published")->item(0);
25 return strtotime($published->nodeValue
);
28 $date = $this->xpath
->query("dc:date", $this->elem
)->item(0);
31 return strtotime($date->nodeValue
);
37 $links = $this->elem
->getElementsByTagName("link");
39 foreach ($links as $link) {
40 if ($link && $link->hasAttribute("href") &&
41 (!$link->hasAttribute("rel")
42 ||
$link->getAttribute("rel") == "alternate"
43 ||
$link->getAttribute("rel") == "standout")) {
44 $base = $this->xpath
->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link);
47 return rewrite_relative_url($base, trim($link->getAttribute("href")));
49 return trim($link->getAttribute("href"));
55 function get_title() {
56 $title = $this->elem
->getElementsByTagName("title")->item(0);
59 return trim($title->nodeValue
);
63 function get_content() {
64 $content = $this->elem
->getElementsByTagName("content")->item(0);
67 if ($content->hasAttribute('type')) {
68 if ($content->getAttribute('type') == 'xhtml') {
69 for ($i = 0; $i < $content->childNodes
->length
; $i++
) {
70 $child = $content->childNodes
->item($i);
72 if ($child->hasChildNodes()) {
73 return $this->doc
->saveHTML($child);
79 return $this->subtree_or_text($content);
83 function get_description() {
84 $content = $this->elem
->getElementsByTagName("summary")->item(0);
87 if ($content->hasAttribute('type')) {
88 if ($content->getAttribute('type') == 'xhtml') {
89 for ($i = 0; $i < $content->childNodes
->length
; $i++
) {
90 $child = $content->childNodes
->item($i);
92 if ($child->hasChildNodes()) {
93 return $this->doc
->saveHTML($child);
99 return $this->subtree_or_text($content);
104 function get_categories() {
105 $categories = $this->elem
->getElementsByTagName("category");
108 foreach ($categories as $cat) {
109 if ($cat->hasAttribute("term"))
110 array_push($cats, trim($cat->getAttribute("term")));
113 $categories = $this->xpath
->query("dc:subject", $this->elem
);
115 foreach ($categories as $cat) {
116 array_push($cats, trim($cat->nodeValue
));
122 function get_enclosures() {
123 $links = $this->elem
->getElementsByTagName("link");
127 foreach ($links as $link) {
128 if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
129 if ($link->getAttribute("rel") == "enclosure") {
130 $enc = new FeedEnclosure();
132 $enc->type
= $link->getAttribute("type");
133 $enc->link
= $link->getAttribute("href");
134 $enc->length
= $link->getAttribute("length");
136 array_push($encs, $enc);
141 $enclosures = $this->xpath
->query("media:content", $this->elem
);
143 foreach ($enclosures as $enclosure) {
144 $enc = new FeedEnclosure();
146 $enc->type
= $enclosure->getAttribute("type");
147 $enc->link
= $enclosure->getAttribute("url");
148 $enc->length
= $enclosure->getAttribute("length");
149 $enc->height
= $enclosure->getAttribute("height");
150 $enc->width
= $enclosure->getAttribute("width");
152 $desc = $this->xpath
->query("media:description", $enclosure)->item(0);
153 if ($desc) $enc->title
= strip_tags($desc->nodeValue
);
155 array_push($encs, $enc);
159 $enclosures = $this->xpath
->query("media:group", $this->elem
);
161 foreach ($enclosures as $enclosure) {
162 $enc = new FeedEnclosure();
164 $content = $this->xpath
->query("media:content", $enclosure)->item(0);
167 $enc->type
= $content->getAttribute("type");
168 $enc->link
= $content->getAttribute("url");
169 $enc->length
= $content->getAttribute("length");
170 $enc->height
= $content->getAttribute("height");
171 $enc->width
= $content->getAttribute("width");
173 $desc = $this->xpath
->query("media:description", $content)->item(0);
175 $enc->title
= strip_tags($desc->nodeValue
);
177 $desc = $this->xpath
->query("media:description", $enclosure)->item(0);
178 if ($desc) $enc->title
= strip_tags($desc->nodeValue
);
181 array_push($encs, $enc);
185 $enclosures = $this->xpath
->query("media:thumbnail", $this->elem
);
187 foreach ($enclosures as $enclosure) {
188 $enc = new FeedEnclosure();
190 $enc->type
= "image/generic";
191 $enc->link
= $enclosure->getAttribute("url");
192 $enc->height
= $enclosure->getAttribute("height");
193 $enc->width
= $enclosure->getAttribute("width");
195 array_push($encs, $enc);
201 function get_language() {
202 $lang = $this->elem
->getAttributeNS(self
::NS_XML
, "lang");
207 // Fall back to the language declared on the feed, if any.
208 return $this->doc
->firstChild
->getAttributeNS(self
::NS_XML
, "lang");