]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/rss.php
pass xpath object to feeditem, support media-rss objects
[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 // todo
67 function get_comments_count() {
68
69 }
70
71 function get_categories() {
72 $categories = $this->elem->getElementsByTagName("category");
73 $cats = array();
74
75 foreach ($categories as $cat) {
76 array_push($cats, $cat->nodeValue);
77 }
78
79 return $cats;
80 }
81
82 function get_enclosures() {
83 $enclosures = $this->elem->getElementsByTagName("enclosure");
84
85 $encs = array();
86
87 foreach ($enclosures as $enclosure) {
88 $enc = new FeedEnclosure();
89
90 $enc->type = $enclosure->getAttribute("type");
91 $enc->link = $enclosure->getAttribute("url");
92 $enc->length = $enclosure->getAttribute("length");
93
94 array_push($encs, $enc);
95 }
96
97 $enclosures = $this->xpath->query("media:content", $this->elem);
98
99 $encs = array();
100
101 foreach ($enclosures as $enclosure) {
102 $enc = new FeedEnclosure();
103
104 $enc->type = $enclosure->getAttribute("type");
105 $enc->link = $enclosure->getAttribute("url");
106 $enc->length = $enclosure->getAttribute("length");
107
108 array_push($encs, $enc);
109 }
110
111 return $encs;
112 }
113
114 function get_author() {
115 $author = $this->elem->getElementsByTagName("author")->item(0);
116
117 if ($author) {
118 $name = $author->getElementsByTagName("name")->item(0);
119
120 if ($name) return $name->nodeValue;
121
122 $email = $author->getElementsByTagName("email")->item(0);
123
124 if ($email) return $email->nodeValue;
125
126 }
127 }
128 }
129 ?>