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