]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/atom.php
Store size of enclosure to database
[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 $enc->height = $enclosure->getAttribute("height");
149 $enc->width = $enclosure->getAttribute("width");
150
151 $desc = $this->xpath->query("media:description", $enclosure)->item(0);
152 if ($desc) $enc->title = strip_tags($desc->nodeValue);
153
154 array_push($encs, $enc);
155 }
156
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
165 if ($content) {
166 $enc->type = $content->getAttribute("type");
167 $enc->link = $content->getAttribute("url");
168 $enc->length = $content->getAttribute("length");
169 $enc->height = $content->getAttribute("height");
170 $enc->width = $content->getAttribute("width");
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 }
179
180 array_push($encs, $enc);
181 }
182 }
183
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");
191 $enc->height = $enclosure->getAttribute("height");
192 $enc->width = $enclosure->getAttribute("width");
193
194 array_push($encs, $enc);
195 }
196
197 return $encs;
198 }
199
200 }
201 ?>