Index: branches/5.1.x/core/units/helpers/category_helper.php =================================================================== diff -u -r13086 -r13168 --- branches/5.1.x/core/units/helpers/category_helper.php (.../category_helper.php) (revision 13086) +++ branches/5.1.x/core/units/helpers/category_helper.php (.../category_helper.php) (revision 13168) @@ -1,6 +1,6 @@ Application->getCache($cache_key); + + if ($cached_path === false) { $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); $navbar_field = $ml_formatter->LangFieldName('CachedNavBar'); $id_field = $this->Application->getUnitOption('c', 'IDField'); $table_name = $this->Application->getUnitOption('c', 'TableName'); + $this->Conn->nextQueryCachable = true; $sql = 'SELECT '.$navbar_field.', ParentPath FROM '.$table_name.' WHERE '.$id_field.' = '.$main_category_id; $category_data = $this->Conn->GetRow($sql); + $cached_path = Array (); $skip_category = $this->Application->findModule('Name', 'Core', 'RootCat'); - $cached_path[$main_category_id] = Array (); + if ($category_data) { $category_names = explode('&|&', $category_data[$navbar_field]); $category_ids = explode('|', substr($category_data['ParentPath'], 1, -1)); @@ -312,11 +315,15 @@ if ($category_id == $skip_category) { continue; } - $cached_path[$main_category_id][$category_id] = $category_names[$category_index]; + + $cached_path[$category_id] = $category_names[$category_index]; } } + + $this->Application->setCache($cache_key, $cached_path); } - return $cached_path[$main_category_id]; + + return $cached_path; } /** @@ -419,10 +426,12 @@ function &_getStructureTree() { // get cached version of structure tree - $sql = 'SELECT Data - FROM ' . TABLE_PREFIX . 'Cache - WHERE VarName = "StructureTree"'; - $data = $this->Conn->GetOne($sql); + if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { + $data = $this->Application->getCache('master:StructureTree', false); + } + else { + $data = $this->Application->getDBCache('StructureTree'); + } if ($data) { $data = unserialize($data); @@ -439,26 +448,85 @@ $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); $data = $this->_getChildren($root_category, $language_count); - $fields_hash = Array ( - 'VarName' => 'StructureTree', - 'Data' => serialize($data), - 'Cached' => adodb_mktime(), - ); + if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { + $this->Application->setCache('master:StructureTree', serialize($data)); + } + else { + $this->Application->setDBCache('StructureTree', serialize($data)); + } - $this->Conn->doInsert($fields_hash, TABLE_PREFIX.'Cache', 'REPLACE'); - return $data; } + function getTemplateMapping() + { + if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { + $data = $this->Application->getCache('master:template_mapping', false); + } + else { + $data = $this->Application->getDBCache('template_mapping'); + } + + if ($data) { + return unserialize($data); + } + + $sql = 'SELECT + IF(c.IsSystem, CONCAT(c.Template, ":", c.ThemeId), CONCAT("id:", c.CategoryId)) AS SrcTemplate, + LOWER( + IF( + c.SymLinkCategoryId IS NOT NULL, + (SELECT cc.NamedParentPath FROM ' . TABLE_PREFIX . 'Category AS cc WHERE cc.CategoryId = c.SymLinkCategoryId), + c.NamedParentPath + ) + ) AS DstTemplate, + c.UseExternalUrl, c.ExternalUrl + FROM ' . TABLE_PREFIX . 'Category AS c + WHERE c.Status = ' . STATUS_ACTIVE; + $pages = $this->Conn->Query($sql, 'SrcTemplate'); + + $mapping = Array (); + $base_url = $this->Application->BaseURL(); + + foreach ($pages as $src_template => $page) { + // process external url, before placing in cache + if ($page['UseExternalUrl']) { + $external_url = $page['ExternalUrl']; + + if (!preg_match('/^(.*?):\/\/(.*)$/', $external_url)) { + // url without protocol will be relative url to our site + $external_url = $base_url . $external_url; + } + + $dst_template = 'external:' . $external_url; + } + else { + $dst_template = preg_replace('/^Content\//i', '', $page['DstTemplate']); + } + + $mapping[$src_template] = $dst_template; + } + + if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { + $data = $this->Application->setCache('master:template_mapping', serialize($mapping)); + } + else { + $this->Application->setDBCache('template_mapping', serialize($mapping)); + } + + return $mapping; + } + /** * Returns category structure as field option list * * @return Array */ function getStructureTreeAsOptions() { - if (defined('IS_INSTALL') && IS_INSTALL) { - // no need to create category structure during install, because it's not used there + if ((defined('IS_INSTALL') && IS_INSTALL) || !$this->Application->isAdmin) { + // no need to create category structure during install + // OR on Front-End, because it's not used there return Array (); }