From 4e45b56ea41cc9975adce873e31443ed4d6457c1 Mon Sep 17 00:00:00 2001 From: djmaze Date: Tue, 10 Aug 2021 10:31:53 +0200 Subject: [PATCH] Speedup templates compiler --- .../0.0.0/app/libraries/RainLoop/Service.php | 2 +- .../app/libraries/RainLoop/ServiceActions.php | 19 ++++----- .../v/0.0.0/app/libraries/RainLoop/Utils.php | 39 ------------------- 3 files changed, 11 insertions(+), 49 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php index 4eaa292f2..8036aced2 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php @@ -175,7 +175,7 @@ class Service } else { $aTemplateParameters['{{BaseAppThemeCss}}'] = $this->oActions->compileCss($this->oActions->GetTheme($bAdmin), $bAdmin); $aTemplateParameters['{{BaseLanguage}}'] = $this->oActions->compileLanguage($sLanguage, $bAdmin); - $aTemplateParameters['{{BaseTemplates}}'] = $this->oServiceActions->compileTemplates($bAdmin, false); + $aTemplateParameters['{{BaseTemplates}}'] = $this->oServiceActions->compileTemplates($bAdmin); $sResult = \strtr(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Index.html'), $aTemplateParameters); $sResult = Utils::ClearHtmlOutput($sResult); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php index 78d522d08..d644bccf4 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php @@ -878,26 +878,27 @@ class ServiceActions return $sResult; } - public function compileTemplates(bool $bAdmin = false, bool $bJsOutput = true) : string + public function compileTemplates(bool $bAdmin = false) : string { $aTemplates = array(); - Utils::CompileTemplates($aTemplates, APP_VERSION_ROOT_PATH.'app/templates/Views/Components', 'Component'); - Utils::CompileTemplates($aTemplates, APP_VERSION_ROOT_PATH.'app/templates/Views/'.($bAdmin ? 'Admin' : 'User')); - Utils::CompileTemplates($aTemplates, APP_VERSION_ROOT_PATH.'app/templates/Views/Common'); + foreach (['Components', ($bAdmin ? 'Admin' : 'User'), 'Common'] as $dir) { + $sNameSuffix = ('Components' === $dir) ? 'Component' : ''; + foreach (\glob(APP_VERSION_ROOT_PATH."app/templates/Views/{$dir}/*.html") as $file) { + $sTemplateName = \basename($file, '.html') . $sNameSuffix; + $aTemplates[$sTemplateName] = $file; + } + } $this->oActions->Plugins()->CompileTemplate($aTemplates, $bAdmin); $sHtml = ''; - foreach ($aTemplates as $sName => $sFile) - { + foreach ($aTemplates as $sName => $sFile) { $sName = \preg_replace('/[^a-zA-Z0-9]/', '', $sName); $sHtml .= ''; } - unset($aTemplates); - - return $bJsOutput ? 'rl.TEMPLATES='.\MailSo\Base\Utils::Php2js($sHtml, $this->Logger()).';' : $sHtml; + return $sHtml; } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Utils.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Utils.php index b5f507762..7b4b68bf1 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Utils.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Utils.php @@ -131,31 +131,6 @@ class Utils return $sResult; } - public static function FolderFiles(string $sDir, string $sType = '') : array - { - $aResult = array(); - if (\is_dir($sDir)) - { - if (false !== ($rDirHandle = \opendir($sDir))) - { - while (false !== ($sFile = \readdir($rDirHandle))) - { - if (empty($sType) || $sType === \substr($sFile, -\strlen($sType))) - { - if (\is_file($sDir.'/'.$sFile)) - { - $aResult[] = $sFile; - } - } - } - - \closedir($rDirHandle); - } - } - - return $aResult; - } - public static function ClearHtmlOutput(string $sHtml) : string { // return $sHtml; @@ -166,20 +141,6 @@ class Utils ); } - public static function CompileTemplates(array &$aList, string $sDirName, string $sNameSuffix = '') - { - if (\file_exists($sDirName)) - { - $aFileList = static::FolderFiles($sDirName, '.html'); - - foreach ($aFileList as $sName) - { - $sTemplateName = \substr($sName, 0, -5).$sNameSuffix; - $aList[$sTemplateName] = $sDirName.'/'.$sName; - } - } - } - /** * @param mixed $mDefault = null * @return mixed