]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/atom.php
atom: remove rel2abs; use rewrite_relative_url
[tt-rss.git] / classes / feeditem / atom.php
1 <?php
2 class FeedItem_Atom extends FeedItem_Common {
3
4 function get_id() {
5 $id = $this->elem->getElementsByTagName("id")->item(0);
6
7 if ($id) {
8 return $id->nodeValue;
9 } else {
10 return $this->get_link();
11 }
12 }
13
14 function get_date() {
15 $updated = $this->elem->getElementsByTagName("updated")->item(0);
16
17 if ($updated) {
18 return strtotime($updated->nodeValue);
19 }
20
21 $published = $this->elem->getElementsByTagName("published")->item(0);
22
23 if ($published) {
24 return strtotime($published->nodeValue);
25 }
26
27 $date = $this->xpath->query("dc:date", $this->elem)->item(0);
28
29 if ($date) {
30 return strtotime($date->nodeValue);
31 }
32 }
33
34
35 function get_link() {
36 $links = $this->elem->getElementsByTagName("link");
37
38 foreach ($links as $link) {
39 if ($link && $link->hasAttribute("href") &&
40 (!$link->hasAttribute("rel")
41 || $link->getAttribute("rel") == "alternate"
42 || $link->getAttribute("rel") == "standout")) {
43 $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link);
44
45 return rewrite_relative_url($base, $link->getAttribute("href"));
46 }
47 }
48 }
49
50 function get_title() {
51 $title = $this->elem->getElementsByTagName("title")->item(0);
52
53 if ($title) {
54 return $title->nodeValue;
55 }
56 }
57
58 function get_content() {
59 $content = $this->elem->getElementsByTagName("content")->item(0);
60
61 if ($content) {
62 if ($content->hasAttribute('type')) {
63 if ($content->getAttribute('type') == 'xhtml') {
64 for ($i = 0; $i < $content->childNodes->length; $i++) {
65 $child = $content->childNodes->item($i);
66
67 if ($child->hasChildNodes()) {
68 return $this->doc->saveXML($child);
69 }
70 }
71 }
72 }
73
74 return $content->nodeValue;
75 }
76 }
77
78 function get_description() {
79 $content = $this->elem->getElementsByTagName("summary")->item(0);
80
81 if ($content) {
82 if ($content->hasAttribute('type')) {
83 if ($content->getAttribute('type') == 'xhtml') {
84 for ($i = 0; $i < $content->childNodes->length; $i++) {
85 $child = $content->childNodes->item($i);
86
87 if ($child->hasChildNodes()) {
88 return $this->doc->saveXML($child);
89 }
90 }
91 }
92 }
93
94 return $content->nodeValue;
95 }
96
97 }
98
99 function get_categories() {
100 $categories = $this->elem->getElementsByTagName("category");
101 $cats = array();
102
103 foreach ($categories as $cat) {
104 if ($cat->hasAttribute("term"))
105 array_push($cats, $cat->getAttribute("term"));
106 }
107
108 $categories = $this->xpath->query("dc:subject", $this->elem);
109
110 foreach ($categories as $cat) {
111 array_push($cats, $cat->nodeValue);
112 }
113
114 return $cats;
115 }
116
117 function get_enclosures() {
118 $links = $this->elem->getElementsByTagName("link");
119
120 $encs = array();
121
122 foreach ($links as $link) {
123 if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
124 if ($link->getAttribute("rel") == "enclosure") {
125 $enc = new FeedEnclosure();
126
127 $enc->type = $link->getAttribute("type");
128 $enc->link = $link->getAttribute("href");
129 $enc->length = $link->getAttribute("length");
130
131 array_push($encs, $enc);
132 }
133 }
134 }
135
136 $enclosures = $this->xpath->query("media:content", $this->elem);
137
138 foreach ($enclosures as $enclosure) {
139 $enc = new FeedEnclosure();
140
141 $enc->type = $enclosure->getAttribute("type");
142 $enc->link = $enclosure->getAttribute("url");
143 $enc->length = $enclosure->getAttribute("length");
144
145 array_push($encs, $enc);
146 }
147
148 return $encs;
149 }
150
151 }
152 ?>