]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/atom.php
48e3aa567173e7067f89d88002a7d429a3e37034
[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 if ($base)
46 return rewrite_relative_url($base, trim($link->getAttribute("href")));
47 else
48 return trim($link->getAttribute("href"));
49
50 }
51 }
52 }
53
54 function get_title() {
55 $title = $this->elem->getElementsByTagName("title")->item(0);
56
57 if ($title) {
58 return trim($title->nodeValue);
59 }
60 }
61
62 function get_content() {
63 $content = $this->elem->getElementsByTagName("content")->item(0);
64
65 if ($content) {
66 if ($content->hasAttribute('type')) {
67 if ($content->getAttribute('type') == 'xhtml') {
68 for ($i = 0; $i < $content->childNodes->length; $i++) {
69 $child = $content->childNodes->item($i);
70
71 if ($child->hasChildNodes()) {
72 return $this->doc->saveXML($child);
73 }
74 }
75 }
76 }
77
78 return $content->nodeValue;
79 }
80 }
81
82 function get_description() {
83 $content = $this->elem->getElementsByTagName("summary")->item(0);
84
85 if ($content) {
86 if ($content->hasAttribute('type')) {
87 if ($content->getAttribute('type') == 'xhtml') {
88 for ($i = 0; $i < $content->childNodes->length; $i++) {
89 $child = $content->childNodes->item($i);
90
91 if ($child->hasChildNodes()) {
92 return $this->doc->saveXML($child);
93 }
94 }
95 }
96 }
97
98 return $content->nodeValue;
99 }
100
101 }
102
103 function get_categories() {
104 $categories = $this->elem->getElementsByTagName("category");
105 $cats = array();
106
107 foreach ($categories as $cat) {
108 if ($cat->hasAttribute("term"))
109 array_push($cats, trim($cat->getAttribute("term")));
110 }
111
112 $categories = $this->xpath->query("dc:subject", $this->elem);
113
114 foreach ($categories as $cat) {
115 array_push($cats, trim($cat->nodeValue));
116 }
117
118 return $cats;
119 }
120
121 function get_enclosures() {
122 $links = $this->elem->getElementsByTagName("link");
123
124 $encs = array();
125
126 foreach ($links as $link) {
127 if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
128 if ($link->getAttribute("rel") == "enclosure") {
129 $enc = new FeedEnclosure();
130
131 $enc->type = $link->getAttribute("type");
132 $enc->link = $link->getAttribute("href");
133 $enc->length = $link->getAttribute("length");
134
135 array_push($encs, $enc);
136 }
137 }
138 }
139
140 $enclosures = $this->xpath->query("media:content", $this->elem);
141
142 foreach ($enclosures as $enclosure) {
143 $enc = new FeedEnclosure();
144
145 $enc->type = $enclosure->getAttribute("type");
146 $enc->link = $enclosure->getAttribute("url");
147 $enc->length = $enclosure->getAttribute("length");
148
149 $desc = $this->xpath->query("media:description", $enclosure)->item(0);
150 if ($desc) $enc->title = strip_tags($desc->nodeValue);
151
152 array_push($encs, $enc);
153 }
154
155
156 $enclosures = $this->xpath->query("media:group", $this->elem);
157
158 foreach ($enclosures as $enclosure) {
159 $enc = new FeedEnclosure();
160
161 $content = $this->xpath->query("media:content", $enclosure)->item(0);
162
163 if ($content) {
164 $enc->type = $content->getAttribute("type");
165 $enc->link = $content->getAttribute("url");
166 $enc->length = $content->getAttribute("length");
167
168 $desc = $this->xpath->query("media:description", $content)->item(0);
169 if ($desc) {
170 $enc->title = strip_tags($desc->nodeValue);
171 } else {
172 $desc = $this->xpath->query("media:description", $enclosure)->item(0);
173 if ($desc) $enc->title = strip_tags($desc->nodeValue);
174 }
175
176 array_push($encs, $enc);
177 }
178 }
179
180 $enclosures = $this->xpath->query("media:thumbnail", $this->elem);
181
182 foreach ($enclosures as $enclosure) {
183 $enc = new FeedEnclosure();
184
185 $enc->type = "image/generic";
186 $enc->link = $enclosure->getAttribute("url");
187
188 array_push($encs, $enc);
189 }
190
191 return $encs;
192 }
193
194 }
195 ?>