Source Code Documentation


s2member\includes\classes\no-cache.inc.php


  1. <?php
  2. /**
  3. * No-cache routines.
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * (coded in the USA)
  8. *
  9. * Released under the terms of the GNU General Public License.
  10. * You should have received a copy of the GNU General Public License,
  11. * along with this software. In the main directory, see: /licensing/
  12. * If not, see: {@link http://www.gnu.org/licenses/}.
  13. *
  14. * @package s2Member\No_Cache
  15. * @since 3.5
  16. */
  17. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  18. exit ("Do not access this file directly.");
  19.  
  20. if (!class_exists ("c_ws_plugin__s2member_no_cache"))
  21. {
  22. /**
  23. * No-cache routines.
  24. *
  25. * @package s2Member\No_Cache
  26. * @since 3.5
  27. */
  28. class c_ws_plugin__s2member_no_cache
  29. {
  30. /**
  31. * No-cache headers required?
  32. *
  33. * @package s2Member\No_Cache
  34. * @since 111115
  35. *
  36. * @var null|bool
  37. */
  38. public static $headers;
  39. /**
  40. * Handles no-cache constants, and no-cache headers.
  41. *
  42. * @package s2Member\No_Cache
  43. * @since 3.5
  44. *
  45. * @attaches-to ``add_action("init");``
  46. * @also-called-by Other routines within s2Member.
  47. *
  48. * @param bool $no_cache Optional. Defaults to false. If true, force no-cache if at all possible.
  49. * @return bool This function will always return `true`.
  50. */
  51. public static function no_cache ($no_cache = FALSE)
  52. {
  53. do_action ("ws_plugin__s2member_before_no_cache", get_defined_vars ());
  54.  
  55. c_ws_plugin__s2member_no_cache::no_cache_constants ($no_cache) . c_ws_plugin__s2member_no_cache::no_cache_headers ($no_cache);
  56.  
  57. do_action ("ws_plugin__s2member_after_no_cache", get_defined_vars ());
  58.  
  59. return true; // Always return true.
  60. }
  61. /**
  62. * Defines no-cache constants for various WordPress® plugins.
  63. *
  64. * This is compatible with Quick Cache, W3 Total Cache, and also with WP Super Cache.
  65. * Quick Cache uses: ``QUICK_CACHE_ALLOWED``, and other plugins use: ``DONOTCACHEPAGE``.
  66. * W3 Total Cache is also known to be compatible with ``DONOTCACHEOBJECT`` and ``DONOTCACHEDB``.
  67. *
  68. * Disallow caching if the ``$no_cache`` parameter is passed in as ``true``, by other routines.
  69. * In addition, always disallow caching for logged in users, and GET requests with: `/?s2member` Systematics.
  70. * For clarity on s2Member Systematics, see: {@link s2Member\Systematics\c_ws_plugin__s2member_systematics::is_s2_systematic_use_page()}.
  71. *
  72. * However, this routine will ALWAYS obey the `?qcAC` query string parameter.
  73. * This Quick Cache parameter explicitly allows caching to occur.
  74. *
  75. * @package s2Member\No_Cache
  76. * @since 3.5
  77. *
  78. * @also-called-by Other routines within s2Member.
  79. *
  80. * @param bool $no_cache Optional. Defaults to false. If true, force no-cache if at all possible.
  81. * @return bool This function will always return `true`.
  82. */
  83. public static function no_cache_constants ($no_cache = FALSE)
  84. {
  85. static $once; // We only need to set these constants once.
  86.  
  87. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  88. do_action ("ws_plugin__s2member_before_no_cache_constants", get_defined_vars ());
  89. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  90.  
  91. if (!$once && empty ($_GET["qcAC"]) && ($no_cache || is_user_logged_in () || c_ws_plugin__s2member_systematics::is_s2_systematic_use_page ()))
  92. {
  93. /**
  94. * No-cache DB queries for plugins.
  95. *
  96. * @package s2Member\No_Cache
  97. * @since 111115
  98. *
  99. * @var bool
  100. */
  101. if (!defined ("DONOTCACHEDB"))
  102. define ("DONOTCACHEDB", true);
  103. /**
  104. * No-cache Page for plugins.
  105. *
  106. * @package s2Member\No_Cache
  107. * @since 3.5
  108. *
  109. * @var bool
  110. */
  111. if (!defined ("DONOTCACHEPAGE"))
  112. define ("DONOTCACHEPAGE", true);
  113. /**
  114. * No-cache Objects for plugins.
  115. *
  116. * @package s2Member\No_Cache
  117. * @since 111115
  118. *
  119. * @var bool
  120. */
  121. if (!defined ("DONOTCACHEOBJECT"))
  122. define ("DONOTCACHEOBJECT", true);
  123. /**
  124. * No-cache anything for Quick Cache plugin.
  125. *
  126. * @package s2Member\No_Cache
  127. * @since 3.5
  128. *
  129. * @var bool
  130. */
  131. if (!defined ("QUICK_CACHE_ALLOWED"))
  132. define ("QUICK_CACHE_ALLOWED", false);
  133.  
  134. $once = true; // Only need to set these constants one time.
  135.  
  136. c_ws_plugin__s2member_no_cache::$headers = /* Headers required too. */ true;
  137.  
  138. do_action ("ws_plugin__s2member_during_no_cache_constants", get_defined_vars ());
  139. }
  140.  
  141. do_action ("ws_plugin__s2member_after_no_cache_constants", get_defined_vars ());
  142.  
  143. return true; // Always return true.
  144. }
  145. /**
  146. * Sends Cache-Control (no-cache) headers.
  147. *
  148. * Disallow browser caching if the ``$no_cache`` parameter is passed in as ``true``, by other routines.
  149. * Disallow browser caching when/if no-cache Constants are set by {@link s2Member\No_Cache\c_ws_plugin__s2member_no_cache::no_cache_constants()},
  150. * via static variable boolean value for: ``c_ws_plugin__s2member_no_cache::$headers``.
  151. *
  152. * However, this routine will ALWAYS obey the `?qcABC` query string parameter.
  153. * This Quick Cache parameter explicitly allows browser caching to occur.
  154. *
  155. * @package s2Member\No_Cache
  156. * @since 3.5
  157. *
  158. * @also-called-by Other routines within s2Member.
  159. *
  160. * @param bool $no_cache Optional. Defaults to false. If true, force no-cache if at all possible.
  161. * @return bool This function will always return `true`.
  162. */
  163. public static function no_cache_headers ($no_cache = FALSE)
  164. {
  165. static $once; // We only need to set these headers one time.
  166.  
  167. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  168. do_action ("ws_plugin__s2member_before_no_cache_headers", get_defined_vars ());
  169. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  170.  
  171. $using_selective_behavior = /* Off by default. */ apply_filters ("ws_plugin__s2member_no_cache_headers_selective", false, get_defined_vars ());
  172.  
  173. if (!$once && !headers_sent () && empty ($_GET["qcABC"]) && ($no_cache || !$using_selective_behavior || c_ws_plugin__s2member_no_cache::$headers))
  174. if ( /* Give Filters a chance. */!apply_filters ("ws_plugin__s2member_disable_no_cache_headers", false, get_defined_vars ()))
  175. {
  176. foreach (headers_list () as $header) // No-cache headers already sent? We need to check here.
  177. if (stripos ($header, "no-cache") !== false) // No-cache headers already sent?
  178. {
  179. $no_cache_headers_already_sent = true; // Yep, sent.
  180. break; // Break now, no need to continue further.
  181. }
  182. if (!isset ($no_cache_headers_already_sent)) // Not yet?
  183. nocache_headers (); // Only if NOT already sent.
  184.  
  185. $once = true; // This is static var. Only send headers once.
  186.  
  187. do_action ("ws_plugin__s2member_during_no_cache_headers", get_defined_vars ());
  188. }
  189.  
  190. do_action ("ws_plugin__s2member_after_no_cache_headers", get_defined_vars ());
  191.  
  192. return true; // Always return true.
  193. }
  194. }
  195. }
  196. ?>

s2member\includes\classes\no-cache.inc.php

Source Code Documentation