Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        framework
5
 * @package         initialize
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: initialize.php 1683 2012-05-03 14:43:27Z darkviper $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/initialize.php $
15
 * @lastmodified    $Date: 2012-05-03 16:43:27 +0200 (Thu, 03 May 2012) $
16
 *
17
 */
18

    
19
/* -------------------------------------------------------- */
20
// Must include code to stop this file being accessed directly
21
require_once(dirname(__FILE__).'/globalExceptionHandler.php');
22
if(!defined('WB_URL')) { throw new IllegalFileException(); }
23
/* -------------------------------------------------------- */
24
/**
25
 * sanitize $_SERVER['HTTP_REFERER']
26
 * @param string $sWbUrl qualified startup URL of current application
27
 */
28
	function SanitizeHttpReferer($sWbUrl = WB_URL) {
29
		$sTmpReferer = '';
30
		if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != '') {
31
			$aRefUrl = parse_url($_SERVER['HTTP_REFERER']);
32
			if ($aRefUrl !== false) {
33
				$aRefUrl['host'] = isset($aRefUrl['host']) ? $aRefUrl['host'] : '';
34
				$aRefUrl['path'] = isset($aRefUrl['path']) ? $aRefUrl['path'] : '';
35
				$aRefUrl['fragment'] = isset($aRefUrl['fragment']) ? '#'.$aRefUrl['fragment'] : '';
36
				$aWbUrl = parse_url(WB_URL);
37
				if ($aWbUrl !== false) {
38
					$aWbUrl['host'] = isset($aWbUrl['host']) ? $aWbUrl['host'] : '';
39
					$aWbUrl['path'] = isset($aWbUrl['path']) ? $aWbUrl['path'] : '';
40
					if (strpos($aRefUrl['host'].$aRefUrl['path'],
41
							   $aWbUrl['host'].$aWbUrl['path']) !== false) {
42
						$aRefUrl['path'] = preg_replace('#^'.$aWbUrl['path'].'#i', '', $aRefUrl['path']);
43
						$sTmpReferer = WB_URL.$aRefUrl['path'].$aRefUrl['fragment'];
44
					}
45
					unset($aWbUrl);
46
				}
47
				unset($aRefUrl);
48
			}
49
		}
50
		$_SERVER['HTTP_REFERER'] = $sTmpReferer;
51
	}
52
/* -------------------------------------------------------- */
53
/**
54
 * Autoloader to load classes according to the new WB-2.9 standard
55
 * @param string $sClassName name of the requested class
56
 */
57
	function CoreAutoloader($sClassName) {
58
		$iCount = 0;
59
		$aSearch = array('/^m_/i', '/^a_/i');
60
		$aReplace = array('modules_', ADMIN_DIRECTORY.'_' );
61
		$sClassName = preg_replace($aSearch, $aReplace, $sClassName, 1, $iCount);
62
		if(!$iCount) { $sClassName = 'framework_'.$sClassName; }
63
		$sFileName = WB_PATH.'/'.str_replace('_', '/', $sClassName).'.php';
64
		if(file_exists($sFileName)) {
65
			include($sFileName);
66
		}
67
	}
68
/* -------------------------------------------------------- */
69
	function SetInstallPathConstants() {
70
		if(!defined('DEBUG')){ define('DEBUG', false); }// Include config file
71
		if(!defined('ADMIN_DIRECTORY')){ define('ADMIN_DIRECTORY', 'admin'); }
72
		if(!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
73
			throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
74
		}
75
		if(!defined('WB_PATH')){ define('WB_PATH', dirname(dirname(__FILE__))); }
76
		if(!defined('ADMIN_URL')){ define('ADMIN_URL', WB_URL.'/'.ADMIN_DIRECTORY); }
77
		if(!defined('ADMIN_PATH')){ define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY); }
78
		if(!defined('WB_REL')){
79
			$x1 = parse_url(WB_URL);
80
			define('WB_REL', (isset($x1['path']) ? $x1['path'] : ''));
81
		}
82
		if(!defined('DOCUMENT_ROOT')) {
83
			define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(WB_REL, '/').'$/', '', WB_PATH));
84
		}
85
	}
86
/* -------------------------------------------------------- */
87
	$starttime = array_sum(explode(" ",microtime()));
88
	SetInstallPathConstants();
89
	SanitizeHttpReferer(WB_URL); // sanitize $_SERVER['HTTP_REFERER']
90
	spl_autoload_register('CoreAutoloader'); // activate core autoloader
91
	date_default_timezone_set('UTC');
92
	// Create database class
93
	$sSqlUrl = DB_TYPE.'://'.DB_USERNAME.':'.DB_PASSWORD.'@'.DB_HOST.'/'.DB_NAME;
94
	$database = Database::getInstance();
95
	$database->doConnect($sSqlUrl);
96
	// disable all kind of magic_quotes
97
	if(get_magic_quotes_gpc() || get_magic_quotes_runtime()) {
98
		@ini_set('magic_quotes_sybase', 0);
99
		@ini_set('magic_quotes_gpc', 0);
100
		@ini_set('magic_quotes_runtime', 0);
101
	}
102
	// Get website settings (title, keywords, description, header, and footer)
