Change generated links to be aware of HTTPS.

This commit is contained in:
jgen 2015-02-02 00:13:05 -08:00
parent 99be9c2fdb
commit 8e3fc1da9f
2 changed files with 24 additions and 4 deletions

View File

@ -402,10 +402,18 @@ function modify_url($url, $changes) {
* @return string * @return string
*/ */
function make_http(/*string*/ $link) { function make_http(/*string*/ $link) {
if(strpos($link, "ttp://") > 0) return $link; if(strpos($link, "ttp://") > 0) {
if(strlen($link) > 0 && $link[0] != '/') $link = get_base_href().'/'.$link; return $link;
$link = "http://".$_SERVER["HTTP_HOST"].$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); $link = str_replace("/./", "/", $link);
return $link; return $link;
} }
@ -549,6 +557,15 @@ function captcha_check() {
* Misc * * 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 * Get MIME type for file
* *

View File

@ -5,8 +5,11 @@ class QRImageTheme extends Themelet {
*/ */
public function links_block($link) { public function links_block($link) {
global $page; global $page;
$protocol = is_https_enabled() ? "https://" : "http://";
$page->add_block( new Block( $page->add_block( new Block(
"QR Code","<img alt='QR Code' src='http://chart.apis.google.com/chart?chs=150x150&amp;cht=qr&amp;chl={$link}' />","left",50)); "QR Code","<img alt='QR Code' src='{$protocol}chart.apis.google.com/chart?chs=150x150&amp;cht=qr&amp;chl={$link}' />","left",50));
} }
} }