Project

General

Profile

« Previous | Next » 

Revision 2121

Added by darkviper about 9 years ago

! SqlImport::setDefaultCollation() requesting charsets modified
! framework/initialize some fixes and modifications

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12
===============================================================================
13 13

  
14
16 Mar-2015 Build 2121 Manuela v.d.Decken(DarkViper)
15
! SqlImport::setDefaultCollation() requesting charsets modified
16
! framework/initialize  some fixes and modifications
14 17
10 Mar-2015 Build 2120 Manuela v.d.Decken(DarkViper)
15 18
# framework/WbAdaptor some litte fixes
16 19
+ framework/WbDatabaseHelper contains now all maintenance methods from WbDatabase
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.4');
54
if(!defined('REVISION')) define('REVISION', '2120');
54
if(!defined('REVISION')) define('REVISION', '2121');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/framework/initialize.php
37 37
 * sanitize $_SERVER['HTTP_REFERER']
38 38
 * @param string $sWbUrl qualified startup URL of current application
39 39
 */
40
	function initSanitizeHttpReferer($sWbUrl) {
41
		$sTmpReferer = '';
42
		if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != '') {
43
			$sTmpReferer = $_SERVER['HTTP_REFERER'];
44
			$aRefUrl = parse_url($_SERVER['HTTP_REFERER']);
45
			if ($aRefUrl !== false) {
46
				$aRefUrl['host'] = isset($aRefUrl['host']) ? $aRefUrl['host'] : '';
47
				$aRefUrl['path'] = isset($aRefUrl['path']) ? $aRefUrl['path'] : '';
48
				$aRefUrl['fragment'] = isset($aRefUrl['fragment']) ? '#'.$aRefUrl['fragment'] : '';
49
				$aWbUrl = parse_url($sWbUrl);
50
				if ($aWbUrl !== false) {
51
					$aWbUrl['host'] = isset($aWbUrl['host']) ? $aWbUrl['host'] : '';
52
					$aWbUrl['path'] = isset($aWbUrl['path']) ? $aWbUrl['path'] : '';
53
					if (strpos($aRefUrl['host'].$aRefUrl['path'],
54
							   $aWbUrl['host'].$aWbUrl['path']) !== false) {
55
						$aRefUrl['path'] = preg_replace('#^'.$aWbUrl['path'].'#i', '', $aRefUrl['path']);
56
						$sTmpReferer = $sWbUrl.$aRefUrl['path'].$aRefUrl['fragment'];
57
					}
58
					unset($aWbUrl);
59
				}
60
				unset($aRefUrl);
61
			}
62
		}
63
		$_SERVER['HTTP_REFERER'] = $sTmpReferer;
64
	}
40
    function initSanitizeHttpReferer($sWbUrl) {
41
        $sTmpReferer = '';
42
        if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != '') {
43
            define('ORG_REFERER', ($_SERVER['HTTP_REFERER'] ?: ''));
44
            $sTmpReferer = $_SERVER['HTTP_REFERER'];
45
            $aRefUrl = parse_url($_SERVER['HTTP_REFERER']);
46
            if ($aRefUrl !== false) {
47
                $aRefUrl['host'] = isset($aRefUrl['host']) ? $aRefUrl['host'] : '';
48
                $aRefUrl['path'] = isset($aRefUrl['path']) ? $aRefUrl['path'] : '';
49
                $aRefUrl['fragment'] = isset($aRefUrl['fragment']) ? '#'.$aRefUrl['fragment'] : '';
50
                $aWbUrl = parse_url($sWbUrl);
51
                if ($aWbUrl !== false) {
52
                    $aWbUrl['host'] = isset($aWbUrl['host']) ? $aWbUrl['host'] : '';
53
                    $aWbUrl['path'] = isset($aWbUrl['path']) ? $aWbUrl['path'] : '';
54
                    if (strpos($aRefUrl['host'].$aRefUrl['path'],
55
                               $aWbUrl['host'].$aWbUrl['path']) !== false) {
56
                        $aRefUrl['path'] = preg_replace('#^'.$aWbUrl['path'].'#i', '', $aRefUrl['path']);
57
                        $sTmpReferer = $sWbUrl.$aRefUrl['path'].$aRefUrl['fragment'];
58
                    }
59
                    unset($aWbUrl);
60
                }
61
                unset($aRefUrl);
62
            }
63
        }
64
        $_SERVER['HTTP_REFERER'] = $sTmpReferer;
65
    }
65 66
/**
66 67
 * Set constants for system/install values
67 68
 * @throws RuntimeException
68 69
 */
69
	function initSetInstallPathConstants() {
70
		if(!defined('DEBUG')){ define('DEBUG', false); } // normaly set in 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', rtrim(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('ADMIN_REL')){ define('ADMIN_REL', WB_REL.'/'.ADMIN_DIRECTORY); }
83
		if(!defined('DOCUMENT_ROOT')) {
84
			define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(str_replace('\\', '/', WB_REL), '/').'$/', '', str_replace('\\', '/', WB_PATH)));
85
			$_SERVER['DOCUMENT_ROOT'] = DOCUMENT_ROOT;
86
		}
87
		if(!defined('TMP_PATH')){ define('TMP_PATH', WB_PATH.'/temp'); }
88
	}
