Index: branches/unlabeled/unlabeled-1.4.2/kernel/units/general/helpers/mod_rewrite_helper.php =================================================================== diff -u -r5560 -r5718 --- branches/unlabeled/unlabeled-1.4.2/kernel/units/general/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 5560) +++ branches/unlabeled/unlabeled-1.4.2/kernel/units/general/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 5718) @@ -100,16 +100,49 @@ function ProcessModuleIndex(&$url_parts) { - if ( count($url_parts) != 0 ) return false; + 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 + array_shift($url_parts); + } + if( $url_parts ) { // if parts are left, it can only be module page + if (!is_numeric($url_parts[0])) return false; + + // 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); + } + } + + // try to find CMS index page of the category + if ($this->Application->isModuleEnabled('In-CMS')) { + $sql = 'SELECT p.Path, ci.CategoryId FROM '.TABLE_PREFIX.'Pages AS p + LEFT JOIN '.TABLE_PREFIX.'CategoryItems AS ci + ON ci.ItemResourceId = p.ResourceId + WHERE + p.IsIndex = 1 + AND + CategoryId = '.$this->Application->GetVar('m_cat_id').' + AND + ci.PrimaryCat = 1'; + $template_found = $this->Conn->GetRow($sql); + if ($template_found !== false) { + $this->HTTPQuery->Set('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) ) ); return true; } - function ProcessModuleItem(&$url_parts) + function ProcessModuleItem(&$url_parts, $set_t=true) { if (!isset($url_parts[0])) return false; if ( count($url_parts) != 1 ) return false; @@ -123,51 +156,51 @@ $page = $rets[2]; } + // locating the item in CategoryItems by filename to detect its ItemPrefix and its category ParentPath $cat_item = $this->Conn->GetRow(' - SELECT ci.ItemPrefix, c.ParentPath, ci.CategoryId FORM '.TABLE_PREFIX.'CategoryItems AS ci + SELECT ci.ItemResourceId, ci.ItemPrefix, c.ParentPath, ci.CategoryId FROM '.TABLE_PREFIX.'CategoryItems AS ci LEFT JOIN '.TABLE_PREFIX.'Category AS c ON c.CategoryId = ci.CategoryId WHERE - CategoryId = '.$this->Application->GetVar('m_cat_id').' + ci.CategoryId = '.$this->Application->GetVar('m_cat_id').' AND - Filename = '.$this->Conn->qstr($url_part)); - if ($cat_item !== false) { + ci.Filename = '.$this->Conn->qstr($url_part)); + + if ($cat_item !== false) { // item found $module_prefix = $cat_item['ItemPrefix']; - $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); - } - $this->Application->SetVar($cat_item['ItemPrefix'].'_id', $item_id); - } + $parent_path = implode(',',explode('|', substr($cat_item['ParentPath'], 1, -1))); + // item template is stored in module' system custom field - need to get that field Id + $item_template_field_id = $this->Conn->GetOne( + 'SELECT CustomFieldId + FROM '.TABLE_PREFIX.'CustomField + WHERE FieldName = '.$this->Conn->qstr($module_prefix.'_ItemTemplate')); + // looking for item template through cats hierarchy sorted by parent path + $query = 'SELECT ccd.l1_cust_'.$item_template_field_id.', + FIND_IN_SET(c.CategoryId, '.$this->Conn->qstr($parent_path).') AS Ord1, + c.CategoryId, c.Name, ccd.l1_cust_15 + FROM inp_Category AS c + LEFT JOIN inp_CategoryCustomData AS ccd + ON ccd.ResourceId = c.ResourceId + WHERE c.CategoryId IN ('.$parent_path.') AND ccd.l1_cust_'.$item_template_field_id.' != \'\' + ORDER BY FIND_IN_SET(c.CategoryId, '.$this->Conn->qstr($parent_path).') DESC'; + $item_template = $this->Conn->GetOne($query); - $this->Application->SetVar( $event->getPrefixSpecial().'_Reviews_Page', $page); + // converting ResourceId to correpsonding Item id + $module_config = $this->Application->getUnitOptions($module_prefix); + $item_id = $this->Conn->GetOne( + 'SELECT '.$module_config['IDField'].' FROM '.$module_config['TableName'].' + WHERE ResourceId = '.$cat_item['ItemResourceId'] + ); - // only filename left, no other parts - $process_module = false; - $sql = 'SELECT ParentPath, CachedItemTemplate, CachedCategoryTemplate - FROM '.TABLE_PREFIX.'Category - WHERE CategoryId = '.$this->Application->GetVar('m_cat_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) { - $module_prefix = $module_info['Var']; - $module_event = new kEvent($module_prefix.':ParseEnv', Array('url_parts' => array_merge(Array($url_part), $url_parts)) ); - $this->Application->HandleEvent($module_event); - - if ($module_event->status == erSUCCESS && $this->HTTPQuery->Get($module_prefix.'_id')) { - $item_template = $category_data['CachedItemTemplate']; - if ($item_template) { - $this->HTTPQuery->Set('t', $item_template ); - return true; + if ($item_template && $item_id) { + if ($set_t) { + $this->HTTPQuery->Set('t', $item_template); } + $this->Application->SetVar($module_prefix.'_id', $item_id); + $this->Application->SetVar($module_prefix.'_Reviews_Page', $page); + return $module_prefix; } } array_unshift($url_parts, $url_part); @@ -264,18 +297,26 @@ $this->HTTPQuery->Set('t', ''); } + $passed = Array('m'); $this->ProcessLanguage($url_parts); $this->ProcessTheme($url_parts); if ( $this->ProcessVirtualTemplate($url_parts) ) { + $this->HTTPQuery->finalizeParsing($passed, $module_params); return true; } $this->ProcessCategory($url_parts); if ( $this->ProcessModuleIndex($url_parts) ) { + foreach ($this->Application->ModuleInfo as $module_name => $info) { + $passed[] = $info['Var']; + } + $this->HTTPQuery->finalizeParsing($passed, $module_params); return ; } - if ( $this->ProcessModuleItem($url_parts) ) { + if ( $module_prefix = $this->ProcessModuleItem($url_parts) ) { + $passed[] = $module_prefix; + $this->HTTPQuery->finalizeParsing($passed, $module_params); return ; } @@ -305,13 +346,22 @@ if ( $this->ProcessPhisycalTemplate($url_parts) ) { if (!$url_parts) { + $this->HTTPQuery->finalizeParsing($passed, $module_params); return true; } } + if ( $module_prefix = $this->ProcessModuleItem($url_parts, false) ) { + $passed[] = $module_prefix; + $this->HTTPQuery->finalizeParsing($passed, $module_params); + return ; + } + + $this->HTTPQuery->finalizeParsing($passed, $module_params); + // pass params left to module - $this->Application->Phrases->Init('phrases'); + /*$this->Application->Phrases->Init('phrases'); $passed = Array('m'); $module_params = Array(); if ( isset($module_prefix) ) { @@ -329,7 +379,7 @@ } } - $this->HTTPQuery->finalizeParsing($passed, $module_params); + $this->HTTPQuery->finalizeParsing($passed, $module_params);*/ }