Ejemplo n.º 1
0
 public static function activate()
 {
     do_action("ws_plugin__qcache_before_activation", get_defined_vars());
     /**/
     !is_numeric(get_option("ws_plugin__qcache_configured")) ? update_option("ws_plugin__qcache_configured", "0") : null;
     !is_array(get_option("ws_plugin__qcache_notices")) ? update_option("ws_plugin__qcache_notices", array()) : null;
     !is_array(get_option("ws_plugin__qcache_options")) ? update_option("ws_plugin__qcache_options", array()) : null;
     /**/
     if ($GLOBALS["WS_PLUGIN__"]["qcache"]["c"]["configured"] && $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["enabled"]) {
         if (c_ws_plugin__qcache_wp_cache::add_wp_cache()) {
             /* Add WP_CACHE to the config file. */
             if (c_ws_plugin__qcache_advanced_cache::add_advanced()) {
                 /* Add the advanced-cache.php file. */
                 if (c_ws_plugin__qcache_garbage_collection::add_garbage_collector()) {
                     /* Add the garbage collector. */
                     if (c_ws_plugin__qcache_purging_routines::schedule_cache_dir_purge(false, false, false)) {
                         $re_activated = true;
                         /* Set this variable has having been re-activated successfully. */
                         $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["auto_cache_enabled"] ? c_ws_plugin__qcache_auto_cache::add_auto_cache_engine() : c_ws_plugin__qcache_auto_cache::delete_auto_cache_engine();
                         c_ws_plugin__qcache_admin_notices::enqueue_admin_notice('<strong>Quick Cache</strong> has been <strong>re-activated</strong> with the latest version. The cache has been reset automatically to avoid conflicts :-)', array("blog|network:plugins.php", "blog|network:ws-plugin--qcache-options"));
                     }
                 }
             }
         }
         /**/
         if (!$re_activated) {
             c_ws_plugin__qcache_admin_notices::enqueue_admin_notice('<strong>Quick Cache</strong> Please go to <code>Quick Cache -> Config Options</code>. You\'ll need to disable, and then re-enable Quick Cache, to complete the upgrade process.', array("blog|network:plugins.php", "blog|network:ws-plugin--qcache-options"), true);
         }
     }
     /**/
     update_option("ws_plugin__qcache_activated_version", WS_PLUGIN__QCACHE_VERSION);
     /**/
     do_action("ws_plugin__qcache_after_activation", get_defined_vars());
     /**/
     return;
     /* Return for uniformity. */
 }
 public static function options_page()
 {
     do_action("ws_plugin__qcache_before_options_page", get_defined_vars());
     /**/
     c_ws_plugin__qcache_menu_pages::update_all_options() . clearstatcache();
     /**/
     if (file_exists(ABSPATH . "wp-config.php") && !is_writable(ABSPATH . "wp-config.php")) {
         c_ws_plugin__qcache_admin_notices::display_admin_notice('<strong>Permissions:</strong> Please check permissions on <code>' . esc_html(preg_replace("/^" . preg_quote($_SERVER["DOCUMENT_ROOT"], "/") . "/", "", ABSPATH . "wp-config.php")) . '</code>. Quick Cache needs write-access to this file. Permissions need to be <code>755</code> or higher.', true);
     } else {
         if (file_exists(dirname(ABSPATH) . "/wp-config.php") && !is_writable(dirname(ABSPATH) . "/wp-config.php")) {
             c_ws_plugin__qcache_admin_notices::display_admin_notice('<strong>Permissions:</strong> Please check permissions on <code>' . esc_html(preg_replace("/^" . preg_quote($_SERVER["DOCUMENT_ROOT"], "/") . "/", "", dirname(ABSPATH) . "/wp-config.php")) . '</code>. Quick Cache needs write-access to this file. Permissions need to be <code>755</code> or higher.', true);
         }
     }
     if (is_dir(WP_CONTENT_DIR) && !is_writable(WP_CONTENT_DIR)) {
         c_ws_plugin__qcache_admin_notices::display_admin_notice('<strong>Permissions:</strong> Please check permissions on <code>' . esc_html(preg_replace("/^" . preg_quote($_SERVER["DOCUMENT_ROOT"], "/") . "/", "", WP_CONTENT_DIR)) . '</code>. Quick Cache needs write-access to this directory. Permissions need to be <code>755</code> or higher.', true);
     }
     if (is_dir(WP_CONTENT_DIR . "/cache") && !is_writable(WP_CONTENT_DIR . "/cache")) {
         c_ws_plugin__qcache_admin_notices::display_admin_notice('<strong>Permissions:</strong> Please check permissions on <code>' . esc_html(preg_replace("/^" . preg_quote($_SERVER["DOCUMENT_ROOT"], "/") . "/", "", WP_CONTENT_DIR . "/cache")) . '</code>. Quick Cache needs write-access to this directory. Permissions need to be <code>755</code> or higher.', true);
     }
     /**/
     include_once dirname(dirname(__FILE__)) . "/menu-pages/options.inc.php";
     /**/
     do_action("ws_plugin__qcache_after_options_page", get_defined_vars());
     /**/
     return;
     /* Return for uniformity. */
 }