70
    function initSetInstallPathConstants() {
71
        if(!defined('DEBUG')){ define('DEBUG', false); } // normaly set in config file
72
        if(!defined('ADMIN_DIRECTORY')){ define('ADMIN_DIRECTORY', 'admin'); }
73
        if(!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
74
            throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
75
        }
76
        if(!defined('WB_PATH')){ define('WB_PATH', dirname(__DIR__)); }
77
        if(!defined('ADMIN_URL')){ define('ADMIN_URL', rtrim(WB_URL, '/\\').'/'.ADMIN_DIRECTORY); }
78
        if(!defined('ADMIN_PATH')){ define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY); }
79
        if(!defined('WB_REL')){
80
            $x1 = parse_url(WB_URL);
81
            define('WB_REL', (isset($x1['path']) ? $x1['path'] : ''));
82
        }
83
        if(!defined('ADMIN_REL')){ define('ADMIN_REL', WB_REL.'/'.ADMIN_DIRECTORY); }
84
        if(!defined('DOCUMENT_ROOT')) {
85
            define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(str_replace('\\', '/', WB_REL), '/').'$/', '', str_replace('\\', '/', WB_PATH)));
86
            $_SERVER['DOCUMENT_ROOT'] = DOCUMENT_ROOT;
87
        }
88
        if(!defined('TMP_PATH')){ define('TMP_PATH', WB_PATH.'/temp'); }
89
    }
89 90
/**
90 91
 * checkValidCaller
91 92
 * @param array $aCaller list of allowed scripts
......
93 94
 * @throws RuntimeException
94 95
 * @description test if acctual file is called from one of the given list
95 96
 */
96
	function initCheckValidCaller(array $aCaller)
97
	{
97
    function initCheckValidCaller(array $aCaller)
98
    {
98 99
        return true;
99
		$x = debug_backtrace();
100
		if(sizeof($x) == 0) {
101
			return true;
102
		}
103
		$sPattern = '/('.str_replace('#', '|', preg_quote(implode('#', $aCaller), '/')).')$/si';
104
		foreach($x as $aStep) {
105
			// define the scripts which can read the configuration
106
			if(preg_match($sPattern, $aStep['file'])) {
107
				return true;
108
			}
109
		}
110
		throw new RuntimeException('illegal file request!');
111
	}
100
        $x = debug_backtrace();
101
        if(sizeof($x) == 0) {
102
            return true;
103
        }
104
        $sPattern = '/('.str_replace('#', '|', preg_quote(implode('#', $aCaller), '/')).')$/si';
105
        foreach($x as $aStep) {
106
            // define the scripts which can read the configuration
107
            if(preg_match($sPattern, $aStep['file'])) {
108
                return true;
109
            }
110
        }
111
        throw new RuntimeException('illegal file request!');
112
    }
112 113
/**
113 114
 * Read DB settings from configuration file
114 115
 * @return array
115 116
 * @throws RuntimeException
116 117
 * 
117 118
 */
118
	function initReadSetupFile()
