diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2014-07-04 07:33:29 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2014-07-04 07:33:29 +0200 |
| commit | 979fd71983f72991b7b698d0fa57b46213503672 (patch) | |
| tree | aabd3e5fa1a7f825e63de5b4ba6e3f76b70928a9 | |
| parent | bbe055e8c11da1ec0eddee461a31fb5acf382c92 (diff) | |
| download | phorkie-979fd71983f72991b7b698d0fa57b46213503672.tar.gz phorkie-979fd71983f72991b7b698d0fa57b46213503672.zip | |
detect baseurl automatically, load config file from .phar
| -rw-r--r-- | data/config.default.php | 2 | ||||
| -rw-r--r-- | src/phorkie/Tools.php | 27 | ||||
| -rw-r--r-- | www/www-header.php | 17 |
3 files changed, 42 insertions, 4 deletions
diff --git a/data/config.default.php b/data/config.default.php index 8f796f4..eb98efd 100644 --- a/data/config.default.php +++ b/data/config.default.php @@ -4,7 +4,7 @@ $GLOBALS['phorkie']['cfg'] = array( 'gitdir' => __DIR__ . '/../repos/git/', 'workdir' => __DIR__ . '/../repos/work/', 'tpl' => __DIR__ . '/templates/', - 'baseurl' => '/', + 'baseurl' => null, 'avatars' => true, 'css' => '', 'iconpng' => '',//phorkie browser icon (favicon) diff --git a/src/phorkie/Tools.php b/src/phorkie/Tools.php index fc815cc..7c9c46e 100644 --- a/src/phorkie/Tools.php +++ b/src/phorkie/Tools.php @@ -70,6 +70,31 @@ class Tools return $file; } -} + public static function detectBaseUrl() + { + if (!isset($_SERVER['REQUEST_URI']) + || !isset($_SERVER['SCRIPT_NAME']) + ) { + return '/'; + } + + $scriptName = $_SERVER['SCRIPT_NAME']; + $requestUri = $_SERVER['REQUEST_URI']; + if (substr($scriptName, -4) != '.php') { + //a phar + return $scriptName . '/'; + } + + if (substr($requestUri, -4) != '.php') { + $requestUri .= '.php'; + } + $snl = strlen($scriptName); + if (substr($requestUri, -$snl) == $scriptName) { + return substr($requestUri, 0, -$snl) . '/'; + } + + return '/'; + } +} ?> diff --git a/www/www-header.php b/www/www-header.php index b58bd95..94ee1d7 100644 --- a/www/www-header.php +++ b/www/www-header.php @@ -30,8 +30,21 @@ set_exception_handler( ); require_once __DIR__ . '/../data/config.default.php'; -if (file_exists(__DIR__ . '/../data/config.php')) { - require_once __DIR__ . '/../data/config.php'; +$pharFile = \Phar::running(); +if ($pharFile == '') { + $cfgFilePath = __DIR__ . '/../data/config.php'; +} else { + //remove phar:// from the path + $cfgFilePath = substr($pharFile, 7) . '.config.php'; +} +$GLOBALS['phorkie']['cfgfiles'][$cfgFilePath] = false; +if (file_exists($cfgFilePath)) { + $GLOBALS['phorkie']['cfgfiles'][$cfgFilePath] = true; + require_once $cfgFilePath; +} + +if ($GLOBALS['phorkie']['cfg']['baseurl'] === null) { + $GLOBALS['phorkie']['cfg']['baseurl'] = Tools::detectBaseUrl(); } // Set/Get git commit session variables |
