Project

General

Profile

« Previous | Next » 

Revision 1864

Added by darkviper over 11 years ago

update classes Translate, TranslateTable, TranslateAdaptorWbOldStyle
added interface TranslateAdaptorInterface
added Klasse_Translate_de.pdf
update class WbAdaptor
update /framework/initialize.php

View differences:

initialize.php
1 1
<?php
2 2
/**
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 4
 *
4
 * @category        framework
5
 * @package         initialize
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
15 9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17
 */
17 18

  
18
/* -------------------------------------------------------- */
19
// Must include code to stop this file being accessed directly
20
require_once(dirname(__FILE__).'/globalExceptionHandler.php');
21
if(!defined('WB_URL')) { throw new IllegalFileException(); }
22
/* -------------------------------------------------------- */
23 19
/**
20
 * initialize.php
21
 *
22
 * @category     Core
23
 * @package      Core_Environment
24
 * @author       Werner v.d.Decken <wkl@isteam.de>
25
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
26
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
27
 * @version      0.0.1
28
 * @revision     $Revision$
29
 * @link         $HeadURL$
30
 * @lastmodified $Date$
31
 * @since        File replaced since 05.02.2013
32
 * @description  set the basic environment to run WebsiteBaker
33
 */
34

  
35
/* *** define some helper functions *** */
36
/**
24 37
 * sanitize $_SERVER['HTTP_REFERER']
25 38
 * @param string $sWbUrl qualified startup URL of current application
26 39
 */
......
48 61
		}
49 62
		$_SERVER['HTTP_REFERER'] = $sTmpReferer;
50 63
	}
51
/* -------------------------------------------------------- */
64
/**
65
 * Set constants for system/install values
66
 * @throws RuntimeException
67
 */
52 68
	function SetInstallPathConstants() {
53
		if(!defined('DEBUG')){ define('DEBUG', false); }// Include config file
69
		if(!defined('DEBUG')){ define('DEBUG', false); } // normaly set in config file
54 70
		if(!defined('ADMIN_DIRECTORY')){ define('ADMIN_DIRECTORY', 'admin'); }
55 71
		if(!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
56 72
			throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
......
62 78
			$x1 = parse_url(WB_URL);
63 79
			define('WB_REL', (isset($x1['path']) ? $x1['path'] : ''));
64 80
		}
81
		define('ADMIN_REL', WB_REL.'/'.ADMIN_DIRECTORY);
65 82
		if(!defined('DOCUMENT_ROOT')) {
83
			
66 84
			define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(WB_REL, '/').'$/', '', WB_PATH));
67 85
		}
86
		define('TMP_PATH', WB_PATH.'/temp');
68 87
	}
69
/* -------------------------------------------------------- */
88
/**
89
 * Read DB settings from configuration file
90
 * @return string
91
 * @throws RuntimeException
92
 * 
93
 */
94
	function readConfiguration($sRetvalType = 'url') {
95
		$x = debug_backtrace();
96
		if(sizeof($x) != 0) { throw new RuntimeException('illegal function request!'); }
97
		$aRetval = array();
98
		$sSetupFile = dirname(dirname(__FILE__)).'/setup.ini.php';
99
		if(is_readable($sSetupFile)) {
100
			$aCfg = parse_ini_file($sSetupFile, true);
101
			foreach($aCfg['Constants'] as $key=>$value) {
102
				if($key == 'debug') { $value = filter_var($value, FILTER_VALIDATE_BOOLEAN); }
103
				if(!defined(strtoupper($key))) { define(strtoupper($key), $value); }
104
			}
105
			$db = $aCfg['DataBase'];
106
			$db['type'] = isset($db['type']) ? $db['type'] : 'mysql';
107
			$db['user'] = isset($db['user']) ? $db['user'] : 'foo';
108
			$db['pass'] = isset($db['pass']) ? $db['pass'] : 'bar';
109
			$db['host'] = isset($db['host']) ? $db['host'] : 'localhost';
110
			$db['port'] = isset($db['port']) ? $db['port'] : '3306';
111
			$db['port'] = ($db['port'] != '3306') ? $db['port'] : '';
112
			$db['name'] = isset($db['name']) ? $db['name'] : 'dummy';
113
			$db['charset'] = isset($db['charset']) ? $db['charset'] : 'utf8';
114
			$db['table_prefix'] = (isset($db['table_prefix']) ? $db['table_prefix'] : '');
115
			define('TABLE_PREFIX', $db['table_prefix']);
116
			if($sRetvalType == 'dsn') {
117
				$aRetval[0] = $db['type'].':dbname='.$db['name'].';host='.$db['host'].';'
118
				            . ($db['port'] != '' ? 'port='.(int)$db['port'].';' : '');
119
				$aRetval[1] = array('CHARSET' => $db['charset'], 'TABLE_PREFIX' => $db['table_prefix']);
120
				$aRetval[2] = array( 'user' => $db['user'], 'pass' => $db['pass']);
121
			}else { // $sRetvalType == 'url'
122
				$aRetval[0] = $db['type'].'://'.$db['user'].':'.$db['pass'].'@'
123
				            . $db['host'].($db['port'] != '' ? ':'.$db['port'] : '').'/'.$db['name'];
124
			}
125
			unset($db, $aCfg);
126
			return $sRetval;
127
		}
128
		throw new RuntimeException('unable to read setup.ini.php');
129
	}
