Пример #1
0
 public static function parse_uri($url_uri = FALSE)
 {
     if (is_string($url_uri) && is_array($parse = c_ws_plugin__qcache_utils_urls::parse_url($url_uri))) {
         $parse["path"] = !empty($parse["path"]) ? strpos($parse["path"], "/") === 0 ? $parse["path"] : "/" . $parse["path"] : "/";
         /**/
         return !empty($parse["query"]) ? $parse["path"] . "?" . $parse["query"] : $parse["path"];
     } else {
         /* Force a string return value here. */
         return "";
     }
 }
Пример #2
0
 public static function auto_cache_engine()
 {
     do_action("ws_plugin__qcache_before_auto_cache_engine", get_defined_vars());
     /**/
     if ($GLOBALS["WS_PLUGIN__"]["qcache"]["c"]["configured"] && $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["enabled"]) {
         if ($GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["auto_cache_enabled"] && $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["auto_cache_agent"]) {
             if ($GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["auto_cache_sitemap_url"] || $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["auto_cache_additional_urls"]) {
                 if ($GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["expiration"] >= 3600) {
                     $log = "";
                     /* Initialize log to an empty string value here. */
                     /**/
                     clearstatcache() . define("QUICK_CACHE_ALLOWED", false);
                     /* Cache NOT allowed here. */
                     /**/
                     @set_time_limit(900) . @ini_set("memory_limit", apply_filters("admin_memory_limit", WP_MAX_MEMORY_LIMIT)) . @ignore_user_abort(true);
                     /**/
                     do_action("ws_plugin__qcache_before_auto_cache_engine_routines", get_defined_vars());
                     /**/
                     if ($GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["use_flock_or_sem"] === "sem" && function_exists("sem_get") && ($mutex = @sem_get(1977, 1, 0644 | IPC_CREAT, 1)) && @sem_acquire($mutex)) {
                         $mutex_method = "sem";
                     } else {
                         if ($GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["use_flock_or_sem"] === "flock" && ($mutex = @fopen(WP_CONTENT_DIR . "/cache/qc-l-ac.mutex.lock", "w")) && @flock($mutex, LOCK_EX)) {
                             $mutex_method = "flock";
                         }
                     }
                     /**/
                     if ($mutex && $mutex_method && is_array($urls = array())) {
                         eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
                         do_action("ws_plugin__qcache_during_auto_cache_engine_before", get_defined_vars());
                         unset($__refs, $__v);
                         /* Unset defined __refs, __v. */
                         /**/
                         if ($GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["auto_cache_sitemap_url"]) {
                             if ($sitemap = c_ws_plugin__qcache_utils_urls::remote($GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["auto_cache_sitemap_url"])) {
                                 preg_match_all("/\\<loc\\>(.+?)\\<\\/loc\\>/i", $sitemap, $sitemap_matches);
                                 if (is_array($sitemap_matches[1]) && !empty($sitemap_matches[1])) {
                                     foreach ($sitemap_matches[1] as $sitemap_match) {
                                         if ($url = trim($sitemap_match)) {
                                             $urls[] = $url;
                                         }
                                     }
                                 }
                             }
                         }
                         /**/
                         if ($GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["auto_cache_additional_urls"]) {
                             foreach (preg_split("/[\r\n\t]+/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["auto_cache_additional_urls"]) as $additional) {
                                 if ($url = trim($additional)) {
                                     $urls[] = $url;
                                 }
                             }
                         }
                         /**/
                         eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
                         do_action("ws_plugin__qcache_during_auto_cache_engine_before_urls", get_defined_vars());
                         unset($__refs, $__v);
                         /* Unset defined __refs, __v. */
                         /**/
                         if (($urls = array_unique($urls)) && !empty($urls) && shuffle($urls)) {
                             foreach ($urls as $url) {
                                 if (is_array($parse = c_ws_plugin__qcache_utils_urls::parse_url($url)) && ($host_uri = preg_replace("/^http(s?)\\:\\/\\//i", "", $url))) {
                                     $host_uri = preg_replace("/^(" . preg_quote($parse["host"], "/") . ")(\\:[0-9]+)(\\/)/i", "\$1\$3", $host_uri);
                                     /**/
                                     list($cache) = (array) glob(WP_CONTENT_DIR . "/cache/qc-c-*-" . md5($host_uri) . "-*");
                                     /* Match md5_2. */
                                     /**/
                                     if (!$cache || filemtime($cache) < strtotime("-" . $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["expiration"] . " seconds")) {
                                         c_ws_plugin__qcache_utils_urls::remote($url, false, array("timeout" => 0.01, "blocking" => false, "user-agent" => $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["auto_cache_agent"] . " + Quick Cache ( Auto-Cache Engine )"));
                                         /**/
                                         $log .= date("M j, Y, g:i a T") . " / Auto-Cached: " . $url . "\n";
                                         /* Keeps a running log of each URL being processed. */
                                         /**/
                                         if (($processed = (int) $processed + 1) >= $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["auto_cache_max_processes"]) {
                                             break;
                                         } else {
                                             if ($processed >= 25) {
                                                 /* Hard-coded maximum; for security. */
                                                 break;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         /**/
                         eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
                         do_action("ws_plugin__qcache_during_auto_cache_engine_before_log", get_defined_vars());
                         unset($__refs, $__v);
                         /* Unset defined __refs, __v. */
                         /**/
                         if ($log && (is_dir(WP_CONTENT_DIR . "/cache") || is_writable(WP_CONTENT_DIR))) {
                             if (!is_dir(WP_CONTENT_DIR . "/cache")) {
                                 mkdir(WP_CONTENT_DIR . "/cache", 0777, true);
                             }
                             /**/
                             clearstatcache();
                             /* Clear stat cache before next routine. */
                             /**/
                             if (is_dir(WP_CONTENT_DIR . "/cache") && is_writable(WP_CONTENT_DIR . "/cache")) {
                                 $auto_cache_log = WP_CONTENT_DIR . "/cache/qc-l-auto-cache.log";
                                 /**/
                                 if (file_exists($auto_cache_log) && filesize($auto_cache_log) > 2097152) {
                                     if (is_writable($auto_cache_log)) {
                                         /* This is a 2MB log rotation ^. */
                                         unlink($auto_cache_log);
                                     }
                                 }
                                 /* Resets the log. */
                                 /**/
                                 clearstatcache();
                                 /* Clear stat cache before next routine. */
                                 /**/
                                 if (!file_exists($auto_cache_log) || is_writable($auto_cache_log)) {
                                     file_put_contents($auto_cache_log, $log, FILE_APPEND);
                                 }
                             }
                         }
                         /**/
                         if ($mutex_method === "sem") {
                             sem_release($mutex);
                         } else {
                             if ($mutex_method === "flock") {
                                 flock($mutex, LOCK_UN);
                             }
                         }
                         /**/
                         do_action("ws_plugin__qcache_during_auto_cache_engine_after", get_defined_vars());
                     }
                     /**/
                     do_action("ws_plugin__qcache_during_auto_cache_engine", get_defined_vars());
                 }
             }
         }
     }
     /**/
     do_action("ws_plugin__qcache_after_auto_cache_engine", get_defined_vars());
     /**/
     return;
     /* Return for uniformity. */
 }
 public static function clear_on_post_page_creations_deletions($id = FALSE)
 {
     static $once = false;
     /* Only clear "all" once. */
     global $pagenow;
     /* This variable holds the current page filename. */
     global $current_site, $current_blog;
     /* Need these for Multisite details. */
     /**/
     eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
     do_action("ws_plugin__qcache_before_clear_on_post_page_creations_deletions", get_defined_vars());
     unset($__refs, $__v);
     /* Unset defined __refs, __v. */
     /**/
     if (is_blog_admin() && in_array($pagenow, $pages = array("edit.php", "post.php", "post-new.php"))) {
         if ($id && preg_match("/^single/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["clear_on_update"])) {
             if (($url = get_permalink($id)) && is_array($parse = c_ws_plugin__qcache_utils_urls::parse_url($url)) && ($host_uri = preg_replace("/^http(s?)\\:\\/\\//i", "", $url))) {
                 $host_uri = preg_replace("/^(" . preg_quote($parse["host"], "/") . ")(\\:[0-9]+)(\\/)/i", "\$1\$3", $host_uri);
                 /**/
                 list($cache) = (array) glob(WP_CONTENT_DIR . "/cache/qc-c-*-" . md5($host_uri) . "-*");
                 /* Match md5_2. */
                 /**/
                 if ($cache) {
                     if (is_writable($cache) && unlink($cache)) {
                         if (!is_multisite() || !c_ws_plugin__qcache_utils_conds::is_multisite_farm() || is_main_site()) {
                             $notice = 'Quick Cache updated: <code>' . esc_html($host_uri) . '</code> automatically :-)';
                             c_ws_plugin__qcache_admin_notices::enqueue_admin_notice($notice, $pages);
                         }
                     } else {
                         if (!is_multisite() || !c_ws_plugin__qcache_utils_conds::is_multisite_farm() || is_main_site()) {
                             $notice = 'Quick Cache was unable to update: <code>' . esc_html($host_uri) . '</code>. File not writable.';
                             c_ws_plugin__qcache_admin_notices::enqueue_admin_notice($notice, $pages, true);
                         }
                     }
                 }
             }
             /**/
             if (preg_match("/^single-fp\$/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["clear_on_update"])) {
                 if (($url = site_url("/")) && is_array($parse = c_ws_plugin__qcache_utils_urls::parse_url($url)) && ($host_uri = preg_replace("/^http(s?)\\:\\/\\//i", "", $url))) {
                     $host_uri = preg_replace("/^(" . preg_quote($parse["host"], "/") . ")(\\:[0-9]+)(\\/)/i", "\$1\$3", $host_uri);
                     /**/
                     list($cache) = (array) glob(WP_CONTENT_DIR . "/cache/qc-c-*-" . md5($host_uri) . "-*");
                     /* Match md5_2. */
                     /**/
                     if ($cache) {
                         if (is_writable($cache) && unlink($cache)) {
                             if (!is_multisite() || !c_ws_plugin__qcache_utils_conds::is_multisite_farm() || is_main_site()) {
                                 $notice = 'Quick Cache updated: <code>' . esc_html($host_uri) . '</code> automatically :-)';
                                 c_ws_plugin__qcache_admin_notices::enqueue_admin_notice($notice, $pages);
                             }
                         } else {
                             if (!is_multisite() || !c_ws_plugin__qcache_utils_conds::is_multisite_farm() || is_main_site()) {
                                 $notice = 'Quick Cache was unable to update: <code>' . esc_html($host_uri) . '</code>. File not writable.';
                                 c_ws_plugin__qcache_admin_notices::enqueue_admin_notice($notice, $pages, true);
                             }
                         }
                     }
                 }
             }
             /**/
             do_action("ws_plugin__qcache_during_clear_on_post_page_creations_deletions", get_defined_vars());
         } else {
             if (!$once && preg_match("/^all\$/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["clear_on_update"]) && ($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_post_page_creations_deletions", get_defined_vars());
             }
         }
     }
     /**/
     do_action("ws_plugin__qcache_after_clear_on_post_page_creations_deletions", get_defined_vars());
     /**/
     return;
     /* Return for uniformity. */
 }