From ecef1edb14a8e935f0bcc0292f28f46a806eb776 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 24 Jul 2009 08:08:29 +0100 Subject: [PATCH] make_http function --- contrib/rss_images/main.php | 2 +- contrib/simpletest/main.php | 4 +--- core/util.inc.php | 13 +++++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/contrib/rss_images/main.php b/contrib/rss_images/main.php index 879e70a7..fbbc18b5 100644 --- a/contrib/rss_images/main.php +++ b/contrib/rss_images/main.php @@ -54,7 +54,7 @@ class RSS_Images extends SimpleExtension { $data = ""; foreach($images as $image) { - $link = make_link("post/view/{$image->id}"); + $link = make_http(make_link("post/view/{$image->id}")); $tags = $image->get_tag_list(); $owner = $image->get_owner(); $thumb_url = $image->get_thumb_link(); diff --git a/contrib/simpletest/main.php b/contrib/simpletest/main.php index 013cffd3..15e6f612 100644 --- a/contrib/simpletest/main.php +++ b/contrib/simpletest/main.php @@ -33,9 +33,7 @@ define('ADMIN_PASS', "demo"); */ class SCoreWebTestCase extends WebTestCase { protected function get_page($page) { - $url = "http://".$_SERVER["HTTP_HOST"].get_base_href().'/'.make_link($page); - $url = str_replace("/./", "/", $url); - $raw = $this->get($url); + $raw = $this->get(make_http(make_link($url))); $this->assertNoText("Exception:"); $this->assertNoText("Error:"); $this->assertNoText("Warning:"); diff --git a/core/util.inc.php b/core/util.inc.php index 1072c42f..09e3a85c 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -127,6 +127,19 @@ function make_link($page=null, $query=null) { } } +/** + * Turn a relative link into an absolute one, including hostname + * + * @retval string + */ +function make_http($link) { + if(strpos($link, "ttp://") > 0) return $link; + if($link[0] != '/') $link = get_base_href().'/'.$link; + $link = "http://".$_SERVER["HTTP_HOST"].$link; + $link = str_replace("/./", "/", $link); + return $link; +} + /** * Make a link to a static file in the current theme's * directory