summaryrefslogtreecommitdiff
path: root/classes/feedparser.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-05-01 19:08:04 +0400
committerAndrew Dolgov <[email protected]>2013-05-01 19:08:04 +0400
commitb9eee80e08fab8ebcc1484e8d62cd646ac451f43 (patch)
tree90be5d075ca477dcadba6ae1a950db149cfe9838 /classes/feedparser.php
parent431e27851bc35845c4bc207db98dae6067ca0516 (diff)
parser: add get_links()
Diffstat (limited to 'classes/feedparser.php')
-rw-r--r--classes/feedparser.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/classes/feedparser.php b/classes/feedparser.php
index ed284a043..6d3a15802 100644
--- a/classes/feedparser.php
+++ b/classes/feedparser.php
@@ -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;
+ }
} ?>