Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
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());
}
Ejemplo n.º 3
0
 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);
 }
 /**
  * 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;
 }
Ejemplo n.º 5
0
 /**
  * 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');
         }
     }
 }
Ejemplo n.º 6
0
 public static function minify($source, array $filters = null, array $plugins = null)
 {
     self::$errors = array();
     $minifier = new CssMinifier($source, $filters, $plugins);
     return $minifier->getMinified();
 }
 /**
  * 
  * @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));
 }
Ejemplo n.º 8
0
 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" >';
     }
 }
Ejemplo n.º 9
0
 /**
  * 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" >';
 }
Ejemplo n.º 12
0
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);
}