From deeeee76d2a85314ddab909f160574d0c7a5964d Mon Sep 17 00:00:00 2001 From: syrnon Date: Wed, 3 Jul 2013 22:35:38 +0300 Subject: [PATCH 1/6] Update feedparser.php --- classes/feedparser.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/classes/feedparser.php b/classes/feedparser.php index eb8606de9..1474c66bf 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -103,9 +103,18 @@ class FeedParser { if (!$articles || $articles->length == 0) $articles = $xpath->query("//atom03:entry"); - foreach ($articles as $article) { - array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath)); + $feed = $this->xpath->query("//atom:feed")->item(0); + $atts = $feed->attributes; + foreach($atts as $attrib) + { + if($attrib->name == "base"){ + $base = $attrib->nodeValue; + } } + foreach ($articles as $article) { + array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath, $base)); + } + break; case $this::FEED_RSS: From bfc24f3794fa658b23215a430aafda050460d21b Mon Sep 17 00:00:00 2001 From: syrnon Date: Wed, 3 Jul 2013 22:36:33 +0300 Subject: [PATCH 2/6] Update atom.php --- classes/feeditem/atom.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index fa6b3a34c..c58d2a5ff 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -1,5 +1,13 @@ baseUrl= $baseUrl; + } + function get_id() { $id = $this->elem->getElementsByTagName("id")->item(0); @@ -39,7 +47,7 @@ class FeedItem_Atom extends FeedItem_Common { || $link->getAttribute("rel") == "alternate" || $link->getAttribute("rel") == "standout")) { - return $link->getAttribute("href"); + return $this->baseUrl.$link->getAttribute("href"); } } } From f150f85a5e3694dd9af195afdb154807c58a7630 Mon Sep 17 00:00:00 2001 From: syrnon Date: Tue, 9 Jul 2013 17:28:15 +0300 Subject: [PATCH 3/6] reverted changes --- classes/feedparser.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/classes/feedparser.php b/classes/feedparser.php index 1474c66bf..a27fd97cc 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -104,18 +104,10 @@ class FeedParser { $articles = $xpath->query("//atom03:entry"); $feed = $this->xpath->query("//atom:feed")->item(0); - $atts = $feed->attributes; - foreach($atts as $attrib) - { - if($attrib->name == "base"){ - $base = $attrib->nodeValue; - } - } foreach ($articles as $article) { - array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath, $base)); + array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath)); } - break; case $this::FEED_RSS: $title = $xpath->query("//channel/title")->item(0); From b28b2ce9eb4265b7360f170ae7f706906fc6d1f9 Mon Sep 17 00:00:00 2001 From: syrnon Date: Tue, 9 Jul 2013 17:29:25 +0300 Subject: [PATCH 4/6] calculating base locally --- classes/feeditem/atom.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index c58d2a5ff..522ca633e 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -1,13 +1,6 @@ baseUrl= $baseUrl; - } - function get_id() { $id = $this->elem->getElementsByTagName("id")->item(0); @@ -46,8 +39,8 @@ class FeedItem_Atom extends FeedItem_Common { (!$link->hasAttribute("rel") || $link->getAttribute("rel") == "alternate" || $link->getAttribute("rel") == "standout")) { - - return $this->baseUrl.$link->getAttribute("href"); + $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)",$link); + return $base.$link->getAttribute("href"); } } } From ef811bba02c4a156d110d0acab4b5619b12837e7 Mon Sep 17 00:00:00 2001 From: syrnon Date: Tue, 9 Jul 2013 17:31:23 +0300 Subject: [PATCH 5/6] reverting --- classes/feedparser.php | 1 - 1 file changed, 1 deletion(-) diff --git a/classes/feedparser.php b/classes/feedparser.php index a27fd97cc..eb8606de9 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -103,7 +103,6 @@ class FeedParser { if (!$articles || $articles->length == 0) $articles = $xpath->query("//atom03:entry"); - $feed = $this->xpath->query("//atom:feed")->item(0); foreach ($articles as $article) { array_push($this->items, new FeedItem_Atom($article, $this->doc, $this->xpath)); } From 6aeb37d062d18519b0f36816f7bd56cb3358cf28 Mon Sep 17 00:00:00 2001 From: syrnon Date: Tue, 9 Jul 2013 18:05:16 +0300 Subject: [PATCH 6/6] fixing the rel url to abs --- classes/feeditem/atom.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php index 522ca633e..532c599cc 100644 --- a/classes/feeditem/atom.php +++ b/classes/feeditem/atom.php @@ -30,7 +30,36 @@ class FeedItem_Atom extends FeedItem_Common { return strtotime($date->nodeValue); } } + + function rel2abs($rel, $base) + { + /* return if already absolute URL */ + if (parse_url($rel, PHP_URL_SCHEME) != '') return $rel; + + /* queries and anchors */ + if ($rel[0]=='#' || $rel[0]=='?') return $base.$rel; + + /* parse base URL and convert to local variables: + $scheme, $host, $path */ + extract(parse_url($base)); + + /* remove non-directory element from path */ + $path = preg_replace('#/[^/]*$#', '', $path); + + /* destroy path if relative url points to root */ + if ($rel[0] == '/') $path = ''; + + /* dirty absolute URL */ + $abs = "$host$path/$rel"; + + /* replace '//' or '/./' or '/foo/../' with '/' */ + $re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#'); + for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {} + /* absolute URL is ready! */ + return $scheme.'://'.$abs; + } + function get_link() { $links = $this->elem->getElementsByTagName("link"); @@ -40,7 +69,7 @@ class FeedItem_Atom extends FeedItem_Common { || $link->getAttribute("rel") == "alternate" || $link->getAttribute("rel") == "standout")) { $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)",$link); - return $base.$link->getAttribute("href"); + return $this->rel2abs($link->getAttribute("href"), $base); } } }