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