public function set_cache_file_path() { if ($this->isMobile() && isset($this->options->wpFastestCacheMobile)) { if (class_exists("WpFcMobileCache") && isset($this->options->wpFastestCacheMobileTheme)) { $wpfc_mobile = new WpFcMobileCache(); $this->cacheFilePath = $this->getWpContentDir() . "/cache/" . $wpfc_mobile->get_folder_name() . "" . $_SERVER["REQUEST_URI"]; } } else { $this->cacheFilePath = $this->getWpContentDir() . "/cache/all" . $_SERVER["REQUEST_URI"]; // qTranslate: in name.com/de REQUEST_URI is "/" instead of "/de" so need to check it // if(isset($_SERVER["HTTP_COOKIE"]) && $_SERVER["HTTP_COOKIE"]){ // if(preg_match("/qtrans/i", $_SERVER["HTTP_COOKIE"])){ // if(isset($_SERVER["REDIRECT_URL"]) && $_SERVER["REDIRECT_URL"]){ // $this->cacheFilePath = $this->getWpContentDir()."/cache/all".$_SERVER["REDIRECT_URL"]; // } // } // } // [HTTP_COOKIE] => qtrans_front_language=en; _ga=GA1.2.1550945439.1457456694; _gat_awxoapTracker=1 } $this->cacheFilePath = $this->cacheFilePath ? rtrim($this->cacheFilePath, "/") . "/" : ""; if (strlen($_SERVER["REQUEST_URI"]) > 1) { // for the sub-pages if (!preg_match("/\\.html/i", $_SERVER["REQUEST_URI"])) { if ($this->is_trailing_slash()) { if (!preg_match("/\\/\$/", $_SERVER["REQUEST_URI"])) { $this->cacheFilePath = false; } } else { //toDo } } } }
public function set_cache_file_path() { if ($this->isMobile()) { if (class_exists("WpFcMobileCache") && isset($this->options->wpFastestCacheMobileTheme)) { $wpfc_mobile = new WpFcMobileCache(); $this->cacheFilePath = $this->getWpContentDir() . "/cache/" . $wpfc_mobile->get_folder_name() . "" . $_SERVER["REQUEST_URI"]; } } else { $this->cacheFilePath = $this->getWpContentDir() . "/cache/all" . $_SERVER["REQUEST_URI"]; // qTranslate: in name.com/de REQUEST_URI is "/" instead of "/de" so need to check it if (isset($_SERVER["HTTP_COOKIE"]) && $_SERVER["HTTP_COOKIE"]) { if (preg_match("/qtrans/i", $_SERVER["HTTP_COOKIE"])) { if (isset($_SERVER["REDIRECT_URL"]) && $_SERVER["REDIRECT_URL"]) { $this->cacheFilePath = $this->getWpContentDir() . "/cache/all" . $_SERVER["REDIRECT_URL"]; } } } } $this->cacheFilePath = $this->cacheFilePath ? rtrim($this->cacheFilePath, "/") . "/" : ""; }
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 delete_current_page_cache() { if (isset($_GET["path"])) { if ($_GET["path"]) { if ($_GET["path"] == "/") { $_GET["path"] = $_GET["path"] . "index.html"; } } else { $_GET["path"] = "/index.html"; } $paths = array(); array_push($paths, $this->getWpContentDir() . "/cache/all" . $_GET["path"]); if (class_exists("WpFcMobileCache")) { $wpfc_mobile = new WpFcMobileCache(); array_push($paths, $this->getWpContentDir() . "/cache/" . $wpfc_mobile->get_folder_name() . "" . $_GET["path"]); } foreach ($paths as $key => $value) { if (file_exists($value)) { $this->rm_folder_recursively($value); } } die(json_encode(array("The cache of page has been cleared", "success"))); } else { die(json_encode(array("Path has NOT been defined", "error", "alert"))); } exit; }
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 -->"; } } } } } } } } } } } } } } } } } }