]>
Commit | Line | Data |
---|---|---|
cd07592c | 1 | <?php |
b4d16900 | 2 | class FeedItem_Atom extends FeedItem_Common { |
bfc24f37 | 3 | |
cd07592c AD |
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() { | |
04d2f9c8 | 15 | $updated = $this->elem->getElementsByTagName("updated")->item(0); |
cd07592c | 16 | |
04d2f9c8 AD |
17 | if ($updated) { |
18 | return strtotime($updated->nodeValue); | |
19 | } | |
ce5d234d | 20 | |
d256f1fb AD |
21 | $published = $this->elem->getElementsByTagName("published")->item(0); |
22 | ||
23 | if ($published) { | |
24 | return strtotime($published->nodeValue); | |
25 | } | |
26 | ||
ce5d234d AD |
27 | $date = $this->xpath->query("dc:date", $this->elem)->item(0); |
28 | ||
29 | if ($date) { | |
30 | return strtotime($date->nodeValue); | |
31 | } | |
cd07592c | 32 | } |
3c4dead6 AD |
33 | |
34 | ||
cd07592c AD |
35 | function get_link() { |
36 | $links = $this->elem->getElementsByTagName("link"); | |
37 | ||
38 | foreach ($links as $link) { | |
df2655e0 AD |
39 | if ($link && $link->hasAttribute("href") && |
40 | (!$link->hasAttribute("rel") | |
41 | || $link->getAttribute("rel") == "alternate" | |
42 | || $link->getAttribute("rel") == "standout")) { | |
3c4dead6 AD |
43 | $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link); |
44 | ||
491ef970 | 45 | if ($base) |
31bd6f76 | 46 | return rewrite_relative_url($base, trim($link->getAttribute("href"))); |
491ef970 | 47 | else |
31bd6f76 | 48 | return trim($link->getAttribute("href")); |
491ef970 | 49 | |
cd07592c AD |
50 | } |
51 | } | |
52 | } | |
53 | ||
54 | function get_title() { | |
55 | $title = $this->elem->getElementsByTagName("title")->item(0); | |
56 | ||
57 | if ($title) { | |
31bd6f76 | 58 | return trim($title->nodeValue); |
cd07592c AD |
59 | } |
60 | } | |
61 | ||
62 | function get_content() { | |
63 | $content = $this->elem->getElementsByTagName("content")->item(0); | |
64 | ||
65 | if ($content) { | |
27004401 AD |
66 | if ($content->hasAttribute('type')) { |
67 | if ($content->getAttribute('type') == 'xhtml') { | |
bc3c887f AD |
68 | for ($i = 0; $i < $content->childNodes->length; $i++) { |
69 | $child = $content->childNodes->item($i); | |
70 | ||
71 | if ($child->hasChildNodes()) { | |
f3774b9d | 72 | return $this->doc->saveHTML($child); |
bc3c887f AD |
73 | } |
74 | } | |
96ce71f3 AD |
75 | } |
76 | } | |
77 | ||
7d1e15c3 | 78 | return $this->subtree_or_text($content); |
cd07592c AD |
79 | } |
80 | } | |
81 | ||
82 | function get_description() { | |
27004401 AD |
83 | $content = $this->elem->getElementsByTagName("summary")->item(0); |
84 | ||
85 | if ($content) { | |
86 | if ($content->hasAttribute('type')) { | |
87 | if ($content->getAttribute('type') == 'xhtml') { | |
bc3c887f AD |
88 | for ($i = 0; $i < $content->childNodes->length; $i++) { |
89 | $child = $content->childNodes->item($i); | |
90 | ||
91 | if ($child->hasChildNodes()) { | |
f3774b9d | 92 | return $this->doc->saveHTML($child); |
bc3c887f AD |
93 | } |
94 | } | |
27004401 AD |
95 | } |
96 | } | |
cd07592c | 97 | |
7d1e15c3 | 98 | return $this->subtree_or_text($content); |
cd07592c | 99 | } |
27004401 | 100 | |
cd07592c AD |
101 | } |
102 | ||
cd07592c AD |
103 | function get_categories() { |
104 | $categories = $this->elem->getElementsByTagName("category"); | |
105 | $cats = array(); | |
106 | ||
107 | foreach ($categories as $cat) { | |
108 | if ($cat->hasAttribute("term")) | |
31bd6f76 | 109 | array_push($cats, trim($cat->getAttribute("term"))); |
cd07592c AD |
110 | } |
111 | ||
d4992d6b AD |
112 | $categories = $this->xpath->query("dc:subject", $this->elem); |
113 | ||
114 | foreach ($categories as $cat) { | |
31bd6f76 | 115 | array_push($cats, trim($cat->nodeValue)); |
d4992d6b | 116 | } |
cd07592c AD |
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 | ||
ed449a9a | 140 | $enclosures = $this->xpath->query("media:content", $this->elem); |
4289b68f AD |
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"); | |
523bd90b FE |
148 | $enc->height = $enclosure->getAttribute("height"); |
149 | $enc->width = $enclosure->getAttribute("width"); | |
4289b68f | 150 | |
5c54e683 AD |
151 | $desc = $this->xpath->query("media:description", $enclosure)->item(0); |
152 | if ($desc) $enc->title = strip_tags($desc->nodeValue); | |
153 | ||
4289b68f AD |
154 | array_push($encs, $enc); |
155 | } | |
156 | ||
ed449a9a JT |
157 | |
158 | $enclosures = $this->xpath->query("media:group", $this->elem); | |
159 | ||
160 | foreach ($enclosures as $enclosure) { | |
161 | $enc = new FeedEnclosure(); | |
162 | ||
163 | $content = $this->xpath->query("media:content", $enclosure)->item(0); | |
164 | ||
2ab7ccb6 AD |
165 | if ($content) { |
166 | $enc->type = $content->getAttribute("type"); | |
167 | $enc->link = $content->getAttribute("url"); | |
168 | $enc->length = $content->getAttribute("length"); | |
523bd90b FE |
169 | $enc->height = $content->getAttribute("height"); |
170 | $enc->width = $content->getAttribute("width"); | |
2ab7ccb6 AD |
171 | |
172 | $desc = $this->xpath->query("media:description", $content)->item(0); | |
173 | if ($desc) { | |
174 | $enc->title = strip_tags($desc->nodeValue); | |
175 | } else { | |
176 | $desc = $this->xpath->query("media:description", $enclosure)->item(0); | |
177 | if ($desc) $enc->title = strip_tags($desc->nodeValue); | |
178 | } | |
ed449a9a | 179 | |
2ab7ccb6 AD |
180 | array_push($encs, $enc); |
181 | } | |
ed449a9a JT |
182 | } |
183 | ||
e23aedd4 AD |
184 | $enclosures = $this->xpath->query("media:thumbnail", $this->elem); |
185 | ||
186 | foreach ($enclosures as $enclosure) { | |
187 | $enc = new FeedEnclosure(); | |
188 | ||
189 | $enc->type = "image/generic"; | |
190 | $enc->link = $enclosure->getAttribute("url"); | |
523bd90b FE |
191 | $enc->height = $enclosure->getAttribute("height"); |
192 | $enc->width = $enclosure->getAttribute("width"); | |
e23aedd4 AD |
193 | |
194 | array_push($encs, $enc); | |
195 | } | |
196 | ||
cd07592c AD |
197 | return $encs; |
198 | } | |
199 | ||
f3774b9d | 200 | } |