119
	{
120
	// check for valid file request. Becomes more stronger in next version
121
		initCheckValidCaller(array('save.php','index.php','config.php','upgrade-script.php'));
122
		$aCfg = array();
119
    function initReadSetupFile()
120
    {
121
    // check for valid file request. Becomes more stronger in next version
122
        initCheckValidCaller(array('save.php','index.php','config.php','upgrade-script.php'));
123
        $aCfg = array();
123 124

  
124
		$sSetupFile = dirname(dirname(__FILE__)).'/setup.ini.php';
125
		if(is_readable($sSetupFile)) {
126
			$aCfg = parse_ini_file($sSetupFile, true);
127
			foreach($aCfg['Constants'] as $key=>$value) {
128
				switch($key):
129
					case 'DEBUG':
130
						$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
131
						if(!defined('DEBUG')) { define('DEBUG', $value); }
132
						break;
133
					case 'WB_URL': // << case is set deprecated
134
					case 'AppUrl':
135
						$value = trim(str_replace('\\', '/', $value), '/'); 
136
						if(!defined('WB_URL')) { define('WB_URL', $value); }
137
						break;
138
					case 'ADMIN_DIRECTORY': // << case is set deprecated
139
					case 'AcpDir':
140
						$value = trim(str_replace('\\', '/', $value), '/'); 
141
						if(!defined('ADMIN_DIRECTORY')) { define('ADMIN_DIRECTORY', $value); }
142
						break;
143
					default:
144
						if(!defined($key)) { define($key, $value); }
145
						break;
146
				endswitch;
147
			}
148
		}
149
		return $aCfg;
150
//		throw new RuntimeException('unable to read setup.ini.php');
151
	}
152
 /**
125
        $sSetupFile = dirname(dirname(__FILE__)).'/setup.ini.php';
126
        if(is_readable($sSetupFile)) {
127
            $aCfg = parse_ini_file($sSetupFile, true);
128
            if (!isset($aCfg['Constants']) || !isset($aCfg['DataBase'])) {
129
                throw new InvalidArgumentException('configuration missmatch in setup.ini.php');
130
            }
131
            foreach($aCfg['Constants'] as $key=>$value) {
132
                switch($key):
133
                    case 'DEBUG':
134
                        $value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
135
                        if(!defined('DEBUG')) { define('DEBUG', $value); }
136
                        break;
137
                    case 'WB_URL': // << case is set deprecated
138
                    case 'AppUrl':
139
                        $value = trim(str_replace('\\', '/', $value), '/');
140
                        if(!defined('WB_URL')) { define('WB_URL', $value); }
141
                        break;
142
                    case 'ADMIN_DIRECTORY': // << case is set deprecated
143
                    case 'AcpDir':
144
                        $value = trim(str_replace('\\', '/', $value), '/');
145
                        if(!defined('ADMIN_DIRECTORY')) { define('ADMIN_DIRECTORY', $value); }
146
                        break;
147
                    default:
148
                        if(!defined($key)) { define($key, $value); }
149
                        break;
150
                endswitch;
151
            }
152
        }
153
        return $aCfg;
154
//      throw new RuntimeException('unable to read setup.ini.php');
155
    }
156
/**
153 157
 * GetDbConnectData
154 158
 * @param array $aCfg
155 159
 * @param string $sDbConnectType  can be 'url' or 'dsn'
156 160
 * @return array
157 161
 *
158 162
 */
159
	function initGetDbConnectData(array $aCfg, $sDbConnectType = 'url')
160
	{
161
		if(defined('DB_TYPE'))
162
		{
163
		// import constants for compatibility reasons
164
			$db = array();
165
			if(defined('DB_TYPE'))      { $db['type']         = DB_TYPE; }
166
			if(defined('DB_USERNAME'))  { $db['user']         = DB_USERNAME; }
167
			if(defined('DB_PASSWORD'))  { $db['pass']         = DB_PASSWORD; }
168
			if(defined('DB_HOST'))      { $db['host']         = DB_HOST; }
169
			if(defined('DB_PORT'))      { $db['port']         = DB_PORT; }
170
			if(defined('DB_NAME'))      { $db['name']         = DB_NAME; }
171
			if(defined('DB_CHARSET'))   { $db['charset']      = DB_CHARSET; }
172
			if(defined('TABLE_PREFIX')) { $db['table_prefix'] = TABLE_PREFIX; }
173
			$aCfg['DataBase'] = $db;
174
		}
175
		// sanitize values
176
		$db = $aCfg['DataBase'];
177
		$db['type'] = isset($db['type']) ? $db['type'] : 'mysql';
178
		$db['user'] = isset($db['user']) ? $db['user'] : 'foo';
179
		$db['pass'] = isset($db['pass']) ? $db['pass'] : 'bar';
180
		$db['host'] = isset($db['host']) ? $db['host'] : 'localhost';
181
		$db['port'] = isset($db['port']) ? $db['port'] : '3306';
182
		$db['port'] = ($db['port'] != '3306') ? $db['port'] : '';
183
		$db['name'] = isset($db['name']) ? $db['name'] : 'dummy';
184
		$db['charset'] = isset($db['charset']) ? trim($db['charset']) : 'utf8';
185
		$db['table_prefix'] = (isset($db['table_prefix']) ? $db['table_prefix'] : '');
163
    function initGetDbConnectData(array $aCfg, $sDbConnectType = 'url')
164
    {
165
        if(defined('DB_TYPE'))
166
        {
167
        // import constants for compatibility reasons
168
            $db = array();
169
            if(defined('DB_TYPE'))      { $db['type']         = DB_TYPE; }
170
            if(defined('DB_USERNAME'))  { $db['user']         = DB_USERNAME; }
171
            if(defined('DB_PASSWORD'))  { $db['pass']         = DB_PASSWORD; }
172
            if(defined('DB_HOST'))      { $db['host']         = DB_HOST; }
173
            if(defined('DB_PORT'))      { $db['port']         = DB_PORT; }
174
            if(defined('DB_NAME'))      { $db['name']         = DB_NAME; }
175
            if(defined('DB_CHARSET'))   { $db['charset']      = DB_CHARSET; }
176
            if(defined('TABLE_PREFIX')) { $db['table_prefix'] = TABLE_PREFIX; }
177
            $aCfg['DataBase'] = $db;
178
        }
179
        // sanitize values
180
        $db = $aCfg['DataBase'];
181
        $db['type'] = isset($db['type']) ? $db['type'] : 'mysql';
182
        $db['user'] = isset($db['user']) ? $db['user'] : 'foo';
183
        $db['pass'] = isset($db['pass']) ? $db['pass'] : 'bar';
184
        $db['host'] = isset($db['host']) ? $db['host'] : 'localhost';
185
        $db['port'] = isset($db['port']) ? $db['port'] : '3306';
186
        $db['port'] = ($db['port'] != '3306') ? $db['port'] : '';
187
        $db['socket'] = isset($db['socket']) ? $db['socket'] : '';
188
        $db['name'] = isset($db['name']) ? $db['name'] : 'dummy';
189
        $db['charset'] = isset($db['charset']) ? trim($db['charset']) : 'utf8';
190
        $db['table_prefix'] = (isset($db['table_prefix']) ? $db['table_prefix'] : '');
186 191
        if (isset($db['options']) && is_array($db['options'])) {
187 192
            foreach ($db['options'] as $key=>$value) {
188 193
                $aRetval['options'][constant($key)] = $value;
189 194
            }
190 195
        }
191
		if(!defined('TABLE_PREFIX')) { define('TABLE_PREFIX', $db['table_prefix']); }
192
		if($sDbConnectType == 'dsn') {
193
		// build dsn to connect
196
        if(!defined('TABLE_PREFIX')) { define('TABLE_PREFIX', $db['table_prefix']); }
197
        if($sDbConnectType == 'dsn') {
198
        // build dsn to connect
194 199
            $aRetval['dsn']      = $db['type'].':dbname='.$db['name'].';host='.$db['host']
195
						         . ($db['port'] != '' ? ';port='.(int)$db['port'] : '');
200
                                 . ($db['port'] != '' ? ';port='.(int)$db['port'] : '');
196 201
            if ($db['charset'] == 'utf8') {
197 202
                $aRetval['dsn'] .= ';charset=UTF8';
198 203
                $aRetval['options'][constant('PDO::MYSQL_ATTR_INIT_COMMAND')]  = 'SET NAMES \'UTF8\'';
......
201 206
            $aRetval['user']     = $db['user'];
202 207
            $aRetval['password'] = $db['pass'];
203 208
            $aRetval['addons']   = array('CHARSET' => $db['charset'], 'TABLE_PREFIX' => $db['table_prefix']);
204
		}else { 
205
		// build url to connect
209
        }else {
210
        // build url to connect
206 211
            $aRetval['url'] = $db['type'].'://'.$db['user'].':'.$db['pass'].'@'
207
						    . $db['host'].($db['port'] != '' ? ':'.$db['port'] : '').'/'.$db['name']
208
						    . '?Charset='.$db['charset'].'&TablePrefix='.$db['table_prefix'];
209
		}
210
		return $aRetval;
211
	}
212
                            . $db['host'].($db['port'] != '' ? ':'.$db['port'] : '').'/'.$db['name']
213
                            . '?Charset='.$db['charset'].'&TablePrefix='.$db['table_prefix'];
214
        }
215
        return $aRetval;
216
    }
212 217

  
213 218
/* ***************************************************************************************
214 219
 * Start initialization                                                                  *
215 220
 ****************************************************************************************/
221
// test for existing and active old config.php
222
    if (defined('TABLE_PREFIX')) { /** TODO */ }
216 223
// initialize debug evaluation values ---	
217
	$starttime = array_sum(explode(" ",microtime()));
218
	$iPhpDeclaredClasses = sizeof(get_declared_classes());
219
	$sDbConnectType = 'url'; // depending from class WbDatabase it can be 'url' or 'dsn'
220
// PHP less then 5.3.2 is prohibited ---
221
	if (version_compare(PHP_VERSION, '5.3.2', '<')) {
222
		$sMsg = '<p style="color: #ff0000;">WebsiteBaker is not able to run with PHP-Version less then 5.3.2!!<br />'
223
		      . 'Please change your PHP-Version to any kind from 5.3.2 and up!<br />'
224
		      . 'If you have problems to solve that, ask your hosting provider for it.<br  />'
225
		      . 'The very best solution is the use of PHP-5.4 and up</p>';
226
		die($sMsg);
227
	}
228
// disable all kind of magic_quotes in PHP versions before 5.4 ---
229
	if (function_exists('get_magic_quotes_gpc') && filter_var(get_magic_quotes_gpc(), FILTER_VALIDATE_BOOLEAN)) {
230
		$sMsg = '<p style="color: #ff0000;">WebsiteBaker is not able to run with magic_quotes=on!!<br />'
231
		      . 'Please change your PHP-ini or add a _htaccess file to switch this setting to off!<br />'
232
		      . 'If you have problems to solve that, ask your hosting provider for it.<br  />'
233
		      . 'The very best solution is the use of PHP-5.4 and up</p>';
234
		die($sMsg);
235
	}
224
    $starttime = array_sum(explode(" ",microtime()));
225
    $iPhpDeclaredClasses = sizeof(get_declared_classes());
226
    $sDbConnectType = 'url'; // depending from class WbDatabase it can be 'url' or 'dsn'
227
    // calculate maximum timestamp
228
    if (!defined('MAX_TIMESTAMP')) { define('MAX_TIMESTAMP', pow(2, 31)-1); } // 2038-01-19 04:14:07
229
// PHP less then 5.4.0 is prohibited ---
230
    if (version_compare(PHP_VERSION, '5.4.0', '<')) {
231
        $sMsg = '<p style="color: #ff0000;">WebsiteBaker is not able to run with PHP-Version less then 5.4.0!!<br />'
232
              . 'Please change your PHP-Version to any kind from 5.4.0 and up!<br />'
233
              . 'If you have problems to solve that, ask your hosting provider for it.<br  />'
234
              . 'The very best solution is the use of PHP-5.5 and up</p>';
235
        die($sMsg);
236
    }
237
    if (! defined('SYSTEM_RUN')) { define('SYSTEM_RUN', true); }
236 238
// load configuration ---
237
	$aCfg = initReadSetupFile();
239
    $aCfg = initReadSetupFile();
238 240
// sanitize $_SERVER['HTTP_REFERER'] ---
239
	initSetInstallPathConstants();
240
	initSanitizeHttpReferer(WB_URL);
241
    initSetInstallPathConstants();
242
    initSanitizeHttpReferer(WB_URL);
241 243
// register WB basic autoloader ---
242
	$sTmp = dirname(__FILE__).'/WbAutoloader.php';
243
	if(!class_exists('WbAutoloader')){ 
244
		include($sTmp);
245
	}
246
	WbAutoloader::doRegister(array(ADMIN_DIRECTORY=>'a', 'modules'=>'m', 'templates'=>'t', 'include'=>'i'));
244
    $sTmp = dirname(__FILE__).'/WbAutoloader.php';
245
    if(!class_exists('WbAutoloader')){
246
        include($sTmp);
247
    }
248
    WbAutoloader::doRegister(array(ADMIN_DIRECTORY=>'a', 'modules'=>'m', 'templates'=>'t', 'include'=>'i'));
247 249
// instantiate and initialize adaptor for temporary registry replacement ---
248 250
    $oReg = WbAdaptor::getInstance();
249
	$oReg->getWbConstants();
251
    $oReg->getWbConstants();
250 252
// register TWIG autoloader ---
251
	$sTmp = dirname(dirname(__FILE__)).'/include/Sensio/Twig/lib/Twig/Autoloader.php';
252
	if(!class_exists('Twig_Autoloader')) { 
253
		include($sTmp); 
254
	}
255
	Twig_Autoloader::register();
253
    $sTmp = dirname(dirname(__FILE__)).'/include/Sensio/Twig/lib/Twig/Autoloader.php';
254
    if(!class_exists('Twig_Autoloader') && is_readable($sTmp)) {
255
        include($sTmp);
256
    	Twig_Autoloader::register();
257
    }
256 258
// register PHPMailer autoloader ---
257
    if (!function_exists('PHPMailerAutoload')) {
258
        require($oReg->AppPath.'include/phpmailer/PHPMailerAutoload.php');
259
    $sTmp = $oReg->AppPath.'include/phpmailer/PHPMailerAutoload.php';
260
    if (!function_exists('PHPMailerAutoload') && is_readable($sTmp)) {
261
        require($sTmp);
259 262
    }
260 263
// aktivate exceptionhandler ---
261
	if(!function_exists('globalExceptionHandler')) {
262
		include(dirname(__FILE__).'/globalExceptionHandler.php');
263
	}
264
    if(!function_exists('globalExceptionHandler')) {
265
        include(dirname(__FILE__).'/globalExceptionHandler.php');
266
    }
264 267
// ---------------------------
265 268
// get Database connection data from configuration
266
	$aSqlData = initGetDbConnectData($aCfg, $sDbConnectType);
269
    $aSqlData = initGetDbConnectData($aCfg, $sDbConnectType);
267 270
// Create global database instance ---
268
	$oDb = $database = WbDatabase::getInstance();
269
	if($sDbConnectType == 'dsn') {
270
		$bTmp = $oDb->doConnect($aSqlData['dsn'], $aSqlData['user'], $aSqlData['password'], null, $aSqlData['addons']);
271
	}else {
272
		$bTmp = $oDb->doConnect($aSqlData['url']);
273
	}
271
    $oDb = $database = WbDatabase::getInstance();
272
    if($sDbConnectType == 'dsn') {
273
        $bTmp = $oDb->doConnect($aSqlData['dsn'], $aSqlData['user'], $aSqlData['password'], null, $aSqlData['addons']);
274
    }else {
275
        $bTmp = $oDb->doConnect($aSqlData['url']);
276
    }
274 277
// remove critical data from memory
275
	unset($aSqlData, $aCfg);
278
    unset($aSqlData, $aCfg);
276 279

  
277
	if(!defined('TABLE_PREFIX')) { define('TABLE_PREFIX', $oDb->TablePrefix); }
280
    if(!defined('TABLE_PREFIX')) { define('TABLE_PREFIX', $oDb->TablePrefix); }
278 281

  
279 282
// load global settings from database and define global consts from ---
280
	$sql = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'settings`';
281
	if(($oSettings = $database->query($sql))) {
282
		if(!$oSettings->numRows()) { throw new AppException('no settings found'); }
283
		while($aSetting = $oSettings->fetchRow(MYSQL_ASSOC)) {
284
			//sanitize true/false values
285
			$aSetting['value'] = ($aSetting['value'] == 'true' 
286
								  ? true 
287
								  : ($aSetting['value'] == 'false' 
288
									 ? false 
289
									 : $aSetting['value'])
290
								 );
291
			$sSettingName = strtoupper($aSetting['name']);
292
			switch($sSettingName):
293
				case 'STRING_FILE_MODE':
294
					$iTmp = ((intval(octdec($aSetting['value'])) & ~0111)|0600);
295
					if(!defined('OCTAL_FILE_MODE')) { define('OCTAL_FILE_MODE', $iTmp); }
296
					if(!defined('STRING_FILE_MODE')) { define('STRING_FILE_MODE', sprintf('0%03o', $iTmp)); }
297
					break;
298
				case 'STRING_DIR_MODE':
299
					$iTmp = (intval(octdec($aSetting['value'])) |0711);
300
					if(!defined('OCTAL_DIR_MODE')) { define('OCTAL_DIR_MODE', $iTmp); }
301
					if(!defined('STRING_DIR_MODE')) { define('STRING_DIR_MODE', sprintf('0%03o', $iTmp)); }
302
					break;
303
				case 'PAGES_DIRECTORY':
304
					// sanitize pages_directory
305
					$sTmp = trim($aSetting['value'], '/');
306
					$sTmp = ($sTmp == '' ? '' : '/'.$sTmp);
307
					if(!defined('PAGES_DIRECTORY')) { define('PAGES_DIRECTORY', $sTmp); }
308
					break;
309
				default: // make global const from setting
310
					if(!defined($sSettingName)) { define($sSettingName, $aSetting['value']); }
311
					break;
312
			endswitch;
313
		}
314
	}else { throw new AppException($database->get_error()); }
283
    $sql = 'SELECT `name`, `value` FROM `'.$oDb->TablePrefix.'settings`';
284
    if(($oSettings = $oDb->doQuery($sql))) {
285
        if(!$oSettings->numRows()) { throw new AppException('no settings found'); }
286
        while($aSetting = $oSettings->fetchRow(MYSQL_ASSOC)) {
287
            //sanitize true/false values
288
            $aSetting['value'] = ($aSetting['value'] == 'true'
289
                                  ? true
290
                                  : ($aSetting['value'] == 'false'
291
                                     ? false
292
                                     : $aSetting['value'])
293
                                 );
294
            $sSettingName = strtoupper($aSetting['name']);
295
            switch($sSettingName):
296
                case 'STRING_FILE_MODE':
297
                    $iTmp = ((intval(octdec($aSetting['value'])) & ~0111)|0600);
298
                    if(!defined('OCTAL_FILE_MODE')) { define('OCTAL_FILE_MODE', $iTmp); } // deprecated
299
                    if(!defined('FILE_MODE_OCTAL')) { define('FILE_MODE_OCTAL', $iTmp); }
300
                    if(!defined('STRING_FILE_MODE')) { define('STRING_FILE_MODE', sprintf('0%03o', $iTmp)); } // deprecated
301
                    if(!defined('FILE_MODE_STRING')) { define('FILE_MODE_STRING', sprintf('0%03o', $iTmp)); }
302
                    break;
303
                case 'STRING_DIR_MODE':
304
                    $iTmp = (intval(octdec($aSetting['value'])) |0711);
305
                    if(!defined('OCTAL_DIR_MODE')) { define('OCTAL_DIR_MODE', $iTmp); } // deprecated
306
                    if(!defined('DIR_MODE_OCTAL')) { define('DIR_MODE_OCTAL', $iTmp); }
307
                    if(!defined('STRING_DIR_MODE')) { define('STRING_DIR_MODE', sprintf('0%03o', $iTmp)); } // deprecated
308
                    if(!defined('DIR_MODE_STRING')) { define('DIR_MODE_STRING', sprintf('0%03o', $iTmp)); }
309
                    break;
310
                case 'PAGES_DIRECTORY':
311
                    // sanitize pages_directory
312
                    $sTmp = trim($aSetting['value'], '/');
313
                    $sTmp = ($sTmp == '' ? '' : '/'.$sTmp);
314
                    if(!defined('PAGES_DIRECTORY')) { define('PAGES_DIRECTORY', $sTmp); }
315
                    break;
316
                default: // make global const from setting
317
                    if(!defined($sSettingName)) { define($sSettingName, $aSetting['value']); }
318
                    break;
319
            endswitch;
320
        }
321
    }else { throw new AppException($database->get_error()); }
315 322
// set error-reporting from loaded settings ---
316
	if(intval(ER_LEVEL) > 0 ) {
317
		error_reporting(ER_LEVEL);
318
		if( intval(ini_get ( 'display_errors' )) == 0 ) {
319
			ini_set('display_errors', 1);
320
		}
321
	}
323
    if(intval(ER_LEVEL) > 0 ) {
324
        error_reporting(ER_LEVEL);
325
        if( intval(ini_get ( 'display_errors' )) == 0 ) {
326
            ini_set('display_errors', 1);
327
        }
328
    }
322 329
// Start a session ---
323
	if(!defined('SESSION_STARTED')) {
324
		session_name(APP_NAME.'_session_id');
325
		@session_start();
326
		define('SESSION_STARTED', true);
327
	}
330
    if(!defined('SESSION_STARTED')) {
331
        session_name(APP_NAME.'_session_id');
332
        @session_start();
333
        define('SESSION_STARTED', true);
334
    }
328 335
// get/set server timezone ---
329
	if(!defined('SERVER_TIMEZONE')) { define('SERVER_TIMEZONE', "UTC"); }
330
	date_default_timezone_set( SERVER_TIMEZONE );
331
	if(!defined('MAX_TIME')) { define('MAX_TIME', (pow(2, 31)-1)); } // 32-Bit Timestamp of 19 Jan 2038 03:14:07 GMT
332
	$sTmp = (isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] != '') ? $_SERVER['HTTP_DNT'] : '0';
333
	if(!defined('DO_NOT_TRACK')) { define('DO_NOT_TRACK', ($sTmp[0] == '1')); }
336
    if(!defined('SERVER_TIMEZONE')) { define('SERVER_TIMEZONE', "UTC"); }
337
    date_default_timezone_set( SERVER_TIMEZONE );
338
    if(!defined('MAX_TIME')) { define('MAX_TIME', (pow(2, 31)-1)); } // 32-Bit Timestamp of 19 Jan 2038 03:14:07 GMT
339
    $sTmp = (isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] != '') ? $_SERVER['HTTP_DNT'] : '0';
340
    if(!defined('DO_NOT_TRACK')) { define('DO_NOT_TRACK', ($sTmp[0] == '1')); }
334 341
// get/set users timezone ---
335
	if(!defined('TIMEZONE')) { define('TIMEZONE', (isset($_SESSION['TIMEZONE']) ? $_SESSION['TIMEZONE'] : DEFAULT_TIMEZONE)); }
336
	if(!defined('DATE_FORMAT')) { define('DATE_FORMAT', (isset($_SESSION['DATE_FORMAT']) ? $_SESSION['DATE_FORMAT'] : DEFAULT_DATE_FORMAT)); }
337
	if(!defined('TIME_FORMAT')) { define('TIME_FORMAT', (isset($_SESSION['TIME_FORMAT']) ? $_SESSION['TIME_FORMAT'] : DEFAULT_TIME_FORMAT)); }
342
    if(!defined('TIMEZONE')) { define('TIMEZONE', (isset($_SESSION['TIMEZONE']) ? $_SESSION['TIMEZONE'] : DEFAULT_TIMEZONE)); }
343
    if(!defined('DATE_FORMAT')) { define('DATE_FORMAT', (isset($_SESSION['DATE_FORMAT']) ? $_SESSION['DATE_FORMAT'] : DEFAULT_DATE_FORMAT)); }
344
    if(!defined('TIME_FORMAT')) { define('TIME_FORMAT', (isset($_SESSION['TIME_FORMAT']) ? $_SESSION['TIME_FORMAT'] : DEFAULT_TIME_FORMAT)); }
338 345
// set Theme directory --- 
339
	if(!defined('THEME_URL')) { define('THEME_URL',  WB_URL.'/templates/'.DEFAULT_THEME); }
340
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME); }
341
	if(!defined('THEME_REL')) { define('THEME_REL',  WB_REL.'/templates/'.DEFAULT_THEME); }
