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