Index: branches/RC/core/install/install_schema.sql =================================================================== diff -u -N -r11635 -r11646 --- branches/RC/core/install/install_schema.sql (.../install_schema.sql) (revision 11635) +++ branches/RC/core/install/install_schema.sql (.../install_schema.sql) (revision 11646) @@ -295,6 +295,7 @@ Description varchar(255) default NULL, FileType int(11) NOT NULL default '0', FileFound tinyint(3) unsigned NOT NULL default '0', + FileMetaInfo text, PRIMARY KEY (FileId), KEY theme (ThemeId), KEY FileName (FileName), Index: branches/RC/core/install/upgrades.sql =================================================================== diff -u -N -r11641 -r11646 --- branches/RC/core/install/upgrades.sql (.../upgrades.sql) (revision 11641) +++ branches/RC/core/install/upgrades.sql (.../upgrades.sql) (revision 11646) @@ -1308,5 +1308,7 @@ DROP TABLE SuggestMail; +ALTER TABLE ThemeFiles ADD FileMetaInfo TEXT NULL; + DELETE FROM Modules WHERE Name = 'Proj-Base'; UPDATE Modules SET Version = '5.0.0', Loaded = 1 WHERE Name = 'In-Portal'; \ No newline at end of file Index: branches/RC/core/units/categories/categories_config.php =================================================================== diff -u -N -r11612 -r11646 --- branches/RC/core/units/categories/categories_config.php (.../categories_config.php) (revision 11612) +++ branches/RC/core/units/categories/categories_config.php (.../categories_config.php) (revision 11646) @@ -268,11 +268,13 @@ // fields from Pages 'Template' => Array ( 'type' => 'string', - 'formatter' => 'kOptionsFormatter', 'options_sql' => ' SELECT CONCAT(tf.Description, " (", TRIM(TRAILING ".des" FROM TRIM(TRAILING ".tpl" FROM FileName) ), ")") AS Title, - CONCAT(FilePath, "/", TRIM(TRAILING ".tpl" FROM FileName)) AS Value - FROM ' . TABLE_PREFIX . 'ThemeFiles AS tf - LEFT JOIN ' . TABLE_PREFIX . 'Theme AS t ON t.ThemeId = tf.ThemeId - WHERE (t.Enabled = 1) AND (tf.FileName NOT LIKE "%%.elm.tpl") AND (tf.FileName NOT LIKE "%%.des.tpl") AND (tf.FilePath = "/designs")', + 'formatter' => 'kOptionsFormatter', + 'options_sql' => ' SELECT CONCAT(tf.Description, " (", TRIM(TRAILING ".des" FROM TRIM(TRAILING ".tpl" FROM FileName) ), ")") AS Title, + CONCAT(FilePath, "/", TRIM(TRAILING ".tpl" FROM FileName)) AS Value + FROM ' . TABLE_PREFIX . 'ThemeFiles AS tf + LEFT JOIN ' . TABLE_PREFIX . 'Theme AS t ON t.ThemeId = tf.ThemeId + WHERE (t.Enabled = 1) AND (tf.FileName NOT LIKE "%%.elm.tpl") AND (tf.FileName NOT LIKE "%%.des.tpl") AND (tf.FilePath = "/designs") + ORDER BY tf.Description ASC, tf.FileName ASC', 'option_key_field' => 'Value', 'option_title_field' => 'Title', /*'required' => 1,*/ 'default' => null ), Index: branches/RC/core/units/general/helpers/themes_helper.php =================================================================== diff -u -N -r11495 -r11646 --- branches/RC/core/units/general/helpers/themes_helper.php (.../themes_helper.php) (revision 11495) +++ branches/RC/core/units/general/helpers/themes_helper.php (.../themes_helper.php) (revision 11646) @@ -10,6 +10,13 @@ var $themesFolder = ''; /** + * List of theme names, found on system + * + * @var Array + */ + var $_themeNames = Array (); + + /** * Temporary array when all theme files from db are stored * * @var Array @@ -91,6 +98,7 @@ } } + $this->_themeNames[$theme_id] = $theme_name; $theme_path = $this->themesFolder.'/'.$theme_name; $this->FindThemeFiles('', $theme_path, $theme_id); // search from base theme directory @@ -140,24 +148,33 @@ elseif (substr($filename, -4) == '.tpl') { $file_path = $folder_path.'/'.$filename; + $meta_info = $this->_getTemplateMetaInfo(trim($file_path, '/'), $theme_id); $file_id = isset($this->themeFiles[$file_path]) ? $this->themeFiles[$file_path] : false; + $file_description = array_key_exists('desc', $meta_info) ? $meta_info['desc'] : ''; + if ($file_id) { // file was found in db & on hdd -> mark as existing - $sql = 'UPDATE '.TABLE_PREFIX.'ThemeFiles - SET FileFound = 1, FileType = '.$auto_structure.' - WHERE FileId = '.$file_id; - $this->Conn->Query($sql); + $fields_hash = Array ( + 'FileFound' => 1, + 'Description' => $file_description, + 'FileType' => $auto_structure, + 'FileMetaInfo' => serialize($meta_info), + ); + + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'ThemeFiles', 'FileId = ' . $file_id); } else { // file was found on hdd, but missing in db -> create new file record - $fields_hash = Array ( - 'ThemeId' => $theme_id, - 'FileName' => $filename, - 'FilePath' => $folder_path, - 'Description' => '', - 'FileType' => $auto_structure, // 1 - built-in, 0 - custom (not in use right now), 2 - skipped in structure - 'FileFound' => 1, - ); + $fields_hash = Array ( + 'ThemeId' => $theme_id, + 'FileName' => $filename, + 'FilePath' => $folder_path, + 'Description' => $file_description, + 'FileType' => $auto_structure, // 1 - built-in, 0 - custom (not in use right now), 2 - skipped in structure + 'FileMetaInfo' => serialize($meta_info), + 'FileFound' => 1, + ); + $this->Conn->doInsert($fields_hash, TABLE_PREFIX.'ThemeFiles'); $this->themeFiles[$file_path] = $this->Conn->getInsertID(); } @@ -168,6 +185,64 @@ } /** + * Returns template information (name, description, path) from it's header comment + * + * @param string $template + * @param int $theme_id + * @return Array + */ + function _getTemplateMetaInfo($template, $theme_id) + { + if (!defined('DBG_NPARSER_FORCE_COMPILE')) { + $this->Application->InitParser(); + define('DBG_NPARSER_FORCE_COMPILE', 1); + } + + $template = 'theme:' . $this->_themeNames[$theme_id] . '/' . $template; + $template_file = $this->Application->TemplatesCache->GetRealFilename($template); // ".tpl" was added before + + if (!file_exists($template_file)) { + // when template without info it's placed in top category + return Array (); + } + + $template_data = file_get_contents($template_file); + + if (substr($template_data, 0, 6) == '*/ + + $comment_end = strpos($template_data, '##-->'); + if ($comment_end === false) { + // badly formatted comment + return Array (); + } + + $comment = trim( substr($template_data, 6, $comment_end - 6) ); + if (preg_match_all('/<(NAME|DESC|SECTION)>(.*?)<\/(NAME|DESC|SECTION)>/is', $comment, $regs)) { + $ret = Array (); + foreach ($regs[1] as $param_order => $param_name) { + $ret[ strtolower($param_name) ] = trim($regs[2][$param_order]); + } + + if (array_key_exists('section', $ret) && $ret['section']) { + $category_path = explode('||', $ret['section']); + $category_path = array_map('trim', $category_path); + $ret['section'] = implode('||', $category_path); + } + + return $ret; + } + } + + return Array (); + } + + /** * Updates file system changes to database for all themes (including new ones) * */ Index: branches/RC/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -r11635 -r11646 --- branches/RC/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 11635) +++ branches/RC/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 11646) @@ -1333,7 +1333,7 @@ * @param StructureItem $object * @param string $template */ - function _prepareAutoPage(&$object, $template, $theme_id = null, $system_mode = SMS_MODE_AUTO, $theme_file_id = null) + function _prepareAutoPage(&$object, $template, $theme_id = null, $system_mode = SMS_MODE_AUTO, $template_info = Array ()) { $template = $this->_stripTemplateExtension($template); @@ -1368,7 +1368,6 @@ if ($system) { $design_template = strtolower($template); // leading "/" not added ! - $template_info = $this->_getTemplateInfo($design_template, $theme_id, $theme_file_id); if ($template_info) { if (array_key_exists('name', $template_info) && $template_info['name']) { $page_name = $template_info['name']; @@ -1488,77 +1487,6 @@ } /** - * Returns template information (name, description, path) from it's header comment - * - * @param string $template - * @param int $theme_id - * @return Array - */ - function _getTemplateInfo($template, $theme_id = null, $theme_file_id = null) - { - if (!defined('DBG_NPARSER_FORCE_COMPILE')) { - $this->Application->InitParser(); - define('DBG_NPARSER_FORCE_COMPILE', 1); - } - - if (!isset($theme_id)) { - $theme_id = $this->_getCurrentThemeId(); - } - - $template = 'theme:' . $this->_getThemeName($theme_id) . '/' . $template; - $template_file = $this->Application->TemplatesCache->GetRealFilename($template) . '.tpl'; - - if (!file_exists($template_file)) { - // when template without info it's placed in top category - return Array (); - } - - $template_data = file_get_contents($template_file); - - if (substr($template_data, 0, 6) == '*/ - - $comment_end = strpos($template_data, '##-->'); - if ($comment_end === false) { - // badly formatted comment - return Array (); - } - - $comment = trim( substr($template_data, 6, $comment_end - 6) ); - if (preg_match_all('/<(NAME|DESC|SECTION)>(.*?)<\/(NAME|DESC|SECTION)>/is', $comment, $regs)) { - $ret = Array (); - foreach ($regs[1] as $param_order => $param_name) { - $ret[ strtolower($param_name) ] = trim($regs[2][$param_order]); - } - - if (array_key_exists('section', $ret) && $ret['section']) { - $category_path = explode('||', $ret['section']); - $category_path = array_map('trim', $category_path); - $ret['section'] = implode('||', $category_path); - } - - if (isset($theme_file_id) && array_key_exists('desc', $ret)) { - // copy description from template to if's file record in ThemeFiles table - $fields_hash = Array ( - 'Description' => $ret['desc'], - ); - - $this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'ThemeFiles', 'FileId = ' . $theme_file_id); - } - - return $ret; - } - } - - return Array (); - } - - /** * Returns theme name by it's id. Used in structure page creation. * * @param int $theme_id @@ -1652,8 +1580,7 @@ $design_folders = array_unique($design_folders); $design_sql = $fields['Template']['options_sql']; - $design_sql = str_replace('(tf.FilePath = "/designs")', '(' . implode(' OR ', $design_folders) . ')', $design_sql); - $design_sql .= ' AND (t.ThemeId = ' . $theme_id . ')'; + $design_sql = str_replace('(tf.FilePath = "/designs")', '(' . implode(' OR ', $design_folders) . ')' . ' AND (t.ThemeId = ' . $theme_id . ')', $design_sql); $fields['Template']['options_sql'] = $design_sql; $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); @@ -1801,7 +1728,7 @@ */ function OnAfterRebuildThemes(&$event) { - $sql = 'SELECT t.ThemeId, CONCAT( tf.FilePath, \'/\', tf.FileName ) AS Path, tf.FileId + $sql = 'SELECT t.ThemeId, CONCAT( tf.FilePath, \'/\', tf.FileName ) AS Path, tf.FileMetaInfo FROM '.TABLE_PREFIX.'ThemeFiles AS tf LEFT JOIN '.TABLE_PREFIX.'Theme AS t ON t.ThemeId = tf.ThemeId WHERE t.Enabled = 1 AND tf.FileType = 1 @@ -1821,7 +1748,7 @@ $error_count = 0; foreach ($files as $a_file => $file_info) { - $status = $this->_prepareAutoPage($dummy, $a_file, $file_info['ThemeId'], SMS_MODE_FORCE, $file_info['FileId']); // create system page + $status = $this->_prepareAutoPage($dummy, $a_file, $file_info['ThemeId'], SMS_MODE_FORCE, unserialize($file_info['FileMetaInfo'])); // create system page if (!$status) { $error_count++; } Index: branches/RC/core/units/theme_files/theme_files_config.php =================================================================== diff -u -N -r8929 -r11646 --- branches/RC/core/units/theme_files/theme_files_config.php (.../theme_files_config.php) (revision 8929) +++ branches/RC/core/units/theme_files/theme_files_config.php (.../theme_files_config.php) (revision 11646) @@ -7,34 +7,34 @@ 'EventHandlerClass' => Array('class' => 'kDBEventHandler', 'file' => '', 'build_event'=>'OnBuild'), 'TagProcessorClass' => Array('class' => 'kDBTagProcessor', 'file' => '', 'build_event'=>'OnBuild'), 'AutoLoad' => true, - + 'QueryString' => Array( 1 => 'id', 2 => 'page', 3 => 'event', ), - + 'IDField' => 'FileId', 'TitleField' => 'FileName', - + 'TableName' => TABLE_PREFIX.'ThemeFiles', 'ForeignKey' => 'ThemeId', 'ParentTableKey' => 'ThemeId', 'ParentPrefix' => 'theme', 'AutoDelete' => true, 'AutoClone' => true, - + 'ListSQLs' => Array( '' => 'SELECT %1$s.* %2$s FROM %s'), 'ItemSQLs' => Array( '' => 'SELECT %1$s.* %2$s FROM %s'), - + 'ListSortings' => Array ( '' => Array( 'Sorting' => Array('FileName' => 'asc'), ) ), - + 'Fields' => Array( 'FileId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), 'ThemeId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), @@ -43,6 +43,7 @@ 'Description' => Array ('type' => 'string', 'max_len' => 255, 'default' => NULL), 'FileType' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), 'FileFound' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), + 'FileMetaInfo' => Array ('type' => 'string', 'default' => NULL), ), 'Grids' => Array (