Changeset 581 for trunk/lib/App.inc.php
- Timestamp:
- Feb 27, 2017 2:27:40 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/App.inc.php
r563 r581 57 57 public $db; 58 58 59 // Instance of database session handler object. 60 public $db_session; 61 59 62 // Array of query arguments will be carried persistently between requests. 60 63 protected $_carry_queries = array(); … … 63 66 protected $_raised_msg_counter = array(MSG_NOTICE => 0, MSG_SUCCESS => 0, MSG_WARNING => 0, MSG_ERR => 0); 64 67 65 // We're running as CLI. Public bec uase we must force this as false when testing sessions via CLI.68 // We're running as CLI. Public because we must force this as false when testing sessions via CLI. 66 69 public $cli = false; 67 70 … … 201 204 public function __construct($namespace='') 202 205 { 203 // Set namespace of application instance.204 $this->_ns = $namespace;205 206 206 // Initialize default parameters. 207 207 $this->_params = array_merge($this->_params, $this->_param_defaults); … … 227 227 { 228 228 if (self::$instance === null) { 229 // TODO: Yep, having a namespace with one singletone instance is not very useful. 229 // FIXME: Yep, having a namespace with one singleton instance is not very useful. This is a design flaw with the Codebase. 230 // We're currently getting instances of App throughout the codebase using `$app =& App::getInstance();` 231 // with no way to determine what the namespace of the containing application is (e.g., `public` vs. `admin`). 232 // Option 1: provide the project namespace to all classes that use App, and then instantiate with `$app =& App::getInstance($this->_ns);`. 233 // In this case the namespace of the App and the namespace of the auxiliary class must match. 234 // Option 2: may be to clone a specific instance to the "default" instance, so, e.g., `$app =& App::getInstance();` 235 // refers to the same namespace as `$app =& App::getInstance('admin');` 236 // Option 3: is to check if there is only one instance, and return it if an unspecified namespace is requested. 237 // However, in the case when multiple namespaces are in play at the same time, this will fail; unspecified namespaces 238 // would cause the creation of an additional instance, since there would not be an obvious named instance to return. 230 239 self::$instance = new self($namespace); 240 } 241 242 if ('' != $namespace) { 243 // We may not be able to request a specific instance, but we can specify a specific namespace. 244 // We're ignoring all instance requests with a blank namespace, so we use the last given one. 245 self::$instance->_ns = $namespace; 231 246 } 232 247 … … 322 337 // Set character set to use for multi-byte string functions. 323 338 mb_internal_encoding($this->getParam('character_set')); 339 ini_set('default_charset', $this->getParam('character_set')); 324 340 switch (mb_strtolower($this->getParam('character_set'))) { 325 341 case 'utf-8' : … … 410 426 // Database session handling. 411 427 require_once dirname(__FILE__) . '/DBSessionHandler.inc.php'; 412 $ db_save_handler= new DBSessionHandler($this->db, array(428 $this->db_session = new DBSessionHandler($this->db, array( 413 429 'db_table' => 'session_tbl', 414 430 'create_table' => $this->getParam('db_create_tables'), … … 424 440 $_SESSION['_app'][$this->_ns] = array( 425 441 'messages' => array(), 426 'boomerang' => array( 'url' => array()),442 'boomerang' => array(), 427 443 ); 428 444 } … … 460 476 if (!$this->cli) { 461 477 if (!headers_sent($h_file, $h_line)) { 462 header( 'Content-type: text/html; charset=' . $this->getParam('character_set'));478 header(sprintf('Content-type: text/html; charset=%s', $this->getParam('character_set'))); 463 479 } else { 464 480 $this->logMsg(sprintf('Unable to set Content-type; headers already sent (output started in %s : %s)', $h_file, $h_line), LOG_DEBUG, __FILE__, __LINE__); … … 472 488 $codebase_version = trim(file_get_contents($codebase_version_file)); 473 489 $this->setParam(array('codebase_version' => $codebase_version)); 474 if (!$this->cli ) {490 if (!$this->cli && $this->getParam('codebase_version')) { 475 491 if (!headers_sent($h_file, $h_line)) { 476 header( 'X-Codebase-Version: ' . $codebase_version);492 header(sprintf('X-Codebase-Version: %s', $this->getParam('codebase_version'))); 477 493 } else { 478 494 $this->logMsg(sprintf('Unable to set X-Codebase-Version; headers already sent (output started in %s : %s)', $h_file, $h_line), LOG_DEBUG, __FILE__, __LINE__); … … 489 505 if (mb_strpos($site_version_file, '.json') !== false) { 490 506 $version_json = json_decode(trim(file_get_contents($site_version_file)), true); 491 $site_version = $version_json['version'];507 $site_version = isset($version_json['version']) ? $version_json['version'] : null; 492 508 } else { 493 509 $site_version = trim(file_get_contents($site_version_file)); … … 497 513 if (!$this->cli && $this->getParam('site_version')) { 498 514 if (!headers_sent($h_file, $h_line)) { 499 header( 'X-Site-Version: ' . $site_version);515 header(sprintf('X-Site-Version: %s', $this->getParam('site_version'))); 500 516 } else { 501 517 $this->logMsg(sprintf('Unable to set X-Site-Version; headers already sent (output started in %s : %s)', $h_file, $h_line), LOG_DEBUG, __FILE__, __LINE__); 502 518 } 503 519 } 520 521 // Unset environment variables we're done with. 522 unset($_SERVER['DB_SERVER'], $_SERVER['DB_NAME'], $_SERVER['DB_USER'], $_SERVER['DB_PASS'], $_SERVER['SIGNING_KEY']); 504 523 505 524 $this->running = true; … … 1393 1412 return false; 1394 1413 } 1395 // A redirection will never happen immediately after setting the boomerangURL.1396 // Set the time so ensure this doesn't happen. See $app->validBoomerangURL for more.1397 1414 1398 1415 if ('' != $url && is_string($url)) { … … 1401 1418 1402 1419 if (isset($_SESSION['_app'][$this->_ns]['boomerang']) && is_array($_SESSION['_app'][$this->_ns]['boomerang']) && !empty($_SESSION['_app'][$this->_ns]['boomerang'])) { 1403 // If the ID =>URL pair currently exists in the boomerang array, delete.1420 // If the ID already exists in the boomerang array, delete it. 1404 1421 foreach (array_keys($_SESSION['_app'][$this->_ns]['boomerang']) as $existing_id) { 1422 // $existing_id could be null if existing boomerang URL was set without an ID. 1405 1423 if ($existing_id === $id) { 1406 $this->logMsg(sprintf(' Found and deleting existing ID=>URL pair: %s=>%s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);1424 $this->logMsg(sprintf('Deleted existing boomerang URL matching ID: %s=>%s', $id, $url), LOG_DEBUG, __FILE__, __LINE__); 1407 1425 unset($_SESSION['_app'][$this->_ns]['boomerang'][$existing_id]); 1408 1426 } … … 1410 1428 } 1411 1429 1430 // A redirection will never happen immediately after setting the boomerang URL. 1431 // Set the time so ensure this doesn't happen. See $app->validBoomerangURL for more. 1412 1432 if (isset($id)) { 1413 1433 $_SESSION['_app'][$this->_ns]['boomerang'][$id] = array( … … 1448 1468 return ''; 1449 1469 } 1450 } else if (is _array($_SESSION['_app'][$this->_ns]['boomerang']) && !empty($_SESSION['_app'][$this->_ns]['boomerang'])) {1470 } else if (isset($_SESSION['_app'][$this->_ns]['boomerang']) && is_array($_SESSION['_app'][$this->_ns]['boomerang']) && !empty($_SESSION['_app'][$this->_ns]['boomerang'])) { 1451 1471 return end($_SESSION['_app'][$this->_ns]['boomerang'])['url']; 1452 1472 } else { … … 1556 1576 1557 1577 /** 1558 * to enforce the user to connect via http (port 80) by redirecting them to 1559 * a http version of the current url. 1578 * This function has changed to do nothing. There is no reason to prefer a non-SSL connection, and doing so may result in a redirect loop. 1560 1579 */ 1561 1580 public function sslOff() 1562 1581 { 1563 if ('' != getenv('HTTPS')) { 1564 $this->dieURL('http://' . getenv('HTTP_HOST') . getenv('REQUEST_URI'), null, true); 1565 } 1582 $app =& App::getInstance(); 1583 $app->logMsg(sprintf('sslOff was called and ignored.', null), LOG_INFO, __FILE__, __LINE__); 1566 1584 } 1567 1585
Note: See TracChangeset
for help on using the changeset viewer.