1ed7b5f09Sandi<?php 2ed7b5f09Sandi/** 3ed7b5f09Sandi * Initialize some defaults needed for DokuWiki 4ed7b5f09Sandi */ 5ed7b5f09Sandi 6ed7b5f09Sandi // define the include path 7ed7b5f09Sandi if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); 8ad15db82Sandi 9c53ea5f2Sandi // set up error reporting to sane values 10c53ea5f2Sandi error_reporting(E_ALL ^ E_NOTICE); 11c53ea5f2Sandi 124724a577Sandi //prepare config array() 13ee20e7d1Sandi global $conf; 144724a577Sandi $conf = array(); 154724a577Sandi 16ad15db82Sandi // load the config file(s) 17ed7b5f09Sandi require_once(DOKU_INC.'conf/dokuwiki.php'); 18ad15db82Sandi @include_once(DOKU_INC.'conf/local.php'); 19ad15db82Sandi 20ad15db82Sandi //prepare language array 21ee20e7d1Sandi global $lang; 22ad15db82Sandi $lang = array(); 23ed7b5f09Sandi 2416521111Sandi //load the language files 25bc3b6aecSandi require_once(DOKU_INC.'inc/lang/en/lang.php'); 26bc3b6aecSandi require_once(DOKU_INC.'inc/lang/'.$conf['lang'].'/lang.php'); 2716521111Sandi 28ed7b5f09Sandi // define baseURL 29ed7b5f09Sandi if(!defined('DOKU_BASE')) define('DOKU_BASE',getBaseURL()); 30ed7b5f09Sandi if(!defined('DOKU_URL')) define('DOKU_URL',getBaseURL(true)); 31ed7b5f09Sandi 32ee20e7d1Sandi // define Plugin dir 33f62ea8a1Sandi if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 34ee20e7d1Sandi 35ed7b5f09Sandi // define main script 36ed7b5f09Sandi if(!defined('DOKU_SCRIPT')) define('DOKU_SCRIPT','doku.php'); 37ed7b5f09Sandi 386b13307fSandi // define Template baseURL 396b13307fSandi if(!defined('DOKU_TPL')) define('DOKU_TPL', 40f62ea8a1Sandi DOKU_BASE.'lib/tpl/'.$conf['template'].'/'); 416b13307fSandi 42ed7b5f09Sandi // make session rewrites XHTML compliant 433fc74836Sandi @ini_set('arg_separator.output', '&'); 44ed7b5f09Sandi 45ed7b5f09Sandi // init session 46ed7b5f09Sandi session_name("DokuWiki"); 476b13307fSandi if (!headers_sent()) session_start(); 48ed7b5f09Sandi 49ed7b5f09Sandi // kill magic quotes 50ed7b5f09Sandi if (get_magic_quotes_gpc()) { 51ed7b5f09Sandi if (!empty($_GET)) remove_magic_quotes($_GET); 52ed7b5f09Sandi if (!empty($_POST)) remove_magic_quotes($_POST); 53ed7b5f09Sandi if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE); 54ed7b5f09Sandi if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST); 55ed7b5f09Sandi if (!empty($_SESSION)) remove_magic_quotes($_SESSION); 563fc74836Sandi @ini_set('magic_quotes_gpc', 0); 57ed7b5f09Sandi } 583fc74836Sandi @set_magic_quotes_runtime(0); 593fc74836Sandi @ini_set('magic_quotes_sybase',0); 60ed7b5f09Sandi 61ed7b5f09Sandi // disable gzip if not available 62ed7b5f09Sandi if($conf['usegzip'] && !function_exists('gzopen')){ 63ed7b5f09Sandi $conf['usegzip'] = 0; 64ed7b5f09Sandi } 65ed7b5f09Sandi 66ed7b5f09Sandi // remember original umask 67ed7b5f09Sandi $conf['oldumask'] = umask(); 68ed7b5f09Sandi 69ed7b5f09Sandi // make absolute mediaweb 70ed7b5f09Sandi if(!preg_match('#^(https?://|/)#i',$conf['mediaweb'])){ 71ed7b5f09Sandi $conf['mediaweb'] = getBaseURL().$conf['mediaweb']; 72ed7b5f09Sandi } 73ed7b5f09Sandi 743dc3a5f1Sandi // make real paths and check them 75f62ea8a1Sandi $conf['datadir'] = init_path($conf['datadir']); 76e33d39a7Sandi if(!$conf['datadir']) die('Wrong datadir! Check config!'); 77f62ea8a1Sandi $conf['olddir'] = init_path($conf['olddir']); 78e33d39a7Sandi if(!$conf['olddir']) die('Wrong olddir! Check config!'); 79f62ea8a1Sandi $conf['mediadir'] = init_path($conf['mediadir']); 80b94418bbSjan if(!$conf['mediadir']) die('Wrong mediadir! Check config!'); 81ed7b5f09Sandi 828c4f28e8Sjan // automatic upgrade to script versions of certain files 83f62ea8a1Sandi scriptify(DOKU_INC.'conf/users.auth'); 84f62ea8a1Sandi scriptify(DOKU_INC.'conf/acl.auth'); 85f62ea8a1Sandi 86f62ea8a1Sandi 87f62ea8a1Sandi/** 88f62ea8a1Sandi * returns absolute path 89f62ea8a1Sandi * 90f62ea8a1Sandi * This tries the given past first, then checks in DOKU_INC 91f62ea8a1Sandi */ 92f62ea8a1Sandifunction init_path($path){ 93f62ea8a1Sandi $p = realpath($path); 94*8fc4e739Sandi if(is_dir($p)) return $p; 95f62ea8a1Sandi $p = realpath(DOKU_INC.$path); 96*8fc4e739Sandi if(is_dir($p)) return $p; 97*8fc4e739Sandi return ''; 98f62ea8a1Sandi} 998c4f28e8Sjan 100ed7b5f09Sandi/** 101ed7b5f09Sandi * remove magic quotes recursivly 102ed7b5f09Sandi * 103ed7b5f09Sandi * @author Andreas Gohr <andi@splitbrain.org> 104ed7b5f09Sandi */ 105ed7b5f09Sandifunction remove_magic_quotes(&$array) { 106ed7b5f09Sandi foreach (array_keys($array) as $key) { 107ed7b5f09Sandi if (is_array($array[$key])) { 108ed7b5f09Sandi remove_magic_quotes($array[$key]); 109ed7b5f09Sandi }else { 110ed7b5f09Sandi $array[$key] = stripslashes($array[$key]); 111ed7b5f09Sandi } 112ed7b5f09Sandi } 113ed7b5f09Sandi} 114ed7b5f09Sandi 115ed7b5f09Sandi/** 116ed7b5f09Sandi * Returns the full absolute URL to the directory where 117ed7b5f09Sandi * DokuWiki is installed in (includes a trailing slash) 118ed7b5f09Sandi * 119ed7b5f09Sandi * @author Andreas Gohr <andi@splitbrain.org> 120ed7b5f09Sandi */ 121ed7b5f09Sandifunction getBaseURL($abs=false){ 122ed7b5f09Sandi global $conf; 123ed7b5f09Sandi //if canonical url enabled always return absolute 124ed7b5f09Sandi if($conf['canonical']) $abs = true; 125ed7b5f09Sandi 12692b83b77Sandi if($conf['basedir']){ 127919eeb46Sandi $dir = $conf['basedir'].'/'; 128bdc127a4Sandi }elseif($_SERVER['SCRIPT_NAME']){ 129bdc127a4Sandi $dir = dirname($_SERVER['SCRIPT_NAME']).'/'; 130093ec9e4Sandi }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){ 131093ec9e4Sandi $dir = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','', 132093ec9e4Sandi $_SERVER['SCRIPT_FILENAME']); 133093ec9e4Sandi $dir = dirname('/'.$dir).'/'; 13492b83b77Sandi }else{ 135ed7b5f09Sandi $dir = dirname($_SERVER['PHP_SELF']).'/'; 13692b83b77Sandi } 137ed7b5f09Sandi 138ed7b5f09Sandi $dir = str_replace('\\','/',$dir); #bugfix for weird WIN behaviour 139ed7b5f09Sandi $dir = preg_replace('#//+#','/',$dir); 140ed7b5f09Sandi 141f62ea8a1Sandi //handle script in lib/exe dir 142f62ea8a1Sandi $dir = preg_replace('!lib/exe/$!','',$dir); 143f62ea8a1Sandi 144ed7b5f09Sandi //finish here for relative URLs 145ed7b5f09Sandi if(!$abs) return $dir; 146ed7b5f09Sandi 147ed7b5f09Sandi $port = ':'.$_SERVER['SERVER_PORT']; 148ed7b5f09Sandi //remove port from hostheader as sent by IE 149ed7b5f09Sandi $host = preg_replace('/:.*$/','',$_SERVER['HTTP_HOST']); 150ed7b5f09Sandi 151ed7b5f09Sandi // see if HTTPS is enabled - apache leaves this empty when not available, 152ed7b5f09Sandi // IIS sets it to 'off', 'false' and 'disabled' are just guessing 153ed7b5f09Sandi if (preg_match('/^(|off|false|disabled)$/i',$_SERVER['HTTPS'])){ 154ed7b5f09Sandi $proto = 'http://'; 155ed7b5f09Sandi if ($_SERVER['SERVER_PORT'] == '80') { 156ed7b5f09Sandi $port=''; 157ed7b5f09Sandi } 158ed7b5f09Sandi }else{ 159ed7b5f09Sandi $proto = 'https://'; 160ed7b5f09Sandi if ($_SERVER['SERVER_PORT'] == '443') { 161ed7b5f09Sandi $port=''; 162ed7b5f09Sandi } 163ed7b5f09Sandi } 164ed7b5f09Sandi 165ed7b5f09Sandi return $proto.$host.$port.$dir; 166ed7b5f09Sandi} 167ed7b5f09Sandi 168b000c6d4Sandi/** 169b000c6d4Sandi * Append a PHP extension to a given file and adds an exit call 170b000c6d4Sandi * 171b000c6d4Sandi * This is used to migrate some old configfiles. An added PHP extension 172b000c6d4Sandi * ensures the contents are not shown to webusers even if .htaccess files 173b000c6d4Sandi * do not work 174b000c6d4Sandi * 175b000c6d4Sandi * @author Jan Decaluwe <jan@jandecaluwe.com> 176b000c6d4Sandi */ 1778c4f28e8Sjanfunction scriptify($file) { 1788c4f28e8Sjan // checks 1798c4f28e8Sjan if (!is_readable($file)) { 1808c4f28e8Sjan return; 1818c4f28e8Sjan } 1828c4f28e8Sjan $fn = $file.'.php'; 1838c4f28e8Sjan if (@file_exists($fn)) { 1848c4f28e8Sjan return; 1858c4f28e8Sjan } 1868c4f28e8Sjan $fh = fopen($fn, 'w'); 1878c4f28e8Sjan if (!$fh) { 1888c4f28e8Sjan die($fn.' is not writable!'); 1898c4f28e8Sjan } 1908c4f28e8Sjan // write php exit hack first 1918c4f28e8Sjan fwrite($fh, "# $fn\n"); 1928c4f28e8Sjan fwrite($fh, '# <?php exit()?>'."\n"); 1938c4f28e8Sjan fwrite($fh, "# Don't modify the lines above\n"); 1948c4f28e8Sjan fwrite($fh, "#\n"); 1958c4f28e8Sjan // copy existing lines 1968c4f28e8Sjan $lines = file($file); 1978c4f28e8Sjan foreach ($lines as $line){ 1988c4f28e8Sjan fwrite($fh, $line); 1998c4f28e8Sjan } 2003ba793e2Sandi fclose($fh); 201b000c6d4Sandi //try to rename the old file 202b000c6d4Sandi @rename($file,"$file.old"); 2038c4f28e8Sjan} 2048c4f28e8Sjan 205ed7b5f09Sandi 206340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 : 207