| 1 |
<?php |
| 2 |
/** |
| 3 |
* s2Member's Post protection routines *( for current Post )*. |
| 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\Posts |
| 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_posts")) |
| 21 |
{ |
| 22 |
/** |
| 23 |
* s2Member's Post protection routines *( for current Post )*. |
| 24 |
* |
| 25 |
* @package s2Member\Posts |
| 26 |
* @since 3.5 |
| 27 |
*/ |
| 28 |
class c_ws_plugin__s2member_posts |
| 29 |
{ |
| 30 |
/** |
| 31 |
* Handles Post Level Access permissions *( for current Post )*. |
| 32 |
* |
| 33 |
* @package s2Member\Posts |
| 34 |
* @since 3.5 |
| 35 |
* |
| 36 |
* @return null Or exits script execution after redirection. |
| 37 |
*/ |
| 38 |
public static function check_post_level_access () |
| 39 |
{ |
| 40 |
global $post; /* get_the_ID() unavailable outside The Loop. */ |
| 41 |
/**/ |
| 42 |
do_action ("ws_plugin__s2member_before_check_post_level_access", get_defined_vars ()); |
| 43 |
/**/ |
| 44 |
$excluded = apply_filters ("ws_plugin__s2member_check_post_level_access_excluded", false, get_defined_vars ()); |
| 45 |
/**/ |
| 46 |
if (!$excluded && is_single () && is_object ($post) && ($post_id = $post->ID) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]) |
| 47 |
{ |
| 48 |
$user = (is_user_logged_in ()) ? wp_get_current_user () : false; /* Get the current User's object. */ |
| 49 |
/**/ |
| 50 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_redirection_override"] && ($login_redirection_uri = c_ws_plugin__s2member_login_redirects::login_redirection_uri ($user, "root-returns-false")) && preg_match ("/^" . preg_quote ($login_redirection_uri, "/") . "$/", $_SERVER["REQUEST_URI"]) && c_ws_plugin__s2member_no_cache::no_cache_constants (true) !== "nill" && (!$user || !current_user_can ("access_s2member_level0"))) |
| 51 |
{ |
| 52 |
wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "post-" . $post_id, "s2member_level_req" => "0")), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())); |
| 53 |
exit (); |
| 54 |
} |
| 55 |
else if (!c_ws_plugin__s2member_systematics::is_systematic_use_page ()) /* Do NOT protect Systematics. However, there is 1 exception ^. */ |
| 56 |
{ |
| 57 |
for ($n = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n >= 0; $n--) /* Post Level restrictions ( including Custom Post Types ). Go through each Level. */ |
| 58 |
{ |
| 59 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_posts"] === "all" && c_ws_plugin__s2member_no_cache::no_cache_constants (true) !== "nill" && (!$user || !current_user_can ("access_s2member_level" . $n))) |
| 60 |
{ |
| 61 |
wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "post-" . $post_id, "s2member_level_req" => $n)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())); |
| 62 |
exit (); |
| 63 |
} |
| 64 |
/**/ |
| 65 |
else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_posts"] && in_array ($post_id, preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_posts"])) && c_ws_plugin__s2member_no_cache::no_cache_constants (true) !== "nill" && (!$user || !current_user_can ("access_s2member_level" . $n))) |
| 66 |
{ |
| 67 |
wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "post-" . $post_id, "s2member_level_req" => $n)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())); |
| 68 |
exit (); |
| 69 |
} |
| 70 |
} |
| 71 |
/**/ |
| 72 |
for ($n = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n >= 0; $n--) /* Category Level restrictions. Go through each Level. */ |
| 73 |
{ |
| 74 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"] === "all" && c_ws_plugin__s2member_no_cache::no_cache_constants (true) !== "nill" && (!$user || !current_user_can ("access_s2member_level" . $n))) |
| 75 |
{ |
| 76 |
wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "post-" . $post_id, "s2member_level_req" => $n)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())); |
| 77 |
exit (); |
| 78 |
} |
| 79 |
/**/ |
| 80 |
else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"] && (in_category (($catgs = preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"])), $post_id) || c_ws_plugin__s2member_utils_conds::in_descendant_category ($catgs, $post_id)) && c_ws_plugin__s2member_no_cache::no_cache_constants (true) !== "nill" && (!$user || !current_user_can ("access_s2member_level" . $n))) |
| 81 |
{ |
| 82 |
wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "post-" . $post_id, "s2member_level_req" => $n)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())); |
| 83 |
exit (); |
| 84 |
} |
| 85 |
} |
| 86 |
/**/ |
| 87 |
if (has_tag ()) /* Here we take a look to see if this Post has any Tags. If so, we need to run the full set of routines against Tags also. */ |
| 88 |
{ |
| 89 |
for ($n = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n >= 0; $n--) /* Tag Level restrictions. Go through each Level. */ |
| 90 |
{ |
| 91 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_ptags"] === "all" && c_ws_plugin__s2member_no_cache::no_cache_constants (true) !== "nill" && (!$user || !current_user_can ("access_s2member_level" . $n))) |
| 92 |
{ |
| 93 |
wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "post-" . $post_id, "s2member_level_req" => $n)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())); |
| 94 |
exit (); |
| 95 |
} |
| 96 |
/**/ |
| 97 |
else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_ptags"] && has_tag (preg_split ("/[\r\n\t;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_ptags"])) && c_ws_plugin__s2member_no_cache::no_cache_constants (true) !== "nill" && (!$user || !current_user_can ("access_s2member_level" . $n))) |
| 98 |
{ |
| 99 |
wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "post-" . $post_id, "s2member_level_req" => $n)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())); |
| 100 |
exit (); |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
/**/ |
| 105 |
for ($n = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n >= 0; $n--) /* URIs. Go through each Level. */ |
| 106 |
{ |
| 107 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_ruris"]) |
| 108 |
foreach (preg_split ("/[\r\n\t]+/", c_ws_plugin__s2member_ruris::fill_ruri_level_access_rc_vars ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_ruris"], $user)) as $str) |
| 109 |
if ($str && preg_match ("/" . preg_quote ($str, "/") . "/", $_SERVER["REQUEST_URI"]) && c_ws_plugin__s2member_no_cache::no_cache_constants (true) !== "nill" && (!$user || !current_user_can ("access_s2member_level" . $n))) |
| 110 |
{ |
| 111 |
wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "post-" . $post_id, "s2member_level_req" => $n)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())); |
| 112 |
exit (); |
| 113 |
} |
| 114 |
} |
| 115 |
/**/ |
| 116 |
if (is_array ($ccaps_req = get_post_meta ($post_id, "s2member_ccaps_req", true)) && !empty ($ccaps_req) && c_ws_plugin__s2member_no_cache::no_cache_constants (true) !== "nill") |
| 117 |
foreach ($ccaps_req as $ccap) /* The $user MUST satisfy ALL Custom Capability requirements. Stored as a serialized array. */ |
| 118 |
if (strlen ($ccap) && (!$user || !$user->has_cap ("access_s2member_ccap_" . $ccap))) |
| 119 |
{ |
| 120 |
wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "post-" . $post_id, "s2member_ccap_req" => $ccap)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())); |
| 121 |
exit (); |
| 122 |
} |
| 123 |
/**/ |
| 124 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["specific_ids"] && in_array ($post_id, preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["specific_ids"])) && c_ws_plugin__s2member_no_cache::no_cache_constants (true) !== "nill" && !c_ws_plugin__s2member_sp_access::sp_access ($post_id)) |
| 125 |
{ |
| 126 |
wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "post-" . $post_id, "s2member_sp_req" => $post_id)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())); |
| 127 |
exit (); |
| 128 |
} |
| 129 |
} |
| 130 |
/**/ |
| 131 |
do_action ("ws_plugin__s2member_during_check_post_level_access", get_defined_vars ()); |
| 132 |
} |
| 133 |
/**/ |
| 134 |
do_action ("ws_plugin__s2member_after_check_post_level_access", get_defined_vars ()); |
| 135 |
/**/ |
| 136 |
return; /* For uniformity. */ |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
?> |