/** * Minify, combine and load site stylesheet */ public static function load() { $backend_site_css_path = MINIFY . DS . 'backend_site.minify.css'; $frontend_site_css_path = MINIFY . DS . 'frontend_site.minify.css'; // Load stylesheets if (count(Stylesheet::$stylesheets) > 0) { $backend_buffer = ''; $backend_regenerate = false; $frontend_buffer = ''; $frontend_regenerate = false; // Sort stylesheets by priority $stylesheets = Arr::subvalSort(Stylesheet::$stylesheets, 'priority'); if (BACKEND) { // Build backend site stylesheets foreach ($stylesheets as $stylesheet) { if (file_exists(ROOT . DS . $stylesheet['file']) and ($stylesheet['load'] == 'backend' or $stylesheet['load'] == 'both')) { if (!file_exists($backend_site_css_path) or filemtime(ROOT . DS . $stylesheet['file']) > filemtime($backend_site_css_path)) { $backend_regenerate = true; break; } } } // Regenerate site stylesheet if ($backend_regenerate) { foreach ($stylesheets as $stylesheet) { if (file_exists(ROOT . DS . $stylesheet['file']) and ($stylesheet['load'] == 'backend' or $stylesheet['load'] == 'both')) { $backend_buffer .= file_get_contents(ROOT . DS . $stylesheet['file']); } } $backend_buffer = Stylesheet::parseVariables($backend_buffer); file_put_contents($backend_site_css_path, MinifyCSS::process($backend_buffer)); $backend_regenerate = false; } } else { // Build frontend site stylesheets foreach ($stylesheets as $stylesheet) { if (file_exists(ROOT . DS . $stylesheet['file']) and ($stylesheet['load'] == 'frontend' or $stylesheet['load'] == 'both')) { if (!file_exists($frontend_site_css_path) or filemtime(ROOT . DS . $stylesheet['file']) > filemtime($frontend_site_css_path)) { $frontend_regenerate = true; break; } } } // Regenerate site stylesheet if ($frontend_regenerate) { foreach ($stylesheets as $stylesheet) { if (file_exists(ROOT . DS . $stylesheet['file']) and ($stylesheet['load'] == 'frontend' or $stylesheet['load'] == 'both')) { $frontend_buffer .= file_get_contents(ROOT . DS . $stylesheet['file']); } } $frontend_buffer = Stylesheet::parseVariables($frontend_buffer); file_put_contents($frontend_site_css_path, MinifyCSS::process($frontend_buffer)); $frontend_regenerate = false; } } // Render if (BACKEND) { echo '<link rel="stylesheet" href="' . Option::get('siteurl') . '/tmp/minify/backend_site.minify.css?' . Option::get('styles_version') . '" type="text/css" />'; } else { echo '<link rel="stylesheet" href="' . Option::get('siteurl') . '/tmp/minify/frontend_site.minify.css?' . Option::get('styles_version') . '" type="text/css" />' . "\n"; } } }
/** * Minify a CSS string * * @param string $css * * @param array $options (currently ignored) * * @return string */ public static function process($css, $options = array()) { $obj = new MinifyCSS($options); return $obj->_process($css); }
public function generateCSSFile() { /*if (!is_file(dirname(__FILE__).'/cache/stylesheet.php')) {*/ $css = $this->generateCSS(); include_once dirname(__FILE__) . '/classes/minify.php'; $minifyCCS = new MinifyCSS($css); $minifyCCS->minify(dirname(__FILE__) . '/cache/stylesheet.php', $stripComments = true, $stripWhitespace = true, $shortenHex = true, $combineImports = true, $importFiles = true); /*}*/ return DIR_WS_HTTP_CATALOG . DIR_WS_MODULES . 'checkout/cache/stylesheet.php'; }
/** * Minify a CSS-file * * @param string $file The file to be minified. * @return string */ private function minifyCSS($file) { // create unique filename $fileName = md5($file) . '.css'; $finalURL = FRONTEND_CACHE_URL . '/minified_css/' . $fileName; $finalPath = FRONTEND_CACHE_PATH . '/minified_css/' . $fileName; // check that file does not yet exist or has been updated already if (!SpoonFile::exists($finalPath) || filemtime(PATH_WWW . $file) > filemtime($finalPath)) { // create directory if it does not exist if (!SpoonDirectory::exists(dirname($finalPath))) { SpoonDirectory::create(dirname($finalPath)); } // minify the file require_once PATH_LIBRARY . '/external/minify.php'; $css = new MinifyCSS(PATH_WWW . $file); $css->minify($finalPath); } return $finalURL; }