346
    if(!defined('THEME_URL')) { define('THEME_URL',  WB_URL.'/templates/'.DEFAULT_THEME); }
347
    if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME); }
348
    if(!defined('THEME_REL')) { define('THEME_REL',  WB_REL.'/templates/'.DEFAULT_THEME); }
342 349
// extended wb editor settings
343
	if(!defined('EDIT_ONE_SECTION')) { define('EDIT_ONE_SECTION', false); }
344
	if(!defined('EDITOR_WIDTH')) { define('EDITOR_WIDTH', 0); }
350
    if(!defined('EDIT_ONE_SECTION')) { define('EDIT_ONE_SECTION', false); }
351
    if(!defined('EDITOR_WIDTH')) { define('EDITOR_WIDTH', 0); }
345 352
// define form security class and preload it ---
346
	$sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
347
	$sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
348
	require_once($sSecMod);
353
    $sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
354
    $sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
355
    require_once($sSecMod);
349 356
// *** begin deprecated part *************************************************************
350 357
// load settings for use in Captch and ASP module
351
	if (!defined('WB_INSTALL_PROCESS') && !defined('ENABLED_CAPTCHA')) {
352
		$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_captcha_control`';
353
		// request settings from database
354
		if(($oSettings = $database->query($sql))) {
355
			if(($aSetting = $oSettings->fetchRow(MYSQL_ASSOC))) {
356
				define('ENABLED_CAPTCHA', ($aSetting['enabled_captcha'] == '1'));
357
				define('ENABLED_ASP', ($aSetting['enabled_asp'] == '1'));
358
				define('CAPTCHA_TYPE', $aSetting['captcha_type']);
359
				define('ASP_SESSION_MIN_AGE', (int)$aSetting['asp_session_min_age']);
360
				define('ASP_VIEW_MIN_AGE', (int)$aSetting['asp_view_min_age']);
361
				define('ASP_INPUT_MIN_AGE', (int)$aSetting['asp_input_min_age']);
362
			}
363
		}
364
	}
365
	if(defined('ENABLED_ASP') && ENABLED_ASP && !isset($_SESSION['session_started'])) {
366
		$_SESSION['session_started'] = time();
367
	}
358
    if (!defined('WB_INSTALL_PROCESS') && !defined('ENABLED_CAPTCHA')) {
359
        $sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_captcha_control`';
360
        // request settings from database
361
        if(($oSettings = $database->query($sql))) {
362
            if(($aSetting = $oSettings->fetchRow(MYSQL_ASSOC))) {
363
                define('ENABLED_CAPTCHA', ($aSetting['enabled_captcha'] == '1'));
364
                define('ENABLED_ASP', ($aSetting['enabled_asp'] == '1'));
365
                define('CAPTCHA_TYPE', $aSetting['captcha_type']);
366
                define('ASP_SESSION_MIN_AGE', (int)$aSetting['asp_session_min_age']);
367
                define('ASP_VIEW_MIN_AGE', (int)$aSetting['asp_view_min_age']);
368
                define('ASP_INPUT_MIN_AGE', (int)$aSetting['asp_input_min_age']);
369
            }
370
        }
371
    }
