summaryrefslogtreecommitdiff
path: root/classes/feeditem
diff options
context:
space:
mode:
authorsyrnon <[email protected]>2013-07-09 18:05:16 +0300
committersyrnon <[email protected]>2013-07-09 18:05:16 +0300
commit6aeb37d062d18519b0f36816f7bd56cb3358cf28 (patch)
treed743167d74184b7fa00283bf7591d5d988c5a145 /classes/feeditem
parentef811bba02c4a156d110d0acab4b5619b12837e7 (diff)
fixing the rel url to abs
Diffstat (limited to 'classes/feeditem')
-rw-r--r--classes/feeditem/atom.php33
1 files changed, 31 insertions, 2 deletions
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);
}
}
}