PluginProbe
Autoptimize / 1.8.2
Autoptimize v1.8.2
2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 All 107 releases
← All changes | classes/autoptimizeHTML.php +50 -84 2.3.41.8.2 View file →
@@ -1,92 +1,58 @@
1 1 <?php
2 +
2 3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3 4
4 5 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 - }
6 + private $keepcomments = false;
7 +
8 + //Does nothing
9 + public function read($options)
10 + {
11 + //Remove the HTML comments?
12 + $this->keepcomments = (bool) $options['keepcomments'];
13 +
14 + //Nothing to read for HTML
15 + return true;
16 + }
17 +
18 + //Joins and optimizes CSS
19 + public function minify()
20 + {
21 + if(class_exists('Minify_HTML'))
22 + {
23 + // noptimize me
24 + $this->content = $this->hide_noptimize($this->content);
40 25
41 - // noptimize me
42 - $this->content = $this->hide_noptimize($this->content);
26 + // Minify html
27 + $options = array('keepComments' => $this->keepcomments);
43 28
44 - // Minify html
45 - $options = array('keepComments' => $this->keepcomments);
46 - if ($this->forcexhtml) {
47 - $options['xhtml'] = true;
48 - }
29 + if (is_callable(array(new Minify_HTML,"minify"))) {
30 + $tmp_content = Minify_HTML::minify($this->content,$options);
31 + if (!empty($tmp_content)) {
32 + $this->content = $tmp_content;
33 + unset($tmp_content);
34 + }
35 + }
49 36
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 - }
37 + // restore noptimize
38 + $this->content = $this->restore_noptimize($this->content);
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 + }
92 58 }