| 1 |
<?php |
| 2 |
// @codingStandardsIgnoreFile |
| 3 |
/** |
| 4 |
* Membership Options Page (inner processing routines). |
| 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\Membership_Options_Page |
| 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_mo_page_in")) |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Membership Options Page (inner processing routines). |
| 25 |
* |
| 26 |
* @package s2Member\Membership_Options_Page |
| 27 |
* @since 3.5 |
| 28 |
*/ |
| 29 |
class c_ws_plugin__s2member_mo_page_in |
| 30 |
{ |
| 31 |
/** |
| 32 |
* Forces a redirection to the Membership Options Page for s2Member. |
| 33 |
* |
| 34 |
* This can be used by 3rd party apps that are not aware of which Page is currently set as the Membership Options Page. |
| 35 |
* Example usage: `http://example.com/?s2member_membership_options_page=1` |
| 36 |
* |
| 37 |
* Redirection URLs containing array brackets MUST be URL encoded to get through: ``wp_sanitize_redirect()``. |
| 38 |
* So we pass everything to ``urlencode_deep()``, as an array. It handles this via ``_http_build_query()``. |
| 39 |
* See bug report here: {@link http://core.trac.wordpress.org/ticket/17052} |
| 40 |
* |
| 41 |
* @package s2Member\Membership_Options_Page |
| 42 |
* @since 3.5 |
| 43 |
* |
| 44 |
* @attaches-to ``add_action("init");`` |
| 45 |
* |
| 46 |
* @return null Or exits script execution after redirection w/ `301` status. |
| 47 |
*/ |
| 48 |
public static function membership_options_page() // Real Membership Options Page. |
| 49 |
{ |
| 50 |
do_action("ws_plugin__s2member_before_membership_options_page", get_defined_vars()); |
| 51 |
|
| 52 |
if(!empty($_GET["s2member_membership_options_page"]) && is_array($_g = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_GET)))) |
| 53 |
{ |
| 54 |
$args = array(); // Initialize this to an empty array value. |
| 55 |
|
| 56 |
foreach($_g as $var => $value) // Include all of the `_?s2member_` variables. |
| 57 |
// Do NOT include `s2member_membership_options_page`; creates a redirection loop. |
| 58 |
if(preg_match("/^_?s2member_/", $var) && $var !== "s2member_membership_options_page") |
| 59 |
$args[$var] = $value; // Supports nested arrays. |
| 60 |
|
| 61 |
wp_redirect(add_query_arg(urlencode_deep($args), get_page_link($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), 301).exit (); |
| 62 |
} |
| 63 |
do_action("ws_plugin__s2member_after_membership_options_page", get_defined_vars()); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Redirects to Membership Options Page w/ MOP Vars. |
| 68 |
* |
| 69 |
* Redirection URLs containing array brackets MUST be URL encoded to get through: ``wp_sanitize_redirect()``. |
| 70 |
* So we pass everything to ``urlencode_deep()``, as an array. It handles this via ``_http_build_query()``. |
| 71 |
* See bug report here: {@link http://core.trac.wordpress.org/ticket/17052} |
| 72 |
* |
| 73 |
* @package s2Member\Membership_Options_Page |
| 74 |
* @since 111101 |
| 75 |
* |
| 76 |
* @param string $seeking_type Seeking content type. One of: `post|page|catg|ptag|file|ruri`. |
| 77 |
* @param string|int $seeking_type_value Seeking content type data. String, or a Post/Page ID. |
| 78 |
* @param string $req_type Access requirement type. One of these values: `level|ccap|sp`. |
| 79 |
* @param string|int $req_type_value Access requirement. String, or a Post/Page ID. |
| 80 |
* @param string $seeking_uri The full URI that access was attempted on. |
| 81 |
* @param string $res_type Restriction type that's preventing access. |
| 82 |
* One of: `post|page|catg|ptag|file|ruri|ccap|sp|sys`. |
| 83 |
* Defaults to ``$seeking_type``. |
| 84 |
* |
| 85 |
* @return bool This function always returns true. |
| 86 |
*/ |
| 87 |
public static function wp_redirect_w_mop_vars($seeking_type = FALSE, $seeking_type_value = FALSE, $req_type = FALSE, $req_type_value = FALSE, $seeking_uri = FALSE, $res_type = FALSE) |
| 88 |
{ |
| 89 |
do_action("ws_plugin__s2member_before_wp_redirect_w_mop_vars", get_defined_vars()); |
| 90 |
|
| 91 |
foreach(array("seeking_type", "seeking_type_value", "req_type", "req_type_value", "seeking_uri", "res_type") as $_param) |
| 92 |
{ |
| 93 |
if($_param === "seeking_uri" || ($_param === "seeking_type_value" && $seeking_type === "ruri")) |
| 94 |
${$_param} = base64_encode((string)${$_param}); |
| 95 |
else ${$_param} = str_replace("..", "--", (string)${$_param}); |
| 96 |
} |
| 97 |
unset($_param); // Housekeeping. |
| 98 |
|
| 99 |
if(!$res_type) $res_type = $seeking_type; |
| 100 |
|
| 101 |
$vars = $res_type."..".$req_type."..".$req_type_value.".."; |
| 102 |
$vars .= $seeking_type."..".$seeking_type_value."..".$seeking_uri; |
| 103 |
$vars = array("_s2member_vars" => $vars); |
| 104 |
|
| 105 |
$status = apply_filters("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars()); |
| 106 |
$status = apply_filters("ws_plugin__s2member_wp_redirect_w_mop_vars_status", $status, get_defined_vars()); |
| 107 |
|
| 108 |
$mop_url = get_page_link($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"]); |
| 109 |
if($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page_vars_enable"]) |
| 110 |
{ |
| 111 |
$mop_url = add_query_arg(urlencode_deep($vars), $mop_url); |
| 112 |
$mop_url = c_ws_plugin__s2member_utils_urls::add_s2member_sig($mop_url); |
| 113 |
} |
| 114 |
if(!empty($_GET) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page_ga_vars_enable"]) |
| 115 |
{ |
| 116 |
$ga_vars = array(); // Initialize. |
| 117 |
|
| 118 |
foreach(stripslashes_deep($_GET) as $_key => $_value) |
| 119 |
if(strpos($_key, 'utm_') === 0) $ga_vars[$_key] = $_value; |
| 120 |
unset($_key, $_value); // Housekeeping. |
| 121 |
|
| 122 |
$mop_url = add_query_arg(urlencode_deep($ga_vars), $mop_url); |
| 123 |
} |
| 124 |
wp_redirect($mop_url, $status); // NOTE: we do not exit here (on purpose). |
| 125 |
|
| 126 |
do_action("ws_plugin__s2member_after_wp_redirect_w_mop_vars", get_defined_vars()); |
| 127 |
|
| 128 |
return TRUE; // Always returns true here. |
| 129 |
} |
| 130 |
|
| 131 |
/* |
| 132 |
* s2Member's MOP Vars are now a double-dot (`..`) delimited list of six values. |
| 133 |
* |
| 134 |
* e.g., .../membership-options-page/ |
| 135 |
* ?_s2member_vars=[restriction type]..[requirement type]..[requirement type value].. |
| 136 |
* [seeking type]..[seeking type value]..[seeking URI base 64 encoded] |
| 137 |
*/ |
| 138 |
public static function back_compat_mop_vars() |
| 139 |
{ |
| 140 |
if(empty($_REQUEST["_s2member_vars"]) |
| 141 |
|| !is_string($_REQUEST["_s2member_vars"]) |
| 142 |
) return; |
| 143 |
|
| 144 |
$v = explode("..", $_REQUEST["_s2member_vars"]); |
| 145 |
if(count($v) !== 6) return; |
| 146 |
|
| 147 |
/* |
| 148 |
* Back compat. Deprecated since v1404xx. |
| 149 |
*/ |
| 150 |
$ov["_s2member_seeking"] = array( |
| 151 |
"type" => $v[3], |
| 152 |
$v[3] => $v[4], |
| 153 |
"_uri" => $v[5] |
| 154 |
); |
| 155 |
$ov["_s2member_req"] = array( |
| 156 |
"type" => $v[1], |
| 157 |
$v[1] => $v[2], |
| 158 |
); |
| 159 |
$ov["_s2member_res"]["type"] = $v[0]; |
| 160 |
|
| 161 |
/* |
| 162 |
* Back compat. Deprecated since v1104xx. |
| 163 |
*/ |
| 164 |
$ov["s2member_seeking"] = $v[3]."-".$v[4]; |
| 165 |
$ov["s2member_".$v[1]."_req"] = $v[2]; |
| 166 |
|
| 167 |
/* |
| 168 |
* Fill both $_GET and $_REQUEST vars. |
| 169 |
*/ |
| 170 |
foreach($ov as $_k => $_v) |
| 171 |
$_GET[$_k] = $_REQUEST[$_k] = $_v; |
| 172 |
unset($_k, $_v); |
| 173 |
} |
| 174 |
} |
| 175 |
} |
| 176 |
|