Exemple #1
0
 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 -->";
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #2
0
 public function minify($url)
 {
     $this->url = $url;
     $cachFilePath = WPFC_WP_CONTENT_DIR . "/cache/wpfc-minified/" . md5($url);
     $cssLink = content_url() . "/cache/wpfc-minified/" . md5($url);
     if (is_dir($cachFilePath)) {
         if ($cssFiles = @scandir($cachFilePath, 1)) {
             if ($cssContent = $this->file_get_contents_curl($cssLink . "/" . $cssFiles[0])) {
                 return array("cachFilePath" => $cachFilePath, "cssContent" => $cssContent, "url" => $cssLink . "/" . $cssFiles[0], "realUrl" => $url);
             } else {
                 return false;
             }
         }
     } else {
         if ($cssContent = $this->file_get_contents_curl($url, "?v=" . time())) {
             $original_content_length = strlen($cssContent);
             $cssContent = $this->fixPathsInCssContent($cssContent, $url);
             if (isset($this->wpfc->options->wpFastestCacheMinifyCss) && $this->wpfc->options->wpFastestCacheMinifyCss) {
                 $cssContent = $this->_process($cssContent);
             }
             if (isset($this->wpfc->options->wpFastestCacheMinifyCssPowerFul) && $this->wpfc->options->wpFastestCacheMinifyCssPowerFul) {
                 if (class_exists("WpFastestCachePowerfulHtml")) {
                     $powerful_html = new WpFastestCachePowerfulHtml();
                     $cssContent = $powerful_html->minify_css($cssContent);
                 }
             }
             $cssContent = str_replace("", '', $cssContent);
             // If the content is empty, the file is not created. This breaks "combine css" feature
             if (strlen($cssContent) == 0 && $original_content_length > 0) {
                 return array("cssContent" => "", "url" => $url);
             }
             if (!is_dir($cachFilePath)) {
                 $prefix = time();
                 if ($this->wpfc->cdn) {
                     $cssContent = preg_replace_callback("/(url)\\(([^\\)]+)\\)/i", array($this->wpfc, 'cdn_replace_urls'), $cssContent);
                 }
                 $this->wpfc->createFolder($cachFilePath, $cssContent, "css", $prefix);
             }
             if ($cssFiles = @scandir($cachFilePath, 1)) {
                 return array("cachFilePath" => $cachFilePath, "cssContent" => $cssContent, "url" => $cssLink . "/" . $cssFiles[0], "realUrl" => $url);
             }
         }
     }
     return false;
 }
