From 8e3fc1da9fbfd641df16a30fc337e0aededd58a9 Mon Sep 17 00:00:00 2001 From: jgen Date: Mon, 2 Feb 2015 00:13:05 -0800 Subject: [PATCH] Change generated links to be aware of HTTPS. --- core/util.inc.php | 23 ++++++++++++++++++++--- ext/qr_code/theme.php | 5 ++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/core/util.inc.php b/core/util.inc.php index 029fcee0..bed0794f 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -402,10 +402,18 @@ function modify_url($url, $changes) { * @return string */ function make_http(/*string*/ $link) { - if(strpos($link, "ttp://") > 0) return $link; - if(strlen($link) > 0 && $link[0] != '/') $link = get_base_href().'/'.$link; - $link = "http://".$_SERVER["HTTP_HOST"].$link; + if(strpos($link, "ttp://") > 0) { + return $link; + } + + if(strlen($link) > 0 && $link[0] != '/') { + $link = get_base_href() . '/' . $link; + } + + $protocol = is_https_enabled() ? "https://" : "http://"; + $link = $protocol . $_SERVER["HTTP_HOST"] . $link; $link = str_replace("/./", "/", $link); + return $link; } @@ -549,6 +557,15 @@ function captcha_check() { * Misc * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/** + * Check if HTTPS is enabled for the server. + * + * @return bool True if HTTPS is enabled + */ +function is_https_enabled() { + return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'); +} + /** * Get MIME type for file * diff --git a/ext/qr_code/theme.php b/ext/qr_code/theme.php index c0600f23..90221b26 100644 --- a/ext/qr_code/theme.php +++ b/ext/qr_code/theme.php @@ -5,8 +5,11 @@ class QRImageTheme extends Themelet { */ public function links_block($link) { global $page; + + $protocol = is_https_enabled() ? "https://" : "http://"; + $page->add_block( new Block( - "QR Code","QR Code","left",50)); + "QR Code","QR Code","left",50)); } }