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() 134724a577Sandi $conf = array(); 144724a577Sandi 15ad15db82Sandi // load the config file(s) 16ed7b5f09Sandi require_once(DOKU_INC.'conf/dokuwiki.php'); 17ad15db82Sandi @include_once(DOKU_INC.'conf/local.php'); 18ad15db82Sandi 19ad15db82Sandi //prepare language array 20ad15db82Sandi $lang = array(); 21ed7b5f09Sandi 22ed7b5f09Sandi // define baseURL 23ed7b5f09Sandi if(!defined('DOKU_BASE')) define('DOKU_BASE',getBaseURL()); 24ed7b5f09Sandi if(!defined('DOKU_URL')) define('DOKU_URL',getBaseURL(true)); 25ed7b5f09Sandi 26ed7b5f09Sandi // define main script 27ed7b5f09Sandi if(!defined('DOKU_SCRIPT')) define('DOKU_SCRIPT','doku.php'); 28ed7b5f09Sandi 296b13307fSandi // define Template baseURL 306b13307fSandi if(!defined('DOKU_TPL')) define('DOKU_TPL', 316b13307fSandi DOKU_BASE.'tpl/'.$conf['template'].'/'); 326b13307fSandi 33ed7b5f09Sandi // make session rewrites XHTML compliant 343fc74836Sandi @ini_set('arg_separator.output', '&'); 35ed7b5f09Sandi 36ed7b5f09Sandi // init session 37ed7b5f09Sandi session_name("DokuWiki"); 386b13307fSandi if (!headers_sent()) session_start(); 39ed7b5f09Sandi 40ed7b5f09Sandi // kill magic quotes 41ed7b5f09Sandi if (get_magic_quotes_gpc()) { 42ed7b5f09Sandi if (!empty($_GET)) remove_magic_quotes($_GET); 43ed7b5f09Sandi if (!empty($_POST)) remove_magic_quotes($_POST); 44ed7b5f09Sandi if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE); 45ed7b5f09Sandi if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST); 46ed7b5f09Sandi if (!empty($_SESSION)) remove_magic_quotes($_SESSION); 473fc74836Sandi @ini_set('magic_quotes_gpc', 0); 48ed7b5f09Sandi } 493fc74836Sandi @set_magic_quotes_runtime(0); 503fc74836Sandi @ini_set('magic_quotes_sybase',0); 51ed7b5f09Sandi 52ed7b5f09Sandi // disable gzip if not available 53ed7b5f09Sandi if($conf['usegzip'] && !function_exists('gzopen')){ 54ed7b5f09Sandi $conf['usegzip'] = 0; 55ed7b5f09Sandi } 56ed7b5f09Sandi 57ed7b5f09Sandi // remember original umask 58ed7b5f09Sandi $conf['oldumask'] = umask(); 59ed7b5f09Sandi 60ed7b5f09Sandi // make absolute mediaweb 61ed7b5f09Sandi if(!preg_match('#^(https?://|/)#i',$conf['mediaweb'])){ 62ed7b5f09Sandi $conf['mediaweb'] = getBaseURL().$conf['mediaweb']; 63ed7b5f09Sandi } 64ed7b5f09Sandi 653dc3a5f1Sandi // make real paths and check them 663dc3a5f1Sandi $conf['datadir'] = realpath($conf['datadir']); 67e33d39a7Sandi if(!$conf['datadir']) die('Wrong datadir! Check config!'); 683dc3a5f1Sandi $conf['olddir'] = realpath($conf['olddir']); 69e33d39a7Sandi if(!$conf['olddir']) die('Wrong olddir! Check config!'); 703dc3a5f1Sandi $conf['mediadir'] = realpath($conf['mediadir']); 71b94418bbSjan if(!$conf['mediadir']) die('Wrong mediadir! Check config!'); 72ed7b5f09Sandi 738c4f28e8Sjan // automatic upgrade to script versions of certain files 748c4f28e8Sjan scriptify('conf/users.auth'); 758c4f28e8Sjan scriptify('conf/acl.auth'); 768c4f28e8Sjan 77ed7b5f09Sandi/** 78ed7b5f09Sandi * remove magic quotes recursivly 79ed7b5f09Sandi * 80ed7b5f09Sandi * @author Andreas Gohr <andi@splitbrain.org> 81ed7b5f09Sandi */ 82ed7b5f09Sandifunction remove_magic_quotes(&$array) { 83ed7b5f09Sandi foreach (array_keys($array) as $key) { 84ed7b5f09Sandi if (is_array($array[$key])) { 85ed7b5f09Sandi remove_magic_quotes($array[$key]); 86ed7b5f09Sandi }else { 87ed7b5f09Sandi $array[$key] = stripslashes($array[$key]); 88ed7b5f09Sandi } 89ed7b5f09Sandi } 90ed7b5f09Sandi} 91ed7b5f09Sandi 92ed7b5f09Sandi/** 93ed7b5f09Sandi * Returns the full absolute URL to the directory where 94ed7b5f09Sandi * DokuWiki is installed in (includes a trailing slash) 95ed7b5f09Sandi * 96ed7b5f09Sandi * @author Andreas Gohr <andi@splitbrain.org> 97ed7b5f09Sandi */ 98ed7b5f09Sandifunction getBaseURL($abs=false){ 99ed7b5f09Sandi global $conf; 100ed7b5f09Sandi //if canonical url enabled always return absolute 101ed7b5f09Sandi if($conf['canonical']) $abs = true; 102ed7b5f09Sandi 10392b83b77Sandi if($conf['basedir']){ 104919eeb46Sandi $dir = $conf['basedir'].'/'; 105bdc127a4Sandi }elseif($_SERVER['SCRIPT_NAME']){ 106bdc127a4Sandi $dir = dirname($_SERVER['SCRIPT_NAME']).'/'; 107093ec9e4Sandi }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){ 108093ec9e4Sandi $dir = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','', 109093ec9e4Sandi $_SERVER['SCRIPT_FILENAME']); 110093ec9e4Sandi $dir = dirname('/'.$dir).'/'; 11192b83b77Sandi }else{ 112ed7b5f09Sandi $dir = dirname($_SERVER['PHP_SELF']).'/'; 11392b83b77Sandi } 114ed7b5f09Sandi 115ed7b5f09Sandi $dir = str_replace('\\','/',$dir); #bugfix for weird WIN behaviour 116ed7b5f09Sandi $dir = preg_replace('#//+#','/',$dir); 117ed7b5f09Sandi 118ed7b5f09Sandi //finish here for relative URLs 119ed7b5f09Sandi if(!$abs) return $dir; 120ed7b5f09Sandi 121ed7b5f09Sandi $port = ':'.$_SERVER['SERVER_PORT']; 122ed7b5f09Sandi //remove port from hostheader as sent by IE 123ed7b5f09Sandi $host = preg_replace('/:.*$/','',$_SERVER['HTTP_HOST']); 124ed7b5f09Sandi 125ed7b5f09Sandi // see if HTTPS is enabled - apache leaves this empty when not available, 126ed7b5f09Sandi // IIS sets it to 'off', 'false' and 'disabled' are just guessing 127ed7b5f09Sandi if (preg_match('/^(|off|false|disabled)$/i',$_SERVER['HTTPS'])){ 128ed7b5f09Sandi $proto = 'http://'; 129ed7b5f09Sandi if ($_SERVER['SERVER_PORT'] == '80') { 130ed7b5f09Sandi $port=''; 131ed7b5f09Sandi } 132ed7b5f09Sandi }else{ 133ed7b5f09Sandi $proto = 'https://'; 134ed7b5f09Sandi if ($_SERVER['SERVER_PORT'] == '443') { 135ed7b5f09Sandi $port=''; 136ed7b5f09Sandi } 137ed7b5f09Sandi } 138ed7b5f09Sandi 139ed7b5f09Sandi return $proto.$host.$port.$dir; 140ed7b5f09Sandi} 141ed7b5f09Sandi 142*b000c6d4Sandi/** 143*b000c6d4Sandi * Append a PHP extension to a given file and adds an exit call 144*b000c6d4Sandi * 145*b000c6d4Sandi * This is used to migrate some old configfiles. An added PHP extension 146*b000c6d4Sandi * ensures the contents are not shown to webusers even if .htaccess files 147*b000c6d4Sandi * do not work 148*b000c6d4Sandi * 149*b000c6d4Sandi * @author Jan Decaluwe <jan@jandecaluwe.com> 150*b000c6d4Sandi */ 1518c4f28e8Sjanfunction scriptify($file) { 1528c4f28e8Sjan // checks 1538c4f28e8Sjan if (!is_readable($file)) { 1548c4f28e8Sjan return; 1558c4f28e8Sjan } 1568c4f28e8Sjan $fn = $file.'.php'; 1578c4f28e8Sjan if (@file_exists($fn)) { 1588c4f28e8Sjan return; 1598c4f28e8Sjan } 1608c4f28e8Sjan $fh = fopen($fn, 'w'); 1618c4f28e8Sjan if (!$fh) { 1628c4f28e8Sjan die($fn.' is not writable!'); 1638c4f28e8Sjan } 1648c4f28e8Sjan // write php exit hack first 1658c4f28e8Sjan fwrite($fh, "# $fn\n"); 1668c4f28e8Sjan fwrite($fh, '# <?php exit()?>'."\n"); 1678c4f28e8Sjan fwrite($fh, "# Don't modify the lines above\n"); 1688c4f28e8Sjan fwrite($fh, "#\n"); 1698c4f28e8Sjan // copy existing lines 1708c4f28e8Sjan $lines = file($file); 1718c4f28e8Sjan foreach ($lines as $line){ 1728c4f28e8Sjan fwrite($fh, $line); 1738c4f28e8Sjan } 1743ba793e2Sandi fclose($fh); 175*b000c6d4Sandi //try to rename the old file 176*b000c6d4Sandi @rename($file,"$file.old"); 1778c4f28e8Sjan} 1788c4f28e8Sjan 179ed7b5f09Sandi 180340756e4Sandi//Setup VIM: ex: et ts=2 enc=utf-8 : 181