[^\>]+<\/p>\s*<\/body>/i", $buffer)){ return true; } } public function callback($buffer){ $this->set_current_page_type($buffer); $this->set_current_page_content_type($buffer); $buffer = $this->checkShortCode($buffer); // for Wordfence: not to cache 503 pages if(defined('DONOTCACHEPAGE') && $this->isPluginActive('wordfence/wordfence.php')){ if(function_exists("http_response_code") && http_response_code() == 503){ return $buffer.""; } } if($this->exclude_page($buffer)){ $buffer = preg_replace('/<\!--WPFC_PAGE_TYPE_[a-z]+-->/i', '', $buffer); return $buffer; } $buffer = preg_replace('/<\!--WPFC_PAGE_TYPE_[a-z]+-->/i', '', $buffer); if($this->is_json() && (!defined('WPFC_CACHE_JSON') || (defined('WPFC_CACHE_JSON') && WPFC_CACHE_JSON !== true))){ return $buffer; }else if(preg_match("/Mediapartners-Google|Google\sWireless\sTranscoder/i", $_SERVER['HTTP_USER_AGENT'])){ return $buffer; }else if (is_user_logged_in() || $this->isCommenter()){ return $buffer; }else if($this->isPasswordProtected($buffer)){ return $buffer.""; }else if($this->isWpLogin($buffer)){ return $buffer.""; }else if($this->hasContactForm7WithCaptcha($buffer)){ return $buffer.""; }else if($this->last_error($buffer)){ return $buffer; }else if($this->ignored($buffer)){ return $buffer; }else if($this->blockCache === true){ return $buffer.""; }else if(isset($_GET["preview"])){ return $buffer.""; }else if($this->checkHtml($buffer)){ return $buffer.""; }else if((function_exists("http_response_code")) && (http_response_code() == 301 || http_response_code() == 302)){ return $buffer; }else if(!$this->cacheFilePath){ return $buffer.""; }else{ $content = $buffer; if(isset($this->options->wpFastestCacheRenderBlocking) && method_exists("WpFastestCachePowerfulHtml", "render_blocking")){ if(class_exists("WpFastestCachePowerfulHtml")){ if(!$this->is_amp($content)){ $powerful_html = new WpFastestCachePowerfulHtml(); if(isset($this->options->wpFastestCacheRenderBlockingCss)){ $content = $powerful_html->render_blocking($content, true); }else{ $content = $powerful_html->render_blocking($content); } } } } if(isset($this->options->wpFastestCacheCombineCss)){ require_once "css-utilities.php"; $css = new CssUtilities($this, $content); $content = $css->combineCss(); unset($css); }else if(isset($this->options->wpFastestCacheMinifyCss)){ require_once "css-utilities.php"; $css = new CssUtilities($this, $content); $content = $css->minifyCss(); unset($css); } if(isset($this->options->wpFastestCacheCombineJs) || isset($this->options->wpFastestCacheMinifyJs) || isset($this->options->wpFastestCacheCombineJsPowerFul)){ require_once "js-utilities.php"; } if(isset($this->options->wpFastestCacheCombineJs)){ $head_new = $this->get_header($content); if($head_new){ if(isset($this->options->wpFastestCacheMinifyJs) && $this->options->wpFastestCacheMinifyJs){ $js = new JsUtilities($this, $head_new, true); }else{ $js = new JsUtilities($this, $head_new); } $tmp_head = $js->combine_js(); $content = str_replace($head_new, $tmp_head, $content); unset($r); unset($js); unset($tmp_head); unset($head_new); } } if(class_exists("WpFastestCachePowerfulHtml")){ if(!isset($powerful_html)){ $powerful_html = new WpFastestCachePowerfulHtml(); } $powerful_html->set_html($content); if(isset($this->options->wpFastestCacheCombineJsPowerFul) && method_exists("WpFastestCachePowerfulHtml", "combine_js_in_footer")){ if(isset($this->options->wpFastestCacheMinifyJs) && $this->options->wpFastestCacheMinifyJs){ $content = $powerful_html->combine_js_in_footer($this, true); }else{ $content = $powerful_html->combine_js_in_footer($this); } } if(isset($this->options->wpFastestCacheRemoveComments)){ $content = $powerful_html->remove_head_comments(); } if(isset($this->options->wpFastestCacheMinifyHtmlPowerFul)){ $content = $powerful_html->minify_html(); } if(isset($this->options->wpFastestCacheMinifyJs) && method_exists("WpFastestCachePowerfulHtml", "minify_js_in_body")){ $content = $powerful_html->minify_js_in_body($this, $this->exclude_rules); } } if($this->err){ return $buffer.""; }else{ $content = $this->cacheDate($content); $content = $this->minify($content); $content = str_replace("", "", $content); if(isset($this->options->wpFastestCacheLazyLoad)){ $execute_lazy_load = true; // to disable Lazy Load if the page is amp if($this->is_amp($content)){ $execute_lazy_load = false; } // to disable for Ajax Load More on the pages if($this->isPluginActive('ajax-load-more/ajax-load-more.php') && preg_match("/\/page\/\d+\//", $_SERVER["REQUEST_URI"])){ $execute_lazy_load = false; } if($execute_lazy_load){ if(!class_exists("WpFastestCacheLazyLoad")){ include_once $this->get_premium_path("lazy-load.php"); } $content = $powerful_html->lazy_load($content); if(method_exists("WpFastestCacheLazyLoad",'get_js_source_new')){ $lazy_load_js = WpFastestCacheLazyLoad::get_js_source_new(); }else if(method_exists("WpFastestCacheLazyLoad",'get_js_source')){ $lazy_load_js = WpFastestCacheLazyLoad::get_js_source(); } $content = preg_replace("/\s*<\/head\s*>/i", $lazy_load_js."", $content, 1); } } $content = $this->cdn_rewrite($content); $content = $this->fix_pre_tag($content, $buffer); if($this->cacheFilePath){ if($this->is_html()){ $this->createFolder($this->cacheFilePath, $content); do_action('wpfc_is_cacheable_action'); }else if($this->is_xml()){ $this->createFolder($this->cacheFilePath, $buffer, "xml"); do_action('wpfc_is_cacheable_action'); return $buffer; }else if($this->is_json()){ $this->createFolder($this->cacheFilePath, $buffer, "json"); do_action('wpfc_is_cacheable_action'); return $buffer; } } return $content.""; } } } public function fix_pre_tag($content, $buffer){ if(preg_match("/
]*>/i", $buffer)){ preg_match_all("/]*>((?!<\/pre>).)+<\/pre>/is", $buffer, $pre_buffer); preg_match_all("/]*>((?!<\/pre>).)+<\/pre>/is", $content, $pre_content); if(isset($pre_content[0]) && isset($pre_content[0][0])){ foreach ($pre_content[0] as $key => $value){ /* location ~ / { set $path /path/$1/index.html; } */ $pre_buffer[0][$key] = preg_replace('/\$(\d)/', '\\\$$1', $pre_buffer[0][$key]); $content = preg_replace("/".preg_quote($value, "/")."/", $pre_buffer[0][$key], $content); } } } return $content; } public function cdn_rewrite($content){ if($this->cdn){ $content = preg_replace_callback("/(srcset|src|href|data-vc-parallax-image|data-bg|data-fullurl|data-mobileurl|data-img-url|data-cvpsrc|data-cvpset|data-thumb|data-bg-url|data-large_image|data-lazyload|data-lazy|data-source-url|data-srcsmall|data-srclarge|data-srcfull|data-slide-img|data-lazy-original)\s{0,2}\=\s{0,2}[\'\"]([^\'\"]+)[\'\"]/i", array($this, 'cdn_replace_urls'), $content); //url() $content = preg_replace_callback("/(url)\(([^\)\>]+)\)/i", array($this, 'cdn_replace_urls'), $content); //{"concatemoji":"http:\/\/your_url.com\/wp-includes\/js\/wp-emoji-release.min.js?ver=4.7"} $content = preg_replace_callback("/\{\"concatemoji\"\:\"[^\"]+\"\}/i", array($this, 'cdn_replace_urls'), $content); // $content = preg_replace_callback("/[\"\']([^\'\"]+)[\"\']\s*\:\s*[\"\']https?\:\\\\\/\\\\\/[^\"\']+[\"\']/i", array($this, 'cdn_replace_urls'), $content); // $content = preg_replace_callback("/(jsFileLocation)\s*\:[\"\']([^\"\']+)[\"\']/i", array($this, 'cdn_replace_urls'), $content); //
]*>((?!<\/pre>).)+<\/pre>/is", $buffer, $pre_buffer); preg_match_all("/]*>((?!<\/pre>).)+<\/pre>/is", $content, $pre_content); if(isset($pre_content[0]) && isset($pre_content[0][0])){ foreach ($pre_content[0] as $key => $value){ /* location ~ / { set $path /path/$1/index.html; } */ $pre_buffer[0][$key] = preg_replace('/\$(\d)/', '\\\$$1', $pre_buffer[0][$key]); $content = preg_replace("/".preg_quote($value, "/")."/", $pre_buffer[0][$key], $content); } } } return $content; } public function cdn_rewrite($content){ if($this->cdn){ $content = preg_replace_callback("/(srcset|src|href|data-vc-parallax-image|data-bg|data-fullurl|data-mobileurl|data-img-url|data-cvpsrc|data-cvpset|data-thumb|data-bg-url|data-large_image|data-lazyload|data-lazy|data-source-url|data-srcsmall|data-srclarge|data-srcfull|data-slide-img|data-lazy-original)\s{0,2}\=\s{0,2}[\'\"]([^\'\"]+)[\'\"]/i", array($this, 'cdn_replace_urls'), $content); //url() $content = preg_replace_callback("/(url)\(([^\)\>]+)\)/i", array($this, 'cdn_replace_urls'), $content); //{"concatemoji":"http:\/\/your_url.com\/wp-includes\/js\/wp-emoji-release.min.js?ver=4.7"} $content = preg_replace_callback("/\{\"concatemoji\"\:\"[^\"]+\"\}/i", array($this, 'cdn_replace_urls'), $content); // $content = preg_replace_callback("/[\"\']([^\'\"]+)[\"\']\s*\:\s*[\"\']https?\:\\\\\/\\\\\/[^\"\']+[\"\']/i", array($this, 'cdn_replace_urls'), $content); // $content = preg_replace_callback("/(jsFileLocation)\s*\:[\"\']([^\"\']+)[\"\']/i", array($this, 'cdn_replace_urls'), $content); //
]*>((?!<\/pre>).)+<\/pre>/is", $content, $pre_content); if(isset($pre_content[0]) && isset($pre_content[0][0])){ foreach ($pre_content[0] as $key => $value){ /* location ~ / { set $path /path/$1/index.html; } */ $pre_buffer[0][$key] = preg_replace('/\$(\d)/', '\\\$$1', $pre_buffer[0][$key]); $content = preg_replace("/".preg_quote($value, "/")."/", $pre_buffer[0][$key], $content); } } } return $content; } public function cdn_rewrite($content){ if($this->cdn){ $content = preg_replace_callback("/(srcset|src|href|data-vc-parallax-image|data-bg|data-fullurl|data-mobileurl|data-img-url|data-cvpsrc|data-cvpset|data-thumb|data-bg-url|data-large_image|data-lazyload|data-lazy|data-source-url|data-srcsmall|data-srclarge|data-srcfull|data-slide-img|data-lazy-original)\s{0,2}\=\s{0,2}[\'\"]([^\'\"]+)[\'\"]/i", array($this, 'cdn_replace_urls'), $content); //url() $content = preg_replace_callback("/(url)\(([^\)\>]+)\)/i", array($this, 'cdn_replace_urls'), $content); //{"concatemoji":"http:\/\/your_url.com\/wp-includes\/js\/wp-emoji-release.min.js?ver=4.7"} $content = preg_replace_callback("/\{\"concatemoji\"\:\"[^\"]+\"\}/i", array($this, 'cdn_replace_urls'), $content); // $content = preg_replace_callback("/[\"\']([^\'\"]+)[\"\']\s*\:\s*[\"\']https?\:\\\\\/\\\\\/[^\"\']+[\"\']/i", array($this, 'cdn_replace_urls'), $content); // $content = preg_replace_callback("/(jsFileLocation)\s*\:[\"\']([^\"\']+)[\"\']/i", array($this, 'cdn_replace_urls'), $content); //