public static function fixCssUrl($style, $currentPath, $oldPath) { self::$_currentCssPath = $currentPath; self::$_oldCssPath = $oldPath; $pattern = '#url\\([\'"]?([^\'"]+)[\'"]?\\)#'; $style = preg_replace_callback($pattern, array('self', 'replaceCssUrl'), $style); // fix import url /* if (strpos($oldPath, '.less') !== false) { $importPattern = '#@import [\'"]+([0-9a-zA-Z/.-]+)[\'"]+#'; $style = preg_replace_callback($importPattern, array('self', 'replaceCssImportUrl'), $style); } */ return $style; }
/** * * @return string */ private function _generateStylesheets() { $combineCss = Zo2Framework::getParam('combine_css', 0); $developmentMode = Zo2Framework::getParam('development_mode', 0); $cssHtml = array(); /** * Only do combine when asked and not in development mode */ if ($combineCss == 1 && $developmentMode == 0) { $cssName = 'cache/zo2_' . md5(serialize($this->_stylesheets)) . '.css'; $cssFilePath = JPATH_ROOT . '/' . $cssName; $cssUri = rtrim(JUri::root(true), '/') . '/' . $cssName; $cssContent = array(); foreach ($this->_stylesheets as $styleSheets => $path) { /* Do not combine vendor stylesheets */ if (strpos($path, 'vendor') !== false) { $cssHtml[] = '<link rel="stylesheet" href="' . Zo2Path::getInstance()->toUrl($styleSheets) . '">'; } else { /* Combine Zo2 stylesheets */ /* Optimize ouput css content */ if (Zo2Framework::getParam('optimzie_css', 0) == 1) { $currentCssContent = CssMinifier::minify(file_get_contents($path)); } else { $currentCssContent = file_get_contents($path); } $currentCssContent = Zo2HelperAssets::fixCssUrl($currentCssContent, $cssUri, '/' . $styleSheets); $cssContent[] = $currentCssContent; } } $cssContent = implode(PHP_EOL, $cssContent); $cssContent = Zo2HelperAssets::moveCssImportToBeginning($cssContent); /* Save to combined css file */ file_put_contents($cssFilePath, $cssContent); $cssHtml[] = '<link rel="stylesheet" href="' . $cssUri . '"></script>'; } else { foreach ($this->_stylesheets as $styleSheets => $path) { $cssHtml[] = '<link rel="stylesheet" href="' . Zo2Path::getInstance()->toUrl($styleSheets) . '">'; } } /* Custom stylesheets */ $cssDeclarationHtml[] = '<style>'; foreach ($this->_stylesheetDeclarations as $stylesheetDeclaration) { if (Zo2Framework::getParam('optimzie_css', 0) == 1 && $developmentMode == 0) { $cssDeclarationHtml[] = CssMinifier::minify($stylesheetDeclaration) . PHP_EOL; } else { $cssDeclarationHtml[] = $stylesheetDeclaration . PHP_EOL; } } $cssDeclarationHtml[] = '</style>'; return trim(implode(PHP_EOL, $cssHtml) . PHP_EOL . implode(PHP_EOL, $cssDeclarationHtml)); }