Index: trunk/core/kernel/application.php =================================================================== diff -u -r3154 -r3162 --- trunk/core/kernel/application.php (.../application.php) (revision 3154) +++ trunk/core/kernel/application.php (.../application.php) (revision 3162) @@ -70,6 +70,13 @@ var $Phrases; /** + * Modules table content, key - module name + * + * @var Array + */ + var $ModuleInfo = Array(); + + /** * Holds DBConnection * * @var kDBConnection @@ -129,7 +136,7 @@ function Init() { if($this->InitDone) return false; - + if( $this->isDebugMode() && dbg_ConstOn('DBG_PROFILE_MEMORY') ) { $GLOBALS['debugger']->appendMemoryUsage('Application before Init:'); @@ -144,11 +151,17 @@ $error_handler = set_error_handler( Array(&$this,'handleError') ); if($error_handler) $this->errorHandlers[] = $error_handler; - $this->DB = new kDBConnection(SQL_TYPE, Array(&$this,'handleSQLError') ); $this->DB->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB); $this->DB->debugMode = $this->isDebugMode(); + $this->ModuleInfo = $this->DB->Query('SELECT * FROM '.TABLE_PREFIX.'Modules ORDER BY LoadOrder', 'Name'); + + $cms_on = defined('CMS') && CMS; + $rewrite_on = $this->ConfigValue('UseModRewrite'); + $admin_on = getArrayValue($_REQUEST, 'admin') || $this->IsAdmin(); + define('MOD_REWRITE', ($rewrite_on || $cms_on) && !$admin_on ? 1 : 0); + $this->Factory = new kFactory(); $this->registerDefaultClasses(); @@ -157,18 +170,22 @@ // 1. to read configs before doing any recallObject (called from "SetDefaultConstants" anyway) $config_reader =& $this->recallObject('kUnitConfigReader'); - $this->VerifyLanguageId(); - $this->VerifyThemeId(); - - if( $this->GetVar('m_cat_id') === false ) $this->SetVar('m_cat_id', 0); - - $this->Phrases = new PhrasesCache( $this->GetVar('m_lang') ); - + // Module items are recalled during url parsing & PhrasesCache is needed already there, + // because it's used in their build events. That's why phrases cache initialization is + // called from httpquery in case when mod_rewrite is used + if( !$this->RewriteURLs() ) + { + $this->Phrases = new PhrasesCache(); + $this->VerifyLanguageId(); + $this->Phrases->Init('phrases'); + $this->VerifyThemeId(); + } + $this->SetVar('lang.current_id', $this->GetVar('m_lang') ); - $language =& $this->recallObject('lang.current', null, Array('live_table'=>true) ); - - if( !$this->GetVar('m_theme') ) $this->SetVar('m_theme', $this->GetDefaultThemeId() ); $this->SetVar('theme.current_id', $this->GetVar('m_theme') ); + if( $this->GetVar('m_cat_id') === false ) $this->SetVar('m_cat_id', 0); + + $language =& $this->recallObject( 'lang.current', null, Array('live_table' => true) ); if( !$this->RecallVar('UserGroups') ) { @@ -189,11 +206,6 @@ $GLOBALS['debugger']->profileFinish('kernel4_startup'); } - $cms_on = defined('CMS') && CMS; - $rewrite_on = $this->ConfigValue('UseModRewrite'); - $admin_on = $this->GetVar('admin') || $this->IsAdmin(); - define('MOD_REWRITE', ($rewrite_on || $cms_on) && !$admin_on ? 1 : 0); - $this->InitDone = true; return true; } @@ -207,15 +219,16 @@ $language_id = $this->GetVar('m_lang'); if($language_id) { - $table = $this->getUnitOption('lang','TableName'); - $id_field = $this->getUnitOption('lang','IDField'); + $table = $this->getUnitOption('lang', 'TableName'); + $id_field = $this->getUnitOption('lang', 'IDField'); $language_ids = $this->DB->GetCol('SELECT '.$id_field.' FROM '.$table); } - if(!$language_id || !in_array($language_id, $language_ids) ) { + if ( !$language_id || !in_array($language_id, $language_ids) ) + { $def_lang = $this->GetDefaultLanguageId(); - $this->SetVar('m_lang', $def_lang ); - $this->StoreVar('m_lang', $def_lang ); + $this->SetVar('m_lang', $def_lang); + $this->StoreVar('m_lang', $def_lang); } } @@ -228,14 +241,17 @@ $theme_id = $this->GetVar('m_theme'); if($theme_id) { - $table = $this->getUnitOption('theme','TableName'); - $id_field = $this->getUnitOption('theme','IDField'); + $table = $this->getUnitOption('theme', 'TableName'); + $id_field = $this->getUnitOption('theme', 'IDField'); $theme_ids = $this->DB->GetCol('SELECT '.$id_field.' FROM '.$table); } - if(!$theme_id || !in_array($theme_id, $theme_ids) ) $this->SetVar('m_theme', $this->GetDefaultThemeId() ); + if ( !$theme_id || !in_array($theme_id, $theme_ids) ) + { + $this->SetVar('m_theme', $this->GetDefaultThemeId() ); + } } - + function GetDefaultLanguageId() { static $language_id = 0; @@ -716,7 +732,9 @@ { if(!$t) $t = $this->GetVar('t'); // moved from MainProcessor->T() - if ( $this->IsAdmin() && $prefix == '') $prefix='/admin'; + if( substr($t, -4) == '.tpl' ) $t = substr($t, 0, strlen($t) - 4 ); + + if ( $this->IsAdmin() && $prefix == '') $prefix = '/admin'; if ( $this->IsAdmin() && $prefix == '_FRONT_END_') $prefix = ''; $index_file = isset($index_file) ? $index_file : (defined('INDEX_FILE') ? INDEX_FILE : basename($_SERVER['SCRIPT_NAME'])); @@ -819,7 +837,7 @@ $event_params['url_params'] = $params; $event = new kEvent($pass_element.':BuildEnv', $event_params); $this->HandleEvent($event); - $ret .= '/'.$event->getEventParam('env_string'); + $ret .= '/'.trim( $event->getEventParam('env_string'), '/'); $params = $event->getEventParam('url_params'); // save back unprocessed parameters } $ret = trim($ret, '/').'.html'; @@ -1014,6 +1032,12 @@ function ReplaceLanguageTags($text, $force_escape=null) { // !!!!!!!! + if( !is_object($this->Phrases) ) + { + print_r( debug_backtrace() ); +// $this->Debugger->appendTrace(); + } + return $this->Phrases->ReplaceLanguageTags($text,$force_escape); }