103
	$query_settings = "SELECT name,value FROM ".TABLE_PREFIX."settings";
104
	$get_settings = $database->query($query_settings);
105
	if($database->is_error()) { die($database->get_error()); }
106
	if($get_settings->numRows() == 0) { die("Settings not found"); }
107
	while($setting = $get_settings->fetchRow()) {
108
		$setting_name=strtoupper($setting['name']);
109
		$setting_value=$setting['value'];
110
		if ($setting_value=='false')
111
			$setting_value=false;
112
		if ($setting_value=='true')
113
			$setting_value=true;
114
		@define($setting_name,$setting_value);
115
	}
116
	@define('DO_NOT_TRACK', (isset($_SERVER['HTTP_DNT'])));
117
	$string_file_mode = STRING_FILE_MODE;
118
	define('OCTAL_FILE_MODE',(int) octdec($string_file_mode));
119
	$string_dir_mode = STRING_DIR_MODE;
120
	define('OCTAL_DIR_MODE',(int) octdec($string_dir_mode));
121
	$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
122
	$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
123
	require_once($sSecMod);
124
	if (!defined("WB_INSTALL_PROCESS")) {
125
		// get CAPTCHA and ASP settings
126
		$table = TABLE_PREFIX.'mod_captcha_control';
127
		if( ($get_settings = $database->query("SELECT * FROM $table LIMIT 1")) ) {
128
			if($get_settings->numRows() == 0) { die("CAPTCHA-Settings not found"); }
129
			$setting = $get_settings->fetchRow();
130
			if($setting['enabled_captcha'] == '1') define('ENABLED_CAPTCHA', true);
131
			else define('ENABLED_CAPTCHA', false);
132
			if($setting['enabled_asp'] == '1') define('ENABLED_ASP', true);
133
			else define('ENABLED_ASP', false);
134
			define('CAPTCHA_TYPE', $setting['captcha_type']);
135
			define('ASP_SESSION_MIN_AGE', (int)$setting['asp_session_min_age']);
136
			define('ASP_VIEW_MIN_AGE', (int)$setting['asp_view_min_age']);
137
			define('ASP_INPUT_MIN_AGE', (int)$setting['asp_input_min_age']);
138
		}
139
	}
140

    
141
	// set error-reporting
142
	if(intval(ER_LEVEL) > 0 )
143
	{
144
		error_reporting(ER_LEVEL);
145
		if( intval(ini_get ( 'display_errors' )) == 0 )
146
		{
147
			ini_set('display_errors', 1);
148
		}
149
	}
150
	// Start a session
151
	if(!defined('SESSION_STARTED')) {
152
		session_name(APP_NAME.'_session_id');
153
		@session_start();
154
		define('SESSION_STARTED', true);
155
	}
156
	if(defined('ENABLED_ASP') && ENABLED_ASP && !isset($_SESSION['session_started']))
157
		$_SESSION['session_started'] = time();
158

    
159
	// Get users language
160
	if(isset($_GET['lang']) AND $_GET['lang'] != '' AND !is_numeric($_GET['lang']) AND strlen($_GET['lang']) == 2) {
161
		define('LANGUAGE', strtoupper($_GET['lang']));
162
		$_SESSION['LANGUAGE']=LANGUAGE;
163
	} else {
164
		if(isset($_SESSION['LANGUAGE']) AND $_SESSION['LANGUAGE'] != '') {
165
			define('LANGUAGE', $_SESSION['LANGUAGE']);
166
		} else {
167
			define('LANGUAGE', DEFAULT_LANGUAGE);
168
		}
169
	}
170

    
171
	// Load Language file
172
	if(!defined('LANGUAGE_LOADED')) {
173
		if(!file_exists(WB_PATH.'/languages/'.LANGUAGE.'.php')) {
174
			exit('Error loading language file '.LANGUAGE.', please check configuration');
175
		} else {
176
			require_once(WB_PATH.'/languages/'.LANGUAGE.'.php');
177
		}
178
	}
179

    
180
	// Get users timezone
181
	if(isset($_SESSION['TIMEZONE'])) {
182
		define('TIMEZONE', $_SESSION['TIMEZONE']);
183
	} else {
184
		define('TIMEZONE', DEFAULT_TIMEZONE);
185
	}
186
	// Get users date format
187
	if(isset($_SESSION['DATE_FORMAT'])) {
188
		define('DATE_FORMAT', $_SESSION['DATE_FORMAT']);
189
	} else {
190
		define('DATE_FORMAT', DEFAULT_DATE_FORMAT);
191
	}
192
	// Get users time format
193
	if(isset($_SESSION['TIME_FORMAT'])) {
194
		define('TIME_FORMAT', $_SESSION['TIME_FORMAT']);
195
	} else {
196
		define('TIME_FORMAT', DEFAULT_TIME_FORMAT);
197
	}
198

    
199
	// Set Theme dir
200
	define('THEME_URL', WB_URL.'/templates/'.DEFAULT_THEME);
201
	define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);
202

    
203
	// extended wb_settings
204
	define('EDIT_ONE_SECTION', false);
205

    
206
	define('EDITOR_WIDTH', 0);
(22-22/23)