| 1 |
<?php |
| 2 |
// @codingStandardsIgnoreFile |
| 3 |
/** |
| 4 |
* s2Member's Category protection routines *(for current page)*. |
| 5 |
* |
| 6 |
* Copyright: © 2009-2011 |
| 7 |
* {@link http://websharks-inc.com/ WebSharks, Inc.} |
| 8 |
* (coded in the USA) |
| 9 |
* |
| 10 |
* Released under the terms of the GNU General Public License. |
| 11 |
* You should have received a copy of the GNU General Public License, |
| 12 |
* along with this software. In the main directory, see: /licensing/ |
| 13 |
* If not, see: {@link http://www.gnu.org/licenses/}. |
| 14 |
* |
| 15 |
* @package s2Member\Categories |
| 16 |
* @since 3.5 |
| 17 |
*/ |
| 18 |
if(!defined('WPINC')) // MUST have WordPress. |
| 19 |
exit('Do not access this file directly.'); |
| 20 |
|
| 21 |
if(!class_exists('c_ws_plugin__s2member_catgs')) |
| 22 |
{ |
| 23 |
/** |
| 24 |
* s2Member's Category protection routines *(for current page)*. |
| 25 |
* |
| 26 |
* @package s2Member\Categories |
| 27 |
* @since 3.5 |
| 28 |
*/ |
| 29 |
class c_ws_plugin__s2member_catgs |
| 30 |
{ |
| 31 |
/** |
| 32 |
* Handles Category Level Access *(for current page)*. |
| 33 |
* |
| 34 |
* @package s2Member\Categories |
| 35 |
* @since 3.5 |
| 36 |
* |
| 37 |
* @return null Or exits script execution after redirection. |
| 38 |
*/ |
| 39 |
public static function check_catg_level_access() |
| 40 |
{ |
| 41 |
global $post; // ``get_the_ID()`` is NOT available outside The Loop. |
| 42 |
|
| 43 |
do_action('ws_plugin__s2member_before_check_catg_level_access', get_defined_vars()); |
| 44 |
|
| 45 |
$ci = $GLOBALS['WS_PLUGIN__']['s2member']['o']['ruris_case_sensitive'] ? '' : 'i'; |
| 46 |
$excluded = apply_filters('ws_plugin__s2member_check_catg_level_access_excluded', FALSE, get_defined_vars()); |
| 47 |
|
| 48 |
if(!$excluded && is_category() && ($cat_id = get_query_var('cat')) && ($cat_id = (int)$cat_id) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['membership_options_page']) |
| 49 |
{ |
| 50 |
if(!c_ws_plugin__s2member_systematics::is_wp_systematic_use_page()) |
| 51 |
{ |
| 52 |
$user = (is_user_logged_in() && is_object($user = wp_get_current_user()) && !empty($user->ID)) ? $user : FALSE; |
| 53 |
|
| 54 |
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, '/').'$/'.$ci, $_SERVER['REQUEST_URI']) && c_ws_plugin__s2member_no_cache::no_cache_constants('restricted') && (!$user || !$user->has_cap('access_s2member_level0'))) |
| 55 |
c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars('catg', $cat_id, 'level', 0, $_SERVER['REQUEST_URI'], 'sys').exit (); |
| 56 |
|
| 57 |
else if(!c_ws_plugin__s2member_systematics::is_systematic_use_page()) |
| 58 |
{ |
| 59 |
for($n = $GLOBALS['WS_PLUGIN__']['s2member']['c']['levels']; $n >= 0; $n--) |
| 60 |
{ |
| 61 |
if($GLOBALS['WS_PLUGIN__']['s2member']['o']['level'.$n.'_catgs'] === 'all' && c_ws_plugin__s2member_no_cache::no_cache_constants('restricted') && (!$user || !$user->has_cap('access_s2member_level'.$n))) |
| 62 |
c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars('catg', $cat_id, 'level', $n, $_SERVER['REQUEST_URI']).exit (); |
| 63 |
|
| 64 |
else if($GLOBALS['WS_PLUGIN__']['s2member']['o']['level'.$n.'_catgs'] && in_array($cat_id, ($catgs = preg_split('/['."\r\n\t".'\s;,]+/', $GLOBALS['WS_PLUGIN__']['s2member']['o']['level'.$n.'_catgs']))) && c_ws_plugin__s2member_no_cache::no_cache_constants('restricted') && (!$user || !$user->has_cap('access_s2member_level'.$n))) |
| 65 |
c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars('catg', $cat_id, 'level', $n, $_SERVER['REQUEST_URI']).exit (); |
| 66 |
|
| 67 |
else if($GLOBALS['WS_PLUGIN__']['s2member']['o']['level'.$n.'_catgs'] /* Check Category ancestry. */) |
| 68 |
foreach(preg_split('/['."\r\n\t".'\s;,]+/', $GLOBALS['WS_PLUGIN__']['s2member']['o']['level'.$n.'_catgs']) as $catg) |
| 69 |
if($catg && cat_is_ancestor_of($catg, $cat_id) && c_ws_plugin__s2member_no_cache::no_cache_constants('restricted') && (!$user || !$user->has_cap('access_s2member_level'.$n))) |
| 70 |
c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars('catg', $cat_id, 'level', $n, $_SERVER['REQUEST_URI']).exit (); |
| 71 |
} |
| 72 |
for($n = $GLOBALS['WS_PLUGIN__']['s2member']['c']['levels']; $n >= 0; $n--) |
| 73 |
{ |
| 74 |
if($GLOBALS['WS_PLUGIN__']['s2member']['o']['level'.$n.'_ruris']) |
| 75 |
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) |
| 76 |
if($str && preg_match('/'.preg_quote($str, '/').'/'.$ci, $_SERVER['REQUEST_URI']) && c_ws_plugin__s2member_no_cache::no_cache_constants('restricted') && (!$user || !$user->has_cap('access_s2member_level'.$n))) |
| 77 |
c_ws_plugin__s2member_mo_page::wp_redirect_w_mop_vars('catg', $cat_id, 'level', $n, $_SERVER['REQUEST_URI'], 'ruri').exit (); |
| 78 |
} |
| 79 |
} |
| 80 |
do_action('ws_plugin__s2member_during_check_catg_level_access', get_defined_vars()); |
| 81 |
} |
| 82 |
} |
| 83 |
do_action('ws_plugin__s2member_after_check_catg_level_access', get_defined_vars()); |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|