]>
git.wh0rd.org - tt-rss.git/blob - classes/feedparser.php
14 function __construct($data) {
15 libxml_use_internal_errors(true);
16 libxml_clear_errors();
17 $this->doc
= new DOMDocument();
18 $this->doc
->loadXML($data);
19 $this->error
= $this->format_error(libxml_get_last_error());
20 libxml_clear_errors();
22 $this->items
= array();
26 $root = $this->doc
->firstChild
;
27 $xpath = new DOMXPath($this->doc
);
28 $xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
30 $root = $xpath->query("(//atom:feed|//channel)")->item(0);
33 switch ($root->tagName
) {
35 $this->type
= $this::FEED_RSS
;
38 $this->type
= $this::FEED_ATOM
;
41 $this->error
= "Unknown/unsupported feed type";
45 switch ($this->type
) {
46 case $this::FEED_ATOM
:
48 $title = $xpath->query("//atom:feed/atom:title")->item(0);
51 $this->title
= $title->nodeValue
;
54 $link = $xpath->query("//atom:feed/atom:link[not(@rel)]")->item(0);
56 if ($link && $link->hasAttributes()) {
57 $this->link
= $link->getAttribute("href");
60 $articles = $xpath->query("//atom:entry");
62 foreach ($articles as $article) {
63 array_push($this->items
, new FeedItem_Atom($article));
72 $title = $xpath->query("//channel/title")->item(0);
75 $this->title
= $title->nodeValue
;
78 $link = $xpath->query("//channel/link")->item(0);
80 if ($link && $link->hasAttributes()) {
81 $this->link
= $link->getAttribute("href");
84 $articles = $xpath->query("//channel/item");
86 foreach ($articles as $article) {
87 array_push($this->items
, new FeedItem_RSS($article));
95 function format_error($error) {
97 return sprintf("LibXML error %s at line %d (column %d): %s",
98 $error->code
, $error->line
, $error->column
,
109 function get_link() {
113 function get_title() {
117 function get_items() {