From: Christian Weiske Date: Mon, 7 Jul 2014 06:50:08 +0000 (+0200) Subject: automatically configure git paths (dir + public clone url) X-Git-Tag: v0.4.0~12 X-Git-Url: https://git.cweiske.de/phorkie.git/commitdiff_plain/f92fbaf636d620a0092fff8b715be9a493547b4f automatically configure git paths (dir + public clone url) --- diff --git a/data/config.default.php b/data/config.default.php index 2e588fa..5b56fc7 100644 --- a/data/config.default.php +++ b/data/config.default.php @@ -2,15 +2,21 @@ $pharFile = \Phar::running(); if ($pharFile == '') { $phorkieDir = __DIR__ . '/../'; + $wwwDir = $phorkieDir . 'www/'; } else { //remove phar:// from the path $phorkieDir = dirname(substr($pharFile, 7)) . '/'; + $wwwDir = $phorkieDir; } $GLOBALS['phorkie']['cfg'] = array( 'debug' => false, - 'gitdir' => $phorkieDir . 'repos/git/', - 'workdir' => $phorkieDir . 'repos/work/', + 'git' => array( + 'public' => '%BASEURL%' . 'repos/git/', + 'private' => null, + ), + 'gitdir' => $wwwDir . 'repos/git/', + 'workdir' => $wwwDir . 'repos/work/', 'tpl' => __DIR__ . '/templates/', 'baseurl' => null, 'avatars' => true, diff --git a/src/phorkie/Tools.php b/src/phorkie/Tools.php index e97c546..2febb29 100644 --- a/src/phorkie/Tools.php +++ b/src/phorkie/Tools.php @@ -48,6 +48,23 @@ class Tools return $prot . '://' . $_SERVER['HTTP_HOST'] . $GLOBALS['phorkie']['cfg']['baseurl'] . $path; } + /** + * Get the full URL to a path, but remove the .phar file from + * the base URL if necessary + * + * @param string $path Path to the file + * + * @return string Full URL without .phar/ + */ + public static function fullUrlNoPhar($path = '') + { + $base = static::fullUrl(); + if (substr($base, -6) == '.phar/') { + $base = dirname($base) . '/'; + } + return $base . $path; + } + /** * Removes malicious parts from a file name * diff --git a/www/www-header.php b/www/www-header.php index 5381eed..eaf1952 100644 --- a/www/www-header.php +++ b/www/www-header.php @@ -50,6 +50,12 @@ if (file_exists($cfgFilePath)) { if ($GLOBALS['phorkie']['cfg']['baseurl'] === null) { $GLOBALS['phorkie']['cfg']['baseurl'] = Tools::detectBaseUrl(); + if (substr($GLOBALS['phorkie']['cfg']['git']['public'], 0, 9) == '%BASEURL%') { + //make autoconfig work + $GLOBALS['phorkie']['cfg']['git']['public'] = Tools::fullUrlNoPhar( + substr($GLOBALS['phorkie']['cfg']['git']['public'], 9) + ); + } } // Set/Get git commit session variables