Пример #1
0
 /**
  * Generate minified HTML code
  *
  * @param string $content
  * @param array $options
  *
  * - `html` - boolean - Minify HTML code
  * - `js`   - boolean - Minify JS
  * - `css`  - boolean - Minify CSS
  *
  * @return string modified content if avaible, otherwise origin content
  */
 public static function minify($content, $options = array())
 {
     $options += array('html' => true, 'js' => true, 'css' => true);
     $minifyOptions = array();
     if ($options['html'] === true) {
         App::uses('Minify', 'Tidy.Vendor/Minify');
         $minifyOptions['xhtml'] = false;
         if ($options['js'] === true) {
             App::uses('JSMin', 'Tidy.Vendor/Minify');
             $minifyOptions['jsMinifier'] = array("JSMin", "minify");
         }
         if ($options['css'] === true) {
             App::uses('Minify_CSS', 'Tidy.Vendor/Minify');
             $minifyOptions['cssMinifier'] = array("Minify_CSS", "minify");
         }
         $Minify = new Minify();
         $minified = $Minify->process($content, $minifyOptions);
         if (!empty($minified)) {
             return $minified;
         }
     }
     return $content;
 }