]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/atom.php
add basic tinyparser/atom
[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
21
22 }
23
24 function get_link() {
25 $links = $this->elem->getElementsByTagName("link");
26
27 foreach ($links as $link) {
28 if ($link && $link->hasAttribute("href") && !$link->hasAttribute("rel")) {
29 return $link->getAttribute("href");
30 }
31 }
32 }
33
34 function get_title() {
35 $title = $this->elem->getElementsByTagName("title")->item(0);
36
37 if ($title) {
38 return $title->nodeValue;
39 }
40 }
41
42 function get_content() {
43 $content = $this->elem->getElementsByTagName("content")->item(0);
44
45 if ($content) {
46 return $content->nodeValue;
47 }
48 }
49
50 function get_description() {
51 $summary = $this->elem->getElementsByTagName("summary")->item(0);
52
53 if ($summary) {
54 return $summary->nodeValue;
55 }
56 }
57
58 // todo
59 function get_comments_url() {
60
61 }
62
63 // todo
64 function get_comments_count() {
65
66 }
67
68 function get_categories() {
69 $categories = $this->elem->getElementsByTagName("category");
70 $cats = array();
71
72 foreach ($categories as $cat) {
73 if ($cat->hasAttribute("term"))
74 array_push($cats, $cat->getAttribute("term"));
75 }
76
77
78 return $cats;
79 }
80
81 function get_enclosures() {
82 $links = $this->elem->getElementsByTagName("link");
83
84 $encs = array();
85
86 foreach ($links as $link) {
87 if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
88 if ($link->getAttribute("rel") == "enclosure") {
89 $enc = new FeedEnclosure();
90
91 $enc->type = $link->getAttribute("type");
92 $enc->link = $link->getAttribute("href");
93 $enc->length = $link->getAttribute("length");
94
95 array_push($encs, $enc);
96 }
97 }
98 }
99
100 return $encs;
101 }
102
103 function get_author() {
104 $author = $this->elem->getElementsByTagName("author")->item(0);
105
106 if ($author) {
107 $name = $author->getElementsByTagName("name")->item(0);
108
109 if ($name) return $name->nodeValue;
110
111 $email = $author->getElementsByTagName("email")->item(0);
112
113 if ($email) return $email->nodeValue;
114
115 }
116 }
117 }
118 ?>