]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/atom.php
add basic rss support
[tt-rss.git] / classes / feeditem / atom.php
1 <?php
2 class FeedItem_Atom {
3 private $elem;
4
5 function __construct($elem) {
6 $this->elem = $elem;
7 }
8
9 function get_id() {
10 $id = $this->elem->getElementsByTagName("id")->item(0);
11
12 if ($id) {
13 return $id->nodeValue;
14 } else {
15 return $this->get_link();
16 }
17 }
18
19 function get_date() {
20 $updated = $this->elem->getElementsByTagName("updated")->item(0);
21
22 if ($updated) {
23 return strtotime($updated->nodeValue);
24 }
25 }
26
27 function get_link() {
28 $links = $this->elem->getElementsByTagName("link");
29
30 foreach ($links as $link) {
31 if ($link && $link->hasAttribute("href") && !$link->hasAttribute("rel")) {
32 return $link->getAttribute("href");
33 }
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("content")->item(0);
47
48 if ($content) {
49 return $content->nodeValue;
50 }
51 }
52
53 function get_description() {
54 $summary = $this->elem->getElementsByTagName("summary")->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 if ($cat->hasAttribute("term"))
77 array_push($cats, $cat->getAttribute("term"));
78 }
79
80
81 return $cats;
82 }
83
84 function get_enclosures() {
85 $links = $this->elem->getElementsByTagName("link");
86
87 $encs = array();
88
89 foreach ($links as $link) {
90 if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
91 if ($link->getAttribute("rel") == "enclosure") {
92 $enc = new FeedEnclosure();
93
94 $enc->type = $link->getAttribute("type");
95 $enc->link = $link->getAttribute("href");
96 $enc->length = $link->getAttribute("length");
97
98 array_push($encs, $enc);
99 }
100 }
101 }
102
103 return $encs;
104 }
105
106 function get_author() {
107 $author = $this->elem->getElementsByTagName("author")->item(0);
108
109 if ($author) {
110 $name = $author->getElementsByTagName("name")->item(0);
111
112 if ($name) return $name->nodeValue;
113
114 $email = $author->getElementsByTagName("email")->item(0);
115
116 if ($email) return $email->nodeValue;
117
118 }
119 }
120 }
121 ?>