Index: core/kernel/application.php =================================================================== --- core/kernel/application.php +++ core/kernel/application.php @@ -468,28 +468,14 @@ */ public 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', ''); - + /** @var LanguagesItem $lang */ $lang = $this->recallObject('lang.current'); - /* @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); } /** @@ -530,16 +516,8 @@ return $path; } - $theme_id = $this->GetVar('m_theme'); - if ( !$theme_id ) { - $theme_id = 'default'; // $this->GetDefaultThemeId(1); // 1 to force front-end mode! - } - - $this->SetVar('m_theme', $theme_id); - $this->SetVar('theme.current_id', $theme_id); // KOSTJA: this is to fool theme' getPassedID - + /** @var ThemeItem $theme */ $theme = $this->recallObject('theme.current'); - /* @var $theme ThemeItem */ if ( !$theme->isLoaded() || !$theme->GetDBField('Enabled') ) { return false; Index: core/units/languages/languages_event_handler.php =================================================================== --- core/units/languages/languages_event_handler.php +++ core/units/languages/languages_event_handler.php @@ -59,6 +59,23 @@ } /** + * Ensure, that current object is always taken from live table. + * + * @param kDBBase|kDBItem|kDBList $object Object. + * @param kEvent $event Event. + * + * @return void + */ + protected function dbBuild(&$object, kEvent $event) + { + if ( $event->Special == 'current' ) { + $event->setEventParam('live_table', true); + } + + parent::dbBuild($object, $event); + } + + /** * Allows to get primary language object * * @param kEvent $event @@ -69,6 +86,16 @@ { if ( $event->Special == 'primary' ) { return $this->Application->GetDefaultLanguageId(); + } + elseif ( $event->Special == 'current' ) { + $language_id = $this->Application->GetVar('m_lang'); + + if ( !$language_id ) { + $language_id = 'default'; + } + + $this->Application->SetVar('m_lang', $language_id); + $this->Application->SetVar($event->getPrefixSpecial() . '_id', $language_id); } return parent::getPassedID($event); Index: core/units/themes/themes_eh.php =================================================================== --- core/units/themes/themes_eh.php +++ core/units/themes/themes_eh.php @@ -53,6 +53,46 @@ } /** + * Ensure, that current object is always taken from live table. + * + * @param kDBBase|kDBItem|kDBList $object Object. + * @param kEvent $event Event. + * + * @return void + */ + protected function dbBuild(&$object, kEvent $event) + { + if ( $event->Special == 'current' ) { + $event->setEventParam('live_table', true); + } + + parent::dbBuild($object, $event); + } + + /** + * Ensures that current theme detection will fallback to primary without extra DB query. + * + * @param kEvent $event Event. + * + * @return integer + */ + public function getPassedID(kEvent $event) + { + if ( $event->Special == 'current' ) { + $theme_id = $this->Application->GetVar('m_theme'); + + if ( !$theme_id ) { + $theme_id = 'default'; + } + + $this->Application->SetVar('m_theme', $theme_id); + $this->Application->SetVar($event->getPrefixSpecial() . '_id', $theme_id); + } + + return parent::getPassedID($event); + } + + /** * Allows to set selected theme as primary * * @param kEvent $event