]>
Commit | Line | Data |
---|---|---|
04d2f9c8 AD |
1 | <?php |
2 | class FeedItem_RSS { | |
3 | private $elem; | |
4c00e15b | 4 | private $xpath; |
04d2f9c8 | 5 | |
4c00e15b | 6 | function __construct($elem, $doc, $xpath) { |
04d2f9c8 | 7 | $this->elem = $elem; |
4c00e15b | 8 | $this->xpath = $xpath; |
04d2f9c8 AD |
9 | } |
10 | ||
11 | function get_id() { | |
b09a4cdc AD |
12 | $id = $this->elem->getElementsByTagName("guid")->item(0); |
13 | ||
14 | if ($id) { | |
15 | return $id->nodeValue; | |
16 | } else { | |
17 | return $this->get_link(); | |
18 | } | |
04d2f9c8 AD |
19 | } |
20 | ||
21 | function get_date() { | |
22 | $pubDate = $this->elem->getElementsByTagName("pubDate")->item(0); | |
23 | ||
24 | if ($pubDate) { | |
25 | return strtotime($pubDate->nodeValue); | |
26 | } | |
27 | } | |
28 | ||
29 | function get_link() { | |
30 | $link = $this->elem->getElementsByTagName("link")->item(0); | |
31 | ||
32 | if ($link) { | |
33 | return $link->nodeValue; | |
34 | } | |
35 | } | |
36 | ||
37 | function get_title() { | |
38 | $title = $this->elem->getElementsByTagName("title")->item(0); | |
39 | ||
40 | if ($title) { | |
41 | return $title->nodeValue; | |
42 | } | |
43 | } | |
44 | ||
45 | function get_content() { | |
46 | $content = $this->elem->getElementsByTagName("description")->item(0); | |
47 | ||
48 | if ($content) { | |
49 | return $content->nodeValue; | |
50 | } | |
51 | } | |
52 | ||
53 | function get_description() { | |
54 | $summary = $this->elem->getElementsByTagName("description")->item(0); | |
55 | ||
56 | if ($summary) { | |
57 | return $summary->nodeValue; | |
58 | } | |
59 | } | |
60 | ||
61 | // todo | |
62 | function get_comments_url() { | |
63 | ||
64 | } | |
65 | ||
04d2f9c8 | 66 | function get_comments_count() { |
d4992d6b | 67 | $comments = $this->xpath->query("slash:comments", $this->elem)->item(0); |
04d2f9c8 | 68 | |
d4992d6b AD |
69 | if ($comments) { |
70 | return $comments->nodeValue; | |
71 | } | |
04d2f9c8 AD |
72 | } |
73 | ||
74 | function get_categories() { | |
75 | $categories = $this->elem->getElementsByTagName("category"); | |
76 | $cats = array(); | |
77 | ||
78 | foreach ($categories as $cat) { | |
79 | array_push($cats, $cat->nodeValue); | |
80 | } | |
81 | ||
d4992d6b AD |
82 | $categories = $this->xpath->query("dc:subject", $this->elem); |
83 | ||
84 | foreach ($categories as $cat) { | |
85 | array_push($cats, $cat->nodeValue); | |
86 | } | |
87 | ||
04d2f9c8 AD |
88 | return $cats; |
89 | } | |
90 | ||
91 | function get_enclosures() { | |
92 | $enclosures = $this->elem->getElementsByTagName("enclosure"); | |
93 | ||
94 | $encs = array(); | |
95 | ||
96 | foreach ($enclosures as $enclosure) { | |
97 | $enc = new FeedEnclosure(); | |
98 | ||
99 | $enc->type = $enclosure->getAttribute("type"); | |
100 | $enc->link = $enclosure->getAttribute("url"); | |
101 | $enc->length = $enclosure->getAttribute("length"); | |
102 | ||
103 | array_push($encs, $enc); | |
104 | } | |
105 | ||
4c00e15b AD |
106 | $enclosures = $this->xpath->query("media:content", $this->elem); |
107 | ||
4c00e15b AD |
108 | foreach ($enclosures as $enclosure) { |
109 | $enc = new FeedEnclosure(); | |
110 | ||
111 | $enc->type = $enclosure->getAttribute("type"); | |
112 | $enc->link = $enclosure->getAttribute("url"); | |
113 | $enc->length = $enclosure->getAttribute("length"); | |
114 | ||
115 | array_push($encs, $enc); | |
116 | } | |
117 | ||
04d2f9c8 AD |
118 | return $encs; |
119 | } | |
120 | ||
121 | function get_author() { | |
122 | $author = $this->elem->getElementsByTagName("author")->item(0); | |
123 | ||
124 | if ($author) { | |
125 | $name = $author->getElementsByTagName("name")->item(0); | |
126 | ||
127 | if ($name) return $name->nodeValue; | |
128 | ||
129 | $email = $author->getElementsByTagName("email")->item(0); | |
130 | ||
131 | if ($email) return $email->nodeValue; | |
f1101505 AD |
132 | } |
133 | ||
134 | $author = $this->xpath->query("dc:creator", $this->elem)->item(0); | |
04d2f9c8 | 135 | |
f1101505 AD |
136 | if ($author) { |
137 | return $author->nodeValue; | |
04d2f9c8 | 138 | } |
f1101505 | 139 | |
04d2f9c8 AD |
140 | } |
141 | } | |
142 | ?> |