Index: trunk/core/kernel/utility/http_query.php =================================================================== diff -u -r3031 -r3162 --- trunk/core/kernel/utility/http_query.php (.../http_query.php) (revision 3031) +++ trunk/core/kernel/utility/http_query.php (.../http_query.php) (revision 3162) @@ -62,18 +62,32 @@ var $Admin = false; /** + * Description + * + * @var kDBConnection + * @access public + */ + var $Conn; + + /** * Loads info from $_POST, $_GET and * related arrays into common place * * @param string $order * @return HTTPQuery * @access public */ - function HTTPQuery($order='CGPF') + function HTTPQuery($order = 'CGPF') { parent::Params(); + $this->Conn =& $this->Application->GetADODBConnection(); + $this->Order = $order; $this->Admin = $this->Application->IsAdmin(); // better cache this value, not to calculate it each time in foreach + } + + function Init($prefix, $special) + { $this->AddAllVars(); $this->specialsToRemove = $this->Get('remove_specials'); @@ -83,7 +97,7 @@ } ini_set('magic_quotes_gpc', 0); } - + function removeSpecials($array) { $ret = Array(); @@ -116,22 +130,31 @@ $current = $this->Order[$i]; switch ($current) { case 'G': - $this->Get =$this->AddVars($_GET); + $this->Get = $this->AddVars($_GET); $this->processQueryString(); + if( $this->Application->RewriteURLs() ) + { + $this->processRewriteURL(); + } break; + case 'P': $this->Post = $this->AddVars($_POST); $this->convertPostEvents(); break; + case 'C': $this->Cookie = $this->AddVars($_COOKIE); break; + case 'E'; $this->Env = $this->AddVars($_ENV); break; + case 'S'; $this->Server = $this->AddVars($_SERVER); break; + case 'F'; $this->convertFiles(); $this->Files = $this->MergeVars($_FILES, false); //do not strip slashes! @@ -243,6 +266,162 @@ } } + + function processRewriteURL() + { + // directory_1_2_3/sc1/inlink/detail/3/l1_ka_asd.html + + $url = $this->Get('url'); + if( substr($url, -5) == '.html' ) $url = substr($url, 0, strlen($url) - 5 ); + + $url_parts = $url ? explode('/', $url) : Array(); + + // set default values + $defaults = Array('t' => '', 'm_cat_id' => 0, 'm_cat_page' => 1, 'm_opener' => 's'); + foreach ($defaults as $default_key => $default_value) + { + $this->Set($default_key, $default_value); + } + + if(!$url_parts) + { + $this->Application->VerifyLanguageId(); + $this->Application->VerifyThemeId(); + $this->Application->Phrases = new PhrasesCache(); + $this->Application->Phrases->Init('phrases'); +// $this->Get('m_lang') ); + $this->Set('t', $this->getDefaultTemplate('') ); + return false; + } + + $url_part = array_shift($url_parts); + + // match language + $sql = 'SELECT LanguageId FROM '.TABLE_PREFIX.'Language WHERE LOWER(PackName) = '.$this->Conn->qstr($url_part).' AND Enabled = 1'; + $language_id = $this->Conn->GetOne($sql); + if($language_id) + { + $this->Set('m_lang', $language_id); + $url_part = $url_parts ? array_shift($url_parts) : ''; // prepare next url part for parsing + } + else + { + $this->Application->VerifyLanguageId(); + } + $this->Application->Phrases = new PhrasesCache(); + $this->Application->Phrases->Init('phrases'); + // $this->Get('m_lang') ); + + // match theme + if($url_part) + { + $sql = 'SELECT ThemeId FROM '.TABLE_PREFIX.'Theme WHERE LOWER(Name) = '.$this->Conn->qstr($url_part).' AND Enabled = 1'; + $theme_id = $this->Conn->GetOne($sql); + if($theme_id) + { + $this->Set('m_theme', $theme_id); + $url_part = $url_parts ? array_shift($url_parts) : ''; // prepare next url part for parsing + } + else + { + $this->Application->VerifyThemeId(); + } + } + + // match category + if($url_part) + { + $category_stack = Array(); + $category_found = false; + $category_path = ''; + do + { + $category_path = trim($category_path.'/'.$url_part, '/'); + + if( preg_match('/(.*)_([\d]+)$/', $category_path, $rets) ) + { + $category_path = $rets[1]; + $this->Set('m_cat_page', $rets[2]); + } + + $sql = 'SELECT CategoryId FROM '.TABLE_PREFIX.'Category WHERE NamedParentPath = '.$this->Conn->qstr($category_path); + array_push($category_stack, $this->Conn->GetOne($sql) ); + $category_found = end($category_stack); + if($category_found) $url_part = array_shift($url_parts); + + }while ($category_found); + + if( count($category_stack) >= 2 ) + { + array_pop($category_stack); // remove last not found category + $category_id = array_pop($category_stack); + if($category_id) + { + $this->Set('m_cat_id', $category_id); + } + } + } + + // match module + if($url_part) + { + foreach ($this->Application->ModuleInfo as $module_name => $module_data) + { + if( trim($module_data['TemplatePath'], '/') == $url_part ) + { + $module_prefix = $module_data['Var']; + break; + } + } + } + + // match template + $template_path = ''; + $template_found = false; + if($url_part) + { + array_unshift($url_parts, $url_part); + $template_parts = $url_parts; + $url_parts = Array(); + do + { + $template_path = implode('/', $template_parts); + + $sql = 'SELECT FileId FROM '.TABLE_PREFIX.'ThemeFiles WHERE CONCAT(FilePath, "/", FileName) = '.$this->Conn->qstr('/'.$template_path.'.tpl'); + $template_found = $this->Conn->GetOne($sql); + if(!$template_found) + { + array_unshift( $url_parts, array_pop($template_parts) ); + } + + }while (!$template_found && $template_parts); + } + $this->Set('t', $this->getDefaultTemplate($template_found ? $template_path : '') ); + // pass params left to module + + $passed = Array('m'); + $module_params = Array(); + if($url_parts && isset($module_prefix) ) + { + $passed[] = $module_prefix; + $module_event = new kEvent($module_prefix.':ParseEnv', Array('url_parts' => $url_parts) ); + $this->Application->HandleEvent($module_event); + $module_params = Array($module_prefix.'_id' => 0); + } + + $this->Set('passed', implode(',', $passed) ); + $env = $this->Application->BuildEnv( $this->Get('t'), $module_params, implode(',', $passed), false, false ); + $this->Set(ENV_VAR_NAME, $env); + $_REQUEST['env'] = $_GET['env'] = $env; // for capability with old in-portal code + } + + function getDefaultTemplate($t) + { + $t = $this->getTemplateName( trim($t, '/') ); + if (!$t) $t = 'index'; + return trim($t, '/'); + } + /** * Process QueryString only, create * events, ids, based on config @@ -260,7 +439,7 @@ if($env_var) { $sid = $this->Get('sid'); - if (defined('MOD_REWRITE') && MOD_REWRITE && $sid && !$this->Get('admin') ) + if ( $this->Application->RewriteURLs() && $sid && !$this->Get('admin') ) { //$env_var = rtrim($sid.$env_var, '/'); $split_by = defined('INPORTAL_ENV') ? '-' : ':'; @@ -272,7 +451,7 @@ $parts=explode(':',$env_var); - if (defined('MOD_REWRITE') && MOD_REWRITE) $env_var = str_replace('/', ':', $env_var); + if ( $this->Application->RewriteURLs() ) $env_var = str_replace('/', ':', $env_var); if (defined('INPORTAL_ENV')) { $sub_parts = array_shift($parts); @@ -287,24 +466,21 @@ } // Save Template Name - $t=$this->getTemplateName( trim($t, '/') ); - if(!$t) $t='index'; - $this->Set('t', trim($t, '/') ); + $this->Set('t', $this->getDefaultTemplate($t) ); } else { // Save Session ID - $sid=array_shift($parts); - if($sid) $this->Set('sid',$sid); + $sid = array_shift($parts); + if ($sid) $this->Set('sid', $sid); // Save Template Name - $t=$this->getTemplateName( array_shift($parts) ); - if(!$t) $t='index'; - $this->Set('t', trim($t, '/') ); + $t = array_shift($parts); + $this->Set('t', $this->getDefaultTemplate($t) ); } if($parts) { - $query_maps=Array(); + $query_maps = Array(); $event_manger =& $this->Application->recallObject('EventManager'); $passed = Array(); @@ -353,7 +529,7 @@ else { $t=$this->getTemplateName('index'); - $this->Set('t',$t); + $this->Set('t', $t); } } @@ -368,13 +544,15 @@ function getTemplateName($querystring_template) { $t_from_post = $this->Get('t'); - $t= $t_from_post ? $t_from_post : $querystring_template; + $t = $t_from_post ? $t_from_post : $querystring_template; - if ( is_numeric($t) ) { - $t = $this->Application->DB->GetOne('SELECT CONCAT(FilePath, \'/\', FileName) FROM '.TABLE_PREFIX.'ThemeFiles - WHERE FileId = '.$t); + if ( is_numeric($t) ) + { + $t = $this->Conn->GetOne(' SELECT CONCAT(FilePath, \'/\', FileName) + FROM '.TABLE_PREFIX.'ThemeFiles + WHERE FileId = '.$t); } - $t = preg_replace("/\.tpl$/", '', $t); + $t = preg_replace('/\.tpl$/', '', $t); return $t; }