Index: branches/RC/core/units/general/helpers/themes_helper.php =================================================================== diff -u -N -r11177 -r11495 --- branches/RC/core/units/general/helpers/themes_helper.php (.../themes_helper.php) (revision 11177) +++ branches/RC/core/units/general/helpers/themes_helper.php (.../themes_helper.php) (revision 11495) @@ -31,21 +31,34 @@ */ function refreshTheme($theme_name) { - if (!file_exists($this->themesFolder.'/'.$theme_name)) { + if (!file_exists($this->themesFolder . '/' . $theme_name)) { // requested theme was not found on hdd return false; } $id_field = $this->Application->getUnitOption('theme', 'IDField'); $table_name = $this->Application->getUnitOption('theme', 'TableName'); - $sql = 'SELECT '.$id_field.' - FROM '.$table_name.' - WHERE Name = '.$this->Conn->qstr($theme_name); - $theme_id = $this->Conn->GetOne($sql); + $sql = 'SELECT ' . $id_field . ', Enabled + FROM ' . $table_name . ' + WHERE Name = ' . $this->Conn->qstr($theme_name); + $theme_info = $this->Conn->GetRow($sql); + if ($theme_info) { + $theme_id = $theme_info[$id_field]; + $theme_enabled = $theme_info['Enabled']; + } + else { + $theme_id = $theme_enabled = false; + } + $this->themeFiles = Array (); if ($theme_id) { + if (!$theme_enabled) { + // don't process existing theme files, that are disabled + return $theme_id; + } + // reset found mark for every themes file (if theme is not new) $sql = 'UPDATE '.TABLE_PREFIX.'ThemeFiles SET FileFound = 0 @@ -61,15 +74,21 @@ 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 - ); + 'Name' => $theme_name, + 'Enabled' => 0, + 'Description' => $theme_name, + 'PrimaryTheme' => 0, + 'CacheTimeout' => 3600, // not in use right now + 'StylesheetId' => 0, // not in use right now + ); + $this->Conn->doInsert($fields_hash, $table_name); $theme_id = $this->Conn->getInsertID(); + + if (!$theme_enabled) { + // don't process newly created theme files, because they are disabled + return $theme_id; + } } $theme_path = $this->themesFolder.'/'.$theme_name; @@ -90,23 +109,24 @@ * @param string $theme_path theme path from web server root * @param int $theme_id id of theme we are scanning */ - function FindThemeFiles($folder_path, $theme_path, $theme_id, $auto_structure_mode=1) + function FindThemeFiles($folder_path, $theme_path, $theme_id, $auto_structure_mode = 1) { $fh = opendir($theme_path.$folder_path.'/'); - if (file_exists($theme_path.$folder_path.'/'.'.smsignore')) { - $ignore = file($theme_path.$folder_path.'/'.'.smsignore'); + // always ingore design and element templates + $ignore = Array ('^CVS$', '^\.svn$', '\.des\.tpl$', '\.elm\.tpl$'); + + $sms_ingore = $theme_path . $folder_path . '/.smsignore'; + + if (file_exists($sms_ingore)) { + $ignore = array_merge($ignore, file($sms_ingore)); } - else { - $ignore = array(); - } while (($filename = readdir($fh))) { if ($filename == '.' || $filename == '..') continue; $auto_structure = $auto_structure_mode; - foreach ($ignore as $pattern) - { + foreach ($ignore as $pattern) { if (preg_match('/'.str_replace('/', '\\/', trim($pattern)).'/', $filename)) { $auto_structure = 2; break; @@ -211,6 +231,41 @@ WHERE '.$id_field.' IN ('.implode(',', $theme_ids).')'; $this->Conn->Query($sql); } + + /** + * Returns current theme (also works in admin) + * + * @return int + */ + function getCurrentThemeId() + { + static $theme_id = null; + + if (isset($theme_id)) { + return $theme_id; + } + + if ($this->Application->IsAdmin()) { + // get theme, that user selected in catalog + $theme_id = $this->Application->RecallVar('theme_id'); + + if ($theme_id === false) { + // query, because "m_theme" is always empty in admin + $id_field = $this->Application->getUnitOption('theme', 'IDField'); + $table_name = $this->Application->getUnitOption('theme', 'TableName'); + + $sql = 'SELECT ' . $id_field . ' + FROM ' . $table_name . ' + WHERE (PrimaryTheme = 1) AND (Enabled = 1)'; + $theme_id = $this->Conn->GetOne($sql); + } + + return $theme_id; + } + + // use current theme, because it's available on Front-End + return $this->Application->GetVar('m_theme'); + } }