| @@ -1,92 +1,44 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| 3 | 2 | |
| 4 | -class autoptimizeHTML extends autoptimizeBase { | |
| 5 | - private $keepcomments = false; | |
| 6 | - private $exclude = array('<!-- ngg_resource_manager_marker -->', '<!--noindex-->', '<!--/noindex-->'); | |
| 7 | - | |
| 8 | - public function read($options) { | |
| 9 | - // Remove the HTML comments? | |
| 10 | - $this->keepcomments = (bool) $options['keepcomments']; | |
| 11 | - | |
| 12 | - // filter to force xhtml | |
| 13 | - $this->forcexhtml = (bool) apply_filters( 'autoptimize_filter_html_forcexhtml', false ); | |
| 14 | - | |
| 15 | - // filter to add strings to be excluded from HTML minification | |
| 16 | - $excludeHTML = apply_filters( 'autoptimize_filter_html_exclude','' ); | |
| 17 | - if ($excludeHTML!=="") { | |
| 18 | - $exclHTMLArr = array_filter(array_map('trim',explode(",",$excludeHTML))); | |
| 19 | - $this->exclude = array_merge($exclHTMLArr,$this->exclude); | |
| 20 | - } | |
| 21 | - | |
| 22 | - // Nothing else for HTML | |
| 23 | - return true; | |
| 24 | - } | |
| 25 | - | |
| 26 | - //Joins and optimizes CSS | |
| 27 | - public function minify() { | |
| 28 | - $noptimizeHTML = apply_filters( 'autoptimize_filter_html_noptimize', false, $this->content ); | |
| 29 | - if ($noptimizeHTML) | |
| 30 | - return false; | |
| 31 | - | |
| 32 | - if(class_exists('Minify_HTML')) { | |
| 33 | - // wrap the to-be-excluded strings in noptimize tags | |
| 34 | - foreach ($this->exclude as $exclString) { | |
| 35 | - if (strpos($this->content,$exclString)!==false) { | |
| 36 | - $replString="<!--noptimize-->".$exclString."<!--/noptimize-->"; | |
| 37 | - $this->content=str_replace($exclString,$replString,$this->content); | |
| 38 | - } | |
| 39 | - } | |
| 40 | - | |
| 41 | - // noptimize me | |
| 42 | - $this->content = $this->hide_noptimize($this->content); | |
| 43 | - | |
| 44 | - // Minify html | |
| 45 | - $options = array('keepComments' => $this->keepcomments); | |
| 46 | - if ($this->forcexhtml) { | |
| 47 | - $options['xhtml'] = true; | |
| 48 | - } | |
| 49 | - | |
| 50 | - if (@is_callable(array("Minify_HTML","minify"))) { | |
| 51 | - $tmp_content = Minify_HTML::minify($this->content,$options); | |
| 52 | - if (!empty($tmp_content)) { | |
| 53 | - $this->content = $tmp_content; | |
| 54 | - unset($tmp_content); | |
| 55 | - } | |
| 56 | - } | |
| 57 | - | |
| 58 | - // restore noptimize | |
| 59 | - $this->content = $this->restore_noptimize($this->content); | |
| 60 | - | |
| 61 | - // remove the noptimize-wrapper from around the excluded strings | |
| 62 | - foreach ($this->exclude as $exclString) { | |
| 63 | - $replString="<!--noptimize-->".$exclString."<!--/noptimize-->"; | |
| 64 | - if (strpos($this->content,$replString)!==false) { | |
| 65 | - $this->content=str_replace($replString,$exclString,$this->content); | |
| 66 | - } | |
| 67 | - } | |
| 68 | - | |
| 69 | - // revslider data attribs somehow suffer from HTML optimization, this fixes that | |
| 70 | - if ( class_exists('RevSlider') && apply_filters('autoptimize_filter_html_dataattrib_cleanup', false) ) { | |
| 71 | - $this->content = preg_replace('#\n(data-.*$)\n#Um',' $1 ', $this->content); | |
| 72 | - $this->content = preg_replace('#<[^>]*(=\"[^"\'<>\s]*\")(\w)#','$1 $2', $this->content); | |
| 73 | - } | |
| 74 | - | |
| 75 | - return true; | |
| 76 | - } | |
| 77 | - | |
| 78 | - // Didn't minify :( | |
| 79 | - return false; | |
| 80 | - } | |
| 81 | - | |
| 82 | - // Does nothing | |
| 83 | - public function cache() { | |
| 84 | - //No cache for HTML | |
| 85 | - return true; | |
| 86 | - } | |
| 87 | - | |
| 88 | - //Returns the content | |
| 89 | - public function getcontent() { | |
| 90 | - return $this->content; | |
| 91 | - } | |
| 3 | +class autoptimizeHTML extends autoptimizeBase | |
| 4 | +{ | |
| 5 | + private $keepcomments = false; | |
| 6 | + | |
| 7 | + //Does nothing | |
| 8 | + public function read($options) | |
| 9 | + { | |
| 10 | + //Remove the HTML comments? | |
| 11 | + $this->keepcomments = (bool) $options['keepcomments']; | |
| 12 | + | |
| 13 | + //Nothing to read for HTML | |
| 14 | + return true; | |
| 15 | + } | |
| 16 | + | |
| 17 | + //Joins and optimizes CSS | |
| 18 | + public function minify() | |
| 19 | + { | |
| 20 | + if(class_exists('Minify_HTML')) | |
| 21 | + { | |
| 22 | + //Minify html | |
| 23 | + $options = array('keepComments' => $this->keepcomments); | |
| 24 | + $this->content = Minify_HTML::minify($this->content,$options); | |
| 25 | + return true; | |
| 26 | + } | |
| 27 | + | |
| 28 | + //Didn't minify :( | |
| 29 | + return false; | |
| 30 | + } | |
| 31 | + | |
| 32 | + //Does nothing | |
| 33 | + public function cache() | |
| 34 | + { | |
| 35 | + //No cache for HTML | |
| 36 | + return true; | |
| 37 | + } | |
| 38 | + | |
| 39 | + //Returns the content | |
| 40 | + public function getcontent() | |
| 41 | + { | |
| 42 | + return $this->content; | |
| 43 | + } | |
| 92 | 44 | } |