]>
git.wh0rd.org - tt-rss.git/blob - classes/feeditem/atom.php
532c599cc858033da4ed3c371d1f87103f525b22
2 class FeedItem_Atom
extends FeedItem_Common
{
5 $id = $this->elem
->getElementsByTagName("id")->item(0);
10 return $this->get_link();
15 $updated = $this->elem
->getElementsByTagName("updated")->item(0);
18 return strtotime($updated->nodeValue
);
21 $published = $this->elem
->getElementsByTagName("published")->item(0);
24 return strtotime($published->nodeValue
);
27 $date = $this->xpath
->query("dc:date", $this->elem
)->item(0);
30 return strtotime($date->nodeValue
);
34 function rel2abs($rel, $base)
36 /* return if already absolute URL */
37 if (parse_url($rel, PHP_URL_SCHEME
) != '') return $rel;
39 /* queries and anchors */
40 if ($rel[0]=='#' ||
$rel[0]=='?') return $base.$rel;
42 /* parse base URL and convert to local variables:
43 $scheme, $host, $path */
44 extract(parse_url($base));
46 /* remove non-directory element from path */
47 $path = preg_replace('#/[^/]*$#', '', $path);
49 /* destroy path if relative url points to root */
50 if ($rel[0] == '/') $path = '';
52 /* dirty absolute URL */
53 $abs = "$host$path/$rel";
55 /* replace '//' or '/./' or '/foo/../' with '/' */
56 $re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#');
57 for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {}
59 /* absolute URL is ready! */
60 return $scheme.'://'.$abs;
64 $links = $this->elem
->getElementsByTagName("link");
66 foreach ($links as $link) {
67 if ($link && $link->hasAttribute("href") &&
68 (!$link->hasAttribute("rel")
69 ||
$link->getAttribute("rel") == "alternate"
70 ||
$link->getAttribute("rel") == "standout")) {
71 $base = $this->xpath
->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)",$link);
72 return $this->rel2abs($link->getAttribute("href"), $base);
77 function get_title() {
78 $title = $this->elem
->getElementsByTagName("title")->item(0);
81 return $title->nodeValue
;
85 function get_content() {
86 $content = $this->elem
->getElementsByTagName("content")->item(0);
89 if ($content->hasAttribute('type')) {
90 if ($content->getAttribute('type') == 'xhtml') {
91 for ($i = 0; $i < $content->childNodes
->length
; $i++
) {
92 $child = $content->childNodes
->item($i);
94 if ($child->hasChildNodes()) {
95 return $this->doc
->saveXML($child);
101 return $content->nodeValue
;
105 function get_description() {
106 $content = $this->elem
->getElementsByTagName("summary")->item(0);
109 if ($content->hasAttribute('type')) {
110 if ($content->getAttribute('type') == 'xhtml') {
111 for ($i = 0; $i < $content->childNodes
->length
; $i++
) {
112 $child = $content->childNodes
->item($i);
114 if ($child->hasChildNodes()) {
115 return $this->doc
->saveXML($child);
121 return $content->nodeValue
;
126 function get_categories() {
127 $categories = $this->elem
->getElementsByTagName("category");
130 foreach ($categories as $cat) {
131 if ($cat->hasAttribute("term"))
132 array_push($cats, $cat->getAttribute("term"));
135 $categories = $this->xpath
->query("dc:subject", $this->elem
);
137 foreach ($categories as $cat) {
138 array_push($cats, $cat->nodeValue
);
144 function get_enclosures() {
145 $links = $this->elem
->getElementsByTagName("link");
149 foreach ($links as $link) {
150 if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
151 if ($link->getAttribute("rel") == "enclosure") {
152 $enc = new FeedEnclosure();
154 $enc->type
= $link->getAttribute("type");
155 $enc->link
= $link->getAttribute("href");
156 $enc->length
= $link->getAttribute("length");
158 array_push($encs, $enc);
163 $enclosures = $this->xpath
->query("media:content", $this->elem
);
165 foreach ($enclosures as $enclosure) {
166 $enc = new FeedEnclosure();
168 $enc->type
= $enclosure->getAttribute("type");
169 $enc->link
= $enclosure->getAttribute("url");
170 $enc->length
= $enclosure->getAttribute("length");
172 array_push($encs, $enc);