Project

General

Profile

« Previous | Next » 

Revision 6

Added by Manuela over 6 years ago

modified class database to default charset utf8mb4
added property database->sTablePrefix

View differences:

branches/main/admin/interface/version.php
48 48

  
49 49
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
50 50
if(!defined('VERSION')) { define('VERSION', '2.10.1-dev'); }
51
if(!defined('REVISION')) { define('REVISION', '5'); }
51
if(!defined('REVISION')) { define('REVISION', '6'); }
52 52
if(!defined('SP')) { define('SP', ''); }
53 53

  
branches/main/framework/class.database.php
36 36

  
37 37
    private $db_handle  = null; // readonly from outside
38 38
    private $db_name    = '';
39
    private $sTablePrefix = '';
39 40
    private $connected  = false;
40
    private $sCharset   = '';
41
    private $sCharset   = 'utf8mb4';
42
    private $sCollation = 'utf8mb4_unicode_ci';
41 43
    private $error      = '';
42 44
    private $error_no   = array();
43 45
    private $error_type = '';
......
46 48

  
47 49

  
48 50
    // Set DB_URL
49
    function __construct($url = '') {
51
    function __construct($url = '')
52
    {
50 53
        // Connect to database
51 54
        if (!$this->connect()) {
52 55
            throw new DatabaseException($this->get_error());
53 56
        }
57
        $this->sTablePrefix = TABLE_PREFIX;
54 58
    }
55 59

  
56 60
    // Connect to the database   DB_CHARSET
57
    function connect() {
58

  
59
        $this->sCharset = strtolower(preg_replace('/[^a-z0-9]/i', '', (defined('DB_CHARSET') ? DB_CHARSET : '')));
60

  
61
        if (defined('DB_PORT')) {
62
            $port = DB_PORT;
63
        } else {
64
            $port = ini_get('mysqli.default_port');
65
        }
61
    function connect()
62
    {
63
        $aTmp = preg_split(
64
            '/[^a-z0-9]/i',
65
            strtolower(preg_replace('/[^a-z0-9_]/i', '', (defined('DB_CHARSET') ? DB_CHARSET : 'utf8mb4_unicode_ci')))
66
        );
67
        $this->sCharset = $aTmp[0];
68
        $this->sCollation = implode('_', $aTmp);
69
        $port = defined('DB_PORT') ? DB_PORT : ini_get('mysqli.default_port');
66 70
        if (!($this->db_handle = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME, $port))) {
67 71
            $this->connected = false;
68 72
            $this->error = mysqli_connect_error();
69 73
        } else {
70 74
            if ($this->sCharset) {
71
                @mysqli_query($this->db_handle, 'SET NAMES '.$this->sCharset);
75
                mysqli_query($this->db_handle, 'SET NAMES '.$this->sCharset);
72 76
                mysqli_set_charset($this->db_handle, $this->sCharset);
73 77
            }
74 78
            $this->db_name = DB_NAME;
......
78 82
    }
79 83

  
80 84
    // Disconnect from the database
81
    function disconnect() {
85
    function disconnect()
86
    {
82 87
        if($this->connected==true) {
83 88
            mysqli_close();
84 89
            return true;
......
88 93
    }
89 94

  
90 95
    // Run a query
91
    function query($statement) {
96
    function query($statement)
97
    {
92 98
        $mysql = new mysql($this->db_handle);
93 99
        $mysql->query($statement);
94 100
        $this->set_error($mysql->error());
......
114 120
    }
115 121

  
116 122
    // Set the DB error
117
    function set_error($message = null) {
123
    function set_error($message = null)
124
    {
118 125
        $this->error = $message;
119 126
        $this->error_type = 'unknown';
120 127
        if ($message!=''){
......
122 129
    }
123 130

  
124 131
    // Return true if there was an error
125
    function is_error() {
132
    function is_error()
133
    {
126 134
        return (!empty($this->error)) ? true : false;
127 135
    }
128 136

  
129 137
    // Return the error
130
    function get_error() {
138
    function get_error()
139
    {
131 140
        return $this->error;
132 141
    }
133 142
    // Return the errno
134
    function get_errno() {
143
    function get_errno()
144
    {
135 145
        return $this->is_error() ? mysqli_errno($this->db_handle) : 0;
136 146
    }
137 147
/**
......
150 160
            case 'DbName':
151 161
                $retval = $this->db_name;
152 162
                break;
163
            case 'sTablePrefix':
164
            case 'TablePrefix':
165
                $retval = $this->sTablePrefix;
166
                break;
153 167
            default:
154 168
                $retval = null;
155 169
                break;
......
347 361
        $sTablePrefix  = '',
348 362
        $mAction       = true,
349 363
        $sTblEngine    = 'MyISAM',
350
        $sTblCollation = 'utf8_unicode_ci'
364
        $sTblCollation = 'utf8mb4_unicode_ci'
351 365
    ) {
352 366
        $iCount = 0;
353 367
        $sSqlBuffer  = '';
......
477 491
define('MYSQLI_SEEK_FIRST', 0);
478 492
define('MYSQLI_SEEK_LAST', -1);
479 493

  
480
class mysql {
481

  
494
class mysql
495
{
482 496
    private $db_handle = null;
483 497
    private $result = null;
484 498
    private $error = '';
485 499

  
486
    public function __construct($handle) {
500
    public function __construct($handle)
501
    {
487 502
        $this->db_handle = $handle;
488 503
    }
489 504
/**
......
507 522
    }
508 523

  
509 524
    // Fetch num rows
510
    public function numRows() {
525
    public function numRows()
526
    {
511 527
        return mysqli_num_rows($this->result);
512 528
    }
513 529

  
514 530
    // Fetch row  $typ = MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH
515
    public function fetchRow($typ = MYSQLI_BOTH) {
531
    public function fetchRow($typ = MYSQLI_BOTH)
532
    {
516 533
        return mysqli_fetch_array($this->result, $typ);
517 534
    }
518 535
/**
......
586 603
    }
587 604

  
588 605
    // Get error
589
    public function error() {
590
        if(isset($this->error)) {
606
    public function error()
607
    {
608
        if (isset($this->error)) {
591 609
            return $this->error;
592 610
        } else {
593 611
            return null;
branches/main/framework/initialize.php
15 15
 * @lastmodified    $Date$
16 16
 *
17 17
 */
18
error_reporting( -1 );
19
$sStarttime = array_sum(explode(" ", microtime()));
20
$aPhpFunctions = get_defined_functions();
18
// $aPhpFunctions = get_defined_functions();
21 19
/**
22 20
 * sanitize $_SERVER['HTTP_REFERER']
23 21
 * @param string $sWbUrl qualified startup URL of current application
24 22
 */
25
function SanitizeHttpReferer($sWbUrl = WB_URL) {
23
function SanitizeHttpReferer($sWbUrl = WB_URL)
24
{
26 25
    $sTmpReferer = '';
27 26
    if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != '') {
28 27
        define('ORG_REFERER', ($_SERVER['HTTP_REFERER'] ?: ''));
......
60 59
    return preg_replace('/^(.*)$/', '[$1]', $aList);
61 60
}
62 61

  
63
/* ***************************************************************************************
64
 * Start initialization                                                                  *
65
 ****************************************************************************************/// aktivate exceptionhandler ---
66
//    throw new Exception('PHP-'.PHP_VERSION.' found, but at last PHP-5.3.6 required !!');
67
// Stop execution if PHP version is too old
68
// PHP less then 5.6.0 is prohibited ---
69
if (version_compare(PHP_VERSION, '5.6.0', '<')) {
70
    $sMsg = '<p style="color: #ff0000;">WebsiteBaker is not able to run with PHP-Version less then 5.6.0!!<br />'
71
          . 'Please change your PHP-Version to any kind from 5.6.0 and up!<br />'
72
          . 'If you have problems to solve that, ask your hosting provider for it.<br  />'
73
          . 'The very best solution is the use of PHP-7.0 and up</p>';
74
    die($sMsg);
75
}
76

  
77
/* -------------------------------------------------------- */
78
if ( !defined('WB_PATH')) { define('WB_PATH', dirname(__DIR__)); }
79
// *** initialize Exception handling
80
if(!function_exists('globalExceptionHandler')) {
81
    include(__DIR__.'/globalExceptionHandler.php');
82
}
83
// *** initialize Error handling
84
$sErrorLogFile = dirname(__DIR__).'/var/logs/php_error.log.php';
85
$sErrorLogPath = dirname($sErrorLogFile);
86

  
87
if (!file_exists($sErrorLogFile)) {
88
    $sTmp = '<?php die(\'illegal file access\'); ?>'
89
          . 'created: ['.date('c').']'.PHP_EOL;
90
    if (false === file_put_contents($sErrorLogFile, $sTmp, FILE_APPEND)) {
91
        throw new Exception('unable to create logfile \'/var/logs/php_error.log.php\'');
92
    }
93
}
94
if (!is_writeable($sErrorLogFile)) {
95
    throw new Exception('not writeable logfile \'/var/logs/php_error.log.php\'');
96
}
97
ini_set('log_errors', 1);
98
ini_set ('error_log', $sErrorLogFile);
99

  
100 62
/**
101 63
 * Read DB settings from configuration file
102 64
 * @return array
......
143 105
 * Set constants for system/install values
144 106
 * @throws RuntimeException
145 107
 */
146
function initSetInstallWbConstants($aCfg) {
108
function initSetInstallWbConstants($aCfg)
109
{
147 110
    if (sizeof($aCfg)) {
148 111
        foreach($aCfg['Constants'] as $key=>$value) {
149 112
            switch($key):
......
265 228
    }
266 229
    $aBt= debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
267 230
    $x = sizeof($aBt) -1;
268
    $x = $x < 0 ? 0 : ($x <= 2 ? $x : 2);
231
    $iSize = $x < 0 ? 0 : ($x <= 2 ? $x : 2);
269 232
    $sEntry = date('c').' '.'['.$sErrorType.'] '.str_replace(dirname(__DIR__), '', $sErrorFile).':['.$iErrorLine.'] '
270
            . ' from '.str_replace(dirname(__DIR__), '', $aBt[$x]['file']).':['.$aBt[$x]['line'].'] '
271
            . (@$aBt[$x]['class'] ? $aBt[$x]['class'].$aBt[$x]['type'] : '').$aBt[$x]['function'].' '
233
            . ' from '.str_replace(dirname(__DIR__), '', $aBt[$iSize]['file']).':['.$aBt[$iSize]['line'].'] '
234
            . (isset($aBt[$iSize]['class']) ? $aBt[$iSize]['class'].$aBt[$iSize]['type'] : '').$aBt[$iSize]['function'].' '
272 235
            . '"'.$sErrorText.'"'.PHP_EOL;
273 236
    file_put_contents($sErrorLogFile, $sEntry, FILE_APPEND);
274 237
    return $bRetval;
275 238
}
239
/**
240
 * create / recreate a admin object
241
 * @param string $section_name (default: '##skip##')
242
 * @param string $section_permission (default: 'start')
243
 * @param bool $auto_header (default: true)
244
 * @param bool $auto_auth (default: true)
245
 * @return \admin
246
 */
247
function newAdmin($section_name= '##skip##', $section_permission = 'start', $auto_header = true, $auto_auth = true)
248
{
249
    if (isset($GLOBALS['admin']) && $GLOBALS['admin'] instanceof admin) {
250
        unset($GLOBALS['admin']);
251
        usleep(10000);
252
    }
253
    return new admin($section_name, $section_permission, $auto_header, $auto_auth);
254
}
255

  
276 256
/* ***************************************************************************************
277 257
 * Start initialization                                                                  *
278 258
 ****************************************************************************************/
279
// activate errorhandler
259
    // Stop execution if PHP version is too old
260
    // PHP less then 5.6.0 is prohibited ---
261
    if (version_compare(PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION.'.'.PHP_RELEASE_VERSION, '5.6.0', '<')) {
262
        $sMsg = '<p style="color: #ff0000;">WebsiteBaker is not able to run with PHP-Version less then 5.6.0!!<br />'
263
              . 'Please change your PHP-Version to any kind from 5.6.0 and up!<br />'
264
              . 'If you have problems to solve that, ask your hosting provider for it.<br  />'
265
              . 'The very best solution is the use of PHP-7.0 and up</p>';
266
        die($sMsg);
267
    }
268
    error_reporting(E_ALL);
269
    $sStarttime = array_sum(explode(" ", microtime()));
270
    /* -------------------------------------------------------- */
271
    if ( !defined('WB_PATH')) { define('WB_PATH', dirname(__DIR__)); }
272
    // *** initialize Exception handling
273
    if(!function_exists('globalExceptionHandler')) {
274
        include(__DIR__.'/globalExceptionHandler.php');
275
    }
276
    // *** initialize Error handling
277
    $sErrorLogFile = dirname(__DIR__).'/var/logs/php_error.log.php';
278
    $sErrorLogPath = dirname($sErrorLogFile);
279

  
280
    if (!file_exists($sErrorLogFile)) {
281
        $sTmp = '<?php die(\'illegal file access\'); ?>'
282
              . 'created: ['.date('c').']'.PHP_EOL;
283
        if (false === file_put_contents($sErrorLogFile, $sTmp, FILE_APPEND)) {
284
            throw new Exception('unable to create logfile \'/var/logs/php_error.log.php\'');
285
        }
286
    }
287
    if (!is_writeable($sErrorLogFile)) {
288
        throw new Exception('not writeable logfile \'/var/logs/php_error.log.php\'');
289
    }
290
    ini_set('log_errors', 1);
291
    ini_set ('error_log', $sErrorLogFile);
292

  
293
// activate errorhandler *****************************************************************
280 294
    set_error_handler('WbErrorHandler', -1 );
281
    if (! defined('SYSTEM_RUN')) { define('SYSTEM_RUN', true); }
295
    defined('SYSTEM_RUN') ? '' : define('SYSTEM_RUN', true);
282 296
// load configuration ---
283 297
    $aCfg = initReadSetupFile();
284 298
    initSetInstallWbConstants($aCfg);
285 299
// ---------------------------
286 300
// get Database connection data from configuration
287
if (!defined('ADMIN_DIRECTORY')) { define('ADMIN_DIRECTORY', 'admin'); }
288
if (!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
289
    throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
290
}
291
if ( !defined('ADMIN_URL')) { define('ADMIN_URL', WB_URL.'/'.ADMIN_DIRECTORY); }
292
if ( !defined('ADMIN_PATH')) { define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY); }
293
if ( !defined('WB_REL')){
294
    $x1 = parse_url(WB_URL);
295
    define('WB_REL', (isset($x1['path']) ? $x1['path'] : ''));
296
}
297
if ( !defined('DOCUMENT_ROOT')) {
298
    define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(str_replace('\\', '/', WB_REL), '/').'$/', '', str_replace('\\', '/', WB_PATH)));
299
    $_SERVER['DOCUMENT_ROOT'] = DOCUMENT_ROOT;
300
}
301
    defined('ADMIN_DIRECTORY') ? '' : define('ADMIN_DIRECTORY', 'admin');
302
    if (!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
303
        throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
304
    }
305
    defined('ADMIN_URL') ? '' : define('ADMIN_URL', WB_URL.'/'.ADMIN_DIRECTORY);
306
    defined('ADMIN_PATH') ? '' : define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY);
307
    if ( !defined('WB_REL')){
308
        $x1 = parse_url(WB_URL);
309
        define('WB_REL', (isset($x1['path']) ? $x1['path'] : ''));
310
    }
311
    if ( !defined('DOCUMENT_ROOT')) {
312
        define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(str_replace('\\', '/', WB_REL), '/').'$/', '', str_replace('\\', '/', WB_PATH)));
313
        $_SERVER['DOCUMENT_ROOT'] = DOCUMENT_ROOT;
314
    }
315
// activate Autoloader
316
    if (!class_exists('\bin\Autoloader')) {
317
        include __DIR__.'/Autoloader.php';
318
    }
319
    \bin\Autoloader::doRegister();
320

  
301 321
if (file_exists(WB_PATH.'/framework/class.database.php')) {
302 322
    // sanitize $_SERVER['HTTP_REFERER']
303 323
    SanitizeHttpReferer(WB_URL);
......
311 331
// register PHPMailer autoloader ---
312 332
    $sTmp = dirname(dirname(__FILE__)).'/include/phpmailer/PHPMailerAutoload.php';
313 333
    if (!function_exists('PHPMailerAutoload') && is_readable($sTmp)) {
314
        require($sTmp);
334
        include $sTmp;
315 335
    }
316 336

  
317
    if (!class_exists('database', false)){
318
      // load database class
319
      require(__DIR__.'/class.database.php');
337
//    if (!class_exists('database', false)){
338
//      // load database class
339
//      require(__DIR__.'/class.database.php');
320 340
      // Create database class
321 341
      $database = new database();
322
      $database->sTablePrefix = TABLE_PREFIX;
323
    }
342
//    }
324 343

  
325 344
    // activate frontend OutputFilterApi (initialize.php)
326 345
    if (is_readable(WB_PATH .'/modules/output_filter/OutputFilterApi.php')) {
......
330 349
    } else {
331 350
        throw new RuntimeException('missing mandatory global OutputFilterApi!');
332 351
    }
333
    if (version_compare(PHP_VERSION, '5.4.0', '<')) {
334
        @ini_set("magic_quotes_runtime", 0); // Disable magic_quotes_runtime
335
        @ini_set("magic_quotes_gpc", 0); // Disable magic_quotes_gpc
336
    }
337
    if (get_magic_quotes_gpc()) {
338
        $unescape = function(&$value, $key) {
339
            $value = stripslashes($value);
340
        };
341
        array_walk_recursive($_POST, $unescape);
342
        array_walk_recursive($_GET,  $unescape);
343
        array_walk_recursive($_REQUEST, $unescape);
344
        array_walk_recursive($_COOKIE, $unescape);
345
    }
346 352
    // Get website settings (title, keywords, description, header, and footer)
347 353
    $sql = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'settings`';
348 354
    if (($get_settings = $database->query($sql))) {
......
356 362
            if ($setting_value == 'true') {
357 363
                $setting_value = true;
358 364
            }
359
            @define($setting_name, $setting_value);
365
            defined($setting_name) ? '' : define($setting_name, $setting_value);
360 366
            $x++;
361 367
        }
362 368
    } else {
......
365 371
    if (!$x) {
366 372
        throw new RuntimeException('no settings found');
367 373
    }
368
    @define('DO_NOT_TRACK', (isset($_SERVER['HTTP_DNT'])));
369
    ini_set('display_errors', ((defined('DEBUG')&& (DEBUG==true)) ?'1':'0'));
374
    defined('DO_NOT_TRACK') ? '' : define('DO_NOT_TRACK', (isset($_SERVER['HTTP_DNT'])));
375
    ini_set('display_errors', ((defined('DEBUG') && (DEBUG==true)) ?'1':'0'));
370 376

  
371
    if (!defined('DEBUG')){ define('DEBUG', false); }
372
    $string_file_mode = defined('STRING_FILE_MODE')?STRING_FILE_MODE:'0644';
373
    @define('OCTAL_FILE_MODE',(int) octdec($string_file_mode));
374
    $string_dir_mode = defined('STRING_DIR_MODE')?STRING_DIR_MODE:'0755';
375
    @define('OCTAL_DIR_MODE',(int) octdec($string_dir_mode));
377
    defined('DEBUG') ? '' : define('DEBUG', false);
378
    $string_file_mode = defined('STRING_FILE_MODE') ? STRING_FILE_MODE : '0644';
379
    defined('OCTAL_FILE_MODE') ? '' : define('OCTAL_FILE_MODE', (int) octdec($string_file_mode));
380
    $string_dir_mode = defined('STRING_DIR_MODE') ? STRING_DIR_MODE : '0755';
381
    defined('OCTAL_DIR_MODE')  ? '' : define('OCTAL_DIR_MODE',  (int) octdec($string_dir_mode));
376 382
//    $sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
377 383
//    $sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
378 384
//    require_once($sSecMod);
379
    if (!defined("WB_INSTALL_PROCESS")) {
385
    if (!defined('WB_INSTALL_PROCESS')) {
380 386
    // get CAPTCHA and ASP settings
381 387
        $sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_captcha_control`';
382 388
        if (($get_settings = $database->query($sql)) &&
383 389
            ($setting = $get_settings->fetchRow(MYSQLI_ASSOC))
384 390
        ) {
385
            @define('ENABLED_CAPTCHA', (($setting['enabled_captcha'] == '1') ? true : false));
386
            @define('ENABLED_ASP', (($setting['enabled_asp'] == '1') ? true : false));
387
            @define('CAPTCHA_TYPE', $setting['captcha_type']);
388
            @define('ASP_SESSION_MIN_AGE', (int)$setting['asp_session_min_age']);
389
            @define('ASP_VIEW_MIN_AGE', (int)$setting['asp_view_min_age']);
390
            @define('ASP_INPUT_MIN_AGE', (int)$setting['asp_input_min_age']);
391
            defined('ENABLED_CAPTCHA')     ? '' : define('ENABLED_CAPTCHA',     (bool) ($setting['enabled_captcha'] == '1'));
392
            defined('ENABLED_ASP')         ? '' : define('ENABLED_ASP',         (bool) ($setting['enabled_asp'] == '1'));
393
            defined('CAPTCHA_TYPE')        ? '' : define('CAPTCHA_TYPE',        $setting['captcha_type']);
394
            defined('ASP_SESSION_MIN_AGE') ? '' : define('ASP_SESSION_MIN_AGE', (int) $setting['asp_session_min_age']);
395
            defined('ASP_VIEW_MIN_AGE')    ? '' : define('ASP_VIEW_MIN_AGE',    (int) $setting['asp_view_min_age']);
396
            defined('ASP_INPUT_MIN_AGE')   ? '' : define('ASP_INPUT_MIN_AGE',   (int) $setting['asp_input_min_age']);
391 397
        } else {
392 398
            throw new RuntimeException('CAPTCHA-Settings not found');
393 399
        }
......
442 448
            require $slangFile;
443 449
        }
444 450
    }
445
    if (!class_exists('Translate', false)) {
446
        include __DIR__.'/Translate.php';
447
    }
451
//    if (!class_exists('Translate', false)) {
452
//        include __DIR__.'/Translate.php';
453
//    }
448 454
    $oTrans = Translate::getInstance();
449 455
    $oTrans->initialize(array('EN', DEFAULT_LANGUAGE, LANGUAGE), $sCachePath); // 'none'
450 456
    // Get users timezone
......
472 478
    define('EDIT_ONE_SECTION', false);
473 479
    define('EDITOR_WIDTH', 0);
474 480
}
475

  
476
function newAdmin($section_name= '##skip##', $section_permission = 'start', $auto_header = true, $auto_auth = true)
477
{
478
    if (isset($GLOBALS['admin']) && $GLOBALS['admin'] instanceof admin) {
479
        unset($GLOBALS['admin']);
480
        usleep(10000);
481
    }
482
    return new admin($section_name, $section_permission, $auto_header, $auto_auth);
483
}

Also available in: Unified diff