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