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