예제 #1
0
 public function wpfc_update_premium_callback()
 {
     if ($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")) {
         if (!file_exists(WPFC_WP_PLUGIN_DIR . "/wp-fastest-cache-premium/pro/library/update.php")) {
             $res = array("success" => false, "error_message" => "update.php is not exist");
         } else {
             include_once $this->get_premium_path("update.php");
             if (!class_exists("WpFastestCacheUpdate")) {
                 $res = array("success" => false, "error_message" => "WpFastestCacheUpdate is not exist");
             } else {
                 $wpfc_premium = new WpFastestCacheUpdate();
                 $content = $wpfc_premium->download_premium();
                 if ($content["success"]) {
                     $wpfc_zip_data = $content["content"];
                     $wpfc_zip_dest_path = WPFC_WP_PLUGIN_DIR . "/wp-fastest-cache-premium.zip";
                     if (@file_put_contents($wpfc_zip_dest_path, $wpfc_zip_data)) {
                         include_once ABSPATH . "wp-admin/includes/file.php";
                         include_once ABSPATH . "wp-admin/includes/plugin.php";
                         if (function_exists("unzip_file")) {
                             $this->rm_folder_recursively(WPFC_WP_PLUGIN_DIR . "/wp-fastest-cache-premium");
                             if (!function_exists('gzopen')) {
                                 $res = array("success" => false, "error_message" => "Missing zlib extension");
                             } else {
                                 WP_Filesystem();
                                 $unzipfile = unzip_file($wpfc_zip_dest_path, WPFC_WP_PLUGIN_DIR . "/");
                                 if ($unzipfile) {
                                     $result = activate_plugin('wp-fastest-cache-premium/wpFastestCachePremium.php');
                                     if (is_wp_error($result)) {
                                         $res = array("success" => false, "error_message" => "Error occured while the plugin was activated");
                                     } else {
                                         $res = array("success" => true);
                                         $this->deleteCache(true);
                                     }
                                 } else {
                                     $res = array("success" => false, "error_message" => 'Error occured while the file was unzipped');
                                 }
                             }
                         } else {
                             $res = array("success" => false, "error_message" => "unzip_file() is not found");
                         }
                     } else {
                         $res = array("success" => false, "error_message" => "/wp-content/plugins/ is not writable");
                     }
                 } else {
                     $res = array("success" => false, "error_message" => $content["error_message"]);
                 }
             }
         }
     } else {
         $res = array("success" => false, "error_message" => "Premium is not active");
     }
     echo json_encode($res);
     exit;
 }
