PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110710
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110710
260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 120219 All 188 releases
s2member / includes / classes / no-cache.inc.php

no-cache.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 110710, at includes/classes/no-cache.inc.php

171 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 * Handles no-cache headers and compatible constants for s2Member.
32 *
33 * This is compatible with Quick Cache and also with WP Super Cache.
34 *
35 * @package s2Member\No_Cache
36 * @since 3.5
37 *
38 * @attaches-to: ``add_action("init");``
39 *
40 * @return null
41 */
42 public static function no_cache ()
43 {
44 do_action ("ws_plugin__s2member_before_no_cache", get_defined_vars ());
45 /**/
46 c_ws_plugin__s2member_no_cache::no_cache_constants (); /* This first. */
47 c_ws_plugin__s2member_no_cache::no_cache_headers (); /* Now run headers. */
48 /**/
49 do_action ("ws_plugin__s2member_after_no_cache", get_defined_vars ());
50 /**/
51 return; /* Return for uniformity. */
52 }
53 /**
54 * Defines compatible cache constants for s2Member.
55 *
56 * This is compatible with Quick Cache and also with WP Super Cache.
57 * Quick Cache uses: ``QUICK_CACHE_ALLOWED``, and Super Cache uses: ``DONOTCACHEPAGE``.
58 * Actually, Quick Cache is compatible with either of these defined constants.
59 *
60 * Always disallow caching for logged in users and GET requests with `/?s2member` systematic use.
61 * For clarity on the systematic use with s2member in the request, see: `/classes/systematics.inc.php`.
62 * Also disallow caching if the ``$no_cache`` param is passed in as true by other routines.
63 * BUT, always obey the `qcAC` param that specifically allows caching.
64 *
65 * This function is also called upon by other routines that protect members-only content areas.
66 * Members-only content areas should never be cached. In other words, there are some important supplemental
67 * routines that occur outside the scope of this single function. This function is called upon by those other
68 * targeted routines, to handle the cache constants when they are required.
69 *
70 * @package s2Member\No_Cache
71 * @since 3.5
72 *
73 * @param bool $no_cache Optional. Defaults to false. If true, force no-cache headers if at all possible.
74 * @return null
75 *
76 * @see s2Member\URIs\c_ws_plugin__s2member_ruris::check_ruri_level_access()
77 * @see s2Member\Categories\c_ws_plugin__s2member_catgs::check_catg_level_access()
78 * @see s2Member\Tags\c_ws_plugin__s2member_ptags::check_ptag_level_access()
79 * @see s2Member\Posts\c_ws_plugin__s2member_posts::check_post_level_access()
80 * @see s2Member\Pages\c_ws_plugin__s2member_pages::check_page_level_access()
81 * @see s2Member\IP_Restrictions\c_ws_plugin__s2member_ip_restrictions::ip_restrictions_ok()
82 * @see s2Member\Files\c_ws_plugin__s2member_files::file_download_key()
83 * @see Button/Form/Shortcode Generators.
84 */
85 public static function no_cache_constants ($no_cache = FALSE)
86 {
87 static $once; /* We only need to set these Constants once. */
88 /**/
89 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
90 do_action ("ws_plugin__s2member_before_no_cache_constants", get_defined_vars ());
91 unset ($__refs, $__v); /* Unset defined __refs, __v. */
92 /**/
93 if (!$once && empty ($_GET["qcAC"]) && ($no_cache || is_user_logged_in () || (!empty ($_SERVER["QUERY_STRING"]) && strpos ($_SERVER["QUERY_STRING"], "s2member") === 0 && c_ws_plugin__s2member_utils_conds::is_site_root ($_SERVER["REQUEST_URI"]))))
94 {
95 /**
96 * No-cache Constant for Quick Cache.
97 *
98 * @package s2Member\No_Cache
99 * @since 3.5
100 *
101 * @var bool
102 */
103 if (!defined ("QUICK_CACHE_ALLOWED"))
104 define ("QUICK_CACHE_ALLOWED", false);
105 /**
106 * No-cache for other cache plugins.
107 *
108 * @package s2Member\No_Cache
109 * @since 3.5
110 *
111 * @var bool
112 */
113 if (!defined ("DONOTCACHEPAGE"))
114 define ("DONOTCACHEPAGE", true);
115 /**/
116 $GLOBALS["ws_plugin__s2member_no_cache_headers_selective"] = true;
117 /**/
118 $once = true; /* Only need to set these Constants one time. */
119 /**/
120 do_action ("ws_plugin__s2member_during_no_cache_constants", get_defined_vars ());
121 }
122 /**/
123 do_action ("ws_plugin__s2member_after_no_cache_constants", get_defined_vars ());
124 /**/
125 return; /* Return for uniformity. */
126 }
127 /**
128 * Sends Cache-Control ( no-cache ) headers.
129 *
130 * This uses the ``nocache_headers()`` function provided by WordPress®.
131 * This is compatible with the Quick Cache parameter `?qcABC=1` as well.
132 * Always obey the `qcABC` param that specifically allows browser caching.
133 *
134 * @package s2Member\No_Cache
135 * @since 3.5
136 *
137 * @return null
138 */
139 public static function no_cache_headers ()
140 {
141 static $once; /* We only need to set these headers one time. */
142 /**/
143 eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
144 do_action ("ws_plugin__s2member_before_no_cache_headers", get_defined_vars ());
145 unset ($__refs, $__v); /* Unset defined __refs, __v. */
146 /**/
147 $using_selective_behavior = apply_filters ("ws_plugin__s2member_no_cache_headers_selective", false, get_defined_vars ());
148 $selective = @$GLOBALS["ws_plugin__s2member_no_cache_headers_selective"]; /* Selective ( i.e. required ) ? */
149 /**/
150 if (!$once && empty ($_GET["qcABC"]) && (!$using_selective_behavior || $selective) && !apply_filters ("ws_plugin__s2member_disable_no_cache_headers", false, get_defined_vars ()))
151 {
152 if (is_array ($headers = headers_list ()))
153 foreach ($headers as $header) /* Already? */
154 if (stripos ($header, "no-cache") !== false)
155 $no_cache_already_sent = true;
156 /**/
157 if (!$no_cache_already_sent)
158 nocache_headers ();
159 /**/
160 $once = true; /* Only need to set these headers once. */
161 /**/
162 do_action ("ws_plugin__s2member_during_no_cache_headers", get_defined_vars ());
163 }
164 /**/
165 do_action ("ws_plugin__s2member_after_no_cache_headers", get_defined_vars ());
166 /**/
167 return; /* Return for uniformity. */
168 }
169 }
170 }
171 ?>