\n",$conf['dmode'])."\n";
# print "$name:".sprintf("umask:%04o
\n",$conf['umask'])."\n";
# print "$name:".sprintf("dmask:%04o
\n",$conf['dmask'])."\n";
# exit;
// make real paths and check them
init_paths();
init_files();
// automatic upgrade to script versions of certain files
scriptify(DOKU_CONF.'users.auth');
scriptify(DOKU_CONF.'acl.auth');
/**
* Checks paths from config file
*/
function init_paths(){
global $conf;
$paths = array('datadir' => 'pages',
'olddir' => 'attic',
'mediadir' => 'media',
'metadir' => 'meta',
'cachedir' => 'cache',
'lockdir' => 'locks',
'changelog' => 'changes.log');
foreach($paths as $c => $p){
if(!$conf[$c]) $conf[$c] = $conf['savedir'].'/'.$p;
$conf[$c] = init_path($conf[$c]);
if(!$conf[$c]) die("$c does not exist or isn't writable. Check config!");
}
}
/**
* Checks the existance of certain files and creates them if missing
*/
function init_files(){
global $conf;
$files = array( $conf['cachedir'].'/word.idx',
$conf['cachedir'].'/page.idx',
$conf['cachedir'].'/index.idx', );
foreach($files as $file){
if(!@file_exists($file)){
$fh = fopen($file,'a');
fclose($fh);
if(isset($conf['fmask'])) { chmod($file, $conf['fmask']); }
}
}
}
/**
* returns absolute path
*
* This tries the given path first, then checks in DOKU_INC
*/
function init_path($path){
$p = realpath($path);
if(@file_exists($p)) return $p;
$p = realpath(DOKU_INC.$path);
if(@file_exists($p)) return $p;
return '';
}
/**
* remove magic quotes recursivly
*
* @author Andreas Gohr
*/
function remove_magic_quotes(&$array) {
foreach (array_keys($array) as $key) {
if (is_array($array[$key])) {
remove_magic_quotes($array[$key]);
}else {
$array[$key] = stripslashes($array[$key]);
}
}
}
/**
* Returns the full absolute URL to the directory where
* DokuWiki is installed in (includes a trailing slash)
*
* @author Andreas Gohr
*/
function getBaseURL($abs=false){
global $conf;
//if canonical url enabled always return absolute
if($conf['canonical']) $abs = true;
if($conf['basedir']){
$dir = $conf['basedir'].'/';
}elseif(substr($_SERVER['SCRIPT_NAME'],-4) == '.php'){
$dir = dirname($_SERVER['SCRIPT_NAME']).'/';
}elseif(substr($_SERVER['PHP_SELF'],-4) == '.php'){
$dir = dirname($_SERVER['PHP_SELF']).'/';
}elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){
$dir = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
$_SERVER['SCRIPT_FILENAME']);
$dir = dirname('/'.$dir).'/';
}else{
$dir = './'; //probably wrong
}
$dir = str_replace('\\','/',$dir); #bugfix for weird WIN behaviour
$dir = preg_replace('#//+#','/',$dir);
//handle script in lib/exe dir
$dir = preg_replace('!lib/exe/$!','',$dir);
//finish here for relative URLs
if(!$abs) return $dir;
//use config option if available
if($conf['baseurl']) return $conf['baseurl'].$dir;
//split hostheader into host and port
list($host,$port) = explode(':',$_SERVER['HTTP_HOST']);
if(!$port) $port = $_SERVER['SERVER_PORT'];
if(!$port) $port = 80;
// see if HTTPS is enabled - apache leaves this empty when not available,
// IIS sets it to 'off', 'false' and 'disabled' are just guessing
if (preg_match('/^(|off|false|disabled)$/i',$_SERVER['HTTPS'])){
$proto = 'http://';
if ($port == '80') {
$port='';
}
}else{
$proto = 'https://';
if ($port == '443') {
$port='';
}
}
if($port) $port = ':'.$port;
return $proto.$host.$port.$dir;
}
/**
* Append a PHP extension to a given file and adds an exit call
*
* This is used to migrate some old configfiles. An added PHP extension
* ensures the contents are not shown to webusers even if .htaccess files
* do not work
*
* @author Jan Decaluwe
*/
function scriptify($file) {
// checks
if (!is_readable($file)) {
return;
}
$fn = $file.'.php';
if (@file_exists($fn)) {
return;
}
$fh = fopen($fn, 'w');
if (!$fh) {
die($fn.' is not writable!');
}
// write php exit hack first
fwrite($fh, "# $fn\n");
fwrite($fh, '# '."\n");
fwrite($fh, "# Don't modify the lines above\n");
fwrite($fh, "#\n");
// copy existing lines
$lines = file($file);
foreach ($lines as $line){
fwrite($fh, $line);
}
fclose($fh);
//try to rename the old file
@rename($file,"$file.old");
}
//Setup VIM: ex: et ts=2 enc=utf-8 :