예제 #2
0
 public function __construct()
 {
     $optimize_image_ajax_requests = array("wpfc_revert_image_ajax_request", "wpfc_statics_ajax_request", "wpfc_optimize_image_ajax_request", "wpfc_update_image_list_ajax_request");
     if (isset($_GET) && isset($_GET["action"]) && $_GET["action"] == "wpfc_cdn_options_ajax_request") {
         $cdn_values = get_option("WpFastestCacheCDN");
         if ($cdn_values) {
             echo $cdn_values;
         } else {
             echo json_encode(array("success" => false));
         }
         exit;
     } else {
         if (isset($_POST) && isset($_POST["action"]) && $_POST["action"] == "wpfc_remove_cdn_integration_ajax_request") {
             delete_option("WpFastestCacheCDN");
             echo json_encode(array("success" => true));
             exit;
         } else {
             if (isset($_POST) && isset($_POST["action"]) && $_POST["action"] == "wpfc_save_cdn_integration_ajax_request") {
                 $values = json_encode($_POST["values"]);
                 if (get_option("WpFastestCacheCDN")) {
                     update_option("WpFastestCacheCDN", $values);
                 } else {
                     add_option("WpFastestCacheCDN", $values, null, "yes");
                 }
                 echo json_encode(array("success" => true));
                 exit;
             } else {
                 if (isset($_GET) && isset($_GET["action"]) && $_GET["action"] == "wpfc_check_url_ajax_request") {
                     $_GET["url"] = strip_tags($_GET["url"]);
                     $_GET["url"] = str_replace(array("'", '"'), "", $_GET["url"]);
                     if (!preg_match("/^http/", $_GET["url"])) {
                         $_GET["url"] = "http://" . $_GET["url"];
                     }
                     $response = wp_remote_get($_GET["url"], array('timeout' => 10));
                     if (!$response || is_wp_error($response)) {
                         $res = array("success" => false, "error_message" => $response->get_error_message());
                     } else {
                         $response_code = wp_remote_retrieve_response_code($response);
                         if ($response_code == 200) {
                             $res = array("success" => true);
                         } else {
                             $res = array("success" => false, "error_message" => $response->get_error_message());
                         }
                     }
                     echo json_encode($res);
                     exit;
                 } else {
                     if (isset($_GET) && isset($_GET["action"]) && $_GET["action"] == "wpfc_cache_statics_get") {
                         if ($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")) {
                             if (file_exists(WPFC_WP_PLUGIN_DIR . "/wp-fastest-cache-premium/pro/library/statics.php")) {
                                 include_once $this->get_premium_path("statics.php");
                                 $cache_statics = new WpFastestCacheStatics();
                                 $res = $cache_statics->get();
                                 echo json_encode($res);
                                 exit;
                             }
                         }
                     } else {
                         if (isset($_GET) && isset($_GET["action"]) && $_GET["action"] == "wpfc_update_premium") {
                             if ($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")) {
                                 if (!file_exists(WPFC_WP_PLUGIN_DIR . "/wp-fastest-cache-premium/pro/library/update.php")) {
                                     $res = array("success" => false, "error_message" => "update.php is not exist");
                                 } else {
                                     include_once $this->get_premium_path("update.php");
                                     if (!class_exists("WpFastestCacheUpdate")) {
                                         $res = array("success" => false, "error_message" => "WpFastestCacheUpdate is not exist");
                                     } else {
                                         $wpfc_premium = new WpFastestCacheUpdate();
                                         $content = $wpfc_premium->download_premium();
                                         if ($content["success"]) {
                                             $wpfc_zip_data = $content["content"];
                                             $wpfc_zip_dest_path = WPFC_WP_PLUGIN_DIR . "/wp-fastest-cache-premium.zip";
                                             if (@file_put_contents($wpfc_zip_dest_path, $wpfc_zip_data)) {
                                                 include_once ABSPATH . "wp-admin/includes/file.php";
                                                 include_once ABSPATH . "wp-admin/includes/plugin.php";
                                                 if (function_exists("unzip_file")) {
                                                     $this->rm_folder_recursively(WPFC_WP_PLUGIN_DIR . "/wp-fastest-cache-premium");
                                                     if (!function_exists('gzopen')) {
                                                         $res = array("success" => false, "error_message" => "Missing zlib extension");
                                                     } else {
                                                         WP_Filesystem();
                                                         $unzipfile = unzip_file($wpfc_zip_dest_path, WPFC_WP_PLUGIN_DIR . "/");
                                                         if ($unzipfile) {
                                                             $result = activate_plugin('wp-fastest-cache-premium/wpFastestCachePremium.php');
                                                             if (is_wp_error($result)) {
                                                                 $res = array("success" => false, "error_message" => "Error occured while the plugin was activated");
                                                             } else {
                                                                 $res = array("success" => true);
                                                                 $this->deleteCache(true);
                                                             }
                                                         } else {
                                                             $res = array("success" => false, "error_message" => 'Error occured while the file was unzipped');
                                                         }
                                                     }
                                                 } else {
                                                     $res = array("success" => false, "error_message" => "unzip_file() is not found");
                                                 }
                                             } else {
                                                 $res = array("success" => false, "error_message" => "/wp-content/plugins/ is not writable");
                                             }
                                         } else {
                                             $res = array("success" => false, "error_message" => $content["error_message"]);
                                         }
                                     }
                                 }
                             } else {
                                 $res = array("success" => false, "error_message" => "Premium is not active");
                             }
                             echo json_encode($res);
                             exit;
                         } else {
                             if (isset($_GET) && isset($_GET["action"]) && in_array($_GET["action"], $optimize_image_ajax_requests)) {
                                 if ($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")) {
                                     include_once $this->get_premium_path("image.php");
                                     $img = new WpFastestCacheImageOptimisation();
                                     $img->hook();
                                 }
                             } else {
                                 $this->setCustomInterval();
                                 $this->options = $this->getOptions();
                                 add_action('transition_post_status', array($this, 'on_all_status_transitions'), 10, 3);
                                 $this->commentHooks();
                                 $this->checkCronTime();
                                 register_deactivation_hook(__FILE__, array('WpFastestCache', 'deactivate'));
                                 if ($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")) {
                                     include_once $this->get_premium_path("mobile-cache.php");
                                 }
                                 if ($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")) {
                                     include_once $this->get_premium_path("powerful-html.php");
                                 }
                                 if ($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")) {
                                     if (file_exists(WPFC_WP_PLUGIN_DIR . "/wp-fastest-cache-premium/pro/library/statics.php")) {
                                         include_once $this->get_premium_path("statics.php");
                                     }
                                 }
                                 if (is_admin()) {
                                     //for wp-panel
                                     $this->setRegularCron();
                                     if ($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")) {
                                         include_once $this->get_premium_path("image.php");
                                     }
                                     if ($this->isPluginActive("wp-fastest-cache-premium/wpFastestCachePremium.php")) {
                                         include_once $this->get_premium_path("logs.php");
                                     }
                                     $this->admin();
                                 } else {
                                     //for cache
                                     $this->cache();
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }