]> git.wh0rd.org - tt-rss.git/blame - classes/feeditem/rss.php
Store size of enclosure to database
[tt-rss.git] / classes / feeditem / rss.php
CommitLineData
04d2f9c8 1<?php
b4d16900 2class FeedItem_RSS extends FeedItem_Common {
04d2f9c8 3 function get_id() {
b09a4cdc
AD
4 $id = $this->elem->getElementsByTagName("guid")->item(0);
5
6 if ($id) {
7 return $id->nodeValue;
8 } else {
9 return $this->get_link();
10 }
04d2f9c8
AD
11 }
12
13 function get_date() {
14 $pubDate = $this->elem->getElementsByTagName("pubDate")->item(0);
15
16 if ($pubDate) {
17 return strtotime($pubDate->nodeValue);
18 }
ce5d234d
AD
19
20 $date = $this->xpath->query("dc:date", $this->elem)->item(0);
21
22 if ($date) {
23 return strtotime($date->nodeValue);
24 }
04d2f9c8
AD
25 }
26
27 function get_link() {
df2655e0 28 $links = $this->xpath->query("atom:link", $this->elem);
04d2f9c8 29
df2655e0
AD
30 foreach ($links as $link) {
31 if ($link && $link->hasAttribute("href") &&
32 (!$link->hasAttribute("rel")
33 || $link->getAttribute("rel") == "alternate"
34 || $link->getAttribute("rel") == "standout")) {
35
31bd6f76 36 return trim($link->getAttribute("href"));
df2655e0 37 }
04d2f9c8 38 }
f7d64d03 39
042003d5
AD
40 $link = $this->elem->getElementsByTagName("guid")->item(0);
41
42 if ($link && $link->hasAttributes() && $link->getAttribute("isPermaLink") == "true") {
31bd6f76 43 return trim($link->nodeValue);
042003d5
AD
44 }
45
2f6b75d5 46 $link = $this->elem->getElementsByTagName("link")->item(0);
f7d64d03
AD
47
48 if ($link) {
31bd6f76 49 return trim($link->nodeValue);
f7d64d03 50 }
04d2f9c8
AD
51 }
52
53 function get_title() {
54 $title = $this->elem->getElementsByTagName("title")->item(0);
55
56 if ($title) {
31bd6f76 57 return trim($title->nodeValue);
04d2f9c8
AD
58 }
59 }
60
61 function get_content() {
f6c61b2d
AD
62 $contentA = $this->xpath->query("content:encoded", $this->elem)->item(0);
63 $contentB = $this->elem->getElementsByTagName("description")->item(0);
04d2f9c8 64
f6c61b2d
AD
65 if ($contentA && !$contentB) {
66 return $contentA->nodeValue;
04d2f9c8 67 }
8a95d630 68
8a95d630 69
f6c61b2d
AD
70 if ($contentB && !$contentA) {
71 return $contentB->nodeValue;
72 }
73
74 if ($contentA && $contentB) {
75 return mb_strlen($contentA->nodeValue) > mb_strlen($contentB->nodeValue) ?
76 $contentA->nodeValue : $contentB->nodeValue;
8a95d630 77 }
04d2f9c8
AD
78 }
79
80 function get_description() {
81 $summary = $this->elem->getElementsByTagName("description")->item(0);
82
83 if ($summary) {
84 return $summary->nodeValue;
85 }
86 }
87
04d2f9c8
AD
88 function get_categories() {
89 $categories = $this->elem->getElementsByTagName("category");
90 $cats = array();
91
92 foreach ($categories as $cat) {
31bd6f76 93 array_push($cats, trim($cat->nodeValue));
04d2f9c8
AD
94 }
95
d4992d6b
AD
96 $categories = $this->xpath->query("dc:subject", $this->elem);
97
98 foreach ($categories as $cat) {
31bd6f76 99 array_push($cats, trim($cat->nodeValue));
d4992d6b
AD
100 }
101
04d2f9c8
AD
102 return $cats;
103 }
104
105 function get_enclosures() {
106 $enclosures = $this->elem->getElementsByTagName("enclosure");
107
108 $encs = array();
109
110 foreach ($enclosures as $enclosure) {
111 $enc = new FeedEnclosure();
112
113 $enc->type = $enclosure->getAttribute("type");
114 $enc->link = $enclosure->getAttribute("url");
115 $enc->length = $enclosure->getAttribute("length");
523bd90b
FE
116 $enc->height = $enclosure->getAttribute("height");
117 $enc->width = $enclosure->getAttribute("width");
04d2f9c8
AD
118
119 array_push($encs, $enc);
120 }
121
ed449a9a 122 $enclosures = $this->xpath->query("media:content", $this->elem);
4289b68f
AD
123
124 foreach ($enclosures as $enclosure) {
125 $enc = new FeedEnclosure();
126
127 $enc->type = $enclosure->getAttribute("type");
128 $enc->link = $enclosure->getAttribute("url");
129 $enc->length = $enclosure->getAttribute("length");
523bd90b
FE
130 $enc->height = $enclosure->getAttribute("height");
131 $enc->width = $enclosure->getAttribute("width");
4289b68f 132
5c54e683
AD
133 $desc = $this->xpath->query("media:description", $enclosure)->item(0);
134 if ($desc) $enc->title = strip_tags($desc->nodeValue);
135
4289b68f
AD
136 array_push($encs, $enc);
137 }
138
ed449a9a
JT
139
140 $enclosures = $this->xpath->query("media:group", $this->elem);
141
142 foreach ($enclosures as $enclosure) {
143 $enc = new FeedEnclosure();
144
145 $content = $this->xpath->query("media:content", $enclosure)->item(0);
146
2ab7ccb6
AD
147 if ($content) {
148 $enc->type = $content->getAttribute("type");
149 $enc->link = $content->getAttribute("url");
150 $enc->length = $content->getAttribute("length");
523bd90b
FE
151 $enc->height = $content->getAttribute("height");
152 $enc->width = $content->getAttribute("width");
2ab7ccb6
AD
153
154 $desc = $this->xpath->query("media:description", $content)->item(0);
155 if ($desc) {
156 $enc->title = strip_tags($desc->nodeValue);
157 } else {
158 $desc = $this->xpath->query("media:description", $enclosure)->item(0);
159 if ($desc) $enc->title = strip_tags($desc->nodeValue);
160 }
161
162 array_push($encs, $enc);
ed449a9a 163 }
ed449a9a
JT
164 }
165
e23aedd4
AD
166 $enclosures = $this->xpath->query("media:thumbnail", $this->elem);
167
168 foreach ($enclosures as $enclosure) {
169 $enc = new FeedEnclosure();
170
171 $enc->type = "image/generic";
172 $enc->link = $enclosure->getAttribute("url");
523bd90b
FE
173 $enc->height = $enclosure->getAttribute("height");
174 $enc->width = $enclosure->getAttribute("width");
e23aedd4
AD
175
176 array_push($encs, $enc);
177 }
178
04d2f9c8
AD
179 return $encs;
180 }
181
04d2f9c8
AD
182}
183?>