process() public méthode

Minify the markeup given in the constructor
public process ( ) : string
Résultat string
Exemple #1
0
 /**
  * "Minify" an HTML page
  *
  * @param string $html
  *
  * @param array $options
  *
  * 'cssMinifier' : (optional) callback function to process content of STYLE
  * elements.
  *
  * 'jsMinifier' : (optional) callback function to process content of SCRIPT
  * elements. Note: the type attribute is ignored.
  *
  * 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
  * unset, minify will sniff for an XHTML doctype.
  *
  * @return string
  */
 public static function minify($html, $options = array())
 {
     $min = new Minify_HTML($html, $options);
     return $min->process();
 }
 public function minify_html()
 {
     require_once MODX_CORE_PATH . "components/" . $this->PKG_NAME_LOWER . "/model/optimize/minify_html.class.php";
     if (class_exists('Minify_HTML')) {
         $options = array('xhtml' => true);
         $mh = new Minify_HTML($this->content, $options);
         // Save compression stats
         $this->content = $this->compress_stats('html', $this->content, $mh->process());
     }
     return;
 }
Exemple #3
0
function minifyHTML($html)
{
    include NITRO_FOLDER . 'lib' . DS . 'minifier' . DS . 'HTMLMin.php';
    $htmlMinifier = new Minify_HTML($html, array('jsCleanComments' => true));
    $html = $htmlMinifier->process();
    //$html = str_replace(array("\n"), array(" "), trim($html));
    return $html;
}
Exemple #4
0
 /**
  * HideMyWP::global_html_filter()
  * Filter output HTML
  * @param mixed $buffer
  * @return
  */
 function global_html_filter($buffer)
 {
     if (is_admin() && $this->admin_replace_old) {
         $buffer = str_replace($this->admin_replace_old, $this->admin_replace_new, $buffer);
         return $buffer;
     }
     if (is_admin()) {
         return $buffer;
     }
     if ($this->opt('remove_html_comments')) {
         if ($this->opt('remove_html_comments') == 'simple') {
             $this->preg_replace_old[] = '/<!--(.*?)-->/';
             $this->preg_replace_new[] = ' ';
             $this->preg_replace_old[] = "%(\n){2,}%";
             $this->preg_replace_new[] = "\n";
         } elseif ($this->opt('remove_html_comments') == 'quick') {
             //comments and more than 2 space or line break will be remove. Simple & quick but not perfect!
             $this->preg_replace_old[] = '!/\\*.*?\\*/!s';
             $this->preg_replace_new[] = ' ';
             $this->preg_replace_old[] = '/\\n\\s*\\n/';
             $this->preg_replace_new[] = ' ';
             $this->preg_replace_old[] = '/<!--(.*?)-->/';
             $this->preg_replace_new[] = ' ';
             $this->preg_replace_old[] = "%(\\s){3,}%";
             $this->preg_replace_new[] = ' ';
         } elseif ($this->opt('remove_html_comments') == 'safe') {
             require_once 'lib/class.HTML-minify.php';
             $min = new Minify_HTML($buffer, array('xhtml' => true));
             $buffer = $min->process();
         }
     }
     if ($this->top_replace_old) {
         $buffer = str_replace($this->top_replace_old, $this->top_replace_new, $buffer);
     }
     if ($this->opt('replace_in_html')) {
         $replace_in_html = $this->h->replace_newline(trim($this->opt('replace_in_html'), ' '), '|');
         $replace_lines = explode('|', $replace_in_html);
         if ($replace_lines) {
             foreach ($replace_lines as $line) {
                 $replace_word = explode('=', $line);
                 if (isset($replace_word[0]) && isset($replace_word[1])) {
                     $replace_word[0] = str_replace('[equal]', '=', $replace_word[0]);
                     $replace_word[1] = str_replace('[equal]', '=', $replace_word[1]);
                     $this->replace_old[] = trim($replace_word[0], ' ');
                     $this->replace_new[] = trim($replace_word[1], ' ');
                 }
             }
         }
     }
     if ($this->opt('replace_mode') == 'safe' && $this->partial_replace_old) {
         $buffer = str_replace($this->partial_replace_old, $this->partial_replace_new, $buffer);
     }
     if ($this->opt('replace_mode') == 'safe' && $this->partial_preg_replace_old) {
         $buffer = preg_replace($this->partial_preg_replace_old, $this->partial_preg_replace_new, $buffer);
     }
     if ($this->replace_old) {
         $buffer = str_replace($this->replace_old, $this->replace_new, $buffer);
     }
     if ($this->preg_replace_old) {
         $buffer = preg_replace($this->preg_replace_old, $this->preg_replace_new, $buffer);
     }
     return $buffer;
 }
