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