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 getHtaccess() { $mobile = ""; $loggedInUser = ""; $ifIsNotSecure = ""; if (isset($_POST["wpFastestCacheMobile"]) && $_POST["wpFastestCacheMobile"] == "on") { $mobile = "RewriteCond %{HTTP_USER_AGENT} !^.*(" . $this->getMobileUserAgents() . ").*\$ [NC]" . "\n"; } if (isset($_POST["wpFastestCacheLoggedInUser"]) && $_POST["wpFastestCacheLoggedInUser"] == "on") { $loggedInUser = "******" . "\n"; } if (!preg_match("/^https/i", get_option("home"))) { $ifIsNotSecure = "RewriteCond %{HTTPS} !=on"; } $data = "# BEGIN WpFastestCache" . "\n" . "<IfModule mod_rewrite.c>" . "\n" . "RewriteEngine On" . "\n" . "RewriteBase /" . "\n" . $this->ruleForWpContent() . "\n" . $this->prefixRedirect() . $this->excludeRules() . "\n" . "RewriteCond %{HTTP_USER_AGENT} !(" . $this->get_excluded_useragent() . ")" . "\n" . "RewriteCond %{REQUEST_METHOD} !POST" . "\n" . $ifIsNotSecure . "\n" . "RewriteCond %{REQUEST_URI} !(\\/){2}\$" . "\n" . "RewriteCond %{QUERY_STRING} !.+" . "\n" . $loggedInUser . 'RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\\"]+ [NC]' . "\n" . 'RewriteCond %{HTTP:Profile} !^[a-z0-9\\"]+ [NC]' . "\n" . $mobile; if (ABSPATH == "//") { $data = $data . "RewriteCond %{DOCUMENT_ROOT}/" . WPFC_WP_CONTENT_BASENAME . "/cache/all/\$1/index.html -f" . "\n"; } else { $data = $data . "RewriteCond %{DOCUMENT_ROOT}/" . WPFC_WP_CONTENT_BASENAME . "/cache/all/\$1/index.html -f [or]" . "\n"; $data = $data . "RewriteCond " . WPFC_WP_CONTENT_DIR . "/cache/all/" . $this->getRewriteBase(true) . "\$1/index.html -f" . "\n"; } $data = $data . 'RewriteRule ^(.*) "/' . $this->getRewriteBase() . WPFC_WP_CONTENT_BASENAME . '/cache/all/' . $this->getRewriteBase(true) . '$1/index.html" [L]' . "\n"; //RewriteRule !/ "/wp-content/cache/all/index.html" [L] if (class_exists("WpFcMobileCache") && isset($this->options->wpFastestCacheMobileTheme) && $this->options->wpFastestCacheMobileTheme) { $wpfc_mobile = new WpFcMobileCache(); if ($this->isPluginActive('wptouch/wptouch.php') || $this->isPluginActive('wptouch-pro/wptouch-pro.php')) { $wpfc_mobile->set_wptouch(true); } else { $wpfc_mobile->set_wptouch(false); } $data = $data . "\n\n\n" . $wpfc_mobile->update_htaccess($data); } $data = $data . "</IfModule>" . "\n" . "<FilesMatch \"\\.(html|htm)\$\">" . "\n" . "AddDefaultCharset UTF-8" . "\n" . "<ifModule mod_headers.c>" . "\n" . "FileETag None" . "\n" . "Header unset ETag" . "\n" . "Header set Cache-Control \"max-age=0, no-cache, no-store, must-revalidate\"" . "\n" . "Header set Pragma \"no-cache\"" . "\n" . "Header set Expires \"Mon, 29 Oct 1923 20:30:00 GMT\"" . "\n" . "</ifModule>" . "\n" . "</FilesMatch>" . "\n" . "# END WpFastestCache" . "\n"; return preg_replace("/\n+/", "\n", $data); }
public function deleteCache($minified = false) { $this->set_preload(); delete_option("WpFastestCacheHTML"); delete_option("WpFastestCacheHTMLSIZE"); delete_option("WpFastestCacheMOBILE"); delete_option("WpFastestCacheMOBILESIZE"); if (class_exists("WpFcMobileCache")) { $wpfc_mobile = new WpFcMobileCache(); $wpfc_mobile->delete_cache($this->getWpContentDir()); wp_schedule_single_event(time() + 60, $this->slug() . "_TmpDelete_" . time()); } $deleted = false; $cache_path = $this->getWpContentDir() . "/cache/all"; $minified_cache_path = $this->getWpContentDir() . "/cache/wpfc-minified"; if (!is_dir($this->getWpContentDir() . "/cache/tmpWpfc")) { if (@mkdir($this->getWpContentDir() . "/cache/tmpWpfc", 0755, true)) { // } else { $this->systemMessage = array("Permission of <strong>/wp-content/cache</strong> must be <strong>755</strong>", "error"); } } if (is_dir($cache_path)) { rename($cache_path, $this->getWpContentDir() . "/cache/tmpWpfc/" . time()); $deleted = true; } if (is_dir($minified_cache_path)) { if ($minified) { rename($minified_cache_path, $this->getWpContentDir() . "/cache/tmpWpfc/m" . time()); $deleted = true; } } if ($deleted) { wp_schedule_single_event(time() + 60, $this->slug() . "_TmpDelete_" . time()); $this->systemMessage = array("All cache files have been deleted", "success"); if ($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")) { include_once $this->get_premium_path("logs.php"); $log = new WpFastestCacheLogs("delete"); $log->action(); } } else { $this->systemMessage = array("Already deleted", "success"); } }
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 deleteCache($minified = false) { $this->set_preload(); $created_tmpWpfc = false; $cache_deleted = false; $minifed_deleted = false; $cache_path = $this->getWpContentDir() . "/cache/all"; $minified_cache_path = $this->getWpContentDir() . "/cache/wpfc-minified"; if (class_exists("WpFcMobileCache")) { $wpfc_mobile = new WpFcMobileCache(); $wpfc_mobile->delete_cache($this->getWpContentDir()); } if (!is_dir($this->getWpContentDir() . "/cache/tmpWpfc")) { if (@mkdir($this->getWpContentDir() . "/cache/tmpWpfc", 0755, true)) { $created_tmpWpfc = true; } else { $created_tmpWpfc = false; //$this->systemMessage = array("Permission of <strong>/wp-content/cache</strong> must be <strong>755</strong>", "error"); } } else { $created_tmpWpfc = true; } if (is_dir($cache_path)) { if (@rename($cache_path, $this->getWpContentDir() . "/cache/tmpWpfc/" . time())) { delete_option("WpFastestCacheHTML"); delete_option("WpFastestCacheHTMLSIZE"); delete_option("WpFastestCacheMOBILE"); delete_option("WpFastestCacheMOBILESIZE"); $cache_deleted = true; } } else { $cache_deleted = true; } if ($minified) { if (is_dir($minified_cache_path)) { if (@rename($minified_cache_path, $this->getWpContentDir() . "/cache/tmpWpfc/m" . time())) { delete_option("WpFastestCacheCSS"); delete_option("WpFastestCacheCSSSIZE"); delete_option("WpFastestCacheJS"); delete_option("WpFastestCacheJSSIZE"); $minifed_deleted = true; } } else { $minifed_deleted = true; } } else { $minifed_deleted = true; } if ($created_tmpWpfc && $cache_deleted && $minifed_deleted) { $this->systemMessage = array("All cache files have been deleted", "success"); if ($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")) { include_once $this->get_premium_path("logs.php"); $log = new WpFastestCacheLogs("delete"); $log->action(); } } else { $this->systemMessage = array("Permissions Problem: <a href='http://www.wpfastestcache.com/warnings/delete-cache-problem-related-to-permission/' target='_blank'>Read More</a>", "error", array("light_box" => "delete_cache_permission_error")); } // for ajax request if (isset($_GET["action"]) && in_array($_GET["action"], array("wpfc_delete_cache", "wpfc_delete_cache_and_minified"))) { die(json_encode($this->systemMessage)); } }
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 -->"; } } } } } } } } } } } } } } } } } }