PageRenderTime 18ms CodeModel.GetById 2ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/quick-cache/includes/classes/clearing-routines.inc.php

https://bitbucket.org/sweetperceptions/nyey-everyday
PHP | 277 lines | 203 code | 0 blank | 74 comment | 83 complexity | 358ff370aec1875741b7de44498c1d57 MD5 | raw file
  1<?php
  2/*
  3Copyright: Š 2009 WebSharks, Inc. ( coded in the USA )
  4<mailto:support@websharks-inc.com> <http://www.websharks-inc.com/>
  5
  6Released under the terms of the GNU General Public License.
  7You should have received a copy of the GNU General Public License,
  8along with this software. In the main directory, see: /licensing/
  9If not, see: <http://www.gnu.org/licenses/>.
 10*/
 11if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
 12	exit ("Do not access this file directly.");
 13/**/
 14if (!class_exists ("c_ws_plugin__qcache_clearing_routines"))
 15	{
 16		class c_ws_plugin__qcache_clearing_routines
 17			{
 18				/*
 19				Function clears cache on creations/deletions.
 20				Attach to: add_action("delete_post");
 21				Attach to: add_action("save_post");
 22				Attach to: add_action("edit_post");
 23				*/
 24				public static function clear_on_post_page_creations_deletions ($id = FALSE)
 25					{
 26						static $once = false; /* Only clear "all" once. */
 27						global $pagenow; /* This variable holds the current page filename. */
 28						global $current_site, $current_blog; /* Need these for Multisite details. */
 29						/**/
 30						eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
 31						do_action ("ws_plugin__qcache_before_clear_on_post_page_creations_deletions", get_defined_vars ());
 32						unset ($__refs, $__v); /* Unset defined __refs, __v. */
 33						/**/
 34						if (is_blog_admin () && in_array ($pagenow, ($pages = array ("edit.php", "post.php", "post-new.php"))))
 35							{
 36								if ($id && preg_match ("/^single/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["clear_on_update"]))
 37									{
 38										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)))
 39											{
 40												$host_uri = preg_replace ("/^(" . preg_quote ($parse["host"], "/") . ")(\:[0-9]+)(\/)/i", "$1$3", $host_uri);
 41												/**/
 42												list ($cache) = (array)glob (WP_CONTENT_DIR . "/cache/qc-c-*-" . md5 ($host_uri) . "-*"); /* Match md5_2. */
 43												/**/
 44												if ($cache) /* If a cache file exists for this $host_uri. */
 45													{
 46														if (is_writable ($cache) && unlink ($cache))
 47															{
 48																if (!is_multisite () || !c_ws_plugin__qcache_utils_conds::is_multisite_farm () || is_main_site ())
 49																	{
 50																		$notice = 'Quick Cache updated: <code>' . esc_html ($host_uri) . '</code> automatically :-)';
 51																		c_ws_plugin__qcache_admin_notices::enqueue_admin_notice ($notice, $pages);
 52																	}
 53															}
 54														else /* Notify site owners when their /cache directory files are NOT writable. */
 55															{
 56																if (!is_multisite () || !c_ws_plugin__qcache_utils_conds::is_multisite_farm () || is_main_site ())
 57																	{
 58																		$notice = 'Quick Cache was unable to update: <code>' . esc_html ($host_uri) . '</code>. File not writable.';
 59																		c_ws_plugin__qcache_admin_notices::enqueue_admin_notice ($notice, $pages, true);
 60																	}
 61															}
 62													}
 63											}
 64										/**/
 65										if (preg_match ("/^single-fp$/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["clear_on_update"]))
 66											{
 67												if (($url = site_url ("/")) && is_array ($parse = c_ws_plugin__qcache_utils_urls::parse_url ($url)) && ($host_uri = preg_replace ("/^http(s?)\:\/\//i", "", $url)))
 68													{
 69														$host_uri = preg_replace ("/^(" . preg_quote ($parse["host"], "/") . ")(\:[0-9]+)(\/)/i", "$1$3", $host_uri);
 70														/**/
 71														list ($cache) = (array)glob (WP_CONTENT_DIR . "/cache/qc-c-*-" . md5 ($host_uri) . "-*"); /* Match md5_2. */
 72														/**/
 73														if ($cache) /* If a cache file exists for this $host_uri. */
 74															{
 75																if (is_writable ($cache) && unlink ($cache))
 76																	{
 77																		if (!is_multisite () || !c_ws_plugin__qcache_utils_conds::is_multisite_farm () || is_main_site ())
 78																			{
 79																				$notice = 'Quick Cache updated: <code>' . esc_html ($host_uri) . '</code> automatically :-)';
 80																				c_ws_plugin__qcache_admin_notices::enqueue_admin_notice ($notice, $pages);
 81																			}
 82																	}
 83																else /* Notify site owners when their /cache directory files are NOT writable. */
 84																	{
 85																		if (!is_multisite () || !c_ws_plugin__qcache_utils_conds::is_multisite_farm () || is_main_site ())
 86																			{
 87																				$notice = 'Quick Cache was unable to update: <code>' . esc_html ($host_uri) . '</code>. File not writable.';
 88																				c_ws_plugin__qcache_admin_notices::enqueue_admin_notice ($notice, $pages, true);
 89																			}
 90																	}
 91															}
 92													}
 93											}
 94										/**/
 95										do_action ("ws_plugin__qcache_during_clear_on_post_page_creations_deletions", get_defined_vars ());
 96									}
 97								else if (!$once && preg_match ("/^all$/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["clear_on_update"]) && ($once = true))
 98									{
 99										if (is_multisite () && is_object ($current_blog) && $current_blog->blog_id)
100											{
101												c_ws_plugin__qcache_purging_routines::schedule_cache_dir_purge ($current_blog);
102												/**/
103												if (!is_multisite () || !c_ws_plugin__qcache_utils_conds::is_multisite_farm () || is_main_site ())
104													{
105														$notice = 'Blog# <code>' . esc_html ($current_blog->blog_id) . '</code> : Quick Cache reset automatically to avoid conflicts :-)';
106														c_ws_plugin__qcache_admin_notices::enqueue_admin_notice ($notice, $pages);
107													}
108											}
109										else /* Otherwise, handle this normally. We are NOT in Multisite Mode. */
110											{
111												c_ws_plugin__qcache_purging_routines::schedule_cache_dir_purge ();
112												/**/
113												if (!is_multisite () || !c_ws_plugin__qcache_utils_conds::is_multisite_farm () || is_main_site ())
114													{
115														$notice = 'Quick Cache reset automatically to avoid conflicts :-)';
116														c_ws_plugin__qcache_admin_notices::enqueue_admin_notice ($notice, $pages);
117													}
118											}
119										/**/
120										do_action ("ws_plugin__qcache_during_clear_on_post_page_creations_deletions", get_defined_vars ());
121									}
122							}
123						/**/
124						do_action ("ws_plugin__qcache_after_clear_on_post_page_creations_deletions", get_defined_vars ());
125						/**/
126						return; /* Return for uniformity. */
127					}
128				/*
129				Function clears cache on various creations/deletions.
130				Attach to: add_action("create_term");
131				Attach to: add_action("edit_terms");
132				Attach to: add_action("delete_term");
133				Attach to: add_action("add_link");
134				Attach to: add_action("edit_link");
135				Attach to: add_action("delete_link");
136				*/
137				public static function clear_on_creations_deletions ($term_or_link_id = FALSE)
138					{
139						static $once = false; /* Only clear once. */
140						global $pagenow; /* This variable holds the current page filename. */
141						global $current_site, $current_blog; /* Need these for Multisite details. */
142						/**/
143						eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
144						do_action ("ws_plugin__qcache_before_clear_on_creations_deletions", get_defined_vars ());
145						unset ($__refs, $__v); /* Unset defined __refs, __v. */
146						/**/
147						if (is_blog_admin () && in_array ($pagenow, ($pages = array ("edit-tags.php", "link-manager.php", "link.php", "link-add.php", "edit-link-categories.php", "link-category.php"))))
148							{
149								if (!$once && preg_match ("/^all$/", $GLOBALS["WS_PLUGIN__"]["qcache"]["o"]["clear_on_update"]) && ($once = true))
150									{
151										if (is_multisite () && is_object ($current_blog) && $current_blog->blog_id)
152											{
153												c_ws_plugin__qcache_purging_routines::schedule_cache_dir_purge ($current_blog);
154												/**/
155												if (!is_multisite () || !c_ws_plugin__qcache_utils_conds::is_multisite_farm () || is_main_site ())
156													{
157														$notice = 'Blog# <code>' . esc_html ($current_blog->blog_id) . '</code> : Quick Cache reset automatically to avoid conflicts :-)';
158														c_ws_plugin__qcache_admin_notices::enqueue_admin_notice ($notice, $pages);
159													}
160											}
161										else /* Otherwise, handle this normally. We are NOT in Multisite Mode. */
162											{
163												c_ws_plugin__qcache_purging_routines::schedule_cache_dir_purge ();
164												/**/
165												if (!is_multisite () || !c_ws_plugin__qcache_utils_conds::is_multisite_farm () || is_main_site ())
166													{
167														$notice = 'Quick Cache reset automatically to avoid conflicts :-)';
168														c_ws_plugin__qcache_admin_notices::enqueue_admin_notice ($notice, $pages);
169													}
170											}
171										/**/
172										do_action ("ws_plugin__qcache_during_clear_on_creations_deletions", get_defined_vars ());
173									}
174							}
175						/**/
176						do_action ("ws_plugin__qcache_after_clear_on_creations_deletions", get_defined_vars ());
177						/**/
178						return; /* Return for uniformity. */
179					}
180				/*
181				Function for clearing cache on theme changes.
182				Attach to: add_action("switch_theme");
183				
184				The cache is always reset after a theme change,
185				no matter what setting has been configured. A theme
186				being changed will always require a cache reset!
187				*/
188				public static function clear_on_theme_changes ()
189					{
190						static $once = false; /* Only clear once. */
191						global $pagenow; /* Holds the current page filename. */
192						global $current_site, $current_blog; /* Need these for Multisite details. */
193						/**/
194						do_action ("ws_plugin__qcache_before_clear_on_theme_changes", get_defined_vars ());
195						/**/
196						if (is_blog_admin () && in_array ($pagenow, ($pages = array ("themes.php"))))
197							{
198								if (!$once && ($once = true)) /* Only clear once. */
199									{
200										if (is_multisite () && is_object ($current_blog) && $current_blog->blog_id)
201											{
202												c_ws_plugin__qcache_purging_routines::schedule_cache_dir_purge ($current_blog);
203												/**/
204												if (!is_multisite () || !c_ws_plugin__qcache_utils_conds::is_multisite_farm () || is_main_site ())
205													{
206														$notice = 'Blog# <code>' . esc_html ($current_blog->blog_id) . '</code> : Quick Cache reset automatically to avoid conflicts :-)';
207														c_ws_plugin__qcache_admin_notices::enqueue_admin_notice ($notice, $pages);
208													}
209											}
210										else /* Otherwise, handle this normally. We are NOT in Multisite Mode. */
211											{
212												c_ws_plugin__qcache_purging_routines::schedule_cache_dir_purge ();
213												/**/
214												if (!is_multisite () || !c_ws_plugin__qcache_utils_conds::is_multisite_farm () || is_main_site ())
215													{
216														$notice = 'Quick Cache reset automatically to avoid conflicts :-)';
217														c_ws_plugin__qcache_admin_notices::enqueue_admin_notice ($notice, $pages);
218													}
219											}
220										/**/
221										do_action ("ws_plugin__qcache_during_clear_on_theme_changes", get_defined_vars ());
222									}
223							}
224						/**/
225						do_action ("ws_plugin__qcache_after_clear_on_theme_changes", get_defined_vars ());
226						/**/
227						return; /* Return for uniformity. */
228					}
229				/*
230				Function for clearing cache via ajax.
231				Attach to: add_action("wp_ajax_ws_plugin__qcache_ajax_clear");
232				*/
233				public static function ajax_clear ()
234					{
235						global $current_site, $current_blog; /* Multisite details. */
236						/**/
237						do_action ("ws_plugin__qcache_before_ajax_clear", get_defined_vars ());
238						/**/
239						status_header (200); /* Send a 200 OK status header. */
240						header ("Content-Type: text/plain; charset=utf-8"); /* Content-Type text/plain with UTF-8. */
241						eval ('while (@ob_end_clean ());'); /* End/clean all output buffers that may or may not exist. */
242						/**/
243						if (($nonce = $_POST["ws_plugin__qcache_ajax_clear"]) && wp_verify_nonce ($nonce, "ws-plugin--qcache-ajax-clear"))
244							{
245								if (is_multisite () && !is_main_site () && is_object ($current_blog) && $current_blog->blog_id)
246									{
247										c_ws_plugin__qcache_purging_routines::purge_cache_dir ($current_blog);
248										/**/
249										$status = 'Cleared ( this blog )'; /* Indicate "this blog" to the Super Admin. */
250										/**/
251										echo "jQuery ('input#ws-plugin--qcache-ajax-clear').css ('background-image', 'url(\'" . c_ws_plugin__qcache_utils_strings::esc_js_sq ($GLOBALS["WS_PLUGIN__"]["qcache"]["c"]["dir_url"], 3) . "/images/ajax-clear.png\')');";
252										echo "setTimeout (function (){ jQuery ('input#ws-plugin--qcache-ajax-clear').val ('Clear Cache'); }, 2000);";
253										echo "jQuery ('input#ws-plugin--qcache-ajax-clear').val ('" . c_ws_plugin__qcache_utils_strings::esc_js_sq ($status) . "');";
254										echo "jQuery ('input#ws-plugin--qcache-ajax-clear').each (function (){ this.blur(); });";
255									}
256								else /* Otherwise, handle this normally. We are NOT in Multisite Mode. */
257									{
258										c_ws_plugin__qcache_purging_routines::purge_cache_dir ();
259										/**/
260										$status = (is_multisite ()) ? 'Cleared ( all blogs )' : '( Cleared )';
261										/**/
262										echo "jQuery ('input#ws-plugin--qcache-ajax-clear').css ('background-image', 'url(\'" . c_ws_plugin__qcache_utils_strings::esc_js_sq ($GLOBALS["WS_PLUGIN__"]["qcache"]["c"]["dir_url"], 3) . "/images/ajax-clear.png\')');";
263										echo "setTimeout (function (){ jQuery ('input#ws-plugin--qcache-ajax-clear').val ('Clear Cache'); }, 2000);";
264										echo "jQuery ('input#ws-plugin--qcache-ajax-clear').val ('" . c_ws_plugin__qcache_utils_strings::esc_js_sq ($status) . "');";
265										echo "jQuery ('input#ws-plugin--qcache-ajax-clear').each (function (){ this.blur(); });";
266									}
267								/**/
268								do_action ("ws_plugin__qcache_during_ajax_clear", get_defined_vars ());
269							}
270						/**/
271						do_action ("ws_plugin__qcache_after_ajax_clear", get_defined_vars ());
272						/**/
273						exit (); /* Clean exit. */
274					}
275			}
276	}
277?>