Index: branches/unlabeled/unlabeled-1.1.2/core/units/general/helpers/themes_helper.php
===================================================================
diff -u
--- branches/unlabeled/unlabeled-1.1.2/core/units/general/helpers/themes_helper.php (revision 0)
+++ branches/unlabeled/unlabeled-1.1.2/core/units/general/helpers/themes_helper.php (revision 6859)
@@ -0,0 +1,192 @@
+themesFolder = FULL_PATH.'/themes';
+ }
+
+ /**
+ * Updates file system changes to database for selected theme
+ *
+ * @param string $theme_name
+ *
+ * @return mixed returns ID of created/used theme or false, if none created
+ */
+ function refreshTheme($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);
+
+ $this->themeFiles = Array ();
+ if ($theme_id) {
+ // reset found mark for every themes file (if theme is not new)
+ $sql = 'UPDATE '.TABLE_PREFIX.'ThemeFiles
+ SET FileFound = 0
+ WHERE ThemeId = '.$theme_id;
+ $this->Conn->Query($sql);
+
+ // get all theme files from db
+ $sql = 'SELECT FileId, CONCAT(FilePath, "/", FileName) AS FullPath
+ FROM '.TABLE_PREFIX.'ThemeFiles
+ WHERE ThemeId = '.$theme_id;
+ $this->themeFiles = $this->Conn->GetCol($sql, 'FullPath');
+ }
+ 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
+ );
+ $this->Conn->doInsert($fields_hash, $table_name);
+ $theme_id = $this->Conn->getInsertID();
+ }
+
+ $theme_path = $this->themesFolder.'/'.$theme_name;
+ $this->FindThemeFiles('', $theme_path, $theme_id); // search from base theme directory
+
+ // delete file records from db, that were not found on hdd
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'ThemeFiles
+ WHERE ThemeId = '.$theme_id.' AND FileFound = 0';
+ $this->Conn->Query($sql);
+
+ return $theme_id;
+ }
+
+ /**
+ * Searches for new templates (missing in db) in spefied folder
+ *
+ * @param string $folder_path subfolder of searchable theme
+ * @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)
+ {
+ $fh = opendir($theme_path.$folder_path.'/');
+
+ while (($filename = readdir($fh))) {
+ if ($filename == '.' || $filename == '..') continue;
+
+ $full_path = $theme_path.$folder_path.'/'.$filename;
+ if (is_dir($full_path)) {
+ $this->FindThemeFiles($folder_path.'/'.$filename, $theme_path, $theme_id);
+ }
+ elseif (substr($filename, -4) == '.tpl') {
+ $file_path = $folder_path.'/'.$filename;
+
+ $file_id = isset($this->themeFiles[$file_path]) ? $this->themeFiles[$file_path] : false;
+ if ($file_id) {
+ // file was found in db & on hdd -> mark as existing
+ $sql = 'UPDATE '.TABLE_PREFIX.'ThemeFiles
+ SET FileFound = 1
+ WHERE FileId = '.$file_id;
+ $this->Conn->Query($sql);
+ }
+ 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' => 0, // 1 - built-in, 1 - custom (not in use right now)
+ 'FileFound' => 1,
+ );
+ $this->Conn->doInsert($fields_hash, TABLE_PREFIX.'ThemeFiles');
+ $this->themeFiles[$file_path] = $this->Conn->getInsertID();
+ }
+// echo 'FilePath: ['.$folder_path.']; FileName: ['.$filename.']; IsNew: ['.($file_id > 0 ? 'NO' : 'YES').']
';
+ }
+
+ }
+ }
+
+ /**
+ * Updates file system changes to database for all themes (including new ones)
+ *
+ */
+ function refreshThemes()
+ {
+ $themes_found = Array();
+
+ $fh = opendir($this->themesFolder.'/');
+ while (($filename = readdir($fh))) {
+ if ($filename == '.' || $filename == '..' || $filename == 'CVS') continue;
+
+ if (is_dir($this->themesFolder.'/'.$filename)) {
+ $theme_id = $this->refreshTheme($filename);
+ if ($theme_id) {
+ $themes_found[] = $theme_id;
+ }
+ }
+ }
+
+ $id_field = $this->Application->getUnitOption('theme', 'IDField');
+ $table_name = $this->Application->getUnitOption('theme', 'TableName');
+
+ // if none themes found -> delete all from db OR delete all except of found themes
+ $sql = 'SELECT '.$id_field.'
+ FROM '.$table_name;
+ if ($themes_found) {
+ $sql .= ' WHERE '.$id_field.' NOT IN ('.implode(',', $themes_found).')';
+ }
+ $theme_ids = $this->Conn->GetCol($sql);
+ $this->deleteThemes($theme_ids);
+ }
+
+ /**
+ * Deletes themes with ids passed from db
+ *
+ * @param Array $theme_ids
+ */
+ function deleteThemes($theme_ids)
+ {
+ if (!$theme_ids) {
+ return ;
+ }
+
+ $id_field = $this->Application->getUnitOption('theme', 'IDField');
+ $table_name = $this->Application->getUnitOption('theme', 'TableName');
+
+ $sql = 'DELETE FROM '.$table_name.'
+ WHERE '.$id_field.' IN ('.implode(',', $theme_ids).')';
+ $this->Conn->Query($sql);
+
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'ThemeFiles
+ WHERE '.$id_field.' IN ('.implode(',', $theme_ids).')';
+ $this->Conn->Query($sql);
+ }
+ }
+
+
+?>
\ No newline at end of file
Index: branches/unlabeled/unlabeled-1.6.2/core/install.php
===================================================================
diff -u -r6709 -r6859
--- branches/unlabeled/unlabeled-1.6.2/core/install.php (.../install.php) (revision 6709)
+++ branches/unlabeled/unlabeled-1.6.2/core/install.php (.../install.php) (revision 6859)
@@ -329,13 +329,20 @@
break;
case 'choose_modules':
+ // run module install scripts
$modules = $this->Application->GetVar('modules');
foreach ($modules as $module) {
$install_file = MODULES_PATH.'/'.$module.'/install.php';
if (file_exists($install_file)) {
include_once($install_file);
}
}
+
+ // scan themes
+ $themes_helper =& $this->Application->recallObject('ThemesHelper');
+ /* @var $themes_helper kThemesHelper */
+
+ $themes_helper->refreshThemes();
break;
}
Index: branches/unlabeled/unlabeled-1.3.2/core/units/general/helpers/helpers_config.php
===================================================================
diff -u -r6848 -r6859
--- branches/unlabeled/unlabeled-1.3.2/core/units/general/helpers/helpers_config.php (.../helpers_config.php) (revision 6848)
+++ branches/unlabeled/unlabeled-1.3.2/core/units/general/helpers/helpers_config.php (.../helpers_config.php) (revision 6859)
@@ -15,5 +15,6 @@
Array('pseudo'=>'FilenamesHelper','class'=>'kFilenamesHelper','file'=>'filenames_helper.php','build_event'=>'','require_classes'=>'kHelper'),
Array('pseudo'=>'ClipboardHelper','class'=>'kClipboardHelper','file'=>'clipboard_helper.php','build_event'=>'','require_classes'=>'kHelper'),
Array('pseudo'=>'ColumnPickerHelper','class'=>'kColumnPickerHelper','file'=>'col_picker_helper.php','build_event'=>'','require_classes'=>'kHelper'),
+ Array('pseudo'=>'ThemesHelper','class'=>'kThemesHelper','file'=>'themes_helper.php','build_event'=>'','require_classes'=>'kHelper'),
),
);
\ No newline at end of file
Index: branches/unlabeled/unlabeled-1.3.2/core/install/install_schema.sql
===================================================================
diff -u -r6787 -r6859
--- branches/unlabeled/unlabeled-1.3.2/core/install/install_schema.sql (.../install_schema.sql) (revision 6787)
+++ branches/unlabeled/unlabeled-1.3.2/core/install/install_schema.sql (.../install_schema.sql) (revision 6859)
@@ -1,3 +1,8 @@
+# Upgrade SQLs:
+#
+# ALTER TABLE ThemeFiles ADD FileFound TINYINT UNSIGNED NOT NULL DEFAULT '0';
+# ALTER TABLE ThemeFiles ADD INDEX (FileFound);
+
CREATE TABLE ConfigurationAdmin (
VariableName varchar(80) NOT NULL default '',
heading varchar(255) default NULL,
@@ -196,7 +201,7 @@
Description varchar(255) default NULL,
PrimaryTheme int(11) NOT NULL default '0',
CacheTimeout int(11) NOT NULL default '0',
- StylesheetId INTEGER(10) UNSIGNED NOT NULL DEFAULT '0',
+ StylesheetId int(10) unsigned NOT NULL default '0',
PRIMARY KEY (ThemeId)
);
@@ -207,10 +212,12 @@
FilePath varchar(255) NOT NULL default '',
Description varchar(255) default NULL,
FileType int(11) NOT NULL default '0',
+ FileFound tinyint(3) unsigned NOT NULL default '0',
PRIMARY KEY (FileId),
KEY theme (ThemeId),
KEY FileName (FileName),
- KEY FilePath (FilePath)
+ KEY FilePath (FilePath),
+ KEY FileFound (FileFound)
);
CREATE TABLE UserGroup (
@@ -356,4 +363,14 @@
KEY PermId (PermId)
);
+CREATE TABLE Stylesheets (
+ StylesheetId int(11) NOT NULL auto_increment,
+ Name varchar(255) NOT NULL default '',
+ Description varchar(255) NOT NULL default '',
+ AdvancedCSS text NOT NULL,
+ LastCompiled int(10) unsigned NOT NULL default '0',
+ Enabled int(11) NOT NULL default '0',
+ PRIMARY KEY (StylesheetId)
+);
+