From 3ae2058f6f7c8115481b476562b6ca146e500b2b Mon Sep 17 00:00:00 2001 From: Molkobain Date: Fri, 24 Jan 2020 16:05:01 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B02314=20-=20Markup=20extensibility:=20Ref?= =?UTF-8?q?actor=20utils::GetCSSFromSASS()=20to=20enable=20SCSS=20compilat?= =?UTF-8?q?ion=20out=20of=20a=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/themehandler.class.inc.php | 13 +-------- application/utils.inc.php | 40 ++++++++++++++++++++------ 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/application/themehandler.class.inc.php b/application/themehandler.class.inc.php index cde81ea02..dc9de8e5b 100644 --- a/application/themehandler.class.inc.php +++ b/application/themehandler.class.inc.php @@ -109,18 +109,7 @@ class ThemeHandler // Checking if our compiled css is outdated if (!file_exists($sThemeCssPath) || (is_writable($sThemeFolderPath) && (@filemtime($sThemeCssPath) < $iStyleLastModified))) { - $oScss = new Compiler(); - $oScss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\Expanded'); - // Setting our xml variables - $oScss->setVariables($aThemeParameters['variables']); - // Setting our imports paths - $oScss->setImportPaths($aImportsPaths); - // Temporary disabling max exec time while compiling - $iCurrentMaxExecTime = (int)ini_get('max_execution_time'); - set_time_limit(0); - // Compiling our theme - $sTmpThemeCssContent = $oScss->compile($sTmpThemeScssContent); - set_time_limit($iCurrentMaxExecTime); + $sTmpThemeCssContent = utils::CompileCSSFromSASS($sTmpThemeScssContent, $aImportsPaths, $aThemeParameters['variables']); file_put_contents($sThemeCssPath, $sTmpThemeCssContent); } } diff --git a/application/utils.inc.php b/application/utils.inc.php index c6d466e04..2f16eabbb 100644 --- a/application/utils.inc.php +++ b/application/utils.inc.php @@ -1,6 +1,6 @@ setImportPaths($aImportPaths); - $oScss->setFormatter('ScssPhp\\ScssPhp\\Formatter\\Expanded'); - // Temporary disabling max exec time while compiling - $iCurrentMaxExecTime = (int) ini_get('max_execution_time'); - set_time_limit(0); - $sCss = $oScss->compile(file_get_contents($sSassPath)); - set_time_limit($iCurrentMaxExecTime); + $sCss = static::CompileCSSFromSASS(file_get_contents($sSassPath), $aImportPaths); file_put_contents($sCssPath, $sCss); } return $sCssRelPath; } + + /** + * Return a string of CSS compiled from the $sSassContent + * + * @param string $sSassContent + * @param array $aImportPaths + * @param array $aVariables + * + * @return string + * + * @since 2.7.0 + */ + public static function CompileCSSFromSASS($sSassContent, $aImportPaths = array(), $aVariables = array()) + { + $oSass = new Compiler(); + $oSass->setFormatter('ScssPhp\\ScssPhp\\Formatter\\Expanded'); + // Setting our variables + $oSass->setVariables($aVariables); + // Setting our imports paths + $oSass->setImportPaths($aImportPaths); + // Temporary disabling max exec time while compiling + $iCurrentMaxExecTime = (int) ini_get('max_execution_time'); + set_time_limit(0); + // Compiling SASS + $sCss = $oSass->compile($sSassContent); + set_time_limit($iCurrentMaxExecTime); + + return $sCss; + } public static function GetImageSize($sImageData) {