PluginProbe ʕ •ᴥ•ʔ
WP Fastest Cache – WordPress Cache Plugin / 0.8.8.5
WP Fastest Cache – WordPress Cache Plugin v0.8.8.5
1.4.9 1.4.8 trunk 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7.0 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.7.7 0.8.7.8 0.8.7.9 0.8.8.0 0.8.8.1 0.8.8.2 0.8.8.3 0.8.8.4 0.8.8.5 0.8.8.6 0.8.8.7 0.8.8.8 0.8.8.9 0.8.9.0 0.8.9.1 0.8.9.2 0.8.9.3 0.8.9.4 0.8.9.5 0.8.9.6 0.8.9.7 0.8.9.8 0.8.9.9 0.9.0.0 0.9.0.1 0.9.0.2 0.9.0.3 0.9.0.4 0.9.0.5 0.9.0.6 0.9.0.7 0.9.0.8 0.9.0.9 0.9.1.0 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 0.9.1.5 0.9.1.6 0.9.1.7 0.9.1.8 0.9.1.9 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7
wp-fastest-cache / wpFastestCache.php
wp-fastest-cache Last commit date
css 8 years ago images 7 years ago inc 7 years ago js 7 years ago languages 10 years ago templates 7 years ago index.html 11 years ago readme.txt 7 years ago uninstall.php 8 years ago wpFastestCache.php 7 years ago
wpFastestCache.php
1950 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: 0.8.8.5
7 Author: Emre Vona
8 Author URI: http://tr.linkedin.com/in/emrevona
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 //test6
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
90 public function __construct(){
91 $this->set_content_url();
92
93 $optimize_image_ajax_requests = array("wpfc_revert_image_ajax_request",
94 "wpfc_statics_ajax_request",
95 "wpfc_optimize_image_ajax_request",
96 "wpfc_update_image_list_ajax_request"
97 );
98
99 add_action('wp_ajax_wpfc_delete_cache', array($this, "deleteCacheToolbar"));
100 add_action('wp_ajax_wpfc_delete_cache_and_minified', array($this, "deleteCssAndJsCacheToolbar"));
101 add_action('wp_ajax_wpfc_delete_current_page_cache', array($this, "delete_current_page_cache"));
102 add_action( 'wp_ajax_wpfc_save_timeout_pages', array($this, 'wpfc_save_timeout_pages_callback'));
103 add_action( 'wp_ajax_wpfc_save_exclude_pages', array($this, 'wpfc_save_exclude_pages_callback'));
104 add_action( 'wp_ajax_wpfc_cdn_options', array($this, 'wpfc_cdn_options_ajax_request_callback'));
105 add_action( 'wp_ajax_wpfc_remove_cdn_integration', array($this, 'wpfc_remove_cdn_integration_ajax_request_callback'));
106 add_action( 'wp_ajax_wpfc_save_cdn_integration', array($this, 'wpfc_save_cdn_integration_ajax_request_callback'));
107 add_action( 'wp_ajax_wpfc_cdn_template', array($this, 'wpfc_cdn_template_ajax_request_callback'));
108 add_action( 'wp_ajax_wpfc_check_url', array($this, 'wpfc_check_url_ajax_request_callback'));
109 add_action( 'wp_ajax_wpfc_cache_statics_get', array($this, 'wpfc_cache_statics_get_callback'));
110 add_action( 'wp_ajax_wpfc_db_statics', array($this, 'wpfc_db_statics_callback'));
111 add_action( 'wp_ajax_wpfc_db_fix', array($this, 'wpfc_db_fix_callback'));
112 add_action( 'rate_post', array($this, 'wp_postratings_clear_fastest_cache'), 10, 2);
113 add_action( 'user_register', array($this, 'modify_htaccess_for_new_user'), 10, 1);
114 add_action( 'profile_update', array($this, 'modify_htaccess_for_new_user'), 10, 1);
115 add_action( 'edit_terms', array($this, 'delete_cache_of_term'), 10, 1);
116
117 // to check nonce is timeout or not
118 //add_action('init', array($this, "nonce_timeout"));
119
120 // to clear cache after new Woocommerce orders
121 add_action( 'woocommerce_checkout_order_processed', array($this, 'clear_cache_after_woocommerce_checkout_order_processed'), 1, 1);
122
123 // kk Star Ratings: to clear the cache of the post after voting
124 add_action( 'kksr_rate', array($this, 'clear_cache_on_kksr_rate'));
125
126 // to clear cache after ajax request by other plugins
127 if(isset($_POST["action"])){
128 // All In One Schema.org Rich Snippets
129 if(preg_match("/bsf_(update|submit)_rating/i", $_POST["action"])){
130 if(isset($_POST["post_id"])){
131 $this->singleDeleteCache(false, $_POST["post_id"]);
132 }
133 }
134
135 // Yet Another Stars Rating
136 if($_POST["action"] == "yasr_send_visitor_rating"){
137 if(isset($_POST["post_id"])){
138 // to need call like that because get_permalink() does not work if we call singleDeleteCache() directly
139 add_action('init', array($this, "singleDeleteCache"));
140 }
141 }
142 }
143
144 // to clear /tmpWpfc folder
145 if(is_dir($this->getWpContentDir()."/cache/tmpWpfc")){
146 $this->rm_folder_recursively($this->getWpContentDir()."/cache/tmpWpfc");
147 }
148
149 if($this->isPluginActive('wp-polls/wp-polls.php')){
150 //for WP-Polls
151 require_once "inc/wp-polls.php";
152 $wp_polls = new WpPollsForWpFc();
153 $wp_polls->hook();
154 }
155
156 if(isset($_GET) && isset($_GET["action"]) && in_array($_GET["action"], $optimize_image_ajax_requests)){
157 if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){
158 include_once $this->get_premium_path("image.php");
159 $img = new WpFastestCacheImageOptimisation();
160 $img->hook();
161 }
162 }else if(isset($_GET) && isset($_GET["action"]) && $_GET["action"] == "wpfastestcache"){
163 if(isset($_GET) && isset($_GET["type"]) && $_GET["type"] == "preload"){
164 // /?action=wpfastestcache&type=preload
165
166 add_action('init', array($this, "create_preload_cache"), 11);
167 }
168
169 if(isset($_GET) && isset($_GET["type"]) && preg_match("/^clearcache(andminified)*$/i", $_GET["type"])){
170 // /?action=wpfastestcache&type=clearcache&token=123
171 // /?action=wpfastestcache&type=clearcacheandminified&token=123
172
173 if(isset($_GET["token"]) && $_GET["token"]){
174 if(defined("WPFC_CLEAR_CACHE_URL_TOKEN") && WPFC_CLEAR_CACHE_URL_TOKEN){
175 if(WPFC_CLEAR_CACHE_URL_TOKEN == $_GET["token"]){
176 if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){
177 include_once $this->get_premium_path("mobile-cache.php");
178 }
179
180 if($_GET["type"] == "clearcache"){
181 $this->deleteCache();
182 }
183
184 if($_GET["type"] == "clearcacheandminified"){
185 $this->deleteCache(true);
186 }
187
188 die("Done");
189 }else{
190 die("Wrong token");
191 }
192 }else{
193 die("WPFC_CLEAR_CACHE_URL_TOKEN must be defined");
194 }
195 }else{
196 die("Security token must be set.");
197 }
198 }
199 }else{
200 $this->setCustomInterval();
201
202 $this->options = $this->getOptions();
203
204 add_action('transition_post_status', array($this, 'on_all_status_transitions'), 10, 3 );
205
206 $this->commentHooks();
207
208 $this->checkCronTime();
209
210 if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){
211 include_once $this->get_premium_path("mobile-cache.php");
212
213 if(file_exists(WPFC_WP_PLUGIN_DIR."/wp-fastest-cache-premium/pro/library/statics.php")){
214 include_once $this->get_premium_path("statics.php");
215 }
216
217 if(!defined('DOING_AJAX')){
218 include_once $this->get_premium_path("powerful-html.php");
219 }
220 }
221
222 if(is_admin()){
223 add_action('wp_loaded', array($this, "load_column"));
224
225 if(defined('DOING_AJAX') && DOING_AJAX){
226 //do nothing
227 }else{
228 // to avoid loading menu and optionPage() twice
229 if(!class_exists("WpFastestCacheAdmin")){
230 //for wp-panel
231
232 if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){
233 include_once $this->get_premium_path("image.php");
234 }
235
236 if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){
237 include_once $this->get_premium_path("logs.php");
238 }
239
240 add_action('plugins_loaded', array($this, 'wpfc_load_plugin_textdomain'));
241 add_action('wp_loaded', array($this, "load_admin_toolbar"));
242
243 $this->admin();
244 }
245 }
246 }else{
247 if(preg_match("/wpfc-minified\/([^\/]+)\/([^\/]+)/", $this->current_url(), $path)){
248 if($sources = @scandir(WPFC_WP_CONTENT_DIR."/cache/wpfc-minified/".$path[1], 1)){
249 if(isset($sources[0])){
250 // $exist_url = str_replace($path[2], $sources[0], $this->current_url());
251 // header('Location: ' . $exist_url, true, 301);
252 // exit;
253
254 if(preg_match("/\.css/", $this->current_url())){
255 header('Content-type: text/css');
256 }else if(preg_match("/\.js/", $this->current_url())){
257 header('Content-type: text/js');
258 }
259
260 echo file_get_contents(WPFC_WP_CONTENT_DIR."/cache/wpfc-minified/".$path[1]."/".$sources[0]);
261 exit;
262 }
263 }
264
265 //for non-exists files
266 if(preg_match("/\.css/", $this->current_url())){
267 header('Content-type: text/css');
268 die("/* File not found */");
269 }else if(preg_match("/\.js/", $this->current_url())){
270 header('Content-type: text/js');
271 die("//File not found");
272 }
273 }else{
274 // to show if the user is logged-in
275 add_action('wp_loaded', array($this, "load_admin_toolbar"));
276
277 //for cache
278 $this->cache();
279 }
280 }
281 }
282 }
283
284 public function set_content_url(){
285 $content_url = content_url();
286
287 // Hide My WP
288 if($this->isPluginActive('hide_my_wp/hide-my-wp.php')){
289 $hide_my_wp = get_option("hide_my_wp");
290
291 if(isset($hide_my_wp["new_content_path"]) && $hide_my_wp["new_content_path"]){
292 $hide_my_wp["new_content_path"] = trim($hide_my_wp["new_content_path"], "/");
293 $content_url = str_replace(basename(WPFC_WP_CONTENT_DIR), $hide_my_wp["new_content_path"], $content_url);
294 }
295 }
296
297 if (!defined('WPFC_WP_CONTENT_URL')) {
298 define("WPFC_WP_CONTENT_URL", $content_url);
299 }
300
301 $this->content_url = $content_url;
302 }
303
304 public function clear_cache_on_kksr_rate($id){
305 $this->singleDeleteCache(false, $id);
306 }
307
308 public function nonce_timeout(){
309 if(!is_user_logged_in()){
310 $run = false;
311 $list = array(
312 "caldera-forms/caldera-core.php",
313 "contact-form-7/wp-contact-form-7.php",
314 "js_composer/js_composer.php",
315 "kk-star-ratings/index.php",
316 "ninja-forms/ninja-forms.php",
317 "yet-another-stars-rating/yet-another-stars-rating.php"
318 );
319
320 foreach ($list as $key => $value) {
321 if($this->isPluginActive($value)){
322 $run = true;
323 }
324 }
325
326 if($run){
327 include_once('inc/nonce-timeout.php');
328
329 $wpfc_nonce = new WPFC_NONCE_TIMEOUT(WPFC_WP_CONTENT_DIR."/cache/all");
330
331 if(!$wpfc_nonce->verify_nonce()){
332 $this->deleteCache();
333 }
334 }
335 }
336 }
337
338 public function clear_cache_after_woocommerce_checkout_order_processed($order_id = false){
339 if(function_exists("wc_get_order")){
340 if($order_id){
341 $order = wc_get_order($order_id);
342
343 if($order){
344 foreach($order->get_items() as $item_key => $item_values ){
345 if(method_exists($item_values, 'get_product_id')){
346 $this->singleDeleteCache(false, $item_values->get_product_id());
347 }
348 }
349 }
350 }
351 }
352 }
353
354 public function wpfc_db_fix_callback(){
355 if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){
356 include_once $this->get_premium_path("db.php");
357
358 if(class_exists("WpFastestCacheDatabaseCleanup")){
359 WpFastestCacheDatabaseCleanup::clean($_GET["type"]);
360 }else{
361 die(json_encode(array("success" => false, "showupdatewarning" => true, "message" => "Only available in Premium version")));
362 }
363
364 }else{
365 die(json_encode(array("success" => false, "message" => "Only available in Premium version")));
366 }
367 }
368
369 public function wpfc_db_statics_callback(){
370 global $wpdb;
371
372 $statics = array("all_warnings" => 0,
373 "post_revisions" => 0,
374 "trashed_contents" => 0,
375 "trashed_spam_comments" => 0,
376 "trackback_pingback" => 0,
377 "transient_options" => 0
378 );
379
380
381 $statics["post_revisions"] = $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->posts` WHERE post_type = 'revision';");
382 $statics["all_warnings"] = $statics["all_warnings"] + $statics["post_revisions"];
383
384 $statics["trashed_contents"] = $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->posts` WHERE post_status = 'trash';");
385 $statics["all_warnings"] = $statics["all_warnings"] + $statics["trashed_contents"];
386
387 $statics["trashed_spam_comments"] = $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->comments` WHERE comment_approved = 'spam' OR comment_approved = 'trash' ;");
388 $statics["all_warnings"] = $statics["all_warnings"] + $statics["trashed_spam_comments"];
389
390 $statics["trackback_pingback"] = $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->comments` WHERE comment_type = 'trackback' OR comment_type = 'pingback' ;");
391 $statics["all_warnings"] = $statics["all_warnings"] + $statics["trackback_pingback"];
392
393 $element = "SELECT COUNT(*) FROM `$wpdb->options` WHERE option_name LIKE '%\_transient\_%' ;";
394 $statics["transient_options"] = $wpdb->get_var( $element ) > 20 ? $wpdb->get_var( $element ) : 0;
395 $statics["all_warnings"] = $statics["all_warnings"] + $statics["transient_options"];
396
397 die(json_encode($statics));
398 }
399
400 public function is_trailing_slash(){
401 // no need to check if Custom Permalinks plugin is active (https://tr.wordpress.org/plugins/custom-permalinks/)
402 if($this->isPluginActive("custom-permalinks/custom-permalinks.php")){
403 return false;
404 }
405
406 if($permalink_structure = get_option('permalink_structure')){
407 if(preg_match("/\/$/", $permalink_structure)){
408 return true;
409 }
410 }
411
412 return false;
413 }
414
415 public function wpfc_cache_statics_get_callback(){
416 if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){
417 if(file_exists(WPFC_WP_PLUGIN_DIR."/wp-fastest-cache-premium/pro/library/statics.php")){
418 include_once $this->get_premium_path("statics.php");
419
420 $cache_statics = new WpFastestCacheStatics();
421 $res = $cache_statics->get();
422 echo json_encode($res);
423 exit;
424 }
425 }
426 }
427
428 public function wpfc_check_url_ajax_request_callback(){
429 include_once('inc/cdn.php');
430 CdnWPFC::check_url();
431 }
432
433 public function wpfc_cdn_template_ajax_request_callback(){
434 include_once('inc/cdn.php');
435 CdnWPFC::cdn_template();
436 }
437
438 public function wpfc_save_cdn_integration_ajax_request_callback(){
439 include_once('inc/cdn.php');
440 CdnWPFC::save_cdn_integration();
441
442 }
443
444 public function wpfc_remove_cdn_integration_ajax_request_callback(){
445 include_once('inc/cdn.php');
446 CdnWPFC::remove_cdn_integration();
447 }
448
449 public function wpfc_cdn_options_ajax_request_callback(){
450 include_once('inc/cdn.php');
451 CdnWPFC::cdn_options();
452 }
453
454 public function wpfc_save_exclude_pages_callback(){
455 if(!wp_verify_nonce($_POST["security"], 'wpfc-save-exclude-ajax-nonce')){
456 die( 'Security check' );
457 }
458
459 if(current_user_can('manage_options')){
460 if(isset($_POST["rules"])){
461 foreach ($_POST["rules"] as $key => &$value) {
462 $value["prefix"] = strip_tags($value["prefix"]);
463 $value["content"] = strip_tags($value["content"]);
464
465 $value["prefix"] = preg_replace("/\'|\"/", "", $value["prefix"]);
466 $value["content"] = preg_replace("/\'|\"/", "", $value["content"]);
467
468 $value["content"] = trim($value["content"], "/");
469
470 $value["content"] = preg_replace("/(\#|\s|\(|\)|\*)/", "", $value["content"]);
471
472 if($value["prefix"] == "homepage"){
473 $this->deleteHomePageCache(false);
474 }
475 }
476
477 $data = json_encode($_POST["rules"]);
478
479 if(get_option("WpFastestCacheExclude")){
480 update_option("WpFastestCacheExclude", $data);
481 }else{
482 add_option("WpFastestCacheExclude", $data, null, "yes");
483 }
484 }else{
485 delete_option("WpFastestCacheExclude");
486 }
487
488 $this->modify_htaccess_for_exclude();
489
490 echo json_encode(array("success" => true));
491 exit;
492 }else{
493 wp_die("Must be admin");
494 }
495 }
496
497 public function modify_htaccess_for_exclude(){
498 $path = ABSPATH;
499
500 if($this->is_subdirectory_install()){
501 $path = $this->getABSPATH();
502 }
503
504 $htaccess = @file_get_contents($path.".htaccess");
505
506 if(preg_match("/\#\s?Start\sWPFC\sExclude/", $htaccess)){
507 $exclude_rules = $this->excludeRules();
508
509 $htaccess = preg_replace("/\#\s?Start\sWPFC\sExclude[^\#]*\#\s?End\sWPFC\sExclude\s+/", $exclude_rules, $htaccess);
510 }
511
512 @file_put_contents($path.".htaccess", $htaccess);
513 }
514
515 public function wpfc_save_timeout_pages_callback(){
516 if(!wp_verify_nonce($_POST["security"], 'wpfc-save-timeout-ajax-nonce')){
517 die( 'Security check' );
518 }
519
520 if(current_user_can('manage_options')){
521 $this->setCustomInterval();
522
523 $crons = _get_cron_array();
524
525 foreach ($crons as $cron_key => $cron_value) {
526 foreach ( (array) $cron_value as $hook => $events ) {
527 if(preg_match("/^wp\_fastest\_cache(.*)/", $hook, $id)){
528 if(!$id[1] || preg_match("/^\_(\d+)$/", $id[1])){
529 foreach ( (array) $events as $event_key => $event ) {
530 if($id[1]){
531 wp_clear_scheduled_hook("wp_fastest_cache".$id[1], $event["args"]);
532 }else{
533 wp_clear_scheduled_hook("wp_fastest_cache", $event["args"]);
534 }
535 }
536 }
537 }
538 }
539 }
540
541 if(isset($_POST["rules"]) && count($_POST["rules"]) > 0){
542 $i = 0;
543
544 foreach ($_POST["rules"] as $key => $value) {
545 if(preg_match("/^(daily|onceaday)$/i", $value["schedule"]) && isset($value["hour"]) && isset($value["minute"]) && strlen($value["hour"]) > 0 && strlen($value["minute"]) > 0){
546 $args = array("prefix" => $value["prefix"], "content" => $value["content"], "hour" => $value["hour"], "minute" => $value["minute"]);
547
548 $timestamp = mktime($value["hour"],$value["minute"],0,date("m"),date("d"),date("Y"));
549
550 $timestamp = $timestamp > time() ? $timestamp : $timestamp + 60*60*24;
551 }else{
552 $args = array("prefix" => $value["prefix"], "content" => $value["content"]);
553 $timestamp = time();
554 }
555
556 wp_schedule_event($timestamp, $value["schedule"], "wp_fastest_cache_".$i, array(json_encode($args)));
557 $i = $i + 1;
558 }
559 }
560
561 echo json_encode(array("success" => true));
562 exit;
563 }else{
564 wp_die("Must be admin");
565 }
566 }
567
568 public function wp_postratings_clear_fastest_cache($rate_userid, $post_id){
569 // to remove cache if vote is from homepage or category page or tag
570 if(isset($_SERVER["HTTP_REFERER"]) && $_SERVER["HTTP_REFERER"]){
571 $url = parse_url($_SERVER["HTTP_REFERER"]);
572
573 $url["path"] = isset($url["path"]) ? $url["path"] : "/index.html";
574
575 if(isset($url["path"])){
576 if($url["path"] == "/"){
577 $this->rm_folder_recursively($this->getWpContentDir()."/cache/all/index.html");
578 }else{
579 $this->rm_folder_recursively($this->getWpContentDir()."/cache/all".$url["path"]);
580 }
581 }
582 }
583
584 if($post_id){
585 $this->singleDeleteCache(false, $post_id);
586 }
587 }
588
589 private function admin(){
590 if(isset($_GET["page"]) && $_GET["page"] == "wpfastestcacheoptions"){
591 include_once('inc/admin.php');
592 $wpfc = new WpFastestCacheAdmin();
593 $wpfc->addMenuPage();
594 }else{
595 add_action('admin_menu', array($this, 'register_my_custom_menu_page'));
596 }
597 }
598
599 public function load_column(){
600 if(!defined('WPFC_HIDE_CLEAR_CACHE_BUTTON') || (defined('WPFC_HIDE_CLEAR_CACHE_BUTTON') && !WPFC_HIDE_CLEAR_CACHE_BUTTON)){
601 include_once plugin_dir_path(__FILE__)."inc/column.php";
602
603 $column = new WpFastestCacheColumn();
604 $column->add();
605 }
606 }
607
608 public function load_admin_toolbar(){
609 if(!defined('WPFC_HIDE_TOOLBAR') || (defined('WPFC_HIDE_TOOLBAR') && !WPFC_HIDE_TOOLBAR)){
610 $show = false;
611
612 // Admin
613 $show = (current_user_can( 'manage_options' ) || current_user_can('edit_others_pages')) ? true : false;
614
615 // Author
616 if(defined('WPFC_TOOLBAR_FOR_AUTHOR') && WPFC_TOOLBAR_FOR_AUTHOR){
617 if(current_user_can( 'delete_published_posts' ) || current_user_can('edit_published_posts')) {
618 $show = true;
619 }
620 }
621
622 if($show){
623 include_once plugin_dir_path(__FILE__)."inc/admin-toolbar.php";
624
625 $toolbar = new WpFastestCacheAdminToolbar();
626 $toolbar->add();
627 }
628
629 }
630 }
631
632 public function register_my_custom_menu_page(){
633 if(function_exists('add_menu_page')){
634 add_menu_page("WP Fastest Cache Settings", "WP Fastest Cache", 'manage_options', "wpfastestcacheoptions", array($this, 'optionsPage'), plugins_url("wp-fastest-cache/images/icon-32x32.png"));
635 wp_enqueue_style("wp-fastest-cache", plugins_url("wp-fastest-cache/css/style.css"), array(), time(), "all");
636 }
637
638 if(isset($_GET["page"]) && $_GET["page"] == "wpfastestcacheoptions"){
639 wp_enqueue_style("wp-fastest-cache-buycredit", plugins_url("wp-fastest-cache/css/buycredit.css"), array(), time(), "all");
640 wp_enqueue_style("wp-fastest-cache-flaticon", plugins_url("wp-fastest-cache/css/flaticon.css"), array(), time(), "all");
641 wp_enqueue_style("wp-fastest-cache-dialog", plugins_url("wp-fastest-cache/css/dialog.css"), array(), time(), "all");
642 }
643 }
644
645 public function deleteCacheToolbar(){
646 $this->deleteCache();
647 }
648
649 public function deleteCssAndJsCacheToolbar(){
650 $this->deleteCache(true);
651 }
652
653 public function delete_current_page_cache(){
654 include_once('inc/cdn.php');
655 CdnWPFC::cloudflare_clear_cache();
656
657 if(isset($_GET["path"])){
658 if($_GET["path"]){
659 if($_GET["path"] == "/"){
660 $_GET["path"] = $_GET["path"]."index.html";
661 }
662 }else{
663 $_GET["path"] = "/index.html";
664 }
665
666 $_GET["path"] = urldecode(esc_url_raw($_GET["path"]));
667
668 $paths = array();
669
670 array_push($paths, $this->getWpContentDir()."/cache/all".$_GET["path"]);
671
672 if(class_exists("WpFcMobileCache")){
673 $wpfc_mobile = new WpFcMobileCache();
674 array_push($paths, $this->getWpContentDir()."/cache/".$wpfc_mobile->get_folder_name()."".$_GET["path"]);
675 }
676
677 foreach ($paths as $key => $value){
678 if(file_exists($value)){
679 if(preg_match("/\/(all|wpfc-mobile-cache)\/index\.html$/i", $value)){
680 @unlink($value);
681 }else{
682 $this->rm_folder_recursively($value);
683 }
684 }
685 }
686
687 die(json_encode(array("The cache of page has been cleared","success")));
688 }else{
689 die(json_encode(array("Path has NOT been defined", "error", "alert")));
690 }
691
692 exit;
693 }
694
695 private function cache(){
696 include_once('inc/cache.php');
697 $wpfc = new WpFastestCacheCreateCache();
698 $wpfc->createCache();
699 }
700
701 protected function slug(){
702 return "wp_fastest_cache";
703 }
704
705 protected function getWpContentDir(){
706 return WPFC_WP_CONTENT_DIR;
707 }
708
709 protected function getOptions(){
710 return $GLOBALS["wp_fastest_cache_options"];
711 }
712
713 protected function getSystemMessage(){
714 return $this->systemMessage;
715 }
716
717 protected function get_excluded_useragent(){
718 return "facebookexternalhit|LinkedInBot|WhatsApp|Mediatoolkitbot";
719 }
720
721 // protected function detectNewPost(){
722 // if(isset($this->options->wpFastestCacheNewPost) && isset($this->options->wpFastestCacheStatus)){
723 // add_filter ('save_post', array($this, 'deleteCache'));
724 // }
725 // }
726
727 public function deleteWidgetCache(){
728 $widget_cache_path = $this->getWpContentDir()."/cache/wpfc-widget-cache";
729
730 if(is_dir($widget_cache_path)){
731 if(!is_dir($this->getWpContentDir()."/cache/tmpWpfc")){
732 if(@mkdir($this->getWpContentDir()."/cache/tmpWpfc", 0755, true)){
733 //tmpWpfc has been created
734 }
735 }
736
737 if(@rename($widget_cache_path, $this->getWpContentDir()."/cache/tmpWpfc/w".time())){
738 //DONE
739 }
740 }
741 }
742
743 public function on_all_status_transitions($new_status, $old_status, $post) {
744 if ( ! wp_is_post_revision($post->ID) ){
745 if(isset($this->options->wpFastestCacheNewPost) && isset($this->options->wpFastestCacheStatus)){
746 if($new_status == "publish" && $old_status != "publish"){
747 if(isset($this->options->wpFastestCacheNewPost_type) && $this->options->wpFastestCacheNewPost_type){
748 if($this->options->wpFastestCacheNewPost_type == "all"){
749 $this->deleteCache();
750 }else if($this->options->wpFastestCacheNewPost_type == "homepage"){
751 $this->deleteHomePageCache();
752
753 //to clear category cache and tag cache
754 $this->singleDeleteCache(false, $post->ID);
755
756 //to clear widget cache
757 $this->deleteWidgetCache();
758 }
759 }else{
760 $this->deleteCache();
761 }
762 }
763 }
764
765 if($new_status == "publish" && $old_status == "publish"){
766 if(isset($this->options->wpFastestCacheUpdatePost) && isset($this->options->wpFastestCacheStatus)){
767
768 if($this->options->wpFastestCacheUpdatePost_type == "post"){
769 $this->singleDeleteCache(false, $post->ID);
770 }else if($this->options->wpFastestCacheUpdatePost_type == "all"){
771 $this->deleteCache();
772 }
773
774 }
775 }
776
777 if($new_status == "trash" && $old_status == "publish"){
778 $this->singleDeleteCache(false, $post->ID);
779 }else if(($new_status == "draft" || $new_status == "pending" || $new_status == "private") && $old_status == "publish"){
780 $this->deleteCache();
781 }
782 }
783 }
784
785 protected function commentHooks(){
786 //it works when the status of a comment changes
787 add_filter ('wp_set_comment_status', array($this, 'singleDeleteCache'));
788
789 //it works when a comment is saved in the database
790 add_filter ('comment_post', array($this, 'detectNewComment'));
791 }
792
793 public function detectNewComment($comment_id){
794 if(current_user_can( 'manage_options') || !get_option('comment_moderation')){
795 $this->singleDeleteCache($comment_id);
796 }
797 }
798
799 public function singleDeleteCache($comment_id = false, $post_id = false){
800 include_once('inc/cdn.php');
801 CdnWPFC::cloudflare_clear_cache();
802
803 $to_clear_parents = true;
804
805 // not to clear cache of homepage/cats/tags after ajax request by other plugins
806 if(isset($_POST) && isset($_POST["action"])){
807 // kk Star Rating
808 if($_POST["action"] == "kksr_ajax"){
809 $to_clear_parents = false;
810 }
811
812 // All In One Schema.org Rich Snippets
813 if(preg_match("/bsf_(update|submit)_rating/i", $_POST["action"])){
814 $to_clear_parents = false;
815 }
816
817 // Yet Another Stars Rating
818 if($_POST["action"] == "yasr_send_visitor_rating"){
819 $to_clear_parents = false;
820 $post_id = $_POST["post_id"];
821 }
822 }
823
824 if($comment_id){
825 $comment_id = intval($comment_id);
826
827 $comment = get_comment($comment_id);
828
829 if($comment && $comment->comment_post_ID){
830 $post_id = $comment->comment_post_ID;
831 }
832 }
833
834 if($post_id){
835 $post_id = intval($post_id);
836
837 $permalink = get_permalink($post_id);
838
839 $permalink = urldecode(get_permalink($post_id));
840
841 //for trash contents
842 $permalink = rtrim($permalink, "/");
843 $permalink = preg_replace("/__trashed$/", "", $permalink);
844
845 if(preg_match("/https?:\/\/[^\/]+\/(.+)/", $permalink, $out)){
846
847 //WPML language switch
848 //https://wpml.org/forums/topic/wpml-language-switch-wp-fastest-cache-issue/
849 if($this->isPluginActive('sitepress-multilingual-cms/sitepress.php')){
850 $current_language = apply_filters('wpml_current_language', false);
851
852 $path = $this->getWpContentDir()."/cache/all/".$current_language."/".$out[1];
853 $mobile_path = $this->getWpContentDir()."/cache/wpfc-mobile-cache/".$current_language."/".$out[1];
854 }else{
855 $path = $this->getWpContentDir()."/cache/all/".$out[1];
856 $mobile_path = $this->getWpContentDir()."/cache/wpfc-mobile-cache/".$out[1];
857 }
858
859 if(is_dir($path)){
860 if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){
861 include_once $this->get_premium_path("logs.php");
862 $log = new WpFastestCacheLogs("delete");
863 $log->action();
864 }
865
866 $this->rm_folder_recursively($path);
867 }
868
869 if(is_dir($mobile_path)){
870 $this->rm_folder_recursively($mobile_path);
871 }
872 }
873
874 if($to_clear_parents){
875 // to clear cache of homepage
876 $this->deleteHomePageCache();
877
878 // to clear cache of cats and tags which contains the post (only first page)
879 global $wpdb;
880 $terms = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."term_relationships` WHERE `object_id`=".$post_id, ARRAY_A);
881
882 foreach ($terms as $term_key => $term_val){
883 $this->delete_cache_of_term($term_val["term_taxonomy_id"]);
884 }
885 }
886 }
887 }
888
889 public function delete_cache_of_term($term_id){
890 $term = get_term($term_id);
891
892 if(!$term || is_wp_error($term)){
893 return false;
894 }
895
896 //if(preg_match("/cat|tag|store|listing/", $term->taxonomy)){}
897
898 $url = get_term_link($term->term_id, $term->taxonomy);
899
900 if(preg_match("/^http/", $url)){
901 $path = preg_replace("/https?\:\/\/[^\/]+/i", "", $url);
902 $path = trim($path, "/");
903
904 // to remove the cache of tag/cat
905 @unlink($this->getWpContentDir()."/cache/all/".$path."/index.html");
906 @unlink($this->getWpContentDir()."/cache/wpfc-mobile-cache/".$path."/index.html");
907
908 // to remove the cache of the pages
909 $this->rm_folder_recursively($this->getWpContentDir()."/cache/all/".$path."/page");
910 $this->rm_folder_recursively($this->getWpContentDir()."/cache/wpfc-mobile-cache/".$path."/page");
911 }
912
913
914
915 }
916
917 public function deleteHomePageCache($log = true){
918 include_once('inc/cdn.php');
919 CdnWPFC::cloudflare_clear_cache();
920
921 $site_url_path = preg_replace("/https?\:\/\/[^\/]+/i", "", site_url());
922 $home_url_path = preg_replace("/https?\:\/\/[^\/]+/i", "", home_url());
923
924 if($site_url_path){
925 $site_url_path = trim($site_url_path, "/");
926
927 if($site_url_path){
928 @unlink($this->getWpContentDir()."/cache/all/".$site_url_path."/index.html");
929 @unlink($this->getWpContentDir()."/cache/wpfc-mobile-cache/".$site_url_path."/index.html");
930
931 //to clear pagination of homepage cache
932 $this->rm_folder_recursively($this->getWpContentDir()."/cache/all/".$site_url_path."/page");
933 $this->rm_folder_recursively($this->getWpContentDir()."/cache/wpfc-mobile-cache/".$site_url_path."/page");
934 }
935 }
936
937 if($home_url_path){
938 $home_url_path = trim($home_url_path, "/");
939
940 if($home_url_path){
941 @unlink($this->getWpContentDir()."/cache/all/".$home_url_path."/index.html");
942 @unlink($this->getWpContentDir()."/cache/wpfc-mobile-cache/".$home_url_path."/index.html");
943
944 //to clear pagination of homepage cache
945 $this->rm_folder_recursively($this->getWpContentDir()."/cache/all/".$home_url_path."/page");
946 $this->rm_folder_recursively($this->getWpContentDir()."/cache/wpfc-mobile-cache/".$home_url_path."/page");
947 }
948 }
949
950 if(file_exists($this->getWpContentDir()."/cache/all/index.html")){
951 @unlink($this->getWpContentDir()."/cache/all/index.html");
952 }
953
954 if(file_exists($this->getWpContentDir()."/cache/wpfc-mobile-cache/index.html")){
955 @unlink($this->getWpContentDir()."/cache/wpfc-mobile-cache/index.html");
956 }
957
958 //to clear pagination of homepage cache
959 $this->rm_folder_recursively($this->getWpContentDir()."/cache/all/page");
960 $this->rm_folder_recursively($this->getWpContentDir()."/cache/wpfc-mobile-cache/page");
961
962
963 if($log){
964 if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){
965 include_once $this->get_premium_path("logs.php");
966
967 $log = new WpFastestCacheLogs("delete");
968 $log->action();
969 }
970 }
971 }
972
973 public function deleteCache($minified = false){
974 include_once('inc/cdn.php');
975 CdnWPFC::cloudflare_clear_cache();
976
977 $this->set_preload();
978
979 $created_tmpWpfc = false;
980 $cache_deleted = false;
981 $minifed_deleted = false;
982
983 $cache_path = $this->getWpContentDir()."/cache/all";
984 $minified_cache_path = $this->getWpContentDir()."/cache/wpfc-minified";
985
986 if(class_exists("WpFcMobileCache")){
987 $wpfc_mobile = new WpFcMobileCache();
988 $wpfc_mobile->delete_cache($this->getWpContentDir());
989 }
990
991 if(!is_dir($this->getWpContentDir()."/cache/tmpWpfc")){
992 if(@mkdir($this->getWpContentDir()."/cache/tmpWpfc", 0755, true)){
993 $created_tmpWpfc = true;
994 }else{
995 $created_tmpWpfc = false;
996 //$this->systemMessage = array("Permission of <strong>/wp-content/cache</strong> must be <strong>755</strong>", "error");
997 }
998 }else{
999 $created_tmpWpfc = true;
1000 }
1001
1002 //to clear widget cache path
1003 $this->deleteWidgetCache();
1004
1005 if(is_dir($cache_path)){
1006 if(@rename($cache_path, $this->getWpContentDir()."/cache/tmpWpfc/".time())){
1007 delete_option("WpFastestCacheHTML");
1008 delete_option("WpFastestCacheHTMLSIZE");
1009 delete_option("WpFastestCacheMOBILE");
1010 delete_option("WpFastestCacheMOBILESIZE");
1011
1012 $cache_deleted = true;
1013 }
1014 }else{
1015 $cache_deleted = true;
1016 }
1017
1018 if($minified){
1019 if(is_dir($minified_cache_path)){
1020 if(@rename($minified_cache_path, $this->getWpContentDir()."/cache/tmpWpfc/m".time())){
1021 delete_option("WpFastestCacheCSS");
1022 delete_option("WpFastestCacheCSSSIZE");
1023 delete_option("WpFastestCacheJS");
1024 delete_option("WpFastestCacheJSSIZE");
1025
1026 $minifed_deleted = true;
1027 }
1028 }else{
1029 $minifed_deleted = true;
1030 }
1031 }else{
1032 $minifed_deleted = true;
1033 }
1034
1035 if($created_tmpWpfc && $cache_deleted && $minifed_deleted){
1036 do_action('wpfc_delete_cache');
1037
1038 $this->systemMessage = array("All cache files have been deleted","success");
1039
1040 if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){
1041 include_once $this->get_premium_path("logs.php");
1042
1043 $log = new WpFastestCacheLogs("delete");
1044 $log->action();
1045 }
1046 }else{
1047 $this->systemMessage = array("Permissions Problem: <a href='http://www.wpfastestcache.com/warnings/delete-cache-problem-related-to-permission/' target='_blank'>Read More</a>", "error", array("light_box" => "delete_cache_permission_error"));
1048 }
1049
1050 // for ajax request
1051 if(isset($_GET["action"]) && in_array($_GET["action"], array("wpfc_delete_cache", "wpfc_delete_cache_and_minified"))){
1052 die(json_encode($this->systemMessage));
1053 }
1054 }
1055
1056 public function checkCronTime(){
1057 $crons = _get_cron_array();
1058
1059 foreach ((array)$crons as $cron_key => $cron_value) {
1060 foreach ( (array) $cron_value as $hook => $events ) {
1061 if(preg_match("/^wp\_fastest\_cache(.*)/", $hook, $id)){
1062 if(!$id[1] || preg_match("/^\_(\d+)$/", $id[1])){
1063 foreach ( (array) $events as $event_key => $event ) {
1064 add_action("wp_fastest_cache".$id[1], array($this, 'setSchedule'));
1065 }
1066 }
1067 }
1068 }
1069 }
1070
1071 add_action($this->slug()."_Preload", array($this, 'create_preload_cache'), 11);
1072 }
1073
1074 public function set_preload(){
1075 $preload_arr = array();
1076
1077 if(!empty($_POST) && isset($_POST["wpFastestCachePreload"])){
1078 foreach ($_POST as $key => $value) {
1079 $key = esc_attr($key);
1080 $value = esc_attr($value);
1081
1082 preg_match("/wpFastestCachePreload_(.+)/", $key, $type);
1083
1084 if(!empty($type)){
1085 if($type[1] == "restart"){
1086 //to need to remove "restart" value
1087 }else if($type[1] == "number"){
1088 $preload_arr[$type[1]] = $value;
1089 }else{
1090 $preload_arr[$type[1]] = 0;
1091 }
1092 }
1093 }
1094 }
1095
1096 if($data = get_option("WpFastestCachePreLoad")){
1097 $preload_std = json_decode($data);
1098
1099 if(!empty($preload_arr)){
1100 foreach ($preload_arr as $key => &$value) {
1101 if(!empty($preload_std->$key)){
1102 if($key != "number"){
1103 $value = $preload_std->$key;
1104 }
1105 }
1106 }
1107
1108 $preload_std = $preload_arr;
1109 }else{
1110 foreach ($preload_std as $key => &$value) {
1111 if($key != "number"){
1112 $value = 0;
1113 }
1114 }
1115 }
1116
1117 update_option("WpFastestCachePreLoad", json_encode($preload_std));
1118
1119 if(!wp_next_scheduled($this->slug()."_Preload")){
1120 wp_schedule_event(time() + 5, 'everyfiveminute', $this->slug()."_Preload");
1121 }
1122 }else{
1123 if(!empty($preload_arr)){
1124 add_option("WpFastestCachePreLoad", json_encode($preload_arr), null, "yes");
1125
1126 if(!wp_next_scheduled($this->slug()."_Preload")){
1127 wp_schedule_event(time() + 5, 'everyfiveminute', $this->slug()."_Preload");
1128 }
1129 }else{
1130 //toDO
1131 }
1132 }
1133 }
1134
1135 public function create_preload_cache(){
1136 if($data = get_option("WpFastestCachePreLoad")){
1137 $count_posts = wp_count_posts("post");
1138 $count_pages = wp_count_posts('page');
1139
1140 $this->options = $this->getOptions();
1141
1142 $pre_load = json_decode($data);
1143
1144 if(defined("WPFC_PRELOAD_NUMBER") && WPFC_PRELOAD_NUMBER){
1145 $number = WPFC_PRELOAD_NUMBER;
1146 }else{
1147 $number = $pre_load->number;
1148 }
1149
1150
1151 $urls_limit = isset($this->options->wpFastestCachePreload_number) ? $this->options->wpFastestCachePreload_number : 4; // must be even
1152 $urls = array();
1153
1154 if(isset($this->options->wpFastestCacheMobileTheme) && $this->options->wpFastestCacheMobileTheme){
1155 $mobile_theme = true;
1156 $number = $number/2;
1157 }else{
1158 $mobile_theme = false;
1159 }
1160
1161
1162 // HOME
1163 if(isset($pre_load->homepage) && $pre_load->homepage > -1){
1164 if($mobile_theme){
1165 array_push($urls, array("url" => get_option("home"), "user-agent" => "mobile"));
1166 $number--;
1167 }
1168
1169 array_push($urls, array("url" => get_option("home"), "user-agent" => "desktop"));
1170 $number--;
1171
1172 $pre_load->homepage = -1;
1173 }
1174
1175 // POST
1176 if($number > 0 && isset($pre_load->post) && $pre_load->post > -1){
1177 // $recent_posts = wp_get_recent_posts(array(
1178 // 'numberposts' => $number,
1179 // 'offset' => $pre_load->post,
1180 // 'orderby' => 'ID',
1181 // 'order' => 'DESC',
1182 // 'post_type' => 'post',
1183 // 'post_status' => 'publish',
1184 // 'suppress_filters' => true
1185 // ), ARRAY_A);
1186 global $wpdb;
1187 $recent_posts = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS ".$wpdb->prefix."posts.ID FROM ".$wpdb->prefix."posts WHERE 1=1 AND (".$wpdb->prefix."posts.post_type = 'post' OR ".$wpdb->prefix."posts.post_type = 'product') AND ((".$wpdb->prefix."posts.post_status = 'publish')) ORDER BY ".$wpdb->prefix."posts.ID DESC LIMIT ".$pre_load->post.", ".$number, ARRAY_A);
1188
1189
1190 if(count($recent_posts) > 0){
1191 foreach ($recent_posts as $key => $post) {
1192 if($mobile_theme){
1193 array_push($urls, array("url" => get_permalink($post["ID"]), "user-agent" => "mobile"));
1194 $number--;
1195 }
1196
1197 array_push($urls, array("url" => get_permalink($post["ID"]), "user-agent" => "desktop"));
1198 $number--;
1199
1200 $pre_load->post = $pre_load->post + 1;
1201 }
1202 }else{
1203 $pre_load->post = -1;
1204 }
1205 }
1206
1207 // ATTACHMENT
1208 if($number > 0 && isset($pre_load->attachment) && $pre_load->attachment > -1){
1209 global $wpdb;
1210 $recent_attachments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS ".$wpdb->prefix."posts.ID FROM ".$wpdb->prefix."posts WHERE 1=1 AND (".$wpdb->prefix."posts.post_type = 'attachment') ORDER BY ".$wpdb->prefix."posts.ID DESC LIMIT ".$pre_load->attachment.", ".$number, ARRAY_A);
1211
1212 if(count($recent_attachments) > 0){
1213 foreach ($recent_attachments as $key => $attachment) {
1214 if($mobile_theme){
1215 array_push($urls, array("url" => get_permalink($attachment["ID"]), "user-agent" => "mobile"));
1216 $number--;
1217 }
1218
1219 array_push($urls, array("url" => get_permalink($attachment["ID"]), "user-agent" => "desktop"));
1220 $number--;
1221
1222 $pre_load->attachment = $pre_load->attachment + 1;
1223 }
1224 }else{
1225 $pre_load->attachment = -1;
1226 }
1227 }
1228
1229 // PAGE
1230 if($number > 0 && isset($pre_load->page) && $pre_load->page > -1){
1231 $pages = get_pages(array(
1232 'sort_order' => 'DESC',
1233 'sort_column' => 'ID',
1234 'parent' => -1,
1235 'hierarchical' => 0,
1236 'number' => $number,
1237 'offset' => $pre_load->page,
1238 'post_type' => 'page',
1239 'post_status' => 'publish'
1240 ));
1241
1242 if(count($pages) > 0){
1243 foreach ($pages as $key => $page) {
1244 $page_url = get_option("home")."/".get_page_uri($page->ID);
1245
1246 if($mobile_theme){
1247 array_push($urls, array("url" => $page_url, "user-agent" => "mobile"));
1248 $number--;
1249 }
1250
1251 array_push($urls, array("url" => $page_url, "user-agent" => "desktop"));
1252 $number--;
1253
1254 $pre_load->page = $pre_load->page + 1;
1255 }
1256 }else{
1257 $pre_load->page = -1;
1258 }
1259 }
1260
1261 // CATEGORY
1262 if($number > 0 && isset($pre_load->category) && $pre_load->category > -1){
1263 // $categories = get_terms(array(
1264 // 'taxonomy' => array('category', 'product_cat'),
1265 // 'orderby' => 'id',
1266 // 'order' => 'DESC',
1267 // 'hide_empty' => false,
1268 // 'number' => $number,
1269 // 'fields' => 'all',
1270 // 'pad_counts' => false,
1271 // 'offset' => $pre_load->category
1272 // ));
1273
1274 global $wpdb;
1275 $categories = $wpdb->get_results("SELECT t.*, tt.* FROM ".$wpdb->prefix."terms AS t INNER JOIN ".$wpdb->prefix."term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category', 'product_cat', 'hersteller', 'anschlussart', 'typ') ORDER BY t.term_id ASC LIMIT ".$pre_load->category.", ".$number, ARRAY_A);
1276
1277 if(count($categories) > 0){
1278 foreach ($categories as $key => $category) {
1279 if($mobile_theme){
1280 array_push($urls, array("url" => get_term_link($category["slug"], $category["taxonomy"]), "user-agent" => "mobile"));
1281 $number--;
1282 }
1283
1284 array_push($urls, array("url" => get_term_link($category["slug"], $category["taxonomy"]), "user-agent" => "desktop"));
1285 $number--;
1286
1287 $pre_load->category = $pre_load->category + 1;
1288
1289 }
1290 }else{
1291 $pre_load->category = -1;
1292 }
1293 }
1294
1295 // TAG
1296 if($number > 0 && isset($pre_load->tag) && $pre_load->tag > -1){
1297 // $tags = get_terms(array(
1298 // 'taxonomy' => array('post_tag', 'product_tag'),
1299 // 'orderby' => 'id',
1300 // 'order' => 'DESC',
1301 // 'hide_empty' => false,
1302 // 'number' => $number,
1303 // 'fields' => 'all',
1304 // 'pad_counts' => false,
1305 // 'offset' => $pre_load->tag
1306 // ));
1307
1308 global $wpdb;
1309 $tags = $wpdb->get_results("SELECT t.*, tt.* FROM ".$wpdb->prefix."terms AS t INNER JOIN ".$wpdb->prefix."term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('post_tag', 'product_tag') ORDER BY t.term_id ASC LIMIT ".$pre_load->tag.", ".$number, ARRAY_A);
1310
1311
1312 if(count($tags) > 0){
1313 foreach ($tags as $key => $tag) {
1314 if($mobile_theme){
1315 array_push($urls, array("url" => get_term_link($tag["slug"], $tag["taxonomy"]), "user-agent" => "mobile"));
1316 $number--;
1317 }
1318
1319 array_push($urls, array("url" => get_term_link($tag["slug"], $tag["taxonomy"]), "user-agent" => "desktop"));
1320 $number--;
1321
1322 $pre_load->tag = $pre_load->tag + 1;
1323
1324 }
1325 }else{
1326 $pre_load->tag = -1;
1327 }
1328 }
1329
1330
1331
1332
1333
1334
1335 if(count($urls) > 0){
1336 foreach ($urls as $key => $arr) {
1337 $user_agent = "";
1338
1339 if($arr["user-agent"] == "desktop"){
1340 $user_agent = "WP Fastest Cache Preload Bot";
1341 }else if($arr["user-agent"] == "mobile"){
1342 $user_agent = "WP Fastest Cache Preload iPhone Mobile Bot";
1343 }
1344
1345 if($this->wpfc_remote_get($arr["url"], $user_agent)){
1346 $status = "<strong style=\"color:lightgreen;\">OK</strong>";
1347 }else{
1348 $status = "<strong style=\"color:red;\">ERROR</strong>";
1349 }
1350
1351 echo $status." ".$arr["url"]." (".$arr["user-agent"].")<br>";
1352 }
1353 echo "<br>";
1354 echo count($urls)." page have been cached";
1355
1356 update_option("WpFastestCachePreLoad", json_encode($pre_load));
1357
1358 echo "<br><br>";
1359
1360 // if(isset($pre_load->homepage)){
1361 // if($pre_load->homepage == -1){
1362 // echo "Homepage: 1/1"."<br>";
1363 // }
1364 // }
1365
1366 // if(isset($pre_load->post)){
1367 // if($pre_load->post > -1){
1368 // echo "Posts: ".$pre_load->post."/".$count_posts->publish."<br>";
1369 // }else{
1370 // echo "Posts: ".$count_posts->publish."/".$count_posts->publish."<br>";
1371 // }
1372 // }
1373
1374 // if(isset($pre_load->page)){
1375 // if($pre_load->page > -1){
1376 // echo "Pages: ".$pre_load->page."/".$count_pages->publish."<br>";
1377 // }else{
1378 // echo "Pages: ".$count_pages->publish."/".$count_pages->publish."<br>";
1379 // }
1380 // }
1381 }else{
1382 if(isset($this->options->wpFastestCachePreload_restart)){
1383 foreach ($pre_load as $pre_load_key => &$pre_load_value) {
1384 if($pre_load_key != "number"){
1385 $pre_load_value = 0;
1386 }
1387 }
1388
1389 update_option("WpFastestCachePreLoad", json_encode($pre_load));
1390
1391 echo "Preload Restarted";
1392
1393 include_once('inc/cdn.php');
1394 CdnWPFC::cloudflare_clear_cache();
1395 }else{
1396 echo "Completed";
1397
1398 wp_clear_scheduled_hook("wp_fastest_cache_Preload");
1399 }
1400 }
1401 }
1402
1403 if(isset($_GET) && isset($_GET["type"]) && $_GET["type"] == "preload"){
1404 die();
1405 }
1406 }
1407
1408 public function wpfc_remote_get($url, $user_agent){
1409 //$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)));
1410 $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")));
1411
1412 if (!$response || is_wp_error($response)){
1413 echo $response->get_error_message()." - ";
1414
1415 return false;
1416 }else{
1417 if(wp_remote_retrieve_response_code($response) != 200){
1418 return false;
1419 }
1420 }
1421
1422 return true;
1423 }
1424
1425 public function setSchedule($args = ""){
1426 if($args){
1427 $rule = json_decode($args);
1428
1429 if($rule->prefix == "all"){
1430 $this->deleteCache();
1431 }else if($rule->prefix == "homepage"){
1432 @unlink($this->getWpContentDir()."/cache/all/index.html");
1433 @unlink($this->getWpContentDir()."/cache/wpfc-mobile-cache/index.html");
1434
1435 if(isset($this->options->wpFastestCachePreload_homepage) && $this->options->wpFastestCachePreload_homepage){
1436 $this->wpfc_remote_get(get_option("home"), "WP Fastest Cache Preload Bot - After Cache Timeout");
1437 $this->wpfc_remote_get(get_option("home"), "WP Fastest Cache Preload iPhone Mobile Bot - After Cache Timeout");
1438 }
1439 }else if($rule->prefix == "startwith"){
1440 if(!is_dir($this->getWpContentDir()."/cache/tmpWpfc")){
1441 if(@mkdir($this->getWpContentDir()."/cache/tmpWpfc", 0755, true)){}
1442 }
1443
1444 $rule->content = trim($rule->content, "/");
1445
1446 $files = glob($this->getWpContentDir()."/cache/all/".$rule->content."*");
1447
1448 foreach ((array)$files as $file) {
1449 $mobile_file = str_replace("/cache/all/", "/cache/wpfc-mobile-cache/", $file);
1450
1451 @rename($file, $this->getWpContentDir()."/cache/tmpWpfc/".time());
1452 @rename($mobile_file, $this->getWpContentDir()."/cache/tmpWpfc/mobile_".time());
1453 }
1454 }else if($rule->prefix == "exact"){
1455 $rule->content = trim($rule->content, "/");
1456
1457 @unlink($this->getWpContentDir()."/cache/all/".$rule->content."/index.html");
1458 @unlink($this->getWpContentDir()."/cache/wpfc-mobile-cache/".$rule->content."/index.html");
1459 }
1460
1461 if($rule->prefix != "all"){
1462 if($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")){
1463 include_once $this->get_premium_path("logs.php");
1464 $log = new WpFastestCacheLogs("delete");
1465 $log->action($rule);
1466 }
1467 }
1468 }else{
1469 //for old cron job
1470 $this->deleteCache();
1471 }
1472 }
1473
1474 public function modify_htaccess_for_new_user($user_id){
1475 $path = ABSPATH;
1476
1477 if($this->is_subdirectory_install()){
1478 $path = $this->getABSPATH();
1479 }
1480
1481 $htaccess = @file_get_contents($path.".htaccess");
1482
1483 if(preg_match("/\#\s?Start_WPFC_Exclude_Admin_Cookie/", $htaccess)){
1484 $rules = $this->excludeAdminCookie();
1485
1486 $htaccess = preg_replace("/\#\s?Start_WPFC_Exclude_Admin_Cookie[^\#]*\#\s?End_WPFC_Exclude_Admin_Cookie\s+/", $rules, $htaccess);
1487 }
1488
1489 @file_put_contents($path.".htaccess", $htaccess);
1490 }
1491
1492 public function excludeAdminCookie(){
1493 $rules = "";
1494 $users_groups = array_chunk(get_users(array("role" => "administrator", "fields" => array("user_login"))), 5);
1495
1496 foreach ($users_groups as $group_key => $group) {
1497 $tmp_users = "";
1498 $tmp_rule = "";
1499
1500 foreach ($group as $key => $value) {
1501 if($tmp_users){
1502 $tmp_users = $tmp_users."|".sanitize_user(wp_unslash($value->user_login), true);
1503 }else{
1504 $tmp_users = sanitize_user(wp_unslash($value->user_login), true);
1505 }
1506
1507 // to replace spaces with \s
1508 $tmp_users = preg_replace("/\s/", "\s", $tmp_users);
1509
1510 if(!next($group)){
1511 $tmp_rule = "RewriteCond %{HTTP:Cookie} !wordpress_logged_in_[^\=]+\=".$tmp_users;
1512 }
1513 }
1514
1515 if($rules){
1516 $rules = $rules."\n".$tmp_rule;
1517 }else{
1518 $rules = $tmp_rule;
1519 }
1520 }
1521
1522 return "# Start_WPFC_Exclude_Admin_Cookie\n".$rules."\n# End_WPFC_Exclude_Admin_Cookie\n";
1523 }
1524
1525 public function excludeRules(){
1526 $htaccess_page_rules = "";
1527 $htaccess_page_useragent = "";
1528 $htaccess_page_cookie = "";
1529
1530 if($rules_json = get_option("WpFastestCacheExclude")){
1531 if($rules_json != "null"){
1532 $rules_std = json_decode($rules_json);
1533
1534 foreach ($rules_std as $key => $value) {
1535 $value->type = isset($value->type) ? $value->type : "page";
1536
1537 // escape the chars
1538 $value->content = str_replace("?", "\?", $value->content);
1539
1540 if($value->type == "page"){
1541 if($value->prefix == "startwith"){
1542 $htaccess_page_rules = $htaccess_page_rules."RewriteCond %{REQUEST_URI} !^/".$value->content." [NC]\n";
1543 }
1544
1545 if($value->prefix == "contain"){
1546 $htaccess_page_rules = $htaccess_page_rules."RewriteCond %{REQUEST_URI} !".$value->content." [NC]\n";
1547 }
1548
1549 if($value->prefix == "exact"){
1550 $htaccess_page_rules = $htaccess_page_rules."RewriteCond %{REQUEST_URI} !\/".$value->content." [NC]\n";
1551 }
1552 }else if($value->type == "useragent"){
1553 $htaccess_page_useragent = $htaccess_page_useragent."RewriteCond %{HTTP_USER_AGENT} !".$value->content." [NC]\n";
1554 }else if($value->type == "cookie"){
1555 $htaccess_page_cookie = $htaccess_page_cookie."RewriteCond %{HTTP:Cookie} !".$value->content." [NC]\n";
1556 }
1557 }
1558 }
1559 }
1560
1561 return "# Start WPFC Exclude\n".$htaccess_page_rules.$htaccess_page_useragent.$htaccess_page_cookie."# End WPFC Exclude\n";
1562 }
1563
1564 public function getABSPATH(){
1565 $path = ABSPATH;
1566 $siteUrl = site_url();
1567 $homeUrl = home_url();
1568 $diff = str_replace($homeUrl, "", $siteUrl);
1569 $diff = trim($diff,"/");
1570
1571 $pos = strrpos($path, $diff);
1572
1573 if($pos !== false){
1574 $path = substr_replace($path, "", $pos, strlen($diff));
1575 $path = trim($path,"/");
1576 $path = "/".$path."/";
1577 }
1578 return $path;
1579 }
1580
1581 public function rm_folder_recursively($dir, $i = 1) {
1582 if(is_dir($dir)){
1583 $files = @scandir($dir);
1584 foreach((array)$files as $file) {
1585 if($i > 50 && !preg_match("/wp-fastest-cache-premium/i", $dir)){
1586 return true;
1587 }else{
1588 $i++;
1589 }
1590 if ('.' === $file || '..' === $file) continue;
1591 if (is_dir("$dir/$file")){
1592 $this->rm_folder_recursively("$dir/$file", $i);
1593 }else{
1594 if(file_exists("$dir/$file")){
1595 @unlink("$dir/$file");
1596 }
1597 }
1598 }
1599 }
1600
1601 if(is_dir($dir)){
1602 $files_tmp = @scandir($dir);
1603
1604 if(!isset($files_tmp[2])){
1605 @rmdir($dir);
1606 }
1607 }
1608
1609 return true;
1610 }
1611
1612 public function is_subdirectory_install(){
1613 if(strlen(site_url()) > strlen(home_url())){
1614 return true;
1615 }
1616 return false;
1617 }
1618
1619 protected function getMobileUserAgents(){
1620 return implode("|", $this->get_mobile_browsers())."|".implode("|", $this->get_operating_systems());
1621 }
1622
1623 public function get_premium_path($name){
1624 return WPFC_WP_PLUGIN_DIR."/wp-fastest-cache-premium/pro/library/".$name;
1625 }
1626
1627 public function cron_add_minute( $schedules ) {
1628 $schedules['everyminute'] = array(
1629 'interval' => 60*1,
1630 'display' => __( 'Once Every 1 Minute' ),
1631 'wpfc' => false
1632 );
1633
1634 $schedules['everyfiveminute'] = array(
1635 'interval' => 60*5,
1636 'display' => __( 'Once Every 5 Minutes' ),
1637 'wpfc' => false
1638 );
1639
1640 $schedules['everyfifteenminute'] = array(
1641 'interval' => 60*15,
1642 'display' => __( 'Once Every 15 Minutes' ),
1643 'wpfc' => true
1644 );
1645
1646 $schedules['twiceanhour'] = array(
1647 'interval' => 60*30,
1648 'display' => __( 'Twice an Hour' ),
1649 'wpfc' => true
1650 );
1651
1652 $schedules['onceanhour'] = array(
1653 'interval' => 60*60,
1654 'display' => __( 'Once an Hour' ),
1655 'wpfc' => true
1656 );
1657
1658 $schedules['everytwohours'] = array(
1659 'interval' => 60*60*2,
1660 'display' => __( 'Once Every 2 Hours' ),
1661 'wpfc' => true
1662 );
1663
1664 $schedules['everythreehours'] = array(
1665 'interval' => 60*60*3,
1666 'display' => __( 'Once Every 3 Hours' ),
1667 'wpfc' => true
1668 );
1669
1670 $schedules['everyfourhours'] = array(
1671 'interval' => 60*60*4,
1672 'display' => __( 'Once Every 4 Hours' ),
1673 'wpfc' => true
1674 );
1675
1676 $schedules['everyfivehours'] = array(
1677 'interval' => 60*60*5,
1678 'display' => __( 'Once Every 5 Hours' ),
1679 'wpfc' => true
1680 );
1681
1682 $schedules['everysixhours'] = array(
1683 'interval' => 60*60*6,
1684 'display' => __( 'Once Every 6 Hours' ),
1685 'wpfc' => true
1686 );
1687
1688 $schedules['everysevenhours'] = array(
1689 'interval' => 60*60*7,
1690 'display' => __( 'Once Every 7 Hours' ),
1691 'wpfc' => true
1692 );
1693
1694 $schedules['everyeighthours'] = array(
1695 'interval' => 60*60*8,
1696 'display' => __( 'Once Every 8 Hours' ),
1697 'wpfc' => true
1698 );
1699
1700 $schedules['everyninehours'] = array(
1701 'interval' => 60*60*9,
1702 'display' => __( 'Once Every 9 Hours' ),
1703 'wpfc' => true
1704 );
1705
1706 $schedules['everytenhours'] = array(
1707 'interval' => 60*60*10,
1708 'display' => __( 'Once Every 10 Hours' ),
1709 'wpfc' => true
1710 );
1711
1712 $schedules['onceaday'] = array(
1713 'interval' => 60*60*24,
1714 'display' => __( 'Once a Day' ),
1715 'wpfc' => true
1716 );
1717
1718 $schedules['everythreedays'] = array(
1719 'interval' => 60*60*24*3,
1720 'display' => __( 'Once Every 3 Days' ),
1721 'wpfc' => true
1722 );
1723
1724 $schedules['weekly'] = array(
1725 'interval' => 60*60*24*7,
1726 'display' => __( 'Once a Week' ),
1727 'wpfc' => true
1728 );
1729
1730 $schedules['everytendays'] = array(
1731 'interval' => 60*60*24*10,
1732 'display' => __( 'Once Every 10 Days' ),
1733 'wpfc' => true
1734 );
1735
1736 $schedules['montly'] = array(
1737 'interval' => 60*60*24*30,
1738 'display' => __( 'Once a Month' ),
1739 'wpfc' => true
1740 );
1741
1742 $schedules['yearly'] = array(
1743 'interval' => 60*60*24*30*12,
1744 'display' => __( 'Once a Year' ),
1745 'wpfc' => true
1746 );
1747
1748 return $schedules;
1749 }
1750
1751 public function setCustomInterval(){
1752 add_filter( 'cron_schedules', array($this, 'cron_add_minute'));
1753 }
1754
1755 public function isPluginActive( $plugin ) {
1756 return in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) || $this->isPluginActiveForNetwork( $plugin );
1757 }
1758
1759 public function isPluginActiveForNetwork( $plugin ) {
1760 if ( !is_multisite() )
1761 return false;
1762
1763 $plugins = get_site_option( 'active_sitewide_plugins');
1764 if ( isset($plugins[$plugin]) )
1765 return true;
1766
1767 return false;
1768 }
1769
1770 public function current_url(){
1771 if(defined('WP_CLI')){
1772 $_SERVER["SERVER_NAME"] = isset($_SERVER["SERVER_NAME"]) ? $_SERVER["SERVER_NAME"] : "";
1773 $_SERVER["SERVER_PORT"] = isset($_SERVER["SERVER_PORT"]) ? $_SERVER["SERVER_PORT"] : 80;
1774 }
1775
1776 $pageURL = 'http';
1777
1778 if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'){
1779 $pageURL .= 's';
1780 }
1781
1782 $pageURL .= '://';
1783
1784 if($_SERVER['SERVER_PORT'] != '80'){
1785 $pageURL .= $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];
1786 }else{
1787 $pageURL .= $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
1788 }
1789
1790 return $pageURL;
1791 }
1792
1793 public function wpfc_load_plugin_textdomain(){
1794 load_plugin_textdomain('wp-fastest-cache', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
1795 }
1796
1797 public function cdn_replace_urls($matches){
1798 if(count($this->cdn) > 0){
1799 foreach ($this->cdn as $key => $cdn) {
1800 if($cdn->id == "cloudflare"){
1801 continue;
1802 }
1803
1804 if(preg_match("/manifest\.json\.php/i", $matches[0])){
1805 return $matches[0];
1806 }
1807
1808 if(preg_match("/^\/\/random/", $cdn->cdnurl) || preg_match("/\/\/i\d\.wp\.com/", $cdn->cdnurl)){
1809 if(preg_match("/^\/\/random/", $cdn->cdnurl)){
1810 $cdnurl = "//i".rand(0,3).".wp.com/".str_replace("www.", "", $_SERVER["HTTP_HOST"]);
1811 $cdnurl = preg_replace("/\/\/i\d\.wp\.com/", "//i".rand(0,3).".wp.com", $cdnurl);
1812 }else{
1813 $cdnurl = $cdn->cdnurl;
1814 }
1815
1816 //to add www. if exists
1817 if(preg_match("/\/\/www\./", $matches[0])){
1818 $cdnurl = preg_replace("/(\/\/i\d\.wp\.com\/)(www\.)?/", "$1www.", $cdnurl);
1819 }
1820 }else{
1821 $cdnurl = $cdn->cdnurl;
1822 }
1823
1824 $cdn->file_types = str_replace(",", "|", $cdn->file_types);
1825
1826 if(preg_match("/\.(".$cdn->file_types.")[\"\'\?\)\s]/i", $matches[0])){
1827 //nothing
1828 }else{
1829 if(preg_match("/js/", $cdn->file_types)){
1830 if(!preg_match("/\/revslider\/public\/assets\/js/", $matches[0])){
1831 continue;
1832 }
1833 }else{
1834 continue;
1835 }
1836 }
1837
1838 if($cdn->keywords){
1839 $cdn->keywords = str_replace(",", "|", $cdn->keywords);
1840
1841 if(!preg_match("/".preg_quote($cdn->keywords, "/")."/i", $matches[0])){
1842 continue;
1843 }
1844 }
1845
1846 if(preg_match("/\{\"concatemoji\"\:\"[^\"]+\"\}/i", $matches[0])){
1847 $matches[0] = preg_replace("/(http(s?)\:)?".preg_quote("\/\/", "/")."(www\.)?/i", "", $matches[0]);
1848 $matches[0] = preg_replace("/".preg_quote($cdn->originurl, "/")."/i", $cdnurl, $matches[0]);
1849 }else if(isset($matches[2]) && preg_match("/".preg_quote($cdn->originurl, "/")."/", $matches[2])){
1850 $matches[0] = preg_replace("/(http(s?)\:)?\/\/(www\.)?".preg_quote($cdn->originurl, "/")."/i", $cdnurl, $matches[0]);
1851 }else if(isset($matches[2]) && preg_match("/^(\/?)(wp-includes|wp-content)/", $matches[2])){
1852 $matches[0] = preg_replace("/(\/?)(wp-includes|wp-content)/i", $cdnurl."/"."$2", $matches[0]);
1853 }else if(preg_match("/[\"\']https?\:\\\\\/\\\\\/[^\"\']+[\"\']/i", $matches[0])){
1854 if(preg_match("/^(logo|url|image)$/i", $matches[1])){
1855 //If the url is called with "//", it causes an error on https://search.google.com/structured-data/testing-tool/u/0/
1856 //<script type="application/ld+json">"logo":{"@type":"ImageObject","url":"\/\/cdn.site.com\/image.png"}</script>
1857 //<script type="application/ld+json">{"logo":"\/\/cdn.site.com\/image.png"}</script>
1858 //<script type="application/ld+json">{"image":"\/\/cdn.site.com\/image.jpg"}</script>
1859 }else{
1860 //<script>var loaderRandomImages=["https:\/\/www.site.com\/wp-content\/uploads\/2016\/12\/image.jpg"];</script>
1861 $matches[0] = preg_replace("/\\\\\//", "/", $matches[0]);
1862
1863 if(preg_match("/".preg_quote($cdn->originurl, "/")."/", $matches[0])){
1864 $matches[0] = preg_replace("/(http(s?)\:)?\/\/(www\.)?".preg_quote($cdn->originurl, "/")."/i", $cdnurl, $matches[0]);
1865 $matches[0] = preg_replace("/\//", "\/", $matches[0]);
1866 }
1867 }
1868 }
1869 }
1870 }
1871
1872 return $matches[0];
1873 }
1874
1875 public function read_file($url){
1876 if(!preg_match("/\.php/", $url)){
1877 $url = preg_replace("/\?.*/", "", $url);
1878 $path = preg_replace("/.+\/wp-content\/(.+)/", WPFC_WP_CONTENT_DIR."/"."$1", $url);
1879
1880 if(file_exists($path)){
1881 $filesize = filesize($path);
1882
1883 if($filesize > 0){
1884 $myfile = fopen($path, "r") or die("Unable to open file!");
1885 $data = fread($myfile, $filesize);
1886 fclose($myfile);
1887
1888 return $data;
1889 }else{
1890 return false;
1891 }
1892 }
1893 }
1894
1895 return false;
1896 }
1897
1898 public function get_operating_systems(){
1899 $operating_systems = array(
1900 'Android',
1901 'blackberry|\bBB10\b|rim\stablet\sos',
1902 'PalmOS|avantgo|blazer|elaine|hiptop|palm|plucker|xiino',
1903 'Symbian|SymbOS|Series60|Series40|SYB-[0-9]+|\bS60\b',
1904 'Windows\sCE.*(PPC|Smartphone|Mobile|[0-9]{3}x[0-9]{3})|Window\sMobile|Windows\sPhone\s[0-9.]+|WCE;',
1905 'Windows\sPhone\s10.0|Windows\sPhone\s8.1|Windows\sPhone\s8.0|Windows\sPhone\sOS|XBLWP7|ZuneWP7|Windows\sNT\s6\.[23]\;\sARM\;',
1906 '\biPhone.*Mobile|\biPod|\biPad',
1907 'Apple-iPhone7C2',
1908 'MeeGo',
1909 'Maemo',
1910 'J2ME\/|\bMIDP\b|\bCLDC\b', // '|Java/' produces bug #135
1911 'webOS|hpwOS',
1912 '\bBada\b',
1913 'BREW'
1914 );
1915 return $operating_systems;
1916 }
1917
1918 public function get_mobile_browsers(){
1919 $mobile_browsers = array(
1920 '\bCrMo\b|CriOS|Android.*Chrome\/[.0-9]*\s(Mobile)?',
1921 '\bDolfin\b',
1922 'Opera.*Mini|Opera.*Mobi|Android.*Opera|Mobile.*OPR\/[0-9.]+|Coast\/[0-9.]+',
1923 'Skyfire',
1924 'Mobile\sSafari\/[.0-9]*\sEdge',
1925 'IEMobile|MSIEMobile', // |Trident/[.0-9]+
1926 'fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile|FxiOS',
1927 'bolt',
1928 'teashark',
1929 'Blazer',
1930 'Version.*Mobile.*Safari|Safari.*Mobile|MobileSafari',
1931 'Tizen',
1932 'UC.*Browser|UCWEB',
1933 'baiduboxapp',
1934 'baidubrowser',
1935 'DiigoBrowser',
1936 'Puffin',
1937 '\bMercury\b',
1938 'Obigo',
1939 'NF-Browser',
1940 'NokiaBrowser|OviBrowser|OneBrowser|TwonkyBeamBrowser|SEMC.*Browser|FlyFlow|Minimo|NetFront|Novarra-Vision|MQQBrowser|MicroMessenger',
1941 'Android.*PaleMoon|Mobile.*PaleMoon'
1942 );
1943 return $mobile_browsers;
1944 }
1945
1946
1947 }
1948
1949 $GLOBALS["wp_fastest_cache"] = new WpFastestCache();
1950 ?>