130
/* ***************************************************************************************
131
 * Start initialization                                                                  *
132
 ****************************************************************************************/
133
// initialize debug evaluation values ---	
134
	$sDbConnectType = 'url'; // depending from class WbDatabase it can be 'url' or 'dsn'
70 135
	$starttime = array_sum(explode(" ",microtime()));
71
	$iPhpDeclaredClasses =  sizeof(get_declared_classes());
136
	$iPhpDeclaredClasses = sizeof(get_declared_classes());
137
// disable all kind of magic_quotes in PHP versions before 5.4 ---
138
	if(version_compare(PHP_VERSION, '5.4.0', '<')) {
139
		if(get_magic_quotes_gpc() || get_magic_quotes_runtime()) {
140
			@ini_set('magic_quotes_sybase', 0);
141
			@ini_set('magic_quotes_gpc', 0);
142
			@ini_set('magic_quotes_runtime', 0);
143
		}
144
	}
145
// define constant systemenvironment settings ---
72 146
	SetInstallPathConstants();
73
	SanitizeHttpReferer(WB_URL); // sanitize $_SERVER['HTTP_REFERER']
74
	if(!class_exists('WbAutoloader', false)){ include(dirname(__FILE__).'/WbAutoloader.php'); }
147
	date_default_timezone_set('UTC');
148
	if(!defined('MAX_TIME')) { define('MAX_TIME', (pow(2, 31)-1)); } // 32-Bit Timestamp of 19 Jan 2038 03:14:07 GMT
149
	if(!defined('DO_NOT_TRACK')) { define('DO_NOT_TRACK', (isset($_SERVER['HTTP_DNT']))); }
150
// register WB basic autoloader ---
151
	$sTmp = dirname(__FILE__).'/WbAutoloader.php';
152
	if(!class_exists('WbAutoloader', false)){ include($sTmp); }
75 153
	WbAutoloader::doRegister(array(ADMIN_DIRECTORY=>'a', 'modules'=>'m'));
76
	require_once dirname(dirname(__FILE__)).'/include/Twig/Autoloader.php';
154
// register TWIG autoloader ---
155
//	$sTmp = dirname(dirname(__FILE__)).'/include/Sensio/Twig/lib/Twig/Autoloader.php';
156
	$sTmp = dirname(dirname(__FILE__)).'/include/Twig/Autoloader.php';
157
	if(!class_exists('Twig_Autoloader', false)){ include($sTmp); }
77 158
	Twig_Autoloader::register();
78
	date_default_timezone_set('UTC');
79
	// Create database class
80
	$sSqlUrl = DB_TYPE.'://'.DB_USERNAME.':'.DB_PASSWORD.'@'.DB_HOST.'/'.DB_NAME;
159
// aktivate exceptionhandler ---
160
	if(!function_exists('globalExceptionHandler')) {
161
		include(dirname(__FILE__).'/globalExceptionHandler.php');
162
	}
163
// load db configuration ---
164
	if(defined('DB_TYPE')) {
165
		$aSqlData = array( 0 => DB_TYPE.'://'.DB_USERNAME.':'.DB_PASSWORD.'@'.DB_HOST.'/'.DB_NAME);
166
	}else {
167
		$aSqlData = readConfiguration($sDbConnectType);
168
	}
