]> git.wh0rd.org - tt-rss.git/blob - classes/feeditem/atom.php
Merge pull request #216 from PerryWerneck/master
[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 $date = $this->xpath->query("dc:date", $this->elem)->item(0);
21
22 if ($date) {
23 return strtotime($date->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") &&
32 (!$link->hasAttribute("rel")
33 || $link->getAttribute("rel") == "alternate"
34 || $link->getAttribute("rel") == "standout")) {
35
36 return $link->getAttribute("href");
37 }
38 }
39 }
40
41 function get_title() {
42 $title = $this->elem->getElementsByTagName("title")->item(0);
43
44 if ($title) {
45 return $title->nodeValue;
46 }
47 }
48
49 function get_content() {
50 $content = $this->elem->getElementsByTagName("content")->item(0);
51
52 if ($content) {
53 if ($content->hasAttribute('type')) {
54 if ($content->getAttribute('type') == 'xhtml') {
55 return $this->doc->saveXML($content->firstChild->nextSibling);
56 }
57 }
58
59 return $content->nodeValue;
60 }
61 }
62
63 function get_description() {
64 $content = $this->elem->getElementsByTagName("summary")->item(0);
65
66 if ($content) {
67 if ($content->hasAttribute('type')) {
68 if ($content->getAttribute('type') == 'xhtml') {
69 return $this->doc->saveXML($content->firstChild->nextSibling);
70 }
71 }
72
73 return $content->nodeValue;
74 }
75
76 }
77
78 function get_categories() {
79 $categories = $this->elem->getElementsByTagName("category");
80 $cats = array();
81
82 foreach ($categories as $cat) {
83 if ($cat->hasAttribute("term"))
84 array_push($cats, $cat->getAttribute("term"));
85 }
86
87 $categories = $this->xpath->query("dc:subject", $this->elem);
88
89 foreach ($categories as $cat) {
90 array_push($cats, $cat->nodeValue);
91 }
92
93 return $cats;
94 }
95
96 function get_enclosures() {
97 $links = $this->elem->getElementsByTagName("link");
98
99 $encs = array();
100
101 foreach ($links as $link) {
102 if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
103 if ($link->getAttribute("rel") == "enclosure") {
104 $enc = new FeedEnclosure();
105
106 $enc->type = $link->getAttribute("type");
107 $enc->link = $link->getAttribute("href");
108 $enc->length = $link->getAttribute("length");
109
110 array_push($encs, $enc);
111 }
112 }
113 }
114
115 $enclosures = $this->xpath->query("media:content", $this->elem);
116
117 foreach ($enclosures as $enclosure) {
118 $enc = new FeedEnclosure();
119
120 $enc->type = $enclosure->getAttribute("type");
121 $enc->link = $enclosure->getAttribute("url");
122 $enc->length = $enclosure->getAttribute("length");
123
124 array_push($encs, $enc);
125 }
126
127 return $encs;
128 }
129
130 }
131 ?>