Index: trunk/core/units/general/helpers/themes_helper.php
===================================================================
diff -u -N -r7391 -r7855
--- trunk/core/units/general/helpers/themes_helper.php (.../themes_helper.php) (revision 7391)
+++ trunk/core/units/general/helpers/themes_helper.php (.../themes_helper.php) (revision 7855)
@@ -1,32 +1,32 @@
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)
@@ -35,23 +35,23 @@
// 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
@@ -71,44 +71,60 @@
$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)
+ 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');
+ }
+ else {
+ $ignore = array();
+ }
+
while (($filename = readdir($fh))) {
if ($filename == '.' || $filename == '..') continue;
-
+
+ $auto_structure = $auto_structure_mode;
+ foreach ($ignore as $pattern)
+ {
+ if (preg_match('/'.str_replace('/', '\\/',$pattern).'/', $filename)) {
+ $auto_structure = 2;
+ break;
+ }
+ }
+
$full_path = $theme_path.$folder_path.'/'.$filename;
if (is_dir($full_path)) {
- $this->FindThemeFiles($folder_path.'/'.$filename, $theme_path, $theme_id);
+ $this->FindThemeFiles($folder_path.'/'.$filename, $theme_path, $theme_id, $auto_structure);
}
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
+ SET FileFound = 1, FileType = '.$auto_structure.'
WHERE FileId = '.$file_id;
$this->Conn->Query($sql);
}
@@ -119,41 +135,41 @@
'FileName' => $filename,
'FilePath' => $folder_path,
'Description' => '',
- 'FileType' => 0, // 1 - built-in, 1 - custom (not in use right now)
+ 'FileType' => $auto_structure, // 1 - built-in, 0 - custom (not in use right now), 2 - skipped in structure
'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;
@@ -162,8 +178,9 @@
}
$theme_ids = $this->Conn->GetCol($sql);
$this->deleteThemes($theme_ids);
+
}
-
+
/**
* Deletes themes with ids passed from db
*
@@ -174,14 +191,14 @@
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);