From b2b1f596eeab5b88edc3579b18cddf7d35e1df39 Mon Sep 17 00:00:00 2001 From: maxpozdeev Date: Sun, 11 Sep 2022 01:04:51 +0300 Subject: [PATCH] * can force to use https scheme with MTT_USE_HTTPS constant in config.php (closes GH-35) --- src/init.php | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/init.php b/src/init.php index 77608a5..de2f534 100644 --- a/src/init.php +++ b/src/init.php @@ -279,10 +279,24 @@ function get_unsafe_mttinfo($v) switch($v) { case 'theme_url': - $_mttinfo['theme_url'] = get_unsafe_mttinfo('mtt_url'). 'content/theme/'; + if (!isset($_mttinfo['theme_url'])) { + if ( Config::getUrl('url') == '' && Config::getUrl('mtt_url') == '' + && (!defined('MTT_USE_HTTPS') || !MTT_USE_HTTPS) ) { + $_mttinfo['theme_url'] = url_dir(getRequestUri()). 'content/theme/'; + } else { + $_mttinfo['theme_url'] = get_unsafe_mttinfo('mtt_url'). 'content/theme/'; + } + } return $_mttinfo['theme_url']; case 'content_url': - $_mttinfo['content_url'] = get_unsafe_mttinfo('mtt_url'). 'content/'; + if (!isset($_mttinfo['content_url'])) { + if ( Config::getUrl('url') == '' && Config::getUrl('mtt_url') == '' + && (!defined('MTT_USE_HTTPS') || !MTT_USE_HTTPS) ) { + $_mttinfo['content_url'] = url_dir(getRequestUri()). 'content/'; + } else { + $_mttinfo['content_url'] = get_unsafe_mttinfo('mtt_url'). 'content/'; + } + } return $_mttinfo['content_url']; case 'url': /* full url to homepage: directory with root index.php or custom index file in the root. */ @@ -290,7 +304,7 @@ function get_unsafe_mttinfo($v) /* Should not contain a query string. Have to be set in config if custom port is used or wrong detection. */ $_mttinfo['url'] = Config::getUrl('url'); if ($_mttinfo['url'] == '') { - $is_https = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') ? true : false; + $is_https = is_https(); $_mttinfo['url'] = ($is_https ? 'https://' : 'http://'). $_SERVER['HTTP_HOST']. url_dir(getRequestUri()); } return $_mttinfo['url']; @@ -330,6 +344,17 @@ function reset_mttinfo($key) unset( $_mttinfo[$key] ); } +function is_https(): bool +{ + if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') { + return true; + } + if (defined('MTT_USE_HTTPS') && MTT_USE_HTTPS) { + return true; + } + return false; +} + function jsonExit($data) { header('Content-type: application/json; charset=utf-8');