Exemplo n.º 1
0
 /**
  * Minifies HTML
  *
  * @param string $html
  * @return string
  */
 function minify_html(&$html)
 {
     $w3_minifier = w3_instance('W3_Minifier');
     $ignored_comments = $this->_config->get_array('minify.html.comments.ignore');
     if (count($ignored_comments)) {
         w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/IgnoredCommentPreserver.php');
         $ignored_comments_preserver = new Minify_IgnoredCommentPreserver();
         $ignored_comments_preserver->setIgnoredComments($ignored_comments);
         $ignored_comments_preserver->search($html);
     }
     if ($this->_config->get_boolean('minify.html.inline.js')) {
         $js_engine = $this->_config->get_string('minify.js.engine');
         if (!$w3_minifier->exists($js_engine) || !$w3_minifier->available($js_engine)) {
             $js_engine = 'js';
         }
         $js_minifier = $w3_minifier->get_minifier($js_engine);
         $js_options = $w3_minifier->get_options($js_engine);
         $w3_minifier->init($js_engine);
         w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/Inline.php');
         w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/Inline/JavaScript.php');
         $html = Minify_Inline_JavaScript::minify($html, $js_minifier, $js_options);
     }
     if ($this->_config->get_boolean('minify.html.inline.css')) {
         $css_engine = $this->_config->get_string('minify.css.engine');
         if (!$w3_minifier->exists($css_engine) || !$w3_minifier->available($css_engine)) {
             $css_engine = 'css';
         }
         $css_minifier = $w3_minifier->get_minifier($css_engine);
         $css_options = $w3_minifier->get_options($css_engine);
         $w3_minifier->init($css_engine);
         w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/Inline.php');
         w3_require_once(W3TC_LIB_MINIFY_DIR . '/Minify/Inline/CSS.php');
         $html = Minify_Inline_CSS::minify($html, $css_minifier, $css_options);
     }
     $engine = $this->_config->get_string('minify.html.engine');
     if (!$w3_minifier->exists($engine) || !$w3_minifier->available($engine)) {
         $engine = 'html';
     }
     if (function_exists('is_feed') && is_feed()) {
         $engine .= 'xml';
     }
     $minifier = $w3_minifier->get_minifier($engine);
     $options = $w3_minifier->get_options($engine);
     $w3_minifier->init($engine);
     $html = call_user_func($minifier, $html, $options);
     if (isset($ignored_comments_preserver)) {
         $ignored_comments_preserver->replace($html);
     }
 }
 /**
  * Minifies HTML
  *
  * @param string  $html
  * @return string
  */
 function minify_html($html)
 {
     $w3_minifier = Dispatcher::component('Minify_ContentMinifier');
     $ignored_comments = $this->_config->get_array('minify.html.comments.ignore');
     if (count($ignored_comments)) {
         $ignored_comments_preserver = new \Minify_IgnoredCommentPreserver();
         $ignored_comments_preserver->setIgnoredComments($ignored_comments);
         $html = $ignored_comments_preserver->search($html);
     }
     if ($this->_config->get_boolean('minify.html.inline.js')) {
         $js_engine = $this->_config->get_string('minify.js.engine');
         if (!$w3_minifier->exists($js_engine) || !$w3_minifier->available($js_engine)) {
             $js_engine = 'js';
         }
         $js_minifier = $w3_minifier->get_minifier($js_engine);
         $js_options = $w3_minifier->get_options($js_engine);
         $w3_minifier->init($js_engine);
         $html = \Minify_Inline_JavaScript::minify($html, $js_minifier, $js_options);
     }
     if ($this->_config->get_boolean('minify.html.inline.css')) {
         $css_engine = $this->_config->get_string('minify.css.engine');
         if (!$w3_minifier->exists($css_engine) || !$w3_minifier->available($css_engine)) {
             $css_engine = 'css';
         }
         $css_minifier = $w3_minifier->get_minifier($css_engine);
         $css_options = $w3_minifier->get_options($css_engine);
         $w3_minifier->init($css_engine);
         $html = \Minify_Inline_CSS::minify($html, $css_minifier, $css_options);
     }
     $engine = $this->_config->get_string('minify.html.engine');
     if (!$w3_minifier->exists($engine) || !$w3_minifier->available($engine)) {
         $engine = 'html';
     }
     if (function_exists('is_feed') && is_feed()) {
         $engine .= 'xml';
     }
     $minifier = $w3_minifier->get_minifier($engine);
     $options = $w3_minifier->get_options($engine);
     $w3_minifier->init($engine);
     $html = call_user_func($minifier, $html, $options);
     if (isset($ignored_comments_preserver)) {
         $html = $ignored_comments_preserver->replace($html);
     }
     return $html;
 }