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