169
// sanitize $_SERVER['HTTP_REFERER'] ---
170
	SanitizeHttpReferer(WB_URL); 
171
// ---------------------------
172
// Create global database instance ---
81 173
	$database = WbDatabase::getInstance();
82
	$database->doConnect($sSqlUrl);
83
	// 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);
174
	if($sDbConnectType == 'dsn') {
175
		$database->doConnect($aSqlData[0], $aSqlData[1]['user'], $aSqlData[1]['pass'], $aSqlData[2]);
176
	}else {
177
		$database->doConnect($aSqlData[0], TABLE_PREFIX);
88 178
	}
89
	// 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
//		if ($setting_value=='') {$setting_value=false;}
98
		if ($setting_value=='false'){$setting_value=false;}
99
		if ($setting_value=='true'){$setting_value=true;}
100
		@define($setting_name,$setting_value);
101
	}
102
	@define('DO_NOT_TRACK', (isset($_SERVER['HTTP_DNT'])));
103
	$string_file_mode = STRING_FILE_MODE;
179
	unset($aSqlData);
180
// load global settings from database and define global consts from ---
181
	$sql = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'settings`';
182
	if(($oSettings = $database->query($sql))) {
183
		if(!$oSettings->numRows()) { throw new AppException('no settings found'); }
184
		while($aSetting = $oSettings->fetchRow(MYSQL_ASSOC)) {
185
			//sanitize true/false values
186
			$aSetting['value'] = ($aSetting['value'] == 'true' 
187
								  ? true 
188
								  : ($aSetting['value'] == 'false' 
189
									 ? false 
190
									 : $aSetting['value'])
191
								 );
192
			// make global const from setting
193
			@define(strtoupper($aSetting['name']), $aSetting['value']);
194
		}
195
	}else { throw new AppException($database->get_error()); }
196
// get/set users timezone ---
197
	define('TIMEZONE',    (isset($_SESSION['TIMEZONE'])    ? $_SESSION['TIMEZONE']    : DEFAULT_TIMEZONE));
198
	define('DATE_FORMAT', (isset($_SESSION['DATE_FORMAT']) ? $_SESSION['DATE_FORMAT'] : DEFAULT_DATE_FORMAT));
199
	define('TIME_FORMAT', (isset($_SESSION['TIME_FORMAT']) ? $_SESSION['TIME_FORMAT'] : DEFAULT_TIME_FORMAT));
200
// set Theme directory --- 
201
	define('THEME_URL',  WB_URL.'/templates/'.DEFAULT_THEME);
202
	define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);
203
	define('THEME_REL',  WB_REL.'/templates/'.DEFAULT_THEME);
204
// extended wb editor settings
205
	define('EDIT_ONE_SECTION', false);
206
	define('EDITOR_WIDTH', 0);
207
// define numeric, octal values for chmod operations ---	
208
	$string_file_mode = STRING_FILE_MODE; // STRING_FILE_MODE is set deprecated
104 209
	define('OCTAL_FILE_MODE',(int) octdec($string_file_mode));
105
	$string_dir_mode = STRING_DIR_MODE;
210
	$string_dir_mode = STRING_DIR_MODE; // STRING_DIR_MODE is set deprecated
106 211
	define('OCTAL_DIR_MODE',(int) octdec($string_dir_mode));
212
// define form security class and preload it ---
107 213
	$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
108 214
	$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
109 215
	require_once($sSecMod);
