]>
Commit | Line | Data |
---|---|---|
cd07592c | 1 | <?php |
b4d16900 | 2 | class FeedItem_Atom extends FeedItem_Common { |
bfc24f37 | 3 | |
cd07592c AD |
4 | function get_id() { |
5 | $id = $this->elem->getElementsByTagName("id")->item(0); | |
6 | ||
7 | if ($id) { | |
8 | return $id->nodeValue; | |
9 | } else { | |
10 | return $this->get_link(); | |
11 | } | |
12 | } | |
13 | ||
14 | function get_date() { | |
04d2f9c8 | 15 | $updated = $this->elem->getElementsByTagName("updated")->item(0); |
cd07592c | 16 | |
04d2f9c8 AD |
17 | if ($updated) { |
18 | return strtotime($updated->nodeValue); | |
19 | } | |
ce5d234d | 20 | |
d256f1fb AD |
21 | $published = $this->elem->getElementsByTagName("published")->item(0); |
22 | ||
23 | if ($published) { | |
24 | return strtotime($published->nodeValue); | |
25 | } | |
26 | ||
ce5d234d AD |
27 | $date = $this->xpath->query("dc:date", $this->elem)->item(0); |
28 | ||
29 | if ($date) { | |
30 | return strtotime($date->nodeValue); | |
31 | } | |
cd07592c | 32 | } |
3c4dead6 AD |
33 | |
34 | ||
cd07592c AD |
35 | function get_link() { |
36 | $links = $this->elem->getElementsByTagName("link"); | |
37 | ||
38 | foreach ($links as $link) { | |
df2655e0 AD |
39 | if ($link && $link->hasAttribute("href") && |
40 | (!$link->hasAttribute("rel") | |
41 | || $link->getAttribute("rel") == "alternate" | |
42 | || $link->getAttribute("rel") == "standout")) { | |
3c4dead6 AD |
43 | $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link); |
44 | ||
45 | return rewrite_relative_url($base, $link->getAttribute("href")); | |
cd07592c AD |
46 | } |
47 | } | |
48 | } | |
49 | ||
50 | function get_title() { | |
51 | $title = $this->elem->getElementsByTagName("title")->item(0); | |
52 | ||
53 | if ($title) { | |
54 | return $title->nodeValue; | |
55 | } | |
56 | } | |
57 | ||
58 | function get_content() { | |
59 | $content = $this->elem->getElementsByTagName("content")->item(0); | |
60 | ||
61 | if ($content) { | |
27004401 AD |
62 | if ($content->hasAttribute('type')) { |
63 | if ($content->getAttribute('type') == 'xhtml') { | |
bc3c887f AD |
64 | for ($i = 0; $i < $content->childNodes->length; $i++) { |
65 | $child = $content->childNodes->item($i); | |
66 | ||
67 | if ($child->hasChildNodes()) { | |
68 | return $this->doc->saveXML($child); | |
69 | } | |
70 | } | |
96ce71f3 AD |
71 | } |
72 | } | |
73 | ||
cd07592c AD |
74 | return $content->nodeValue; |
75 | } | |
76 | } | |
77 | ||
78 | function get_description() { | |
27004401 AD |
79 | $content = $this->elem->getElementsByTagName("summary")->item(0); |
80 | ||
81 | if ($content) { | |
82 | if ($content->hasAttribute('type')) { | |
83 | if ($content->getAttribute('type') == 'xhtml') { | |
bc3c887f AD |
84 | for ($i = 0; $i < $content->childNodes->length; $i++) { |
85 | $child = $content->childNodes->item($i); | |
86 | ||
87 | if ($child->hasChildNodes()) { | |
88 | return $this->doc->saveXML($child); | |
89 | } | |
90 | } | |
27004401 AD |
91 | } |
92 | } | |
cd07592c | 93 | |
27004401 | 94 | return $content->nodeValue; |
cd07592c | 95 | } |
27004401 | 96 | |
cd07592c AD |
97 | } |
98 | ||
cd07592c AD |
99 | function get_categories() { |
100 | $categories = $this->elem->getElementsByTagName("category"); | |
101 | $cats = array(); | |
102 | ||
103 | foreach ($categories as $cat) { | |
104 | if ($cat->hasAttribute("term")) | |
105 | array_push($cats, $cat->getAttribute("term")); | |
106 | } | |
107 | ||
d4992d6b AD |
108 | $categories = $this->xpath->query("dc:subject", $this->elem); |
109 | ||
110 | foreach ($categories as $cat) { | |
111 | array_push($cats, $cat->nodeValue); | |
112 | } | |
cd07592c AD |
113 | |
114 | return $cats; | |
115 | } | |
116 | ||
117 | function get_enclosures() { | |
118 | $links = $this->elem->getElementsByTagName("link"); | |
119 | ||
120 | $encs = array(); | |
121 | ||
122 | foreach ($links as $link) { | |
123 | if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) { | |
124 | if ($link->getAttribute("rel") == "enclosure") { | |
125 | $enc = new FeedEnclosure(); | |
126 | ||
127 | $enc->type = $link->getAttribute("type"); | |
128 | $enc->link = $link->getAttribute("href"); | |
129 | $enc->length = $link->getAttribute("length"); | |
130 | ||
131 | array_push($encs, $enc); | |
132 | } | |
133 | } | |
134 | } | |
135 | ||
d4992d6b AD |
136 | $enclosures = $this->xpath->query("media:content", $this->elem); |
137 | ||
138 | foreach ($enclosures as $enclosure) { | |
139 | $enc = new FeedEnclosure(); | |
140 | ||
141 | $enc->type = $enclosure->getAttribute("type"); | |
142 | $enc->link = $enclosure->getAttribute("url"); | |
143 | $enc->length = $enclosure->getAttribute("length"); | |
144 | ||
145 | array_push($encs, $enc); | |
146 | } | |
147 | ||
cd07592c AD |
148 | return $encs; |
149 | } | |
150 | ||
cd07592c AD |
151 | } |
152 | ?> |