]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/atom.php
atom: support <published>
[tt-rss.git] / classes / feeditem / atom.php
1 <?php
2 class FeedItem_Atom extends FeedItem_Common {
3 function get_id() {
4 $id = $this->elem->getElementsByTagName("id")->item(0);
5
6 if ($id) {
7 return $id->nodeValue;
8 } else {
9 return $this->get_link();
10 }
11 }
12
13 function get_date() {
14 $updated = $this->elem->getElementsByTagName("updated")->item(0);
15
16 if ($updated) {
17 return strtotime($updated->nodeValue);
18 }
19
20 $published = $this->elem->getElementsByTagName("published")->item(0);
21
22 if ($published) {
23 return strtotime($published->nodeValue);
24 }
25
26 $date = $this->xpath->query("dc:date", $this->elem)->item(0);
27
28 if ($date) {
29 return strtotime($date->nodeValue);
30 }
31 }
32
33 function get_link() {
34 $links = $this->elem->getElementsByTagName("link");
35
36 foreach ($links as $link) {
37 if ($link && $link->hasAttribute("href") &&
38 (!$link->hasAttribute("rel")
39 || $link->getAttribute("rel") == "alternate"
40 || $link->getAttribute("rel") == "standout")) {
41
42 return $link->getAttribute("href");
43 }
44 }
45 }
46
47 function get_title() {
48 $title = $this->elem->getElementsByTagName("title")->item(0);
49
50 if ($title) {
51 return $title->nodeValue;
52 }
53 }
54
55 function get_content() {
56 $content = $this->elem->getElementsByTagName("content")->item(0);
57
58 if ($content) {
59 if ($content->hasAttribute('type')) {
60 if ($content->getAttribute('type') == 'xhtml') {
61 return $this->doc->saveXML($content->firstChild->nextSibling);
62 }
63 }
64
65 return $content->nodeValue;
66 }
67 }
68
69 function get_description() {
70 $content = $this->elem->getElementsByTagName("summary")->item(0);
71
72 if ($content) {
73 if ($content->hasAttribute('type')) {
74 if ($content->getAttribute('type') == 'xhtml') {
75 return $this->doc->saveXML($content->firstChild->nextSibling);
76 }
77 }
78
79 return $content->nodeValue;
80 }
81
82 }
83
84 function get_categories() {
85 $categories = $this->elem->getElementsByTagName("category");
86 $cats = array();
87
88 foreach ($categories as $cat) {
89 if ($cat->hasAttribute("term"))
90 array_push($cats, $cat->getAttribute("term"));
91 }
92
93 $categories = $this->xpath->query("dc:subject", $this->elem);
94
95 foreach ($categories as $cat) {
96 array_push($cats, $cat->nodeValue);
97 }
98
99 return $cats;
100 }
101
102 function get_enclosures() {
103 $links = $this->elem->getElementsByTagName("link");
104
105 $encs = array();
106
107 foreach ($links as $link) {
108 if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
109 if ($link->getAttribute("rel") == "enclosure") {
110 $enc = new FeedEnclosure();
111
112 $enc->type = $link->getAttribute("type");
113 $enc->link = $link->getAttribute("href");
114 $enc->length = $link->getAttribute("length");
115
116 array_push($encs, $enc);
117 }
118 }
119 }
120
121 $enclosures = $this->xpath->query("media:content", $this->elem);
122
123 foreach ($enclosures as $enclosure) {
124 $enc = new FeedEnclosure();
125
126 $enc->type = $enclosure->getAttribute("type");
127 $enc->link = $enclosure->getAttribute("url");
128 $enc->length = $enclosure->getAttribute("length");
129
130 array_push($encs, $enc);
131 }
132
133 return $encs;
134 }
135
136 }
137 ?>