PluginProbe
Autoptimize / 2.1.2
Autoptimize v2.1.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
autoptimize / classes / autoptimizeHTML.php

autoptimizeHTML.php in Autoptimize 2.1.2, at classes/autoptimizeHTML.php

87 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4 class autoptimizeHTML extends autoptimizeBase {
5 private $keepcomments = false;
6 private $exclude = array('<!-- ngg_resource_manager_marker -->');
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 return true;
70 }
71
72 // Didn't minify :(
73 return false;
74 }
75
76 // Does nothing
77 public function cache() {
78 //No cache for HTML
79 return true;
80 }
81
82 //Returns the content
83 public function getcontent() {
84 return $this->content;
85 }
86 }
87