]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/atom.php
add support for dc:subject and slash:comments
[tt-rss.git] / classes / feeditem / atom.php
1 <?php
2 class FeedItem_Atom {
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("id")->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 $updated = $this->elem->getElementsByTagName("updated")->item(0);
23
24 if ($updated) {
25 return strtotime($updated->nodeValue);
26 }
27 }
28
29 function get_link() {
30 $links = $this->elem->getElementsByTagName("link");
31
32 foreach ($links as $link) {
33 if ($link && $link->hasAttribute("href") && !$link->hasAttribute("rel")) {
34 return $link->getAttribute("href");
35 }
36 }
37 }
38
39 function get_title() {
40 $title = $this->elem->getElementsByTagName("title")->item(0);
41
42 if ($title) {
43 return $title->nodeValue;
44 }
45 }
46
47 function get_content() {
48 $content = $this->elem->getElementsByTagName("content")->item(0);
49
50 if ($content) {
51 return $content->nodeValue;
52 }
53 }
54
55 function get_description() {
56 $summary = $this->elem->getElementsByTagName("summary")->item(0);
57
58 if ($summary) {
59 return $summary->nodeValue;
60 }
61 }
62
63 // todo
64 function get_comments_url() {
65
66 }
67
68 function get_comments_count() {
69 $comments = $this->xpath->query("slash:comments", $this->elem)->item(0);
70
71 if ($comments) {
72 return $comments->nodeValue;
73 }
74 }
75
76 function get_categories() {
77 $categories = $this->elem->getElementsByTagName("category");
78 $cats = array();
79
80 foreach ($categories as $cat) {
81 if ($cat->hasAttribute("term"))
82 array_push($cats, $cat->getAttribute("term"));
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 $links = $this->elem->getElementsByTagName("link");
96
97 $encs = array();
98
99 foreach ($links as $link) {
100 if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
101 if ($link->getAttribute("rel") == "enclosure") {
102 $enc = new FeedEnclosure();
103
104 $enc->type = $link->getAttribute("type");
105 $enc->link = $link->getAttribute("href");
106 $enc->length = $link->getAttribute("length");
107
108 array_push($encs, $enc);
109 }
110 }
111 }
112
113 $enclosures = $this->xpath->query("media:content", $this->elem);
114
115 foreach ($enclosures as $enclosure) {
116 $enc = new FeedEnclosure();
117
118 $enc->type = $enclosure->getAttribute("type");
119 $enc->link = $enclosure->getAttribute("url");
120 $enc->length = $enclosure->getAttribute("length");
121
122 array_push($encs, $enc);
123 }
124
125 return $encs;
126 }
127
128 function get_author() {
129 $author = $this->elem->getElementsByTagName("author")->item(0);
130
131 if ($author) {
132 $name = $author->getElementsByTagName("name")->item(0);
133
134 if ($name) return $name->nodeValue;
135
136 $email = $author->getElementsByTagName("email")->item(0);
137
138 if ($email) return $email->nodeValue;
139
140 }
141 }
142 }
143 ?>