Index: branches/5.1.x/core/units/helpers/themes_helper.php =================================================================== diff -u -r12657 -r13086 --- branches/5.1.x/core/units/helpers/themes_helper.php (.../themes_helper.php) (revision 12657) +++ branches/5.1.x/core/units/helpers/themes_helper.php (.../themes_helper.php) (revision 13086) @@ -1,6 +1,6 @@ Application->getUnitOption('theme', 'IDField'); $table_name = $this->Application->getUnitOption('theme', 'TableName'); - $sql = 'SELECT ' . $id_field . ', Enabled + $sql = 'SELECT * FROM ' . $table_name . ' WHERE Name = ' . $this->Conn->qstr($theme_name); $theme_info = $this->Conn->GetRow($sql); @@ -94,16 +94,17 @@ } else { // theme was not found in db, but found on hdd -> create new - $fields_hash = Array ( - 'Name' => $theme_name, - 'Enabled' => 0, - 'Description' => $theme_name, - 'PrimaryTheme' => 0, - 'CacheTimeout' => 3600, // not in use right now - 'StylesheetId' => 0, // not in use right now + $theme_info = Array ( + 'Name' => $theme_name, + 'Enabled' => 0, + 'Description' => $theme_name, + 'PrimaryTheme' => 0, + 'CacheTimeout' => 3600, // not in use right now + 'StylesheetId' => 0, // not in use right now + 'LanguagePackInstalled' => 0 ); - $this->Conn->doInsert($fields_hash, $table_name); + $this->Conn->doInsert($theme_info, $table_name); $theme_id = $this->Conn->getInsertID(); if (!$theme_enabled) { @@ -121,6 +122,81 @@ WHERE ThemeId = '.$theme_id.' AND FileFound = 0'; $this->Conn->Query($sql); + // install language packs, associated with theme (if any found and wasn't aready installed) + if (!$theme_info['LanguagePackInstalled']) { + $language_import_helper =& $this->Application->recallObject('LanguageImportHelper'); + /* @var $language_import_helper LanguageImportHelper */ + + foreach ($this->Application->ModuleInfo as $module_name => $module_info) { + if ($module_name == 'In-Portal') { + continue; + } + + $lang_file = $theme_path . '/' . $module_info['TemplatePath'] . '_install/english.lang'; + + if (file_exists($lang_file)) { + $language_import_helper->performImport($lang_file, '|0|', '', LANG_SKIP_EXISTING); + } + } + + $fields_hash = Array ( + 'LanguagePackInstalled' => 1, + ); + + $this->Conn->doUpdate($fields_hash, $table_name, $id_field . ' = ' . $theme_id); + } + + // get template aliases from "/_install/theme.xml" files in theme + $template_aliases = Array (); + + $xml_parser =& $this->Application->recallObject('kXMLHelper'); + /* @var $xml_parser kXMLHelper */ + + foreach ($this->Application->ModuleInfo as $module_name => $module_info) { + if ($module_name == 'In-Portal') { + continue; + } + + $xml_file = $theme_path . '/' . $module_info['TemplatePath'] . '_install/theme.xml'; + + if (file_exists($xml_file)) { + $xml_data = file_get_contents($xml_file); + $root_node =& $xml_parser->Parse($xml_data); + + if (!is_object($root_node) || !is_a($root_node, 'kXMLNode') || !$root_node->Children) { + // broken xml OR no aliases defined + continue; + } + + $current_node =& $root_node->firstChild; + + do { + $template_path = trim($current_node->Data); + $alias = '#' . $module_info['TemplatePath'] . strtolower($current_node->Name). '#'; + + // remember alias in global theme mapping + $template_aliases[$alias] = $template_path; + + // 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), + ); + + $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); + } while (($current_node =& $current_node->NextSibling())); + } + } + + $fields_hash = Array ( + 'TemplateAliases' => serialize($template_aliases), + ); + + $this->Conn->doUpdate($fields_hash, $table_name, $id_field . ' = ' . $theme_id); + return $theme_id; } @@ -343,7 +419,7 @@ return $theme_id; } - if ($this->Application->IsAdmin()) { + if ($this->Application->isAdmin) { // get theme, that user selected in catalog $theme_id = $this->Application->RecallVar('theme_id'); @@ -375,18 +451,26 @@ * Returns page id based on given template * * @param string $template + * @param int $theme_id * @return int */ - function getPageByTemplate($template) + function getPageByTemplate($template, $theme_id = null) { + if (!isset($theme_id)) { + // during mod-rewrite url parsing current theme + // is not available to kHTTPQuery class, so don't use it + $theme_id = (int)$this->getCurrentThemeId(); + } + $sql = 'SELECT ' . $this->Application->getUnitOption('c', 'IDField') . ' FROM ' . $this->Application->getUnitOption('c', 'TableName') . ' WHERE ( (NamedParentPath = ' . $this->Conn->qstr('Content/' . $template) . ') OR (IsSystem = 1 AND CachedTemplate = ' . $this->Conn->qstr($template) . ') ) - AND (ThemeId = ' . $this->getCurrentThemeId() . ' OR ThemeId = 0)'; + AND (ThemeId = ' . $theme_id . ($theme_id > 0 ? ' OR ThemeId = 0' : '') . ')'; + return $this->Conn->GetOne($sql); } } \ No newline at end of file