| 1 |
<?php |
| 2 |
|
| 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 |
// but don't remove comment-blocks needed by WP Super Cache (& W3 Total Cache) |
| 24 |
if ( ($this->keepcomments===false) && (preg_match( '/<!--mclude|<!--mfunc|<!--dynamic-cached-content-->/', $this->content ))) { |
| 25 |
$this->content = preg_replace('#(<!--mclude .*<!--/mclude-->)#ise','\'%%MFUNC%%\'.base64_encode("$0").\'%%MFUNC%%\'', $this->content); |
| 26 |
$this->content = preg_replace('#(<!--mfunc.*<!--/mfunc-->)#ise','\'%%MFUNC%%\'.base64_encode("$1").\'%%MFUNC%%\'', $this->content); |
| 27 |
$this->content = preg_replace('#(<!--dynamic-cached-content-->.*<!--/dynamic-cached-content-->)#ise','\'%%MFUNC%%\'.base64_encode("$0").\'%%MFUNC%%\'', $this->content); |
| 28 |
$restore_mfuncs=true; |
| 29 |
} |
| 30 |
|
| 31 |
$options = array('keepComments' => $this->keepcomments); |
| 32 |
$this->content = Minify_HTML::minify($this->content,$options); |
| 33 |
|
| 34 |
|
| 35 |
if (isset($restore_mfuncs)) { |
| 36 |
$this->content = preg_replace('#%%MFUNC%%(.*)%%MFUNC%%#sie','stripslashes(base64_decode("$1"))',$this->content); |
| 37 |
} |
| 38 |
|
| 39 |
return true; |
| 40 |
} |
| 41 |
|
| 42 |
//Didn't minify :( |
| 43 |
return false; |
| 44 |
} |
| 45 |
|
| 46 |
//Does nothing |
| 47 |
public function cache() |
| 48 |
{ |
| 49 |
//No cache for HTML |
| 50 |
return true; |
| 51 |
} |
| 52 |
|
| 53 |
//Returns the content |
| 54 |
public function getcontent() |
| 55 |
{ |
| 56 |
return $this->content; |
| 57 |
} |
| 58 |
} |
| 59 |
|