diff --git a/classes/frontendfile/FrontEndFileHandler.class.php b/classes/frontendfile/FrontEndFileHandler.class.php index 3b07eafd1..670579a9f 100644 --- a/classes/frontendfile/FrontEndFileHandler.class.php +++ b/classes/frontendfile/FrontEndFileHandler.class.php @@ -298,11 +298,47 @@ class FrontEndFileHandler extends Handler $compiledFileName = $file->fileName . ($minify ? '.min' : '') . '.css'; $compiledFileHash = sha1($file->fileRealPath . ':' . serialize($file->vars)); $compiledFilePath = \RX_BASEDIR . self::$assetdir . '/compiled/' . $compiledFileHash . '.' . $compiledFileName; + + $importedFileName = $file->fileName . ($minify ? '.min' : '') . '.imports.php'; + $importedFilePath = \RX_BASEDIR . self::$assetdir . '/compiled/' . $compiledFileHash . '.' . $importedFileName; - if (!file_exists($compiledFilePath) || filemtime($compiledFilePath) < filemtime($file->fileFullPath)) + if (!file_exists($compiledFilePath)) + { + $recompile = 1; + } + else + { + $compiledTime = filemtime($compiledFilePath); + if ($compiledTime < filemtime($file->fileFullPath)) + { + $recompile = 2; + } + else + { + $checklist = Rhymix\Framework\Storage::readPHPData($importedFilePath); + if (is_array($checklist)) + { + $recompile = 0; + foreach ($checklist as $filename) + { + if (!file_exists($filename) || filemtime($filename) > $compiledTime) + { + $recompile = 3; + break; + } + } + } + else + { + $recompile = 4; + } + } + } + + if ($recompile) { $method_name = 'compile' . $file->fileExtension; - $success = Rhymix\Framework\Formatter::$method_name($file->fileFullPath, $compiledFilePath, $file->vars, $minify); + Rhymix\Framework\Formatter::$method_name($file->fileFullPath, $compiledFilePath, $file->vars, $minify); } $file->fileName = $compiledFileHash . '.' . $compiledFileName; diff --git a/common/framework/formatter.php b/common/framework/formatter.php index 010532f7c..bdd65b102 100644 --- a/common/framework/formatter.php +++ b/common/framework/formatter.php @@ -179,7 +179,8 @@ class Formatter public static function compileLESS($source_filename, $target_filename, $variables = array(), $minify = false) { // Get the cleaned and concatenated content. - $content = self::concatCSS($source_filename, $target_filename); + $imported_list = []; + $content = self::concatCSS($source_filename, $target_filename, true, $imported_list); // Compile! try @@ -206,6 +207,11 @@ class Formatter // Save the result to the target file. Storage::write($target_filename, $content); + + // Save the list of imported files. + Storage::writePHPData(preg_replace('/\.css$/', '.imports.php', $target_filename), $imported_list, null, false); + + // Also return the compiled CSS content. return $result; } @@ -221,7 +227,8 @@ class Formatter public static function compileSCSS($source_filename, $target_filename, $variables = array(), $minify = false) { // Get the cleaned and concatenated content. - $content = self::concatCSS($source_filename, $target_filename); + $imported_list = []; + $content = self::concatCSS($source_filename, $target_filename, true, $imported_list); // Compile! try @@ -248,6 +255,11 @@ class Formatter // Save the result to the target file. Storage::write($target_filename, $content); + + // Save the list of imported files. + Storage::writePHPData(preg_replace('/\.css$/', '.imports.php', $target_filename), $imported_list, null, false); + + // Also return the compiled CSS content. return $result; } @@ -311,9 +323,10 @@ class Formatter * @param string|array $source_filename * @param string $target_filename * @param bool $add_comment + * @param array &$imported_list * @return string */ - public static function concatCSS($source_filename, $target_filename, $add_comment = true) + public static function concatCSS($source_filename, $target_filename, $add_comment = true, &$imported_list = []) { $result = ''; @@ -339,7 +352,7 @@ class Formatter // Convert all paths in LESS and SCSS imports, too. $import_type = ends_with('.scss', $filename) ? 'scss' : 'normal'; - $content = preg_replace_callback('/@import\s+(?:\\([^()]+\\))?([^;]+);/', function($matches) use($filename, $target_filename, $import_type) { + $content = preg_replace_callback('/@import\s+(?:\\([^()]+\\))?([^;]+);/', function($matches) use($filename, $target_filename, $import_type, &$imported_list) { $import_content = ''; $import_files = array_map(function($str) use($filename, $import_type) { $str = trim(trim(trim(preg_replace('/^url\\(([^()]+)\\)$/', '$1', trim($str))), '"\'')); @@ -377,7 +390,8 @@ class Formatter { if (!preg_match('!^(https?:)?//!i', $import_filename) && file_exists($import_filename)) { - $import_content .= self::concatCSS($import_filename, $target_filename, false); + $imported_list[] = $import_filename; + $import_content .= self::concatCSS($import_filename, $target_filename, false, $imported_list); } else {