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__).'/../').'/'); 8*ad15db82Sandi 9*ad15db82Sandi // load the config file(s) 10ed7b5f09Sandi require_once(DOKU_INC.'conf/dokuwiki.php'); 11*ad15db82Sandi @include_once(DOKU_INC.'conf/local.php'); 12*ad15db82Sandi 13*ad15db82Sandi //prepare language array 14*ad15db82Sandi $lang = array(); 15ed7b5f09Sandi 16ed7b5f09Sandi // define baseURL 17ed7b5f09Sandi if(!defined('DOKU_BASE')) define('DOKU_BASE',getBaseURL()); 18ed7b5f09Sandi if(!defined('DOKU_URL')) define('DOKU_URL',getBaseURL(true)); 19ed7b5f09Sandi 20ed7b5f09Sandi // define main script 21ed7b5f09Sandi if(!defined('DOKU_SCRIPT')) define('DOKU_SCRIPT','doku.php'); 22ed7b5f09Sandi 23ed7b5f09Sandi // set up error reporting to sane values 24ed7b5f09Sandi error_reporting(E_ALL ^ E_NOTICE); 25ed7b5f09Sandi 26ed7b5f09Sandi // make session rewrites XHTML compliant 27ed7b5f09Sandi ini_set('arg_separator.output', '&'); 28ed7b5f09Sandi 29ed7b5f09Sandi // init session 30ed7b5f09Sandi session_name("DokuWiki"); 31ed7b5f09Sandi session_start(); 32ed7b5f09Sandi 33ed7b5f09Sandi // kill magic quotes 34ed7b5f09Sandi if (get_magic_quotes_gpc()) { 35ed7b5f09Sandi if (!empty($_GET)) remove_magic_quotes($_GET); 36ed7b5f09Sandi if (!empty($_POST)) remove_magic_quotes($_POST); 37ed7b5f09Sandi if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE); 38ed7b5f09Sandi if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST); 39ed7b5f09Sandi if (!empty($_SESSION)) remove_magic_quotes($_SESSION); 40ed7b5f09Sandi ini_set('magic_quotes_gpc', 0); 41ed7b5f09Sandi } 42ed7b5f09Sandi set_magic_quotes_runtime(0); 43ed7b5f09Sandi ini_set('magic_quotes_sybase',0); 44ed7b5f09Sandi 45ed7b5f09Sandi // disable gzip if not available 46ed7b5f09Sandi if($conf['usegzip'] && !function_exists('gzopen')){ 47ed7b5f09Sandi $conf['usegzip'] = 0; 48ed7b5f09Sandi } 49ed7b5f09Sandi 50ed7b5f09Sandi // remember original umask 51ed7b5f09Sandi $conf['oldumask'] = umask(); 52ed7b5f09Sandi 53ed7b5f09Sandi // make absolute mediaweb 54ed7b5f09Sandi if(!preg_match('#^(https?://|/)#i',$conf['mediaweb'])){ 55ed7b5f09Sandi $conf['mediaweb'] = getBaseURL().$conf['mediaweb']; 56ed7b5f09Sandi } 57ed7b5f09Sandi 583dc3a5f1Sandi // make real paths and check them 593dc3a5f1Sandi $conf['datadir'] = realpath($conf['datadir']); 603dc3a5f1Sandi if(!$conf['datadir']) msg('Wrong datadir!',-1); 613dc3a5f1Sandi $conf['olddir'] = realpath($conf['olddir']); 623dc3a5f1Sandi if(!$conf['olddir']) msg('Wrong olddir!',-1); 633dc3a5f1Sandi $conf['mediadir'] = realpath($conf['mediadir']); 643dc3a5f1Sandi if(!$conf['mediadir']) msg('Wrong mediadir!',-1); 65ed7b5f09Sandi 66ed7b5f09Sandi/** 67ed7b5f09Sandi * remove magic quotes recursivly 68ed7b5f09Sandi * 69ed7b5f09Sandi * @author Andreas Gohr <andi@splitbrain.org> 70ed7b5f09Sandi */ 71ed7b5f09Sandifunction remove_magic_quotes(&$array) { 72ed7b5f09Sandi foreach (array_keys($array) as $key) { 73ed7b5f09Sandi if (is_array($array[$key])) { 74ed7b5f09Sandi remove_magic_quotes($array[$key]); 75ed7b5f09Sandi }else { 76ed7b5f09Sandi $array[$key] = stripslashes($array[$key]); 77ed7b5f09Sandi } 78ed7b5f09Sandi } 79ed7b5f09Sandi} 80ed7b5f09Sandi 81ed7b5f09Sandi/** 82ed7b5f09Sandi * Returns the full absolute URL to the directory where 83ed7b5f09Sandi * DokuWiki is installed in (includes a trailing slash) 84ed7b5f09Sandi * 85ed7b5f09Sandi * @author Andreas Gohr <andi@splitbrain.org> 86ed7b5f09Sandi */ 87ed7b5f09Sandifunction getBaseURL($abs=false){ 88ed7b5f09Sandi global $conf; 89ed7b5f09Sandi //if canonical url enabled always return absolute 90ed7b5f09Sandi if($conf['canonical']) $abs = true; 91ed7b5f09Sandi 92ed7b5f09Sandi $dir = dirname($_SERVER['PHP_SELF']).'/'; 93ed7b5f09Sandi 94ed7b5f09Sandi $dir = str_replace('\\','/',$dir); #bugfix for weird WIN behaviour 95ed7b5f09Sandi $dir = preg_replace('#//+#','/',$dir); 96ed7b5f09Sandi 97ed7b5f09Sandi //finish here for relative URLs 98ed7b5f09Sandi if(!$abs) return $dir; 99ed7b5f09Sandi 100ed7b5f09Sandi $port = ':'.$_SERVER['SERVER_PORT']; 101ed7b5f09Sandi //remove port from hostheader as sent by IE 102ed7b5f09Sandi $host = preg_replace('/:.*$/','',$_SERVER['HTTP_HOST']); 103ed7b5f09Sandi 104ed7b5f09Sandi // see if HTTPS is enabled - apache leaves this empty when not available, 105ed7b5f09Sandi // IIS sets it to 'off', 'false' and 'disabled' are just guessing 106ed7b5f09Sandi if (preg_match('/^(|off|false|disabled)$/i',$_SERVER['HTTPS'])){ 107ed7b5f09Sandi $proto = 'http://'; 108ed7b5f09Sandi if ($_SERVER['SERVER_PORT'] == '80') { 109ed7b5f09Sandi $port=''; 110ed7b5f09Sandi } 111ed7b5f09Sandi }else{ 112ed7b5f09Sandi $proto = 'https://'; 113ed7b5f09Sandi if ($_SERVER['SERVER_PORT'] == '443') { 114ed7b5f09Sandi $port=''; 115ed7b5f09Sandi } 116ed7b5f09Sandi } 117ed7b5f09Sandi 118ed7b5f09Sandi return $proto.$host.$port.$dir; 119ed7b5f09Sandi} 120ed7b5f09Sandi 121ed7b5f09Sandi 122ed7b5f09Sandi?> 123