PluginProbe
Autoptimize / 1.9.3
Autoptimize v1.9.3
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 1.9.3, at classes/autoptimizeHTML.php

82 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5 class autoptimizeHTML extends autoptimizeBase {
6 private $keepcomments = false;
7 private $exclude = array('<!-- ngg_resource_manager_marker -->');
8
9 public function read($options) {
10 // Remove the HTML comments?
11 $this->keepcomments = (bool) $options['keepcomments'];
12
13 // filter to add strings to be excluded from HTML minification
14 $excludeHTML = apply_filters( 'autoptimize_filter_html_exclude','' );
15 if ($excludeHTML!=="") {
16 $exclHTMLArr = array_filter(array_map('trim',explode(",",$excludeHTML)));
17 $this->exclude = array_merge($exclHTMLArr,$this->exclude);
18 }
19
20 // Nothing else for HTML
21 return true;
22 }
23
24 //Joins and optimizes CSS
25 public function minify() {
26 $noptimizeHTML = apply_filters( 'autoptimize_filter_html_noptimize', false, $this->content );
27 if ($noptimizeHTML)
28 return false;
29
30 if(class_exists('Minify_HTML')) {
31 // wrap the to-be-excluded strings in noptimize tags
32 foreach ($this->exclude as $exclString) {
33 if (strpos($this->content,$exclString)!==false) {
34 $replString="<!--noptimize-->".$exclString."<!--/noptimize-->";
35 $this->content=str_replace($exclString,$replString,$this->content);
36 }
37 }
38
39 // noptimize me
40 $this->content = $this->hide_noptimize($this->content);
41
42 // Minify html
43 $options = array('keepComments' => $this->keepcomments);
44
45 if (@is_callable(array(new Minify_HTML,"minify"))) {
46 $tmp_content = Minify_HTML::minify($this->content,$options);
47 if (!empty($tmp_content)) {
48 $this->content = $tmp_content;
49 unset($tmp_content);
50 }
51 }
52
53 // restore noptimize
54 $this->content = $this->restore_noptimize($this->content);
55
56 // remove the noptimize-wrapper from around the excluded strings
57 foreach ($this->exclude as $exclString) {
58 $replString="<!--noptimize-->".$exclString."<!--/noptimize-->";
59 if (strpos($this->content,$replString)!==false) {
60 $this->content=str_replace($replString,$exclString,$this->content);
61 }
62 }
63
64 return true;
65 }
66
67 // Didn't minify :(
68 return false;
69 }
70
71 // Does nothing
72 public function cache() {
73 //No cache for HTML
74 return true;
75 }
76
77 //Returns the content
78 public function getcontent() {
79 return $this->content;
80 }
81 }
82