Ejemplo n.º 3
0
 public static function admin_notices()
 {
     global $pagenow;
     /* This holds the current page filename. */
     /**/
     do_action("ws_plugin__qcache_before_admin_notices", get_defined_vars());
     /**/
     if (is_admin() && is_array($notices = get_option("ws_plugin__qcache_notices")) && !empty($notices)) {
         $a = is_blog_admin() ? "blog" : $a;
         $a = is_user_admin() ? "user" : $a;
         $a = is_network_admin() ? "network" : $a;
         $a = !$a ? "blog" : $a;
         /* Default Blog Admin. */
         /**/
         foreach ($notices as $i => $notice) {
             /* Check several things about each Notice. */
             foreach (!$notice["on_pages"] ? array("*") : (array) $notice["on_pages"] as $page) {
                 if (!preg_match("/^(.+?)\\:/", $page)) {
                     /* NO prefix? */
                     $page = "blog:" . ltrim($page, ":");
                 }
                 /* `blog:` */
                 /**/
                 $adms = preg_split("/\\|/", preg_replace("/\\:(.*)\$/i", "", $page));
                 $page = preg_replace("/^([^\\:]*)\\:/i", "", $page);
                 /**/
                 if (empty($adms) || in_array("*", $adms) || in_array($a, $adms)) {
                     if (!$page || "*" === $page || $pagenow === $page || $_GET["page"] === $page) {
                         if (strtotime("now") >= (int) $notice["time"]) {
                             eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
                             do_action("ws_plugin__qcache_during_admin_notices_before_display", get_defined_vars());
                             unset($__refs, $__v);
                             /* Unset defined __refs, __v. */
                             /**/
                             if (!$notice["dismiss"] || $_GET["ws-plugin--qcache-dismiss-admin-notice"] === md5($notice["notice"])) {
                                 unset($notices[$i]);
                             }
                             /* Clear this administrative notice now? */
                             /**/
                             if (!$notice["dismiss"] || $_GET["ws-plugin--qcache-dismiss-admin-notice"] !== md5($notice["notice"])) {
                                 c_ws_plugin__qcache_admin_notices::display_admin_notice($notice["notice"], $notice["error"], $notice["dismiss"]);
                             }
                             /**/
                             do_action("ws_plugin__qcache_during_admin_notices_after_display", get_defined_vars());
                         }
                         /**/
                         continue 2;
                         /* This Notice processed; continue to next. */
                     }
                 }
             }
         }
         /**/
         $notices = array_merge($notices);
         /* Re-index array. */
         /**/
         eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
         do_action("ws_plugin__qcache_during_admin_notices", get_defined_vars());
         unset($__refs, $__v);
         /* Unset defined __refs, __v. */
         /**/
         update_option("ws_plugin__qcache_notices", $notices);
     }
     /**/
     do_action("ws_plugin__qcache_after_admin_notices", get_defined_vars());
     /**/
     return;
     /* Return for uniformity. */
 }
 public static function clear_on_theme_changes()
 {
     static $once = false;
     /* Only clear once. */
     global $pagenow;
     /* Holds the current page filename. */
     global $current_site, $current_blog;
     /* Need these for Multisite details. */
     /**/
     do_action("ws_plugin__qcache_before_clear_on_theme_changes", get_defined_vars());
     /**/
     if (c_ws_plugin__qcache_utils_conds::is_blog_admin() && in_array($pagenow, $pages = array("themes.php"))) {
         if (!$once && ($once = true)) {
             if (is_multisite() && is_object($current_blog) && $current_blog->blog_id) {
                 c_ws_plugin__qcache_purging_routines::schedule_cache_dir_purge($current_blog);
                 /**/
                 if (!is_multisite() || !c_ws_plugin__qcache_utils_conds::is_multisite_farm() || is_main_site()) {
                     $notice = 'Blog# <code>' . esc_html($current_blog->blog_id) . '</code> : Quick Cache reset automatically to avoid conflicts :-)';
                     c_ws_plugin__qcache_admin_notices::enqueue_admin_notice($notice, $pages);
                 }
             } else {
                 c_ws_plugin__qcache_purging_routines::schedule_cache_dir_purge();
                 /**/
                 if (!is_multisite() || !c_ws_plugin__qcache_utils_conds::is_multisite_farm() || is_main_site()) {
                     $notice = 'Quick Cache reset automatically to avoid conflicts :-)';
                     c_ws_plugin__qcache_admin_notices::enqueue_admin_notice($notice, $pages);
                 }
             }
             /**/
             do_action("ws_plugin__qcache_during_clear_on_theme_changes", get_defined_vars());
         }
     }
     /**/
     do_action("ws_plugin__qcache_after_clear_on_theme_changes", get_defined_vars());
     /**/
     return;
     /* Return for uniformity. */
 }
