]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/atom.php
catch warning when removing source element
[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 for ($i = 0; $i < $content->childNodes->length; $i++) {
62 $child = $content->childNodes->item($i);
63
64 if ($child->hasChildNodes()) {
65 return $this->doc->saveXML($child);
66 }
67 }
68 }
69 }
70
71 return $content->nodeValue;
72 }
73 }
74
75 function get_description() {
76 $content = $this->elem->getElementsByTagName("summary")->item(0);
77
78 if ($content) {
79 if ($content->hasAttribute('type')) {
80 if ($content->getAttribute('type') == 'xhtml') {
81 for ($i = 0; $i < $content->childNodes->length; $i++) {
82 $child = $content->childNodes->item($i);
83
84 if ($child->hasChildNodes()) {
85 return $this->doc->saveXML($child);
86 }
87 }
88 }
89 }
90
91 return $content->nodeValue;
92 }
93
94 }
95
96 function get_categories() {
97 $categories = $this->elem->getElementsByTagName("category");
98 $cats = array();
99
100 foreach ($categories as $cat) {
101 if ($cat->hasAttribute("term"))
102 array_push($cats, $cat->getAttribute("term"));
103 }
104
105 $categories = $this->xpath->query("dc:subject", $this->elem);
106
107 foreach ($categories as $cat) {
108 array_push($cats, $cat->nodeValue);
109 }
110
111 return $cats;
112 }
113
114 function get_enclosures() {
115 $links = $this->elem->getElementsByTagName("link");
116
117 $encs = array();
118
119 foreach ($links as $link) {
120 if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
121 if ($link->getAttribute("rel") == "enclosure") {
122 $enc = new FeedEnclosure();
123
124 $enc->type = $link->getAttribute("type");
125 $enc->link = $link->getAttribute("href");
126 $enc->length = $link->getAttribute("length");
127
128 array_push($encs, $enc);
129 }
130 }
131 }
132
133 $enclosures = $this->xpath->query("media:content", $this->elem);
134
135 foreach ($enclosures as $enclosure) {
136 $enc = new FeedEnclosure();
137
138 $enc->type = $enclosure->getAttribute("type");
139 $enc->link = $enclosure->getAttribute("url");
140 $enc->length = $enclosure->getAttribute("length");
141
142 array_push($encs, $enc);
143 }
144
145 return $encs;
146 }
147
148 }
149 ?>