]>
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 function count_children($node) {
78 return $node->getElementsByTagName("*")->length
;
81 function subtree_or_text($node) {
82 if ($this->count_children($node) == 0) {
83 return $node->nodeValue
;