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 1638 2012-03-13 23:01:47Z darkviper $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/initialize.php $
15
 * @lastmodified    $Date: 2012-03-14 00:01:47 +0100 (Wed, 14 Mar 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
if( !defined('ADMIN_DIRECTORY')) { define('ADMIN_DIRECTORY', 'admin'); }
54
if(!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
55
	throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
56
}
57

    
58
if( !defined('ADMIN_URL')) { define('ADMIN_URL', WB_URL.'/'.ADMIN_DIRECTORY); }
59
if( !defined('WB_PATH')) { define('WB_PATH', dirname(dirname(__FILE__))); }
60
if( !defined('ADMIN_PATH')) { define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY); }
61

    
62
if (file_exists(WB_PATH.'/framework/class.database.php')) {
63
	// sanitize $_SERVER['HTTP_REFERER']
64
	SanitizeHttpReferer(WB_URL);
65
	date_default_timezone_set('UTC');
66
	require_once(WB_PATH.'/framework/class.database.php');
67

    
68
	// Create database class
69
	$database = new database();
70

    
71
    if(version_compare(PHP_VERSION, '5.3.0', '<'))
72
    {
73
        set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
74
    }
75
	// Get website settings (title, keywords, description, header, and footer)
76
	$query_settings = "SELECT name,value FROM ".TABLE_PREFIX."settings";
77
	$get_settings = $database->query($query_settings);
78
	if($database->is_error()) { die($database->get_error()); }
79
	if($get_settings->numRows() == 0) { die("Settings not found"); }
80
	while($setting = $get_settings->fetchRow()) {
81
		$setting_name=strtoupper($setting['name']);
82
		$setting_value=$setting['value'];
83
		if ($setting_value=='false')
84
			$setting_value=false;
85
		if ($setting_value=='true')
86
			$setting_value=true;
87
		@define($setting_name,$setting_value);
88
	}
89
	@define('DO_NOT_TRACK', (isset($_SERVER['HTTP_DNT'])));
90
	$string_file_mode = STRING_FILE_MODE;
91
	define('OCTAL_FILE_MODE',(int) octdec($string_file_mode));
92
	$string_dir_mode = STRING_DIR_MODE;
93
	define('OCTAL_DIR_MODE',(int) octdec($string_dir_mode));
94
	$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
95
	$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
96
	require_once($sSecMod);
97
	if (!defined("WB_INSTALL_PROCESS")) {
98
		// get CAPTCHA and ASP settings
99
		$table = TABLE_PREFIX.'mod_captcha_control';
100
		if( ($get_settings = $database->query("SELECT * FROM $table LIMIT 1")) ) {
101
			if($get_settings->numRows() == 0) { die("CAPTCHA-Settings not found"); }
102
			$setting = $get_settings->fetchRow();
103
			if($setting['enabled_captcha'] == '1') define('ENABLED_CAPTCHA', true);
104
			else define('ENABLED_CAPTCHA', false);
105
			if($setting['enabled_asp'] == '1') define('ENABLED_ASP', true);
106
			else define('ENABLED_ASP', false);
107
			define('CAPTCHA_TYPE', $setting['captcha_type']);
108
			define('ASP_SESSION_MIN_AGE', (int)$setting['asp_session_min_age']);
109
			define('ASP_VIEW_MIN_AGE', (int)$setting['asp_view_min_age']);
110
			define('ASP_INPUT_MIN_AGE', (int)$setting['asp_input_min_age']);
111
		}
112
	}
113

    
114
	// set error-reporting
115
	if(intval(ER_LEVEL) > 0 )
116
	{
117
		error_reporting(ER_LEVEL);
118
		if( intval(ini_get ( 'display_errors' )) == 0 )
119
		{
120
			ini_set('display_errors', 1);
121
		}
122
	}
123
	// Start a session
124
	if(!defined('SESSION_STARTED')) {
125
		session_name(APP_NAME.'_session_id');
126
		@session_start();
127
		define('SESSION_STARTED', true);
128
	}
129
	if(defined('ENABLED_ASP') && ENABLED_ASP && !isset($_SESSION['session_started']))
130
		$_SESSION['session_started'] = time();
131

    
132
	// Get users language
133
	if(isset($_GET['lang']) AND $_GET['lang'] != '' AND !is_numeric($_GET['lang']) AND strlen($_GET['lang']) == 2) {
134
	  	define('LANGUAGE', strtoupper($_GET['lang']));
135
		$_SESSION['LANGUAGE']=LANGUAGE;
136
	} else {
137
		if(isset($_SESSION['LANGUAGE']) AND $_SESSION['LANGUAGE'] != '') {
138
			define('LANGUAGE', $_SESSION['LANGUAGE']);
139
		} else {
140
			define('LANGUAGE', DEFAULT_LANGUAGE);
141
		}
142
	}
143
	
144
	// Load Language file
145
	if(!defined('LANGUAGE_LOADED')) {
146
		if(!file_exists(WB_PATH.'/languages/'.LANGUAGE.'.php')) {
147
			exit('Error loading language file '.LANGUAGE.', please check configuration');
148
		} else {
149
			require_once(WB_PATH.'/languages/'.LANGUAGE.'.php');
150
		}
151
	}
152
	
153
	// Get users timezone
154
	if(isset($_SESSION['TIMEZONE'])) {
155
		define('TIMEZONE', $_SESSION['TIMEZONE']);
156
	} else {
157
		define('TIMEZONE', DEFAULT_TIMEZONE);
158
	}
159
	// Get users date format
160
	if(isset($_SESSION['DATE_FORMAT'])) {
161
		define('DATE_FORMAT', $_SESSION['DATE_FORMAT']);
162
	} else {
163
		define('DATE_FORMAT', DEFAULT_DATE_FORMAT);
164
	}
165
	// Get users time format
166
	if(isset($_SESSION['TIME_FORMAT'])) {
167
		define('TIME_FORMAT', $_SESSION['TIME_FORMAT']);
168
	} else {
169
		define('TIME_FORMAT', DEFAULT_TIME_FORMAT);
170
	}
171

    
172
	// Set Theme dir
173
	define('THEME_URL', WB_URL.'/templates/'.DEFAULT_THEME);
174
	define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);
175

    
176
    // extended wb_settings
177
	define('EDIT_ONE_SECTION', false);
178

    
179
	define('EDITOR_WIDTH', 0);
180

    
181
}
(21-21/22)