372
    if(defined('ENABLED_ASP') && ENABLED_ASP && !isset($_SESSION['session_started'])) {
373
        $_SESSION['session_started'] = time();
374
    }
368 375
// *** end of deprecated part ************************************************************
369 376
// get user language ---
370 377
    $sRequestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
......
389 396
// activate translations / load language definitions
390 397
/** begin of deprecated part || will be replaced by class Translate **/	
391 398
// Load Language file
392
	if(!file_exists(WB_PATH.'/languages/'.LANGUAGE.'.php')) {
393
		$sMsg = 'Error loading language file '.LANGUAGE.', please check configuration';
394
		throw new AppException($sMsg);
395
	} else {
396
	// include language file
397
		require_once(WB_PATH.'/languages/'.LANGUAGE.'.php');
398
	}
399
    if(!file_exists(WB_PATH.'/languages/'.LANGUAGE.'.php')) {
400
        $sMsg = 'Error loading language file '.LANGUAGE.', please check configuration';
401
        throw new AppException($sMsg);
402
    } else {
403
    // include language file
404
        require_once(WB_PATH.'/languages/'.LANGUAGE.'.php');
405
    }
399 406
/** end of deprecated part **/
400 407
// instantiate and initialize adaptor for temporary registry replacement ---
401
	$oReg->getWbConstants();
