]>
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
;
29 switch ($root->tagName
) {
31 $this->type
= $this::FEED_RSS
;
34 $this->type
= $this::FEED_ATOM
;
37 $this->error
= "Unknown/unsupported feed type";
41 $xpath = new DOMXPath($this->doc
);
43 switch ($this->type
) {
44 case $this::FEED_ATOM
:
45 $xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
47 $title = $xpath->query("//atom:feed/atom:title")->item(0);
50 $this->title
= $title->nodeValue
;
53 $link = $xpath->query("//atom:feed/atom:link[not(@rel)]")->item(0);
55 if ($link && $link->hasAttributes()) {
56 $this->link
= $link->getAttribute("href");
59 $articles = $xpath->query("//atom:entry");
61 foreach ($articles as $article) {
62 array_push($this->items
, new FeedItem_Atom($article));
75 function format_error($error) {
77 return sprintf("LibXML error %s at line %d (column %d): %s",
78 $error->code
, $error->line
, $error->column
,
93 function get_title() {
97 function get_items() {