Index: install/install_toolkit.php
===================================================================
--- install/install_toolkit.php (revision 14733)
+++ install/install_toolkit.php (working copy)
@@ -902,7 +902,7 @@
/* @var $themes_helper kThemesHelper */
$module_name = $this->Application->findModule('Path', rtrim($module_folder, '/') . '/', 'Name');
- $themes_helper->syncronizeModule($module_name);
+ $themes_helper->synchronizeModule($module_name);
$this->deleteCache($refresh_permissions);
Index: kernel/managers/rewrite_url_processor.php
===================================================================
--- kernel/managers/rewrite_url_processor.php (revision 14751)
+++ kernel/managers/rewrite_url_processor.php (working copy)
@@ -567,48 +567,34 @@
*/
protected function _parsePhysicalTemplate($url_parts, &$vars)
{
- if (!$url_parts) {
+ if ( !$url_parts ) {
return false;
}
+ $themes_helper =& $this->Application->recallObject('ThemesHelper');
+ /* @var $themes_helper kThemesHelper */
+
do {
$template_path = implode('/', $url_parts);
+ $template_found = $themes_helper->getTemplateId($template_path, $vars['m_theme']);
- $physical_template = $this->Application->getPhysicalTemplate($template_path);
-
- if (($physical_template !== false) && (substr($physical_template, 0, 3) != 'id:')) {
- // replace menu template name with it's actual template name on disk
- list ($template_path) = explode(':', $physical_template, 2);
- }
-
- $t_parts['path'] = dirname($template_path) == '.' ? '' : '/' . dirname($template_path);
- $t_parts['file'] = basename($template_path);
-
- $sql = 'SELECT FileId
- FROM ' . TABLE_PREFIX . 'ThemeFiles
- WHERE (ThemeId = ' . $vars['m_theme'] . ') AND (FilePath = ' . $this->Conn->qstr($t_parts['path']) . ') AND (FileName = ' . $this->Conn->qstr($t_parts['file'] . '.tpl') . ')';
- $template_found = $this->Conn->GetOne($sql);
-
- if (!$template_found) {
+ if ( !$template_found ) {
array_shift($url_parts);
}
- } while (!$template_found && $url_parts);
+ } while ( !$template_found && $url_parts );
- if ($template_found) {
+ if ( $template_found ) {
$vars['t'] = $template_path;
$template_parts = explode('/', $template_path);
while ( $template_parts ) {
- $this->partParsed( array_pop($template_parts), 'rtl' );
+ $this->partParsed(array_pop($template_parts), 'rtl');
}
// 1. will damage actual category during category item review add process
// 2. will use "use_section" parameter of "m_Link" tag to gain same effect
-// $themes_helper =& $this->Application->recallObject('ThemesHelper');
-// /* @var $themes_helper kThemesHelper */
-//
-// $vars['m_cat_id'] = $themes_helper->getPageByTemplate($template_path, $vars['m_theme']);
+// $vars['m_cat_id'] = $themes_helper->getPageByTemplate($template_path, $vars['m_theme']);
return true;
}
@@ -616,8 +602,6 @@
return false;
}
-
-
/**
* Returns environment variable values for given prefix (uses directly given params, when available)
*
@@ -685,12 +669,12 @@
$cache_key = __CLASS__ . '::' . __FUNCTION__ . '[%CIDSerial:' . $category_id . '%]:' . $module_prefix;
$cached_value = $this->Application->getCache($cache_key);
- if ($cached_value !== false) {
+ if ( $cached_value !== false ) {
return $cached_value;
}
- if (!is_array($category)) {
- if ($category == 0) {
+ if ( !is_array($category) ) {
+ if ( $category == 0 ) {
$category = $this->Application->findModule('Var', $module_prefix, 'RootCat');
}
$sql = 'SELECT c.ParentPath, c.CategoryId
@@ -698,7 +682,7 @@
WHERE c.CategoryId = ' . $category;
$category = $this->Conn->GetRow($sql);
}
- $parent_path = implode(',',explode('|', substr($category['ParentPath'], 1, -1)));
+ $parent_path = implode(',', explode('|', substr($category['ParentPath'], 1, -1)));
// item template is stored in module' system custom field - need to get that field Id
$primary_lang = $this->Application->GetDefaultLanguageId();
@@ -715,7 +699,7 @@
ORDER BY FIND_IN_SET(c.CategoryId, ' . $this->Conn->qstr($parent_path) . ') DESC';
$item_template = $this->Conn->GetOne($query);
- if (!isset($this->_templateAliases)) {
+ if ( !isset($this->_templateAliases) ) {
// when empty url OR mod-rewrite disabled
$themes_helper =& $this->Application->recallObject('ThemesHelper');
@@ -729,8 +713,9 @@
$this->_templateAliases = $template_aliases ? unserialize($template_aliases) : Array ();
}
- if ($item_template && array_key_exists($item_template, $this->_templateAliases)) {
- $item_template = $this->_templateAliases[$item_template];
+ if ( substr($item_template, 0, 1) == '#' ) {
+ // it's template alias + "#" isn't allowed in filenames
+ $item_template = (string)getArrayValue($this->_templateAliases, $item_template);
}
$this->Application->setCache($cache_key, $item_template);
Index: units/helpers/mod_rewrite_helper.php
===================================================================
--- units/helpers/mod_rewrite_helper.php (revision 14733)
+++ units/helpers/mod_rewrite_helper.php (working copy)
@@ -179,12 +179,12 @@
*/
protected function _parseCategoryItemUrl(&$url_parts, &$vars)
{
- if (!$url_parts) {
+ if ( !$url_parts ) {
return false;
}
$item_filename = end($url_parts);
- if (is_numeric($item_filename)) {
+ if ( is_numeric($item_filename) ) {
// this page, don't process here
return false;
}
@@ -192,7 +192,7 @@
$rewrite_processor =& $this->Application->recallObject('kRewriteUrlProcessor');
/* @var $rewrite_processor kRewriteUrlProcessor */
- if (preg_match('/^bb_([\d]+)/', $item_filename, $regs)) {
+ if ( preg_match('/^bb_([\d]+)/', $item_filename, $regs) ) {
// process topics separately, because they don't use item filenames
array_pop($url_parts);
$rewrite_processor->partParsed($item_filename, 'rtl');
@@ -207,12 +207,12 @@
WHERE (ci.CategoryId = ' . (int)$vars['m_cat_id'] . ') AND (ci.Filename = ' . $this->Conn->qstr($item_filename) . ')';
$cat_item = $this->Conn->GetRow($sql);
- if ($cat_item !== false) {
+ if ( $cat_item !== false ) {
// item found
$module_prefix = $cat_item['ItemPrefix'];
$item_template = $rewrite_processor->GetItemTemplate($cat_item, $module_prefix);
- // converting ResourceId to correpsonding Item id
+ // converting ResourceId to corresponding Item id
$module_config = $this->Application->getUnitOptions($module_prefix);
$sql = 'SELECT ' . $module_config['IDField'] . '
@@ -220,14 +220,13 @@
WHERE ResourceId = ' . $cat_item['ItemResourceId'];
$item_id = $this->Conn->GetOne($sql);
- array_pop($url_parts);
+ if ( $item_id ) {
+ array_pop($url_parts);
- if ($item_id) {
- $rewrite_processor->partParsed($item_filename, 'rtl');
-
- if ($item_template) {
+ if ( $item_template ) {
// when template is found in category -> set it
$vars['t'] = $item_template;
+ $rewrite_processor->partParsed($item_filename, 'rtl');
}
// we have category item id
Index: units/helpers/themes_helper.php
===================================================================
--- units/helpers/themes_helper.php (revision 14733)
+++ units/helpers/themes_helper.php (working copy)
@@ -207,22 +207,31 @@
}
$current_node =& $root_node->firstChild;
+ /* @var $current_node kXMLNode */
do {
$template_path = trim($current_node->Data);
- $alias = '#' . $module_info['TemplatePath'] . strtolower($current_node->Name) . '#';
+ $module_override = $current_node->GetAttribute('module');
- // remember alias in global theme mapping
- $template_aliases[$alias] = $template_path;
+ if ( $module_override ) {
+ // allow to put template mappings form all modules into single theme.xml file
+ $module_folder = $this->Application->findModule('Name', $module_override, 'TemplatePath');
+ }
+ else {
+ // no module specified -> use module based on theme.xml file location
+ $module_folder = $module_info['TemplatePath'];
+ }
- // store alias in theme file record to use later in design dropdown
- $t_parts = Array ('path' => dirname($template_path) == '.' ? ''
- : '/' . dirname($template_path), 'file' => basename($template_path),);
+ // only store alias, when template exists on disk
+ if ( $this->getTemplateId($template_path, $theme_id) ) {
+ $alias = '#' . $module_folder . strtolower($current_node->Name) . '#';
- $sql = 'UPDATE ' . TABLE_PREFIX . 'ThemeFiles
- SET TemplateAlias = ' . $this->Conn->qstr($alias) . '
- WHERE (ThemeId = ' . $theme_id . ') AND (FilePath = ' . $this->Conn->qstr($t_parts['path']) . ') AND (FileName = ' . $this->Conn->qstr($t_parts['file'] . '.tpl') . ')';
- $this->Conn->Query($sql);
+ // remember alias in global theme mapping
+ $template_aliases[$alias] = $template_path;
+
+ // store alias in theme file record to use later in design dropdown
+ $this->updateTemplate($template_path, $theme_id, Array ('TemplateAlias' => $alias));
+ }
} while ( ($current_node =& $current_node->NextSibling()) );
}
}
@@ -231,11 +240,69 @@
}
/**
+ * Returns ID of given physical template (relative to theme) given from ThemeFiles table
+ * @param string $template_path
+ * @param int $theme_id
+ * @return int
+ * @access public
+ */
+ public function getTemplateId($template_path, $theme_id)
+ {
+ $physical_template = $this->Application->getPhysicalTemplate($template_path);
+
+ if ( ($physical_template !== false) && (substr($physical_template, 0, 3) != 'id:') ) {
+ // replace menu template name with it's actual template name on disk
+ list ($template_path) = explode(':', $physical_template, 2);
+ }
+
+ $sql = 'SELECT FileId
+ FROM ' . TABLE_PREFIX . 'ThemeFiles
+ WHERE ' . $this->getTemplateWhereClause($template_path, $theme_id);
+
+ return $this->Conn->GetOne($sql);
+ }
+
+ /**
+ * Updates template record with a given data
+ *
+ * @param string $template_path
+ * @param int $theme_id
+ * @param Array $fields_hash
+ * @return void
+ * @access public
+ */
+ public function updateTemplate($template_path, $theme_id, $fields_hash)
+ {
+ $where_clause = $this->getTemplateWhereClause($template_path, $theme_id);
+ $this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'ThemeFiles', $where_clause);
+ }
+
+ /**
+ * Returns where clause to get associated record from ThemeFiles table for given template path
+ * @param string $template_path
+ * @param int $theme_id
+ * @return string
+ * @access protected
+ */
+ protected function getTemplateWhereClause($template_path, $theme_id)
+ {
+ $folder = dirname($template_path);
+
+ $where_clause = Array (
+ 'ThemeId = ' . $theme_id,
+ 'FilePath = ' . $this->Conn->qstr($folder == '.' ? '' : '/' . $folder),
+ 'FileName = ' . $this->Conn->qstr(basename($template_path) . '.tpl'),
+ );
+
+ return '(' . implode(') AND (', $where_clause) . ')';
+ }
+
+ /**
* Installs given module language pack and refreshed it from all themes
*
* @param string $module_name
*/
- function syncronizeModule($module_name)
+ function synchronizeModule($module_name)
{
$sql = 'SELECT `Name`, ThemeId
FROM ' . TABLE_PREFIX . 'Theme';