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 25*bc3b6aecSandi require_once(DOKU_INC.'inc/lang/en/lang.php'); 26*bc3b6aecSandi 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); 94f62ea8a1Sandi if($p) return $p; 95f62ea8a1Sandi $p = realpath(DOKU_INC.$path); 96f62ea8a1Sandi return $p; 97f62ea8a1Sandi} 988c4f28e8Sjan 99ed7b5f09Sandi/** 100ed7b5f09Sandi * remove magic quotes recursivly 101ed7b5f09Sandi * 102ed7b5f09Sandi * @author Andreas Gohr <andi@splitbrain.org> 103ed7b5f09Sandi */ 104ed7b5f09Sandifunction remove_magic_quotes(&$array) { 105ed7b5f09Sandi foreach (array_keys($array) as $key) { 106ed7b5f09Sandi if (is_array($array[$key])) { 107ed7b5f09Sandi remove_magic_quotes($array[$key]); 108ed7b5f09Sandi }else { 109ed7b5f09Sandi $array[$key] = stripslashes($array[$key]); 110ed7b5f09Sandi } 111ed7b5f09Sandi } 112ed7b5f09Sandi} 113ed7b5f09Sandi 114ed7b5f09Sandi/** 115ed7b5f09Sandi * Returns the full absolute URL to the directory where 116ed7b5f09Sandi * DokuWiki is installed in (includes a trailing slash) 117ed7b5f09Sandi * 118ed7b5f09Sandi * @author Andreas Gohr <andi@splitbrain.org> 119ed7b5f09Sandi */ 120ed7b5f09Sandifunction getBaseURL($abs=false){ 121ed7b5f09Sandi global $conf; 122ed7b5f09Sandi //if canonical url enabled always return absolute 123ed7b5f09Sandi if($conf['canonical']) $abs = true; 124ed7b5f09Sandi 12592b83b77Sandi if($conf['basedir']){ 126919eeb46Sandi $dir = $conf['basedir'].'/'; 127bdc127a4Sandi }elseif($_SERVER['SCRIPT_NAME']){ 128bdc127a4Sandi $dir = dirname($_SERVER['SCRIPT_NAME']).'/'; 129093ec9e4Sandi }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){ 130093ec9e4Sandi $dir = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','', 131093ec9e4Sandi $_SERVER['SCRIPT_FILENAME']); 132093ec9e4Sandi $dir = dirname('/'.$dir).'/'; 13392b83b77Sandi }else{ 134ed7b5f09Sandi $dir = dirname($_SERVER['PHP_SELF']).'/'; 13592b83b77Sandi } 136ed7b5f09Sandi 137ed7b5f09Sandi $dir = str_replace('\\','/',$dir); #bugfix for weird WIN behaviour 138ed7b5f09Sandi $dir = preg_replace('#//+#','/',$dir); 139ed7b5f09Sandi 140f62ea8a1Sandi //handle script in lib/exe dir 141f62ea8a1Sandi $dir = preg_replace('!lib/exe/$!','',$dir); 142f62ea8a1Sandi 143ed7b5f09Sandi //finish here for relative URLs 144ed7b5f09Sandi if(!$abs) return $dir; 145ed7b5f09Sandi 146ed7b5f09Sandi $port = ':'.$_SERVER['SERVER_PORT']; 147ed7b5f09Sandi //remove port from hostheader as sent by IE 148ed7b5f09Sandi $host = preg_replace('/:.*$/','',$_SERVER['HTTP_HOST']); 149ed7b5f09Sandi 150ed7b5f09Sandi // see if HTTPS is enabled - apache leaves this empty when not available, 151ed7b5f09Sandi // IIS sets it to 'off', 'false' and 'disabled' are just guessing 152ed7b5f09Sandi if (preg_match('/^(|off|false|disabled)$/i',$_SERVER['HTTPS'])){ 153ed7b5f09Sandi $proto = 'http://'; 154ed7b5f09Sandi if ($_SERVER['SERVER_PORT'] == '80') { 155ed7b5f09Sandi $port=''; 156ed7b5f09Sandi } 157ed7b5f09Sandi }else{ 158ed7b5f09Sandi $proto = 'https://'; 159ed7b5f09Sandi if ($_SERVER['SERVER_PORT'] == '443') { 160ed7b5f09Sandi $port=''; 161ed7b5f09Sandi } 162ed7b5f09Sandi } 163ed7b5f09Sandi 164ed7b5f09Sandi return $proto.$host.$port.$dir; 165ed7b5f09Sandi} 166ed7b5f09Sandi 167b000c6d4Sandi/** 168b000c6d4Sandi * Append a PHP extension to a given file and adds an exit call 169b000c6d4Sandi * 170b000c6d4Sandi * This is used to migrate some old configfiles. An added PHP extension 171b000c6d4Sandi * ensures the contents are not shown to webusers even if .htaccess files 172b000c6d4Sandi * do not work 173b000c6d4Sandi * 174b000c6d4Sandi * @author Jan Decaluwe <jan@jandecaluwe.com> 175b000c6d4Sandi */ 1768c4f28e8Sjanfunction scriptify($file) { 1778c4f28e8Sjan // checks 1788c4f28e8Sjan if (!is_readable($file)) { 1798c4f28e8Sjan return; 1808c4f28e8Sjan } 1818c4f28e8Sjan $fn = $file.'.php'; 1828c4f28e8Sjan if (@file_exists($fn)) { 1838c4f28e8Sjan return; 1848c4f28e8Sjan } 1858c4f28e8Sjan $fh = fopen($fn, 'w'); 1868c4f28e8Sjan if (!$fh) { 1878c4f28e8Sjan die($fn.' is not writable!'); 1888c4f28e8Sjan } 1898c4f28e8Sjan // write php exit hack first 1908c4f28e8Sjan fwrite($fh, "# $fn\n"); 1918c4f28e8Sjan fwrite($fh, '# <?php exit()?>'."\n"); 1928c4f28e8Sjan fwrite($fh, "# Don't modify the lines above\n"); 1938c4f28e8Sjan fwrite($fh, "#\n"); 1948c4f28e8Sjan // copy existing lines 1958c4f28e8Sjan $lines = file($file); 1968c4f28e8Sjan foreach ($lines as $line){ 1978c4f28e8Sjan fwrite($fh, $line); 1988c4f28e8Sjan } 1993ba793e2Sandi fclose($fh); 200b000c6d4Sandi //try to rename the old file 201b000c6d4Sandi @rename($file,"$file.old"); 2028c4f28e8Sjan} 2038c4f28e8Sjan 204ed7b5f09Sandi 205340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 : 206