]>
git.wh0rd.org - tt-rss.git/blob - classes/feeditem/rss.php
95f3acdebb5dbb2df9aba9837139bb2ffe2b6f38
2 class FeedItem_RSS
extends FeedItem_Common
{
4 $id = $this->elem
->getElementsByTagName("guid")->item(0);
9 return $this->get_link();
14 $pubDate = $this->elem
->getElementsByTagName("pubDate")->item(0);
17 return strtotime($pubDate->nodeValue
);
20 $date = $this->xpath
->query("dc:date", $this->elem
)->item(0);
23 return strtotime($date->nodeValue
);
28 $links = $this->xpath
->query("atom:link", $this->elem
);
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")) {
36 return trim($link->getAttribute("href"));
40 $link = $this->elem
->getElementsByTagName("guid")->item(0);
42 if ($link && $link->hasAttributes() && $link->getAttribute("isPermaLink") == "true") {
43 return trim($link->nodeValue
);
46 $link = $this->elem
->getElementsByTagName("link")->item(0);
49 return trim($link->nodeValue
);
53 function get_title() {
54 $title = $this->xpath
->query("title", $this->elem
)->item(0);
57 return trim($title->nodeValue
);
60 // if the document has a default namespace then querying for
61 // title would fail because of reasons so let's try the old way
62 $title = $this->elem
->getElementsByTagName("title")->item(0);
65 return trim($title->nodeValue
);
69 function get_content() {
70 $contentA = $this->xpath
->query("content:encoded", $this->elem
)->item(0);
71 $contentB = $this->elem
->getElementsByTagName("description")->item(0);
73 if ($contentA && !$contentB) {
74 return $contentA->c14n();
77 if ($contentB && !$contentA) {
78 return $contentB->c14n();
81 if ($contentA && $contentB) {
82 return mb_strlen($contentA->nodeValue
) > mb_strlen($contentB->nodeValue
) ?
83 $contentA->c14n() : $contentB->c14n();
87 function get_description() {
88 $summary = $this->elem
->getElementsByTagName("description")->item(0);
91 return $summary->c14n();
95 function get_categories() {
96 $categories = $this->elem
->getElementsByTagName("category");
99 foreach ($categories as $cat) {
100 array_push($cats, trim($cat->nodeValue
));
103 $categories = $this->xpath
->query("dc:subject", $this->elem
);
105 foreach ($categories as $cat) {
106 array_push($cats, trim($cat->nodeValue
));
112 function get_enclosures() {
113 $enclosures = $this->elem
->getElementsByTagName("enclosure");
117 foreach ($enclosures as $enclosure) {
118 $enc = new FeedEnclosure();
120 $enc->type
= $enclosure->getAttribute("type");
121 $enc->link
= $enclosure->getAttribute("url");
122 $enc->length
= $enclosure->getAttribute("length");
123 $enc->height
= $enclosure->getAttribute("height");
124 $enc->width
= $enclosure->getAttribute("width");
126 array_push($encs, $enc);
129 $enclosures = $this->xpath
->query("media:content", $this->elem
);
131 foreach ($enclosures as $enclosure) {
132 $enc = new FeedEnclosure();
134 $enc->type
= $enclosure->getAttribute("type");
135 $enc->link
= $enclosure->getAttribute("url");
136 $enc->length
= $enclosure->getAttribute("length");
137 $enc->height
= $enclosure->getAttribute("height");
138 $enc->width
= $enclosure->getAttribute("width");
140 $desc = $this->xpath
->query("media:description", $enclosure)->item(0);
141 if ($desc) $enc->title
= strip_tags($desc->nodeValue
);
143 array_push($encs, $enc);
147 $enclosures = $this->xpath
->query("media:group", $this->elem
);
149 foreach ($enclosures as $enclosure) {
150 $enc = new FeedEnclosure();
152 $content = $this->xpath
->query("media:content", $enclosure)->item(0);
155 $enc->type
= $content->getAttribute("type");
156 $enc->link
= $content->getAttribute("url");
157 $enc->length
= $content->getAttribute("length");
158 $enc->height
= $content->getAttribute("height");
159 $enc->width
= $content->getAttribute("width");
161 $desc = $this->xpath
->query("media:description", $content)->item(0);
163 $enc->title
= strip_tags($desc->nodeValue
);
165 $desc = $this->xpath
->query("media:description", $enclosure)->item(0);
166 if ($desc) $enc->title
= strip_tags($desc->nodeValue
);
169 array_push($encs, $enc);
173 $enclosures = $this->xpath
->query("media:thumbnail", $this->elem
);
175 foreach ($enclosures as $enclosure) {
176 $enc = new FeedEnclosure();
178 $enc->type
= "image/generic";
179 $enc->link
= $enclosure->getAttribute("url");
180 $enc->height
= $enclosure->getAttribute("height");
181 $enc->width
= $enclosure->getAttribute("width");
183 array_push($encs, $enc);