wp-fastest-cache
Last commit date
css
2 years ago
images
2 years ago
inc
2 years ago
js
2 years ago
languages
2 years ago
templates
2 years ago
index.html
11 years ago
readme.txt
2 years ago
uninstall.php
2 years ago
wpFastestCache.php
2 years ago
wpFastestCache.php
2541 lines
| 1 | <?php |
| 2 | /* |
| 3 | Plugin Name: WP Fastest Cache |
| 4 | Plugin URI: http://wordpress.org/plugins/wp-fastest-cache/ |
| 5 | Description: The simplest and fastest WP Cache system |
| 6 | Version: 1.2.2 |
| 7 | Author: Emre Vona |
| 8 | Author URI: https://www.wpfastestcache.com/ |
| 9 | Text Domain: wp-fastest-cache |
| 10 | Domain Path: /languages/ |
| 11 | |
| 12 | Copyright (C)2013 Emre Vona |
| 13 | |
| 14 | This program is free software; you can redistribute it and/or |
| 15 | modify it under the terms of the GNU General Public License |
| 16 | as published by the Free Software Foundation; either version 2 |
| 17 | of the License, or (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, |
| 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | GNU General Public License for more details. |
| 23 | */ |
| 24 | |
| 25 | if (!defined('WPFC_WP_CONTENT_BASENAME')) { |
| 26 | if (!defined('WPFC_WP_PLUGIN_DIR')) { |
| 27 | if(preg_match("/(\/trunk\/|\/wp-fastest-cache\/)$/", plugin_dir_path( __FILE__ ))){ |
| 28 | define("WPFC_WP_PLUGIN_DIR", preg_replace("/(\/trunk\/|\/wp-fastest-cache\/)$/", "", plugin_dir_path( __FILE__ ))); |
| 29 | }else if(preg_match("/\\\wp-fastest-cache\/$/", plugin_dir_path( __FILE__ ))){ |
| 30 | //D:\hosting\LINEapp\public_html\wp-content\plugins\wp-fastest-cache/ |
| 31 | define("WPFC_WP_PLUGIN_DIR", preg_replace("/\\\wp-fastest-cache\/$/", "", plugin_dir_path( __FILE__ ))); |
| 32 | } |
| 33 | } |
| 34 | define("WPFC_WP_CONTENT_DIR", dirname(WPFC_WP_PLUGIN_DIR)); |
| 35 | define("WPFC_WP_CONTENT_BASENAME", basename(WPFC_WP_CONTENT_DIR)); |
| 36 | } |
| 37 | |
| 38 | if (!defined('WPFC_MAIN_PATH')) { |
| 39 | define("WPFC_MAIN_PATH", plugin_dir_path( __FILE__ )); |
| 40 | } |
| 41 | |
| 42 | if(!isset($GLOBALS["wp_fastest_cache_options"])){ |
| 43 | if($wp_fastest_cache_options = get_option("WpFastestCache")){ |
| 44 | $GLOBALS["wp_fastest_cache_options"] = json_decode($wp_fastest_cache_options); |
| 45 | }else{ |
| 46 | $GLOBALS["wp_fastest_cache_options"] = array(); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | function wpfastestcache_activate(){ |
| 51 | if($options = get_option("WpFastestCache")){ |
| 52 | $post = json_decode($options, true); |
| 53 | |
| 54 | include_once('inc/admin.php'); |
| 55 | $wpfc = new WpFastestCacheAdmin(); |
| 56 | $wpfc->modifyHtaccess($post); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | function wpfastestcache_deactivate(){ |
| 61 | $wpfc = new WpFastestCache(); |
| 62 | |
| 63 | $path = ABSPATH; |
| 64 | |
| 65 | if($wpfc->is_subdirectory_install()){ |
| 66 | $path = $wpfc->getABSPATH(); |
| 67 | } |
| 68 | |
| 69 | if(is_file($path.".htaccess") && is_writable($path.".htaccess")){ |
| 70 | $htaccess = file_get_contents($path.".htaccess"); |
| 71 | $htaccess = preg_replace("/#\s?BEGIN\s?WpFastestCache.*?#\s?END\s?WpFastestCache/s", "", $htaccess); |
| 72 | $htaccess = preg_replace("/#\s?BEGIN\s?GzipWpFastestCache.*?#\s?END\s?GzipWpFastestCache/s", "", $htaccess); |
| 73 | $htaccess = preg_replace("/#\s?BEGIN\s?LBCWpFastestCache.*?#\s?END\s?LBCWpFastestCache/s", "", $htaccess); |
| 74 | $htaccess = preg_replace("/#\s?BEGIN\s?WEBPWpFastestCache.*?#\s?END\s?WEBPWpFastestCache/s", "", $htaccess); |
| 75 | @file_put_contents($path.".htaccess", $htaccess); |
| 76 | } |
| 77 | |
| 78 | $wpfc->deleteCache(); |
| 79 | } |
| 80 | |
| 81 | register_activation_hook( __FILE__, "wpfastestcache_activate"); |
| 82 | register_deactivation_hook( __FILE__, "wpfastestcache_deactivate"); |
| 83 | |
| 84 | class WpFastestCache{ |
| 85 | private $systemMessage = ""; |
| 86 | private $options = array(); |
| 87 | public $noscript = ""; |
| 88 | public $content_url = ""; |
| 89 | public $deleted_before = false; |
| 90 | |
| 91 | public function __construct(){ |
| 92 | $this->set_content_url(); |
| 93 | |
| 94 | $optimize_image_ajax_requests = array("wpfc_revert_image_ajax_request", |
| 95 | "wpfc_statics_ajax_request", |
| 96 | "wpfc_optimize_image_ajax_request", |
| 97 | "wpfc_update_image_list_ajax_request" |
| 98 | ); |
| 99 | |
| 100 | add_action('wp_ajax_wpfc_delete_cache', array($this, "deleteCacheToolbar")); |
| 101 | add_action('wp_ajax_wpfc_delete_cache_and_minified', array($this, "deleteCssAndJsCacheToolbar")); |
| 102 | add_action('wp_ajax_wpfc_delete_current_page_cache', array($this, "delete_current_page_cache")); |
| 103 | |
| 104 | add_action('wp_ajax_wpfc_clear_cache_of_allsites', array($this, "wpfc_clear_cache_of_allsites_callback")); |
| 105 | |
| 106 | add_action('wp_ajax_wpfc_toolbar_save_settings', array($this, "wpfc_toolbar_save_settings_callback")); |
| 107 | add_action('wp_ajax_wpfc_toolbar_get_settings', array($this, "wpfc_toolbar_get_settings_callback")); |
| 108 | |
| 109 | //add_action('wp_ajax_wpfc_cache_path_save_settings', array($this, "wpfc_cache_path_save_settings_callback")); |
| 110 | |
| 111 | add_action( 'wp_ajax_wpfc_save_timeout_pages', array($this, 'wpfc_save_timeout_pages_callback')); |
| 112 | add_action( 'wp_ajax_wpfc_save_exclude_pages', array($this, 'wpfc_save_exclude_pages_callback')); |
| 113 | add_action( 'wp_ajax_wpfc_cdn_options', array($this, 'wpfc_cdn_options_ajax_request_callback')); |
| 114 | add_action( 'wp_ajax_wpfc_remove_cdn_integration', array($this, 'wpfc_remove_cdn_integration_ajax_request_callback')); |
| 115 | add_action( 'wp_ajax_wpfc_pause_cdn_integration', array($this, 'wpfc_pause_cdn_integration_ajax_request_callback')); |
| 116 | add_action( 'wp_ajax_wpfc_start_cdn_integration', array($this, 'wpfc_start_cdn_integration_ajax_request_callback')); |
| 117 | add_action( 'wp_ajax_wpfc_save_cdn_integration', array($this, 'wpfc_save_cdn_integration_ajax_request_callback')); |
| 118 | add_action( 'wp_ajax_wpfc_cdn_template', array($this, 'wpfc_cdn_template_ajax_request_callback')); |
| 119 | add_action( 'wp_ajax_wpfc_check_url', array($this, 'wpfc_check_url_ajax_request_callback')); |
| 120 | add_action( 'wp_ajax_wpfc_cache_statics_get', array($this, 'wpfc_cache_statics_get_callback')); |
| 121 | add_action( 'wp_ajax_wpfc_db_statics', array($this, 'wpfc_db_statics_callback')); |
| 122 | add_action( 'wp_ajax_wpfc_db_fix', array($this, 'wpfc_db_fix_callback')); |
| 123 | add_action( 'rate_post', array($this, 'wp_postratings_clear_fastest_cache'), 10, 2); |
| 124 | add_action( 'user_register', array($this, 'modify_htaccess_for_new_user'), 10, 1); |
| 125 | add_action( 'profile_update', array($this, 'modify_htaccess_for_new_user'), 10, 1); |
| 126 | add_action( 'edit_terms', array($this, 'delete_cache_of_term'), 10, 1); |
| 127 | |
| 128 | add_action( 'wp_ajax_wpfc_save_csp', array($this, 'wpfc_save_csp_callback')); |
| 129 | add_action( 'wp_ajax_wpfc_remove_csp', array($this, 'wpfc_remove_csp_callback')); |
| 130 | add_action( 'wp_ajax_wpfc_get_list_csp', array($this, 'wpfc_get_list_csp_callback')); |
| 131 | |
| 132 | |
| 133 | add_action( 'wp_ajax_wpfc_save_varnish', array($this, 'wpfc_save_varnish_callback')); |
| 134 | add_action( 'wp_ajax_wpfc_remove_varnish', array($this, 'wpfc_remove_varnish_callback')); |
| 135 | add_action( 'wp_ajax_wpfc_pause_varnish', array($this, 'wpfc_pause_varnish_callback')); |
| 136 | add_action( 'wp_ajax_wpfc_start_varnish', array($this, 'wpfc_start_varnish_callback')); |
| 137 | add_action( 'wp_ajax_wpfc_purgecache_varnish', array($this, 'wpfc_purgecache_varnish_callback')); |
| 138 | |
| 139 | |
| 140 | if(defined("WPFC_CLEAR_CACHE_AFTER_SWITCH_THEME") && WPFC_CLEAR_CACHE_AFTER_SWITCH_THEME){ |
| 141 | add_action('after_switch_theme', array($this, 'clear_cache_after_switch_theme')); |
| 142 | } |
| 143 | |
| 144 | if(defined("WPFC_CLEAR_CACHE_AFTER_ACTIVATE_DEACTIVATE_PLUGIN") && WPFC_CLEAR_CACHE_AFTER_ACTIVATE_DEACTIVATE_PLUGIN){ |
| 145 | add_action('activate_plugin', array($this, 'clear_cache_after_activate_plugin')); |
| 146 | add_action('deactivate_plugin', array($this, 'clear_cache_after_deactivate_plugin')); |
| 147 | } |
| 148 | |
| 149 | |
| 150 | add_action('upgrader_process_complete', array($this, 'clear_cache_after_update_plugin'), 10, 2); |
| 151 | add_action('upgrader_process_complete', array($this, 'clear_cache_after_update_theme'), 10, 2); |
| 152 | |
| 153 | |
| 154 | if(defined("WPFC_DISABLE_CLEARING_CACHE_AFTER_WOOCOMMERCE_CHECKOUT_ORDER_PROCESSED") && WPFC_DISABLE_CLEARING_CACHE_AFTER_WOOCOMMERCE_CHECKOUT_ORDER_PROCESSED){ |
| 155 | }else if(defined("WPFC_DISABLE_CLEARING_CACHE_AFTER_WOOCOMMERCE_ORDER_STATUS_CHANGED") && WPFC_DISABLE_CLEARING_CACHE_AFTER_WOOCOMMERCE_ORDER_STATUS_CHANGED){ |
| 156 | }else{ |
| 157 | // to clear cache after new Woocommerce orders |
| 158 | add_action('woocommerce_order_status_changed', array($this, 'clear_cache_after_woocommerce_order_status_changed'), 1, 1); |
| 159 | } |
| 160 | |
| 161 | |
| 162 | // kk Star Ratings: to clear the cache of the post after voting |
| 163 | add_action('kksr_rate', array($this, 'clear_cache_on_kksr_rate')); |
| 164 | |
| 165 | // Elementor: to clear cache after Maintenance Mode activation/deactivation |
| 166 | add_action('elementor/maintenance_mode/mode_changed', array($this, 'deleteCache')); |
| 167 | |
| 168 | // clearing cache hooks |
| 169 | add_action("wpfc_clear_all_cache", array($this, 'deleteCache'), 10, 1); |
| 170 | add_action("wpfc_clear_all_site_cache", array($this, 'wpfc_clear_cache_of_allsites_callback')); |
| 171 | add_action("wpfc_clear_post_cache_by_id", array($this, 'singleDeleteCache'), 10, 2); |
| 172 | |
| 173 | // create cache by id hook |
| 174 | add_action("wpfc_create_post_cache_by_id", array($this, 'create_post_cache_by_id'), 10, 1); |
| 175 | |
| 176 | // to enable Auto Cache Panel for the classic editor |
| 177 | add_action( 'admin_init', array($this, 'enable_auto_cache_settings_panel')); |
| 178 | |
| 179 | // to add settings link |
| 180 | add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array($this, 'action_links')); |
| 181 | |
| 182 | // to clear cache after ajax request by other plugins |
| 183 | if(isset($_POST["action"])){ |
| 184 | // All In One Schema.org Rich Snippets |
| 185 | if(preg_match("/bsf_(update|submit)_rating/i", $_POST["action"])){ |
| 186 | if(isset($_POST["post_id"])){ |
| 187 | $this->singleDeleteCache(false, $_POST["post_id"]); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // Yet Another Stars Rating |
| 192 | if($_POST["action"] == "yasr_send_visitor_rating"){ |
| 193 | if(isset($_POST["post_id"])){ |
| 194 | // to need call like that because get_permalink() does not work if we call singleDeleteCache() directly |
| 195 | add_action('init', array($this, "singleDeleteCache")); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | // to clear /tmpWpfc folder |
| 201 | if(is_dir($this->getWpContentDir("/cache/tmpWpfc"))){ |
| 202 | $this->rm_folder_recursively($this->getWpContentDir("/cache/tmpWpfc")); |
| 203 | } |
| 204 | |
| 205 | |
| 206 | if($this->isPluginActive('wp-polls/wp-polls.php')){ |
| 207 | //for WP-Polls |
| 208 | require_once "inc/wp-polls.php"; |
| 209 | $wp_polls = new WpPollsForWpFc(); |
| 210 | $wp_polls->hook(); |
| 211 | } |
| 212 | |
| 213 | if(isset($_GET) && isset($_GET["action"]) && in_array($_GET["action"], $optimize_image_ajax_requests)){ |
| 214 | if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){ |
| 215 | include_once $this->get_premium_path("image.php"); |
| 216 | $img = new WpFastestCacheImageOptimisation(); |
| 217 | $img->hook(); |
| 218 | } |
| 219 | }else if(isset($_GET) && isset($_GET["action"]) && $_GET["action"] == "wpfastestcache"){ |
| 220 | if(isset($_GET) && isset($_GET["type"]) && $_GET["type"] == "preload"){ |
| 221 | // /?action=wpfastestcache&type=preload |
| 222 | |
| 223 | add_action('init', array($this, "create_preload_cache"), 11); |
| 224 | } |
| 225 | |
| 226 | if(isset($_GET) && isset($_GET["type"]) && preg_match("/^clearcache(andminified|allsites)*$/i", $_GET["type"])){ |
| 227 | // /?action=wpfastestcache&type=clearcache&token=123 |
| 228 | // /?action=wpfastestcache&type=clearcacheandminified&token=123 |
| 229 | |
| 230 | if(isset($_GET["token"]) && $_GET["token"]){ |
| 231 | if(defined("WPFC_CLEAR_CACHE_URL_TOKEN") && WPFC_CLEAR_CACHE_URL_TOKEN){ |
| 232 | if(WPFC_CLEAR_CACHE_URL_TOKEN == $_GET["token"]){ |
| 233 | if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){ |
| 234 | include_once $this->get_premium_path("mobile-cache.php"); |
| 235 | } |
| 236 | |
| 237 | if($_GET["type"] == "clearcache"){ |
| 238 | $this->deleteCache(); |
| 239 | } |
| 240 | |
| 241 | if($_GET["type"] == "clearcacheandminified"){ |
| 242 | $this->deleteCache(true); |
| 243 | } |
| 244 | |
| 245 | if($_GET["type"] == "clearcacheallsites"){ |
| 246 | $this->wpfc_clear_cache_of_allsites_callback(); |
| 247 | } |
| 248 | |
| 249 | die("Done"); |
| 250 | }else{ |
| 251 | die("Wrong token"); |
| 252 | } |
| 253 | }else{ |
| 254 | die("WPFC_CLEAR_CACHE_URL_TOKEN must be defined"); |
| 255 | } |
| 256 | }else{ |
| 257 | die("Security token must be set."); |
| 258 | } |
| 259 | } |
| 260 | }else{ |
| 261 | $this->setCustomInterval(); |
| 262 | |
| 263 | $this->options = $this->getOptions(); |
| 264 | |
| 265 | add_action('transition_post_status', array($this, 'on_all_status_transitions'), 10, 3 ); |
| 266 | |
| 267 | // when the regular price is updated, the "transition_post_status" action cannot catch it |
| 268 | add_action('woocommerce_update_product', array($this, 'clear_cache_after_woocommerce_update_product'), 10, 1); |
| 269 | |
| 270 | $this->commentHooks(); |
| 271 | |
| 272 | $this->checkCronTime(); |
| 273 | |
| 274 | if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){ |
| 275 | include_once $this->get_premium_path("mobile-cache.php"); |
| 276 | |
| 277 | if(file_exists(WPFC_WP_PLUGIN_DIR."/wp-fastest-cache-premium/pro/library/statics.php")){ |
| 278 | include_once $this->get_premium_path("statics.php"); |
| 279 | } |
| 280 | |
| 281 | if(!defined('DOING_AJAX')){ |
| 282 | include_once $this->get_premium_path("powerful-html.php"); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | if(is_admin()){ |
| 287 | add_action('wp_loaded', array($this, "load_column")); |
| 288 | |
| 289 | if(defined('DOING_AJAX') && DOING_AJAX){ |
| 290 | //do nothing |
| 291 | }else{ |
| 292 | // to avoid loading menu and optionPage() twice |
| 293 | if(!class_exists("WpFastestCacheAdmin")){ |
| 294 | //for wp-panel |
| 295 | |
| 296 | if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){ |
| 297 | include_once $this->get_premium_path("image.php"); |
| 298 | } |
| 299 | |
| 300 | if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){ |
| 301 | include_once $this->get_premium_path("logs.php"); |
| 302 | } |
| 303 | |
| 304 | add_action('plugins_loaded', array($this, 'wpfc_load_plugin_textdomain')); |
| 305 | add_action('wp_loaded', array($this, "load_admin_toolbar")); |
| 306 | |
| 307 | $this->admin(); |
| 308 | } |
| 309 | } |
| 310 | }else{ |
| 311 | if(preg_match("/\/([^\/]+)\/([^\/]+(\.css|\.js))(\?.+)?$/", $this->current_url(), $path)){ |
| 312 | // for security |
| 313 | if(preg_match("/\.{2,}/", $this->current_url())){ |
| 314 | die("May be Directory Traversal Attack"); |
| 315 | } |
| 316 | |
| 317 | if(is_dir($this->getWpContentDir("/cache/wpfc-minified/").$path[1])){ |
| 318 | if($sources = @scandir($this->getWpContentDir("/cache/wpfc-minified/").$path[1], 1)){ |
| 319 | if(isset($sources[0])){ |
| 320 | // $exist_url = str_replace($path[2], $sources[0], $this->current_url()); |
| 321 | // header('Location: ' . $exist_url, true, 301); |
| 322 | // exit; |
| 323 | |
| 324 | if(preg_match("/\.css/", $this->current_url())){ |
| 325 | header('Content-type: text/css'); |
| 326 | }else if(preg_match("/\.js/", $this->current_url())){ |
| 327 | header('Content-type: text/js'); |
| 328 | } |
| 329 | |
| 330 | echo file_get_contents($this->getWpContentDir("/cache/wpfc-minified/").$path[1]."/".$sources[0]); |
| 331 | exit; |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | |
| 337 | if(preg_match("/".basename($this->getWpContentDir("/cache/wpfc-minified/"))."/i", $this->current_url())){ |
| 338 | //for non-exists minified files |
| 339 | if(preg_match("/\.css/", $this->current_url())){ |
| 340 | header('Content-type: text/css'); |
| 341 | die("/* File not found */"); |
| 342 | }else if(preg_match("/\.js/", $this->current_url())){ |
| 343 | header('Content-type: text/js'); |
| 344 | die("//File not found"); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | }else{ |
| 349 | // to show if the user is logged-in |
| 350 | add_action('wp_loaded', array($this, "load_admin_toolbar")); |
| 351 | |
| 352 | //for cache |
| 353 | $this->cache(); |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | public function enable_auto_cache_settings_panel(){ |
| 360 | if($this->isPluginActive('classic-editor/classic-editor.php') || $this->isPluginActive('disable-gutenberg/disable-gutenberg.php') || has_filter("use_block_editor_for_post", "__return_false")){ |
| 361 | add_action("add_meta_boxes", array($this, "add_meta_box"), 10, 2); |
| 362 | add_action('admin_notices', array($this, 'single_preload_inline_js')); |
| 363 | add_action('wp_ajax_wpfc_preload_single_save_settings', array($this, "wpfc_preload_single_save_settings_callback")); |
| 364 | add_action('wp_ajax_wpfc_preload_single', array($this, "wpfc_preload_single_callback")); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | public function clear_cache_after_activate_plugin(){ |
| 369 | $this->deleteCache(true); |
| 370 | } |
| 371 | |
| 372 | public function clear_cache_after_deactivate_plugin(){ |
| 373 | $this->deleteCache(true); |
| 374 | } |
| 375 | |
| 376 | public function clear_cache_after_switch_theme(){ |
| 377 | $this->deleteCache(true); |
| 378 | } |
| 379 | |
| 380 | public function clear_cache_after_update_plugin($upgrader_object, $options){ |
| 381 | if(isset($options['action']) && isset($options['type'])){ |
| 382 | if($options['action'] == 'update'){ |
| 383 | if($options['type'] == 'plugin' && (isset($options['plugins']) || isset($options['plugin']))){ |
| 384 | |
| 385 | $options_json = json_encode($options); |
| 386 | |
| 387 | if(preg_match("/elementor\\\\\/elementor\.php/i", $options_json)){ |
| 388 | $this->deleteCache(true); |
| 389 | } |
| 390 | |
| 391 | if(defined("WPFC_CLEAR_CACHE_AFTER_PLUGIN_UPDATE") && WPFC_CLEAR_CACHE_AFTER_PLUGIN_UPDATE){ |
| 392 | $this->deleteCache(true); |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | public function clear_cache_after_update_theme($upgrader_object, $options){ |
| 400 | if(isset($options['action']) && isset($options['type'])){ |
| 401 | if($options['action'] == 'update'){ |
| 402 | if($options['type'] == 'theme' && isset($options['themes'])){ |
| 403 | |
| 404 | if(defined("WPFC_CLEAR_CACHE_AFTER_THEME_UPDATE") && WPFC_CLEAR_CACHE_AFTER_THEME_UPDATE){ |
| 405 | $this->deleteCache(true); |
| 406 | } |
| 407 | |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | public function action_links($actions){ |
| 414 | $actions['powered_settings'] = sprintf(__( '<a href="%s">Settings</a>', 'wp-fastest-cache'), esc_url( admin_url( 'admin.php?page=wpfastestcacheoptions'))); |
| 415 | return array_reverse($actions); |
| 416 | } |
| 417 | |
| 418 | public function wpfc_preload_single_callback(){ |
| 419 | if(!wp_verify_nonce($_REQUEST["nonce"], 'wpfc')){ |
| 420 | die( 'Security check' ); |
| 421 | } |
| 422 | |
| 423 | include_once('inc/single-preload.php'); |
| 424 | SinglePreloadWPFC::create_cache(); |
| 425 | } |
| 426 | |
| 427 | public function create_post_cache_by_id($id){ |
| 428 | include_once('inc/single-preload.php'); |
| 429 | SinglePreloadWPFC::init($id); |
| 430 | $res = SinglePreloadWPFC::create_cache_for_all_urls(); |
| 431 | |
| 432 | return $res; |
| 433 | } |
| 434 | |
| 435 | public function single_preload_inline_js(){ |
| 436 | include_once('inc/single-preload.php'); |
| 437 | SinglePreloadWPFC::init(); |
| 438 | SinglePreloadWPFC::put_inline_js(); |
| 439 | } |
| 440 | public function add_meta_box(){ |
| 441 | include_once('inc/single-preload.php'); |
| 442 | SinglePreloadWPFC::add_meta_box(); |
| 443 | } |
| 444 | |
| 445 | public function wpfc_preload_single_save_settings_callback(){ |
| 446 | if(!wp_verify_nonce($_REQUEST["nonce"], 'wpfc')){ |
| 447 | die( 'Security check' ); |
| 448 | } |
| 449 | |
| 450 | include_once('inc/single-preload.php'); |
| 451 | SinglePreloadWPFC::save_settings(); |
| 452 | } |
| 453 | |
| 454 | public function notify($message = array()){ |
| 455 | if(isset($message[0]) && $message[0]){ |
| 456 | if(function_exists("add_settings_error")){ |
| 457 | add_settings_error('wpfc-notice', esc_attr( 'settings_updated' ), $message[0], $message[1]); |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | public function set_content_url(){ |
| 463 | $content_url = content_url(); |
| 464 | |
| 465 | // Hide My WP |
| 466 | if($this->isPluginActive('hide_my_wp/hide-my-wp.php')){ |
| 467 | $hide_my_wp = get_option("hide_my_wp"); |
| 468 | |
| 469 | if(isset($hide_my_wp["new_content_path"]) && $hide_my_wp["new_content_path"]){ |
| 470 | $hide_my_wp["new_content_path"] = trim($hide_my_wp["new_content_path"], "/"); |
| 471 | $content_url = str_replace(basename(WPFC_WP_CONTENT_DIR), $hide_my_wp["new_content_path"], $content_url); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | // to change content url if a different url is used for other langs |
| 476 | if($this->isPluginActive('polylang/polylang.php') || $this->isPluginActive('polylang-pro/polylang.php')){ |
| 477 | $url = parse_url($content_url); |
| 478 | |
| 479 | if($url["host"] != $_SERVER['HTTP_HOST']){ |
| 480 | $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; |
| 481 | $content_url = $protocol.$_SERVER['HTTP_HOST'].$url['path']; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | if (!defined('WPFC_WP_CONTENT_URL')) { |
| 486 | define("WPFC_WP_CONTENT_URL", $content_url); |
| 487 | } |
| 488 | |
| 489 | $this->content_url = $content_url; |
| 490 | } |
| 491 | |
| 492 | public function clear_cache_on_kksr_rate($id){ |
| 493 | $this->singleDeleteCache(false, $id); |
| 494 | } |
| 495 | |
| 496 | public function clear_cache_after_woocommerce_order_status_changed($order_id = false){ |
| 497 | if(function_exists("wc_get_order")){ |
| 498 | if($order_id){ |
| 499 | $order = wc_get_order($order_id); |
| 500 | |
| 501 | if($order){ |
| 502 | foreach($order->get_items() as $item_key => $item_values ){ |
| 503 | if(method_exists($item_values, 'get_product_id')){ |
| 504 | $this->singleDeleteCache(false, $item_values->get_product_id()); |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | public function wpfc_db_fix_callback(){ |
| 513 | if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){ |
| 514 | include_once $this->get_premium_path("db.php"); |
| 515 | |
| 516 | if(class_exists("WpFastestCacheDatabaseCleanup")){ |
| 517 | WpFastestCacheDatabaseCleanup::clean($_GET["type"]); |
| 518 | }else{ |
| 519 | die(json_encode(array("success" => false, "showupdatewarning" => true, "message" => "Only available in Premium version"))); |
| 520 | } |
| 521 | |
| 522 | }else{ |
| 523 | die(json_encode(array("success" => false, "message" => "Only available in Premium version"))); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | public function wpfc_db_statics_callback(){ |
| 528 | if(!wp_verify_nonce($_REQUEST["nonce"], 'wpfc')){ |
| 529 | die( 'Security check' ); |
| 530 | } |
| 531 | |
| 532 | global $wpdb; |
| 533 | |
| 534 | $statics = array("all_warnings" => 0, |
| 535 | "post_revisions" => 0, |
| 536 | "trashed_contents" => 0, |
| 537 | "trashed_spam_comments" => 0, |
| 538 | "trackback_pingback" => 0, |
| 539 | "transient_options" => 0 |
| 540 | ); |
| 541 | |
| 542 | |
| 543 | $statics["post_revisions"] = $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->posts` WHERE post_type = 'revision';"); |
| 544 | $statics["all_warnings"] = $statics["all_warnings"] + $statics["post_revisions"]; |
| 545 | |
| 546 | $statics["trashed_contents"] = $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->posts` WHERE post_status = 'trash';"); |
| 547 | $statics["all_warnings"] = $statics["all_warnings"] + $statics["trashed_contents"]; |
| 548 | |
| 549 | $statics["trashed_spam_comments"] = $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->comments` WHERE comment_approved = 'spam' OR comment_approved = 'trash' ;"); |
| 550 | $statics["all_warnings"] = $statics["all_warnings"] + $statics["trashed_spam_comments"]; |
| 551 | |
| 552 | $statics["trackback_pingback"] = $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->comments` WHERE comment_type = 'trackback' OR comment_type = 'pingback' ;"); |
| 553 | $statics["all_warnings"] = $statics["all_warnings"] + $statics["trackback_pingback"]; |
| 554 | |
| 555 | $element = "SELECT COUNT(*) FROM `$wpdb->options` WHERE option_name LIKE '%\_transient\_%' ;"; |
| 556 | $statics["transient_options"] = $wpdb->get_var( $element ) > 100 ? $wpdb->get_var( $element ) : 0; |
| 557 | $statics["all_warnings"] = $statics["all_warnings"] + $statics["transient_options"]; |
| 558 | |
| 559 | die(json_encode($statics)); |
| 560 | } |
| 561 | |
| 562 | public function is_trailing_slash(){ |
| 563 | // no need to check if Custom Permalinks plugin is active (https://tr.wordpress.org/plugins/custom-permalinks/) |
| 564 | if($this->isPluginActive("custom-permalinks/custom-permalinks.php")){ |
| 565 | return false; |
| 566 | } |
| 567 | |
| 568 | if($permalink_structure = get_option('permalink_structure')){ |
| 569 | if(preg_match("/\/$/", $permalink_structure)){ |
| 570 | return true; |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | return false; |
| 575 | } |
| 576 | |
| 577 | public function wpfc_cache_statics_get_callback(){ |
| 578 | if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){ |
| 579 | if(file_exists(WPFC_WP_PLUGIN_DIR."/wp-fastest-cache-premium/pro/library/statics.php")){ |
| 580 | include_once $this->get_premium_path("statics.php"); |
| 581 | |
| 582 | $cache_statics = new WpFastestCacheStatics(); |
| 583 | $res = $cache_statics->get(); |
| 584 | echo json_encode($res); |
| 585 | exit; |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | public function wpfc_check_url_ajax_request_callback(){ |
| 591 | if(!wp_verify_nonce($_REQUEST["nonce"], 'cdn-nonce')){ |
| 592 | die( 'Security check' ); |
| 593 | } |
| 594 | |
| 595 | include_once('inc/cdn.php'); |
| 596 | CdnWPFC::check_url(); |
| 597 | } |
| 598 | |
| 599 | public function wpfc_cdn_template_ajax_request_callback(){ |
| 600 | include_once('inc/cdn.php'); |
| 601 | CdnWPFC::cdn_template(); |
| 602 | } |
| 603 | |
| 604 | public function wpfc_save_cdn_integration_ajax_request_callback(){ |
| 605 | if(!wp_verify_nonce($_REQUEST["nonce"], 'cdn-nonce')){ |
| 606 | die( 'Security check' ); |
| 607 | } |
| 608 | |
| 609 | include_once('inc/cdn.php'); |
| 610 | CdnWPFC::save_cdn_integration(); |
| 611 | } |
| 612 | |
| 613 | public function wpfc_start_cdn_integration_ajax_request_callback(){ |
| 614 | if(!wp_verify_nonce($_REQUEST["nonce"], 'cdn-nonce')){ |
| 615 | die( 'Security check' ); |
| 616 | } |
| 617 | |
| 618 | include_once('inc/cdn.php'); |
| 619 | CdnWPFC::start_cdn_integration(); |
| 620 | } |
| 621 | |
| 622 | public function wpfc_pause_cdn_integration_ajax_request_callback(){ |
| 623 | if(!wp_verify_nonce($_REQUEST["nonce"], 'cdn-nonce')){ |
| 624 | die( 'Security check' ); |
| 625 | } |
| 626 | |
| 627 | include_once('inc/cdn.php'); |
| 628 | CdnWPFC::pause_cdn_integration(); |
| 629 | } |
| 630 | |
| 631 | public function wpfc_remove_cdn_integration_ajax_request_callback(){ |
| 632 | if(!wp_verify_nonce($_REQUEST["nonce"], 'cdn-nonce')){ |
| 633 | die( 'Security check' ); |
| 634 | } |
| 635 | |
| 636 | include_once('inc/cdn.php'); |
| 637 | CdnWPFC::remove_cdn_integration(); |
| 638 | } |
| 639 | |
| 640 | public function wpfc_cdn_options_ajax_request_callback(){ |
| 641 | include_once('inc/cdn.php'); |
| 642 | CdnWPFC::cdn_options(); |
| 643 | } |
| 644 | |
| 645 | public function wpfc_save_exclude_pages_callback(){ |
| 646 | if(!wp_verify_nonce($_POST["security"], 'wpfc-save-exclude-ajax-nonce')){ |
| 647 | die( 'Security check' ); |
| 648 | } |
| 649 | |
| 650 | if(current_user_can('manage_options')){ |
| 651 | if(isset($_POST["rules"])){ |
| 652 | foreach ($_POST["rules"] as $key => &$value) { |
| 653 | $value["prefix"] = strip_tags($value["prefix"]); |
| 654 | $value["content"] = strip_tags($value["content"]); |
| 655 | |
| 656 | $value["prefix"] = preg_replace("/\'|\"/", "", $value["prefix"]); |
| 657 | |
| 658 | if($value["prefix"] == "regex"){ |
| 659 | $value["content"] = stripslashes($value["content"]); |
| 660 | |
| 661 | $value["content"] = esc_attr($value["content"]); |
| 662 | }else{ |
| 663 | $value["content"] = preg_replace("/\'|\"/", "", $value["content"]); |
| 664 | $value["content"] = preg_replace("/(\#|\s|\(|\)|\*)/", "", $value["content"]); |
| 665 | } |
| 666 | |
| 667 | if($value["prefix"] == "homepage"){ |
| 668 | $this->deleteHomePageCache(false); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | $data = json_encode($_POST["rules"]); |
| 673 | |
| 674 | if(get_option("WpFastestCacheExclude")){ |
| 675 | update_option("WpFastestCacheExclude", $data); |
| 676 | }else{ |
| 677 | add_option("WpFastestCacheExclude", $data, null, "yes"); |
| 678 | } |
| 679 | }else{ |
| 680 | delete_option("WpFastestCacheExclude"); |
| 681 | } |
| 682 | |
| 683 | $this->modify_htaccess_for_exclude(); |
| 684 | |
| 685 | echo json_encode(array("success" => true)); |
| 686 | exit; |
| 687 | }else{ |
| 688 | wp_die("Must be admin"); |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | public function modify_htaccess_for_exclude(){ |
| 693 | $path = ABSPATH; |
| 694 | |
| 695 | if($this->is_subdirectory_install()){ |
| 696 | $path = $this->getABSPATH(); |
| 697 | } |
| 698 | |
| 699 | $htaccess = @file_get_contents($path.".htaccess"); |
| 700 | |
| 701 | if(preg_match("/\#\s?Start\sWPFC\sExclude/", $htaccess)){ |
| 702 | $exclude_rules = $this->excludeRules(); |
| 703 | |
| 704 | $htaccess = preg_replace("/\#\s?Start\sWPFC\sExclude[^\#]*\#\s?End\sWPFC\sExclude\s+/", $exclude_rules, $htaccess); |
| 705 | } |
| 706 | |
| 707 | @file_put_contents($path.".htaccess", $htaccess); |
| 708 | } |
| 709 | |
| 710 | public function wpfc_purgecache_varnish_callback(){ |
| 711 | if(!wp_verify_nonce($_REQUEST["security"], 'wpfc-varnish-ajax-nonce')){ |
| 712 | die( 'Security check' ); |
| 713 | } |
| 714 | |
| 715 | if($varnish_datas = get_option("WpFastestCacheVarnish")){ |
| 716 | include_once('inc/varnish.php'); |
| 717 | $res_arr = VarnishWPFC::purge_cache($varnish_datas["server"]); |
| 718 | |
| 719 | wp_send_json($res_arr); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | public function wpfc_save_varnish_callback(){ |
| 724 | include_once('inc/varnish.php'); |
| 725 | VarnishWPFC::save(); |
| 726 | } |
| 727 | |
| 728 | public function wpfc_remove_varnish_callback(){ |
| 729 | include_once('inc/varnish.php'); |
| 730 | VarnishWPFC::remove(); |
| 731 | } |
| 732 | |
| 733 | public function wpfc_start_varnish_callback(){ |
| 734 | include_once('inc/varnish.php'); |
| 735 | VarnishWPFC::start(); |
| 736 | } |
| 737 | |
| 738 | public function wpfc_pause_varnish_callback(){ |
| 739 | include_once('inc/varnish.php'); |
| 740 | VarnishWPFC::pause(); |
| 741 | } |
| 742 | |
| 743 | public function wpfc_status_varnish(){ |
| 744 | include_once('inc/varnish.php'); |
| 745 | VarnishWPFC::status(); |
| 746 | } |
| 747 | |
| 748 | public function wpfc_get_list_csp_callback(){ |
| 749 | include_once('inc/clearing-specific-pages.php'); |
| 750 | ClearingSpecificPagesWPFC::get_list(); |
| 751 | } |
| 752 | |
| 753 | public function wpfc_save_csp_callback(){ |
| 754 | include_once('inc/clearing-specific-pages.php'); |
| 755 | ClearingSpecificPagesWPFC::save(); |
| 756 | } |
| 757 | |
| 758 | public function wpfc_remove_csp_callback(){ |
| 759 | include_once('inc/clearing-specific-pages.php'); |
| 760 | ClearingSpecificPagesWPFC::remove(); |
| 761 | } |
| 762 | |
| 763 | public function wpfc_save_timeout_pages_callback(){ |
| 764 | if(!wp_verify_nonce($_POST["security"], 'wpfc-save-timeout-ajax-nonce')){ |
| 765 | die( 'Security check' ); |
| 766 | } |
| 767 | |
| 768 | if(current_user_can('manage_options')){ |
| 769 | $this->setCustomInterval(); |
| 770 | |
| 771 | $crons = _get_cron_array(); |
| 772 | |
| 773 | foreach ($crons as $cron_key => $cron_value) { |
| 774 | foreach ( (array) $cron_value as $hook => $events ) { |
| 775 | if(preg_match("/^wp\_fastest\_cache(.*)/", $hook, $id)){ |
| 776 | if(!$id[1] || preg_match("/^\_(\d+)$/", $id[1])){ |
| 777 | foreach ( (array) $events as $event_key => $event ) { |
| 778 | if($id[1]){ |
| 779 | wp_clear_scheduled_hook("wp_fastest_cache".$id[1], $event["args"]); |
| 780 | }else{ |
| 781 | wp_clear_scheduled_hook("wp_fastest_cache", $event["args"]); |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | if(isset($_POST["rules"]) && count($_POST["rules"]) > 0){ |
| 790 | $i = 0; |
| 791 | |
| 792 | foreach ($_POST["rules"] as $key => $value) { |
| 793 | if(preg_match("/^(daily|onceaday)$/i", $value["schedule"]) && isset($value["hour"]) && isset($value["minute"]) && strlen($value["hour"]) > 0 && strlen($value["minute"]) > 0){ |
| 794 | $args = array("prefix" => $value["prefix"], "content" => $value["content"], "hour" => $value["hour"], "minute" => $value["minute"]); |
| 795 | |
| 796 | $timestamp = mktime($value["hour"],$value["minute"],0,date("m"),date("d"),date("Y")); |
| 797 | |
| 798 | $timestamp = $timestamp > time() ? $timestamp : $timestamp + 60*60*24; |
| 799 | }else{ |
| 800 | $args = array("prefix" => $value["prefix"], "content" => $value["content"]); |
| 801 | $timestamp = time(); |
| 802 | } |
| 803 | |
| 804 | wp_schedule_event($timestamp, $value["schedule"], "wp_fastest_cache_".$i, array(json_encode($args))); |
| 805 | $i = $i + 1; |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | echo json_encode(array("success" => true)); |
| 810 | exit; |
| 811 | }else{ |
| 812 | wp_die("Must be admin"); |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | public function wp_postratings_clear_fastest_cache($rate_userid, $post_id){ |
| 817 | // to remove cache if vote is from homepage or category page or tag |
| 818 | if(isset($_SERVER["HTTP_REFERER"]) && $_SERVER["HTTP_REFERER"]){ |
| 819 | $url = parse_url($_SERVER["HTTP_REFERER"]); |
| 820 | |
| 821 | $url["path"] = isset($url["path"]) ? $url["path"] : "/index.html"; |
| 822 | |
| 823 | if(isset($url["path"])){ |
| 824 | if($url["path"] == "/"){ |
| 825 | $this->rm_folder_recursively($this->getWpContentDir("/cache/all/index.html")); |
| 826 | }else{ |
| 827 | // to prevent changing path with ../ or with another method |
| 828 | if($url["path"] == realpath(".".$url["path"])){ |
| 829 | $this->rm_folder_recursively($this->getWpContentDir("/cache/all").$url["path"]); |
| 830 | } |
| 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | if($post_id){ |
| 836 | $this->singleDeleteCache(false, $post_id); |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | private function admin(){ |
| 841 | if(isset($_GET["page"]) && $_GET["page"] == "wpfastestcacheoptions"){ |
| 842 | include_once('inc/admin.php'); |
| 843 | $wpfc = new WpFastestCacheAdmin(); |
| 844 | $wpfc->addMenuPage(); |
| 845 | }else{ |
| 846 | add_action('admin_menu', array($this, 'register_my_custom_menu_page')); |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | public function load_column(){ |
| 851 | if(!defined('WPFC_HIDE_CLEAR_CACHE_BUTTON') || (defined('WPFC_HIDE_CLEAR_CACHE_BUTTON') && !WPFC_HIDE_CLEAR_CACHE_BUTTON)){ |
| 852 | include_once plugin_dir_path(__FILE__)."inc/column.php"; |
| 853 | |
| 854 | $column = new WpFastestCacheColumn(); |
| 855 | $column->add(); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | public function load_admin_toolbar(){ |
| 860 | if(!defined('WPFC_HIDE_TOOLBAR') || (defined('WPFC_HIDE_TOOLBAR') && !WPFC_HIDE_TOOLBAR)){ |
| 861 | $user = wp_get_current_user(); |
| 862 | $allowed_roles = array('administrator'); |
| 863 | |
| 864 | $wpfc_role_status = get_option("WpFastestCacheToolbarSettings"); |
| 865 | if(is_array($wpfc_role_status) && !empty($wpfc_role_status)){ |
| 866 | foreach ($wpfc_role_status as $key => $value){ |
| 867 | $key = str_replace("wpfc_toolbar_", "", $key); |
| 868 | array_push($allowed_roles, strtolower($key)); |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | |
| 873 | if(array_intersect($allowed_roles, $user->roles)){ |
| 874 | include_once plugin_dir_path(__FILE__)."inc/admin-toolbar.php"; |
| 875 | |
| 876 | if(preg_match("/\/cache\/all/", $this->getWpContentDir("/cache/all"))){ |
| 877 | $is_multi = false; |
| 878 | }else{ |
| 879 | $is_multi = true; |
| 880 | } |
| 881 | |
| 882 | $toolbar = new WpFastestCacheAdminToolbar($is_multi); |
| 883 | $toolbar->add(); |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | public function tmp_saveOption(){ |
| 889 | if(!empty($_POST)){ |
| 890 | if(isset($_POST["wpFastestCachePage"])){ |
| 891 | include_once('inc/admin.php'); |
| 892 | $wpfc = new WpFastestCacheAdmin(); |
| 893 | $wpfc->optionsPageRequest(); |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | public function register_mysettings(){ |
| 899 | register_setting('wpfc-group', 'wpfc-group', array($this, 'tmp_saveOption')); |
| 900 | } |
| 901 | |
| 902 | public function register_my_custom_menu_page(){ |
| 903 | if(function_exists('add_menu_page')){ |
| 904 | |
| 905 | if(defined("WPFC_MOVE_MENU_ITEM_UNDER_SETTINGS") && WPFC_MOVE_MENU_ITEM_UNDER_SETTINGS){ |
| 906 | add_options_page("WP Fastest Cache Settings", "WP Fastest Cache", 'manage_options', 'wpfastestcacheoptions', array($this, 'optionsPage')); |
| 907 | }else{ |
| 908 | add_menu_page("WP Fastest Cache Settings", "WP Fastest Cache", 'manage_options', "wpfastestcacheoptions", array($this, 'optionsPage'), plugins_url("wp-fastest-cache/images/icon.svg")); |
| 909 | } |
| 910 | |
| 911 | add_action('admin_init', array($this, 'register_mysettings')); |
| 912 | |
| 913 | wp_enqueue_style("wp-fastest-cache", plugins_url("wp-fastest-cache/css/style.css"), array(), time(), "all"); |
| 914 | } |
| 915 | |
| 916 | if(isset($_GET["page"]) && $_GET["page"] == "wpfastestcacheoptions"){ |
| 917 | wp_enqueue_style("wp-fastest-cache-buycredit", plugins_url("wp-fastest-cache/css/buycredit.css"), array(), time(), "all"); |
| 918 | wp_enqueue_style("wp-fastest-cache-flaticon", plugins_url("wp-fastest-cache/css/flaticon.css"), array(), time(), "all"); |
| 919 | wp_enqueue_style("wp-fastest-cache-dialog", plugins_url("wp-fastest-cache/css/dialog.css"), array(), time(), "all"); |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | public function deleteCacheToolbar(){ |
| 924 | if(!wp_verify_nonce($_REQUEST["nonce"], 'wpfc')){ |
| 925 | die( 'Security check' ); |
| 926 | } |
| 927 | |
| 928 | $this->deleteCache(); |
| 929 | } |
| 930 | |
| 931 | public function deleteCssAndJsCacheToolbar(){ |
| 932 | if(!wp_verify_nonce($_REQUEST["nonce"], 'wpfc')){ |
| 933 | die( 'Security check' ); |
| 934 | } |
| 935 | |
| 936 | $this->deleteCache(true); |
| 937 | } |
| 938 | |
| 939 | public function wpfc_toolbar_get_settings_callback(){ |
| 940 | if(current_user_can('manage_options')){ |
| 941 | $result = array("success" => true, "roles" => false); |
| 942 | |
| 943 | $wpfc_role_status = get_option("WpFastestCacheToolbarSettings"); |
| 944 | if(is_array($wpfc_role_status) && !empty($wpfc_role_status)){ |
| 945 | $result["roles"] = $wpfc_role_status; |
| 946 | } |
| 947 | |
| 948 | die(json_encode($result)); |
| 949 | }else{ |
| 950 | wp_die("Must be admin"); |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | public function wpfc_cache_path_save_settings_callback(){ |
| 955 | if(current_user_can('manage_options')){ |
| 956 | foreach($_POST as $key => &$value){ |
| 957 | $value = esc_html(esc_sql($value)); |
| 958 | } |
| 959 | |
| 960 | $path_arr = array( |
| 961 | "cachepath" => sanitize_text_field($_POST["cachepath"]), |
| 962 | "optimizedpath" => sanitize_text_field($_POST["optimizedpath"]) |
| 963 | ); |
| 964 | |
| 965 | if(get_option("WpFastestCachePathSettings") === false){ |
| 966 | add_option("WpFastestCachePathSettings", $path_arr, 1, "no"); |
| 967 | }else{ |
| 968 | update_option("WpFastestCachePathSettings", $path_arr); |
| 969 | } |
| 970 | |
| 971 | die(json_encode(array("success" => true))); |
| 972 | }else{ |
| 973 | wp_die("Must be admin"); |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | public function wpfc_toolbar_save_settings_callback(){ |
| 978 | if(!wp_verify_nonce($_REQUEST["nonce"], 'wpfc')){ |
| 979 | die( 'Security check' ); |
| 980 | } |
| 981 | |
| 982 | if(current_user_can('manage_options')){ |
| 983 | if(isset($_GET["roles"]) && is_array($_GET["roles"]) && !empty($_GET["roles"])){ |
| 984 | $roles_arr = array(); |
| 985 | |
| 986 | foreach($_GET["roles"] as $key => $value){ |
| 987 | $value = esc_html(esc_sql($value)); |
| 988 | $key = esc_html(esc_sql($key)); |
| 989 | |
| 990 | $roles_arr[$key] = $value; |
| 991 | } |
| 992 | |
| 993 | if(get_option("WpFastestCacheToolbarSettings") === false){ |
| 994 | add_option("WpFastestCacheToolbarSettings", $roles_arr, 1, "no"); |
| 995 | }else{ |
| 996 | update_option("WpFastestCacheToolbarSettings", $roles_arr); |
| 997 | } |
| 998 | }else{ |
| 999 | delete_option("WpFastestCacheToolbarSettings"); |
| 1000 | } |
| 1001 | |
| 1002 | |
| 1003 | die(json_encode(array("Saved","success"))); |
| 1004 | }else{ |
| 1005 | wp_die("Must be admin"); |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | public function wpfc_clear_cache_of_allsites_callback(){ |
| 1010 | |
| 1011 | if(defined('DOING_AJAX') && DOING_AJAX){ |
| 1012 | if(!wp_verify_nonce($_REQUEST["nonce"], 'wpfc')){ |
| 1013 | die( 'Security check' ); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | include_once('inc/cdn.php'); |
| 1018 | CdnWPFC::cloudflare_clear_cache(); |
| 1019 | |
| 1020 | $path = $this->getWpContentDir("/cache/*"); |
| 1021 | |
| 1022 | $files = glob($this->getWpContentDir("/cache/*")); |
| 1023 | |
| 1024 | if(!is_dir($this->getWpContentDir("/cache/tmpWpfc"))){ |
| 1025 | if(@mkdir($this->getWpContentDir("/cache/tmpWpfc"), 0755, true)){ |
| 1026 | //tmpWpfc has been created |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | foreach ((array)$files as $file){ |
| 1031 | @rename($file, $this->getWpContentDir("/cache/tmpWpfc/").basename($file)."-".time()); |
| 1032 | } |
| 1033 | |
| 1034 | if (is_admin() && defined('DOING_AJAX') && DOING_AJAX){ |
| 1035 | die(json_encode(array("The cache of page has been cleared","success"))); |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | public function delete_current_page_cache(){ |
| 1040 | if(!wp_verify_nonce($_GET["nonce"], "wpfc")){ |
| 1041 | die(json_encode(array("Security Error!", "error", "alert"))); |
| 1042 | } |
| 1043 | |
| 1044 | if($varnish_datas = get_option("WpFastestCacheVarnish")){ |
| 1045 | include_once('inc/varnish.php'); |
| 1046 | VarnishWPFC::purge_cache($varnish_datas); |
| 1047 | } |
| 1048 | |
| 1049 | include_once('inc/cdn.php'); |
| 1050 | CdnWPFC::cloudflare_clear_cache(); |
| 1051 | |
| 1052 | if(isset($_GET["path"])){ |
| 1053 | if($_GET["path"]){ |
| 1054 | if($_GET["path"] == "/"){ |
| 1055 | $_GET["path"] = $_GET["path"]."index.html"; |
| 1056 | } |
| 1057 | }else{ |
| 1058 | $_GET["path"] = "/index.html"; |
| 1059 | } |
| 1060 | |
| 1061 | $_GET["path"] = urldecode(esc_url_raw($_GET["path"])); |
| 1062 | |
| 1063 | // for security |
| 1064 | if(preg_match("/\.{2,}/", $_GET["path"])){ |
| 1065 | die("May be Directory Traversal Attack"); |
| 1066 | } |
| 1067 | |
| 1068 | $paths = array(); |
| 1069 | |
| 1070 | array_push($paths, $this->getWpContentDir("/cache/all").$_GET["path"]); |
| 1071 | |
| 1072 | if(class_exists("WpFcMobileCache")){ |
| 1073 | $wpfc_mobile = new WpFcMobileCache(); |
| 1074 | array_push($paths, $this->getWpContentDir("/cache/wpfc-mobile-cache").$_GET["path"]); |
| 1075 | } |
| 1076 | |
| 1077 | foreach ($paths as $key => $value){ |
| 1078 | if(file_exists($value)){ |
| 1079 | if(preg_match("/\/(all|wpfc-mobile-cache)\/index\.html$/i", $value)){ |
| 1080 | @unlink($value); |
| 1081 | }else{ |
| 1082 | $this->rm_folder_recursively($value); |
| 1083 | } |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | $this->delete_multiple_domain_mapping_cache(); |
| 1088 | |
| 1089 | die(json_encode(array("The cache of page has been cleared","success"))); |
| 1090 | }else{ |
| 1091 | die(json_encode(array("Path has NOT been defined", "error", "alert"))); |
| 1092 | } |
| 1093 | |
| 1094 | exit; |
| 1095 | } |
| 1096 | |
| 1097 | private function cache(){ |
| 1098 | if(isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST']){ |
| 1099 | include_once('inc/cache.php'); |
| 1100 | $wpfc = new WpFastestCacheCreateCache(); |
| 1101 | $wpfc->createCache(); |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | protected function slug(){ |
| 1106 | return "wp_fastest_cache"; |
| 1107 | } |
| 1108 | |
| 1109 | public function getWpContentDir($path = false){ |
| 1110 | /* |
| 1111 | Sample Paths; |
| 1112 | |
| 1113 | /cache/ |
| 1114 | |
| 1115 | /cache/all/ |
| 1116 | /cache/all |
| 1117 | /cache/all/page |
| 1118 | /cache/all/index.html |
| 1119 | |
| 1120 | /cache/wpfc-minified |
| 1121 | |
| 1122 | /cache/wpfc-widget-cache |
| 1123 | |
| 1124 | /cache/wpfc-mobile-cache/ |
| 1125 | /cache/wpfc-mobile-cache/page |
| 1126 | /cache/wpfc-mobile-cache/index.html |
| 1127 | |
| 1128 | /cache/tmpWpfc |
| 1129 | /cache/tmpWpfc/ |
| 1130 | /cache/tmpWpfc/mobile_ |
| 1131 | /cache/tmpWpfc/m |
| 1132 | /cache/tmpWpfc/w |
| 1133 | |
| 1134 | |
| 1135 | /cache/testWpFc/ |
| 1136 | |
| 1137 | /cache/all/testWpFc/ |
| 1138 | |
| 1139 | /cache/wpfc-widget-cache/ |
| 1140 | /cache/wpfc-widget-cache |
| 1141 | /cache/wpfc-widget-cache/".$args["widget_id"].".html |
| 1142 | */ |
| 1143 | |
| 1144 | if($path){ |
| 1145 | if(preg_match("/\/cache\/(all|wpfc-minified|wpfc-widget-cache|wpfc-mobile-cache)/", $path)){ |
| 1146 | //WPML language switch |
| 1147 | //https://wpml.org/forums/topic/wpml-language-switch-wp-fastest-cache-issue/ |
| 1148 | $language_negotiation_type = apply_filters('wpml_setting', false, 'language_negotiation_type'); |
| 1149 | if(($language_negotiation_type == 2) && $this->isPluginActive('sitepress-multilingual-cms/sitepress.php')){ |
| 1150 | $my_home_url = apply_filters('wpml_home_url', get_option('home')); |
| 1151 | $my_home_url = preg_replace("/https?\:\/\//i", "", $my_home_url); |
| 1152 | $my_home_url = trim($my_home_url, "/"); |
| 1153 | |
| 1154 | $path = preg_replace("/\/cache\/(all|wpfc-minified|wpfc-widget-cache|wpfc-mobile-cache)/", "/cache/".$my_home_url."/$1", $path); |
| 1155 | }else if(($language_negotiation_type == 1) && $this->isPluginActive('sitepress-multilingual-cms/sitepress.php')){ |
| 1156 | $my_current_lang = apply_filters('wpml_current_language', NULL); |
| 1157 | |
| 1158 | if($my_current_lang){ |
| 1159 | $path = preg_replace("/\/cache\/wpfc-widget-cache\/(.+)/", "/cache/wpfc-widget-cache/".$my_current_lang."-"."$1", $path); |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | if($this->isPluginActive('multiple-domain-mapping-on-single-site/multidomainmapping.php')){ |
| 1164 | $path = preg_replace("/\/cache\/(all|wpfc-minified|wpfc-widget-cache|wpfc-mobile-cache)/", "/cache/".$_SERVER['HTTP_HOST']."/$1", $path); |
| 1165 | } |
| 1166 | |
| 1167 | if($this->isPluginActive('polylang/polylang.php')){ |
| 1168 | $polylang_settings = get_option("polylang"); |
| 1169 | |
| 1170 | if(isset($polylang_settings["force_lang"])){ |
| 1171 | if($polylang_settings["force_lang"] == 2 || $polylang_settings["force_lang"] == 3){ |
| 1172 | // The language is set from the subdomain name in pretty permalinks |
| 1173 | // The language is set from different domains |
| 1174 | $path = preg_replace("/\/cache\/(all|wpfc-minified|wpfc-widget-cache|wpfc-mobile-cache)/", "/cache/".$_SERVER['HTTP_HOST']."/$1", $path); |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | if($this->isPluginActive('multiple-domain/multiple-domain.php')){ |
| 1180 | $path = preg_replace("/\/cache\/(all|wpfc-minified|wpfc-widget-cache|wpfc-mobile-cache)/", "/cache/".$_SERVER['HTTP_HOST']."/$1", $path); |
| 1181 | } |
| 1182 | |
| 1183 | if(is_multisite()){ |
| 1184 | $path = preg_replace("/\/cache\/(all|wpfc-minified|wpfc-widget-cache|wpfc-mobile-cache)/", "/cache/".$_SERVER['HTTP_HOST']."/$1", $path); |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | return WPFC_WP_CONTENT_DIR.$path; |
| 1189 | }else{ |
| 1190 | return WPFC_WP_CONTENT_DIR; |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | protected function getOptions(){ |
| 1195 | return $GLOBALS["wp_fastest_cache_options"]; |
| 1196 | } |
| 1197 | |
| 1198 | protected function getSystemMessage(){ |
| 1199 | return $this->systemMessage; |
| 1200 | } |
| 1201 | |
| 1202 | protected function get_excluded_useragent(){ |
| 1203 | return "facebookexternalhit|WP_FASTEST_CACHE_CSS_VALIDATOR|Twitterbot|LinkedInBot|WhatsApp|Mediatoolkitbot"; |
| 1204 | } |
| 1205 | |
| 1206 | // protected function detectNewPost(){ |
| 1207 | // if(isset($this->options->wpFastestCacheNewPost) && isset($this->options->wpFastestCacheStatus)){ |
| 1208 | // add_filter ('save_post', array($this, 'deleteCache')); |
| 1209 | // } |
| 1210 | // } |
| 1211 | |
| 1212 | public function deleteWidgetCache(){ |
| 1213 | $widget_cache_path = $this->getWpContentDir("/cache/wpfc-widget-cache"); |
| 1214 | |
| 1215 | if(is_dir($widget_cache_path)){ |
| 1216 | if(!is_dir($this->getWpContentDir("/cache/tmpWpfc"))){ |
| 1217 | if(@mkdir($this->getWpContentDir("/cache/tmpWpfc"), 0755, true)){ |
| 1218 | //tmpWpfc has been created |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | if(@rename($widget_cache_path, $this->getWpContentDir("/cache/tmpWpfc/w").time())){ |
| 1223 | //DONE |
| 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | public function clear_cache_after_woocommerce_update_product($product_id){ |
| 1229 | if(!$this->deleted_before){ |
| 1230 | $this->singleDeleteCache(false, $product_id); |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | public function on_all_status_transitions($new_status, $old_status, $post){ |
| 1235 | $this->deleted_before = true; |
| 1236 | |
| 1237 | if(!wp_is_post_revision($post->ID)){ |
| 1238 | if(isset($post->post_type)){ |
| 1239 | if($post->post_type == "nf_sub"){ |
| 1240 | return 0; |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | if($new_status == "publish" && $old_status != "publish"){ |
| 1245 | |
| 1246 | $this->specificDeleteCache(); |
| 1247 | |
| 1248 | if(isset($this->options->wpFastestCacheNewPost) && isset($this->options->wpFastestCacheStatus)){ |
| 1249 | if(isset($this->options->wpFastestCacheNewPost_type) && $this->options->wpFastestCacheNewPost_type){ |
| 1250 | if($this->options->wpFastestCacheNewPost_type == "all"){ |
| 1251 | $this->deleteCache(); |
| 1252 | }else if($this->options->wpFastestCacheNewPost_type == "homepage"){ |
| 1253 | $this->deleteHomePageCache(); |
| 1254 | |
| 1255 | //to clear category cache and tag cache |
| 1256 | $this->singleDeleteCache(false, $post->ID); |
| 1257 | |
| 1258 | //to clear widget cache |
| 1259 | $this->deleteWidgetCache(); |
| 1260 | } |
| 1261 | }else{ |
| 1262 | $this->deleteCache(); |
| 1263 | } |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | if(isset($this->options->wpFastestCacheStatus) && $new_status == "publish" && $old_status == "publish"){ |
| 1268 | |
| 1269 | // if(isset($this->options->wpFastestCacheUpdatePost) && isset($this->options->wpFastestCacheStatus)){ |
| 1270 | |
| 1271 | // if($this->options->wpFastestCacheUpdatePost_type == "post"){ |
| 1272 | // $this->singleDeleteCache(false, $post->ID); |
| 1273 | // }else if($this->options->wpFastestCacheUpdatePost_type == "all"){ |
| 1274 | // $this->deleteCache(); |
| 1275 | // } |
| 1276 | |
| 1277 | // } |
| 1278 | |
| 1279 | $this->specificDeleteCache(); |
| 1280 | |
| 1281 | if(isset($this->options->wpFastestCacheUpdatePost)){ |
| 1282 | |
| 1283 | if($this->options->wpFastestCacheUpdatePost_type == "post"){ |
| 1284 | $this->singleDeleteCache(false, $post->ID); |
| 1285 | }else if($this->options->wpFastestCacheUpdatePost_type == "all"){ |
| 1286 | $this->deleteCache(); |
| 1287 | } |
| 1288 | |
| 1289 | }else{ |
| 1290 | // to clear only cache of content even though the "update post" option is disabled |
| 1291 | $this->singleDeleteCache(false, $post->ID, false); |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | if($new_status == "trash" && $old_status == "publish"){ |
| 1296 | $this->singleDeleteCache(false, $post->ID); |
| 1297 | }else if(($new_status == "draft" || $new_status == "pending" || $new_status == "private") && $old_status == "publish"){ |
| 1298 | $this->deleteCache(); |
| 1299 | } |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | protected function commentHooks(){ |
| 1304 | //it works when the status of a comment changes |
| 1305 | add_action('wp_set_comment_status', array($this, 'singleDeleteCache'), 10, 1); |
| 1306 | |
| 1307 | //it works when a comment is saved in the database |
| 1308 | add_action('comment_post', array($this, 'detectNewComment'), 10, 2); |
| 1309 | |
| 1310 | // it work when a commens is updated |
| 1311 | add_action('edit_comment', array($this, 'detectEditComment'), 10, 2); |
| 1312 | } |
| 1313 | |
| 1314 | public function detectEditComment($comment_id, $comment_data){ |
| 1315 | if($comment_data["comment_approved"] == 1){ |
| 1316 | $this->singleDeleteCache($comment_id); |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | public function detectNewComment($comment_id, $comment_approved){ |
| 1321 | // if(current_user_can( 'manage_options') || !get_option('comment_moderation')){ |
| 1322 | if($comment_approved === 1){ |
| 1323 | $this->singleDeleteCache($comment_id); |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | public function specificDeleteCache(){ |
| 1328 | $urls = get_option("WpFastestCacheCSP"); |
| 1329 | $files = array(); |
| 1330 | |
| 1331 | if(!empty($urls)){ |
| 1332 | foreach ($urls as $key => $value) { |
| 1333 | |
| 1334 | if(preg_match("/https?:\/\/[^\/]+\/(.+)/", $value->url, $out)){ |
| 1335 | |
| 1336 | if(preg_match("/\/\(\.\*\)/", $out[1])){ |
| 1337 | $out[1] = str_replace("(.*)", "", $out[1]); |
| 1338 | |
| 1339 | $path = $this->getWpContentDir("/cache/all/").$out[1]; |
| 1340 | $mobile_path = $this->getWpContentDir("/cache/wpfc-mobile-cache/").$out[1]; |
| 1341 | }else{ |
| 1342 | $out[1] = $out[1]."index.html"; |
| 1343 | |
| 1344 | $path = $this->getWpContentDir("/cache/all/").$out[1]; |
| 1345 | $mobile_path = $this->getWpContentDir("/cache/wpfc-mobile-cache/").$out[1]; |
| 1346 | } |
| 1347 | |
| 1348 | if(!is_dir($this->getWpContentDir("/cache/tmpWpfc"))){ |
| 1349 | @mkdir($this->getWpContentDir("/cache/tmpWpfc"), 0755, true); |
| 1350 | } |
| 1351 | |
| 1352 | if(is_dir($path)){ |
| 1353 | rename($path, $this->getWpContentDir("/cache/tmpWpfc/").time()); |
| 1354 | } |
| 1355 | |
| 1356 | if(is_dir($mobile_path)){ |
| 1357 | rename($mobile_path, $this->getWpContentDir("/cache/tmpWpfc/mobile_").time()); |
| 1358 | } |
| 1359 | |
| 1360 | } |
| 1361 | |
| 1362 | } |
| 1363 | } |
| 1364 | } |
| 1365 | |
| 1366 | public function singleDeleteCache($comment_id = false, $post_id = false, $to_clear_parents = true){ |
| 1367 | if($varnish_datas = get_option("WpFastestCacheVarnish")){ |
| 1368 | include_once('inc/varnish.php'); |
| 1369 | VarnishWPFC::purge_cache($varnish_datas); |
| 1370 | } |
| 1371 | |
| 1372 | include_once('inc/cdn.php'); |
| 1373 | CdnWPFC::cloudflare_clear_cache(); |
| 1374 | |
| 1375 | $to_clear_feed = true; |
| 1376 | |
| 1377 | // not to clear cache of homepage/cats/tags after ajax request by other plugins |
| 1378 | if(isset($_POST) && isset($_POST["action"])){ |
| 1379 | // kk Star Rating |
| 1380 | if($_POST["action"] == "kksr_ajax"){ |
| 1381 | $to_clear_parents = false; |
| 1382 | } |
| 1383 | |
| 1384 | // All In One Schema.org Rich Snippets |
| 1385 | if(preg_match("/bsf_(update|submit)_rating/i", $_POST["action"])){ |
| 1386 | $to_clear_parents = false; |
| 1387 | } |
| 1388 | |
| 1389 | // Yet Another Stars Rating |
| 1390 | if($_POST["action"] == "yasr_send_visitor_rating"){ |
| 1391 | $to_clear_parents = false; |
| 1392 | $post_id = sanitize_text_field($_POST["post_id"]); |
| 1393 | } |
| 1394 | |
| 1395 | // All In One Schema.org Rich Snippets |
| 1396 | if(preg_match("/bsf_(update|submit)_rating/i", $_POST["action"])){ |
| 1397 | $to_clear_feed = false; |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | if($comment_id){ |
| 1402 | $comment_id = intval($comment_id); |
| 1403 | |
| 1404 | $comment = get_comment($comment_id); |
| 1405 | |
| 1406 | if($comment && $comment->comment_post_ID){ |
| 1407 | $post_id = $comment->comment_post_ID; |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | if($post_id){ |
| 1412 | $post_id = intval($post_id); |
| 1413 | |
| 1414 | $permalink = get_permalink($post_id); |
| 1415 | |
| 1416 | $permalink = urldecode(get_permalink($post_id)); |
| 1417 | |
| 1418 | |
| 1419 | |
| 1420 | //for trash contents |
| 1421 | if(preg_match("/\/\?p\=\d+/i", $permalink)){ |
| 1422 | $post = get_post($post_id); |
| 1423 | |
| 1424 | $clone_post = clone $post; |
| 1425 | $clone_post->post_status = 'publish'; |
| 1426 | |
| 1427 | $permalink = get_permalink($clone_post); |
| 1428 | $permalink = rtrim($permalink, "/"); |
| 1429 | |
| 1430 | $permalink = preg_replace("/__trashed$/", "", $permalink); |
| 1431 | //for /%postname%/%post_id% : sample-url__trashed/57595 |
| 1432 | $permalink = preg_replace("/__trashed\/(\d+)$/", "/$1", $permalink); |
| 1433 | } |
| 1434 | |
| 1435 | |
| 1436 | |
| 1437 | if(preg_match("/https?:\/\/[^\/]+\/(.+)/", $permalink, $out)){ |
| 1438 | $path = $this->getWpContentDir("/cache/all/").$out[1]; |
| 1439 | $mobile_path = $this->getWpContentDir("/cache/wpfc-mobile-cache/").$out[1]; |
| 1440 | |
| 1441 | if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){ |
| 1442 | include_once $this->get_premium_path("logs.php"); |
| 1443 | $log = new WpFastestCacheLogs("delete"); |
| 1444 | $log->action(); |
| 1445 | } |
| 1446 | |
| 1447 | $files = array(); |
| 1448 | |
| 1449 | if(is_dir($path)){ |
| 1450 | array_push($files, $path); |
| 1451 | } |
| 1452 | |
| 1453 | if(is_dir($mobile_path)){ |
| 1454 | array_push($files, $mobile_path); |
| 1455 | } |
| 1456 | |
| 1457 | if(defined('WPFC_CACHE_QUERYSTRING') && WPFC_CACHE_QUERYSTRING){ |
| 1458 | $files_with_query_string = glob($path."\?*"); |
| 1459 | $mobile_files_with_query_string = glob($mobile_path."\?*"); |
| 1460 | |
| 1461 | if(is_array($files_with_query_string) && (count($files_with_query_string) > 0)){ |
| 1462 | $files = array_merge($files, $files_with_query_string); |
| 1463 | } |
| 1464 | |
| 1465 | if(is_array($mobile_files_with_query_string) && (count($mobile_files_with_query_string) > 0)){ |
| 1466 | $files = array_merge($files, $mobile_files_with_query_string); |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | if($to_clear_feed){ |
| 1471 | // to clear cache of /feed |
| 1472 | if(preg_match("/https?:\/\/[^\/]+\/(.+)/", get_feed_link(), $feed_out)){ |
| 1473 | array_push($files, $this->getWpContentDir("/cache/all/").$feed_out[1]); |
| 1474 | } |
| 1475 | |
| 1476 | // to clear cache of /comments/feed/ |
| 1477 | if(preg_match("/https?:\/\/[^\/]+\/(.+)/", get_feed_link("comments_"), $comment_feed_out)){ |
| 1478 | array_push($files, $this->getWpContentDir("/cache/all/").$comment_feed_out[1]); |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | foreach((array)$files as $file){ |
| 1483 | $this->rm_folder_recursively($file); |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | if($to_clear_parents){ |
| 1488 | // to clear cache of homepage |
| 1489 | $this->deleteHomePageCache(); |
| 1490 | |
| 1491 | // to clear cache of author page |
| 1492 | $this->delete_author_page_cache($post_id); |
| 1493 | |
| 1494 | // to clear sitemap cache |
| 1495 | $this->delete_sitemap_cache(); |
| 1496 | |
| 1497 | // to clear cache of next post and cache of prev post |
| 1498 | $this->delete_next_prev_cache($post_id); |
| 1499 | |
| 1500 | // to clear cache of cats and tags which contains the post (only first page) |
| 1501 | global $wpdb; |
| 1502 | $terms = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."term_relationships` WHERE `object_id`=".$post_id, ARRAY_A); |
| 1503 | |
| 1504 | foreach ($terms as $term_key => $term_val){ |
| 1505 | $this->delete_cache_of_term($term_val["term_taxonomy_id"]); |
| 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | $this->delete_multiple_domain_mapping_cache(); |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | public function delete_next_prev_cache($post_id){ |
| 1514 | global $wpdb; |
| 1515 | |
| 1516 | $post = get_post($post_id); |
| 1517 | |
| 1518 | $next_post_query = "SELECT * FROM `".$wpdb->prefix."posts` WHERE ID = (SELECT min(ID) FROM `".$wpdb->prefix."posts` where ID > ".$post_id." AND `post_type` = '".$post->post_type."' AND `post_status` = 'publish')"; |
| 1519 | $prev_post_query = "SELECT * FROM `".$wpdb->prefix."posts` WHERE ID = (SELECT max(ID) FROM `".$wpdb->prefix."posts` where ID < ".$post_id." AND `post_type` = '".$post->post_type."' AND `post_status` = 'publish')"; |
| 1520 | |
| 1521 | $res = $wpdb->get_results($next_post_query." UNION ".$prev_post_query); |
| 1522 | |
| 1523 | if(isset($res[0])){ |
| 1524 | |
| 1525 | foreach ($res as $key => $value) { |
| 1526 | $permalink = urldecode(get_permalink($value->ID)); |
| 1527 | |
| 1528 | if(preg_match("/https?:\/\/[^\/]+\/(.+)/", $permalink, $out)){ |
| 1529 | $path = $this->getWpContentDir("/cache/all/").$out[1]; |
| 1530 | $mobile_path = $this->getWpContentDir("/cache/wpfc-mobile-cache/").$out[1]; |
| 1531 | |
| 1532 | if(is_dir($path)){ |
| 1533 | $this->rm_folder_recursively($path); |
| 1534 | } |
| 1535 | |
| 1536 | if(is_dir($mobile_path)){ |
| 1537 | $this->rm_folder_recursively($mobile_path); |
| 1538 | } |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | } |
| 1543 | |
| 1544 | |
| 1545 | } |
| 1546 | |
| 1547 | public function delete_sitemap_cache(){ |
| 1548 | //to clear sitemap.xml and sitemap-(.+).xml |
| 1549 | $files = array_merge(glob($this->getWpContentDir("/cache/all/")."sitemap*.xml"), glob($this->getWpContentDir("/cache/wpfc-mobile-cache/")."sitemap*.xml")); |
| 1550 | |
| 1551 | foreach((array)$files as $file){ |
| 1552 | $this->rm_folder_recursively($file); |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | public function delete_multiple_domain_mapping_cache($minified = false){ |
| 1557 | //https://wordpress.org/plugins/multiple-domain-mapping-on-single-site/ |
| 1558 | if($this->isPluginActive("multiple-domain-mapping-on-single-site/multidomainmapping.php")){ |
| 1559 | $multiple_arr = get_option('falke_mdm_mappings'); |
| 1560 | |
| 1561 | if(isset($multiple_arr) && isset($multiple_arr["mappings"]) && isset($multiple_arr["mappings"][0])){ |
| 1562 | foreach($multiple_arr["mappings"] as $mapping_key => $mapping_value){ |
| 1563 | if($minified){ |
| 1564 | $mapping_domain_path = preg_replace("/(\/cache\/[^\/]+\/all\/)/", "/cache/".$mapping_value["domain"]."/", $this->getWpContentDir("/cache/all/")); |
| 1565 | |
| 1566 | if(is_dir($mapping_domain_path)){ |
| 1567 | if(@rename($mapping_domain_path, $this->getWpContentDir("/cache/tmpWpfc/").$mapping_value["domain"]."_".time())){ |
| 1568 | |
| 1569 | } |
| 1570 | } |
| 1571 | }else{ |
| 1572 | $mapping_domain_path = preg_replace("/(\/cache\/[^\/]+\/all)/", "/cache/".$mapping_value["domain"]."/all", $this->getWpContentDir("/cache/all/index.html")); |
| 1573 | |
| 1574 | @unlink($mapping_domain_path); |
| 1575 | } |
| 1576 | } |
| 1577 | } |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | public function delete_author_page_cache($post_id){ |
| 1582 | $author_id = get_post_field ('post_author', $post_id); |
| 1583 | $permalink = get_author_posts_url($author_id); |
| 1584 | |
| 1585 | if(preg_match("/https?:\/\/[^\/]+\/(.+)/", $permalink, $out)){ |
| 1586 | $path = $this->getWpContentDir("/cache/all/").$out[1]; |
| 1587 | $mobile_path = $this->getWpContentDir("/cache/wpfc-mobile-cache/").$out[1]; |
| 1588 | |
| 1589 | $this->move_folder_to_tmpWpfc($path); |
| 1590 | $this->move_folder_to_tmpWpfc($mobile_path); |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | public function move_folder_to_tmpWpfc($path = false){ |
| 1595 | if(!is_dir($this->getWpContentDir("/cache/tmpWpfc"))){ |
| 1596 | @mkdir($this->getWpContentDir("/cache/tmpWpfc"), 0755, true); |
| 1597 | } |
| 1598 | |
| 1599 | if(!$path){ |
| 1600 | return false; |
| 1601 | } |
| 1602 | |
| 1603 | if(!is_dir($this->getWpContentDir("/cache/tmpWpfc"))){ |
| 1604 | return false; |
| 1605 | } |
| 1606 | |
| 1607 | if(is_dir($path)){ |
| 1608 | preg_match("/\/([^\/]+)\/?$/", $path, $type); |
| 1609 | |
| 1610 | if(isset($type[1])){ |
| 1611 | if(preg_match("/\/cache\/wpfc-mobile-cache\//", $path)){ |
| 1612 | $type[1] = "m_".$type[1]; |
| 1613 | } |
| 1614 | |
| 1615 | $move_to = $this->getWpContentDir("/cache/tmpWpfc/").$type[1]."_".time(); |
| 1616 | |
| 1617 | rename($path, $move_to); |
| 1618 | } |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | public function delete_cache_of_term($term_taxonomy_id){ |
| 1623 | $term = get_term_by("term_taxonomy_id", $term_taxonomy_id); |
| 1624 | |
| 1625 | if(!$term || is_wp_error($term)){ |
| 1626 | return false; |
| 1627 | } |
| 1628 | |
| 1629 | //if(preg_match("/cat|tag|store|listing/", $term->taxonomy)){} |
| 1630 | |
| 1631 | $url = get_term_link($term->term_id, $term->taxonomy); |
| 1632 | |
| 1633 | if(preg_match("/^http/", $url)){ |
| 1634 | $path = preg_replace("/https?\:\/\/[^\/]+/i", "", $url); |
| 1635 | $path = trim($path, "/"); |
| 1636 | $path = urldecode($path); |
| 1637 | |
| 1638 | // to remove the cache of tag/cat |
| 1639 | if(file_exists($this->getWpContentDir("/cache/all/").$path."/index.html")){ |
| 1640 | @unlink($this->getWpContentDir("/cache/all/").$path."/index.html"); |
| 1641 | } |
| 1642 | |
| 1643 | if(file_exists($this->getWpContentDir("/cache/wpfc-mobile-cache/").$path."/index.html")){ |
| 1644 | @unlink($this->getWpContentDir("/cache/wpfc-mobile-cache/").$path."/index.html"); |
| 1645 | } |
| 1646 | |
| 1647 | |
| 1648 | // to remove the cache of the pages |
| 1649 | $this->rm_folder_recursively($this->getWpContentDir("/cache/all/").$path."/page"); |
| 1650 | $this->rm_folder_recursively($this->getWpContentDir("/cache/wpfc-mobile-cache/").$path."/page"); |
| 1651 | |
| 1652 | // to remove the cache of the feeds |
| 1653 | $this->rm_folder_recursively($this->getWpContentDir("/cache/all/").$path."/feed"); |
| 1654 | $this->rm_folder_recursively($this->getWpContentDir("/cache/wpfc-mobile-cache/").$path."/feed"); |
| 1655 | } |
| 1656 | |
| 1657 | if($term->parent > 0){ |
| 1658 | $parent = get_term_by("id", $term->parent, $term->taxonomy); |
| 1659 | |
| 1660 | if(isset($parent->term_taxonomy_id)){ |
| 1661 | $this->delete_cache_of_term($parent->term_taxonomy_id); |
| 1662 | } |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | public function unlink($path){ |
| 1667 | if(file_exists($path)){ |
| 1668 | unlink($path); |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | public function deleteHomePageCache($log = true){ |
| 1673 | if($varnish_datas = get_option("WpFastestCacheVarnish")){ |
| 1674 | include_once('inc/varnish.php'); |
| 1675 | VarnishWPFC::purge_cache($varnish_datas); |
| 1676 | } |
| 1677 | |
| 1678 | include_once('inc/cdn.php'); |
| 1679 | CdnWPFC::cloudflare_clear_cache(); |
| 1680 | |
| 1681 | $site_url_path = preg_replace("/https?\:\/\/[^\/]+/i", "", site_url()); |
| 1682 | $home_url_path = preg_replace("/https?\:\/\/[^\/]+/i", "", home_url()); |
| 1683 | |
| 1684 | if($site_url_path){ |
| 1685 | $site_url_path = trim($site_url_path, "/"); |
| 1686 | |
| 1687 | if($site_url_path){ |
| 1688 | $this->unlink($this->getWpContentDir("/cache/all/").$site_url_path."/index.html"); |
| 1689 | $this->unlink($this->getWpContentDir("/cache/wpfc-mobile-cache/").$site_url_path."/index.html"); |
| 1690 | |
| 1691 | //to clear pagination of homepage cache |
| 1692 | $this->rm_folder_recursively($this->getWpContentDir("/cache/all/").$site_url_path."/page"); |
| 1693 | $this->rm_folder_recursively($this->getWpContentDir("/cache/wpfc-mobile-cache/").$site_url_path."/page"); |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | if($home_url_path){ |
| 1698 | $home_url_path = trim($home_url_path, "/"); |
| 1699 | |
| 1700 | if($home_url_path){ |
| 1701 | $this->unlink($this->getWpContentDir("/cache/all/").$home_url_path."/index.html"); |
| 1702 | $this->unlink($this->getWpContentDir("/cache/wpfc-mobile-cache/").$home_url_path."/index.html"); |
| 1703 | |
| 1704 | //to clear pagination of homepage cache |
| 1705 | $this->rm_folder_recursively($this->getWpContentDir("/cache/all/").$home_url_path."/page"); |
| 1706 | $this->rm_folder_recursively($this->getWpContentDir("/cache/wpfc-mobile-cache/").$home_url_path."/page"); |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | if(function_exists("wc_get_page_id")){ |
| 1711 | if($shop_id = wc_get_page_id('shop')){ |
| 1712 | $store_url_path = preg_replace("/https?\:\/\/[^\/]+/i", "", get_permalink($shop_id)); |
| 1713 | |
| 1714 | if($store_url_path){ |
| 1715 | $store_url_path = trim($store_url_path, "/"); |
| 1716 | |
| 1717 | if($store_url_path){ |
| 1718 | if(file_exists($this->getWpContentDir("/cache/all/").$store_url_path."/index.html")){ |
| 1719 | @unlink($this->getWpContentDir("/cache/all/").$store_url_path."/index.html"); |
| 1720 | } |
| 1721 | |
| 1722 | if(file_exists($this->getWpContentDir("/cache/wpfc-mobile-cache/").$store_url_path."/index.html")){ |
| 1723 | @unlink($this->getWpContentDir("/cache/wpfc-mobile-cache/").$store_url_path."/index.html"); |
| 1724 | } |
| 1725 | |
| 1726 | //to clear pagination of store homepage cache |
| 1727 | $this->rm_folder_recursively($this->getWpContentDir("/cache/all/").$store_url_path."/page"); |
| 1728 | $this->rm_folder_recursively($this->getWpContentDir("/cache/wpfc-mobile-cache/").$store_url_path."/page"); |
| 1729 | } |
| 1730 | } |
| 1731 | } |
| 1732 | } |
| 1733 | |
| 1734 | $this->unlink($this->getWpContentDir("/cache/all/index.html")); |
| 1735 | $this->unlink($this->getWpContentDir("/cache/wpfc-mobile-cache/index.html")); |
| 1736 | |
| 1737 | //to clear pagination of homepage cache |
| 1738 | $this->rm_folder_recursively($this->getWpContentDir("/cache/all/page")); |
| 1739 | $this->rm_folder_recursively($this->getWpContentDir("/cache/wpfc-mobile-cache/page")); |
| 1740 | |
| 1741 | // options-reading.php - static posts page |
| 1742 | if($page_for_posts_id = get_option('page_for_posts')){ |
| 1743 | $page_for_posts_permalink = urldecode(get_permalink($page_for_posts_id)); |
| 1744 | |
| 1745 | $page_for_posts_permalink = rtrim($page_for_posts_permalink, "/"); |
| 1746 | $page_for_posts_permalink = preg_replace("/__trashed$/", "", $page_for_posts_permalink); |
| 1747 | //for /%postname%/%post_id% : sample-url__trashed/57595 |
| 1748 | $page_for_posts_permalink = preg_replace("/__trashed\/(\d+)$/", "/$1", $page_for_posts_permalink); |
| 1749 | |
| 1750 | if(preg_match("/https?:\/\/[^\/]+\/(.+)/", $page_for_posts_permalink, $out)){ |
| 1751 | $page_for_posts_path = $this->getWpContentDir("/cache/all/").$out[1]; |
| 1752 | $page_for_posts_mobile_path = $this->getWpContentDir("/cache/wpfc-mobile-cache/").$out[1]; |
| 1753 | |
| 1754 | $this->rm_folder_recursively($page_for_posts_path); |
| 1755 | $this->rm_folder_recursively($page_for_posts_mobile_path); |
| 1756 | } |
| 1757 | } |
| 1758 | |
| 1759 | |
| 1760 | if($log){ |
| 1761 | if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){ |
| 1762 | include_once $this->get_premium_path("logs.php"); |
| 1763 | |
| 1764 | $log = new WpFastestCacheLogs("delete"); |
| 1765 | $log->action(); |
| 1766 | } |
| 1767 | } |
| 1768 | } |
| 1769 | |
| 1770 | public function deleteCache($minified = false){ |
| 1771 | if($varnish_datas = get_option("WpFastestCacheVarnish")){ |
| 1772 | include_once('inc/varnish.php'); |
| 1773 | VarnishWPFC::purge_cache($varnish_datas); |
| 1774 | } |
| 1775 | |
| 1776 | include_once('inc/cdn.php'); |
| 1777 | CdnWPFC::cloudflare_clear_cache(); |
| 1778 | |
| 1779 | $this->set_preload(); |
| 1780 | |
| 1781 | $created_tmpWpfc = false; |
| 1782 | $cache_deleted = false; |
| 1783 | $minifed_deleted = false; |
| 1784 | |
| 1785 | $cache_path = $this->getWpContentDir("/cache/all"); |
| 1786 | $minified_cache_path = $this->getWpContentDir("/cache/wpfc-minified"); |
| 1787 | |
| 1788 | if(class_exists("WpFcMobileCache")){ |
| 1789 | |
| 1790 | |
| 1791 | |
| 1792 | |
| 1793 | if(is_dir($this->getWpContentDir("/cache/wpfc-mobile-cache"))){ |
| 1794 | if(is_dir($this->getWpContentDir("/cache/tmpWpfc"))){ |
| 1795 | rename($this->getWpContentDir("/cache/wpfc-mobile-cache"), $this->getWpContentDir("/cache/tmpWpfc/mobile_").time()); |
| 1796 | }else if(@mkdir($this->getWpContentDir("/cache/tmpWpfc"), 0755, true)){ |
| 1797 | rename($this->getWpContentDir("/cache/wpfc-mobile-cache"), $this->getWpContentDir("/cache/tmpWpfc/mobile_").time()); |
| 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | |
| 1802 | } |
| 1803 | |
| 1804 | if(!is_dir($this->getWpContentDir("/cache/tmpWpfc"))){ |
| 1805 | if(@mkdir($this->getWpContentDir("/cache/tmpWpfc"), 0755, true)){ |
| 1806 | $created_tmpWpfc = true; |
| 1807 | }else{ |
| 1808 | $created_tmpWpfc = false; |
| 1809 | //$this->systemMessage = array("Permission of <strong>/wp-content/cache</strong> must be <strong>755</strong>", "error"); |
| 1810 | } |
| 1811 | }else{ |
| 1812 | $created_tmpWpfc = true; |
| 1813 | } |
| 1814 | |
| 1815 | //to clear widget cache path |
| 1816 | $this->deleteWidgetCache(); |
| 1817 | |
| 1818 | $this->delete_multiple_domain_mapping_cache($minified); |
| 1819 | |
| 1820 | if(is_dir($cache_path)){ |
| 1821 | if(@rename($cache_path, $this->getWpContentDir("/cache/tmpWpfc/").time())){ |
| 1822 | delete_option("WpFastestCacheHTML"); |
| 1823 | delete_option("WpFastestCacheHTMLSIZE"); |
| 1824 | delete_option("WpFastestCacheMOBILE"); |
| 1825 | delete_option("WpFastestCacheMOBILESIZE"); |
| 1826 | |
| 1827 | $cache_deleted = true; |
| 1828 | } |
| 1829 | }else{ |
| 1830 | $cache_deleted = true; |
| 1831 | } |
| 1832 | |
| 1833 | if($minified){ |
| 1834 | if(is_dir($minified_cache_path)){ |
| 1835 | if(@rename($minified_cache_path, $this->getWpContentDir("/cache/tmpWpfc/m").time())){ |
| 1836 | delete_option("WpFastestCacheCSS"); |
| 1837 | delete_option("WpFastestCacheCSSSIZE"); |
| 1838 | delete_option("WpFastestCacheJS"); |
| 1839 | delete_option("WpFastestCacheJSSIZE"); |
| 1840 | |
| 1841 | $minifed_deleted = true; |
| 1842 | } |
| 1843 | }else{ |
| 1844 | $minifed_deleted = true; |
| 1845 | } |
| 1846 | }else{ |
| 1847 | $minifed_deleted = true; |
| 1848 | } |
| 1849 | |
| 1850 | if($created_tmpWpfc && $cache_deleted && $minifed_deleted){ |
| 1851 | do_action('wpfc_delete_cache'); |
| 1852 | |
| 1853 | $this->notify(array("All cache files have been deleted", "updated")); |
| 1854 | |
| 1855 | if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){ |
| 1856 | include_once $this->get_premium_path("logs.php"); |
| 1857 | |
| 1858 | $log = new WpFastestCacheLogs("delete"); |
| 1859 | $log->action(); |
| 1860 | } |
| 1861 | }else{ |
| 1862 | $this->notify(array("Permissions Problem: <a href='http://www.wpfastestcache.com/warnings/delete-cache-problem-related-to-permission/' target='_blank'>Read More</a>", "error")); |
| 1863 | } |
| 1864 | |
| 1865 | // for ajax request |
| 1866 | if(isset($_GET["action"]) && in_array($_GET["action"], array("wpfc_delete_cache", "wpfc_delete_cache_and_minified"))){ |
| 1867 | die(json_encode($this->systemMessage)); |
| 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | public function checkCronTime(){ |
| 1872 | $crons = _get_cron_array(); |
| 1873 | |
| 1874 | foreach ((array)$crons as $cron_key => $cron_value) { |
| 1875 | foreach ( (array) $cron_value as $hook => $events ) { |
| 1876 | if(preg_match("/^wp\_fastest\_cache(.*)/", $hook, $id)){ |
| 1877 | if(!$id[1] || preg_match("/^\_(\d+)$/", $id[1])){ |
| 1878 | foreach ( (array) $events as $event_key => $event ) { |
| 1879 | add_action("wp_fastest_cache".$id[1], array($this, 'setSchedule')); |
| 1880 | } |
| 1881 | } |
| 1882 | } |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | add_action($this->slug()."_Preload", array($this, 'create_preload_cache'), 11); |
| 1887 | } |
| 1888 | |
| 1889 | public function set_preload(){ |
| 1890 | include_once('inc/preload.php'); |
| 1891 | PreloadWPFC::set_preload($this->slug()); |
| 1892 | } |
| 1893 | |
| 1894 | public function create_preload_cache(){ |
| 1895 | $this->options = $this->getOptions(); |
| 1896 | |
| 1897 | include_once('inc/preload.php'); |
| 1898 | PreloadWPFC::create_preload_cache($this->options); |
| 1899 | } |
| 1900 | |
| 1901 | public function wpfc_remote_get($url, $user_agent, $return_content = false){ |
| 1902 | //$response = wp_remote_get($url, array('timeout' => 10, 'sslverify' => false, 'headers' => array("cache-control" => array("no-store, no-cache, must-revalidate", "post-check=0, pre-check=0"),'user-agent' => $user_agent))); |
| 1903 | $response = wp_remote_get($url, array('user-agent' => $user_agent, 'timeout' => 10, 'sslverify' => false, 'headers' => array("cache-control" => "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"))); |
| 1904 | |
| 1905 | if (!$response || is_wp_error($response)){ |
| 1906 | echo $response->get_error_message()." - "; |
| 1907 | |
| 1908 | return false; |
| 1909 | }else{ |
| 1910 | if(wp_remote_retrieve_response_code($response) != 200){ |
| 1911 | return false; |
| 1912 | } |
| 1913 | |
| 1914 | if($return_content){ |
| 1915 | if(wp_remote_retrieve_response_code($response) == 200){ |
| 1916 | $data = wp_remote_retrieve_body($response); |
| 1917 | |
| 1918 | return $data; |
| 1919 | } |
| 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | return true; |
| 1924 | } |
| 1925 | |
| 1926 | public function setSchedule($args = ""){ |
| 1927 | if($args){ |
| 1928 | $rule = json_decode($args); |
| 1929 | |
| 1930 | if($rule->prefix == "all"){ |
| 1931 | $this->deleteCache(); |
| 1932 | }else if($rule->prefix == "homepage"){ |
| 1933 | $this->deleteHomePageCache(); |
| 1934 | |
| 1935 | if(isset($this->options->wpFastestCachePreload_homepage) && $this->options->wpFastestCachePreload_homepage){ |
| 1936 | $this->wpfc_remote_get(get_option("home"), "WP Fastest Cache Preload Bot - After Cache Timeout"); |
| 1937 | $this->wpfc_remote_get(get_option("home"), "WP Fastest Cache Preload iPhone Mobile Bot - After Cache Timeout"); |
| 1938 | } |
| 1939 | }else if($rule->prefix == "startwith"){ |
| 1940 | if(!is_dir($this->getWpContentDir("/cache/tmpWpfc"))){ |
| 1941 | if(@mkdir($this->getWpContentDir("/cache/tmpWpfc"), 0755, true)){} |
| 1942 | } |
| 1943 | |
| 1944 | $rule->content = trim($rule->content, "/"); |
| 1945 | |
| 1946 | $files = glob($this->getWpContentDir("/cache/all/").$rule->content."*"); |
| 1947 | |
| 1948 | foreach ((array)$files as $file) { |
| 1949 | $mobile_file = str_replace("/cache/all/", "/cache/wpfc-mobile-cache/", $file); |
| 1950 | |
| 1951 | @rename($file, $this->getWpContentDir("/cache/tmpWpfc/").time()); |
| 1952 | @rename($mobile_file, $this->getWpContentDir("/cache/tmpWpfc/mobile_").time()); |
| 1953 | } |
| 1954 | }else if($rule->prefix == "exact"){ |
| 1955 | $rule->content = trim($rule->content, "/"); |
| 1956 | |
| 1957 | @unlink($this->getWpContentDir("/cache/all/").$rule->content."/index.html"); |
| 1958 | @unlink($this->getWpContentDir("/cache/wpfc-mobile-cache/").$rule->content."/index.html"); |
| 1959 | } |
| 1960 | |
| 1961 | if($rule->prefix != "all"){ |
| 1962 | if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){ |
| 1963 | include_once $this->get_premium_path("logs.php"); |
| 1964 | $log = new WpFastestCacheLogs("delete"); |
| 1965 | $log->action($rule); |
| 1966 | } |
| 1967 | } |
| 1968 | }else{ |
| 1969 | //for old cron job |
| 1970 | $this->deleteCache(); |
| 1971 | } |
| 1972 | } |
| 1973 | |
| 1974 | public function modify_htaccess_for_new_user($user_id){ |
| 1975 | $path = ABSPATH; |
| 1976 | |
| 1977 | if($this->is_subdirectory_install()){ |
| 1978 | $path = $this->getABSPATH(); |
| 1979 | } |
| 1980 | |
| 1981 | $htaccess = @file_get_contents($path.".htaccess"); |
| 1982 | |
| 1983 | if(preg_match("/\#\s?Start_WPFC_Exclude_Admin_Cookie/", $htaccess)){ |
| 1984 | $rules = $this->excludeAdminCookie(); |
| 1985 | |
| 1986 | $htaccess = preg_replace("/\#\s?Start_WPFC_Exclude_Admin_Cookie[^\#]*\#\s?End_WPFC_Exclude_Admin_Cookie\s+/", $rules, $htaccess); |
| 1987 | } |
| 1988 | |
| 1989 | @file_put_contents($path.".htaccess", $htaccess); |
| 1990 | } |
| 1991 | |
| 1992 | public function excludeAdminCookie(){ |
| 1993 | $usernames = array(); |
| 1994 | $users_groups = array_chunk(get_users(array("role" => "administrator", "fields" => array("user_login"))), 5); |
| 1995 | |
| 1996 | foreach ($users_groups as $group_key => $group) { |
| 1997 | $tmp_user = ""; |
| 1998 | $tmp_rule = ""; |
| 1999 | |
| 2000 | foreach ($group as $key => $value) { |
| 2001 | $tmp_user = sanitize_user(wp_unslash($value->user_login), true); |
| 2002 | |
| 2003 | /* |
| 2004 | to replace spaces with %20 |
| 2005 | |
| 2006 | 1. Empty space character causes 500 internal server error |
| 2007 | 2. "\s" is not detected by htaccess so we added "%20" |
| 2008 | */ |
| 2009 | |
| 2010 | $tmp_user = preg_replace("/\s/", "%20", $tmp_user); |
| 2011 | |
| 2012 | array_push($usernames, $tmp_user); |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | $rule = "# Start_WPFC_Exclude_Admin_Cookie\n"; |
| 2017 | $rule = $rule."RewriteCond %{HTTP:Cookie} !wordpress_logged_in_[^\=]+\=".implode("|", $usernames); |
| 2018 | $rule = $rule."\n# End_WPFC_Exclude_Admin_Cookie\n"; |
| 2019 | |
| 2020 | return $rule; |
| 2021 | } |
| 2022 | |
| 2023 | public function excludeRules(){ |
| 2024 | $htaccess_page_rules = ""; |
| 2025 | $htaccess_page_useragent = ""; |
| 2026 | $htaccess_page_cookie = ""; |
| 2027 | |
| 2028 | if($rules_json = get_option("WpFastestCacheExclude")){ |
| 2029 | if($rules_json != "null"){ |
| 2030 | $rules_std = json_decode($rules_json); |
| 2031 | |
| 2032 | foreach ($rules_std as $key => $value) { |
| 2033 | $value->type = isset($value->type) ? $value->type : "page"; |
| 2034 | |
| 2035 | // escape the chars |
| 2036 | $value->content = str_replace("?", "\?", $value->content); |
| 2037 | |
| 2038 | if($value->type == "page"){ |
| 2039 | if($value->prefix == "startwith"){ |
| 2040 | $value->content = ltrim($value->content, "/"); |
| 2041 | |
| 2042 | $htaccess_page_rules = $htaccess_page_rules."RewriteCond %{REQUEST_URI} !^/".$value->content." [NC]\n"; |
| 2043 | } |
| 2044 | |
| 2045 | if($value->prefix == "contain"){ |
| 2046 | $htaccess_page_rules = $htaccess_page_rules."RewriteCond %{REQUEST_URI} !".$value->content." [NC]\n"; |
| 2047 | } |
| 2048 | |
| 2049 | if($value->prefix == "exact"){ |
| 2050 | $value->content = trim($value->content, "/"); |
| 2051 | |
| 2052 | $htaccess_page_rules = $htaccess_page_rules."RewriteCond %{REQUEST_URI} !\/".$value->content." [NC]\n"; |
| 2053 | } |
| 2054 | }else if($value->type == "useragent"){ |
| 2055 | $htaccess_page_useragent = $htaccess_page_useragent."RewriteCond %{HTTP_USER_AGENT} !".$value->content." [NC]\n"; |
| 2056 | }else if($value->type == "cookie"){ |
| 2057 | $htaccess_page_cookie = $htaccess_page_cookie."RewriteCond %{HTTP:Cookie} !".$value->content." [NC]\n"; |
| 2058 | } |
| 2059 | } |
| 2060 | } |
| 2061 | } |
| 2062 | |
| 2063 | return "# Start WPFC Exclude\n".$htaccess_page_rules.$htaccess_page_useragent.$htaccess_page_cookie."# End WPFC Exclude\n"; |
| 2064 | } |
| 2065 | |
| 2066 | public function getABSPATH(){ |
| 2067 | $path = ABSPATH; |
| 2068 | $siteUrl = site_url(); |
| 2069 | $homeUrl = home_url(); |
| 2070 | $diff = str_replace($homeUrl, "", $siteUrl); |
| 2071 | $diff = trim($diff,"/"); |
| 2072 | |
| 2073 | $pos = strrpos($path, $diff); |
| 2074 | |
| 2075 | if($pos !== false){ |
| 2076 | $path = substr_replace($path, "", $pos, strlen($diff)); |
| 2077 | $path = trim($path,"/"); |
| 2078 | $path = "/".$path."/"; |
| 2079 | } |
| 2080 | return $path; |
| 2081 | } |
| 2082 | |
| 2083 | public function rm_folder_recursively($dir, $i = 1) { |
| 2084 | if(is_dir($dir)){ |
| 2085 | $files = @scandir($dir); |
| 2086 | foreach((array)$files as $file) { |
| 2087 | if($i > 50 && !preg_match("/wp-fastest-cache-premium/i", $dir)){ |
| 2088 | return true; |
| 2089 | }else{ |
| 2090 | $i++; |
| 2091 | } |
| 2092 | if ('.' === $file || '..' === $file) continue; |
| 2093 | if (is_dir("$dir/$file")){ |
| 2094 | $this->rm_folder_recursively("$dir/$file", $i); |
| 2095 | }else{ |
| 2096 | if(file_exists("$dir/$file")){ |
| 2097 | @unlink("$dir/$file"); |
| 2098 | } |
| 2099 | } |
| 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | if(is_dir($dir)){ |
| 2104 | $files_tmp = @scandir($dir); |
| 2105 | |
| 2106 | if(!isset($files_tmp[2])){ |
| 2107 | @rmdir($dir); |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | return true; |
| 2112 | } |
| 2113 | |
| 2114 | public function is_subdirectory_install(){ |
| 2115 | if(strlen(site_url()) > strlen(home_url())){ |
| 2116 | return true; |
| 2117 | } |
| 2118 | return false; |
| 2119 | } |
| 2120 | |
| 2121 | protected function getMobileUserAgents(){ |
| 2122 | return implode("|", $this->get_mobile_browsers())."|".implode("|", $this->get_operating_systems()); |
| 2123 | } |
| 2124 | |
| 2125 | public function get_premium_path($name){ |
| 2126 | return WPFC_WP_PLUGIN_DIR."/wp-fastest-cache-premium/pro/library/".$name; |
| 2127 | } |
| 2128 | |
| 2129 | public function cron_add_minute( $schedules ) { |
| 2130 | $schedules['everyminute'] = array( |
| 2131 | 'interval' => 60*1, |
| 2132 | 'display' => __( 'Once Every 1 Minute' ), |
| 2133 | 'wpfc' => true |
| 2134 | ); |
| 2135 | |
| 2136 | $schedules['everyfiveminute'] = array( |
| 2137 | 'interval' => 60*5, |
| 2138 | 'display' => __( 'Once Every 5 Minutes' ), |
| 2139 | 'wpfc' => true |
| 2140 | ); |
| 2141 | |
| 2142 | $schedules['everyfifteenminute'] = array( |
| 2143 | 'interval' => 60*15, |
| 2144 | 'display' => __( 'Once Every 15 Minutes' ), |
| 2145 | 'wpfc' => true |
| 2146 | ); |
| 2147 | |
| 2148 | $schedules['twiceanhour'] = array( |
| 2149 | 'interval' => 60*30, |
| 2150 | 'display' => __( 'Twice an Hour' ), |
| 2151 | 'wpfc' => true |
| 2152 | ); |
| 2153 | |
| 2154 | $schedules['onceanhour'] = array( |
| 2155 | 'interval' => 60*60, |
| 2156 | 'display' => __( 'Once an Hour' ), |
| 2157 | 'wpfc' => true |
| 2158 | ); |
| 2159 | |
| 2160 | $schedules['everytwohours'] = array( |
| 2161 | 'interval' => 60*60*2, |
| 2162 | 'display' => __( 'Once Every 2 Hours' ), |
| 2163 | 'wpfc' => true |
| 2164 | ); |
| 2165 | |
| 2166 | $schedules['everythreehours'] = array( |
| 2167 | 'interval' => 60*60*3, |
| 2168 | 'display' => __( 'Once Every 3 Hours' ), |
| 2169 | 'wpfc' => true |
| 2170 | ); |
| 2171 | |
| 2172 | $schedules['everyfourhours'] = array( |
| 2173 | 'interval' => 60*60*4, |
| 2174 | 'display' => __( 'Once Every 4 Hours' ), |
| 2175 | 'wpfc' => true |
| 2176 | ); |
| 2177 | |
| 2178 | $schedules['everyfivehours'] = array( |
| 2179 | 'interval' => 60*60*5, |
| 2180 | 'display' => __( 'Once Every 5 Hours' ), |
| 2181 | 'wpfc' => true |
| 2182 | ); |
| 2183 | |
| 2184 | $schedules['everysixhours'] = array( |
| 2185 | 'interval' => 60*60*6, |
| 2186 | 'display' => __( 'Once Every 6 Hours' ), |
| 2187 | 'wpfc' => true |
| 2188 | ); |
| 2189 | |
| 2190 | $schedules['everysevenhours'] = array( |
| 2191 | 'interval' => 60*60*7, |
| 2192 | 'display' => __( 'Once Every 7 Hours' ), |
| 2193 | 'wpfc' => true |
| 2194 | ); |
| 2195 | |
| 2196 | $schedules['everyeighthours'] = array( |
| 2197 | 'interval' => 60*60*8, |
| 2198 | 'display' => __( 'Once Every 8 Hours' ), |
| 2199 | 'wpfc' => true |
| 2200 | ); |
| 2201 | |
| 2202 | $schedules['everyninehours'] = array( |
| 2203 | 'interval' => 60*60*9, |
| 2204 | 'display' => __( 'Once Every 9 Hours' ), |
| 2205 | 'wpfc' => true |
| 2206 | ); |
| 2207 | |
| 2208 | $schedules['everytenhours'] = array( |
| 2209 | 'interval' => 60*60*10, |
| 2210 | 'display' => __( 'Once Every 10 Hours' ), |
| 2211 | 'wpfc' => true |
| 2212 | ); |
| 2213 | |
| 2214 | $schedules['onceaday'] = array( |
| 2215 | 'interval' => 60*60*24, |
| 2216 | 'display' => __( 'Once a Day' ), |
| 2217 | 'wpfc' => true |
| 2218 | ); |
| 2219 | |
| 2220 | $schedules['everythreedays'] = array( |
| 2221 | 'interval' => 60*60*24*3, |
| 2222 | 'display' => __( 'Once Every 3 Days' ), |
| 2223 | 'wpfc' => true |
| 2224 | ); |
| 2225 | |
| 2226 | $schedules['everysevendays'] = array( |
| 2227 | 'interval' => 60*60*24*7, |
| 2228 | 'display' => __( 'Once Every 7 Days' ), |
| 2229 | 'wpfc' => true |
| 2230 | ); |
| 2231 | |
| 2232 | $schedules['everytendays'] = array( |
| 2233 | 'interval' => 60*60*24*10, |
| 2234 | 'display' => __( 'Once Every 10 Days' ), |
| 2235 | 'wpfc' => true |
| 2236 | ); |
| 2237 | |
| 2238 | $schedules['everyfifteendays'] = array( |
| 2239 | 'interval' => 60*60*24*15, |
| 2240 | 'display' => __( 'Once Every 15 Days' ), |
| 2241 | 'wpfc' => true |
| 2242 | ); |
| 2243 | |
| 2244 | $schedules['montly'] = array( |
| 2245 | 'interval' => 60*60*24*30, |
| 2246 | 'display' => __( 'Once a Month' ), |
| 2247 | 'wpfc' => true |
| 2248 | ); |
| 2249 | |
| 2250 | $schedules['yearly'] = array( |
| 2251 | 'interval' => 60*60*24*30*12, |
| 2252 | 'display' => __( 'Once a Year' ), |
| 2253 | 'wpfc' => true |
| 2254 | ); |
| 2255 | |
| 2256 | return $schedules; |
| 2257 | } |
| 2258 | |
| 2259 | public function setCustomInterval(){ |
| 2260 | add_filter( 'cron_schedules', array($this, 'cron_add_minute')); |
| 2261 | } |
| 2262 | |
| 2263 | public function isPluginActive( $plugin ) { |
| 2264 | return in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) || $this->isPluginActiveForNetwork( $plugin ); |
| 2265 | } |
| 2266 | |
| 2267 | public function isPluginActiveForNetwork( $plugin ) { |
| 2268 | if ( !is_multisite() ) |
| 2269 | return false; |
| 2270 | |
| 2271 | $plugins = get_site_option( 'active_sitewide_plugins'); |
| 2272 | if ( isset($plugins[$plugin]) ) |
| 2273 | return true; |
| 2274 | |
| 2275 | return false; |
| 2276 | } |
| 2277 | |
| 2278 | public function current_url(){ |
| 2279 | global $wp; |
| 2280 | $current_url = home_url($_SERVER['REQUEST_URI']); |
| 2281 | |
| 2282 | return $current_url; |
| 2283 | |
| 2284 | |
| 2285 | // if(defined('WP_CLI')){ |
| 2286 | // $_SERVER["SERVER_NAME"] = isset($_SERVER["SERVER_NAME"]) ? $_SERVER["SERVER_NAME"] : ""; |
| 2287 | // $_SERVER["SERVER_PORT"] = isset($_SERVER["SERVER_PORT"]) ? $_SERVER["SERVER_PORT"] : 80; |
| 2288 | // } |
| 2289 | |
| 2290 | // $pageURL = 'http'; |
| 2291 | |
| 2292 | // if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'){ |
| 2293 | // $pageURL .= 's'; |
| 2294 | // } |
| 2295 | |
| 2296 | // $pageURL .= '://'; |
| 2297 | |
| 2298 | // if($_SERVER['SERVER_PORT'] != '80'){ |
| 2299 | // $pageURL .= $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI']; |
| 2300 | // }else{ |
| 2301 | // $pageURL .= $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
| 2302 | // } |
| 2303 | |
| 2304 | // return $pageURL; |
| 2305 | } |
| 2306 | |
| 2307 | public function wpfc_load_plugin_textdomain(){ |
| 2308 | load_plugin_textdomain('wp-fastest-cache', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' ); |
| 2309 | } |
| 2310 | |
| 2311 | public function cdn_replace_urls($matches){ |
| 2312 | if(count($this->cdn) > 0){ |
| 2313 | foreach ($this->cdn as $key => $cdn) { |
| 2314 | if($cdn->id == "cloudflare"){ |
| 2315 | continue; |
| 2316 | } |
| 2317 | |
| 2318 | if(isset($cdn->status) && $cdn->status == "pause"){ |
| 2319 | continue; |
| 2320 | } |
| 2321 | |
| 2322 | if(preg_match("/manifest\.json\.php/i", $matches[0])){ |
| 2323 | return $matches[0]; |
| 2324 | } |
| 2325 | |
| 2326 | //https://site.com?brizy_media=AttachmentName.jpg&brizy_crop=CropSizes&brizy_post=TheCurrentPost |
| 2327 | if(preg_match("/brizy_media\=/i", $matches[0])){ |
| 2328 | return $matches[0]; |
| 2329 | } |
| 2330 | |
| 2331 | //https://cdn.shortpixel.ai/client/q_glossy,ret_img,w_736/http://wpfc.com/stories.png |
| 2332 | if(preg_match("/cdn\.shortpixel\.ai\/client/i", $matches[0])){ |
| 2333 | return $matches[0]; |
| 2334 | } |
| 2335 | |
| 2336 | |
| 2337 | if(preg_match("/^\/\/random/", $cdn->cdnurl) || preg_match("/\/\/i\d\.wp\.com/", $cdn->cdnurl)){ |
| 2338 | // Photon will no longer be supported |
| 2339 | continue; |
| 2340 | } |
| 2341 | |
| 2342 | $cdnurl = $cdn->cdnurl; |
| 2343 | |
| 2344 | $cdn->file_types = str_replace(",", "|", $cdn->file_types); |
| 2345 | |
| 2346 | if(preg_match("/\.(".$cdn->file_types.")(\"|\'|\?|\)|\s|\"\;)/i", $matches[0])){ |
| 2347 | //nothing |
| 2348 | }else{ |
| 2349 | if(preg_match("/js/", $cdn->file_types)){ |
| 2350 | if(!preg_match("/\/revslider\/public\/assets\/js/", $matches[0])){ |
| 2351 | continue; |
| 2352 | } |
| 2353 | }else{ |
| 2354 | continue; |
| 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | if($cdn->keywords){ |
| 2359 | $cdn->keywords = str_replace(",", "|", $cdn->keywords); |
| 2360 | |
| 2361 | if(!preg_match("/".preg_quote($cdn->keywords, "/")."/i", $matches[0])){ |
| 2362 | continue; |
| 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | if(isset($cdn->excludekeywords) && $cdn->excludekeywords){ |
| 2367 | $cdn->excludekeywords = str_replace(",", "|", $cdn->excludekeywords); |
| 2368 | |
| 2369 | if(preg_match("/".preg_quote($cdn->excludekeywords, "/")."/i", $matches[0])){ |
| 2370 | continue; |
| 2371 | } |
| 2372 | } |
| 2373 | |
| 2374 | if(preg_match("/(data-product_variations|data-siteorigin-parallax)\=[\"\'][^\"\']+[\"\']/i", $matches[0])){ |
| 2375 | $cdnurl = preg_replace("/(https?\:)?(\/\/)(www\.)?/", "", $cdnurl); |
| 2376 | |
| 2377 | // if(preg_match("/i\d\.wp\.com/i", $cdnurl)){ |
| 2378 | // $matches[0] = preg_replace("/(quot\;|\s)(https?\:)?(\\\\\/\\\\\/|\/\/)(www\.)?".$cdn->originurl."/i", "$1$2$3".$cdnurl, $matches[0]); |
| 2379 | // }else{ |
| 2380 | // $matches[0] = preg_replace("/(quot\;|\s)(https?\:)?(\\\\\/\\\\\/|\/\/)(www\.)?".$cdn->originurl."/i", "$1$2$3$4".$cdnurl, $matches[0]); |
| 2381 | // } |
| 2382 | |
| 2383 | $matches[0] = preg_replace("/(quot\;|\s)(https?\:)?(\\\\\/\\\\\/|\/\/)(www\.)?".$cdn->originurl."/i", '${1}${2}${3}'.$cdnurl, $matches[0]); |
| 2384 | |
| 2385 | |
| 2386 | }else if(preg_match("/\{\"concatemoji\"\:\"[^\"]+\"\}/i", $matches[0])){ |
| 2387 | $matches[0] = preg_replace("/(http(s?)\:)?".preg_quote("\/\/", "/")."(www\.)?/i", "", $matches[0]); |
| 2388 | $matches[0] = preg_replace("/".preg_quote($cdn->originurl, "/")."/i", $cdnurl, $matches[0]); |
| 2389 | }else if(isset($matches[2]) && preg_match("/".preg_quote($cdn->originurl, "/")."/", $matches[2])){ |
| 2390 | $matches[0] = preg_replace("/(http(s?)\:)?\/\/(www\.)?".preg_quote($cdn->originurl, "/")."/i", $cdnurl, $matches[0]); |
| 2391 | }else if(isset($matches[2]) && preg_match("/^(\/?)(wp-includes|wp-content)/", $matches[2])){ |
| 2392 | $matches[0] = preg_replace("/(\/?)(wp-includes|wp-content)/i", $cdnurl."/"."$2", $matches[0]); |
| 2393 | }else if(preg_match("/[\"\']https?\:\\\\\/\\\\\/[^\"\']+[\"\']/i", $matches[0])){ |
| 2394 | if(preg_match("/^(logo|url|image)$/i", $matches[1])){ |
| 2395 | //If the url is called with "//", it causes an error on https://search.google.com/structured-data/testing-tool/u/0/ |
| 2396 | //<script type="application/ld+json">"logo":{"@type":"ImageObject","url":"\/\/cdn.site.com\/image.png"}</script> |
| 2397 | //<script type="application/ld+json">{"logo":"\/\/cdn.site.com\/image.png"}</script> |
| 2398 | //<script type="application/ld+json">{"image":"\/\/cdn.site.com\/image.jpg"}</script> |
| 2399 | }else{ |
| 2400 | //<script>var loaderRandomImages=["https:\/\/www.site.com\/wp-content\/uploads\/2016\/12\/image.jpg"];</script> |
| 2401 | $matches[0] = preg_replace("/\\\\\//", "/", $matches[0]); |
| 2402 | |
| 2403 | if(preg_match("/".preg_quote($cdn->originurl, "/")."/", $matches[0])){ |
| 2404 | $matches[0] = preg_replace("/(http(s?)\:)?\/\/(www\.)?".preg_quote($cdn->originurl, "/")."/i", $cdnurl, $matches[0]); |
| 2405 | $matches[0] = preg_replace("/\//", "\/", $matches[0]); |
| 2406 | } |
| 2407 | } |
| 2408 | } |
| 2409 | } |
| 2410 | } |
| 2411 | |
| 2412 | return $matches[0]; |
| 2413 | } |
| 2414 | |
| 2415 | public function read_file($url){ |
| 2416 | if(!preg_match("/\.php/", $url)){ |
| 2417 | $url = preg_replace("/\?.*/", "", $url); |
| 2418 | |
| 2419 | if(preg_match("/wp-content/", $url)){ |
| 2420 | $path = preg_replace("/.+\/wp-content\/(.+)/", WPFC_WP_CONTENT_DIR."/"."$1", $url); |
| 2421 | }else if(preg_match("/wp-includes/", $url)){ |
| 2422 | $path = preg_replace("/.+\/wp-includes\/(.+)/", ABSPATH."wp-includes/"."$1", $url); |
| 2423 | } |
| 2424 | |
| 2425 | if(isset($path)){ |
| 2426 | if(@file_exists($path)){ |
| 2427 | $filesize = filesize($path); |
| 2428 | |
| 2429 | if($filesize > 0){ |
| 2430 | $myfile = fopen($path, "r") or die("Unable to open file!"); |
| 2431 | $data = fread($myfile, $filesize); |
| 2432 | fclose($myfile); |
| 2433 | |
| 2434 | return $data; |
| 2435 | }else{ |
| 2436 | return false; |
| 2437 | } |
| 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | |
| 2442 | } |
| 2443 | |
| 2444 | return false; |
| 2445 | } |
| 2446 | |
| 2447 | public function get_operating_systems(){ |
| 2448 | $operating_systems = array( |
| 2449 | 'Android', |
| 2450 | 'blackberry|\bBB10\b|rim\stablet\sos', |
| 2451 | 'PalmOS|avantgo|blazer|elaine|hiptop|palm|plucker|xiino', |
| 2452 | 'Symbian|SymbOS|Series60|Series40|SYB-[0-9]+|\bS60\b', |
| 2453 | 'Windows\sCE.*(PPC|Smartphone|Mobile|[0-9]{3}x[0-9]{3})|Window\sMobile|Windows\sPhone\s[0-9.]+|WCE;', |
| 2454 | 'Windows\sPhone\s10.0|Windows\sPhone\s8.1|Windows\sPhone\s8.0|Windows\sPhone\sOS|XBLWP7|ZuneWP7|Windows\sNT\s6\.[23]\;\sARM\;', |
| 2455 | '\biPhone.*Mobile|\biPod|\biPad', |
| 2456 | 'Apple-iPhone7C2', |
| 2457 | 'MeeGo', |
| 2458 | 'Maemo', |
| 2459 | 'J2ME\/|\bMIDP\b|\bCLDC\b', // '|Java/' produces bug #135 |
| 2460 | 'webOS|hpwOS', |
| 2461 | '\bBada\b', |
| 2462 | 'BREW' |
| 2463 | ); |
| 2464 | return $operating_systems; |
| 2465 | } |
| 2466 | |
| 2467 | public function get_mobile_browsers(){ |
| 2468 | $mobile_browsers = array( |
| 2469 | '\bCrMo\b|CriOS|Android.*Chrome\/[.0-9]*\s(Mobile)?', |
| 2470 | '\bDolfin\b', |
| 2471 | 'Opera.*Mini|Opera.*Mobi|Android.*Opera|Mobile.*OPR\/[0-9.]+|Coast\/[0-9.]+', |
| 2472 | 'Skyfire', |
| 2473 | 'Mobile\sSafari\/[.0-9]*\sEdge', |
| 2474 | 'IEMobile|MSIEMobile', // |Trident/[.0-9]+ |
| 2475 | 'fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile|FxiOS', |
| 2476 | 'bolt', |
| 2477 | 'teashark', |
| 2478 | 'Blazer', |
| 2479 | 'Version.*Mobile.*Safari|Safari.*Mobile|MobileSafari', |
| 2480 | 'Tizen', |
| 2481 | 'UC.*Browser|UCWEB', |
| 2482 | 'baiduboxapp', |
| 2483 | 'baidubrowser', |
| 2484 | 'DiigoBrowser', |
| 2485 | 'Puffin', |
| 2486 | '\bMercury\b', |
| 2487 | 'Obigo', |
| 2488 | 'NF-Browser', |
| 2489 | 'NokiaBrowser|OviBrowser|OneBrowser|TwonkyBeamBrowser|SEMC.*Browser|FlyFlow|Minimo|NetFront|Novarra-Vision|MQQBrowser|MicroMessenger', |
| 2490 | 'Android.*PaleMoon|Mobile.*PaleMoon' |
| 2491 | ); |
| 2492 | return $mobile_browsers; |
| 2493 | } |
| 2494 | |
| 2495 | |
| 2496 | } |
| 2497 | |
| 2498 | // Load WP CLI command(s) on demand. |
| 2499 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 2500 | require_once "inc/cli.php"; |
| 2501 | } |
| 2502 | |
| 2503 | function wpfc_clear_all_site_cache(){ |
| 2504 | if(defined('WPFC_DISABLE_HOOK_CLEAR_ALL_CACHE') && WPFC_DISABLE_HOOK_CLEAR_ALL_CACHE){ |
| 2505 | return array("success" => false, "message" => "Clearing Cache Hook system has been disabled"); |
| 2506 | } |
| 2507 | |
| 2508 | do_action("wpfc_clear_all_cache"); |
| 2509 | } |
| 2510 | |
| 2511 | function wpfc_clear_all_cache($minified = false){ |
| 2512 | if(defined('WPFC_DISABLE_HOOK_CLEAR_ALL_CACHE') && WPFC_DISABLE_HOOK_CLEAR_ALL_CACHE){ |
| 2513 | return array("success" => false, "message" => "Clearing Cache Hook system has been disabled"); |
| 2514 | } |
| 2515 | |
| 2516 | do_action("wpfc_clear_all_cache", $minified); |
| 2517 | } |
| 2518 | |
| 2519 | function wpfc_exclude_current_page(){ |
| 2520 | do_action("wpfc_exclude_current_page"); |
| 2521 | } |
| 2522 | |
| 2523 | function wpfc_clear_post_cache_by_id($post_id = false){ |
| 2524 | if($post_id){ |
| 2525 | do_action("wpfc_clear_post_cache_by_id", false, $post_id); |
| 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | function wpfc_create_post_cache_by_id($post_id = false){ |
| 2530 | if($post_id){ |
| 2531 | do_action("wpfc_create_post_cache_by_id", $post_id); |
| 2532 | } |
| 2533 | } |
| 2534 | |
| 2535 | |
| 2536 | |
| 2537 | $GLOBALS["wp_fastest_cache"] = new WpFastestCache(); |
| 2538 | |
| 2539 | |
| 2540 | |
| 2541 | ?> |