more https support, and dedupe get_image/thumb_link

This commit is contained in:
Shish 2015-06-01 10:57:56 +01:00
parent 21d96db771
commit 8d2b97b72f
2 changed files with 21 additions and 35 deletions

View file

@ -321,33 +321,7 @@ class Image {
* @return string * @return string
*/ */
public function get_image_link() { public function get_image_link() {
global $config; return $this->get_link('image_ilink', '_images/$hash/$id%20-%20$tags.$ext', 'image/$id.jpg');
$image_ilink = $config->get_string('image_ilink'); // store a copy for speed.
if( !empty($image_ilink) ) { /* empty is faster than strlen */
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%20-%20$tags.$ext'));
}
else {
return $this->parse_link_template(make_link('image/$id.$ext'));
}
}
/**
* Get a short link to the full size image
*
* @deprecated
* @return string
*/
public function get_short_link() {
global $config;
return $this->parse_link_template($config->get_string('image_slink'));
} }
/** /**
@ -356,21 +330,33 @@ class Image {
* @return string * @return string
*/ */
public function get_thumb_link() { public function get_thumb_link() {
return $this->get_link('image_tlink', '_thumbs/$hash/thumb.jpg', 'thumb/$id.jpg');
}
/**
* Check configured template for a link, then try nice URL, then plain URL
*
* @param $template
* @param $nice
* @param $plain
* @return string
*/
private function get_link($template, $nice, $plain) {
global $config; global $config;
$image_tlink = $config->get_string('image_tlink'); // store a copy for speed. $image_link = $config->get_string($template);
if( !empty($image_tlink) ) { /* empty is faster than strlen */ if(!empty($image_link)) {
if(!startsWith($image_tlink, "http://") && !startsWith($image_tlink, "/")) { if(!(strpos($link, "://") > 0) && !startsWith($image_link, "/")) {
$image_tlink = make_link($image_tlink); $image_link = make_link($image_link);
} }
return $this->parse_link_template($image_tlink); return $this->parse_link_template($image_link);
} }
else if($config->get_bool('nice_urls', false)) { else if($config->get_bool('nice_urls', false)) {
return $this->parse_link_template(make_link('_thumbs/$hash/thumb.jpg')); return $this->parse_link_template(make_link($nice));
} }
else { else {
return $this->parse_link_template(make_link('thumb/$id.jpg')); return $this->parse_link_template(make_link($plain));
} }
} }

View file

@ -402,7 +402,7 @@ function modify_url($url, $changes) {
* @return string * @return string
*/ */
function make_http(/*string*/ $link) { function make_http(/*string*/ $link) {
if(strpos($link, "ttp://") > 0) { if(strpos($link, "://") > 0) {
return $link; return $link;
} }