]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/atom.php
Update atom.php
[tt-rss.git] / classes / feeditem / atom.php
1 <?php
2 class FeedItem_Atom extends FeedItem_Common {
3
4 private $baseUrl;
5
6 function __construct($elem, $doc, $xpath, $baseUrl) {
7 parent::__construct($elem, $doc, $xpath);
8 $this->baseUrl= $baseUrl;
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 $published = $this->elem->getElementsByTagName("published")->item(0);
29
30 if ($published) {
31 return strtotime($published->nodeValue);
32 }
33
34 $date = $this->xpath->query("dc:date", $this->elem)->item(0);
35
36 if ($date) {
37 return strtotime($date->nodeValue);
38 }
39 }
40
41 function get_link() {
42 $links = $this->elem->getElementsByTagName("link");
43
44 foreach ($links as $link) {
45 if ($link && $link->hasAttribute("href") &&
46 (!$link->hasAttribute("rel")
47 || $link->getAttribute("rel") == "alternate"
48 || $link->getAttribute("rel") == "standout")) {
49
50 return $this->baseUrl.$link->getAttribute("href");
51 }
52 }
53 }
54
55 function get_title() {
56 $title = $this->elem->getElementsByTagName("title")->item(0);
57
58 if ($title) {
59 return $title->nodeValue;
60 }
61 }
62
63 function get_content() {
64 $content = $this->elem->getElementsByTagName("content")->item(0);
65
66 if ($content) {
67 if ($content->hasAttribute('type')) {
68 if ($content->getAttribute('type') == 'xhtml') {
69 for ($i = 0; $i < $content->childNodes->length; $i++) {
70 $child = $content->childNodes->item($i);
71
72 if ($child->hasChildNodes()) {
73 return $this->doc->saveXML($child);
74 }
75 }
76 }
77 }
78
79 return $content->nodeValue;
80 }
81 }
82
83 function get_description() {
84 $content = $this->elem->getElementsByTagName("summary")->item(0);
85
86 if ($content) {
87 if ($content->hasAttribute('type')) {
88 if ($content->getAttribute('type') == 'xhtml') {
89 for ($i = 0; $i < $content->childNodes->length; $i++) {
90 $child = $content->childNodes->item($i);
91
92 if ($child->hasChildNodes()) {
93 return $this->doc->saveXML($child);
94 }
95 }
96 }
97 }
98
99 return $content->nodeValue;
100 }
101
102 }
103
104 function get_categories() {
105 $categories = $this->elem->getElementsByTagName("category");
106 $cats = array();
107
108 foreach ($categories as $cat) {
109 if ($cat->hasAttribute("term"))
110 array_push($cats, $cat->getAttribute("term"));
111 }
112
113 $categories = $this->xpath->query("dc:subject", $this->elem);
114
115 foreach ($categories as $cat) {
116 array_push($cats, $cat->nodeValue);
117 }
118
119 return $cats;
120 }
121
122 function get_enclosures() {
123 $links = $this->elem->getElementsByTagName("link");
124
125 $encs = array();
126
127 foreach ($links as $link) {
128 if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
129 if ($link->getAttribute("rel") == "enclosure") {
130 $enc = new FeedEnclosure();
131
132 $enc->type = $link->getAttribute("type");
133 $enc->link = $link->getAttribute("href");
134 $enc->length = $link->getAttribute("length");
135
136 array_push($encs, $enc);
137 }
138 }
139 }
140
141 $enclosures = $this->xpath->query("media:content", $this->elem);
142
143 foreach ($enclosures as $enclosure) {
144 $enc = new FeedEnclosure();
145
146 $enc->type = $enclosure->getAttribute("type");
147 $enc->link = $enclosure->getAttribute("url");
148 $enc->length = $enclosure->getAttribute("length");
149
150 array_push($encs, $enc);
151 }
152
153 return $encs;
154 }
155
156 }
157 ?>