Exemple #5
0
 /**
  * HideMyWP::global_html_filter()
  * Filter output HTML
  * @param mixed $buffer
  * @return
  */
 function global_html_filter($buffer)
 {
     if (is_admin() && $this->admin_replace_old && !isset($_GET['die_message'])) {
         $buffer = str_replace($this->admin_replace_old, $this->admin_replace_new, $buffer);
         return $buffer;
     }
     if ($this->opt('replace_in_ajax')) {
         if (is_admin() && !defined('DOING_AJAX')) {
             return $buffer;
         }
     } else {
         if (is_admin()) {
             return $buffer;
         }
     }
     //first minify rocket then change other URLS
     if (function_exists('rocket_minify_process')) {
         $buffer = rocket_minify_process($buffer);
     }
     if ($this->opt('remove_html_comments') && !defined('DOING_AJAX')) {
         if ($this->opt('remove_html_comments') == 'simple') {
             $this->preg_replace_old[] = '/<!--(.*?)-->/';
             $this->preg_replace_new[] = ' ';
             $this->preg_replace_old[] = "%(\n){2,}%";
             $this->preg_replace_new[] = "\n";
         } elseif ($this->opt('remove_html_comments') == 'quick') {
             //comments and more than 2 space or line break will be remove. Simple & quick but not perfect!
             $this->preg_replace_old[] = '!/\\*.*?\\*/!s';
             $this->preg_replace_new[] = ' ';
             $this->preg_replace_old[] = '/\\n\\s*\\n/';
             $this->preg_replace_new[] = ' ';
             $this->preg_replace_old[] = '/<!--(.*?)-->/';
             $this->preg_replace_new[] = ' ';
             $this->preg_replace_old[] = "%(\\s){3,}%";
             $this->preg_replace_new[] = ' ';
         } elseif ($this->opt('remove_html_comments') == 'safe') {
             require_once 'lib/class.HTML-minify.php';
             $min = new Minify_HTML($buffer, array('xhtml' => true));
             $buffer = $min->process();
         }
     }
     if ($this->top_replace_old) {
         $buffer = str_replace($this->top_replace_old, $this->top_replace_new, $buffer);
     }
     if ($this->opt('replace_in_html')) {
         $replace_in_html = $this->h->replace_newline(trim($this->opt('replace_in_html'), ' '), '|');
         $replace_lines = explode('|', $replace_in_html);
         if ($replace_lines) {
             foreach ($replace_lines as $line) {
                 $replace_word = explode('=', $line);
                 if (isset($replace_word[0]) && isset($replace_word[1])) {
                     $replace_word[0] = str_replace(array('[equal]', '[bslash]', '[new_line]'), array('=', "\\", "\n"), $replace_word[0]);
                     $replace_word[1] = str_replace(array('[equal]', '[bslash]', '[new_line]'), array('=', "\\", "\n"), $replace_word[1]);
                     $this->replace_old[] = trim($replace_word[0], ' ');
                     $this->replace_new[] = trim($replace_word[1], ' ');
                 }
             }
         }
     }
     if ($this->opt('cdn_path')) {
         if (trim($this->opt('new_theme_path'), ' /')) {
             $this->replace_old[] = site_url(trim($this->opt('new_theme_path'), ' /'));
             $this->replace_new[] = trim($this->opt('cdn_path'), '/ ') . '/' . trim($this->opt('new_theme_path'), ' /');
         } else {
             $this->replace_old[] = site_url('wp-content/themes');
             $this->replace_new[] = trim($this->opt('cdn_path'), '/ ') . '/' . 'wp-content/themes';
         }
         if (trim($this->opt('new_plugin_path'), ' /')) {
             $this->replace_old[] = site_url(trim($this->opt('new_plugin_path'), ' /'));
             $this->replace_new[] = trim($this->opt('cdn_path'), '/ ') . '/' . trim($this->opt('new_plugin_path'), ' /');
         } else {
             $this->replace_old[] = site_url('wp-content/plugins');
             $this->replace_new[] = trim($this->opt('cdn_path'), '/ ') . '/' . 'wp-content/plugins';
         }
         if (trim($this->opt('new_include_path'), ' /')) {
             $this->replace_old[] = site_url(trim($this->opt('new_include_path'), ' /'));
             $this->replace_new[] = trim($this->opt('cdn_path'), '/ ') . '/' . trim($this->opt('new_include_path'), ' /');
         } else {
             $this->replace_old[] = site_url('wp-includes');
             $this->replace_new[] = trim($this->opt('cdn_path'), '/ ') . '/' . 'wp-includes';
         }
         if (trim($this->opt('new_upload_path'), ' /')) {
             $this->replace_old[] = site_url(trim($this->opt('new_upload_path'), ' /'));
             $this->replace_new[] = trim($this->opt('cdn_path'), '/ ') . '/' . trim($this->opt('new_upload_path'), ' /');
         } else {
             $this->replace_old[] = site_url('wp-content/uploads');
             $this->replace_new[] = trim($this->opt('cdn_path'), '/ ') . '/' . 'wp-content/uploads';
         }
     }
     if ($this->opt('replace_mode') == 'safe' && $this->partial_replace_old) {
         $buffer = str_replace($this->partial_replace_old, $this->partial_replace_new, $buffer);
     }
     if ($this->opt('replace_mode') == 'safe' && $this->partial_preg_replace_old) {
         $buffer = preg_replace($this->partial_preg_replace_old, $this->partial_preg_replace_new, $buffer);
     }
     if ($this->replace_old) {
         $buffer = str_replace($this->replace_old, $this->replace_new, $buffer);
     }
     if ($this->preg_replace_old) {
         $buffer = preg_replace($this->preg_replace_old, $this->preg_replace_new, $buffer);
     }
     return $buffer;
 }