some image links are absolute for good reason (eg they point to a CDN with a different hostname)

This commit is contained in:
Shish 2012-01-31 15:11:06 +00:00
parent 61483aced2
commit 04ed07a0df
2 changed files with 18 additions and 1 deletions

View File

@ -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)) {

View File

@ -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 *