]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/rss.php
add support for dc:subject and slash:comments
[tt-rss.git] / classes / feeditem / rss.php
1 <?php
2 class FeedItem_RSS {
3 private $elem;
4 private $xpath;
5
6 function __construct($elem, $doc, $xpath) {
7 $this->elem = $elem;
8 $this->xpath = $xpath;
9 }
10
11 function get_id() {
12 $id = $this->elem->getElementsByTagName("guid")->item(0);
13
14 if ($id) {
15 return $id->nodeValue;
16 } else {
17 return $this->get_link();
18 }
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
66 function get_comments_count() {
67 $comments = $this->xpath->query("slash:comments", $this->elem)->item(0);
68
69 if ($comments) {
70 return $comments->nodeValue;
71 }
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
82 $categories = $this->xpath->query("dc:subject", $this->elem);
83
84 foreach ($categories as $cat) {
85 array_push($cats, $cat->nodeValue);
86 }
87
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
106 $enclosures = $this->xpath->query("media:content", $this->elem);
107
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
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;
132
133 }
134 }
135 }
136 ?>