]>
Commit | Line | Data |
---|---|---|
b4d16900 AD |
1 | <?php |
2 | abstract class FeedItem_Common extends FeedItem { | |
3 | protected $elem; | |
4 | protected $xpath; | |
5 | protected $doc; | |
6 | ||
7 | function __construct($elem, $doc, $xpath) { | |
8 | $this->elem = $elem; | |
9 | $this->xpath = $xpath; | |
10 | $this->doc = $doc; | |
b5844603 | 11 | |
01561287 | 12 | try { |
b5844603 | 13 | |
01561287 AD |
14 | $source = $elem->getElementsByTagName("source")->item(0); |
15 | ||
16 | // we don't need <source> element | |
17 | if ($source) | |
18 | $elem->removeChild($source); | |
19 | } catch (DOMException $e) { | |
20 | // | |
21 | } | |
b4d16900 AD |
22 | } |
23 | ||
40f4a7aa AD |
24 | function get_element() { |
25 | return $this->elem; | |
26 | } | |
27 | ||
b4d16900 AD |
28 | function get_author() { |
29 | $author = $this->elem->getElementsByTagName("author")->item(0); | |
30 | ||
31 | if ($author) { | |
32 | $name = $author->getElementsByTagName("name")->item(0); | |
33 | ||
34 | if ($name) return $name->nodeValue; | |
35 | ||
36 | $email = $author->getElementsByTagName("email")->item(0); | |
37 | ||
38 | if ($email) return $email->nodeValue; | |
602fe534 AD |
39 | |
40 | if ($author->nodeValue) | |
41 | return $author->nodeValue; | |
b4d16900 AD |
42 | } |
43 | ||
44 | $author = $this->xpath->query("dc:creator", $this->elem)->item(0); | |
45 | ||
46 | if ($author) { | |
47 | return $author->nodeValue; | |
48 | } | |
49 | } | |
50 | ||
b4d16900 | 51 | function get_comments_url() { |
d71ac5d3 | 52 | //RSS only. Use a query here to avoid namespace clashes (e.g. with slash). |
53 | //might give a wrong result if a default namespace was declared (possible with XPath 2.0) | |
54 | $com_url = $this->xpath->query("comments", $this->elem)->item(0); | |
b4d16900 | 55 | |
d71ac5d3 | 56 | if($com_url) |
57 | return $com_url->nodeValue; | |
58 | ||
59 | //Atom Threading Extension (RFC 4685) stuff. Could be used in RSS feeds, so it's in common. | |
60 | //'text/html' for type is too restrictive? | |
61 | $com_url = $this->xpath->query("atom:link[@rel='replies' and contains(@type,'text/html')]/@href", $this->elem)->item(0); | |
62 | ||
63 | if($com_url) | |
64 | return $com_url->nodeValue; | |
b4d16900 AD |
65 | } |
66 | ||
67 | function get_comments_count() { | |
d71ac5d3 | 68 | //also query for ATE stuff here |
69 | $query = "slash:comments|thread:total|atom:link[@rel='replies']/@thread:count"; | |
70 | $comments = $this->xpath->query($query, $this->elem)->item(0); | |
b4d16900 AD |
71 | |
72 | if ($comments) { | |
73 | return $comments->nodeValue; | |
74 | } | |
75 | } | |
76 | ||
7d1e15c3 AD |
77 | function count_children($node) { |
78 | return $node->getElementsByTagName("*")->length; | |
79 | } | |
80 | ||
81 | function subtree_or_text($node) { | |
82 | if ($this->count_children($node) == 0) { | |
83 | return $node->nodeValue; | |
84 | } else { | |
85 | return $node->c14n(); | |
86 | } | |
87 | } | |
b4d16900 | 88 | |
ea79a0e0 | 89 | } |