Project

General

Profile

1 1349 Luisehahne
<?php
2
/**
3
 *
4
 * @category        framework
5
 * @package         initialize
6 1694 Luisehahne
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1349 Luisehahne
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11 1374 Luisehahne
 * @requirements    PHP 5.2.2 and higher
12 1349 Luisehahne
 * @version         $Id$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15
 *
16
 */
17
18 1488 DarkViper
/* -------------------------------------------------------- */
19
// Must include code to stop this file being accessed directly
20 1499 DarkViper
require_once(dirname(__FILE__).'/globalExceptionHandler.php');
21 1637 darkviper
if(!defined('WB_URL')) { throw new IllegalFileException(); }
22 1488 DarkViper
/* -------------------------------------------------------- */
23 1617 darkviper
/**
24
 * sanitize $_SERVER['HTTP_REFERER']
25
 * @param string $sWbUrl qualified startup URL of current application
26
 */
27
	function SanitizeHttpReferer($sWbUrl = WB_URL) {
28
		$sTmpReferer = '';
29
		if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != '') {
30
			$aRefUrl = parse_url($_SERVER['HTTP_REFERER']);
31
			if ($aRefUrl !== false) {
32
				$aRefUrl['host'] = isset($aRefUrl['host']) ? $aRefUrl['host'] : '';
33
				$aRefUrl['path'] = isset($aRefUrl['path']) ? $aRefUrl['path'] : '';
34
				$aRefUrl['fragment'] = isset($aRefUrl['fragment']) ? '#'.$aRefUrl['fragment'] : '';
35
				$aWbUrl = parse_url(WB_URL);
36
				if ($aWbUrl !== false) {
37
					$aWbUrl['host'] = isset($aWbUrl['host']) ? $aWbUrl['host'] : '';
38
					$aWbUrl['path'] = isset($aWbUrl['path']) ? $aWbUrl['path'] : '';
39
					if (strpos($aRefUrl['host'].$aRefUrl['path'],
40
							   $aWbUrl['host'].$aWbUrl['path']) !== false) {
41
						$aRefUrl['path'] = preg_replace('#^'.$aWbUrl['path'].'#i', '', $aRefUrl['path']);
42
						$sTmpReferer = WB_URL.$aRefUrl['path'].$aRefUrl['fragment'];
43
					}
44
					unset($aWbUrl);
45
				}
46
				unset($aRefUrl);
47
			}
48
		}
49
		$_SERVER['HTTP_REFERER'] = $sTmpReferer;
50
	}
51 1680 darkviper
/* -------------------------------------------------------- */
52
	function SetInstallPathConstants() {
53
		if(!defined('DEBUG')){ define('DEBUG', false); }// Include config file
54
		if(!defined('ADMIN_DIRECTORY')){ define('ADMIN_DIRECTORY', 'admin'); }
55
		if(!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
56
			throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
57
		}
58
		if(!defined('WB_PATH')){ define('WB_PATH', dirname(dirname(__FILE__))); }
59
		if(!defined('ADMIN_URL')){ define('ADMIN_URL', WB_URL.'/'.ADMIN_DIRECTORY); }
60
		if(!defined('ADMIN_PATH')){ define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY); }
61
		if(!defined('WB_REL')){
62
			$x1 = parse_url(WB_URL);
63
			define('WB_REL', (isset($x1['path']) ? $x1['path'] : ''));
64
		}
65
		if(!defined('DOCUMENT_ROOT')) {
66
			define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(WB_REL, '/').'$/', '', WB_PATH));
67
		}
68
	}
69
/* -------------------------------------------------------- */
70
	$starttime = array_sum(explode(" ",microtime()));
71 1694 Luisehahne
	$iPhpDeclaredClasses =  sizeof(get_declared_classes());
72 1680 darkviper
	SetInstallPathConstants();
73
	SanitizeHttpReferer(WB_URL); // sanitize $_SERVER['HTTP_REFERER']
74 1687 darkviper
	if(!class_exists('WbAutoloader', false)){ include(dirname(__FILE__).'/WbAutoloader.php'); }
75
	WbAutoloader::doRegister(array(ADMIN_DIRECTORY=>'a', 'modules'=>'m'));
76
	require_once dirname(dirname(__FILE__)).'/include/Twig/Autoloader.php';
77
	Twig_Autoloader::register();
78 1462 DarkViper
	date_default_timezone_set('UTC');
79 1349 Luisehahne
	// Create database class
80 1682 darkviper
	$sSqlUrl = DB_TYPE.'://'.DB_USERNAME.':'.DB_PASSWORD.'@'.DB_HOST.'/'.DB_NAME;
81 1686 darkviper
	$database = WbDatabase::getInstance();
82 1683 darkviper
	$database->doConnect($sSqlUrl);
83 1680 darkviper
	// disable all kind of magic_quotes
84
	if(get_magic_quotes_gpc() || get_magic_quotes_runtime()) {
85
		@ini_set('magic_quotes_sybase', 0);
86
		@ini_set('magic_quotes_gpc', 0);
87
		@ini_set('magic_quotes_runtime', 0);
88
	}
89 1349 Luisehahne
	// Get website settings (title, keywords, description, header, and footer)
90
	$query_settings = "SELECT name,value FROM ".TABLE_PREFIX."settings";
91
	$get_settings = $database->query($query_settings);
92
	if($database->is_error()) { die($database->get_error()); }
93
	if($get_settings->numRows() == 0) { die("Settings not found"); }
