PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/sweetperceptions/nyey-everyday
PHP | 104 lines | 70 code | 0 blank | 34 comment | 36 complexity | 2eb0e0363cb364bcc2710695d43f0064 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /*
  3. Copyright: Š 2009 WebSharks, Inc. ( coded in the USA )
  4. <mailto:support@websharks-inc.com> <http://www.websharks-inc.com/>
  5. Released under the terms of the GNU General Public License.
  6. You should have received a copy of the GNU General Public License,
  7. along with this software. In the main directory, see: /licensing/
  8. If not, see: <http://www.gnu.org/licenses/>.
  9. */
  10. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  11. exit("Do not access this file directly.");
  12. /**/
  13. if (!class_exists ("c_ws_plugin__qcache_purging_routines"))
  14. {
  15. class c_ws_plugin__qcache_purging_routines
  16. {
  17. /*
  18. Schedules an immediate purge of the cache directory.
  19. By default, this includes all sites; and leaves locks / logs.
  20. */
  21. public static function schedule_cache_dir_purge ($qc_c_blog = FALSE, $leave_qc_l_locks = TRUE, $leave_qc_l_logs = TRUE)
  22. {
  23. static $once; /* Only schedule once. */
  24. /**/
  25. do_action ("ws_plugin__qcache_before_schedule_cache_dir_purge", get_defined_vars ());
  26. /**/
  27. if (!isset ($once)) /* No need to duplicate this. */
  28. {
  29. if (function_exists ("wp_cron") && ($once = true)) /* If available. */
  30. {
  31. $args = array ($qc_c_blog, $leave_qc_l_locks, $leave_qc_l_logs);
  32. /**/
  33. wp_schedule_single_event (time (), "ws_plugin__qcache_purge_cache_dir__schedule", $args);
  34. /**/
  35. do_action ("ws_plugin__qcache_during_schedule_cache_dir_purge", get_defined_vars ());
  36. }
  37. else /* WP-Cron is not available. */
  38. {
  39. $once = false;
  40. }
  41. }
  42. /**/
  43. return apply_filters ("ws_plugin__qcache_schedule_cache_dir_purge", $once, get_defined_vars ());
  44. }
  45. /*
  46. Performs an immediate purge of the cache directory.
  47. By default, this includes all blogs; and leaves locks / logs.
  48. Attach to: add_action("ws_plugin__qcache_purge_cache_dir__schedule");
  49. */
  50. public static function purge_cache_dir ($qc_c_blog = FALSE, $leave_qc_l_locks = TRUE, $leave_qc_l_logs = TRUE)
  51. {
  52. do_action ("ws_plugin__qcache_before_purge_cache_dir", get_defined_vars ());
  53. /**/
  54. clearstatcache () . define ("QUICK_CACHE_ALLOWED", false); /* Cache NOT allowed here. */
  55. /**/
  56. @set_time_limit(900) . @ini_set ("memory_limit", apply_filters ("admin_memory_limit", WP_MAX_MEMORY_LIMIT)) . @ignore_user_abort (true);
  57. /**/
  58. do_action ("ws_plugin__qcache_before_purge_cache_dir_routines", get_defined_vars ());
  59. /**/
  60. if (is_dir (WP_CONTENT_DIR . "/cache") && is_writable (WP_CONTENT_DIR . "/cache"))
  61. {
  62. $glob = "qc-c-*"; /* Default glob; all cache files. */
  63. /**/
  64. if (is_object ($blog = $qc_c_blog) && $blog->domain && $blog->path)
  65. $glob = "qc-c-*-*-" . md5 ($blog->domain . $blog->path);
  66. /**/
  67. foreach ((array)glob (WP_CONTENT_DIR . "/cache/" . $glob) as $file)
  68. if ($file && $file !== "." && $file !== ".." && is_file ($file))
  69. $error = (!is_writable ($file) || !unlink ($file)) ? true : $error;
  70. /**/
  71. if (!$leave_qc_l_locks && ($glob = "qc-l-*.lock"))
  72. foreach ((array)glob (WP_CONTENT_DIR . "/cache/" . $glob) as $file)
  73. if ($file && $file !== "." && $file !== ".." && is_file ($file))
  74. $error = (!is_writable ($file) || !unlink ($file)) ? true : $error;
  75. /**/
  76. if (!$leave_qc_l_logs && ($glob = "qc-l-*.log"))
  77. foreach ((array)glob (WP_CONTENT_DIR . "/cache/" . $glob) as $file)
  78. if ($file && $file !== "." && $file !== ".." && is_file ($file))
  79. $error = (!is_writable ($file) || !unlink ($file)) ? true : $error;
  80. /**/
  81. do_action ("ws_plugin__qcache_during_purge_cache_dir", get_defined_vars ());
  82. /**/
  83. if ($error) /* Failed, the purging routine ran into a writable error somewhere. */
  84. {
  85. return apply_filters ("ws_plugin__qcache_purge_cache_dir", false, get_defined_vars ());
  86. }
  87. else /* Completed successfully. The cache directory was purged as requested. */
  88. {
  89. return apply_filters ("ws_plugin__qcache_purge_cache_dir", true, get_defined_vars ());
  90. }
  91. }
  92. else if (is_dir (WP_CONTENT_DIR . "/cache") && !is_writable (WP_CONTENT_DIR . "/cache"))
  93. {
  94. return apply_filters ("ws_plugin__qcache_purge_cache_dir", false, get_defined_vars ());
  95. }
  96. else /* Defaults to true for deletion. */
  97. {
  98. return apply_filters ("ws_plugin__qcache_purge_cache_dir", true, get_defined_vars ());
  99. }
  100. }
  101. }
  102. }
  103. ?>