Exemple #3
0
 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 -->";
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #4
0
 public function minify($url)
 {
     $this->url = $url;
     $cachFilePath = WPFC_WP_CONTENT_DIR . "/cache/wpfc-minified/" . md5($url);
     $jsLink = content_url() . "/cache/wpfc-minified/" . md5($url);
     if (is_dir($cachFilePath)) {
         return array("cachFilePath" => $cachFilePath, "jsContent" => "", "url" => $jsLink);
     } else {
         if ($js = $this->file_get_contents_curl($url)) {
             if ($this->minify) {
                 if (class_exists("WpFastestCachePowerfulHtml")) {
                     $powerful_html = new WpFastestCachePowerfulHtml();
                     $js = $powerful_html->minify_js($js);
                 } else {
                     $js = "\n// source --> " . $url . " \n" . $js;
                 }
             } else {
                 $js = "\n// source --> " . $url . " \n" . $js;
             }
             return array("cachFilePath" => $cachFilePath, "jsContent" => $js, "url" => $jsLink);
         }
     }
     return false;
 }
 public function combineCss($wpfc, $minify = false)
 {
     if (count($this->getCssLinks()) > 0) {
         $prev = array("content" => "", "value" => array(), "name" => "");
         foreach ($this->getCssLinks() as $key => $value) {
             if ($href = $this->checkInternal($value)) {
                 if (preg_match("/\\.ttf/", $href)) {
                     continue;
                 }
                 if (strpos($this->getCssLinksExcept(), $href) === false && (preg_match("/media=[\\'\"]all[\\'\"]/", $value) || !preg_match("/media=/", $value))) {
                     $minifiedCss = $this->minify($href, $minify);
                     if ($minifiedCss) {
                         if ($minify && isset($wpfc->options->wpFastestCacheMinifyCssPowerFul)) {
                             $powerful_html = new WpFastestCachePowerfulHtml();
                             $minifiedCss["cssContent"] = $powerful_html->minify_css($minifiedCss["cssContent"]);
                         }
                         if (!is_dir($minifiedCss["cachFilePath"])) {
                             $prefix = time();
                             $wpfc->createFolder($minifiedCss["cachFilePath"], $minifiedCss["cssContent"], "css", $prefix);
                         }
                         if ($cssFiles = @scandir($minifiedCss["cachFilePath"], 1)) {
                             if ($cssContent = $this->file_get_contents_curl($minifiedCss["url"] . "/" . $cssFiles[0] . "?v=" . time())) {
                                 $prev["name"] .= $minifiedCss["realUrl"];
                                 $prev["content"] .= $cssContent . "\n";
                                 array_push($prev["value"], $value);
                             }
                         }
                     }
                 } else {
                     $prev["content"] = $this->fixRules($prev["content"]);
                     $this->mergeCss($wpfc, $prev);
                     $prev = array("content" => "", "value" => array());
                 }
             } else {
                 $prev["content"] = $this->fixRules($prev["content"]);
                 $this->mergeCss($wpfc, $prev);
                 $prev = array("content" => "", "value" => array());
             }
         }
         $prev["content"] = $this->fixRules($prev["content"]);
         $this->mergeCss($wpfc, $prev);
     }
     $this->html = preg_replace("/(<!-- )+/", "<!-- ", $this->html);
     $this->html = preg_replace("/( -->)+/", " -->", $this->html);
     return $this->html;
 }
 public function combineJs($content, $minify = false)
 {
     $minify = true;
     if (isset($this->options->wpFastestCacheCombineJs)) {
         require_once "js-utilities.php";
         $js = new JsUtilities($this, $content);
         if (count($js->getJsLinks()) > 0) {
             $prev = array("content" => "", "value" => array());
             foreach ($js->getJsLinks() as $key => $value) {
                 if ($href = $js->checkInternal($value)) {
                     if (strpos($js->getJsLinksExcept(), $href) === false) {
                         if (!preg_match("/<script[^>]+json[^>]+>.+/", $value)) {
                             $minifiedJs = $js->minify($href, $minify);
                             if ($minifiedJs) {
                                 if (!is_dir($minifiedJs["cachFilePath"])) {
                                     if (isset($this->options->wpFastestCacheCombineJsPowerFul)) {
                                         $powerful_html = new WpFastestCachePowerfulHtml();
                                         $minifiedJs["jsContent"] = $powerful_html->minify_js($minifiedJs["jsContent"]);
                                     }
                                     $prefix = time();
                                     $this->createFolder($minifiedJs["cachFilePath"], $minifiedJs["jsContent"], "js", $prefix);
                                 }
                                 if ($jsFiles = @scandir($minifiedJs["cachFilePath"], 1)) {
                                     if ($jsContent = $js->file_get_contents_curl($minifiedJs["url"] . "/" . $jsFiles[0] . "?v=" . time())) {
                                         $prev["content"] = $prev["content"] . "\n" . $jsContent;
                                         array_push($prev["value"], $value);
                                     }
                                 }
                             }
                         } else {
                             $content = $js->mergeJs($prev, $this);
                             $prev = array("content" => "", "value" => array());
                         }
                     } else {
                         $content = $js->mergeJs($prev, $this);
                         $prev = array("content" => "", "value" => array());
                     }
                 } else {
                     $content = $js->mergeJs($prev, $this);
                     $prev = array("content" => "", "value" => array());
                 }
             }
             $content = $js->mergeJs($prev, $this);
         }
     }
     $content = preg_replace("/(<!-- )+/", "<!-- ", $content);
     $content = preg_replace("/( -->)+/", " -->", $content);
     return $content;
 }
 public function minify($url)
 {
     $this->url = $url;
     $cachFilePath = WPFC_WP_CONTENT_DIR . "/cache/wpfc-minified/" . md5($url);
     $cssLink = content_url() . "/cache/wpfc-minified/" . md5($url);
     if (is_dir($cachFilePath)) {
         if ($cssFiles = @scandir($cachFilePath, 1)) {
             if ($cssContent = $this->file_get_contents_curl($cssLink . "/" . $cssFiles[0])) {
                 return array("cachFilePath" => $cachFilePath, "cssContent" => $cssContent, "url" => $cssLink . "/" . $cssFiles[0], "realUrl" => $url);
             } else {
                 return false;
             }
         }
     } else {
         if ($cssContent = $this->file_get_contents_curl($url . "?v=" . time())) {
             $cssContent = $this->fixPathsInCssContent($cssContent);
             if (isset($this->wpfc->options->wpFastestCacheMinifyCss) && $this->wpfc->options->wpFastestCacheMinifyCss) {
                 $cssContent = $this->_process($cssContent);
             }
             if (isset($this->wpfc->options->wpFastestCacheMinifyCssPowerFul) && $this->wpfc->options->wpFastestCacheMinifyCssPowerFul) {
                 if (class_exists("WpFastestCachePowerfulHtml")) {
                     $powerful_html = new WpFastestCachePowerfulHtml();
                     $cssContent = $powerful_html->minify_css($cssContent);
                 }
             }
             $cssContent = str_replace("", '', $cssContent);
             if (!is_dir($cachFilePath)) {
                 $prefix = time();
                 $this->wpfc->createFolder($cachFilePath, $cssContent, "css", $prefix);
             }
             if ($cssFiles = @scandir($cachFilePath, 1)) {
                 return array("cachFilePath" => $cachFilePath, "cssContent" => $cssContent, "url" => $cssLink . "/" . $cssFiles[0], "realUrl" => $url);
             }
         }
     }
     return false;
 }
