]>
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 AD |
32 | } |
33 | ||
34 | function get_link() { | |
35 | $links = $this->elem->getElementsByTagName("link"); | |
36 | ||
37 | foreach ($links as $link) { | |
df2655e0 AD |
38 | if ($link && $link->hasAttribute("href") && |
39 | (!$link->hasAttribute("rel") | |
40 | || $link->getAttribute("rel") == "alternate" | |
41 | || $link->getAttribute("rel") == "standout")) { | |
b28b2ce9 | 42 | $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)",$link); |
43 | return $base.$link->getAttribute("href"); | |
cd07592c AD |
44 | } |
45 | } | |
46 | } | |
47 | ||
48 | function get_title() { | |
49 | $title = $this->elem->getElementsByTagName("title")->item(0); | |
50 | ||
51 | if ($title) { | |
52 | return $title->nodeValue; | |
53 | } | |
54 | } | |
55 | ||
56 | function get_content() { | |
57 | $content = $this->elem->getElementsByTagName("content")->item(0); | |
58 | ||
59 | if ($content) { | |
27004401 AD |
60 | if ($content->hasAttribute('type')) { |
61 | if ($content->getAttribute('type') == 'xhtml') { | |
bc3c887f AD |
62 | for ($i = 0; $i < $content->childNodes->length; $i++) { |
63 | $child = $content->childNodes->item($i); | |
64 | ||
65 | if ($child->hasChildNodes()) { | |
66 | return $this->doc->saveXML($child); | |
67 | } | |
68 | } | |
96ce71f3 AD |
69 | } |
70 | } | |
71 | ||
cd07592c AD |
72 | return $content->nodeValue; |
73 | } | |
74 | } | |
75 | ||
76 | function get_description() { | |
27004401 AD |
77 | $content = $this->elem->getElementsByTagName("summary")->item(0); |
78 | ||
79 | if ($content) { | |
80 | if ($content->hasAttribute('type')) { | |
81 | if ($content->getAttribute('type') == 'xhtml') { | |
bc3c887f AD |
82 | for ($i = 0; $i < $content->childNodes->length; $i++) { |
83 | $child = $content->childNodes->item($i); | |
84 | ||
85 | if ($child->hasChildNodes()) { | |
86 | return $this->doc->saveXML($child); | |
87 | } | |
88 | } | |
27004401 AD |
89 | } |
90 | } | |
cd07592c | 91 | |
27004401 | 92 | return $content->nodeValue; |
cd07592c | 93 | } |
27004401 | 94 | |
cd07592c AD |
95 | } |
96 | ||
cd07592c AD |
97 | function get_categories() { |
98 | $categories = $this->elem->getElementsByTagName("category"); | |
99 | $cats = array(); | |
100 | ||
101 | foreach ($categories as $cat) { | |
102 | if ($cat->hasAttribute("term")) | |
103 | array_push($cats, $cat->getAttribute("term")); | |
104 | } | |
105 | ||
d4992d6b AD |
106 | $categories = $this->xpath->query("dc:subject", $this->elem); |
107 | ||
108 | foreach ($categories as $cat) { | |
109 | array_push($cats, $cat->nodeValue); | |
110 | } | |
cd07592c AD |
111 | |
112 | return $cats; | |
113 | } | |
114 | ||
115 | function get_enclosures() { | |
116 | $links = $this->elem->getElementsByTagName("link"); | |
117 | ||
118 | $encs = array(); | |
119 | ||
120 | foreach ($links as $link) { | |
121 | if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) { | |
122 | if ($link->getAttribute("rel") == "enclosure") { | |
123 | $enc = new FeedEnclosure(); | |
124 | ||
125 | $enc->type = $link->getAttribute("type"); | |
126 | $enc->link = $link->getAttribute("href"); | |
127 | $enc->length = $link->getAttribute("length"); | |
128 | ||
129 | array_push($encs, $enc); | |
130 | } | |
131 | } | |
132 | } | |
133 | ||
d4992d6b AD |
134 | $enclosures = $this->xpath->query("media:content", $this->elem); |
135 | ||
136 | foreach ($enclosures as $enclosure) { | |
137 | $enc = new FeedEnclosure(); | |
138 | ||
139 | $enc->type = $enclosure->getAttribute("type"); | |
140 | $enc->link = $enclosure->getAttribute("url"); | |
141 | $enc->length = $enclosure->getAttribute("length"); | |
142 | ||
143 | array_push($encs, $enc); | |
144 | } | |
145 | ||
cd07592c AD |
146 | return $encs; |
147 | } | |
148 | ||
cd07592c AD |
149 | } |
150 | ?> |