]> git.wh0rd.org Git - tt-rss.git/commitdiff
parser: add get_links()
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 1 May 2013 15:08:04 +0000 (19:08 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 1 May 2013 15:08:04 +0000 (19:08 +0400)
classes/feedparser.php

index ed284a0437cbf6c469b5296130f7aa8b437260c5..6d3a15802633e957b6ca1ed1dd416d7f691691bf 100644 (file)
@@ -6,6 +6,7 @@ class FeedParser {
        private $link;
        private $title;
        private $type;
+       private $xpath;
 
        const FEED_RDF = 0;
        const FEED_RSS = 1;
@@ -26,6 +27,7 @@ class FeedParser {
                $root = $this->doc->firstChild;
                $xpath = new DOMXPath($this->doc);
                $xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
+               $this->xpath = $xpath;
 
                $root = $xpath->query("(//atom:feed|//channel)")->item(0);
 
@@ -115,4 +117,27 @@ class FeedParser {
                return $this->items;
        }
 
+       function get_links($rel) {
+               $rv = array();
+
+               switch ($this->type) {
+               case $this::FEED_ATOM:
+                       $links = $this->xpath->query("//atom:feed/atom:link");
+
+                       foreach ($links as $link) {
+                               if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) {
+                                       array_push($rv, $link->getAttribute('href'));
+                               }
+                       }
+                       break;
+               case $this::FEED_RSS:
+                       $links = $this->xpath->query("//channel/link");
+                       if (!$rel || $link->hasAttribute('rel') && $link->getAttribute('rel') == $rel) {
+                               array_push($rv, $link->getAttribute('href'));
+                       }
+                       break;
+               }
+
+               return $rv;
+       }
 } ?>