408
    $oReg->getWbConstants();
402 409
// load and activate new global translation table
403
	Translate::getInstance()->initialize('en',
404
										 (defined('DEFAULT_LANGUAGE') ? DEFAULT_LANGUAGE : ''), 
405
										 (defined('LANGUAGE') ? LANGUAGE : ''),
406
										 'WbOldStyle',
407
										 (Translate::CACHE_DISABLED|Translate::KEEP_MISSING)
408
//										 (DEBUG ? Translate::CACHE_DISABLED|Translate::KEEP_MISSING : 0)
409
										);
410
	if(!class_exists('PasswordHash', false)) { include(WB_PATH.'/include/phpass/PasswordHash.php'); }
411
	$oPass = Password::getInstance(new PasswordHash(Password::CRYPT_LOOPS_DEFAULT, Password::HASH_TYPE_AUTO));
412
	if(defined('PASSWORD_CRYPT_LOOPS')) { $oPass->setIteration(PASSWORD_CRYPT_LOOPS); }
413
	if(defined('PASSWORD_HASH_TYPES'))  { $oPass->setHashType(PASSWORD_HASH_TYPES); }
414
// *** END OF FILE ***********************************************************************
415
 
410
    $oTrans = Translate::getInstance();
411
/* initializise Translate old style */
412
    $oTrans->initialize(
413
        'en',
414
        (defined('DEFAULT_LANGUAGE') ? DEFAULT_LANGUAGE : ''),
415
        (defined('LANGUAGE') ? LANGUAGE : ''),
416
        'WbOldStyle',
417
//        (Translate::CACHE_DISABLED|Translate::KEEP_MISSING),
418
        (DEBUG ? Translate::CACHE_DISABLED|Translate::KEEP_MISSING : 0)
419
    );
