]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/rss.php
Merge pull request #211 from PerryWerneck/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
21 function get_link() {
22 $links = $this->xpath->query("atom:link", $this->elem);
23
24 foreach ($links as $link) {
25 if ($link && $link->hasAttribute("href") &&
26 (!$link->hasAttribute("rel")
27 || $link->getAttribute("rel") == "alternate"
28 || $link->getAttribute("rel") == "standout")) {
29
30 return $link->getAttribute("href");
31 }
32 }
33
34 $link = $this->elem->getElementsByTagName("guid")->item(0);
35
36 if ($link && $link->hasAttributes() && $link->getAttribute("isPermaLink") == "true") {
37 return $link->nodeValue;
38 }
39
40 $link = $this->elem->getElementsByTagName("link")->item(0);
41
42 if ($link) {
43 return $link->nodeValue;
44 }
45 }
46
47 function get_title() {
48 $title = $this->elem->getElementsByTagName("title")->item(0);
49
50 if ($title) {
51 return $title->nodeValue;
52 }
53 }
54
55 function get_content() {
56 $content = $this->xpath->query("content:encoded", $this->elem)->item(0);
57
58 if ($content) {
59 return $content->nodeValue;
60 }
61
62 $content = $this->elem->getElementsByTagName("description")->item(0);
63
64 if ($content) {
65 return $content->nodeValue;
66 }
67 }
68
69 function get_description() {
70 $summary = $this->elem->getElementsByTagName("description")->item(0);
71
72 if ($summary) {
73 return $summary->nodeValue;
74 }
75 }
76
77 function get_categories() {
78 $categories = $this->elem->getElementsByTagName("category");
79 $cats = array();
80
81 foreach ($categories as $cat) {
82 array_push($cats, $cat->nodeValue);
83 }
84
85 $categories = $this->xpath->query("dc:subject", $this->elem);
86
87 foreach ($categories as $cat) {
88 array_push($cats, $cat->nodeValue);
89 }
90
91 return $cats;
92 }
93
94 function get_enclosures() {
95 $enclosures = $this->elem->getElementsByTagName("enclosure");
96
97 $encs = array();
98
99 foreach ($enclosures as $enclosure) {
100 $enc = new FeedEnclosure();
101
102 $enc->type = $enclosure->getAttribute("type");
103 $enc->link = $enclosure->getAttribute("url");
104 $enc->length = $enclosure->getAttribute("length");
105
106 array_push($encs, $enc);
107 }
108
109 $enclosures = $this->xpath->query("media:content", $this->elem);
110
111 foreach ($enclosures as $enclosure) {
112 $enc = new FeedEnclosure();
113
114 $enc->type = $enclosure->getAttribute("type");
115 $enc->link = $enclosure->getAttribute("url");
116 $enc->length = $enclosure->getAttribute("length");
117
118 array_push($encs, $enc);
119 }
120
121 return $encs;
122 }
123
124 }
125 ?>