Index: trunk/core/kernel/utility/http_query.php =================================================================== diff -u -N -r3879 -r4138 --- trunk/core/kernel/utility/http_query.php (.../http_query.php) (revision 3879) +++ trunk/core/kernel/utility/http_query.php (.../http_query.php) (revision 4138) @@ -377,15 +377,16 @@ $this->Set('m_cat_page', $rets[2]); } - $sql = 'SELECT CategoryId FROM '.TABLE_PREFIX.'Category WHERE NamedParentPath = '.$this->Conn->qstr($category_path); + $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 && $url_part); - if( count($category_stack) >= 2 ) - { + if (count($category_stack)) { $category_id = array_pop($category_stack); // remove last not found category if($category_id === false) { @@ -396,12 +397,46 @@ $this->Set('m_cat_id', $category_id); } } - elseif (!$category_found && getArrayValue($rets, 2)) - { + elseif (!$category_found && getArrayValue($rets, 2)) { $url_part = array_shift($url_parts); } } + + if (!$url_part) { + // no more parts left in url + $sql = 'SELECT CachedCategoryTemplate + FROM '.TABLE_PREFIX.'Category + WHERE CategoryId = '.$category_id; + $category_template = $this->Conn->GetOne($sql); + if ($category_template) { + $category_template = explode('/', $category_template); + $url_part = array_shift($category_template); + $url_parts = $category_template; + } + else { + $url_part = 'index'; + } + } + elseif ($url_part && count($url_parts) == 0) { + // only filename left, no other parts + $sql = 'SELECT ParentPath, CachedItemTemplate + FROM '.TABLE_PREFIX.'Category + WHERE CategoryId = '.$category_id; + $category_data = $this->Conn->GetRow($sql); + + $root_category_id = array_shift( explode('|', substr($category_data['ParentPath'], 1, -1)) ); + $module_info = $this->Application->findModule('RootCat', $root_category_id); + if ($module_info) { + $item_template = $category_data['CachedItemTemplate']; + if ($item_template) { + $url_parts = explode('/', $item_template); + array_push($url_parts, $url_part); // save item's filename as not processed + $url_part = array_shift($url_parts); + } + } + } + // match module $next_template = $this->Get('next_template'); if($url_part || $next_template)