protected function getPaths(&$urlconf, $pseudoScriptName = '', $isCli = false)
{
// retrieve the script path+name.
// for cli, it will be the path from the directory were we execute the script (given to the php exec).
// for web, it is the path from the root of the url
if ($pseudoScriptName) {
$urlconf['urlScript'] = $pseudoScriptName;
} else {
if ($urlconf['scriptNameServerVariable'] == '') {
$urlconf['scriptNameServerVariable'] = self::findServerName('.php', $isCli);
}
$urlconf['urlScript'] = $_SERVER[$urlconf['scriptNameServerVariable']];
}
// now we separate the path and the name of the script, and then the basePath
if ($isCli) {
$lastslash = strrpos($urlconf['urlScript'], DIRECTORY_SEPARATOR);
if ($lastslash === false) {
$urlconf['urlScriptPath'] = $pseudoScriptName ? App::appPath('/scripts/') : getcwd() . '/';
$urlconf['urlScriptName'] = $urlconf['urlScript'];
} else {
$urlconf['urlScriptPath'] = getcwd() . '/' . substr($urlconf['urlScript'], 0, $lastslash) . '/';
$urlconf['urlScriptName'] = substr($urlconf['urlScript'], $lastslash + 1);
}
$basepath = $urlconf['urlScriptPath'];
$snp = $urlconf['urlScriptName'];
$urlconf['urlScript'] = $basepath . $snp;
} else {
$lastslash = strrpos($urlconf['urlScript'], '/');
$urlconf['urlScriptPath'] = substr($urlconf['urlScript'], 0, $lastslash) . '/';
$urlconf['urlScriptName'] = substr($urlconf['urlScript'], $lastslash + 1);
$basepath = $urlconf['basePath'];
if ($basepath == '') {
// for beginners or simple site, we "guess" the base path
$basepath = $localBasePath = $urlconf['urlScriptPath'];
} else {
if ($basepath != '/') {
if ($basepath[0] != '/') {
$basepath = '/' . $basepath;
}
if (substr($basepath, -1) != '/') {
$basepath .= '/';
}
}
if ($pseudoScriptName) {
// with pseudoScriptName, we aren't in a true context, we could be in a cli context
// (the installer), and we want the path like when we are in a web context.
// $pseudoScriptName is supposed to be relative to the basePath
$urlconf['urlScriptPath'] = substr($basepath, 0, -1) . $urlconf['urlScriptPath'];
$urlconf['urlScript'] = $urlconf['urlScriptPath'] . $urlconf['urlScriptName'];
}
$localBasePath = $basepath;
if ($urlconf['backendBasePath']) {
$localBasePath = $urlconf['backendBasePath'];
// we have to change urlScriptPath. it may contains the base path of the backend server
// we should replace this base path by the basePath of the frontend server
if (strpos($urlconf['urlScriptPath'], $urlconf['backendBasePath']) === 0) {
$urlconf['urlScriptPath'] = $basepath . substr($urlconf['urlScriptPath'], strlen($urlconf['backendBasePath']));
} else {
$urlconf['urlScriptPath'] = $basepath . substr($urlconf['urlScriptPath'], 1);
}
} elseif (strpos($urlconf['urlScriptPath'], $basepath) !== 0) {
throw new Exception('Error in main configuration on basePath -- basePath (' . $basepath . ') in config file doesn\'t correspond to current base path. You should setup it to ' . $urlconf['urlScriptPath']);
}
}
$urlconf['basePath'] = $basepath;
if ($urlconf['jelixWWWPath'][0] != '/') {
$urlconf['jelixWWWPath'] = $basepath . $urlconf['jelixWWWPath'];
}
if ($urlconf['jqueryPath'][0] != '/') {
$urlconf['jqueryPath'] = $basepath . $urlconf['jqueryPath'];
}
$snp = substr($urlconf['urlScript'], strlen($localBasePath));
if ($localBasePath == '/') {
$urlconf['documentRoot'] = App::wwwPath();
} else {
if (strpos(App::wwwPath(), $localBasePath) === false) {
if (isset($_SERVER['DOCUMENT_ROOT'])) {
$urlconf['documentRoot'] = $_SERVER['DOCUMENT_ROOT'];
} else {
$urlconf['documentRoot'] = App::wwwPath();
}
} else {
$urlconf['documentRoot'] = substr(App::wwwPath(), 0, -strlen($localBasePath));
}
}
}
$pos = strrpos($snp, '.php');
if ($pos !== false) {
$snp = substr($snp, 0, $pos);
}
$urlconf['urlScriptId'] = $snp;
$urlconf['urlScriptIdenc'] = rawurlencode($snp);
}