94
	while($setting = $get_settings->fetchRow()) {
95
		$setting_name=strtoupper($setting['name']);
96
		$setting_value=$setting['value'];
97 1694 Luisehahne
//		if ($setting_value=='') {$setting_value=false;}
98
		if ($setting_value=='false'){$setting_value=false;}
99
		if ($setting_value=='true'){$setting_value=true;}
100 1349 Luisehahne
		@define($setting_name,$setting_value);
101
	}
102 1510 darkviper
	@define('DO_NOT_TRACK', (isset($_SERVER['HTTP_DNT'])));
103 1349 Luisehahne
	$string_file_mode = STRING_FILE_MODE;
104
	define('OCTAL_FILE_MODE',(int) octdec($string_file_mode));
105
	$string_dir_mode = STRING_DIR_MODE;
106
	define('OCTAL_DIR_MODE',(int) octdec($string_dir_mode));
107 1465 Luisehahne
	$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
108 1462 DarkViper
	$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
109
	require_once($sSecMod);
110 1349 Luisehahne
	if (!defined("WB_INSTALL_PROCESS")) {
111
		// get CAPTCHA and ASP settings
112
		$table = TABLE_PREFIX.'mod_captcha_control';
113 1462 DarkViper
		if( ($get_settings = $database->query("SELECT * FROM $table LIMIT 1")) ) {
114 1349 Luisehahne
			if($get_settings->numRows() == 0) { die("CAPTCHA-Settings not found"); }
115
			$setting = $get_settings->fetchRow();
116
			if($setting['enabled_captcha'] == '1') define('ENABLED_CAPTCHA', true);
117
			else define('ENABLED_CAPTCHA', false);
118
			if($setting['enabled_asp'] == '1') define('ENABLED_ASP', true);
119
			else define('ENABLED_ASP', false);
120
			define('CAPTCHA_TYPE', $setting['captcha_type']);
121
			define('ASP_SESSION_MIN_AGE', (int)$setting['asp_session_min_age']);
122
			define('ASP_VIEW_MIN_AGE', (int)$setting['asp_view_min_age']);
123
			define('ASP_INPUT_MIN_AGE', (int)$setting['asp_input_min_age']);
124
		}
125
	}
126
127
	// set error-reporting
128
	if(intval(ER_LEVEL) > 0 )
129
	{
130
		error_reporting(ER_LEVEL);
131 1352 Luisehahne
		if( intval(ini_get ( 'display_errors' )) == 0 )
132 1349 Luisehahne
		{
133
			ini_set('display_errors', 1);
134
		}
135
	}
136
	// Start a session
137
	if(!defined('SESSION_STARTED')) {
138
		session_name(APP_NAME.'_session_id');
139
		@session_start();
140
		define('SESSION_STARTED', true);
141
	}
142
	if(defined('ENABLED_ASP') && ENABLED_ASP && !isset($_SESSION['session_started']))
143
		$_SESSION['session_started'] = time();
144
145 1780 Luisehahne
146
147 1349 Luisehahne
	// Get users language
148 1780 Luisehahne
	$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
149
	$language = (intval(isset(${$requestMethod}['lang'])) ? ${$requestMethod}['lang'] : null);
150
	if(isset($language) AND $language != '' AND !is_numeric($language) AND strlen($language) == 2) {
151
		define('LANGUAGE', strtoupper($language));
152 1349 Luisehahne
		$_SESSION['LANGUAGE']=LANGUAGE;
153
	} else {
154
		if(isset($_SESSION['LANGUAGE']) AND $_SESSION['LANGUAGE'] != '') {
155
			define('LANGUAGE', $_SESSION['LANGUAGE']);
156
		} else {
157
			define('LANGUAGE', DEFAULT_LANGUAGE);
158
		}
159
	}
160 1680 darkviper
161 1349 Luisehahne
	// Load Language file
162
	if(!defined('LANGUAGE_LOADED')) {
163
		if(!file_exists(WB_PATH.'/languages/'.LANGUAGE.'.php')) {
164
			exit('Error loading language file '.LANGUAGE.', please check configuration');
165
		} else {
166
			require_once(WB_PATH.'/languages/'.LANGUAGE.'.php');
167
		}
168
	}
169 1680 darkviper
170 1349 Luisehahne
	// Get users timezone
171
	if(isset($_SESSION['TIMEZONE'])) {
172
		define('TIMEZONE', $_SESSION['TIMEZONE']);
173
	} else {
174
		define('TIMEZONE', DEFAULT_TIMEZONE);
175
	}
176
	// Get users date format
177
	if(isset($_SESSION['DATE_FORMAT'])) {
178
		define('DATE_FORMAT', $_SESSION['DATE_FORMAT']);
179
	} else {
180
		define('DATE_FORMAT', DEFAULT_DATE_FORMAT);
181
	}
182
	// Get users time format
183
	if(isset($_SESSION['TIME_FORMAT'])) {
184
		define('TIME_FORMAT', $_SESSION['TIME_FORMAT']);
185
	} else {
186
		define('TIME_FORMAT', DEFAULT_TIME_FORMAT);
187
	}
188
189
	// Set Theme dir
190
	define('THEME_URL', WB_URL.'/templates/'.DEFAULT_THEME);
191
	define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);
192
193 1680 darkviper
	// extended wb_settings
194 1349 Luisehahne
	define('EDIT_ONE_SECTION', false);
195
196
	define('EDITOR_WIDTH', 0);