summaryrefslogtreecommitdiff
path: root/classes/feeditem
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-07-11 14:15:32 +0400
committerAndrew Dolgov <[email protected]>2013-07-11 14:15:32 +0400
commit940e29a63789111c813d5c2d88c0e30071b113f0 (patch)
tree7e6178dee9b358b50dcd1002186e2477692b6a86 /classes/feeditem
parent41a7a066eff0c4914720685c38fa282e99d79041 (diff)
parent6aeb37d062d18519b0f36816f7bd56cb3358cf28 (diff)
Merge branch 'master' of git://github.com/syrnon/Tiny-Tiny-RSS into syrnon-master
Diffstat (limited to 'classes/feeditem')
-rw-r--r--classes/feeditem/atom.php36
1 files changed, 33 insertions, 3 deletions
diff --git a/classes/feeditem/atom.php b/classes/feeditem/atom.php
index fa6b3a34c..532c599cc 100644
--- a/classes/feeditem/atom.php
+++ b/classes/feeditem/atom.php
@@ -1,5 +1,6 @@
<?php
class FeedItem_Atom extends FeedItem_Common {
+
function get_id() {
$id = $this->elem->getElementsByTagName("id")->item(0);
@@ -29,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");
@@ -38,8 +68,8 @@ class FeedItem_Atom extends FeedItem_Common {
(!$link->hasAttribute("rel")
|| $link->getAttribute("rel") == "alternate"
|| $link->getAttribute("rel") == "standout")) {
-
- return $link->getAttribute("href");
+ $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)",$link);
+ return $this->rel2abs($link->getAttribute("href"), $base);
}
}
}