Ejemplo n.º 5
0
 public static function add_advanced()
 {
     do_action("ws_plugin__qcache_before_add_advanced", get_defined_vars());
     /**/
     if (!c_ws_plugin__qcache_advanced_cache::delete_advanced()) {
         return apply_filters("ws_plugin__qcache_add_advanced", false, get_defined_vars());
     } else {
         if (is_writable(WP_CONTENT_DIR) && (!file_exists(WP_CONTENT_DIR . "/advanced-cache.php") || is_writable(WP_CONTENT_DIR . "/advanced-cache.php")) && ($handler = file_get_contents(dirname(dirname(__FILE__)) . "/templates/handler.tpl.php"))) {
             $handler = preg_replace("/\"%%QUICK_CACHE_ENABLED%%\"/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["enabled"], $handler);
             $handler = preg_replace("/\"%%QUICK_CACHE_ENABLE_DEBUGGING%%\"/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["enable_debugging"], $handler);
             $handler = preg_replace("/\"%%QUICK_CACHE_DONT_CACHE_WHEN_LOGGED_IN%%\"/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["dont_cache_when_logged_in"], $handler);
             $handler = preg_replace("/\"%%QUICK_CACHE_DONT_CACHE_QUERY_STRING_REQUESTS%%\"/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["dont_cache_query_string_requests"], $handler);
             $handler = preg_replace("/\"%%QUICK_CACHE_EXPIRATION%%\"/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["expiration"], $handler);
             $handler = preg_replace("/\"%%QUICK_CACHE_ALLOW_BROWSER_CACHE%%\"/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["allow_browser_cache"], $handler);
             /**/
             $handler = preg_replace("/%%QUICK_CACHE_USE_FLOCK_OR_SEM%%/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["use_flock_or_sem"], $handler);
             /**/
             foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["dont_cache_these_uris"]) as $uri) {
                 if ($uri = trim($uri)) {
                     $uris .= "|" . preg_quote($uri, "/");
                 }
             }
             if ($uris = trim($uris, " \r\n\t\v|")) {
                 $uris = "/" . c_ws_plugin__qcache_utils_strings::esc_dq($uris) . "/";
             }
             $handler = preg_replace("/%%QUICK_CACHE_DONT_CACHE_THESE_URIS%%/", $uris, $handler);
             /**/
             foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["dont_cache_these_refs"]) as $ref) {
                 if ($ref = trim($ref)) {
                     $refs .= "|" . preg_quote($ref, "/");
                 }
             }
             if ($refs = trim($refs, " \r\n\t\v|")) {
                 $refs = "/" . c_ws_plugin__qcache_utils_strings::esc_dq($refs) . "/i";
             }
             $handler = preg_replace("/%%QUICK_CACHE_DONT_CACHE_THESE_REFS%%/", $refs, $handler);
             /**/
             foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["dont_cache_these_agents"]) as $agent) {
                 if ($agent = trim($agent)) {
                     $agents .= "|" . preg_quote($agent, "/");
                 }
             }
             if ($agents = trim($agents, " \r\n\t\v|")) {
                 $agents = "/" . c_ws_plugin__qcache_utils_strings::esc_dq($agents) . "/i";
             }
             $handler = preg_replace("/%%QUICK_CACHE_DONT_CACHE_THESE_AGENTS%%/", $agents, $handler);
             /**/
             if (strlen($GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["version_salt"])) {
                 if (file_put_contents(WP_CONTENT_DIR . "/qcache-salt-ok.php", '<?php error_reporting(0); $v = ' . $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["version_salt"] . '; echo "ok"; ?>')) {
                     $salt_ok = ($syntax_check = c_ws_plugin__qcache_utils_urls::remote(WP_CONTENT_URL . "/qcache-salt-ok.php")) === "ok" ? true : false;
                     if (!$salt_ok) {
                         /* If we could not validate the syntax of their salt, we need to notify them that it will not be used. */
                         c_ws_plugin__qcache_admin_notices::enqueue_admin_notice("<strong>Quick Cache:</strong> Your MD5 Version Salt may contain syntax errors. Please check it and try again. Otherwise, if you are unable to correct the problem, your Salt will simply be ignored. Quick Cache will continue to function properly using its default setting.", "blog|network:ws-plugin--qcache-options", true);
                     }
                     unlink(WP_CONTENT_DIR . "/qcache-salt-ok.php");
                 }
             }
             $handler = preg_replace("/\"%%QUICK_CACHE_VERSION_SALT%%\"/", $salt_ok ? $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["version_salt"] : '""', $handler);
             /**/
             eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
             do_action("ws_plugin__qcache_during_add_advanced", get_defined_vars());
             unset($__refs, $__v);
             /* Unset defined __refs, __v. */
             /**/
             file_put_contents(WP_CONTENT_DIR . "/advanced-cache.php", trim($handler));
             /**/
             return apply_filters("ws_plugin__qcache_add_advanced", true, get_defined_vars());
         } else {
             return apply_filters("ws_plugin__qcache_add_advanced", false, get_defined_vars());
         }
     }
 }