Index: kernel/nparser/compiler.php
===================================================================
--- kernel/nparser/compiler.php (revision 14653)
+++ kernel/nparser/compiler.php (working copy)
@@ -22,18 +22,22 @@
function CompileTemplatesStep()
{
$templates = $this->Application->RecallVar('templates_to_compile');
- if (!$templates) {
+ if ( !$templates ) {
// build $templates
$templates = $this->FindTemplates();
}
else {
$templates = unserialize($templates);
}
+
$total = count($templates);
$current = $this->Application->RecallVar('current_template_to_compile');
- if (!$current) $current = 0;
+ if ( !$current ) {
+ $current = 0;
+ }
- if ($errors = $this->Application->RecallVar('compile_errors')) {
+ $errors = $this->Application->RecallVar('compile_errors');
+ if ( $errors ) {
$this->Errors = unserialize($errors);
}
@@ -41,13 +45,13 @@
$i = $current;
$this->Application->InitParser(true);
- while ($i < $total && $i < ($current + 20)) {
+
+ while ( $i < $total && $i < ($current + 20) ) {
$a_template = $templates[$i];
try {
$this->Application->Parser->CheckTemplate($a_template['module'] . '/' . $a_template['path']);
- }
- catch (ParserException $e) {
+ } catch ( ParserException $e ) {
$this->Errors[] = Array ('msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine());
}
@@ -59,11 +63,12 @@
$this->Application->StoreVar('compile_errors', serialize($this->Errors));
$res = floor(($current / $total) * 100);
- if ($res == 100 || $current >= $total) {
+ if ( $res == 100 || $current >= $total ) {
$this->Application->RemoveVar('templates_to_compile');
$this->Application->RemoveVar('current_template_to_compile');
$this->Application->Redirect($this->Application->GetVar('finish_template'));
}
+
echo $res;
}
@@ -102,24 +107,34 @@
return $this->Templates;
}
- function FindTemplateFiles($folderPath, $options)
+ /**
+ * Recursively collects all TPL file across whole installation
+ *
+ * @param string $folder_path
+ * @param Array $options
+ * @return void
+ */
+ function FindTemplateFiles($folder_path, $options)
{
// if FULL_PATH = "/" ensure, that all "/" in $folderPath are not deleted
- $reg_exp = '/^'.preg_quote(FULL_PATH, '/').'/';
- $folderPath = preg_replace($reg_exp, '', $folderPath, 1); // this make sense, since $folderPath may NOT contain FULL_PATH
+ $reg_exp = '/^' . preg_quote(FULL_PATH, '/') . '/';
+ $folder_path = preg_replace($reg_exp, '', $folder_path, 1); // this make sense, since $folderPath may NOT contain FULL_PATH
- $fh = opendir(FULL_PATH.$folderPath);
- while (($sub_folder = readdir($fh))) {
- $full_path = FULL_PATH.$folderPath.'/'.$sub_folder;
- $base_name = basename($full_path);
- if (is_dir($full_path) && $base_name != '.' && $base_name != '..') {
+ $iterator = new DirectoryIterator(FULL_PATH . $folder_path);
+ /* @var $file_info DirectoryIterator */
+
+ foreach ($iterator as $file_info) {
+ $filename = $file_info->getFilename();
+ $full_path = $file_info->getPathname();
+
+ if ( $file_info->isDir() && !$file_info->isDot() && $filename != '.svn' && $filename != 'CVS' ) {
$this->FindTemplateFiles($full_path, $options);
}
- else {
- $info = pathinfo($full_path);
- if (isset($info['extension']) && $info['extension'] == 'tpl') {
- $this->Templates[] = array('module' => mb_strtolower($options['Name']), 'path' => str_replace(FULL_PATH . $options['Path'] . '/', '', preg_replace('/\.tpl$/', '', $full_path)));
- }
+ elseif ( pathinfo($full_path, PATHINFO_EXTENSION) == 'tpl' ) {
+ $this->Templates[] = Array (
+ 'module' => mb_strtolower( $options['Name'] ),
+ 'path' => str_replace(FULL_PATH . $options['Path'] . '/', '', preg_replace('/\.tpl$/', '', $full_path))
+ );
}
}
}
Index: units/helpers/themes_helper.php
===================================================================
--- units/helpers/themes_helper.php (revision 14653)
+++ units/helpers/themes_helper.php (working copy)
@@ -266,38 +266,24 @@
* @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
+ * @param int $auto_structure_mode
*/
function FindThemeFiles($folder_path, $theme_path, $theme_id, $auto_structure_mode = 1)
{
- $fh = opendir($theme_path.$folder_path.'/');
+ $ignore_regexp = $this->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 . '/';
}
/**