- Timestamp:
- Jul 10, 2019 2:01:24 AM (5 years ago)
- Location:
- trunk/lib
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/App.inc.php
r692 r693 54 54 public $running = false; 55 55 56 // Instance of database object .56 // Instance of database object (from mysql_connect() PHP version < 7). 57 57 public $db; 58 59 // Instance of PDO object. 60 public $pdo; 58 61 59 62 // Instance of database session handler object. … … 135 138 // Use database? 136 139 'enable_db' => false, 140 'enable_db_pdo' => false, 137 141 138 142 // Use db-based sessions? … … 397 401 */ 398 402 399 if (true === $this->getParam('enable_db') ) {403 if (true === $this->getParam('enable_db') || true === $this->getParam('enable_db_pdo')) { 400 404 401 405 // DB connection parameters taken from environment variables in the server httpd.conf file (readable only by root)⊠… … 418 422 if (false !== $db_auth_file = stream_resolve_include_path($this->getParam('db_auth_file'))) { 419 423 if (is_readable($db_auth_file)) { 420 $this->setParam(json_decode(file_get_contents($db_auth_file), true)); 424 $db_auth = json_decode(file_get_contents($db_auth_file), true); 425 if (is_null($db_auth)) { 426 $app->logMsg(sprintf('Unable to decode json in DB auth file: %s', $db_auth_file), LOG_ERR, __FILE__, __LINE__); 427 } else { 428 $this->setParam($db_auth); 429 } 421 430 } else { 422 $this->logMsg(sprintf('Unable to read DB auth file: %s', $db_auth_file), LOG_ NOTICE, __FILE__, __LINE__);431 $this->logMsg(sprintf('Unable to read DB auth file: %s', $db_auth_file), LOG_ERR, __FILE__, __LINE__); 423 432 } 424 433 } else { 425 $this->logMsg(sprintf('DB auth file not found: %s', $this->getParam('db_auth_file')), LOG_ NOTICE, __FILE__, __LINE__);434 $this->logMsg(sprintf('DB auth file not found: %s', $this->getParam('db_auth_file')), LOG_ERR, __FILE__, __LINE__); 426 435 } 427 436 } 428 437 429 // There will ever only be one instance of the DB object, and here is where it is instantiated.430 require_once dirname(__FILE__) . '/ DB.inc.php';431 $this-> db =& DB::getInstance();432 $this-> db->setParam(array(438 // If the app wants a DB connection, always set up a PDO object. 439 require_once dirname(__FILE__) . '/PDO.inc.php'; 440 $this->pdo =& \Strangecode\Codebase\PDO::getInstance(); 441 $this->pdo->setParam(array( 433 442 'db_server' => $this->getParam('db_server'), 434 443 'db_name' => $this->getParam('db_name'), … … 442 451 'collation' => $this->getParam('db_collation'), 443 452 )); 444 445 // Connect to database. 446 $this->db->connect(); 453 $this->pdo->connect(); 454 455 // Only create a legacy mysql_* DB object if it is explicitly requested. 456 if (true === $this->getParam('enable_db')) { 457 require_once dirname(__FILE__) . '/DB.inc.php'; 458 $this->db =& DB::getInstance(); 459 $this->db->setParam(array( 460 'db_server' => $this->getParam('db_server'), 461 'db_name' => $this->getParam('db_name'), 462 'db_user' => $this->getParam('db_user'), 463 'db_pass' => $this->getParam('db_pass'), 464 'db_always_debug' => $this->getParam('db_always_debug'), 465 'db_debug' => $this->getParam('db_debug'), 466 'db_die_on_failure' => $this->getParam('db_die_on_failure'), 467 'timezone' => $this->getParam('db_timezone'), 468 'character_set' => $this->getParam('db_character_set'), 469 'collation' => $this->getParam('db_collation'), 470 )); 471 $this->db->connect(); 472 } 447 473 } 448 474 … … 506 532 507 533 // To get a safe hostname, remove port and invalid hostname characters. 508 $safe_http_host = preg_replace('/[^a-z\d.:-]/ ', '', strtok(getenv('HTTP_HOST'), ':')); // FIXME: strtok shouldn't be used if there is a chance HTTP_HOST may be empty except for the port, e.g., `:80` will return `80`534 $safe_http_host = preg_replace('/[^a-z\d.:-]/u', '', strtok(getenv('HTTP_HOST'), ':')); // FIXME: strtok shouldn't be used if there is a chance HTTP_HOST may be empty except for the port, e.g., `:80` will return `80` 509 535 // If strtok() matched a ':' in the previous line, the rest of the string contains the port number (or FALSE) 510 $safe_http_port = preg_replace('/[^0-9]/ ', '', strtok(''));536 $safe_http_port = preg_replace('/[^0-9]/u', '', strtok('')); 511 537 if ('' != $safe_http_host && '' == $this->getParam('site_hostname')) { 512 538 $this->setParam(array('site_hostname' => $safe_http_host)); … … 1153 1179 // Avoid indexed-array query params because in a URL array param keys should all match. 1154 1180 // I.e, we want to use `array[]=A&array[]=B` instead of `array[0]=A&array[1]=B`. 1155 $key = preg_replace('/\[\d+\]$/ ', '[]', $key);1181 $key = preg_replace('/\[\d+\]$/u', '[]', $key); 1156 1182 // Check value is set and value does not already exist in the url. 1157 1183 if (!preg_match('/[?&]' . preg_quote($key) . '=/', $url)) { … … 1222 1248 1223 1249 // Replace any & not followed by an html or unicode entity with its & equivalent. 1224 $url = preg_replace('/&(?![\w\d#]{1,10};)/ ', '&', $url);1250 $url = preg_replace('/&(?![\w\d#]{1,10};)/u', '&', $url); 1225 1251 1226 1252 return $url; … … 1538 1564 if ('' != $url && is_string($url)) { 1539 1565 // Delete any boomerang request keys in the query string (along with any trailing delimiters after the deletion). 1540 $url = preg_replace(array('/([&?])boomerang=[^&?]+[&?]?/ ', '/[&?]$/'), array('$1', ''), $url);1566 $url = preg_replace(array('/([&?])boomerang=[^&?]+[&?]?/u', '/[&?]$/'), array('$1', ''), $url); 1541 1567 1542 1568 if (isset($_SESSION['_app'][$this->_ns]['boomerang']) && is_array($_SESSION['_app'][$this->_ns]['boomerang']) && !empty($_SESSION['_app'][$this->_ns]['boomerang'])) {
Note: See TracChangeset
for help on using the changeset viewer.