Permalink
Browse files

applying Matthew's & Tomas' ideas

  • Loading branch information...
futtta committed Jun 9, 2017
1 parent 1c35ffa commit 2d37d8eaedb16f2a44cecc557a6767f0da1a2d10
Showing with 12 additions and 14 deletions.
  1. +1 −3 autoptimize.php
  2. +7 −7 classes/autoptimizeBase.php
  3. +1 −1 classes/autoptimizeScripts.php
  4. +3 −3 classes/autoptimizeStyles.php
View
@@ -222,9 +222,6 @@ function autoptimize_start_buffering() {
function autoptimize_end_buffering($content) {
if ( ((stripos($content,"<html") === false) && (stripos($content,"<!DOCTYPE html") === false)) || preg_match('/<html[^>]*(?:amp|⚡)/',$content) === 1 || stripos($content,"<xsl:stylesheet") !== false ) { return $content; }
// we need clean HTML before optimization
$content=preg_replace("#%%(?:INJECTLATER|COMMENTS|IEHACK|NOPTIMIZE)%%.*?%%(?:INJECTLATER|COMMENTS|IEHACK|NOPTIMIZE)%%#is","",$content);
// load URL constants as late as possible to allow domain mapper to kick in
if (function_exists("domain_mapping_siteurl")) {
define('AUTOPTIMIZE_WP_SITE_URL',domain_mapping_siteurl(get_current_blog_id()));
@@ -241,6 +238,7 @@ function autoptimize_end_buffering($content) {
define('AUTOPTIMIZE_CACHE_URL',AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR);
}
define('AUTOPTIMIZE_WP_ROOT_URL',str_replace(AUTOPTIMIZE_WP_CONTENT_NAME,'',AUTOPTIMIZE_WP_CONTENT_URL));
define('AUTOPTIMIZE_HASH',wp_hash(AUTOPTIMIZE_CACHE_URL.microtime()));
// Config element
$conf = autoptimizeConfig::instance();
@@ -145,7 +145,7 @@ protected function hide_noptimize($noptimize_in) {
'#<!--\s?noptimize\s?-->.*?<!--\s?/\s?noptimize\s?-->#is',
create_function(
'$matches',
'return "%%NOPTIMIZE%%".base64_encode($matches[0])."%%NOPTIMIZE%%";'
'return "%%NOPTIMIZE".AUTOPTIMIZE_HASH."%%".base64_encode($matches[0])."%%NOPTIMIZE%%";'
),
$noptimize_in
);
@@ -159,7 +159,7 @@ protected function hide_noptimize($noptimize_in) {
protected function restore_noptimize($noptimize_in) {
if ( strpos( $noptimize_in, '%%NOPTIMIZE%%' ) !== false ) {
$noptimize_out = preg_replace_callback(
'#%%NOPTIMIZE%%(.*?)%%NOPTIMIZE%%#is',
'#%%NOPTIMIZE'.AUTOPTIMIZE_HASH.'%%(.*?)%%NOPTIMIZE%%#is',
create_function(
'$matches',
'return base64_decode($matches[1]);'
@@ -178,7 +178,7 @@ protected function hide_iehacks($iehacks_in) {
'#<!--\[if.*?\[endif\]-->#is',
create_function(
'$matches',
'return "%%IEHACK%%".base64_encode($matches[0])."%%IEHACK%%";'
'return "%%IEHACK".AUTOPTIMIZE_HASH."%%".base64_encode($matches[0])."%%IEHACK%%";'
),
$iehacks_in
);
@@ -191,7 +191,7 @@ protected function hide_iehacks($iehacks_in) {
protected function restore_iehacks($iehacks_in) {
if ( strpos( $iehacks_in, '%%IEHACK%%' ) !== false ) {
$iehacks_out = preg_replace_callback(
'#%%IEHACK%%(.*?)%%IEHACK%%#is',
'#%%IEHACK'.AUTOPTIMIZE_HASH.'%%(.*?)%%IEHACK%%#is',
create_function(
'$matches',
'return base64_decode($matches[1]);'
@@ -210,7 +210,7 @@ protected function hide_comments($comments_in) {
'#<!--.*?-->#is',
create_function(
'$matches',
'return "%%COMMENTS%%".base64_encode($matches[0])."%%COMMENTS%%";'
'return "%%COMMENTS".AUTOPTIMIZE_HASH."%%".base64_encode($matches[0])."%%COMMENTS%%";'
),
$comments_in
);
@@ -223,7 +223,7 @@ protected function hide_comments($comments_in) {
protected function restore_comments($comments_in) {
if ( strpos( $comments_in, '%%COMMENTS%%' ) !== false ) {
$comments_out = preg_replace_callback(
'#%%COMMENTS%%(.*?)%%COMMENTS%%#is',
'#%%COMMENTS'.AUTOPTIMIZE_HASH.'%%(.*?)%%COMMENTS%%#is',
create_function(
'$matches',
'return base64_decode($matches[1]);'
@@ -299,7 +299,7 @@ protected function isremovable($tag, $removables) {
protected function inject_minified($in) {
if ( strpos( $in, '%%INJECTLATER%%' ) !== false ) {
$out = preg_replace_callback(
'#\/\*\!%%INJECTLATER%%(.*?)%%INJECTLATER%%\*\/#is',
'#\/\*\!%%INJECTLATER'.AUTOPTIMIZE_HASH.'%%(.*?)%%INJECTLATER%%\*\/#is',
create_function(
'$matches',
'$filepath=base64_decode(strtok($matches[1],"|"));
@@ -243,7 +243,7 @@ public function minify() {
$scriptsrc=$tmpscriptsrc;
$this->alreadyminified=true;
} else if ($this->can_inject_late($script)) {
$scriptsrc="/*!%%INJECTLATER%%".base64_encode($script)."|".$scripthash."%%INJECTLATER%%*/";
$scriptsrc="/*!%%INJECTLATER".AUTOPTIMIZE_HASH."%%".base64_encode($script)."|".$scripthash."%%INJECTLATER%%*/";
}
$this->jscode .= "\n".$scriptsrc;
}/*else{
@@ -97,7 +97,7 @@ public function read($options) {
'#<(?:no)?script.*?<\/(?:no)?script>#is',
create_function(
'$matches',
'return "%%SCRIPT%%".base64_encode($matches[0])."%%SCRIPT%%";'
'return "%%SCRIPT".AUTOPTIMIZE_HASH."%%".base64_encode($matches[0])."%%SCRIPT%%";'
),
$this->content
);
@@ -283,7 +283,7 @@ public function minify() {
$code=$tmpstyle;
$this->alreadyminified=true;
} else if ($this->can_inject_late($path,$code)) {
$code="/*!%%INJECTLATER%%".base64_encode($path)."|".md5($code)."%%INJECTLATER%%*/";
$code="/*!%%INJECTLATER".AUTOPTIMIZE_HASH."%%".base64_encode($path)."|".md5($code)."%%INJECTLATER%%*/";
}
if(!empty($code)) {
@@ -478,7 +478,7 @@ public function getcontent() {
// restore (no)script
if ( strpos( $this->content, '%%SCRIPT%%' ) !== false ) {
$this->content = preg_replace_callback(
'#%%SCRIPT%%(.*?)%%SCRIPT%%#is',
'#%%SCRIPT'.AUTOPTIMIZE_HASH.'%%(.*?)%%SCRIPT%%#is',
create_function(
'$matches',
'return base64_decode($matches[1]);'

0 comments on commit 2d37d8e

Please sign in to comment.