Index: branches/5.2.x/core/units/helpers/themes_helper.php =================================================================== diff -u -N -r14699 -r14753 --- branches/5.2.x/core/units/helpers/themes_helper.php (.../themes_helper.php) (revision 14699) +++ branches/5.2.x/core/units/helpers/themes_helper.php (.../themes_helper.php) (revision 14753) @@ -1,6 +1,6 @@ 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';