Index: branches/5.2.x/core/units/helpers/themes_helper.php
===================================================================
diff -u -r14628 -r14698
--- branches/5.2.x/core/units/helpers/themes_helper.php (.../themes_helper.php) (revision 14628)
+++ branches/5.2.x/core/units/helpers/themes_helper.php (.../themes_helper.php) (revision 14698)
@@ -1,6 +1,6 @@
getIgnoreRegexp($theme_path . $folder_path);
- // always ingore design and element templates
- $ignore = Array ('^CVS$', '^\.svn$', '\.des\.tpl$', '\.elm\.tpl$');
+ $iterator = new DirectoryIterator($theme_path . $folder_path . '/');
+ /* @var $file_info DirectoryIterator */
- $sms_ingore = $theme_path . $folder_path . '/.smsignore';
+ foreach ($iterator as $file_info) {
+ $filename = $file_info->getFilename();
+ $auto_structure = preg_match($ignore_regexp, $filename) ? 2 : $auto_structure_mode;
+ $file_path = $folder_path . '/' . $filename; // don't pass path to theme top folder!
- if (file_exists($sms_ingore)) {
- $ignore = array_merge($ignore, file($sms_ingore));
- }
-
- while (($filename = readdir($fh))) {
- if ($filename == '.' || $filename == '..') continue;
-
- $auto_structure = $auto_structure_mode;
- foreach ($ignore as $pattern) {
- if (preg_match('/'.str_replace('/', '\\/', trim($pattern)).'/', $filename)) {
- $auto_structure = 2;
- break;
- }
+ if ( $file_info->isDir() && !$file_info->isDot() && $filename != 'CVS' && $filename != '.svn' ) {
+ $this->FindThemeFiles($file_path, $theme_path, $theme_id, $auto_structure);
}
-
- $full_path = $theme_path.$folder_path.'/'.$filename;
- if (is_dir($full_path)) {
- $this->FindThemeFiles($folder_path.'/'.$filename, $theme_path, $theme_id, $auto_structure);
- }
- elseif (substr($filename, -4) == '.tpl') {
- $file_path = $folder_path.'/'.$filename;
-
+ elseif ( pathinfo($filename, PATHINFO_EXTENSION) == 'tpl' ) {
$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'] : '';
@@ -330,8 +316,30 @@
}
// echo 'FilePath: ['.$folder_path.']; FileName: ['.$filename.']; IsNew: ['.($file_id > 0 ? 'NO' : 'YES').']
';
}
+ }
+ }
+ /**
+ * Returns single regular expression to match all ignore patters, that are valid for given folder
+ *
+ * @param string $folder_path
+ * @return string
+ */
+ protected function getIgnoreRegexp($folder_path)
+ {
+ // always ignore design and element templates
+ $ignore = '\.des\.tpl$|\.elm\.tpl$';
+ $sms_ignore_file = $folder_path . '/.smsignore';
+
+ if ( file_exists($sms_ignore_file) ) {
+ $manual_patterns = array_map('trim', file($sms_ignore_file));
+
+ foreach ($manual_patterns as $manual_pattern) {
+ $ignore .= '|' . str_replace('/', '\\/', $manual_pattern);
+ }
}
+
+ return '/' . $ignore . '/';
}
/**