/** * Compress style styleSheet * @param str $inputFile * @param str $outputFile * @todo Make it easier to read and upgrade * @return boolean */ public static function styleSheet($inputFile, $outputFile) { if (JFile::exists($inputFile) && (!is_file($outputFile) || filemtime($inputFile) > filemtime($outputFile))) { $content = file_get_contents($inputFile); $content = CssMinifier::minify($content); return JFile::write($outputFile, $content); } return false; }
/** * * @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)); }