public function callback($buffer) { $buffer = $this->checkShortCode($buffer); if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "POST") { return $buffer; } else { if (preg_match("/Mediapartners-Google/i", $_SERVER['HTTP_USER_AGENT'])) { return $buffer; } else { if ($this->exclude_page()) { return $buffer . "<!-- Wp Fastest Cache: Exclude Page -->"; } else { if ($this->is_xml($buffer)) { return $buffer . "<!-- Wp Fastest Cache: XML Content -->"; } else { if (is_user_logged_in() || $this->isCommenter()) { return $buffer; } else { if (isset($_SERVER["HTTP_ACCEPT"]) && preg_match("/json/i", $_SERVER["HTTP_ACCEPT"])) { return $buffer; } else { if ($this->checkWoocommerceSession()) { if ($this->checkHtml($buffer)) { return $buffer; } else { return $buffer . "<!-- \$_COOKIE['wp_woocommerce_session'] has been set -->"; } } else { if (defined('DONOTCACHEPAGE') && $this->isPluginActive('wordfence/wordfence.php')) { // for Wordfence: not to cache 503 pages return $buffer . "<!-- DONOTCACHEPAGE is defined as TRUE -->"; } else { if ($this->isPasswordProtected($buffer)) { return $buffer . "<!-- Password protected content has been detected -->"; } else { if ($this->isWpLogin($buffer)) { return $buffer . "<!-- wp-login.php -->"; } else { if ($this->hasContactForm7WithCaptcha($buffer)) { return $buffer . "<!-- This page was not cached because ContactForm7's captcha -->"; } else { if (is_404()) { return $buffer; } else { if ($this->ignored()) { return $buffer; } else { if ($this->blockCache === true) { return $buffer . "<!-- wpfcNOT has been detected -->"; } else { if (isset($_GET["preview"])) { return $buffer . "<!-- not cached -->"; } else { if (preg_match("/\\?/", $_SERVER["REQUEST_URI"]) && !preg_match("/\\/\\?fdx\\_switcher\\=true/", $_SERVER["REQUEST_URI"])) { // for WP Mobile Edition return $buffer; } else { if ($this->checkHtml($buffer)) { return $buffer . "<!-- html is corrupted -->"; } else { if ($this->isMobile()) { if (class_exists("WpFcMobileCache") && isset($this->options->wpFastestCacheMobileTheme)) { // wptouch: ipad is accepted as a desktop so no need to create cache if user agent is ipad // https://wordpress.org/support/topic/plugin-wptouch-wptouch-wont-display-mobile-version-on-ipad?replies=12 if ($this->isPluginActive('wptouch/wptouch.php')) { if (preg_match("/ipad/i", $_SERVER['HTTP_USER_AGENT'])) { return $buffer . "<!-- ipad user -->"; } } $wpfc_mobile = new WpFcMobileCache(); $cachFilePath = $this->getWpContentDir() . "/cache/" . $wpfc_mobile->get_folder_name() . "" . $_SERVER["REQUEST_URI"]; } else { return $buffer . "<!-- mobile user -->"; } } else { $cachFilePath = $this->getWpContentDir() . "/cache/all" . $_SERVER["REQUEST_URI"]; } //to show cache version of home page via php if htaccess rewrite rule does not work if ($_SERVER["REQUEST_URI"] == "/") { if (file_exists($cachFilePath . "index.html")) { if ($content = @file_get_contents($cachFilePath . "index.html")) { return $content . "<!-- via php -->"; } } } $content = $buffer; if (isset($this->options->wpFastestCacheCombineCss)) { require_once "css-utilities.php"; $css = new CssUtilities($this, $content); $content = $css->combineCss(); } else { if (isset($this->options->wpFastestCacheMinifyCss)) { require_once "css-utilities.php"; $css = new CssUtilities($this, $content); $content = $css->minifyCss(); } } if (isset($this->options->wpFastestCacheCombineJs) || isset($this->options->wpFastestCacheMinifyJs) || isset($this->options->wpFastestCacheCombineJsPowerFul)) { require_once "js-utilities.php"; } if (isset($this->options->wpFastestCacheCombineJs)) { preg_match("/<head(.*?)<\\/head>/si", $content, $head); if (isset($this->options->wpFastestCacheMinifyJs) && $this->options->wpFastestCacheMinifyJs) { $js = new JsUtilities($this, $head[1], true); } else { $js = new JsUtilities($this, $head[1]); } $tmp_head = $js->combine_js(); $content = str_replace($head[1], $tmp_head, $content); } if (class_exists("WpFastestCachePowerfulHtml")) { $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); } } if ($this->err) { return $buffer . "<!-- " . $this->err . " -->"; } else { $content = $this->cacheDate($content); $content = $this->minify($content); if ($this->cdn) { $content = preg_replace_callback("/[\\'\"][^\\'\"]+" . preg_quote($this->cdn->originurl, "/") . "[^\\'\"]+[\\'\"]/i", array($this, 'cdn_replace_urls'), $content); // url() $content = preg_replace_callback("/url\\([^\\)]+\\)/i", array($this, 'cdn_replace_urls'), $content); } if (isset($this->options->wpFastestCacheRenderBlocking) && method_exists("WpFastestCachePowerfulHtml", "render_blocking")) { $content = $powerful_html->render_blocking($content); } $content = str_replace("<!--WPFC_FOOTER_START-->", "", $content); $this->createFolder($cachFilePath, $content); return $buffer . "<!-- need to refresh to see cached version -->"; } } } } } } } } } } } } } } } } } } }
public function callback($buffer) { $buffer = $this->checkShortCode($buffer); if (preg_match("/Mediapartners-Google/i", $_SERVER['HTTP_USER_AGENT'])) { return $buffer; } else { if ($this->exclude_page()) { return $buffer . "<!-- Wp Fastest Cache: Exclude Page -->"; } else { if ($this->is_xml($buffer)) { return $buffer . "<!-- Wp Fastest Cache: XML Content -->"; } else { if (is_user_logged_in() || $this->isCommenter()) { return $buffer; } else { if (preg_match("/json/i", $_SERVER["HTTP_ACCEPT"])) { return $buffer; } else { if ($this->checkWoocommerceSession()) { if ($this->checkHtml($buffer)) { return $buffer; } else { return $buffer . "<!-- \$_COOKIE['wp_woocommerce_session'] has been set -->"; } } else { if (defined('DONOTCACHEPAGE') && $this->isPluginActive('wordfence/wordfence.php')) { // for Wordfence: not to cache 503 pages return $buffer . "<!-- DONOTCACHEPAGE is defined as TRUE -->"; } else { if ($this->isPasswordProtected($buffer)) { return $buffer . "<!-- Password protected content has been detected -->"; } else { if ($this->isWpLogin($buffer)) { return $buffer; } else { if ($this->hasContactForm7WithCaptcha($buffer)) { return $buffer . "<!-- This page was not cached because ContactForm7's captcha -->"; } else { if (is_404()) { return $buffer; } else { if ($this->ignored()) { return $buffer . "<!-- ignored -->"; } else { if ($this->blockCache === true) { return $buffer . "<!-- wpfcNOT has been detected -->"; } else { if (isset($_GET["preview"])) { return $buffer . "<!-- not cached -->"; } else { if (preg_match("/\\?/", $_SERVER["REQUEST_URI"])) { return $buffer; } else { if ($this->checkHtml($buffer)) { return $buffer . "<!-- html is corrupted -->"; } else { if ($this->isMobile()) { if (class_exists("WpFcMobileCache") && isset($this->options->wpFastestCacheMobileTheme)) { $wpfc_mobile = new WpFcMobileCache(); $cachFilePath = $this->getWpContentDir() . "/cache/" . $wpfc_mobile->get_folder_name() . "" . $_SERVER["REQUEST_URI"]; } else { return $buffer . "<!-- mobile user -->"; } } else { $cachFilePath = $this->getWpContentDir() . "/cache/all" . $_SERVER["REQUEST_URI"]; } //to show cache version of home page via php if htaccess rewrite rule does not work if ($_SERVER["REQUEST_URI"] == "/") { if (file_exists($cachFilePath . "index.html")) { if ($content = @file_get_contents($cachFilePath . "index.html")) { return $content . "<!-- via php -->"; } } } $content = $this->cacheDate($buffer); if (isset($this->options->wpFastestCacheCombineCss) && isset($this->options->wpFastestCacheMinifyCss)) { require_once "css-utilities.php"; $css = new CssUtilities($this, $content); $content = $css->combineCss($this, true); //to minify css files which are NOT "media='all'" $content = $css->minifyCss($this, true); $this->err = $css->getError(); } else { if (isset($this->options->wpFastestCacheCombineCss)) { require_once "css-utilities.php"; $css = new CssUtilities($this, $content); $content = $css->combineCss($this, false); } else { if (isset($this->options->wpFastestCacheMinifyCss)) { require_once "css-utilities.php"; $css = new CssUtilities($this, $content); $content = $css->minifyCss($this, false); $this->err = $css->getError(); } } } if (isset($this->options->wpFastestCacheCombineJs)) { $content = $this->combineJs($content, false); } if (class_exists("WpFastestCachePowerfulHtml")) { $powerful_html = new WpFastestCachePowerfulHtml(); $powerful_html->set_html($content); if (isset($this->options->wpFastestCacheRemoveComments)) { $content = $powerful_html->remove_head_comments(); } if (isset($this->options->wpFastestCacheMinifyHtmlPowerFul)) { $content = $powerful_html->minify_html(); } } if ($this->err) { return $buffer . "<!-- " . $this->err . " -->"; } else { $content = $this->minify($content); $this->createFolder($cachFilePath, $content); return $buffer . "<!-- need to refresh to see cached version -->"; } } } } } } } } } } } } } } } } } }
public function callback($buffer) { $buffer = $this->checkShortCode($buffer); if (preg_match("/Mediapartners-Google|Google\\sWireless\\sTranscoder/i", $_SERVER['HTTP_USER_AGENT'])) { return $buffer; } else { if ($this->exclude_page()) { return $buffer . "<!-- Wp Fastest Cache: Exclude Page -->"; } else { if ($this->is_xml($buffer)) { return $buffer; } else { if (is_user_logged_in() || $this->isCommenter()) { return $buffer; } else { if (isset($_SERVER["HTTP_ACCEPT"]) && preg_match("/json/i", $_SERVER["HTTP_ACCEPT"])) { return $buffer; } else { if (isset($_COOKIE["wptouch-pro-view"])) { return $buffer . "<!-- \$_COOKIE['wptouch-pro-view'] has been set -->"; } else { if ($this->checkWoocommerceSession()) { if ($this->checkHtml($buffer)) { return $buffer; } else { return $buffer . "<!-- \$_COOKIE['wp_woocommerce_session'] has been set -->"; } } else { if (defined('DONOTCACHEPAGE') && $this->isPluginActive('wordfence/wordfence.php')) { // for Wordfence: not to cache 503 pages return $buffer . "<!-- DONOTCACHEPAGE is defined as TRUE -->"; } else { if ($this->isPasswordProtected($buffer)) { return $buffer . "<!-- Password protected content has been detected -->"; } else { if ($this->isWpLogin($buffer)) { return $buffer . "<!-- wp-login.php -->"; } else { if ($this->hasContactForm7WithCaptcha($buffer)) { return $buffer . "<!-- This page was not cached because ContactForm7's captcha -->"; } else { if (is_404()) { return $buffer; } else { if ($this->ignored()) { return $buffer; } else { if ($this->blockCache === true) { return $buffer . "<!-- wpfcNOT has been detected -->"; } else { if (isset($_GET["preview"])) { return $buffer . "<!-- not cached -->"; } else { if (preg_match("/\\?/", $_SERVER["REQUEST_URI"]) && !preg_match("/\\/\\?fdx\\_switcher\\=true/", $_SERVER["REQUEST_URI"])) { // for WP Mobile Edition return $buffer; } else { if ($this->checkHtml($buffer)) { return $buffer . "<!-- html is corrupted -->"; } else { $content = $buffer; if (isset($this->options->wpFastestCacheCombineCss)) { require_once "css-utilities.php"; $css = new CssUtilities($this, $content); $content = $css->combineCss(); } else { if (isset($this->options->wpFastestCacheMinifyCss)) { require_once "css-utilities.php"; $css = new CssUtilities($this, $content); $content = $css->minifyCss(); } } 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 = ""; $r = explode("<head", $content); if (isset($r[1])) { $r = explode("</head>", $r[1]); $head_new = $r[0]; } 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); } } if (class_exists("WpFastestCachePowerfulHtml")) { $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); } } if ($this->err) { return $buffer . "<!-- " . $this->err . " -->"; } else { $content = $this->cacheDate($content); $content = $this->minify($content); if ($this->cdn) { $content = preg_replace_callback("/[\\'\"][^\\'\"]+" . preg_quote($this->cdn->originurl, "/") . "[^\\'\"]+[\\'\"]/i", array($this, 'cdn_replace_urls'), $content); // url() $content = preg_replace_callback("/url\\([^\\)]+\\)/i", array($this, 'cdn_replace_urls'), $content); } if (isset($this->options->wpFastestCacheRenderBlocking) && method_exists("WpFastestCachePowerfulHtml", "render_blocking")) { $content = $powerful_html->render_blocking($content); } $content = str_replace("<!--WPFC_FOOTER_START-->", "", $content); if ($this->cacheFilePath) { $this->createFolder($this->cacheFilePath, $content); } return $buffer . "<!-- need to refresh to see cached version -->"; } } } } } } } } } } } } } } } } } } }
public function callback($buffer) { $buffer = $this->checkShortCode($buffer); if (preg_match("/Mediapartners-Google|Google\\sWireless\\sTranscoder/i", $_SERVER['HTTP_USER_AGENT'])) { return $buffer; } else { if ($this->is_xml($buffer)) { return $buffer; } else { if (is_user_logged_in() || $this->isCommenter()) { return $buffer; } else { if (isset($_SERVER["HTTP_ACCEPT"]) && preg_match("/json/i", $_SERVER["HTTP_ACCEPT"])) { return $buffer; } else { if (isset($_COOKIE["wptouch-pro-view"])) { return $buffer . "<!-- \$_COOKIE['wptouch-pro-view'] has been set -->"; } else { if ($this->checkWoocommerceSession()) { if ($this->checkHtml($buffer)) { return $buffer; } else { return $buffer . "<!-- \$_COOKIE['wp_woocommerce_session'] has been set -->"; } } else { if (defined('DONOTCACHEPAGE') && $this->isPluginActive('wordfence/wordfence.php')) { // for Wordfence: not to cache 503 pages return $buffer . "<!-- DONOTCACHEPAGE is defined as TRUE -->"; } else { if ($this->isPasswordProtected($buffer)) { return $buffer . "<!-- Password protected content has been detected -->"; } else { if ($this->isWpLogin($buffer)) { return $buffer . "<!-- wp-login.php -->"; } else { if ($this->hasContactForm7WithCaptcha($buffer)) { return $buffer . "<!-- This page was not cached because ContactForm7's captcha -->"; } else { if (is_404()) { return $buffer; } else { if ($this->ignored($buffer)) { return $buffer; } else { if ($this->blockCache === true) { return $buffer . "<!-- wpfcNOT has been detected -->"; } else { if (isset($_GET["preview"])) { return $buffer . "<!-- not cached -->"; } else { if ($this->checkHtml($buffer)) { return $buffer . "<!-- html is corrupted -->"; } else { if (function_exists("http_response_code") && (http_response_code() == 301 || http_response_code() == 302)) { return $buffer; } else { $content = $buffer; if (isset($this->options->wpFastestCacheRenderBlocking) && method_exists("WpFastestCachePowerfulHtml", "render_blocking")) { if (class_exists("WpFastestCachePowerfulHtml")) { $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 (!$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 . "<!-- " . $this->err . " -->"; } else { $content = $this->cacheDate($content); $content = $this->minify($content); if ($this->cdn) { $content = preg_replace_callback("/(srcset|src|href|data-lazyload)\\=[\\'\"]([^\\'\"]+)[\\'\"]/i", array($this, 'cdn_replace_urls'), $content); // url() $content = preg_replace_callback("/(url)\\(([^\\)]+)\\)/i", array($this, 'cdn_replace_urls'), $content); } if (isset($this->options->wpFastestCacheLazyLoad)) { include_once plugin_dir_path(__FILE__) . "pro/library/lazy-load.php"; if (method_exists("WpFastestCacheLazyLoad", "images_to_lazyload")) { $content = WpFastestCacheLazyLoad::images_to_lazyload($content, $this->options->wpFastestCacheLazyLoad_type); } } $content = str_replace("<!--WPFC_FOOTER_START-->", "", $content); if ($this->cacheFilePath) { $this->createFolder($this->cacheFilePath, $content); } return $content . "<!-- need to refresh to see cached version -->"; } } } } } } } } } } } } } } } } } }