From 04ed07a0df0a43900c4e3480961b5ddefb5153cb Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 31 Jan 2012 15:11:06 +0000 Subject: [PATCH] some image links are absolute for good reason (eg they point to a CDN with a different hostname) --- core/imageboard.pack.php | 8 +++++++- core/util.inc.php | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 033a1bfe..bac574b7 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -255,7 +255,10 @@ class Image { $image_ilink = $config->get_string('image_ilink'); // store a copy for speed. if( !empty($image_ilink) ) { /* empty is faster than strlen */ - return $this->parse_link_template(make_link($image_ilink)); + if(!startsWith($image_ilink, "http://") && !startsWith($image_ilink, "/")) { + $image_ilink = make_link($image_ilink); + } + return $this->parse_link_template($image_ilink); } else if($config->get_bool('nice_urls', false)) { return $this->parse_link_template(make_link('_images/$hash/$id - $tags.$ext')); @@ -287,6 +290,9 @@ class Image { $image_tlink = $config->get_string('image_tlink'); // store a copy for speed. if( !empty($image_tlink) ) { /* empty is faster than strlen */ + if(!startsWith($image_tlink, "http://") && !startsWith($image_tlink, "/")) { + $image_tlink = make_link($image_tlink); + } return $this->parse_link_template($image_tlink); } else if($config->get_bool('nice_urls', false)) { diff --git a/core/util.inc.php b/core/util.inc.php index 43a53bdb..e7563d6c 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -190,6 +190,17 @@ function undb_bool($val) { if($val === false || $val == 'N' || $val == 'n' || $val == 'F' || $val == 'f' || $val === 0) return false; } +function startsWith($haystack, $needle) { + $length = strlen($needle); + return (substr($haystack, 0, $length) === $needle); +} + +function endsWith($haystack, $needle) { + $length = strlen($needle); + $start = $length * -1; //negative + return (substr($haystack, $start) === $needle); +} + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * HTML Generation *