]>
git.wh0rd.org - tt-rss.git/blob - classes/feeditem/common.php
2 abstract class FeedItem_Common
extends FeedItem
{
7 function __construct($elem, $doc, $xpath) {
14 $source = $elem->getElementsByTagName("source")->item(0);
16 // we don't need <source> element
18 $elem->removeChild($source);
19 } catch (DOMException
$e) {
24 function get_element() {
28 function get_author() {
29 $author = $this->elem
->getElementsByTagName("author")->item(0);
32 $name = $author->getElementsByTagName("name")->item(0);
34 if ($name) return $name->nodeValue
;
36 $email = $author->getElementsByTagName("email")->item(0);
38 if ($email) return $email->nodeValue
;
40 if ($author->nodeValue
)
41 return $author->nodeValue
;
44 $author = $this->xpath
->query("dc:creator", $this->elem
)->item(0);
47 return $author->nodeValue
;
51 function get_comments_url() {
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);
57 return $com_url->nodeValue
;
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);
64 return $com_url->nodeValue
;
67 function get_comments_count() {
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);
73 return $comments->nodeValue
;
77 // this is common for both Atom and RSS types and deals with various media: elements
78 function get_enclosures() {
81 $enclosures = $this->xpath
->query("media:content", $this->elem
);
83 foreach ($enclosures as $enclosure) {
84 $enc = new FeedEnclosure();
86 $enc->type
= $enclosure->getAttribute("type");
87 $enc->link
= $enclosure->getAttribute("url");
88 $enc->length
= $enclosure->getAttribute("length");
89 $enc->height
= $enclosure->getAttribute("height");
90 $enc->width
= $enclosure->getAttribute("width");
92 $medium = $enclosure->getAttribute("medium");
93 if (!$enc->type
&& $medium) {
94 $enc->type
= strtolower("$medium/generic");
97 $desc = $this->xpath
->query("media:description", $enclosure)->item(0);
98 if ($desc) $enc->title
= strip_tags($desc->nodeValue
);
100 array_push($encs, $enc);
103 $enclosures = $this->xpath
->query("media:group", $this->elem
);
105 foreach ($enclosures as $enclosure) {
106 $enc = new FeedEnclosure();
108 $content = $this->xpath
->query("media:content", $enclosure)->item(0);
111 $enc->type
= $content->getAttribute("type");
112 $enc->link
= $content->getAttribute("url");
113 $enc->length
= $content->getAttribute("length");
114 $enc->height
= $content->getAttribute("height");
115 $enc->width
= $content->getAttribute("width");
117 $medium = $content->getAttribute("medium");
118 if (!$enc->type
&& $medium) {
119 $enc->type
= strtolower("$medium/generic");
122 $desc = $this->xpath
->query("media:description", $content)->item(0);
124 $enc->title
= strip_tags($desc->nodeValue
);
126 $desc = $this->xpath
->query("media:description", $enclosure)->item(0);
127 if ($desc) $enc->title
= strip_tags($desc->nodeValue
);
130 array_push($encs, $enc);
134 $enclosures = $this->xpath
->query("media:thumbnail", $this->elem
);
136 foreach ($enclosures as $enclosure) {
137 $enc = new FeedEnclosure();
139 $enc->type
= "image/generic";
140 $enc->link
= $enclosure->getAttribute("url");
141 $enc->height
= $enclosure->getAttribute("height");
142 $enc->width
= $enclosure->getAttribute("width");
144 array_push($encs, $enc);
150 function count_children($node) {
151 return $node->getElementsByTagName("*")->length
;
154 function subtree_or_text($node) {
155 if ($this->count_children($node) == 0) {
156 return $node->nodeValue
;
158 return $node->c14n();