420
/* initializise Translate new style */
421
/*
422
    $oTrans->initialize(
423
        new TranslateAdaptorWbOldStyle,
424
        'en',
425
        (defined('DEFAULT_LANGUAGE') ? DEFAULT_LANGUAGE : ''),
426
        (defined('LANGUAGE') ? LANGUAGE : ''),
427
//        (Translate::CACHE_DISABLED|Translate::KEEP_MISSING),
428
        (DEBUG ? Translate::CACHE_DISABLED|Translate::KEEP_MISSING : 0),
429
        $oReg->DirModeOctal,
430
        $oReg->TempPath
431
    );
432
 */
433
/* ****** */
434
    $oReg->setDatabase(WbDatabase::getInstance());
435
    $oReg->setTranslate(Translate::getInstance());
436
    if(!class_exists('PasswordHash', false)) { include(WB_PATH.'/include/phpass/PasswordHash.php'); }
437
    $oPass = Password::getInstance(new PasswordHash(Password::CRYPT_LOOPS_DEFAULT, Password::HASH_TYPE_AUTO));
438
    if(defined('PASSWORD_CRYPT_LOOPS')) { $oPass->setIteration(PASSWORD_CRYPT_LOOPS); }
439
    if(defined('PASSWORD_HASH_TYPES'))  { $oPass->setHashType(PASSWORD_HASH_TYPES); }
440
/* *** END OF FILE ******************************************************************** */
branches/2.8.x/wb/framework/SqlImport.php
106 106
    {
107 107
        $bRetval = false;
108 108
        // test if selected collation is available on current server.
109
        $sql = 'SHOW COLLATION LIKE \''.$this->oDb->escapeString($sCollation).'\'';
109
        $sql = 'SHOW COLLATION LIKE \''.$this->oDb->escapeString(addcslashes($sCollation, '_%')).'\'';
110 110
        if (($oAvailCollations = $this->oDb->doQuery($sql))) {
111 111
            if (($oAvailCollations->numRows())) {
112 112
                //use new collation
......
173 173
                $sAction
174 174
            )
175 175
        );
176
        $sAction = ($sAction == '' ? 'install' : $sAction);
177
        if ($this->importSql($sAction)) {
176
        if ($this->importSql(($sAction == '' ? 'install' : $sAction))) {
178 177
            return true;
179 178
        } else {
180 179
            $this->aErrMsg[] = $this->oDb->getError();

Also available in: Unified diff