Changeset View
Changeset View
Standalone View
Standalone View
core/kernel/application.php
Show First 20 Lines • Show All 210 Lines • ▼ Show 20 Line(s) | |||||
* | * | ||||
* @var kDBItem | * @var kDBItem | ||||
* @access public | * @access public | ||||
* @todo move away into separate module | * @todo move away into separate module | ||||
*/ | */ | ||||
public $siteDomain = null; | public $siteDomain = null; | ||||
/** | /** | ||||
* Web Request, that is being processed currently. | |||||
* | |||||
* Will be null, when no request is being processed (e.g. application is used from CLI). | |||||
* | |||||
* @var \Symfony\Component\HttpFoundation\Request | |||||
*/ | |||||
public $request; | |||||
/** | |||||
* Prevent kApplication class to be created directly, only via Instance method | * Prevent kApplication class to be created directly, only via Instance method | ||||
* | * | ||||
* @access private | * @access private | ||||
*/ | */ | ||||
private function __construct() | private function __construct() | ||||
{ | { | ||||
} | } | ||||
Show All 24 Lines | |||||
* @return kApplication | * @return kApplication | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public static function &Instance() | public static function &Instance() | ||||
{ | { | ||||
static $instance = false; | static $instance = false; | ||||
if ( !$instance ) { | if ( !$instance ) { | ||||
$class = defined('APPLICATION_CLASS') ? APPLICATION_CLASS : 'kApplication'; | $class = APPLICATION_CLASS; | ||||
// Replacement application class won't work for CLI. | |||||
if ( PHP_SAPI === 'cli' ) { | |||||
kUtil::includeOnce(__DIR__ . '/console_application.php'); | |||||
$class = 'ConsoleApplication'; | |||||
} | |||||
$instance = new $class(); | $instance = new $class(); | ||||
} | } | ||||
return $instance; | return $instance; | ||||
} | } | ||||
/** | /** | ||||
* Initializes the Application | * Initializes the Application | ||||
* | * | ||||
* @param string $factory_class | * @param string $factory_class | ||||
* @return bool Was Init actually made now or before | * @return bool Was Init actually made now or before | ||||
* @access public | * @access public | ||||
* @see kHTTPQuery | * @see kHTTPQuery | ||||
* @see Session | * @see Session | ||||
* @see TemplatesCache | * @see TemplatesCache | ||||
*/ | */ | ||||
public function Init($factory_class = 'kFactory') | public function Init($factory_class = 'kFactory') | ||||
{ | { | ||||
if ( $this->InitDone ) { | if ( $this->InitDone ) { | ||||
return false; | return false; | ||||
} | } | ||||
// FIXME: Assign Symfony Request object provided from outside. | |||||
if ( PHP_SAPI !== 'cli' ) { | |||||
$this->request = true; | |||||
} | |||||
if ( preg_match('/utf-8/i', CHARSET) ) { | if ( preg_match('/utf-8/i', CHARSET) ) { | ||||
setlocale(LC_ALL, 'en_US.UTF-8'); | setlocale(LC_ALL, 'en_US.UTF-8'); | ||||
mb_internal_encoding('UTF-8'); | mb_internal_encoding('UTF-8'); | ||||
} | } | ||||
$this->isAdmin = kUtil::constOn('ADMIN'); | $this->isAdmin = kUtil::constOn('ADMIN'); | ||||
if ( !kUtil::constOn('SKIP_OUT_COMPRESSION') ) { | if ( !kUtil::constOn('SKIP_OUT_COMPRESSION') ) { | ||||
Show All 28 Lines | |||||
$this->registerModuleConstants(); | $this->registerModuleConstants(); | ||||
if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | ||||
$this->Debugger->appendTimestamp('After UnitConfigReader'); | $this->Debugger->appendTimestamp('After UnitConfigReader'); | ||||
} | } | ||||
define('MOD_REWRITE', $this->ConfigValue('UseModRewrite') && !$this->isAdmin ? 1 : 0); | define('MOD_REWRITE', $this->ConfigValue('UseModRewrite') && !$this->isAdmin ? 1 : 0); | ||||
// start processing request | $this->initBeforeOnAfterConfigRead(); | ||||
$site_timezone = $this->ConfigValue('Config_Site_Time'); | |||||
if ( $site_timezone ) { | |||||
date_default_timezone_set($site_timezone); | |||||
} | |||||
// Must be called before AfterConfigRead, because current user should be available there. | |||||
$this->ValidateLogin(); | |||||
$this->UnitConfigReader->AfterConfigRead(); | |||||
if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | |||||
$this->Debugger->appendTimestamp('Processed AfterConfigRead'); | |||||
} | |||||
$this->initAfterOnAfterConfigRead(); | |||||
if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | |||||
$this->Debugger->profileFinish('kernel4_startup'); | |||||
} | |||||
$this->InitDone = true; | |||||
if ( PHP_SAPI !== 'cli' && !$this->isAdmin ) { | |||||
$this->HandleEvent(new kEvent('adm:OnStartup')); | |||||
} | |||||
return true; | |||||
} | |||||
/** | |||||
* Handles initialization part before "OnAfterConfigRead" events are called. | |||||
* | |||||
* @return void | |||||
*/ | |||||
protected function initBeforeOnAfterConfigRead() | |||||
{ | |||||
// Start processing request. | |||||
$this->HttpQuery = $this->recallObject('kHTTPQuery'); | $this->HttpQuery = $this->recallObject('kHTTPQuery'); | ||||
$this->HttpQuery->process(); | $this->HttpQuery->process(); | ||||
if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | ||||
$this->Debugger->appendTimestamp('Processed HTTPQuery initial'); | $this->Debugger->appendTimestamp('Processed HTTPQuery initial'); | ||||
} | } | ||||
$this->Session = $this->recallObject('Session'); | $this->Session = $this->recallObject('Session'); | ||||
if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | ||||
$this->Debugger->appendTimestamp('Processed Session'); | $this->Debugger->appendTimestamp('Processed Session'); | ||||
} | } | ||||
$this->Session->ValidateExpired(); // needs mod_rewrite url already parsed to keep user at proper template after session expiration | $this->Session->ValidateExpired(); // needs mod_rewrite url already parsed to keep user at proper template after session expiration | ||||
if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | ||||
$this->Debugger->appendTimestamp('Processed HTTPQuery AfterInit'); | $this->Debugger->appendTimestamp('Processed HTTPQuery AfterInit'); | ||||
} | } | ||||
$this->cacheManager->LoadApplicationCache(); | $this->cacheManager->LoadApplicationCache(); | ||||
$site_timezone = $this->ConfigValue('Config_Site_Time'); | |||||
if ( $site_timezone ) { | |||||
date_default_timezone_set($site_timezone); | |||||
} | |||||
if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | ||||
$this->Debugger->appendTimestamp('Loaded cache and phrases'); | $this->Debugger->appendTimestamp('Loaded cache and phrases'); | ||||
} | } | ||||
$this->ValidateLogin(); // must be called before AfterConfigRead, because current user should be available there | |||||
$this->UnitConfigReader->AfterConfigRead(); | |||||
if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | |||||
$this->Debugger->appendTimestamp('Processed AfterConfigRead'); | |||||
} | } | ||||
/** | |||||
* Handles initialization part after "OnAfterConfigRead" events are called. | |||||
* | |||||
* @return void | |||||
*/ | |||||
protected function initAfterOnAfterConfigRead() | |||||
{ | |||||
if ( $this->GetVar('m_cat_id') === false ) { | if ( $this->GetVar('m_cat_id') === false ) { | ||||
$this->SetVar('m_cat_id', 0); | $this->SetVar('m_cat_id', 0); | ||||
} | } | ||||
if ( !$this->RecallVar('curr_iso') && !(defined('IS_INSTALL') && IS_INSTALL) ) { | if ( !$this->RecallVar('curr_iso') && !(defined('IS_INSTALL') && IS_INSTALL) ) { | ||||
$this->StoreVar('curr_iso', $this->GetPrimaryCurrency(), true); // true for optional | $this->StoreVar('curr_iso', $this->GetPrimaryCurrency(), true); // true for optional | ||||
} | } | ||||
$visit_id = $this->RecallVar('visit_id'); | $visit_id = $this->RecallVar('visit_id'); | ||||
if ( $visit_id !== false ) { | if ( $visit_id !== false ) { | ||||
$this->SetVar('visits_id', $visit_id); | $this->SetVar('visits_id', $visit_id); | ||||
} | } | ||||
if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { | |||||
$this->Debugger->profileFinish('kernel4_startup'); | |||||
} | |||||
$this->InitDone = true; | |||||
if ( PHP_SAPI !== 'cli' && !$this->isAdmin ) { | |||||
$this->HandleEvent(new kEvent('adm:OnStartup')); | |||||
} | } | ||||
return true; | /** | ||||
* Detects if this is a web request. | |||||
* | |||||
* @return boolean | |||||
*/ | |||||
public function isWebRequest() | |||||
{ | |||||
return isset($this->request); | |||||
} | } | ||||
/** | /** | ||||
* Performs initialization of manager classes, that can be overridden from unit configs | * Performs initialization of manager classes, that can be overridden from unit configs | ||||
* | * | ||||
* @return void | * @return void | ||||
* @access public | * @access public | ||||
* @throws Exception | * @throws Exception | ||||
▲ Show 20 Lines • Show All 2068 Lines • ▼ Show 20 Line(s) | |||||
// stop searching, when parent prefix is not registered | // stop searching, when parent prefix is not registered | ||||
break; | break; | ||||
} | } | ||||
$current_prefix = $parent_prefix; | $current_prefix = $parent_prefix; | ||||
array_unshift($prefixes, $current_prefix); | array_unshift($prefixes, $current_prefix); | ||||
} | } | ||||
if ( $real_top ) { | if ( $real_top || !$this->isWebRequest() ) { | ||||
return $current_prefix; | return $current_prefix; | ||||
} | } | ||||
// 2. find what if parent is passed | // 2. find what if parent is passed | ||||
$passed = explode(',', $this->GetVar('all_passed')); | $passed = explode(',', $this->GetVar('all_passed')); | ||||
foreach ($prefixes as $a_prefix) { | foreach ($prefixes as $a_prefix) { | ||||
if ( in_array($a_prefix, $passed) ) { | if ( in_array($a_prefix, $passed) ) { | ||||
return $a_prefix; | return $a_prefix; | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
*/ | */ | ||||
public function LoggedIn() | public function LoggedIn() | ||||
{ | { | ||||
// no session during expiration process | // no session during expiration process | ||||
return is_null($this->Session) ? false : $this->Session->LoggedIn(); | return is_null($this->Session) ? false : $this->Session->LoggedIn(); | ||||
} | } | ||||
/** | /** | ||||
* Determines if access permissions should not be checked. | |||||
* | |||||
* @param integer|null $user_id User ID. | |||||
* | |||||
* @return boolean | |||||
*/ | |||||
public function permissionCheckingDisabled($user_id = null) | |||||
{ | |||||
if ( !isset($user_id) ) { | |||||
$user_id = $this->RecallVar('user_id'); | |||||
} | |||||
return $user_id == USER_ROOT; | |||||
} | |||||
/** | |||||
* Check current user permissions based on it's group permissions in specified category | * Check current user permissions based on it's group permissions in specified category | ||||
* | * | ||||
* @param string $name permission name | * @param string $name permission name | ||||
* @param int $cat_id category id, current used if not specified | * @param int $cat_id category id, current used if not specified | ||||
* @param int $type permission type {1 - system, 0 - per category} | * @param int $type permission type {1 - system, 0 - per category} | ||||
* @return int | * @return int | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 529 Lines • Show Last 20 Lines |