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