Index: branches/unlabeled/unlabeled-1.62.2/core/kernel/db/db_tag_processor.php =================================================================== diff -u -r5718 -r5724 --- branches/unlabeled/unlabeled-1.62.2/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 5718) +++ branches/unlabeled/unlabeled-1.62.2/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 5724) @@ -90,7 +90,7 @@ $filters = Array(); $prefix_special = $this->getPrefixSpecial(); - + foreach ($filter_menu['Filters'] as $filter_key => $filter_params) { $group_params = isset($filter_params['group_id']) ? $filter_menu['Groups'][ $filter_params['group_id'] ] : Array(); if (!isset($group_params['element_type'])) { @@ -115,8 +115,8 @@ $block_params['filter_status'] = $status; // 1 - checkbox, 2 - radio, 0 - no image $filters[] = $this->Application->ParseBlock($block_params); } - - + + return implode('', $filters); } @@ -328,11 +328,19 @@ $backup_id=$this->Application->GetVar($this->Prefix."_id"); $displayed = array(); $column_number = 1; + + $cache_mod_rw = $this->Application->getUnitOption($this->Prefix, 'CacheModRewrite') && $this->Application->RewriteURLs(); + while (!$list->EOL()) { $this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField($id_field) ); // for edit/delete links using GET $this->Application->SetVar( $this->Prefix.'_id', $list->GetDBField($id_field) ); + if ($cache_mod_rw) { + $this->Application->setCache('filenames', $this->Prefix.'_'.$list->GetDBField($id_field), $list->GetDBField('Filename')); + $this->Application->setCache('filenames', 'c_'.$list->GetDBField('CategoryId'), $list->GetDBField('CategoryFilename')); + } + if ($i % $columns == 0) { // record in this iteration is first in row, then open row $column_number = 1; Index: branches/unlabeled/unlabeled-1.155.2/core/kernel/application.php =================================================================== diff -u -r5718 -r5724 --- branches/unlabeled/unlabeled-1.155.2/core/kernel/application.php (.../application.php) (revision 5718) +++ branches/unlabeled/unlabeled-1.155.2/core/kernel/application.php (.../application.php) (revision 5724) @@ -323,15 +323,7 @@ { $language_id = $this->GetVar('m_lang'); if (!$language_id) { - $language_id = $this->GetDefaultLanguageId(); - if (!$language_id) { - if (!$this->Application->IsAdmin()) { - $this->ApplicationDie('No Primary Language Selected'); - } - else { - $language_id = 1; - } - } + $language_id = 'default'; } $this->SetVar('lang.current_id', $language_id ); $this->SetVar('m_lang', $language_id ); @@ -520,6 +512,8 @@ $this->setCache('item_templates', $id, $category_data['CachedItemTemplate']); } else { + + $resource_id = $this->Conn->GetOne('SELECT ResourceId FROM '.$table.' WHERE '.$id_field.' = '.$this->Conn->qstr($id)); if (is_null($category_id)) $category_id = $this->GetVar('m_cat_id'); $sql = 'SELECT Filename FROM '.TABLE_PREFIX.'CategoryItems WHERE ItemResourceId = '.$resource_id.' AND CategoryId = '.$category_id; @@ -1409,7 +1403,7 @@ $buffer_content = ob_get_clean(); echo $this->UseOutputCompression() ? gzencode($buffer_content, DBG_COMPRESSION_LEVEL) : $buffer_content; - + $session =& $this->recallObject('Session'); $session->SaveData(); $this->SaveBlocksCache(); Index: branches/unlabeled/unlabeled-1.5.2/core/units/languages/languages_item.php =================================================================== diff -u -r5154 -r5724 --- branches/unlabeled/unlabeled-1.5.2/core/units/languages/languages_item.php (.../languages_item.php) (revision 5154) +++ branches/unlabeled/unlabeled-1.5.2/core/units/languages/languages_item.php (.../languages_item.php) (revision 5724) @@ -1,27 +1,27 @@ IDField.') FROM '.$this->Application->GetLiveName($this->TableName); return $this->Conn->GetOne($sql) + 1; } - + function setPrimary($reset_primary = true) { if ($reset_primary) { $sql = 'UPDATE '.$this->TableName.' SET PrimaryLang = 0'; $this->Conn->Query($sql); } - + $sql = 'UPDATE '.$this->TableName.' SET PrimaryLang = 1, Enabled = 1 WHERE '.$this->IDField.' = '.$this->GetID(); - $this->Conn->Query($sql); + $this->Conn->Query($sql); } - + /** * Allows to format number according to regional settings * @@ -33,6 +33,32 @@ { return number_format($number, $precision, $this->GetDBField('DecimalPoint'), $this->GetDBField('ThousandSep')); } + + function Load($id, $id_field_name=null) + { + $default = false; + if ($id == 'default') { + $id = 1; + $id_field_name = 'PrimaryLang'; + $default = true; + } + + $res = parent::Load($id, $id_field_name); + + if ($default) { + if (!$res) { + if ($this->Application->IsAdmin()) { + $res = parent::Load(1); + } + else { + $this->Application->ApplicationDie('No Primary Language Selected'); + } + } + $this->Application->SetVar('lang.current_id', $this->GetID() ); + $this->Application->SetVar('m_lang', $this->GetID() ); + } + return $res; + } } ?> \ No newline at end of file Index: branches/unlabeled/unlabeled-1.5.2/kernel/units/languages/languages_item.php =================================================================== diff -u -r5154 -r5724 --- branches/unlabeled/unlabeled-1.5.2/kernel/units/languages/languages_item.php (.../languages_item.php) (revision 5154) +++ branches/unlabeled/unlabeled-1.5.2/kernel/units/languages/languages_item.php (.../languages_item.php) (revision 5724) @@ -1,27 +1,27 @@ IDField.') FROM '.$this->Application->GetLiveName($this->TableName); return $this->Conn->GetOne($sql) + 1; } - + function setPrimary($reset_primary = true) { if ($reset_primary) { $sql = 'UPDATE '.$this->TableName.' SET PrimaryLang = 0'; $this->Conn->Query($sql); } - + $sql = 'UPDATE '.$this->TableName.' SET PrimaryLang = 1, Enabled = 1 WHERE '.$this->IDField.' = '.$this->GetID(); - $this->Conn->Query($sql); + $this->Conn->Query($sql); } - + /** * Allows to format number according to regional settings * @@ -33,6 +33,32 @@ { return number_format($number, $precision, $this->GetDBField('DecimalPoint'), $this->GetDBField('ThousandSep')); } + + function Load($id, $id_field_name=null) + { + $default = false; + if ($id == 'default') { + $id = 1; + $id_field_name = 'PrimaryLang'; + $default = true; + } + + $res = parent::Load($id, $id_field_name); + + if ($default) { + if (!$res) { + if ($this->Application->IsAdmin()) { + $res = parent::Load(1); + } + else { + $this->Application->ApplicationDie('No Primary Language Selected'); + } + } + $this->Application->SetVar('lang.current_id', $this->GetID() ); + $this->Application->SetVar('m_lang', $this->GetID() ); + } + return $res; + } } ?> \ No newline at end of file Index: branches/unlabeled/unlabeled-1.4.2/core/units/general/helpers/mod_rewrite_helper.php =================================================================== diff -u -r5718 -r5724 --- branches/unlabeled/unlabeled-1.4.2/core/units/general/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 5718) +++ branches/unlabeled/unlabeled-1.4.2/core/units/general/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 5724) @@ -8,18 +8,18 @@ $this->HTTPQuery =& $this->Application->recallObject('HTTPQuery'); } - function SetDefaultValues() + function SetDefaultValues(&$vars) { $defaults = Array('m_cat_id' => 0, 'm_cat_page' => 1, 'm_opener' => 's'); foreach ($defaults as $default_key => $default_value) { if ($this->HTTPQuery->Get($default_key) == null) { - $this->HTTPQuery->Set($default_key, $default_value); + $vars[$default_key] = $default_value; } } } - function ProcessLanguage(&$url_parts) + function ProcessLanguage(&$url_parts, &$vars) { if (!isset($url_parts[0])) return false; $res = false; @@ -30,7 +30,7 @@ $this->Application->Phrases = new PhrasesCache(); if($language_id) { - $this->HTTPQuery->Set('m_lang', $language_id); + $vars['m_lang'] = $language_id; $res = true; } @@ -41,7 +41,7 @@ return $res; } - function ProcessTheme(&$url_parts) + function ProcessTheme(&$url_parts, &$vars) { if (!isset($url_parts[0])) return false; $res = false; @@ -51,7 +51,7 @@ $theme_id = $this->Conn->GetOne($sql); if($theme_id) { - $this->HTTPQuery->Set('m_theme', $theme_id); + $vars['m_theme'] = $theme_id; $res = true; } $this->Application->VerifyThemeId(); // verify anyway - will set default if not found!!! @@ -61,7 +61,7 @@ return $res; } - function ProcessCategory(&$url_parts) + function ProcessCategory(&$url_parts, &$vars) { if (!isset($url_parts[0])) return false; $res = false; @@ -77,7 +77,7 @@ if( preg_match('/(.*)_([\d]+)$/', $category_path, $rets) ) { $category_path = $rets[1]; - $this->HTTPQuery->Set('m_cat_page', $rets[2]); + $vars['m_cat_page'] = $rets[2]; } $category_id = $this->Conn->GetOne( @@ -90,15 +90,15 @@ $res = true; } } while ($category_id !== false && $url_part); - $this->HTTPQuery->Set('m_cat_id', $last_category_id); + $vars['m_cat_id'] = $last_category_id; if ($url_part) { array_unshift($url_parts, $url_part); } return $res; } - function ProcessModuleIndex(&$url_parts) + function ProcessModuleIndex(&$url_parts, &$vars) { if ( count($url_parts) > 1) return false; // if no more parts or only 1 part left if ( $url_parts && $url_parts[0] == 'index') { // treat index same as no parts @@ -111,9 +111,9 @@ // set module pages for all modules, since we don't know which module will need it foreach ($this->Application->ModuleInfo as $module_name => $module_data) { - $this->Application->SetVar( $module_data['Var'].'_id', 0); - $this->Application->SetVar( $module_data['Var'].'_Page', $url_parts[0]); - $this->Application->SetVar( $module_data['Var'].'_Reviews_Page', 0); + $vars[ $module_data['Var'].'_id'] = 0; + $vars[ $module_data['Var'].'_Page'] = $url_parts[0]; + $vars[ $module_data['Var'].'_Reviews_Page'] = 0; } } @@ -125,24 +125,25 @@ WHERE p.IsIndex = 1 AND - CategoryId = '.$this->Application->GetVar('m_cat_id').' + CategoryId = '.$vars['m_cat_id'].' AND ci.PrimaryCat = 1'; $template_found = $this->Conn->GetRow($sql); if ($template_found !== false) { - $this->HTTPQuery->Set('t', $template_found['Path']); + $vars['t'] = $template_found['Path']; return true; } } $sql = 'SELECT CachedCategoryTemplate FROM '.TABLE_PREFIX.'Category - WHERE CategoryId = '.$this->Application->GetVar('m_cat_id'); - $this->HTTPQuery->Set('t', $this->HTTPQuery->getDefaultTemplate( $this->Conn->GetOne($sql) ) ); + WHERE CategoryId = '.$vars['m_cat_id']; + $vars['t'] = $this->Conn->GetOne($sql); + if (!$vars['t']) $vars['t'] = 'index'; return true; } - function ProcessModuleItem(&$url_parts, $set_t=true) + function ProcessModuleItem(&$url_parts, &$vars, $set_t=true) { if (!isset($url_parts[0])) return false; if ( count($url_parts) != 1 ) return false; @@ -162,7 +163,7 @@ LEFT JOIN '.TABLE_PREFIX.'Category AS c ON c.CategoryId = ci.CategoryId WHERE - ci.CategoryId = '.$this->Application->GetVar('m_cat_id').' + ci.CategoryId = '.$vars['m_cat_id'].' AND ci.Filename = '.$this->Conn->qstr($url_part)); @@ -196,18 +197,18 @@ if ($item_template && $item_id) { if ($set_t) { - $this->HTTPQuery->Set('t', $item_template); + $vars['t'] = $item_template; } - $this->Application->SetVar($module_prefix.'_id', $item_id); - $this->Application->SetVar($module_prefix.'_Reviews_Page', $page); + $vars[ $module_prefix.'_id' ] = $item_id; + $vars[ $module_prefix.'_Reviews_Page' ] = $page; return $module_prefix; } } array_unshift($url_parts, $url_part); return false; } - function ProcessPhisycalTemplate(&$url_parts) + function ProcessPhisycalTemplate(&$url_parts, &$vars) { if (!isset($url_parts[0])) return false; @@ -234,7 +235,7 @@ $url_parts = $remaining; if ($template_found) { - $this->HTTPQuery->Set('t', $template_path ); + $vars['t'] = $template_path; return true; } return false; @@ -246,7 +247,7 @@ * @param array $url_parts * @return boolean */ - function ProcessVirtualTemplate(&$url_parts) + function ProcessVirtualTemplate(&$url_parts, &$vars) { if (!isset($url_parts[0]) || !$this->Application->isModuleEnabled('In-CMS')) return false; @@ -261,8 +262,8 @@ $template_found = $this->Conn->GetRow($sql); if ($template_found) { - $this->Application->SetVar('m_cat_id', $template_found['CategoryId']); - $this->HTTPQuery->Set('t', $template_path ); + $vars['m_cat_id'] = $template_found['CategoryId']; + $vars['t'] = $template_path; return true; } @@ -271,53 +272,90 @@ function processRewriteURL() { + $passed = array(); $url = $this->HTTPQuery->Get('_mod_rw_url_'); if( substr($url, -5) == '.html' ) $url = substr($url, 0, strlen($url) - 5 ); + + $restored = false; + $cache = $this->Conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "mod_rw_'.md5($url).'"'); + if ($cache && $cache['Cached'] > 0) { + $cache = unserialize($cache['Data']); + $vars = $cache['vars']; + $passed = $cache['passed']; + $restored = true; + } + else { + $passed = array(); + $vars = $this->parseRewriteURL($url,$passed); + $cache = array('vars'=>$vars,'passed'=>$passed); + $this->Conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("mod_rw_'.md5($url).'", '.$this->Conn->qstr(serialize($cache)).', '.adodb_mktime().')'); + } + foreach ($vars as $name => $value) + { + $this->HTTPQuery->Set($name,$value); + } + if ($restored) { + $this->InitAll(); + } + $this->HTTPQuery->finalizeParsing($passed); + } + + function InitAll() + { + $this->Application->Phrases = new PhrasesCache(); + $this->Application->VerifyLanguageId(); + $this->Application->Phrases->Init('phrases'); + $this->Application->VerifyThemeId(); + } + + function parseRewriteURL($url, &$passed) + { + $vars = $this->Conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "mod_rw_'.md5($url).'"'); + if ($vars && $vars['Cached'] > 0) { + $vars = unserialize($menu['Data']); + return $vars; + } + + $vars = array(); $url_parts = $url ? explode('/', $url) : Array(); $process_module = true; if($this->HTTPQuery->Get('rewrite') == 'on' || !$url_parts) { - $this->SetDefaultValues(); + $this->SetDefaultValues($vars); } if(!$url_parts) { - $this->Application->Phrases = new PhrasesCache(); - $this->Application->VerifyLanguageId(); - $this->Application->Phrases->Init('phrases'); - $this->Application->VerifyThemeId(); + $this->InitAll(); - $this->HTTPQuery->Set('t', $this->HTTPQuery->getDefaultTemplate('') ); - $this->HTTPQuery->finalizeParsing(Array('m')); - return false; + $vars['t'] = $this->HTTPQuery->getDefaultTemplate(''); + $passed[] = 'm'; + return $vars; } else { - $this->HTTPQuery->Set('t', ''); + $vars['t'] = ''; } $passed = Array('m'); - $this->ProcessLanguage($url_parts); - $this->ProcessTheme($url_parts); + $this->ProcessLanguage($url_parts, $vars); + $this->ProcessTheme($url_parts, $vars); - if ( $this->ProcessVirtualTemplate($url_parts) ) { - $this->HTTPQuery->finalizeParsing($passed, $module_params); - return true; + if ( $this->ProcessVirtualTemplate($url_parts, $vars) ) { + return $vars; } - $this->ProcessCategory($url_parts); - if ( $this->ProcessModuleIndex($url_parts) ) { + $this->ProcessCategory($url_parts, $vars); + if ( $this->ProcessModuleIndex($url_parts, $vars) ) { foreach ($this->Application->ModuleInfo as $module_name => $info) { $passed[] = $info['Var']; } - $this->HTTPQuery->finalizeParsing($passed, $module_params); - return ; + return $vars; } - if ( $module_prefix = $this->ProcessModuleItem($url_parts) ) { + if ( $module_prefix = $this->ProcessModuleItem($url_parts, $vars) ) { $passed[] = $module_prefix; - $this->HTTPQuery->finalizeParsing($passed, $module_params); - return ; + return $vars; } /*// match module @@ -344,21 +382,22 @@ } }*/ - if ( $this->ProcessPhisycalTemplate($url_parts) ) { + if ( $this->ProcessPhisycalTemplate($url_parts, $vars) ) { if (!$url_parts) { - $this->HTTPQuery->finalizeParsing($passed, $module_params); - return true; + return $vars; } } - if ( $module_prefix = $this->ProcessModuleItem($url_parts, false) ) { + if ( $module_prefix = $this->ProcessModuleItem($url_parts, $vars, false) ) { $passed[] = $module_prefix; - $this->HTTPQuery->finalizeParsing($passed, $module_params); - return ; + return $vars; } - $this->HTTPQuery->finalizeParsing($passed, $module_params); + $not_found = $this->Application->ConfigValue('ErrorTemplate'); + $vars['t'] = $not_found ? $not_found : 'error_notfound'; +// $this->HTTPQuery->finalizeParsing($passed, $module_params); + // pass params left to module /*$this->Application->Phrases->Init('phrases'); Index: branches/unlabeled/unlabeled-1.4.2/kernel/units/general/helpers/mod_rewrite_helper.php =================================================================== diff -u -r5718 -r5724 --- branches/unlabeled/unlabeled-1.4.2/kernel/units/general/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 5718) +++ branches/unlabeled/unlabeled-1.4.2/kernel/units/general/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 5724) @@ -8,18 +8,18 @@ $this->HTTPQuery =& $this->Application->recallObject('HTTPQuery'); } - function SetDefaultValues() + function SetDefaultValues(&$vars) { $defaults = Array('m_cat_id' => 0, 'm_cat_page' => 1, 'm_opener' => 's'); foreach ($defaults as $default_key => $default_value) { if ($this->HTTPQuery->Get($default_key) == null) { - $this->HTTPQuery->Set($default_key, $default_value); + $vars[$default_key] = $default_value; } } } - function ProcessLanguage(&$url_parts) + function ProcessLanguage(&$url_parts, &$vars) { if (!isset($url_parts[0])) return false; $res = false; @@ -30,7 +30,7 @@ $this->Application->Phrases = new PhrasesCache(); if($language_id) { - $this->HTTPQuery->Set('m_lang', $language_id); + $vars['m_lang'] = $language_id; $res = true; } @@ -41,7 +41,7 @@ return $res; } - function ProcessTheme(&$url_parts) + function ProcessTheme(&$url_parts, &$vars) { if (!isset($url_parts[0])) return false; $res = false; @@ -51,7 +51,7 @@ $theme_id = $this->Conn->GetOne($sql); if($theme_id) { - $this->HTTPQuery->Set('m_theme', $theme_id); + $vars['m_theme'] = $theme_id; $res = true; } $this->Application->VerifyThemeId(); // verify anyway - will set default if not found!!! @@ -61,7 +61,7 @@ return $res; } - function ProcessCategory(&$url_parts) + function ProcessCategory(&$url_parts, &$vars) { if (!isset($url_parts[0])) return false; $res = false; @@ -77,7 +77,7 @@ if( preg_match('/(.*)_([\d]+)$/', $category_path, $rets) ) { $category_path = $rets[1]; - $this->HTTPQuery->Set('m_cat_page', $rets[2]); + $vars['m_cat_page'] = $rets[2]; } $category_id = $this->Conn->GetOne( @@ -90,15 +90,15 @@ $res = true; } } while ($category_id !== false && $url_part); - $this->HTTPQuery->Set('m_cat_id', $last_category_id); + $vars['m_cat_id'] = $last_category_id; if ($url_part) { array_unshift($url_parts, $url_part); } return $res; } - function ProcessModuleIndex(&$url_parts) + function ProcessModuleIndex(&$url_parts, &$vars) { if ( count($url_parts) > 1) return false; // if no more parts or only 1 part left if ( $url_parts && $url_parts[0] == 'index') { // treat index same as no parts @@ -111,9 +111,9 @@ // set module pages for all modules, since we don't know which module will need it foreach ($this->Application->ModuleInfo as $module_name => $module_data) { - $this->Application->SetVar( $module_data['Var'].'_id', 0); - $this->Application->SetVar( $module_data['Var'].'_Page', $url_parts[0]); - $this->Application->SetVar( $module_data['Var'].'_Reviews_Page', 0); + $vars[ $module_data['Var'].'_id'] = 0; + $vars[ $module_data['Var'].'_Page'] = $url_parts[0]; + $vars[ $module_data['Var'].'_Reviews_Page'] = 0; } } @@ -125,24 +125,25 @@ WHERE p.IsIndex = 1 AND - CategoryId = '.$this->Application->GetVar('m_cat_id').' + CategoryId = '.$vars['m_cat_id'].' AND ci.PrimaryCat = 1'; $template_found = $this->Conn->GetRow($sql); if ($template_found !== false) { - $this->HTTPQuery->Set('t', $template_found['Path']); + $vars['t'] = $template_found['Path']; return true; } } $sql = 'SELECT CachedCategoryTemplate FROM '.TABLE_PREFIX.'Category - WHERE CategoryId = '.$this->Application->GetVar('m_cat_id'); - $this->HTTPQuery->Set('t', $this->HTTPQuery->getDefaultTemplate( $this->Conn->GetOne($sql) ) ); + WHERE CategoryId = '.$vars['m_cat_id']; + $vars['t'] = $this->Conn->GetOne($sql); + if (!$vars['t']) $vars['t'] = 'index'; return true; } - function ProcessModuleItem(&$url_parts, $set_t=true) + function ProcessModuleItem(&$url_parts, &$vars, $set_t=true) { if (!isset($url_parts[0])) return false; if ( count($url_parts) != 1 ) return false; @@ -162,7 +163,7 @@ LEFT JOIN '.TABLE_PREFIX.'Category AS c ON c.CategoryId = ci.CategoryId WHERE - ci.CategoryId = '.$this->Application->GetVar('m_cat_id').' + ci.CategoryId = '.$vars['m_cat_id'].' AND ci.Filename = '.$this->Conn->qstr($url_part)); @@ -196,18 +197,18 @@ if ($item_template && $item_id) { if ($set_t) { - $this->HTTPQuery->Set('t', $item_template); + $vars['t'] = $item_template; } - $this->Application->SetVar($module_prefix.'_id', $item_id); - $this->Application->SetVar($module_prefix.'_Reviews_Page', $page); + $vars[ $module_prefix.'_id' ] = $item_id; + $vars[ $module_prefix.'_Reviews_Page' ] = $page; return $module_prefix; } } array_unshift($url_parts, $url_part); return false; } - function ProcessPhisycalTemplate(&$url_parts) + function ProcessPhisycalTemplate(&$url_parts, &$vars) { if (!isset($url_parts[0])) return false; @@ -234,7 +235,7 @@ $url_parts = $remaining; if ($template_found) { - $this->HTTPQuery->Set('t', $template_path ); + $vars['t'] = $template_path; return true; } return false; @@ -246,7 +247,7 @@ * @param array $url_parts * @return boolean */ - function ProcessVirtualTemplate(&$url_parts) + function ProcessVirtualTemplate(&$url_parts, &$vars) { if (!isset($url_parts[0]) || !$this->Application->isModuleEnabled('In-CMS')) return false; @@ -261,8 +262,8 @@ $template_found = $this->Conn->GetRow($sql); if ($template_found) { - $this->Application->SetVar('m_cat_id', $template_found['CategoryId']); - $this->HTTPQuery->Set('t', $template_path ); + $vars['m_cat_id'] = $template_found['CategoryId']; + $vars['t'] = $template_path; return true; } @@ -271,53 +272,90 @@ function processRewriteURL() { + $passed = array(); $url = $this->HTTPQuery->Get('_mod_rw_url_'); if( substr($url, -5) == '.html' ) $url = substr($url, 0, strlen($url) - 5 ); + + $restored = false; + $cache = $this->Conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "mod_rw_'.md5($url).'"'); + if ($cache && $cache['Cached'] > 0) { + $cache = unserialize($cache['Data']); + $vars = $cache['vars']; + $passed = $cache['passed']; + $restored = true; + } + else { + $passed = array(); + $vars = $this->parseRewriteURL($url,$passed); + $cache = array('vars'=>$vars,'passed'=>$passed); + $this->Conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("mod_rw_'.md5($url).'", '.$this->Conn->qstr(serialize($cache)).', '.adodb_mktime().')'); + } + foreach ($vars as $name => $value) + { + $this->HTTPQuery->Set($name,$value); + } + if ($restored) { + $this->InitAll(); + } + $this->HTTPQuery->finalizeParsing($passed); + } + + function InitAll() + { + $this->Application->Phrases = new PhrasesCache(); + $this->Application->VerifyLanguageId(); + $this->Application->Phrases->Init('phrases'); + $this->Application->VerifyThemeId(); + } + + function parseRewriteURL($url, &$passed) + { + $vars = $this->Conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "mod_rw_'.md5($url).'"'); + if ($vars && $vars['Cached'] > 0) { + $vars = unserialize($menu['Data']); + return $vars; + } + + $vars = array(); $url_parts = $url ? explode('/', $url) : Array(); $process_module = true; if($this->HTTPQuery->Get('rewrite') == 'on' || !$url_parts) { - $this->SetDefaultValues(); + $this->SetDefaultValues($vars); } if(!$url_parts) { - $this->Application->Phrases = new PhrasesCache(); - $this->Application->VerifyLanguageId(); - $this->Application->Phrases->Init('phrases'); - $this->Application->VerifyThemeId(); + $this->InitAll(); - $this->HTTPQuery->Set('t', $this->HTTPQuery->getDefaultTemplate('') ); - $this->HTTPQuery->finalizeParsing(Array('m')); - return false; + $vars['t'] = $this->HTTPQuery->getDefaultTemplate(''); + $passed[] = 'm'; + return $vars; } else { - $this->HTTPQuery->Set('t', ''); + $vars['t'] = ''; } $passed = Array('m'); - $this->ProcessLanguage($url_parts); - $this->ProcessTheme($url_parts); + $this->ProcessLanguage($url_parts, $vars); + $this->ProcessTheme($url_parts, $vars); - if ( $this->ProcessVirtualTemplate($url_parts) ) { - $this->HTTPQuery->finalizeParsing($passed, $module_params); - return true; + if ( $this->ProcessVirtualTemplate($url_parts, $vars) ) { + return $vars; } - $this->ProcessCategory($url_parts); - if ( $this->ProcessModuleIndex($url_parts) ) { + $this->ProcessCategory($url_parts, $vars); + if ( $this->ProcessModuleIndex($url_parts, $vars) ) { foreach ($this->Application->ModuleInfo as $module_name => $info) { $passed[] = $info['Var']; } - $this->HTTPQuery->finalizeParsing($passed, $module_params); - return ; + return $vars; } - if ( $module_prefix = $this->ProcessModuleItem($url_parts) ) { + if ( $module_prefix = $this->ProcessModuleItem($url_parts, $vars) ) { $passed[] = $module_prefix; - $this->HTTPQuery->finalizeParsing($passed, $module_params); - return ; + return $vars; } /*// match module @@ -344,21 +382,22 @@ } }*/ - if ( $this->ProcessPhisycalTemplate($url_parts) ) { + if ( $this->ProcessPhisycalTemplate($url_parts, $vars) ) { if (!$url_parts) { - $this->HTTPQuery->finalizeParsing($passed, $module_params); - return true; + return $vars; } } - if ( $module_prefix = $this->ProcessModuleItem($url_parts, false) ) { + if ( $module_prefix = $this->ProcessModuleItem($url_parts, $vars, false) ) { $passed[] = $module_prefix; - $this->HTTPQuery->finalizeParsing($passed, $module_params); - return ; + return $vars; } - $this->HTTPQuery->finalizeParsing($passed, $module_params); + $not_found = $this->Application->ConfigValue('ErrorTemplate'); + $vars['t'] = $not_found ? $not_found : 'error_notfound'; +// $this->HTTPQuery->finalizeParsing($passed, $module_params); + // pass params left to module /*$this->Application->Phrases->Init('phrases');