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 ""; } }
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()); } } }
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 = ""; clearstatcache(); @set_time_limit(900); @ignore_user_abort(true); @ini_set("memory_limit", "512M"); /**/ define("QUICK_CACHE_ALLOWED", false); /**/ 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 (($parsed = parse_url($url)) && ($host_uri = preg_replace("/^http(s?)\\:\\/\\//i", "", $url))) { $host_uri = preg_replace("/^(" . preg_quote($parsed["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. */ }