PageRenderTime 23ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/s2member/includes/classes/ruris-sp.inc.php

https://gitlab.com/Gashler/sg
PHP | 75 lines | 37 code | 6 blank | 32 comment | 26 complexity | d257612aa3221f9f9371eef048575160 MD5 | raw file
  1. <?php
  2. /**
  3. * s2Member's URI protection routines *(for specific URIs)*.
  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\URIs
  15. * @since 3.5
  16. */
  17. if(!defined('WPINC')) // MUST have WordPress.
  18. exit('Do not access this file directly.');
  19. if(!class_exists('c_ws_plugin__s2member_ruris_sp'))
  20. {
  21. /**
  22. * s2Member's URI protection routines *(for specific URIs)*.
  23. *
  24. * @package s2Member\URIs
  25. * @since 3.5
  26. */
  27. class c_ws_plugin__s2member_ruris_sp
  28. {
  29. /**
  30. * Handles URI Level Access *(for specific URIs)*.
  31. *
  32. * @package s2Member\URIs
  33. * @since 3.5
  34. *
  35. * @param string $uri A URI, or a full URL is also fine.
  36. * @param bool $check_user Test permissions against the current User? Defaults to true.
  37. *
  38. * @return null|array Non-empty array(with details) if access is denied, else null if access is allowed.
  39. */
  40. public static function check_specific_ruri_level_access($uri = '', $check_user = TRUE)
  41. {
  42. do_action('ws_plugin__s2member_before_check_specific_ruri_level_access', get_defined_vars());
  43. $ci = $GLOBALS['WS_PLUGIN__']['s2member']['o']['ruris_case_sensitive'] ? '' : 'i';
  44. $uri = ($uri && is_string($uri) && ($uri = c_ws_plugin__s2member_utils_urls::parse_uri($uri))) ? $uri : FALSE;
  45. $excluded = apply_filters('ws_plugin__s2member_check_specific_ruri_level_access_excluded', FALSE, get_defined_vars());
  46. if(!$excluded && !empty($uri) && is_string($uri) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['membership_options_page'])
  47. {
  48. if(!c_ws_plugin__s2member_systematics_sp::is_wp_systematic_use_specific_page(NULL, $uri)) // Do NOT touch WordPress Systematics.
  49. {
  50. $user = (is_user_logged_in() && is_object($user = wp_get_current_user()) && !empty($user->ID)) ? $user : FALSE; // Current User's object.
  51. 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, $uri) && (!$check_user || !$user || !$user->has_cap('access_s2member_level0')))
  52. return apply_filters('ws_plugin__s2member_check_specific_ruri_level_access', array('s2member_level_req' => 0), get_defined_vars());
  53. else if(!c_ws_plugin__s2member_systematics_sp::is_systematic_use_specific_page(NULL, $uri)) // Never restrict Systematics. However, there is 1 exception above.
  54. {
  55. for($n = $GLOBALS['WS_PLUGIN__']['s2member']['c']['levels']; $n >= 0; $n--) // URIs. Go through each Level.
  56. {
  57. if($GLOBALS['WS_PLUGIN__']['s2member']['o']['level'.$n.'_ruris']) // URIs configured at this Level?
  58. 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)
  59. if($str && preg_match('/'.preg_quote($str, '/').'/'.$ci, $uri) && (!$check_user || !$user || !$user->has_cap('access_s2member_level'.$n)))
  60. return apply_filters('ws_plugin__s2member_check_specific_ruri_level_access', array('s2member_level_req' => $n), get_defined_vars());
  61. }
  62. }
  63. do_action('ws_plugin__s2member_during_check_specific_ruri_level_access', get_defined_vars());
  64. }
  65. }
  66. return apply_filters('ws_plugin__s2member_check_specific_ruri_level_access', NULL, get_defined_vars());
  67. }
  68. }
  69. }