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