Index: branches/5.0.x/core/kernel/application.php =================================================================== diff -u -r12511 -r12726 --- branches/5.0.x/core/kernel/application.php (.../application.php) (revision 12511) +++ branches/5.0.x/core/kernel/application.php (.../application.php) (revision 12726) @@ -1,6 +1,6 @@ InitDone) return false; + if($this->InitDone) { + return false; + } + $this->isAdmin = constOn('ADMIN'); + $this->InitMemcached(); if (!constOn('SKIP_OUT_COMPRESSION')) { @@ -326,7 +346,7 @@ $rewrite_on = $this->ConfigValue('UseModRewrite'); // admin=1 - when front is browsed using admin session - $admin_on = getArrayValue($_REQUEST, 'admin') || $this->IsAdmin(); + $admin_on = getArrayValue($_REQUEST, 'admin') || $this->isAdmin; define('MOD_REWRITE', $rewrite_on && !$admin_on ? 1 : 0); $this->HttpQuery =& $this->recallObject('HTTPQuery'); @@ -465,18 +485,26 @@ function VerifyLanguageId() { $language_id = $this->GetVar('m_lang'); + if (!$language_id) { $language_id = 'default'; } + $this->SetVar('lang.current_id', $language_id ); $this->SetVar('m_lang', $language_id ); $lang_mode = $this->GetVar('lang_mode'); $this->SetVar('lang_mode', ''); + $lang =& $this->recallObject('lang.current'); - if ( !$lang->IsLoaded() || (!$this->Application->IsAdmin() && !$lang->GetDBField('Enabled')) ) { - if (!defined('IS_INSTALL')) $this->ApplicationDie('Unknown or disabled language'); + /* @var $lang kDBItem */ + + if (!$lang->isLoaded() || (!$this->isAdmin && !$lang->GetDBField('Enabled'))) { + if (!defined('IS_INSTALL')) { + $this->ApplicationDie('Unknown or disabled language'); + } } + $this->SetVar('lang_mode',$lang_mode); } @@ -486,7 +514,7 @@ */ function VerifyThemeId() { - if ($this->Application->IsAdmin()) { + if ($this->isAdmin) { safeDefine('THEMES_PATH', '/core/admin_templates'); return; } @@ -567,7 +595,7 @@ if (constOn('DBG_FORCE_THEME')) { $theme_id = DBG_FORCE_THEME; } - elseif (!$force_front && $this->IsAdmin()) { + elseif (!$force_front && $this->isAdmin) { $theme_id = 999; } else { @@ -804,7 +832,7 @@ $this->Debugger->appendMemoryUsage('Application before Run:'); } - if ($this->IsAdmin()) { + if ($this->isAdminUser) { // for permission checking in events & templates $this->LinkVar('module'); // for common configuration templates $this->LinkVar('module_key'); // for common search templates @@ -813,8 +841,6 @@ if ($this->GetVar('m_opener') == 'p') { $this->LinkVar('main_prefix'); // window prefix, that opened selector $this->LinkVar('dst_field'); // field to set value choosed in selector -// $this->LinkVar('return_template'); // template to go, when something was coosen from popup (from finalizePopup) -// $this->LinkVar('return_m'); // main env part to restore after popup will be closed (from finalizePopup) } if ($this->GetVar('ajax') == 'yes' && !$this->GetVar('debug_ajax')) { @@ -844,7 +870,7 @@ $this->InitParser(); $t = $this->GetVar('t'); - if (!$this->TemplatesCache->TemplateExists($t) && !$this->IsAdmin()) { + if (!$this->TemplatesCache->TemplateExists($t) && !$this->isAdmin) { $cms_handler =& $this->recallObject('st_EventHandler'); /* @var $cms_handler CategoriesEventHandler */ @@ -927,7 +953,7 @@ $this->Session->SaveData(); } - if (defined('DBG_CAPTURE_STATISTICS') && DBG_CAPTURE_STATISTICS && !$this->IsAdmin()) { + if (defined('DBG_CAPTURE_STATISTICS') && DBG_CAPTURE_STATISTICS && !$this->isAdmin) { $this->_storeStatistics(); } } @@ -1310,26 +1336,19 @@ */ function HREF($t, $prefix='', $params=null, $index_file=null) { - if(!$t) $t = $this->GetVar('t'); // moved from kMainTagProcessor->T() + if (!$t) { + $t = $this->GetVar('t'); // moved from kMainTagProcessor->T() + } $t = preg_replace('/^Content\//i', '', $t); - - /*if ($this->GetVar('skip_last_template')) { - $params['opener'] = 'p'; - $this->SetVar('m_opener', 'p'); + if (substr($t, -4) == '.tpl') { + $t = substr($t, 0, strlen($t) - 4); } - if ($t == 'incs/close_popup') { - // because this template closes the popup and we don't need popup mark here anymore - $params['m_opener'] = 's'; - }*/ + if ($this->isAdmin && $prefix == '') $prefix = ADMIN_DIRECTORY; + if ($this->isAdmin && $prefix == '_FRONT_END_') $prefix = ''; - if( substr($t, -4) == '.tpl' ) $t = substr($t, 0, strlen($t) - 4 ); - - if ( $this->IsAdmin() && $prefix == '') $prefix = ADMIN_DIRECTORY; - if ( $this->IsAdmin() && $prefix == '_FRONT_END_') $prefix = ''; - $index_file = $this->getIndexFile($prefix, $index_file, $params); if (isset($params['_auto_prefix_'])) { @@ -1952,16 +1971,23 @@ { $session =& $this->recallObject('Session'); $user_id = $session->GetField('PortalUserId'); - if (!$user_id && $user_id != -1) $user_id = -2; + + if (!$user_id && $user_id != -1) { + $user_id = -2; + + } + $this->SetVar('u.current_id', $user_id); - if (!$this->IsAdmin()) { + if (!$this->isAdmin) { // needed for "profile edit", "registration" forms ON FRONT ONLY $this->SetVar('u_id', $user_id); } $this->StoreVar('user_id', $user_id, $user_id == -2); // storing Guest user_id (-2) is optional + $this->isAdminUser = $this->isAdmin && $this->LoggedIn(); + if ($this->GetVar('expired') == 1) { // this parameter is set only from admin $user =& $this->recallObject('u.current'); @@ -1989,7 +2015,7 @@ } function LoadCache() { - $cache_key = $this->GetVar('t').$this->GetVar('m_theme').$this->GetVar('m_lang').$this->IsAdmin(); + $cache_key = $this->GetVar('t').$this->GetVar('m_theme').$this->GetVar('m_lang').$this->isAdmin; $query = sprintf("SELECT PhraseList, ConfigVariables FROM %s WHERE Template = %s", TABLE_PREFIX.'PhraseCache', $this->Conn->qstr(md5($cache_key))); @@ -2017,7 +2043,7 @@ $update = $update || $this->Phrases->NeedsCacheUpdate(); $update = $update || (count($this->ConfigCacheIds) && $this->ConfigCacheIds != $this->Caches['ConfigVariables']); if ($update) { - $cache_key = $this->GetVar('t').$this->GetVar('m_theme').$this->GetVar('m_lang').$this->IsAdmin(); + $cache_key = $this->GetVar('t').$this->GetVar('m_theme').$this->GetVar('m_lang').$this->isAdmin; $query = sprintf("REPLACE %s (PhraseList, CacheDate, Template, ConfigVariables) VALUES (%s, %s, %s, %s)", TABLE_PREFIX.'PhraseCache', @@ -2263,17 +2289,6 @@ } /** - * Checks if it is admin - * - * @return bool - * @author Alex - */ - function IsAdmin() - { - return constOn('ADMIN'); - } - - /** * Apply url rewriting used by mod_rewrite or not * * @param bool $ssl Force ssl link to be build @@ -2628,7 +2643,7 @@ */ function setVisitField($field, $value) { - if ($this->IsAdmin() || !$this->ConfigValue('UseVisitorTracking')) { + if ($this->isAdmin || !$this->ConfigValue('UseVisitorTracking')) { // admin logins are not registred in visits list return ; }