]>
Commit | Line | Data |
---|---|---|
cd07592c | 1 | <?php |
b4d16900 | 2 | class FeedItem_Atom extends FeedItem_Common { |
a377d5c9 | 3 | const NS_XML = "http://www.w3.org/XML/1998/namespace"; |
bfc24f37 | 4 | |
cd07592c AD |
5 | function get_id() { |
6 | $id = $this->elem->getElementsByTagName("id")->item(0); | |
7 | ||
8 | if ($id) { | |
9 | return $id->nodeValue; | |
10 | } else { | |
11 | return $this->get_link(); | |
12 | } | |
13 | } | |
14 | ||
15 | function get_date() { | |
04d2f9c8 | 16 | $updated = $this->elem->getElementsByTagName("updated")->item(0); |
cd07592c | 17 | |
04d2f9c8 AD |
18 | if ($updated) { |
19 | return strtotime($updated->nodeValue); | |
20 | } | |
ce5d234d | 21 | |
d256f1fb AD |
22 | $published = $this->elem->getElementsByTagName("published")->item(0); |
23 | ||
24 | if ($published) { | |
25 | return strtotime($published->nodeValue); | |
26 | } | |
27 | ||
ce5d234d AD |
28 | $date = $this->xpath->query("dc:date", $this->elem)->item(0); |
29 | ||
30 | if ($date) { | |
31 | return strtotime($date->nodeValue); | |
32 | } | |
cd07592c | 33 | } |
3c4dead6 AD |
34 | |
35 | ||
cd07592c AD |
36 | function get_link() { |
37 | $links = $this->elem->getElementsByTagName("link"); | |
38 | ||
39 | foreach ($links as $link) { | |
df2655e0 AD |
40 | if ($link && $link->hasAttribute("href") && |
41 | (!$link->hasAttribute("rel") | |
42 | || $link->getAttribute("rel") == "alternate" | |
43 | || $link->getAttribute("rel") == "standout")) { | |
3c4dead6 AD |
44 | $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link); |
45 | ||
491ef970 | 46 | if ($base) |
31bd6f76 | 47 | return rewrite_relative_url($base, trim($link->getAttribute("href"))); |
491ef970 | 48 | else |
31bd6f76 | 49 | return trim($link->getAttribute("href")); |
491ef970 | 50 | |
cd07592c AD |
51 | } |
52 | } | |
53 | } | |
54 | ||
55 | function get_title() { | |
56 | $title = $this->elem->getElementsByTagName("title")->item(0); | |
57 | ||
58 | if ($title) { | |
31bd6f76 | 59 | return trim($title->nodeValue); |
cd07592c AD |
60 | } |
61 | } | |
62 | ||
63 | function get_content() { | |
64 | $content = $this->elem->getElementsByTagName("content")->item(0); | |
65 | ||
66 | if ($content) { | |
27004401 AD |
67 | if ($content->hasAttribute('type')) { |
68 | if ($content->getAttribute('type') == 'xhtml') { | |
bc3c887f AD |
69 | for ($i = 0; $i < $content->childNodes->length; $i++) { |
70 | $child = $content->childNodes->item($i); | |
71 | ||
72 | if ($child->hasChildNodes()) { | |
f3774b9d | 73 | return $this->doc->saveHTML($child); |
bc3c887f AD |
74 | } |
75 | } | |
96ce71f3 AD |
76 | } |
77 | } | |
78 | ||
7d1e15c3 | 79 | return $this->subtree_or_text($content); |
cd07592c AD |
80 | } |
81 | } | |
82 | ||
83 | function get_description() { | |
27004401 AD |
84 | $content = $this->elem->getElementsByTagName("summary")->item(0); |
85 | ||
86 | if ($content) { | |
87 | if ($content->hasAttribute('type')) { | |
88 | if ($content->getAttribute('type') == 'xhtml') { | |
bc3c887f AD |
89 | for ($i = 0; $i < $content->childNodes->length; $i++) { |
90 | $child = $content->childNodes->item($i); | |
91 | ||
92 | if ($child->hasChildNodes()) { | |
f3774b9d | 93 | return $this->doc->saveHTML($child); |
bc3c887f AD |
94 | } |
95 | } | |
27004401 AD |
96 | } |
97 | } | |
cd07592c | 98 | |
7d1e15c3 | 99 | return $this->subtree_or_text($content); |
cd07592c | 100 | } |
27004401 | 101 | |
cd07592c AD |
102 | } |
103 | ||
cd07592c AD |
104 | function get_categories() { |
105 | $categories = $this->elem->getElementsByTagName("category"); | |
106 | $cats = array(); | |
107 | ||
108 | foreach ($categories as $cat) { | |
109 | if ($cat->hasAttribute("term")) | |
31bd6f76 | 110 | array_push($cats, trim($cat->getAttribute("term"))); |
cd07592c AD |
111 | } |
112 | ||
d4992d6b AD |
113 | $categories = $this->xpath->query("dc:subject", $this->elem); |
114 | ||
115 | foreach ($categories as $cat) { | |
31bd6f76 | 116 | array_push($cats, trim($cat->nodeValue)); |
d4992d6b | 117 | } |
cd07592c AD |
118 | |
119 | return $cats; | |
120 | } | |
121 | ||
122 | function get_enclosures() { | |
123 | $links = $this->elem->getElementsByTagName("link"); | |
124 | ||
125 | $encs = array(); | |
126 | ||
127 | foreach ($links as $link) { | |
128 | if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) { | |
129 | if ($link->getAttribute("rel") == "enclosure") { | |
130 | $enc = new FeedEnclosure(); | |
131 | ||
132 | $enc->type = $link->getAttribute("type"); | |
133 | $enc->link = $link->getAttribute("href"); | |
134 | $enc->length = $link->getAttribute("length"); | |
135 | ||
136 | array_push($encs, $enc); | |
137 | } | |
138 | } | |
139 | } | |
140 | ||
ed449a9a | 141 | $enclosures = $this->xpath->query("media:content", $this->elem); |
4289b68f AD |
142 | |
143 | foreach ($enclosures as $enclosure) { | |
144 | $enc = new FeedEnclosure(); | |
145 | ||
146 | $enc->type = $enclosure->getAttribute("type"); | |
147 | $enc->link = $enclosure->getAttribute("url"); | |
148 | $enc->length = $enclosure->getAttribute("length"); | |
523bd90b FE |
149 | $enc->height = $enclosure->getAttribute("height"); |
150 | $enc->width = $enclosure->getAttribute("width"); | |
4289b68f | 151 | |
5c54e683 AD |
152 | $desc = $this->xpath->query("media:description", $enclosure)->item(0); |
153 | if ($desc) $enc->title = strip_tags($desc->nodeValue); | |
154 | ||
4289b68f AD |
155 | array_push($encs, $enc); |
156 | } | |
157 | ||
ed449a9a JT |
158 | |
159 | $enclosures = $this->xpath->query("media:group", $this->elem); | |
160 | ||
161 | foreach ($enclosures as $enclosure) { | |
162 | $enc = new FeedEnclosure(); | |
163 | ||
164 | $content = $this->xpath->query("media:content", $enclosure)->item(0); | |
165 | ||
2ab7ccb6 AD |
166 | if ($content) { |
167 | $enc->type = $content->getAttribute("type"); | |
168 | $enc->link = $content->getAttribute("url"); | |
169 | $enc->length = $content->getAttribute("length"); | |
523bd90b FE |
170 | $enc->height = $content->getAttribute("height"); |
171 | $enc->width = $content->getAttribute("width"); | |
2ab7ccb6 AD |
172 | |
173 | $desc = $this->xpath->query("media:description", $content)->item(0); | |
174 | if ($desc) { | |
175 | $enc->title = strip_tags($desc->nodeValue); | |
176 | } else { | |
177 | $desc = $this->xpath->query("media:description", $enclosure)->item(0); | |
178 | if ($desc) $enc->title = strip_tags($desc->nodeValue); | |
179 | } | |
ed449a9a | 180 | |
2ab7ccb6 AD |
181 | array_push($encs, $enc); |
182 | } | |
ed449a9a JT |
183 | } |
184 | ||
e23aedd4 AD |
185 | $enclosures = $this->xpath->query("media:thumbnail", $this->elem); |
186 | ||
187 | foreach ($enclosures as $enclosure) { | |
188 | $enc = new FeedEnclosure(); | |
189 | ||
190 | $enc->type = "image/generic"; | |
191 | $enc->link = $enclosure->getAttribute("url"); | |
523bd90b FE |
192 | $enc->height = $enclosure->getAttribute("height"); |
193 | $enc->width = $enclosure->getAttribute("width"); | |
e23aedd4 AD |
194 | |
195 | array_push($encs, $enc); | |
196 | } | |
197 | ||
cd07592c AD |
198 | return $encs; |
199 | } | |
200 | ||
22a866ed | 201 | function get_language() { |
a377d5c9 | 202 | $lang = $this->elem->getAttributeNS(self::NS_XML, "lang"); |
22a866ed | 203 | |
a377d5c9 TK |
204 | if (!empty($lang)) { |
205 | return $lang; | |
206 | } else { | |
207 | // Fall back to the language declared on the feed, if any. | |
208 | return $this->doc->firstChild->getAttributeNS(self::NS_XML, "lang"); | |
209 | } | |
22a866ed | 210 | } |
f3774b9d | 211 | } |