110
	if (!defined("WB_INSTALL_PROCESS")) {
111
		// get CAPTCHA and ASP settings
112
		$table = TABLE_PREFIX.'mod_captcha_control';
113
		if( ($get_settings = $database->query("SELECT * FROM $table LIMIT 1")) ) {
114
			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
	{
216
// set error-reporting from loaded settings ---
217
	if(intval(ER_LEVEL) > 0 ) {
130 218
		error_reporting(ER_LEVEL);
131
		if( intval(ini_get ( 'display_errors' )) == 0 )
132
		{
219
		if( intval(ini_get ( 'display_errors' )) == 0 ) {
133 220
			ini_set('display_errors', 1);
134 221
		}
135 222
	}
136
	// Start a session
223
// Start a session ---
137 224
	if(!defined('SESSION_STARTED')) {
138 225
		session_name(APP_NAME.'_session_id');
139 226
		@session_start();
140 227
		define('SESSION_STARTED', true);
141 228
	}
142
	if(defined('ENABLED_ASP') && ENABLED_ASP && !isset($_SESSION['session_started']))
229
// *** begin deprecated part *************************************************************
230
// load settings for use in Captch and ASP module
231
	if (!defined("WB_INSTALL_PROCESS")) {
232
		$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_captcha_control`';
233
		// request settings from database
234
		if(($oSettings = $database->query($sql))) {
235
			if(($aSetting = $oSettings->fetchRow(MYSQL_ASSOC))) {
236
				define('ENABLED_CAPTCHA', ($aSetting['enabled_captcha'] == '1'));
237
				define('ENABLED_ASP', ($aSetting['enabled_asp'] == '1'));
238
				define('CAPTCHA_TYPE', $aSetting['captcha_type']);
239
				define('ASP_SESSION_MIN_AGE', (int)$aSetting['asp_session_min_age']);
240
				define('ASP_VIEW_MIN_AGE', (int)$aSetting['asp_view_min_age']);
241
				define('ASP_INPUT_MIN_AGE', (int)$aSetting['asp_input_min_age']);
242
			}
243
		}
244
	}
245
	if(defined('ENABLED_ASP') && ENABLED_ASP && !isset($_SESSION['session_started'])) {
143 246
		$_SESSION['session_started'] = time();
144

  
145

  
146

  
147
	// Get users language
148
	$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));
247
	}
248
// *** end of deprecated part ************************************************************
249
// get user language ---
250
	$sRequestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
251
	// check if get/post value is available
252
	$sTempLanguage = (isset(${$sRequestMethod}['lang']) ? ${$sRequestMethod}['lang'] : '');
253
	// validate language code
254
	if(preg_match('/^[a-z]{2}$/si', $sTempLanguage)) {
255
	// if there's valid get/post
256
		define('LANGUAGE', strtoupper($sTempLanguage));
152 257
		$_SESSION['LANGUAGE']=LANGUAGE;
153
	} else {
154
		if(isset($_SESSION['LANGUAGE']) AND $_SESSION['LANGUAGE'] != '') {
258
	}else {
259
		if(isset($_SESSION['LANGUAGE']) && $_SESSION['LANGUAGE']) {
260
		// if there's valid session value
155 261
			define('LANGUAGE', $_SESSION['LANGUAGE']);
156
		} else {
262
		}else {
263
		// otherwise set to default
157 264
			define('LANGUAGE', DEFAULT_LANGUAGE);
158 265
		}
159 266
	}
160

  
161
	// 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

  
170
	// Get users timezone
171
	if(isset($_SESSION['TIMEZONE'])) {
172
		define('TIMEZONE', $_SESSION['TIMEZONE']);
267
// activate translations / load language definitions
268
/** begin of deprecated part || will be replaced by class Translate **/	
269
// Load Language file
270
	if(!file_exists(WB_PATH.'/languages/'.LANGUAGE.'.php')) {
271
		$sMsg = 'Error loading language file '.LANGUAGE.', please check configuration';
272
		throw new AppException($sMsg);
173 273
	} else {
174
		define('TIMEZONE', DEFAULT_TIMEZONE);
274
	// include language file
275
		require_once(WB_PATH.'/languages/'.LANGUAGE.'.php');
175 276
	}
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);
277
/** end of deprecated part **/
278
// instantiate and initialize adaptor for temporary registry replacement ---
279
	if(class_exists('WbAdaptor')) {
280
		WbAdaptor::getInstance()->getWbConstants();
181 281
	}
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
	// extended wb_settings
194
	define('EDIT_ONE_SECTION', false);
195

  
196
	define('EDITOR_WIDTH', 0);
282
// load and activate new global translation table
283
	Translate::getInstance()->initialize('en',
284
	                                     (defined('DEFAULT_LANGUAGE') ? DEFAULT_LANGUAGE : ''), 
285
	                                     (defined('LANGUAGE') ? LANGUAGE : ''), 
286
	                                     'WbOldStyle');
287
// *** END OF FILE ***********************************************************************
288
	

Also available in: Unified diff