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');