]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/rss.php
Merge pull request #334 from Menti/master
[tt-rss.git] / classes / feeditem / rss.php
1 <?php
2 class FeedItem_RSS extends FeedItem_Common {
3 function get_id() {
4 $id = $this->elem->getElementsByTagName("guid")->item(0);
5
6 if ($id) {
7 return $id->nodeValue;
8 } else {
9 return $this->get_link();
10 }
11 }
12
13 function get_date() {
14 $pubDate = $this->elem->getElementsByTagName("pubDate")->item(0);
15
16 if ($pubDate) {
17 return strtotime($pubDate->nodeValue);
18 }
19
20 $date = $this->xpath->query("dc:date", $this->elem)->item(0);
21
22 if ($date) {
23 return strtotime($date->nodeValue);
24 }
25 }
26
27 function get_link() {
28 $links = $this->xpath->query("atom:link", $this->elem);
29
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
36 return $link->getAttribute("href");
37 }
38 }
39
40 $link = $this->elem->getElementsByTagName("guid")->item(0);
41
42 if ($link && $link->hasAttributes() && $link->getAttribute("isPermaLink") == "true") {
43 return $link->nodeValue;
44 }
45
46 $link = $this->elem->getElementsByTagName("link")->item(0);
47
48 if ($link) {
49 return $link->nodeValue;
50 }
51 }
52
53 function get_title() {
54 $title = $this->elem->getElementsByTagName("title")->item(0);
55
56 if ($title) {
57 return $title->nodeValue;
58 }
59 }
60
61 function get_content() {
62 $content = $this->xpath->query("content:encoded", $this->elem)->item(0);
63
64 if ($content) {
65 return $content->nodeValue;
66 }
67
68 $content = $this->elem->getElementsByTagName("description")->item(0);
69
70 if ($content) {
71 return $content->nodeValue;
72 }
73 }
74
75 function get_description() {
76 $summary = $this->elem->getElementsByTagName("description")->item(0);
77
78 if ($summary) {
79 return $summary->nodeValue;
80 }
81 }
82
83 function get_categories() {
84 $categories = $this->elem->getElementsByTagName("category");
85 $cats = array();
86
87 foreach ($categories as $cat) {
88 array_push($cats, $cat->nodeValue);
89 }
90
91 $categories = $this->xpath->query("dc:subject", $this->elem);
92
93 foreach ($categories as $cat) {
94 array_push($cats, $cat->nodeValue);
95 }
96
97 return $cats;
98 }
99
100 function get_enclosures() {
101 $enclosures = $this->elem->getElementsByTagName("enclosure");
102
103 $encs = array();
104
105 foreach ($enclosures as $enclosure) {
106 $enc = new FeedEnclosure();
107
108 $enc->type = $enclosure->getAttribute("type");
109 $enc->link = $enclosure->getAttribute("url");
110 $enc->length = $enclosure->getAttribute("length");
111
112 array_push($encs, $enc);
113 }
114
115 $enclosures = $this->xpath->query("media:content", $this->elem);
116
117 foreach ($enclosures as $enclosure) {
118 $enc = new FeedEnclosure();
119
120 $enc->type = $enclosure->getAttribute("type");
121 $enc->link = $enclosure->getAttribute("url");
122 $enc->length = $enclosure->getAttribute("length");
123
124 $desc = $this->xpath->query("media:description", $enclosure)->item(0);
125 if ($desc) $enc->title = strip_tags($desc->nodeValue);
126
127 array_push($encs, $enc);
128 }
129
130
131 $enclosures = $this->xpath->query("media:group", $this->elem);
132
133 foreach ($enclosures as $enclosure) {
134 $enc = new FeedEnclosure();
135
136 $content = $this->xpath->query("media:content", $enclosure)->item(0);
137
138 $enc->type = $content->getAttribute("type");
139 $enc->link = $content->getAttribute("url");
140 $enc->length = $content->getAttribute("length");
141
142 $desc = $this->xpath->query("media:description", $content)->item(0);
143 if ($desc) {
144 $enc->title = strip_tags($desc->nodeValue);
145 } else {
146 $desc = $this->xpath->query("media:description", $enclosure)->item(0);
147 if ($desc) $enc->title = strip_tags($desc->nodeValue);
148 }
149
150 array_push($encs, $enc);
151 }
152
153 $enclosures = $this->xpath->query("media:thumbnail", $this->elem);
154
155 foreach ($enclosures as $enclosure) {
156 $enc = new FeedEnclosure();
157
158 $enc->type = "image/generic";
159 $enc->link = $enclosure->getAttribute("url");
160
161 array_push($encs, $enc);
162 }
163
164 return $encs;
165 }
166
167 }
168 ?>