Exemple #8
0
 public function mergeCss($wpfc, $prev)
 {
     if (count($prev["value"]) > 0) {
         $name = "";
         foreach ($prev["value"] as $prevKey => $prevValue) {
             if ($prevKey == count($prev["value"]) - 1) {
                 $name = md5($prev["name"]);
                 $cachFilePath = WPFC_WP_CONTENT_DIR . "/cache/wpfc-minified/" . $name;
                 $prev["content"] = $this->fixRules($prev["content"]);
                 if (isset($this->wpfc->options->wpFastestCacheMinifyCss) && $this->wpfc->options->wpFastestCacheMinifyCss) {
                     $prev["content"] = $this->_process($prev["content"]);
                 }
                 if (isset($this->wpfc->options->wpFastestCacheMinifyCssPowerFul) && $this->wpfc->options->wpFastestCacheMinifyCssPowerFul) {
                     $powerful_html = new WpFastestCachePowerfulHtml();
                     $prev["content"] = $powerful_html->minify_css($prev["content"]);
                 }
                 /* 
                 	The css files are saved in the previous function.
                 	If only one css file is in the array, there is need to save again.
                 */
                 if (count($prev["value"]) == 1) {
                     if ($cssFiles = @scandir($cachFilePath, 1)) {
                         file_put_contents($cachFilePath . "/" . $cssFiles[0], $prev["content"]);
                     }
                 } else {
                     if (!is_dir($cachFilePath)) {
                         $wpfc->createFolder($cachFilePath, $prev["content"], "css", time());
                     }
                 }
                 if ($cssFiles = @scandir($cachFilePath, 1)) {
                     $prefixLink = str_replace(array("http:", "https:"), "", content_url());
                     $newLink = "<link rel='stylesheet' href='" . $prefixLink . "/cache/wpfc-minified/" . $name . "/" . $cssFiles[0] . "' type='text/css' media='all' />";
                     $this->html = $wpfc->replaceLink($prevValue, "<!-- " . $prevValue . " -->" . "\n" . $newLink, $this->html);
                 }
             } else {
                 $name .= $prevValue;
                 $this->html = $wpfc->replaceLink($prevValue, "<!-- " . $prevValue . " -->", $this->html);
             }
         }
     }
 }
Exemple #9
0
 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 -->";
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }