public function postprocess(&$path, &$content) { if (!class_exists('CssMin')) { $dir = Templates_HTML_Postprocess::option('minify_php_dir'); require_once $dir . 'CssMin/CssMin.php'; } $m = new CssMinifier($content, $filters, $plugins); $content = $m->getMinified(); }
function GenerateStyle() { global $CSS_FILES, $CSS_OUT, $CSS_VARS; if (!OutOfDate($CSS_FILES, $CSS_OUT)) { return; } $css = MergeContents($CSS_FILES); foreach ($CSS_VARS as $key => $value) { $css = str_replace("[{$key}]", $value, $css); } $css = new \CssMinifier($css); file_put_contents($CSS_OUT, $css->getMinified()); }
public function postprocess($path, $data, $content = null) { if (!class_exists('CssMin')) { $dir = Templates_HTML_Assets_Postprocess_Minify::option('minify_php_dir'); require_once $dir . 'CssMin/CssMin.php'; } if ($this->filter($path, $data)) { if (empty($content)) { list($content, $path) = $this->load($path); } if (!empty($content)) { $m = new CssMinifier($content, $filters, $plugins); $content = $m->getMinified(); } } return array($path, $content); }
/** * Cssmin * * @param string $content * @return string * @throws Exception */ private static function cssmin($content) { if (is_string($content) === false) { throw new Exception('Style must be a string'); } if (empty($content) === true) { return $content; } require_once __DIR__ . '/CssMin/build/CssMin.php'; try { $minify = new \CssMinifier($content); return $minify->getMinified(); } catch (\Exception $e) { if (is_string($e) === true) { throw new Exception($e); } else { throw new Exception('Unknown error'); } } }
public static function minify($source, array $filters = null, array $plugins = null) { self::$errors = array(); $minifier = new CssMinifier($source, $filters, $plugins); return $minifier->getMinified(); }
private function get_css_html($cachefile) { if (false === file_exists($this->cachePath['css'] . '/' . $cachefile)) { // Get the content $file_content = ''; foreach ($this->libs['css'] as $lib) { $change = strstr($lib, 'http://'); if ($change != '') { $lib = str_replace('.css', '', $lib); $file_content .= "\n\n" . file_get_contents($lib); } else { $file_content .= "\n\n" . file_get_contents($this->basePath['css'] . '/' . $lib); } } // Get inline code if exist if (!empty($this->inline_code['css'])) { foreach ($this->inline_code['css'] as $inlineCss) { $file_content .= "\n\n" . $inlineCss; } } // If compression is enable, compress it ! if ($this->__options['css']['enableCompression']) { App::import('Vendor', 'cssmin', array('file' => 'cssmin' . DS . 'cssmin.php')); $css_minifier = new CssMinifier($file_content); // JossToDo - here we could implement filters and plugins, as per http://code.google.com/p/cssmin/wiki/Configuration $file_content = $css_minifier->getMinified(); } if ($fp = fopen($this->cachePath['css'] . '/' . $cachefile, 'wb')) { fwrite($fp, $file_content); fclose($fp); } } if (COMBINATOR_PATH != 'admin/') { return '<link href="' . $this->root_url('/' . COMBINATOR_PATH . $this->__options['css']['cachePath'] . '/' . $cachefile) . '" rel="stylesheet" type="text/css" >'; } else { return '<link href="' . $this->url('/' . $this->extraPath . $this->__options['css']['cachePath'] . '/' . $cachefile) . '" rel="stylesheet" type="text/css" >'; } }
/** * Minifies CSS source. * * @param string $source CSS source * @param array $filters Filter configuration [optional] * @param array $plugins Plugin configuration [optional] * @return string Minified CSS */ public static function minify($source, array $filters = null, array $plugins = null, $string = true) { self::$errors = array(); $minifier = new CssMinifier($source, $filters, $plugins); return $string ? $minifier->getMinified() : $minifier->getTokens(); }
/** * Выполняет сжатие * * @return mixed|void */ public function compress() { $oCssMinifier = new CssMinifier($this->getContent()); $this->setContent($oCssMinifier->getMinified()); }
private function get_css_html($cachefile) { if (false === file_exists($this->cachePath['css'] . '/' . $cachefile)) { // Get the content $file_content = ''; foreach ($this->libs['css'] as $lib) { if (preg_match('/http\\:\\/\\//', $lib) || strpos($lib, '//') === 0) { if (strpos($lib, '//') === 0) { $lib = 'http:' . $lib; } $file_content .= "\n\n" . file_get_contents($lib); } else { $tfile = str_replace('.css', '', $lib); $partials = preg_split('/\\./', $tfile, -1, PREG_SPLIT_NO_EMPTY); if (count($partials) > 1) { $path = APP . 'Plugin' . DS . array_shift($partials) . DS . 'webroot' . DS . 'css' . DS . implode('.', $partials) . '.css'; if (file_exists($path)) { $file_content .= "\n\n" . file_get_contents($path); } } else { $file_content .= "\n\n" . file_get_contents($this->basePath['css'] . '/' . $lib); } } } // Get inline code if exist if (!empty($this->inline_code['css'])) { foreach ($this->inline_code['css'] as $inlineCss) { $file_content .= "\n\n" . $inlineCss; } } // If compression is enable, compress it ! if ($this->__options['css']['enableCompression']) { App::import('Vendor', 'Combinator.cssmin', array('file' => 'cssmin' . DS . 'cssmin.php')); $css_minifier = new CssMinifier($file_content); // JossToDo - here we could implement filters and plugins, as per http://code.google.com/p/cssmin/wiki/Configuration $file_content = $css_minifier->getMinified(); } if ($fp = fopen($this->cachePath['css'] . '/' . $cachefile, 'wb')) { fwrite($fp, $file_content); fclose($fp); } } return '<link href="' . $this->url('/' . $this->extraPath . $this->__options['css']['cachePath'] . '/' . $cachefile) . '" rel="stylesheet" type="text/css" >'; }
function sn_save_css() { global $wpdb; $css_options = $wpdb->get_results("\n\t\tSELECT *\n\t\tFROM {$wpdb->options}\n\t\tWHERE option_name LIKE 'sn_css_%'\n\t\tORDER BY option_name\n\t"); $css = ''; foreach ($css_options as $option) { $css .= $option->option_value; } //odstran nesmysly $pattern = "/([a-z-]*:;)/"; $css = preg_replace($pattern, '', $css); $sn_filename = SN_CUSTOM_STYLES_FILENAME; require_once 'cssmin.php'; $minifier = new CssMinifier($css); $css = $minifier->getMinified(); $sn_file = fopen($sn_filename, 'w+'); @chmod($sn_filename, 0777); fwrite($sn_file, $css); fclose($sn_file); }