]>
Commit | Line | Data |
---|---|---|
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 trim($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 trim($link->nodeValue); | |
44 | } | |
45 | ||
46 | $link = $this->elem->getElementsByTagName("link")->item(0); | |
47 | ||
48 | if ($link) { | |
49 | return trim($link->nodeValue); | |
50 | } | |
51 | } | |
52 | ||
53 | function get_title() { | |
54 | $title = $this->elem->getElementsByTagName("title")->item(0); | |
55 | ||
56 | if ($title) { | |
57 | return trim($title->nodeValue); | |
58 | } | |
59 | } | |
60 | ||
61 | function get_content() { | |
62 | $contentA = $this->xpath->query("content:encoded", $this->elem)->item(0); | |
63 | $contentB = $this->elem->getElementsByTagName("description")->item(0); | |
64 | ||
65 | if ($contentA && !$contentB) { | |
66 | return $contentA->nodeValue; | |
67 | } | |
68 | ||
69 | ||
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; | |
77 | } | |
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 | ||
88 | function get_categories() { | |
89 | $categories = $this->elem->getElementsByTagName("category"); | |
90 | $cats = array(); | |
91 | ||
92 | foreach ($categories as $cat) { | |
93 | array_push($cats, trim($cat->nodeValue)); | |
94 | } | |
95 | ||
96 | $categories = $this->xpath->query("dc:subject", $this->elem); | |
97 | ||
98 | foreach ($categories as $cat) { | |
99 | array_push($cats, trim($cat->nodeValue)); | |
100 | } | |
101 | ||
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"); | |
116 | ||
117 | array_push($encs, $enc); | |
118 | } | |
119 | ||
120 | $enclosures = $this->xpath->query("media:content", $this->elem); | |
121 | ||
122 | foreach ($enclosures as $enclosure) { | |
123 | $enc = new FeedEnclosure(); | |
124 | ||
125 | $enc->type = $enclosure->getAttribute("type"); | |
126 | $enc->link = $enclosure->getAttribute("url"); | |
127 | $enc->length = $enclosure->getAttribute("length"); | |
128 | ||
129 | $desc = $this->xpath->query("media:description", $enclosure)->item(0); | |
130 | if ($desc) $enc->title = strip_tags($desc->nodeValue); | |
131 | ||
132 | array_push($encs, $enc); | |
133 | } | |
134 | ||
135 | ||
136 | $enclosures = $this->xpath->query("media:group", $this->elem); | |
137 | ||
138 | foreach ($enclosures as $enclosure) { | |
139 | $enc = new FeedEnclosure(); | |
140 | ||
141 | $content = $this->xpath->query("media:content", $enclosure)->item(0); | |
142 | ||
143 | if ($content) { | |
144 | $enc->type = $content->getAttribute("type"); | |
145 | $enc->link = $content->getAttribute("url"); | |
146 | $enc->length = $content->getAttribute("length"); | |
147 | ||
148 | $desc = $this->xpath->query("media:description", $content)->item(0); | |
149 | if ($desc) { | |
150 | $enc->title = strip_tags($desc->nodeValue); | |
151 | } else { | |
152 | $desc = $this->xpath->query("media:description", $enclosure)->item(0); | |
153 | if ($desc) $enc->title = strip_tags($desc->nodeValue); | |
154 | } | |
155 | ||
156 | array_push($encs, $enc); | |
157 | } | |
158 | } | |
159 | ||
160 | $enclosures = $this->xpath->query("media:thumbnail", $this->elem); | |
161 | ||
162 | foreach ($enclosures as $enclosure) { | |
163 | $enc = new FeedEnclosure(); | |
164 | ||
165 | $enc->type = "image/generic"; | |
166 | $enc->link = $enclosure->getAttribute("url"); | |
167 | ||
168 | array_push($encs, $enc); | |
169 | } | |
170 | ||
171 | return $encs; | |
172 | } | |
173 | ||
174 | } | |
175 | ?> |