xref: /dokuwiki/inc/init.php (revision 0e1c636e20bd809a1d388e0c6f630b0ecda7086b)
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', '&amp;');
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  $dir = dirname($_SERVER['PHP_SELF']).'/';
97
98  $dir = str_replace('\\','/',$dir); #bugfix for weird WIN behaviour
99  $dir = preg_replace('#//+#','/',$dir);
100
101  //finish here for relative URLs
102  if(!$abs) return $dir;
103
104  $port = ':'.$_SERVER['SERVER_PORT'];
105  //remove port from hostheader as sent by IE
106  $host = preg_replace('/:.*$/','',$_SERVER['HTTP_HOST']);
107
108  // see if HTTPS is enabled - apache leaves this empty when not available,
109  // IIS sets it to 'off', 'false' and 'disabled' are just guessing
110  if (preg_match('/^(|off|false|disabled)$/i',$_SERVER['HTTPS'])){
111    $proto = 'http://';
112    if ($_SERVER['SERVER_PORT'] == '80') {
113      $port='';
114    }
115  }else{
116    $proto = 'https://';
117    if ($_SERVER['SERVER_PORT'] == '443') {
118      $port='';
119    }
120  }
121
122  return $proto.$host.$port.$dir;
123}
124
125
126?>
127