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