s2Member Framework (Member Roles, Capabilities, Membership, PayPal Members) - Version 110926

Version Description

Download this release

Release Info

Developer PriMoThemes
Plugin Icon 128x128 s2Member Framework (Member Roles, Capabilities, Membership, PayPal Members)
Version 110926
Comparing to
See all releases

Code changes from version 110915 to 110926

Files changed (53) hide show
  1. images/jwplayer-logo.png +0 -0
  2. includes/_xtnls/mailchimp/nc-mcapi.inc.php +32 -92
  3. includes/classes/admin-lockouts.inc.php +14 -13
  4. includes/classes/auto-eots.inc.php +6 -3
  5. includes/classes/cache.inc.php +22 -22
  6. includes/classes/custom-reg-fields-4bp.inc.php +22 -20
  7. includes/classes/email-configs.inc.php +16 -13
  8. includes/classes/files-in.inc.php +1190 -197
  9. includes/classes/files.inc.php +60 -20
  10. includes/classes/list-servers.inc.php +2 -2
  11. includes/classes/login-redirects-r.inc.php +27 -3
  12. includes/classes/login-redirects.inc.php +15 -15
  13. includes/classes/menu-pages.inc.php +43 -33
  14. includes/classes/option-forces.inc.php +3 -2
  15. includes/classes/paypal-notify-in-subscr-modify-w-level.inc.php +1 -1
  16. includes/classes/paypal-notify-in-subscr-or-rp-eots-w-level.inc.php +0 -1
  17. includes/classes/paypal-notify-in-subscr-or-wa-w-level.inc.php +2 -2
  18. includes/classes/paypal-notify-in-wa-ccaps-wo-level.inc.php +8 -8
  19. includes/classes/paypal-notify-in-web-accept-sp.inc.php +1 -1
  20. includes/classes/paypal-notify-in.inc.php +14 -10
  21. includes/classes/paypal-return-in-no-tx-data.inc.php +1 -0
  22. includes/classes/register-access.inc.php +6 -4
  23. includes/classes/registration-times.inc.php +12 -13
  24. includes/classes/registrations.inc.php +193 -187
  25. includes/classes/sc-files-in.inc.php +85 -0
  26. includes/classes/sc-files.inc.php +49 -0
  27. includes/classes/systematics-sp.inc.php +19 -6
  28. includes/classes/systematics.inc.php +3 -3
  29. includes/classes/translations.inc.php +23 -1
  30. includes/classes/user-deletions.inc.php +24 -16
  31. includes/classes/utils-conds.inc.php +68 -8
  32. includes/classes/utils-strings.inc.php +56 -11
  33. includes/classes/utils-urls.inc.php +21 -11
  34. includes/codes.inc.php +2 -1
  35. includes/functions/api-functions.inc.php +55 -6
  36. includes/functions/pluggables.inc.php +2 -1
  37. includes/hooks.inc.php +2 -1
  38. includes/menu-pages/code-samples/jwplayer-standard-mp4.php +23 -0
  39. includes/menu-pages/code-samples/jwplayer-streaming-mp4-sca.php +35 -0
  40. includes/menu-pages/code-samples/jwplayer-streaming-mp4-webm.php +37 -0
  41. includes/menu-pages/code-samples/jwplayer-streaming-mp4.php +31 -0
  42. includes/menu-pages/down-ops.inc.php +205 -15
  43. includes/menu-pages/menu-pages-s-min.js +1 -1
  44. includes/menu-pages/menu-pages-s.js +145 -91
  45. includes/menu-pages/res-ops.inc.php +4 -4
  46. includes/s2member-min.js +1 -1
  47. includes/s2member.js +25 -15
  48. includes/syscon.inc.php +25 -8
  49. includes/templates/cfg-files/s2-cross-xml.php +10 -0
  50. includes/templates/cfg-files/s2member-files.php +26 -5
  51. includes/translations/s2member.pot +600 -179
  52. readme.txt +10 -2
  53. s2member.php +4 -4
images/jwplayer-logo.png ADDED
Binary file
includes/_xtnls/mailchimp/nc-mcapi.inc.php CHANGED
@@ -2398,119 +2398,59 @@ class NC_MCAPI {
2398
}
2399
2400
/**
2401
- * Actually connect to the server and call the requested methods, parsing the result
2402
- * You should never have to call this function manually
2403
*/
2404
function callServer($method, $params) {
2405
- $dc = "us1";
2406
- if (strstr($this->api_key,"-")){
2407
list($key, $dc) = explode("-",$this->api_key,2);
2408
if (!$dc) $dc = "us1";
2409
}
2410
$this->apiUrl["prefix"] = $dc;
2411
$host = $dc.".".$this->apiUrl["host"];
2412
$params["apikey"] = $this->api_key;
2413
2414
$this->errorMessage = "";
2415
$this->errorCode = "";
2416
- $sep_changed = false;
2417
- //sigh, apparently some distribs change this to & by default
2418
- if (ini_get("arg_separator.output")!="&"){
2419
- $sep_changed = true;
2420
- $orig_sep = ini_get("arg_separator.output");
2421
- ini_set("arg_separator.output", "&");
2422
- }
2423
$post_vars = http_build_query($params);
2424
- if ($sep_changed){
2425
- ini_set("arg_separator.output", $orig_sep);
2426
- }
2427
-
2428
- # $payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
2429
- # $payload .= "Host: " . $host . "\r\n";
2430
- # $payload .= "User-Agent: MCAPI/" . $this->version ."\r\n";
2431
- # $payload .= "Content-type: application/x-www-form-urlencoded\r\n";
2432
- # $payload .= "Content-length: " . strlen($post_vars) . "\r\n";
2433
- # $payload .= "Connection: close \r\n\r\n";
2434
- # $payload .= $post_vars;
2435
-
2436
- ob_start();
2437
-
2438
- $s2_ags = array("user-agent" => "MCAPI/" . $this->version, "timeout" => $this->timeout);
2439
-
2440
- $s2_url = $host . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method;
2441
- $s2_url = ($this->secure) ? "https://" . $s2_url : "http://" . $s2_url;
2442
-
2443
- if (!strlen ($response = c_ws_plugin__s2member_utils_urls::remote ($s2_url, $post_vars, $s2_ags, true))){
2444
- $this->errorMessage = "Could not connect.";
2445
- $this->errorCode = "-99";
2446
- ob_end_clean();
2447
- return false;
2448
- }
2449
-
2450
- ob_end_clean();
2451
-
2452
- # if ($this->secure){
2453
- # $sock = fsockopen("ssl://".$host, 443, $errno, $errstr, 30);
2454
- # } else {
2455
- # $sock = fsockopen($host, 80, $errno, $errstr, 30);
2456
- # }
2457
- # if(!$sock) {
2458
- # $this->errorMessage = "Could not connect (ERR $errno: $errstr)";
2459
- # $this->errorCode = "-99";
2460
- # ob_end_clean();
2461
- # return false;
2462
- # }
2463
-
2464
- # $response = "";
2465
- # fwrite($sock, $payload);
2466
- # stream_set_timeout($sock, $this->timeout);
2467
- # $info = stream_get_meta_data($sock);
2468
- # while ((!feof($sock)) && (!$info["timed_out"])) {
2469
- # $response .= fread($sock, $this->chunkSize);
2470
- # $info = stream_get_meta_data($sock);
2471
- # }
2472
- # fclose($sock);
2473
- # ob_end_clean();
2474
- # if ($info["timed_out"]) {
2475
- # $this->errorMessage = "Could not read response (timed out)";
2476
- # $this->errorCode = -98;
2477
- # return false;
2478
- # }
2479
-
2480
- list($headers, $response) = explode("\r\n\r\n", $response, 2);
2481
- $headers = explode("\r\n", $headers);
2482
- $errored = false;
2483
- foreach($headers as $h){
2484
- if (substr( /* WebSharks, Inc. ( lowercase ). */
2485
- strtolower($h),0,26)==="x-mailchimp-api-error-code"){
2486
- $errored = true;
2487
- $error_code = trim(substr($h,27));
2488
- break;
2489
- }
2490
}
2491
-
2492
- # if(ini_get("magic_quotes_runtime")) $response = stripslashes($response);
2493
-
2494
- $serial = /* WebSharks, Inc. ( maybe ). */ maybe_unserialize($response);
2495
-
2496
- if($response && $serial === false) {
2497
- $response = array("error" => "Bad Response. Got This: " . $response, "code" => "-99");
2498
- } else {
2499
- $response = $serial;
2500
}
2501
- if($errored && is_array($response) && isset($response["error"])) {
2502
$this->errorMessage = $response["error"];
2503
$this->errorCode = $response["code"];
2504
return false;
2505
- } elseif($errored){
2506
- $this->errorMessage = "No error message was found.";
2507
- $this->errorCode = $error_code;
2508
return false;
2509
}
2510
-
2511
return $response;
2512
}
2513
2514
}
2515
-
2516
?>
2398
}
2399
2400
/**
2401
+ * Actually connect to the server and call the requested methods, parsing the result.
2402
+ * You should never have to call this function manually.
2403
*/
2404
function callServer($method, $params) {
2405
+
2406
+ $dc = "us1"; if (strstr($this->api_key,"-")){
2407
list($key, $dc) = explode("-",$this->api_key,2);
2408
if (!$dc) $dc = "us1";
2409
}
2410
+
2411
$this->apiUrl["prefix"] = $dc;
2412
$host = $dc.".".$this->apiUrl["host"];
2413
$params["apikey"] = $this->api_key;
2414
2415
$this->errorMessage = "";
2416
$this->errorCode = "";
2417
+ $error = false;
2418
+
2419
$post_vars = http_build_query($params);
2420
+
2421
+ $s2_ags = array("user-agent" => "MCAPI/" . $this->version, "timeout" => $this->timeout);
2422
+ $s2_url = $host . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method;
2423
+ $s2_url = ($this->secure) ? "https://" . $s2_url : "http://" . $s2_url;
2424
+
2425
+ if (!is_array ($_response = c_ws_plugin__s2member_utils_urls::remote ($s2_url, $post_vars, $s2_ags, "array"))){
2426
+ $this->errorMessage = "Could not connect to API server.";
2427
+ $this->errorCode = "-99";
2428
+ return false;
2429
}
2430
+
2431
+ $headers = $_response["headers"];
2432
+ $body = $response = maybe_unserialize($_response["body"]);
2433
+
2434
+ if (!empty($headers["x-mailchimp-api-error-code"])){
2435
+ $error = trim($headers["x-mailchimp-api-error-code"]);
2436
}
2437
+
2438
+ if($error && isset($response["error"], $response["code"])) {
2439
$this->errorMessage = $response["error"];
2440
$this->errorCode = $response["code"];
2441
return false;
2442
+ } else if($error){
2443
+ $this->errorMessage = "No error message from API server.";
2444
+ $this->errorCode = $error;
2445
+ return false;
2446
+ } else if(!is_array($response) || empty($response)){
2447
+ $this->errorMessage = "No response from API server.";
2448
+ $this->errorCode = "-98";
2449
return false;
2450
}
2451
+
2452
return $response;
2453
}
2454
2455
}
2456
?>
includes/classes/admin-lockouts.inc.php CHANGED
@@ -15,7 +15,7 @@
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_admin_lockouts"))
21
{
@@ -41,16 +41,17 @@ if (!class_exists ("c_ws_plugin__s2member_admin_lockouts"))
41
{
42
do_action ("ws_plugin__s2member_before_admin_lockouts", get_defined_vars ());
43
/**/
44
- if (!current_user_can ("edit_posts") && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["force_admin_lockouts"] && apply_filters ("ws_plugin__s2member_admin_lockout", true, get_defined_vars ()))
45
- {
46
- if ($redirection_url = c_ws_plugin__s2member_login_redirects::login_redirection_url ())
47
- wp_redirect($redirection_url); /* Special Redirection. */
48
- /**/
49
- else /* Else we use the Login Welcome Page configured for s2Member. */
50
- wp_redirect(get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"]));
51
- /**/
52
- exit (); /* Clean exit. */
53
- }
54
/**/
55
do_action ("ws_plugin__s2member_after_admin_lockouts", get_defined_vars ());
56
/**/
@@ -76,7 +77,7 @@ if (!class_exists ("c_ws_plugin__s2member_admin_lockouts"))
76
if (is_object ($wp_admin_bar) && !current_user_can ("edit_posts"))
77
{
78
if (isset ($wp_admin_bar->menu->{"dashboard"})) /* We don't need this. */
79
- unset($wp_admin_bar->menu->{"dashboard"}); /* Remove this entire menu. */
80
/**/
81
if (is_multisite () && !c_ws_plugin__s2member_utils_conds::is_multisite_farm () && isset ($wp_admin_bar->menu->{"my-blogs"}))
82
{
@@ -87,7 +88,7 @@ if (!class_exists ("c_ws_plugin__s2member_admin_lockouts"))
87
if (is_array ($blog) && isset ($blog["href"], $blog["children"]) && is_object ($blog["children"]))
88
{
89
$blog["href"] = preg_replace ("/\/wp-admin/", "", $blog["href"]);
90
- unset($blog["children"]); /* Cause all we need is the link. */
91
}
92
}
93
/**/
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_admin_lockouts"))
21
{
41
{
42
do_action ("ws_plugin__s2member_before_admin_lockouts", get_defined_vars ());
43
/**/
44
+ if ((!defined ("DOING_AJAX") || !DOING_AJAX) && !current_user_can ("edit_posts") && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["force_admin_lockouts"])
45
+ if (apply_filters ("ws_plugin__s2member_admin_lockout", true, get_defined_vars ()) /* Give Filters a chance here too. */)
46
+ {
47
+ if ($redirection_url = c_ws_plugin__s2member_login_redirects::login_redirection_url ())
48
+ wp_redirect ($redirection_url); /* Special Redirection. */
49
+ /**/
50
+ else /* Else we use the Login Welcome Page configured for s2Member. */
51
+ wp_redirect (get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"]));
52
+ /**/
53
+ exit (); /* Clean exit. */
54
+ }
55
/**/
56
do_action ("ws_plugin__s2member_after_admin_lockouts", get_defined_vars ());
57
/**/
77
if (is_object ($wp_admin_bar) && !current_user_can ("edit_posts"))
78
{
79
if (isset ($wp_admin_bar->menu->{"dashboard"})) /* We don't need this. */
80
+ unset ($wp_admin_bar->menu->{"dashboard"}); /* Remove this entire menu. */
81
/**/
82
if (is_multisite () && !c_ws_plugin__s2member_utils_conds::is_multisite_farm () && isset ($wp_admin_bar->menu->{"my-blogs"}))
83
{
88
if (is_array ($blog) && isset ($blog["href"], $blog["children"]) && is_object ($blog["children"]))
89
{
90
$blog["href"] = preg_replace ("/\/wp-admin/", "", $blog["href"]);
91
+ unset ($blog["children"]); /* Cause all we need is the link. */
92
}
93
}
94
/**/
includes/classes/auto-eots.inc.php CHANGED
@@ -119,7 +119,7 @@ if (!class_exists ("c_ws_plugin__s2member_auto_eots"))
119
{
120
if (($user_id = $eot->ID) && is_object ($user = new WP_User ($user_id)) && $user->ID)
121
{
122
- delete_user_option ($user_id, "s2member_auto_eot_time"); /* ALWAYS delete this. */
123
/**/
124
if (!$user->has_cap ("administrator")) /* Do NOT process Administrator accounts. */
125
{
@@ -154,7 +154,6 @@ if (!class_exists ("c_ws_plugin__s2member_auto_eots"))
154
delete_user_option ($user_id, "s2member_subscr_gateway");
155
/**/
156
delete_user_option ($user_id, "s2member_ipn_signup_vars");
157
- /**/
158
if (!apply_filters ("ws_plugin__s2member_preserve_paid_registration_times", true, get_defined_vars ()))
159
delete_user_option ($user_id, "s2member_paid_registration_times");
160
/**/
@@ -192,7 +191,8 @@ if (!class_exists ("c_ws_plugin__s2member_auto_eots"))
192
/**/
193
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_del_notification_recipients"] && is_array ($cv = preg_split ("/\|/", $custom)))
194
{
195
- c_ws_plugin__s2member_email_configs::email_config_release (); /* Release all Filters applied to wp_mail() From: headers. */
196
/**/
197
$msg = $sbj = "( s2Member / API Notification Email ) - EOT/Deletion";
198
$msg .= "\n\n"; /* Spacing in the message body. */
@@ -239,6 +239,9 @@ if (!class_exists ("c_ws_plugin__s2member_auto_eots"))
239
foreach (c_ws_plugin__s2member_utils_strings::trim_deep (preg_split ("/;+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_del_notification_recipients"])) as $recipient)
240
($recipient) ? wp_mail ($recipient, apply_filters ("ws_plugin__s2member_eot_del_notification_email_sbj", $sbj, get_defined_vars ()), apply_filters ("ws_plugin__s2member_eot_del_notification_email_msg", $msg, get_defined_vars ()), "From: \"" . preg_replace ('/"/', "'", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_name"]) . "\" <" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_email"] . ">\r\nContent-Type: text/plain; charset=utf-8") : null;
241
}
242
}
243
/**/
244
eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
119
{
120
if (($user_id = $eot->ID) && is_object ($user = new WP_User ($user_id)) && $user->ID)
121
{
122
+ delete_user_option ($user_id, "s2member_auto_eot_time"); /* Always delete. */
123
/**/
124
if (!$user->has_cap ("administrator")) /* Do NOT process Administrator accounts. */
125
{
154
delete_user_option ($user_id, "s2member_subscr_gateway");
155
/**/
156
delete_user_option ($user_id, "s2member_ipn_signup_vars");
157
if (!apply_filters ("ws_plugin__s2member_preserve_paid_registration_times", true, get_defined_vars ()))
158
delete_user_option ($user_id, "s2member_paid_registration_times");
159
/**/
191
/**/
192
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_del_notification_recipients"] && is_array ($cv = preg_split ("/\|/", $custom)))
193
{
194
+ $email_configs_were_on = c_ws_plugin__s2member_email_configs::email_config_status ();
195
+ c_ws_plugin__s2member_email_configs::email_config_release ();
196
/**/
197
$msg = $sbj = "( s2Member / API Notification Email ) - EOT/Deletion";
198
$msg .= "\n\n"; /* Spacing in the message body. */
239
foreach (c_ws_plugin__s2member_utils_strings::trim_deep (preg_split ("/;+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["eot_del_notification_recipients"])) as $recipient)
240
($recipient) ? wp_mail ($recipient, apply_filters ("ws_plugin__s2member_eot_del_notification_email_sbj", $sbj, get_defined_vars ()), apply_filters ("ws_plugin__s2member_eot_del_notification_email_msg", $msg, get_defined_vars ()), "From: \"" . preg_replace ('/"/', "'", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_name"]) . "\" <" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_email"] . ">\r\nContent-Type: text/plain; charset=utf-8") : null;
241
}
242
+ /**/
243
+ if ($email_configs_were_on) /* Back on? */
244
+ c_ws_plugin__s2member_email_configs::email_config ();
245
}
246
/**/
247
eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
includes/classes/cache.inc.php CHANGED
@@ -44,51 +44,51 @@ if (!class_exists ("c_ws_plugin__s2member_cache"))
44
{
45
do_action ("ws_plugin__s2member_before_cached_page_links", get_defined_vars ());
46
/**/
47
- $login_welcome_page = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"];
48
- $membership_options_page = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"];
49
- $file_download_limit_exceeded_page = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"];
50
/**/
51
- $login_welcome_page_cache = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"];
52
- $membership_options_page_cache = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"];
53
- $file_download_limit_exceeded_page_cache = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"];
54
/**/
55
$links = array ("login_welcome_page" => "", "membership_options_page" => "", "file_download_limit_exceeded_page" => "");
56
/**/
57
- if ($login_welcome_page_cache["page"] === $login_welcome_page && $login_welcome_page_cache["time"] >= strtotime ("-15 minutes") && $login_welcome_page_cache["link"])
58
{
59
- $links["login_welcome_page"] = $login_welcome_page_cache["link"];
60
}
61
- else /* Otherwise, we need to query the database using get_page_link() and update the cache. */
62
{
63
$GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["time"] = time ();
64
- $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["page"] = $login_welcome_page;
65
- $links["login_welcome_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["link"] = get_page_link ($login_welcome_page);
66
/**/
67
$cache_needs_updating = true; /* Flag for cache update. */
68
}
69
/**/
70
- if ($membership_options_page_cache["page"] === $membership_options_page && $membership_options_page_cache["time"] >= strtotime ("-15 minutes") && $membership_options_page_cache["link"])
71
{
72
- $links["membership_options_page"] = $membership_options_page_cache["link"];
73
}
74
- else /* Otherwise, we need to query the database using get_page_link() and update the cache. */
75
{
76
$GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["time"] = time ();
77
- $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["page"] = $membership_options_page;
78
- $links["membership_options_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["link"] = get_page_link ($membership_options_page);
79
/**/
80
$cache_needs_updating = true; /* Flag for cache update. */
81
}
82
/**/
83
- if ($file_download_limit_exceeded_page_cache["page"] === $file_download_limit_exceeded_page && $file_download_limit_exceeded_page_cache["time"] >= strtotime ("-15 minutes") && $file_download_limit_exceeded_page_cache["link"])
84
{
85
- $links["file_download_limit_exceeded_page"] = $file_download_limit_exceeded_page_cache["link"];
86
}
87
- else /* Otherwise, we need to query the database using get_page_link() and update the cache. */
88
{
89
$GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["time"] = time ();
90
- $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["page"] = $file_download_limit_exceeded_page;
91
- $links["file_download_limit_exceeded_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["link"] = get_page_link ($file_download_limit_exceeded_page);
92
/**/
93
$cache_needs_updating = true; /* Flag for cache update. */
94
}
@@ -100,7 +100,7 @@ if (!class_exists ("c_ws_plugin__s2member_cache"))
100
/**/
101
$scheme = (is_ssl ()) ? "https" : "http"; /* SSL mode? */
102
foreach ($links as &$link) /* Conversions for SSL and non-SSL mode. */
103
- $link = preg_replace ("/^http(s)?\:\/\//i", $scheme . "://", $link);
104
/**/
105
return apply_filters ("ws_plugin__s2member_cached_page_links", $links, get_defined_vars ());
106
}
44
{
45
do_action ("ws_plugin__s2member_before_cached_page_links", get_defined_vars ());
46
/**/
47
+ $lwp = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"];
48
+ $mop = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"];
49
+ $fdlep = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"];
50
/**/
51
+ $lwp_cache = @$GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"];
52
+ $mop_cache = @$GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"];
53
+ $fdlep_cache = @$GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"];
54
/**/
55
$links = array ("login_welcome_page" => "", "membership_options_page" => "", "file_download_limit_exceeded_page" => "");
56
/**/
57
+ if (isset ($lwp_cache["page"], $lwp_cache["time"], $lwp_cache["link"]) && $lwp_cache["page"] === $lwp && $lwp_cache["time"] >= strtotime ("-15 minutes") && $lwp_cache["link"])
58
{
59
+ $links["login_welcome_page"] = $lwp_cache["link"];
60
}
61
+ else /* Otherwise, query the database using ``get_page_link()`` and update the cache. */
62
{
63
+ $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["page"] = $lwp;
64
$GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["time"] = time ();
65
+ $links["login_welcome_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["link"] = get_page_link ($lwp);
66
/**/
67
$cache_needs_updating = true; /* Flag for cache update. */
68
}
69
/**/
70
+ if (isset ($mop_cache["page"], $mop_cache["time"], $mop_cache["link"]) && $mop_cache["page"] === $mop && $mop_cache["time"] >= strtotime ("-15 minutes") && $mop_cache["link"])
71
{
72
+ $links["membership_options_page"] = $mop_cache["link"];
73
}
74
+ else /* Otherwise, query the database using ``get_page_link()`` and update the cache. */
75
{
76
+ $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["page"] = $mop;
77
$GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["time"] = time ();
78
+ $links["membership_options_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["link"] = get_page_link ($mop);
79
/**/
80
$cache_needs_updating = true; /* Flag for cache update. */
81
}
82
/**/
83
+ if (isset ($fdlep_cache["page"], $fdlep_cache["time"], $fdlep_cache["link"]) && $fdlep_cache["page"] === $fdlep && $fdlep_cache["time"] >= strtotime ("-15 minutes") && $fdlep_cache["link"])
84
{
85
+ $links["file_download_limit_exceeded_page"] = $fdlep_cache["link"];
86
}
87
+ else /* Otherwise, query the database using ``get_page_link()`` and update the cache. */
88
{
89
+ $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["page"] = $fdlep;
90
$GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["time"] = time ();
91
+ $links["file_download_limit_exceeded_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["link"] = get_page_link ($fdlep);
92
/**/
93
$cache_needs_updating = true; /* Flag for cache update. */
94
}
100
/**/
101
$scheme = (is_ssl ()) ? "https" : "http"; /* SSL mode? */
102
foreach ($links as &$link) /* Conversions for SSL and non-SSL mode. */
103
+ $link = preg_replace ("/^https?\:\/\//i", $scheme . "://", $link);
104
/**/
105
return apply_filters ("ws_plugin__s2member_cached_page_links", $links, get_defined_vars ());
106
}
includes/classes/custom-reg-fields-4bp.inc.php CHANGED
@@ -15,7 +15,7 @@
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_custom_reg_fields_4bp"))
21
{
@@ -61,7 +61,7 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
61
echo '<input type="hidden" name="ws_plugin__s2member_registration" value="' . esc_attr (wp_create_nonce ("ws-plugin--s2member-registration")) . '" />' . "\n";
62
}
63
/**/
64
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
65
do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_before", get_defined_vars ());
66
unset ($__refs, $__v); /* Unset defined __refs, __v. */
67
/**/
@@ -70,7 +70,7 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
70
{
71
foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
72
{
73
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
74
do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_before_custom_fields", get_defined_vars ());
75
unset ($__refs, $__v); /* Unset defined __refs, __v. */
76
/**/
@@ -79,7 +79,7 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
79
$field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"]));
80
$field_id_class = preg_replace ("/_/", "-", $field_var);
81
/**/
82
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
83
if (apply_filters ("ws_plugin__s2member_during_custom_registration_fields_4bp_during_custom_fields_display", true, get_defined_vars ()))
84
{
85
if (!empty ($field["section"]) && $field["section"] === "yes") /* Starts a new section? */
@@ -94,7 +94,7 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
94
unset ($__refs, $__v); /* Unset defined __refs, __v. */
95
}
96
/**/
97
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
98
do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_after_custom_fields", get_defined_vars ());
99
unset ($__refs, $__v); /* Unset defined __refs, __v. */
100
}
@@ -102,7 +102,7 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
102
/**/
103
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_opt_in"] && c_ws_plugin__s2member_list_servers::list_servers_integrated ())
104
{
105
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
106
do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_before_opt_in", get_defined_vars ());
107
unset ($__refs, $__v); /* Unset defined __refs, __v. */
108
/**/
@@ -113,7 +113,7 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
113
echo '</label>' . "\n";
114
echo '</div>' . "\n";
115
/**/
116
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
117
do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_after_opt_in", get_defined_vars ());
118
unset ($__refs, $__v); /* Unset defined __refs, __v. */
119
}
@@ -121,7 +121,7 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
121
if ($close_section_container)
122
echo '</div></div>' . "\n";
123
/**/
124
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
125
do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_after", get_defined_vars ());
126
unset ($__refs, $__v); /* Unset defined __refs, __v. */
127
}
@@ -149,13 +149,14 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
149
/**/
150
if (!$processed && in_array ("profile", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields_4bp"]))
151
if (apply_filters ("ws_plugin__s2member_custom_profile_fields_4bp_display", true, get_defined_vars ()))
152
- if (bp_is_user_profile () && bp_is_profile_edit () && (int)bp_get_the_profile_group_id () === 1)
153
if (isset ($bp->displayed_user->id) && ($user_id = $bp->displayed_user->id))
154
if (($processed = true)) /* Mark as having been processed now. */
155
{
156
echo '<input type="hidden" name="ws_plugin__s2member_profile_4bp_save" id="ws-plugin--s2member-profile-4bp-save" value="' . esc_attr (wp_create_nonce ("ws-plugin--s2member-profile-4bp-save")) . '" />' . "\n";
157
/**/
158
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
159
do_action ("ws_plugin__s2member_during_custom_profile_fields_4bp_before", get_defined_vars ());
160
unset ($__refs, $__v); /* Unset defined __refs, __v. */
161
/**/
@@ -167,7 +168,7 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
167
/**/
168
foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
169
{
170
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
171
do_action ("ws_plugin__s2member_during_custom_profile_fields_4bp_before_custom_fields", get_defined_vars ());
172
unset ($__refs, $__v); /* Unset defined __refs, __v. */
173
/**/
@@ -176,7 +177,7 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
176
$field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"]));
177
$field_id_class = preg_replace ("/_/", "-", $field_var);
178
/**/
179
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
180
if (apply_filters ("ws_plugin__s2member_during_custom_profile_fields_4bp_during_custom_fields_display", true, get_defined_vars ()))
181
{
182
if (!empty ($field["section"]) && $field["section"] === "yes") /* Starts a new section? */
@@ -191,13 +192,13 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
191
unset ($__refs, $__v); /* Unset defined __refs, __v. */
192
}
193
/**/
194
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
195
do_action ("ws_plugin__s2member_during_custom_profile_fields_4bp_after_custom_fields", get_defined_vars ());
196
unset ($__refs, $__v); /* Unset defined __refs, __v. */
197
}
198
}
199
/**/
200
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
201
do_action ("ws_plugin__s2member_during_custom_profile_fields_4bp_after", get_defined_vars ());
202
unset ($__refs, $__v); /* Unset defined __refs, __v. */
203
}
@@ -225,11 +226,12 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
225
/**/
226
if (!$processed && in_array ("profile-view", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields_4bp"]))
227
if (apply_filters ("ws_plugin__s2member_custom_profile_field_items_4bp_display", true, get_defined_vars ()))
228
- if (bp_is_user_profile () && !bp_is_profile_edit () && (int)bp_get_the_profile_group_id () === 1)
229
if (isset ($bp->displayed_user->id) && ($user_id = $bp->displayed_user->id))
230
if (($processed = true)) /* Mark as having been processed now. */
231
{
232
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
233
do_action ("ws_plugin__s2member_during_custom_profile_field_items_4bp_before", get_defined_vars ());
234
unset ($__refs, $__v); /* Unset defined __refs, __v. */
235
/**/
@@ -241,7 +243,7 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
241
/**/
242
foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
243
{
244
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
245
do_action ("ws_plugin__s2member_during_custom_profile_field_items_4bp_before_custom_fields", get_defined_vars ());
246
unset ($__refs, $__v); /* Unset defined __refs, __v. */
247
/**/
@@ -250,7 +252,7 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
250
$field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"]));
251
$field_id_class = preg_replace ("/_/", "-", $field_var);
252
/**/
253
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
254
if (apply_filters ("ws_plugin__s2member_during_custom_profile_field_items_4bp_during_custom_fields_display", true, get_defined_vars ()))
255
{
256
if (!empty ($field["section"]) && $field["section"] === "yes") /* New section? */
@@ -268,13 +270,13 @@ if (!class_exists ("c_ws_plugin__s2member_custom_reg_fields_4bp"))
268
unset ($__refs, $__v); /* Unset defined __refs, __v. */
269
}
270
/**/
271
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
272
do_action ("ws_plugin__s2member_during_custom_profile_field_items_4bp_after_custom_fields", get_defined_vars ());
273
unset ($__refs, $__v); /* Unset defined __refs, __v. */
274
}
275
}
276
/**/
277
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
278
do_action ("ws_plugin__s2member_during_custom_profile_field_items_4bp_after", get_defined_vars ());
279
unset ($__refs, $__v); /* Unset defined __refs, __v. */
280
}
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_custom_reg_fields_4bp"))
21
{
61
echo '<input type="hidden" name="ws_plugin__s2member_registration" value="' . esc_attr (wp_create_nonce ("ws-plugin--s2member-registration")) . '" />' . "\n";
62
}
63
/**/
64
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
65
do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_before", get_defined_vars ());
66
unset ($__refs, $__v); /* Unset defined __refs, __v. */
67
/**/
70
{
71
foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
72
{
73
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
74
do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_before_custom_fields", get_defined_vars ());
75
unset ($__refs, $__v); /* Unset defined __refs, __v. */
76
/**/
79
$field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"]));
80
$field_id_class = preg_replace ("/_/", "-", $field_var);
81
/**/
82
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
83
if (apply_filters ("ws_plugin__s2member_during_custom_registration_fields_4bp_during_custom_fields_display", true, get_defined_vars ()))
84
{
85
if (!empty ($field["section"]) && $field["section"] === "yes") /* Starts a new section? */
94
unset ($__refs, $__v); /* Unset defined __refs, __v. */
95
}
96
/**/
97
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
98
do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_after_custom_fields", get_defined_vars ());
99
unset ($__refs, $__v); /* Unset defined __refs, __v. */
100
}
102
/**/
103
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_opt_in"] && c_ws_plugin__s2member_list_servers::list_servers_integrated ())
104
{
105
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
106
do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_before_opt_in", get_defined_vars ());
107
unset ($__refs, $__v); /* Unset defined __refs, __v. */
108
/**/
113
echo '</label>' . "\n";
114
echo '</div>' . "\n";
115
/**/
116
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
117
do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_after_opt_in", get_defined_vars ());
118
unset ($__refs, $__v); /* Unset defined __refs, __v. */
119
}
121
if ($close_section_container)
122
echo '</div></div>' . "\n";
123
/**/
124
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
125
do_action ("ws_plugin__s2member_during_custom_registration_fields_4bp_after", get_defined_vars ());
126
unset ($__refs, $__v); /* Unset defined __refs, __v. */
127
}
149
/**/
150
if (!$processed && in_array ("profile", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields_4bp"]))
151
if (apply_filters ("ws_plugin__s2member_custom_profile_fields_4bp_display", true, get_defined_vars ()))
152
+ if (bp_is_user_profile () && (( /* BuddyPress v1.5. */function_exists ("bp_is_user_profile_edit") && bp_is_user_profile_edit ())/**/
153
+ || ( /* for BuddyPress < v1.5. */function_exists ("bp_is_profile_edit") && bp_is_profile_edit ())) && (int)bp_get_the_profile_group_id () === 1)
154
if (isset ($bp->displayed_user->id) && ($user_id = $bp->displayed_user->id))
155
if (($processed = true)) /* Mark as having been processed now. */
156
{
157
echo '<input type="hidden" name="ws_plugin__s2member_profile_4bp_save" id="ws-plugin--s2member-profile-4bp-save" value="' . esc_attr (wp_create_nonce ("ws-plugin--s2member-profile-4bp-save")) . '" />' . "\n";
158
/**/
159
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
160
do_action ("ws_plugin__s2member_during_custom_profile_fields_4bp_before", get_defined_vars ());
161
unset ($__refs, $__v); /* Unset defined __refs, __v. */
162
/**/
168
/**/
169
foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
170
{
171
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
172
do_action ("ws_plugin__s2member_during_custom_profile_fields_4bp_before_custom_fields", get_defined_vars ());
173
unset ($__refs, $__v); /* Unset defined __refs, __v. */
174
/**/
177
$field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"]));
178
$field_id_class = preg_replace ("/_/", "-", $field_var);
179
/**/
180
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
181
if (apply_filters ("ws_plugin__s2member_during_custom_profile_fields_4bp_during_custom_fields_display", true, get_defined_vars ()))
182
{
183
if (!empty ($field["section"]) && $field["section"] === "yes") /* Starts a new section? */
192
unset ($__refs, $__v); /* Unset defined __refs, __v. */
193
}
194
/**/
195
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
196
do_action ("ws_plugin__s2member_during_custom_profile_fields_4bp_after_custom_fields", get_defined_vars ());
197
unset ($__refs, $__v); /* Unset defined __refs, __v. */
198
}
199
}
200
/**/
201
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
202
do_action ("ws_plugin__s2member_during_custom_profile_fields_4bp_after", get_defined_vars ());
203
unset ($__refs, $__v); /* Unset defined __refs, __v. */
204
}
226
/**/
227
if (!$processed && in_array ("profile-view", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields_4bp"]))
228
if (apply_filters ("ws_plugin__s2member_custom_profile_field_items_4bp_display", true, get_defined_vars ()))
229
+ if (bp_is_user_profile () && (( /* BuddyPress v1.5. */function_exists ("bp_is_user_profile_edit") && !bp_is_user_profile_edit ())/**/
230
+ || ( /* for BuddyPress < v1.5. */function_exists ("bp_is_profile_edit") && !bp_is_profile_edit ())) && (int)bp_get_the_profile_group_id () === 1)
231
if (isset ($bp->displayed_user->id) && ($user_id = $bp->displayed_user->id))
232
if (($processed = true)) /* Mark as having been processed now. */
233
{
234
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
235
do_action ("ws_plugin__s2member_during_custom_profile_field_items_4bp_before", get_defined_vars ());
236
unset ($__refs, $__v); /* Unset defined __refs, __v. */
237
/**/
243
/**/
244
foreach (json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field)
245
{
246
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
247
do_action ("ws_plugin__s2member_during_custom_profile_field_items_4bp_before_custom_fields", get_defined_vars ());
248
unset ($__refs, $__v); /* Unset defined __refs, __v. */
249
/**/
252
$field_var = preg_replace ("/[^a-z0-9]/i", "_", strtolower ($field["id"]));
253
$field_id_class = preg_replace ("/_/", "-", $field_var);
254
/**/
255
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
256
if (apply_filters ("ws_plugin__s2member_during_custom_profile_field_items_4bp_during_custom_fields_display", true, get_defined_vars ()))
257
{
258
if (!empty ($field["section"]) && $field["section"] === "yes") /* New section? */
270
unset ($__refs, $__v); /* Unset defined __refs, __v. */
271
}
272
/**/
273
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
274
do_action ("ws_plugin__s2member_during_custom_profile_field_items_4bp_after_custom_fields", get_defined_vars ());
275
unset ($__refs, $__v); /* Unset defined __refs, __v. */
276
}
277
}
278
/**/
279
+ eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
280
do_action ("ws_plugin__s2member_during_custom_profile_field_items_4bp_after", get_defined_vars ());
281
unset ($__refs, $__v); /* Unset defined __refs, __v. */
282
}
includes/classes/email-configs.inc.php CHANGED
@@ -49,7 +49,7 @@ if (!class_exists ("c_ws_plugin__s2member_email_configs"))
49
return apply_filters ("ws_plugin__s2member_after_email_filter", $array, get_defined_vars ());
50
}
51
/**
52
- * Modifies email From: "Name" <address>.
53
*
54
* These Filters are only needed during registration.
55
*
@@ -62,8 +62,7 @@ if (!class_exists ("c_ws_plugin__s2member_email_configs"))
62
{
63
do_action ("ws_plugin__s2member_before_email_config", get_defined_vars ());
64
/**/
65
- c_ws_plugin__s2member_email_configs::email_config_release (); /* Release all. */
66
- /**/
67
add_filter ("wp_mail_from", "c_ws_plugin__s2member_email_configs::_email_config_email");
68
add_filter ("wp_mail_from_name", "c_ws_plugin__s2member_email_configs::_email_config_name");
69
/**/
@@ -111,10 +110,10 @@ if (!class_exists ("c_ws_plugin__s2member_email_configs"))
111
* @package s2Member\Email_Configs
112
* @since 3.5
113
*
114
- * @param bool $any Optional. Defaults to true. If true, return true if ANY Filters are being applied, not just those applied by s2Member.
115
* @return bool True if Filters are being applied, else false.
116
*/
117
- public static function email_config_status ($any = TRUE)
118
{
119
do_action ("ws_plugin__s2member_before_email_config_status", get_defined_vars ());
120
/**/
@@ -132,17 +131,17 @@ if (!class_exists ("c_ws_plugin__s2member_email_configs"))
132
* @package s2Member\Email_Configs
133
* @since 3.5
134
*
135
- * @param bool $all Optional. Defaults to true. If true, remove ALL Filters, not just those applied by s2Member.
136
* @return null
137
*/
138
- public static function email_config_release ($all = TRUE)
139
{
140
do_action ("ws_plugin__s2member_before_email_config_release", get_defined_vars ());
141
/**/
142
remove_filter ("wp_mail_from", "c_ws_plugin__s2member_email_configs::_email_config_email");
143
remove_filter ("wp_mail_from_name", "c_ws_plugin__s2member_email_configs::_email_config_name");
144
/**/
145
- if ($all) /* If $all is true, then we remove all attached WordPress® Filters. */
146
remove_all_filters("wp_mail_from") . remove_all_filters ("wp_mail_from_name");
147
/**/
148
do_action ("ws_plugin__s2member_after_email_config_release", get_defined_vars ());
@@ -190,9 +189,12 @@ if (!class_exists ("c_ws_plugin__s2member_email_configs"))
190
do_action ("ws_plugin__s2member_before_new_user_notification", get_defined_vars ());
191
unset ($__refs, $__v); /* Unset defined __refs, __v. */
192
/**/
193
- if ($user_id && ($user = new WP_User ($user_id)) && ($user_id = $user->ID) && is_array ($notify) && !empty ($notify))
194
{
195
- if (in_array ("user", $notify) && !empty ($user_pass)) /* Send User a notification? */
196
{
197
$fields = get_user_option ("s2member_custom_fields", $user_id);
198
$cv = preg_split ("/\|/", get_user_option ("s2member_custom", $user_id));
@@ -234,9 +236,7 @@ if (!class_exists ("c_ws_plugin__s2member_email_configs"))
234
break;
235
/**/
236
if (($sbj = trim (preg_replace ("/%%(.+?)%%/i", "", $sbj))) && ($msg = trim (preg_replace ("/%%(.+?)%%/i", "", $msg))))
237
- {
238
- wp_mail ('"' . c_ws_plugin__s2member_utils_strings::esc_dq ($user_full_name) . '" <' . $user->user_email . '>', $sbj, $msg, "From: \"" . preg_replace ('/"/', "'", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_name"]) . "\" <" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_email"] . ">\r\nContent-Type: text/plain; charset=utf-8");
239
- }
240
}
241
}
242
}
@@ -309,6 +309,9 @@ if (!class_exists ("c_ws_plugin__s2member_email_configs"))
309
}
310
}
311
/**/
312
return apply_filters ("ws_plugin__s2member_new_user_notification", true, get_defined_vars ());
313
}
314
else
49
return apply_filters ("ws_plugin__s2member_after_email_filter", $array, get_defined_vars ());
50
}
51
/**
52
+ * Modifies email From: `"Name" <address>`.
53
*
54
* These Filters are only needed during registration.
55
*
62
{
63
do_action ("ws_plugin__s2member_before_email_config", get_defined_vars ());
64
/**/
65
+ c_ws_plugin__s2member_email_configs::email_config_release ();
66
add_filter ("wp_mail_from", "c_ws_plugin__s2member_email_configs::_email_config_email");
67
add_filter ("wp_mail_from_name", "c_ws_plugin__s2member_email_configs::_email_config_name");
68
/**/
110
* @package s2Member\Email_Configs
111
* @since 3.5
112
*
113
+ * @param bool $any Optional. Defaults to false. If true, return true if ANY Filters are being applied, not just those applied by s2Member.
114
* @return bool True if Filters are being applied, else false.
115
*/
116
+ public static function email_config_status ($any = FALSE)
117
{
118
do_action ("ws_plugin__s2member_before_email_config_status", get_defined_vars ());
119
/**/
131
* @package s2Member\Email_Configs
132
* @since 3.5
133
*
134
+ * @param bool $all Optional. Defaults to false. If true, remove ALL Filters, not just those applied by s2Member.
135
* @return null
136
*/
137
+ public static function email_config_release ($all = FALSE)
138
{
139
do_action ("ws_plugin__s2member_before_email_config_release", get_defined_vars ());
140
/**/
141
remove_filter ("wp_mail_from", "c_ws_plugin__s2member_email_configs::_email_config_email");
142
remove_filter ("wp_mail_from_name", "c_ws_plugin__s2member_email_configs::_email_config_name");
143
/**/
144
+ if ($all) /* If ``$all`` is true, remove ALL attached WordPress® Filters. */
145
remove_all_filters("wp_mail_from") . remove_all_filters ("wp_mail_from_name");
146
/**/
147
do_action ("ws_plugin__s2member_after_email_config_release", get_defined_vars ());
189
do_action ("ws_plugin__s2member_before_new_user_notification", get_defined_vars ());
190
unset ($__refs, $__v); /* Unset defined __refs, __v. */
191
/**/
192
+ if ($user_id && ($user = new WP_User ($user_id)) && !empty ($user->ID) && ($user_id = $user->ID) && is_array ($notify) && !empty ($notify))
193
{
194
+ $email_configs_were_on = c_ws_plugin__s2member_email_configs::email_config_status ();
195
+ c_ws_plugin__s2member_email_configs::email_config_release ();
196
+ /**/
197
+ if (in_array ("user", $notify) && $user_pass) /* Send User a notification? */
198
{
199
$fields = get_user_option ("s2member_custom_fields", $user_id);
200
$cv = preg_split ("/\|/", get_user_option ("s2member_custom", $user_id));
236
break;
237
/**/
238
if (($sbj = trim (preg_replace ("/%%(.+?)%%/i", "", $sbj))) && ($msg = trim (preg_replace ("/%%(.+?)%%/i", "", $msg))))
239
+ c_ws_plugin__s2member_email_configs::email_config () . wp_mail ('"' . c_ws_plugin__s2member_utils_strings::esc_dq ($user_full_name) . '" <' . $user->user_email . '>', $sbj, $msg, "From: \"" . preg_replace ('/"/', "'", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_name"]) . "\" <" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_email"] . ">\r\nContent-Type: text/plain; charset=utf-8") . c_ws_plugin__s2member_email_configs::email_config_release ();
240
}
241
}
242
}
309
}
310
}
311
/**/
312
+ if ($email_configs_were_on) /* Back on? */
313
+ c_ws_plugin__s2member_email_configs::email_config ();
314
+ /**/
315
return apply_filters ("ws_plugin__s2member_new_user_notification", true, get_defined_vars ());
316
}
317
else
includes/classes/files-in.inc.php CHANGED
@@ -34,257 +34,1250 @@ if (!class_exists ("c_ws_plugin__s2member_files_in"))
34
* @since 3.5
35
*
36
* @attaches-to: ``add_action("init");``
37
*
38
- * @return null Or exits script execution after serving a File Download.
39
*/
40
- public static function check_file_download_access ()
41
{
42
do_action ("ws_plugin__s2member_before_file_download_access", get_defined_vars ());
43
/**/
44
- if (!empty ($_GET["s2member_file_download"])) /* Ignore `..`, and `^.` files like `.htaccess`. */
45
- if (strpos ($_GET["s2member_file_download"], "..") === false) /* Ignore `..` if it appears anywhere. */
46
- if (strpos (basename ($_GET["s2member_file_download"]), ".") !== 0) /* Ignore any/all hidden files. */
47
- {
48
@set_time_limit(0) . @ini_set ("zlib.output_compression", 0) . eval ('while (@ob_end_clean ());');
49
- /**/
50
- $excluded = apply_filters ("ws_plugin__s2member_check_file_download_access_excluded", false, get_defined_vars ());
51
- /**/
52
- if (!($using_amazon_s3_storage = 0) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_bucket"] && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_access_key"] && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_secret_key"])
53
- $using_amazon_s3_storage = true; /* Amazon® S3 storage has been configured! */
54
- /**/
55
- if (!$excluded && (empty ($_GET["s2member_file_download_key"]) || (!empty ($_GET["s2member_file_download_key"]) && !($file_download_key_is_valid = ($_GET["s2member_file_download_key"] === c_ws_plugin__s2member_files::file_download_key ($_GET["s2member_file_download"]) || $_GET["s2member_file_download_key"] === c_ws_plugin__s2member_files::file_download_key ($_GET["s2member_file_download"], "ip-forever") || $_GET["s2member_file_download_key"] === c_ws_plugin__s2member_files::file_download_key ($_GET["s2member_file_download"], "universal"))))))
56
- {
57
- $_GET["s2member_file_download"] = trim ($_GET["s2member_file_download"], "/"); /* Trim slashes after Key comparison. */
58
- /**/
59
- if (!$using_amazon_s3_storage && !file_exists ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"] . "/" . $_GET["s2member_file_download"]))
60
- {
61
status_header(404) . exit (_x ("404: Sorry, file not found. Please contact Support for assistance.", "s2member-front", "s2member"));
62
- }
63
- /**/
64
- else if (!empty ($_GET["s2member_file_download_key"]) && !$file_download_key_is_valid)
65
- {
66
status_header(503) . exit (_x ("503 ( Invalid Key ): Sorry, your access to this file has expired. Please contact Support for assistance.", "s2member-front", "s2member"));
67
- }
68
/**/
69
- else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"] || ($file_download_access_is_allowed = $min_level_4_downloads = c_ws_plugin__s2member_files::min_level_4_downloads ()) === false)
70
{
71
- if (!has_filter ("ws_plugin__s2member_check_file_download_access_user", "c_ws_plugin__s2member_files_in::_file_remote_authorization"))
72
- add_filter ("ws_plugin__s2member_check_file_download_access_user", "c_ws_plugin__s2member_files_in::_file_remote_authorization", 10, 2);
73
- /**/
74
- if ((isset ($file_download_access_is_allowed, $min_level_4_downloads) && $file_download_access_is_allowed === false) || ($file_download_access_is_allowed = $min_level_4_downloads = c_ws_plugin__s2member_files::min_level_4_downloads ()) === false)
75
- {
76
- status_header(503) . exit (_x ("503: Sorry, File Downloads are NOT enabled yet. Please contact Support for assistance. If you are the site owner, please configure: `s2Member -> Download Options -> Basic Download Restrictions`.", "s2member-front", "s2member"));
77
- }
78
- /**/
79
- else if (!is_object ($user = apply_filters ("ws_plugin__s2member_check_file_download_access_user", ((is_user_logged_in ()) ? wp_get_current_user () : false), get_defined_vars ())) || !($user_id = $user->ID))
80
- {
81
- if (preg_match ("/^access[_\-]s2member[_\-]level([0-9]+)\//", $_GET["s2member_file_download"], $m))
82
- {
83
- $level_req = $m[1]; /* Which Level does this require? */
84
- if (wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $_GET["s2member_file_download"], "s2member_level_req" => $level_req)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) !== "nill")
85
- exit ();
86
- }
87
- else if (preg_match ("/^access[_\-]s2member[_\-]ccap[_\-](.+?)\//", $_GET["s2member_file_download"], $m))
88
- {
89
- $ccap_req = preg_replace ("/-/", "_", $m[1]); /* Which Capability does this require? */
90
- if (wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $_GET["s2member_file_download"], "s2member_ccap_req" => $ccap_req)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) !== "nill")
91
- exit ();
92
- }
93
- else if (wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $_GET["s2member_file_download"], "s2member_level_req" => (string)$min_level_4_downloads)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) !== "nill")
94
- exit ();
95
- }
96
- /**/
97
- else if ((!is_array ($file_downloads = c_ws_plugin__s2member_files::user_downloads ($user)) || !$file_downloads["allowed"] || !$file_downloads["allowed_days"])/**/
98
- && wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $_GET["s2member_file_download"])), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) !== "nill")
99
- exit ();
100
- /**/
101
- else if (preg_match ("/^access[_\-]s2member[_\-]level([0-9]+)\//", $_GET["s2member_file_download"], $m))
102
- {
103
- $level_req = $m[1]; /* Which Level does this require? */
104
- if (!$user->has_cap ("access_s2member_level" . $level_req) /* Does the User have access to this Level? */
105
- && wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $_GET["s2member_file_download"], "s2member_level_req" => $level_req)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) !== "nill")
106
- exit ();
107
- }
108
/**/
109
- else if (preg_match ("/^access[_\-]s2member[_\-]ccap[_\-](.+?)\//", $_GET["s2member_file_download"], $m))
110
{
111
- $ccap_req = preg_replace ("/-/", "_", $m[1]); /* Which Capability does this require? */
112
- if (!$user->has_cap ("access_s2member_ccap_" . $ccap_req) /* Does the User have access to this Custom Capability? */
113
- && wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $_GET["s2member_file_download"], "s2member_ccap_req" => $ccap_req)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) !== "nill")
114
- exit ();
115
}
116
/**/
117
- $already_downloaded = false; /* Initialize this to a false value. */
118
- $previous_file_downloads = 0; /* Here we're going to count how many downloads they've performed. */
119
- $max_days_logged = c_ws_plugin__s2member_files::max_download_period (); /* Longest period/days. */
120
- $file_download_access_log = (array)get_user_option ("s2member_file_download_access_log", $user_id);
121
- $file_download_access_arc = (array)get_user_option ("s2member_file_download_access_arc", $user_id);
122
/**/
123
- foreach ($file_download_access_log as $file_download_access_log_entry_key => $file_download_access_log_entry)
124
{
125
- if (strtotime ($file_download_access_log_entry["date"]) < strtotime ("-" . $max_days_logged . " days"))
126
{
127
- unset($file_download_access_log[$file_download_access_log_entry_key]);
128
- $file_download_access_arc[] = $file_download_access_log_entry;
129
- }
130
- else if (strtotime ($file_download_access_log_entry["date"]) >= strtotime ("-" . $file_downloads["allowed_days"] . " days"))
131
- {
132
- $previous_file_downloads++;
133
- if ($file_download_access_log_entry["file"] === $_GET["s2member_file_download"])
134
- $already_downloaded = true;
135
}
136
}
137
/**/
138
- if (!$already_downloaded && $previous_file_downloads >= $file_downloads["allowed"] /* They have NOT already downloaded this file, and they're over their limit. */
139
- && wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $_GET["s2member_file_download"])), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) !== "nill")
140
- exit ();
141
- /**/
142
- if (!$already_downloaded) /* Only add this file to the log if they have not already downloaded it. */
143
- $file_download_access_log[] = array ("date" => date ("Y-m-d"), "file" => $_GET["s2member_file_download"]);
144
- /**/
145
- update_user_option ($user_id, "s2member_file_download_access_arc", c_ws_plugin__s2member_utils_arrays::array_unique ($file_download_access_arc));
146
- update_user_option ($user_id, "s2member_file_download_access_log", c_ws_plugin__s2member_utils_arrays::array_unique ($file_download_access_log));
147
- }
148
- }
149
- else /* Otherwise... it's either $excluded; or permission was granted with a valid Download Key. */
150
- {
151
- $_GET["s2member_file_download"] = trim ($_GET["s2member_file_download"], "/");
152
- /**/
153
- if (!$using_amazon_s3_storage && !file_exists ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"] . "/" . $_GET["s2member_file_download"]))
154
- {
155
- status_header(404) . exit (_x ("404: Sorry, file not found. Please contact Support for assistance.", "s2member-front", "s2member"));
156
}
157
}
158
- /*
159
- Here we are going to put together all of the File Download information.
160
- */
161
- $extension = strtolower (substr ($_GET["s2member_file_download"], strrpos ($_GET["s2member_file_download"], ".") + 1)); /* To lowercase. */
162
- /**/
163
- $mimetypes = parse_ini_file (dirname (dirname (dirname (__FILE__))) . "/includes/mime-types.ini"); /* Types provided by: `mime-types.ini`. */
164
- $mimetype = ($mimetypes[$extension]) ? $mimetypes[$extension] : "application/octet-stream"; /* Lookup the MIME type for this file extension. */
165
- /**/
166
- $inline = (isset ($_GET["s2member_file_inline"])) ? filter_var ($_GET["s2member_file_inline"], FILTER_VALIDATE_BOOLEAN) : ((in_array ($extension, preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_inline_extensions"]))) ? true : false);
167
- /**/
168
- $basename = basename ($_GET["s2member_file_download"]); /* The actual name of this File Download ( i.e. the basename ); including its file extension too. */
169
/**/
170
- $pathinfo = (!$using_amazon_s3_storage) ? pathinfo (($file = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"] . "/" . $_GET["s2member_file_download"])) : array ();
171
- $length = (!$using_amazon_s3_storage && $file) ? filesize ($file) : -1; /* The overall file size, in bytes. */
172
/**/
173
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
174
- do_action ("ws_plugin__s2member_during_file_download_access", get_defined_vars ());
175
- unset ($__refs, $__v); /* Unset defined __refs, __v. */
176
/**/
177
- if ($using_amazon_s3_storage) /* Using Amazon® S3 storage? In this case, we use an authenticated redirection to S3 storage. */
178
{
179
- $amazon_s3_file_expires = strtotime ("+" . apply_filters ("ws_plugin__s2member_amazon_s3_file_expires_time", "30 seconds", get_defined_vars ()));
180
/**/
181
- $amazon_s3_file = "/" . $_GET["s2member_file_download"] . "?response-cache-control=" . urlencode (($amazon_s3_cache_control = "no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0")) . "&response-content-disposition=" . urlencode (($amazon_s3_content_disposition = (($inline) ? "inline" : "attachment") . '; filename="' . $basename . '"')) . "&response-content-type=" . urlencode (($amazon_s3_content_type = $mimetype)) . "&response-expires=" . urlencode (($amazon_s3_expires = gmdate ("D, d M Y H:i:s", strtotime ("-1 week")) . " GMT"));
182
- $amazon_s3_raw_file = "/" . $_GET["s2member_file_download"] . "?response-cache-control=" . $amazon_s3_cache_control . "&response-content-disposition=" . $amazon_s3_content_disposition . "&response-content-type=" . $amazon_s3_content_type . "&response-expires=" . $amazon_s3_expires;
183
- $amazon_s3_signature = base64_encode (c_ws_plugin__s2member_files_in::amazon_s3_sign ("GET\n\n\n" . $amazon_s3_file_expires . "\n" . "/" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_bucket"] . $amazon_s3_raw_file));
184
/**/
185
- $amazon_s3_redirection_url = "http://" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_bucket"] . ".s3.amazonaws.com" . $amazon_s3_file;
186
- if (strtolower ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_bucket"]) !== $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_bucket"])
187
- $amazon_s3_redirection_url = "http://s3.amazonaws.com/" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_bucket"] . $amazon_s3_file;
188
/**/
189
- $amazon_s3_redirection_url .= "&AWSAccessKeyId=" . urlencode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_access_key"]);
190
- $amazon_s3_redirection_url .= "&Expires=" . urlencode ($amazon_s3_file_expires);
191
- $amazon_s3_redirection_url .= "&Signature=" . urlencode ($amazon_s3_signature);
192
/**/
193
- wp_redirect($amazon_s3_redirection_url) . exit ();
194
- }
195
- /**/
196
- else /* Else, using localized storage ( default ). */
197
- {
198
- status_header(200);
199
- header("Accept-Ranges: none");
200
- header("Content-Encoding: none");
201
- header("Content-Type: " . $mimetype);
202
- header("Expires: " . gmdate ("D, d M Y H:i:s", strtotime ("-1 week")) . " GMT");
203
- header("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT");
204
- header("Cache-Control: no-cache, must-revalidate, max-age=0");
205
- header ("Cache-Control: post-check=0, pre-check=0", false);
206
- header("Pragma: no-cache");
207
/**/
208
- header('Content-Disposition: ' . (($inline) ? "inline" : "attachment") . '; filename="' . $basename . '"');
209
- /**/
210
- if ($length && apply_filters ("ws_plugin__s2member_stream_file_downloads", true, get_defined_vars ()) && ($stream = fopen ($file, "rb")))
211
- {
212
- $_stream_w_content_length = (stripos (PHP_OS, "win") === 0 && (!function_exists ("apache_get_version") || apache_get_version () === false)) ? false : true;
213
- /* Windows® IIS doesn't seem to like it when both `Content-Length` and `Transfer-Encoding: chunked` are sent together. */
214
- if (apply_filters ("ws_plugin__s2member_stream_file_downloads_w_content_length", $_stream_w_content_length, get_defined_vars ()))
215
- header("Content-Length: " . $length);
216
- /**/
217
- header("Transfer-Encoding: chunked"); /* Uses `Transfer-Encoding: chunked` for simulated streaming. */
218
- /**/
219
- while (!feof ($stream) && ($chunk_size = strlen ($data = fread ($stream, 2097152))))
220
- eval('echo dechex ($chunk_size) . "\r\n". $data . "\r\n"; @flush ();');
221
- /**/
222
- fclose($stream) . exit ("0\r\n\r\n");
223
- }
224
- else if ($length) /* Else `file_get_contents()`. */
225
- {
226
- header("Content-Length: " . $length) . exit (file_get_contents ($file));
227
- }
228
- else /* Else, we have an empty file. */
229
- {
230
- header("Content-Length: 0") . exit (); /* Empty file. */
231
- }
232
}
233
}
234
- /**/
235
- do_action ("ws_plugin__s2member_after_file_download_access", get_defined_vars ());
236
}
237
/**
238
- * Creates an Amazon® S3 HMAC-SHA1 signature.
239
*
240
* @package s2Member\Files
241
- * @since 110524RC
242
*
243
- * @param str $data Input data, to be signed by this routine.
244
- * @return str An HMAC-SHA1 signature for Amazon® S3.
245
*/
246
- public static function amazon_s3_sign ($data = FALSE)
247
{
248
- $key = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_secret_key"];
249
- $key = str_pad (((strlen ($key) > 64) ? pack ('H*', sha1 ($key)) : $key), 64, chr (0x00));
250
- return pack ('H*', sha1 (($key ^ str_repeat (chr (0x5c), 64)) . pack ('H*', sha1 (($key ^ str_repeat (chr (0x36), 64)) . $data))));
251
}
252
/**
253
- * A sort of callback function that handles Header Authorization for File Downloads.
254
*
255
* @package s2Member\Files
256
- * @since 3.5
257
*
258
- * @attaches-to: ``add_filter("ws_plugin__s2member_check_file_download_access_user");``
259
- *
260
- * @param obj $user Expects a WP_User object passed in by the Filter.
261
- * @return obj A WP_User object, possibly obtained through Header Authorization.
262
*/
263
- public static function _file_remote_authorization ($user = FALSE)
264
{
265
- eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
266
- do_action ("_ws_plugin__s2member_before_file_remote_authorization", get_defined_vars ());
267
- unset ($__refs, $__v); /* Unset defined __refs, __v. */
268
- /**/
269
- if (!is_object ($user) && isset ($_GET["s2member_file_remote"]) && filter_var ($_GET["s2member_file_remote"], FILTER_VALIDATE_BOOLEAN))
270
{
271
- do_action ("_ws_plugin__s2member_during_file_remote_authorization_before", get_defined_vars ());
272
/**/
273
- if (empty ($_SERVER["PHP_AUTH_USER"]) || empty ($_SERVER["PHP_AUTH_PW"]) || !user_pass_ok ($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]))
274
{
275
- header('WWW-Authenticate: Basic realm="' . _x ("Members Only", "s2member-front", "s2member") . '"');
276
- status_header(401); /* Unauthorized status header. */
277
- exit(_x ("Access Denied", "s2member-front", "s2member"));
278
}
279
- else if (is_object ($_user = new WP_User ($_SERVER["PHP_AUTH_USER"])) && $_user->ID)
280
{
281
- $user = $_user; /* Now assign $user. */
282
}
283
- /**/
284
- do_action ("_ws_plugin__s2member_during_file_remote_authorization_after", get_defined_vars ());
285
}
286
- /**/
287
- return apply_filters ("_ws_plugin__s2member_file_remote_authorization", $user, get_defined_vars ());
288
}
289
}
290
}
34
* @since 3.5
35
*
36
* @attaches-to: ``add_action("init");``
37
+ * @also-called-by: API Function {@link s2Member\API_Functions\s2member_file_download_url()}, w/ ``$create_file_download_url`` param.
38
*
39
+ * @param array $create_file_download_url Optional. If this function is called directly, we can pass arguments through this array.
40
+ * Possible array elements: `file_download` *(required)*, `file_download_key`, `file_stream`, `file_inline`, `file_storage`, `file_remote`, `file_ssl`, `file_rewrite`, `file_rewrite_base`, `skip_confirmation`, `url_to_storage_source`, `count_against_user`, `ignore_user`.
41
+ * @return null|str If called directly with ``$create_file_download_url``, returns a string with the URL, based on configuration.
42
+ * Else, this function may exit script execution after serving a File Download.
43
*/
44
+ public static function check_file_download_access ($create_file_download_url = FALSE)
45
{
46
+ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
47
do_action ("ws_plugin__s2member_before_file_download_access", get_defined_vars ());
48
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
49
/**/
50
+ $_g = !empty ($_GET) ? $_GET : array ();
51
+ $_g = c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($_g));
52
+ /**/
53
+ $creating = (is_array ($create = $create_file_download_url)) ? true : false; /* Creating URL? */
54
+ $serving = (!$creating) ? true : false; /* If NOT creating a File Download URL, we're serving one. */
55
+ /**/
56
+ $req["file_download"] = ($creating) ? @$create["file_download"] : @$_g["s2member_file_download"];
57
+ $req["file_download_key"] = ($creating) ? @$create["file_download_key"] : @$_g["s2member_file_download_key"];
58
+ /**/
59
+ $req["file_stream"] = ($creating) ? @$create["file_stream"] : @$_g["s2member_file_stream"];
60
+ $req["file_inline"] = ($creating) ? @$create["file_inline"] : @$_g["s2member_file_inline"];
61
+ $req["file_storage"] = ($creating) ? @$create["file_storage"] : @$_g["s2member_file_storage"];
62
+ $req["file_remote"] = ($creating) ? @$create["file_remote"] : @$_g["s2member_file_remote"];
63
+ $req["file_ssl"] = ($creating) ? @$create["file_ssl"] : @$_g["s2member_file_ssl"];
64
+ /**/
65
+ $req["file_rewrite"] = ($creating) ? @$create["file_rewrite"] : /* N/A. */ null;
66
+ $req["file_rewrite_base"] = ($creating) ? @$create["file_rewrite_base"] : /* N/A. */ null;
67
+ /**/
68
+ $req["skip_confirmation"] = ($creating) ? @$create["skip_confirmation"] : /* N/A. */ null;
69
+ $req["url_to_storage_source"] = ($creating) ? @$create["url_to_storage_source"] : /* N/A. */ null;
70
+ $req["count_against_user"] = ($creating) ? @$create["count_against_user"] : /* N/A. */ null;
71
+ $req["ignore_user"] = ($creating) ? @$create["ignore_user"] : /* N/A. */ null;
72
+ /**/
73
+ if ($req["file_download"] && is_string ($req["file_download"]) && ($req["file_download"] = trim ($req["file_download"], "/")))
74
+ if (strpos ($req["file_download"], "..") === false && strpos (basename ($req["file_download"]), ".") !== 0)
75
+ {
76
+ if ($serving) /* We only need this section when/if we're actually serving. */
77
@set_time_limit(0) . @ini_set ("zlib.output_compression", 0) . eval ('while (@ob_end_clean ());');
78
+ /**/
79
+ $using_amazon_s3_storage = ((!$req["file_storage"] || strcasecmp ((string)$req["file_storage"], "s3") === 0) && c_ws_plugin__s2member_utils_conds::using_amazon_s3_storage ()) ? true : false;
80
+ $using_amazon_cf_storage = ((!$req["file_storage"] || strcasecmp ((string)$req["file_storage"], "cf") === 0) && c_ws_plugin__s2member_utils_conds::using_amazon_cf_storage ()) ? true : false;
81
+ $using_amazon_storage = ($using_amazon_s3_storage || $using_amazon_cf_storage) ? true : false; /* Either/or? */
82
+ /**/
83
+ $excluded = apply_filters ("ws_plugin__s2member_check_file_download_access_excluded", false, get_defined_vars ());
84
+ $valid_file_download_key = ($req["file_download_key"] && is_string ($req["file_download_key"])) ? c_ws_plugin__s2member_files_in::check_file_download_key ($req["file_download"], $req["file_download_key"]) : false;
85
+ $checking_user = ($excluded || $valid_file_download_key || ($creating && isset ($req["ignore_user"]) && filter_var ($req["ignore_user"], FILTER_VALIDATE_BOOLEAN))) ? false : true; /* Checking User? */
86
+ $updating_user_counter = (!$checking_user || ($creating && (!isset ($req["count_against_user"]) || !filter_var ($req["count_against_user"], FILTER_VALIDATE_BOOLEAN)))) ? false : true;
87
+ /**/
88
+ if (($serving || $creating) && $checking_user) /* In either case, the following routines apply whenever we ARE ``$checking_user``. */
89
+ {
90
+ if (!$using_amazon_storage && !file_exists ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"] . "/" . $req["file_download"]))
91
+ {
92
+ if ($serving) /* We only need this section when/if we're actually serving. */
93
status_header(404) . exit (_x ("404: Sorry, file not found. Please contact Support for assistance.", "s2member-front", "s2member"));
94
+ /**/
95
+ else /* Else return false. */
96
+ return false;
97
+ }
98
+ /**/
99
+ else if ($req["file_download_key"] && is_string ($req["file_download_key"]) && !$valid_file_download_key)
100
+ {
101
+ if ($serving) /* We only need this section when/if we're actually serving. */
102
status_header(503) . exit (_x ("503 ( Invalid Key ): Sorry, your access to this file has expired. Please contact Support for assistance.", "s2member-front", "s2member"));
103
+ /**/
104
+ else /* Else return false. */
105
+ return false;
106
+ }
107
+ /**/
108
+ else if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"] || ($file_downloads_enabled = $min_level_4_downloads = c_ws_plugin__s2member_files::min_level_4_downloads ()) === false)
109
+ {
110
+ if ($serving) /* We only need remote functionality when/if we're actually serving. */
111
+ if (!has_filter ("ws_plugin__s2member_check_file_download_access_user", "c_ws_plugin__s2member_files_in::check_file_remote_authorization"))
112
+ add_filter ("ws_plugin__s2member_check_file_download_access_user", "c_ws_plugin__s2member_files_in::check_file_remote_authorization", 10, 2);
113
+ /**/
114
+ if ($creating) /* We only need remote functionality when/if we're actually serving. */
115
+ if (has_filter ("ws_plugin__s2member_check_file_download_access_user", "c_ws_plugin__s2member_files_in::check_file_remote_authorization"))
116
+ remove_filter ("ws_plugin__s2member_check_file_download_access_user", "c_ws_plugin__s2member_files_in::check_file_remote_authorization", 10, 2);
117
+ /**/
118
+ if ((isset ($file_downloads_enabled, $min_level_4_downloads) && $file_downloads_enabled === false) || ($file_downloads_enabled = $min_level_4_downloads = c_ws_plugin__s2member_files::min_level_4_downloads ()) === false)
119
+ {
120
+ if ($serving) /* We only need this section when/if we're actually serving. */
121
+ status_header(503) . exit (_x ("503: Sorry, File Downloads are NOT enabled yet. Please contact Support for assistance. If you are the site owner, please configure: `s2Member -> Download Options -> Basic Download Restrictions`.", "s2member-front", "s2member"));
122
+ /**/
123
+ else /* Else return false. */
124
+ return false;
125
+ }
126
+ /**/
127
+ else if (!is_object ($user = apply_filters ("ws_plugin__s2member_check_file_download_access_user", ((is_user_logged_in ()) ? wp_get_current_user () : false), get_defined_vars ())) || empty ($user->ID) || !($user_id = $user->ID))
128
+ {
129
+ if (preg_match ("/^access[_\-]s2member[_\-]level([0-9]+)\//", $req["file_download"], $m))
130
+ {
131
+ $level_req = $m[1]; /* Memebership Level required. */
132
+ /**/
133
+ if ($serving) /* We only need this section when/if we're actually serving. */
134
+ wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $req["file_download"], "s2member_level_req" => $level_req)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) . exit ();
135
+ /**/
136
+ else /* Else return false. */
137
+ return false;
138
+ }
139
+ /**/
140
+ else if (preg_match ("/^access[_\-]s2member[_\-]ccap[_\-](.+?)\//", $req["file_download"], $m))
141
+ {
142
+ $ccap_req = preg_replace ("/-/", "_", $m[1]); /* Custom Capability required. */
143
+ /**/
144
+ if ($serving) /* We only need this section when/if we're actually serving. */
145
+ wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $req["file_download"], "s2member_ccap_req" => $ccap_req)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) . exit ();
146
+ /**/
147
+ else /* Else return false. */
148
+ return false;
149
+ }
150
+ /**/
151
+ else if ($serving) /* We only need this section when/if we're actually serving. */
152
+ wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $req["file_download"], "s2member_level_req" => (string)$min_level_4_downloads)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) . exit ();
153
+ /**/
154
+ else /* Else return false. */
155
+ return false;
156
+ }
157
+ /**/
158
+ else if (!is_array ($file_downloads = c_ws_plugin__s2member_files::user_downloads ($user)) || (!$user->has_cap ("administrator") && (!$file_downloads["allowed"] || !$file_downloads["allowed_days"])))
159
+ {
160
+ if ($serving) /* We only need this section when/if we're actually serving. */
161
+ wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $req["file_download"])), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) . exit ();
162
+ /**/
163
+ else /* Else return false. */
164
+ return false;
165
+ }
166
+ /**/
167
+ else if (preg_match ("/^access[_\-]s2member[_\-]level([0-9]+)\//", $req["file_download"], $m) && strlen ($level_req = $m[1]) && !$user->has_cap ("access_s2member_level" . $level_req))
168
+ {
169
+ if ($serving) /* We only need this section when/if we're actually serving. */
170
+ wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $req["file_download"], "s2member_level_req" => $level_req)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) . exit ();
171
+ /**/
172
+ else /* Else return false. */
173
+ return false;
174
+ }
175
+ /**/
176
+ else if (preg_match ("/^access[_\-]s2member[_\-]ccap[_\-](.+?)\//", $req["file_download"], $m) && strlen ($ccap_req = preg_replace ("/-/", "_", $m[1])) && !$user->has_cap ("access_s2member_ccap_" . $ccap_req))
177
+ {
178
+ if ($serving) /* We only need this section when/if we're actually serving. */
179
+ wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $req["file_download"], "s2member_ccap_req" => $ccap_req)), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) . exit ();
180
+ /**/
181
+ else /* Else return false. */
182
+ return false;
183
+ }
184
+ /**/
185
+ else if ($serving || $creating) /* In either case, the following routines apply. */
186
+ {
187
+ $already_downloaded = $streaming_variation_already_downloaded = false;
188
+ $previous_file_downloads = 0; /* Here we're going to count how many downloads they have. */
189
+ $max_days_logged = c_ws_plugin__s2member_files::max_download_period (); /* Max period/days. */
190
+ $file_download_access_log = (array)get_user_option ("s2member_file_download_access_log", $user_id);
191
+ $file_download_access_arc = (array)get_user_option ("s2member_file_download_access_arc", $user_id);
192
+ $streaming_file_extns = c_ws_plugin__s2member_utils_strings::preg_quote_deep ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["streaming_file_extns"], "/");
193
+ $streaming_variations = /* Only count one streaming media file variation. */ "/\.(" . implode ("|", $streaming_file_extns) . ")#x2F;i";
194
+ /**/
195
+ foreach ($file_download_access_log as $file_download_access_log_entry_key => $file_download_access_log_entry)
196
+ {
197
+ if (strtotime ($file_download_access_log_entry["date"]) < strtotime ("-" . $max_days_logged . " days"))
198
+ {
199
+ unset($file_download_access_log[$file_download_access_log_entry_key]);
200
+ $file_download_access_arc[] = $file_download_access_log_entry;
201
+ }
202
+ else if (strtotime ($file_download_access_log_entry["date"]) >= strtotime ("-" . $file_downloads["allowed_days"] . " days"))
203
+ {
204
+ $previous_file_downloads++; /* A previous file that counts. */
205
+ /**/
206
+ if ($file_download_access_log_entry["file"] === $req["file_download"]) /* Already downloaded this file? Or another streaming variation? */
207
+ $already_downloaded = true; /* Already downloaded this file? Or another streaming variation? */
208
+ /**/
209
+ else if (preg_replace ($streaming_variations, "", $file_download_access_log_entry["file"]) === preg_replace ($streaming_variations, "", $req["file_download"]))
210
+ $already_downloaded = $streaming_variation_already_downloaded = true;
211
+ }
212
+ }
213
+ /**/
214
+ if (!$already_downloaded && !$streaming_variation_already_downloaded && !$user->has_cap ("administrator") && $previous_file_downloads >= $file_downloads["allowed"])
215
+ {
216
+ if ($serving) /* We only need this section when/if we're actually serving. */
217
+ wp_redirect (add_query_arg (urlencode_deep (array ("s2member_seeking" => "file-" . $req["file_download"])), get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"])), apply_filters ("ws_plugin__s2member_content_redirect_status", 301, get_defined_vars ())) . exit ();
218
+ /**/
219
+ else /* Else return false. */
220
+ return false;
221
+ }
222
+ /**/
223
+ else if (!$already_downloaded && !$streaming_variation_already_downloaded)
224
+ $file_download_access_log[] = array ("date" => date ("Y-m-d"), "file" => $req["file_download"]);
225
+ /**/
226
+ if ($updating_user_counter) /* By default, we do NOT update the counter when a URL is being created; but this behavior can be modified. */
227
+ {
228
+ update_user_option ($user_id, "s2member_file_download_access_arc", c_ws_plugin__s2member_utils_arrays::array_unique ($file_download_access_arc));
229
+ update_user_option ($user_id, "s2member_file_download_access_log", c_ws_plugin__s2member_utils_arrays::array_unique ($file_download_access_log));
230
+ }
231
+ }
232
+ }
233
+ }
234
+ else /* Otherwise, we're either NOT ``$checking_user``; or permission was granted with a valid File Download Key. */
235
+ {
236
+ if (!$using_amazon_storage && !file_exists ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"] . "/" . $req["file_download"]))
237
+ {
238
+ if ($serving) /* We only need this section when/if we're actually serving. */
239
+ status_header(404) . exit (_x ("404: Sorry, file not found. Please contact Support for assistance.", "s2member-front", "s2member"));
240
+ /**/
241
+ else /* Else return false. */
242
+ return false;
243
+ }
244
+ }
245
+ /**/
246
+ if ($serving || $creating) /* In either case, the following routines apply. */
247
+ {
248
+ $basename = basename ($req["file_download"]);
249
+ $mimetypes = parse_ini_file (dirname (dirname (dirname (__FILE__))) . "/includes/mime-types.ini");
250
+ $extension = strtolower (substr ($req["file_download"], strrpos ($req["file_download"], ".") + 1));
251
+ /**/
252
+ $key = ($req["file_download_key"] && is_string ($req["file_download_key"])) ? $req["file_download_key"] : false;
253
+ /**/
254
+ $stream = (isset ($req["file_stream"])) ? filter_var ($req["file_stream"], FILTER_VALIDATE_BOOLEAN) : ((in_array ($extension, preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_stream_extensions"]))) ? true : false);
255
+ $inline = (!$stream && isset ($req["file_inline"])) ? filter_var ($req["file_inline"], FILTER_VALIDATE_BOOLEAN) : (($stream || in_array ($extension, preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_inline_extensions"]))) ? true : false);
256
+ $ssl = (isset ($req["file_ssl"])) ? filter_var ($req["file_ssl"], FILTER_VALIDATE_BOOLEAN) : ((is_ssl ()) ? true : false);
257
+ $storage = ($req["file_storage"] && is_string ($req["file_storage"])) ? strtolower ($req["file_storage"]) : false;
258
+ $remote = (isset ($req["file_remote"])) ? filter_var ($req["file_remote"], FILTER_VALIDATE_BOOLEAN) : false;
259
+ /**/
260
+ $rewrite_base_guess = dirname ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["dir_url"]) . "/" . c_ws_plugin__s2member_utils_dirs::basename_dir_app_data ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"]);
261
+ $rewrite_base = ($req["file_rewrite_base"] && is_string ($req["file_rewrite_base"])) ? $req["file_rewrite_base"] : false;
262
+ $rewrite = $rewriting = (!$rewrite_base && isset ($req["file_rewrite"])) ? filter_var ($req["file_rewrite"], FILTER_VALIDATE_BOOLEAN) : (($rewrite_base) ? true : false);
263
+ /**/
264
+ $skip_confirmation = (isset ($req["skip_confirmation"])) ? filter_var ($req["skip_confirmation"], FILTER_VALIDATE_BOOLEAN) : false;
265
+ $url_to_storage_source = (isset ($req["url_to_storage_source"])) ? filter_var ($req["url_to_storage_source"], FILTER_VALIDATE_BOOLEAN) : false;
266
+ /**/
267
+ $pathinfo = (!$using_amazon_storage) ? pathinfo (($file = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"] . "/" . $req["file_download"])) : array ();
268
+ $mimetype = ($mimetypes[$extension]) ? $mimetypes[$extension] : "application/octet-stream";
269
+ $length = (!$using_amazon_storage && $file) ? filesize ($file) : -1;
270
+ /**/
271
+ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
272
+ do_action ("ws_plugin__s2member_during_file_download_access", get_defined_vars ());
273
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
274
+ /**/
275
+ if ($using_amazon_s3_storage && ($serving || ($creating && $url_to_storage_source)))
276
+ {
277
+ if ($serving) /* We only need this section when/if we're actually serving. */
278
+ wp_redirect(c_ws_plugin__s2member_files_in::amazon_s3_url ($req["file_download"], $stream, $inline, $ssl, $basename, $mimetype)) . exit ();
279
+ /**/
280
+ else /* Else return File Download URL. */
281
+ return apply_filters ("ws_plugin__s2member_file_download_access_url", c_ws_plugin__s2member_files_in::amazon_s3_url ($req["file_download"], $stream, $inline, $ssl, $basename, $mimetype), get_defined_vars ());
282
+ }
283
+ /**/
284
+ else if ($using_amazon_cf_storage && ($serving || ($creating && $url_to_storage_source)))
285
+ {
286
+ if ($serving) /* We only need this section when/if we're actually serving. */
287
+ wp_redirect(c_ws_plugin__s2member_files_in::amazon_cf_url ($req["file_download"], $stream, $inline, $ssl, $basename, $mimetype)) . exit ();
288
+ /**/
289
+ else /* Else return File Download URL. */
290
+ return apply_filters ("ws_plugin__s2member_file_download_access_url", c_ws_plugin__s2member_files_in::amazon_cf_url ($req["file_download"], $stream, $inline, $ssl, $basename, $mimetype), get_defined_vars ());
291
+ }
292
+ /**/
293
+ else if ($creating && $rewriting) /* Creating a rewrite URL, pointing to local storage. */
294
+ {
295
+ $url = ($rewrite_base) ? rtrim ($rewrite_base, "/") : rtrim ($rewrite_base_guess, "/");
296
+ $url .= (isset ($req["file_download_key"])) ? (($key) ? "/s2member-file-download-key-" . $key : "") : "";
297
+ $url .= (isset ($req["file_stream"])) ? (($stream) ? "/s2member-file-stream" : "/s2member-file-stream-no") : "";
298
+ $url .= (isset ($req["file_inline"])) ? (($inline) ? "/s2member-file-inline" : "/s2member-file-inline-no") : "";
299
+ $url .= (isset ($req["file_storage"])) ? (($storage) ? "/s2member-file-storage-" . $storage : "") : "";
300
+ $url .= (isset ($req["file_remote"])) ? (($remote) ? "/s2member-file-remote" : "/s2member-file-remote-no") : "";
301
+ $url .= (isset ($req["skip_confirmation"])) ? (($skip_confirmation) ? "/s2member-skip-confirmation" : "/s2member-skip-confirmation-no") : "";
302
+ /**/
303
+ $url = $url . "/" . $req["file_download"]; /* File Download Access URL via `mod_rewrite` functionality. */
304
+ $url = ($ssl) ? preg_replace ("/^https?/", "https", $url) : preg_replace ("/^https?/", "http", $url);
305
+ /**/
306
+ return apply_filters ("ws_plugin__s2member_file_download_access_url", $url, get_defined_vars ());
307
+ }
308
+ /**/
309
+ else if ($creating) /* Else we're creating a URL w/ a query-string, pointing to local storage. */
310
+ {
311
+ $url = (isset ($req["file_download_key"])) ? (($key) ? "&s2member_file_download_key=" . urlencode ($key) : "") : "";
312
+ $url .= (isset ($req["file_stream"])) ? (($stream) ? "&s2member_file_stream=yes" : "&s2member_file_stream=no") : "";
313
+ $url .= (isset ($req["file_inline"])) ? (($inline) ? "&s2member_file_inline=yes" : "&s2member_file_inline=no") : "";
314
+ $url .= (isset ($req["file_storage"])) ? (($storage) ? "&s2member_file_storage=" . urlencode ($storage) : "") : "";
315
+ $url .= (isset ($req["file_remote"])) ? (($remote) ? "&s2member_file_remote=yes" : "&s2member_file_remote=no") : "";
316
+ $url .= (isset ($req["skip_confirmation"])) ? (($skip_confirmation) ? "&s2member_skip_confirmation=yes" : "&s2member_skip_confirmation=no") : "";
317
+ /**/
318
+ $url = site_url ("/?" . ltrim ($url . "&s2member_file_download=/" . urlencode ($req["file_download"]), "&"));
319
+ $url = ($ssl) ? preg_replace ("/^https?/", "https", $url) : preg_replace ("/^https?/", "http", $url);
320
+ /**/
321
+ return apply_filters ("ws_plugin__s2member_file_download_access_url", $url, get_defined_vars ());
322
+ }
323
+ /**/
324
+ else /* Else, ``if ($serving)`` , use local storage option (default). */
325
+ {
326
+ status_header(200);
327
+ /**/
328
+ header("Accept-Ranges: none");
329
+ header("Content-Encoding: none");
330
+ header("Content-Type: " . $mimetype);
331
+ header("Expires: " . gmdate ("D, d M Y H:i:s", strtotime ("-1 week")) . " GMT");
332
+ header("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT");
333
+ header("Cache-Control: no-cache, must-revalidate, max-age=0");
334
+ header ("Cache-Control: post-check=0, pre-check=0", false);
335
+ header("Pragma: no-cache");
336
+ /**/
337
+ header('Content-Disposition: ' . (($inline) ? "inline" : "attachment") . '; filename="' . $basename . '"');
338
+ /**/
339
+ if ($length && apply_filters ("ws_plugin__s2member_chunk_file_downloads", true, get_defined_vars ()) && is_resource ($resource = fopen ($file, "rb")))
340
+ {
341
+ $_chunk_size = apply_filters ("ws_plugin__s2member_chunk_file_downloads_w_chunk_size", 2097152, get_defined_vars ());
342
+ $_chunk_w_content_length = (stripos (PHP_OS, "win") === 0 && (!function_exists ("apache_get_version") || apache_get_version () === false)) ? false : true;
343
+ /**/
344
+ /* Windows® IIS doesn't seem to like it when both `Content-Length` and `Transfer-Encoding: chunked` are sent together. */
345
+ if (apply_filters ("ws_plugin__s2member_chunk_file_downloads_w_content_length", $_chunk_w_content_length, get_defined_vars ()))
346
+ header("Content-Length: " . $length);
347
+ /**/
348
+ header("Transfer-Encoding: chunked"); /* Uses `Transfer-Encoding: chunked` for simulated streaming. */
349
+ /**/
350
+ while (!feof ($resource) && ($chunk_size = strlen ($data = fread ($resource, $_chunk_size))))
351
+ eval('echo dechex ($chunk_size) . "\r\n". $data . "\r\n"; @flush ();');
352
+ /**/
353
+ fclose($resource) . exit ("0\r\n\r\n");
354
+ }
355
+ else if ($length) /* Else, use: ``file_get_contents()``. */
356
+ {
357
+ header("Content-Length: " . $length) . exit (file_get_contents ($file));
358
+ }
359
+ else /* Else, we have an empty file with no length. */
360
+ {
361
+ header("Content-Length: 0") . exit ();
362
+ }
363
+ }
364
+ }
365
+ }
366
+ /**/
367
+ else if ($serving && $req["file_download"]) /* We only need this section when/if we're actually serving. */
368
+ status_header(503) . exit (_x ("503: Access denied. Invalid File Download specs.", "s2member-front", "s2member"));
369
+ /**/
370
+ else if ($creating) /* We only need this section when/if we're creating a URL. */
371
+ return false;
372
+ /**/
373
+ do_action ("ws_plugin__s2member_after_file_download_access", get_defined_vars ());
374
+ /**/
375
+ return ($creating) ? false : null; /* If creating, false. */
376
+ }
377
+ /**
378
+ * Generates a File Download URL for access to a file protected by s2Member.
379
+ *
380
+ * @package s2Member\Files
381
+ * @since 110926
382
+ *
383
+ * @param array $config Required. This is an array of configuration options associated with permissions being checked against the current User/Member; and also the actual URL generated by this routine.
384
+ * Possible ``$config`` array elements: `file_download` *(required)*, `file_download_key`, `file_stream`, `file_inline`, `file_storage`, `file_remote`, `file_ssl`, `file_rewrite`, `file_rewrite_base`, `skip_confirmation`, `url_to_storage_source`, `count_against_user`, `ignore_user`.
385
+ * @return str A File Download URL string on success; or an array on success, with elements `streamer`, `file`, `url` when/if ``$get_streamer_array`` is true; else false on any type of failure.
386
+ * Note: by default, this function DOES consider the current User/Member. If `ignore_user` is NOT set, or is set to false, this function MAY very well return false, when/if the current User/Member is NOT allowed access to the `file_download`, based on configuration.
387
+ */
388
+ public static function create_file_download_url ($config = FALSE, $get_streamer_array = FALSE)
389
+ {
390
+ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
391
+ do_action ("ws_plugin__s2member_before_create_file_download_url", get_defined_vars ()); /* Be VERY careful, if you use this Hook. */
392
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
393
+ /**/
394
+ $config = (is_array ($config)) ? $config : array (); /* This absolutely MUST be an array. */
395
+ /**/
396
+ $config["file_download"] = (isset ($config["file_download"]) && is_string ($config["file_download"])) ? trim ($config["file_download"], "/") : @$config["file_download"];
397
+ $config["file_download_key"] = (isset ($config["file_download"]) && is_string ($config["file_download"]) && !empty ($config["file_download_key"])) /* Automatically generate a File Download Key here? */
398
+ ? c_ws_plugin__s2member_files::file_download_key ($config["file_download"], ((in_array ($config["file_download_key"], array ("ip-forever", "universal", "cache-compatible"))) ? $config["file_download_key"] : false)) : @$config["file_download_key"];
399
+ /**/
400
+ $config["url_to_storage_source"] = /* Force a streaming URL here via ``$get_streamer_array``? */ ($get_streamer_array) ? true : @$config["url_to_storage_source"];
401
+ $config["file_stream"] = /* Force a streaming URL here via ``$get_streamer_array``? */ ($get_streamer_array) ? true : @$config["file_stream"];
402
+ /**/
403
+ if (($_url = c_ws_plugin__s2member_files_in::check_file_download_access (($create_file_download_url = $config))) /* Successfully created a URL to the file? */)
404
+ {
405
+ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
406
+ do_action ("ws_plugin__s2member_during_create_file_download_url", get_defined_vars ()); /* Be VERY careful, if you use this Hook. */
407
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
408
+ /**/
409
+ $extension = strtolower (substr ($config["file_download"], strrpos ($config["file_download"], ".") + 1));
410
+ $streaming = (isset ($config["file_stream"])) ? filter_var ($config["file_stream"], FILTER_VALIDATE_BOOLEAN) : ((in_array ($extension, preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_stream_extensions"]))) ? true : false);
411
+ $ssl = (isset ($config["file_ssl"])) ? filter_var ($config["file_ssl"], FILTER_VALIDATE_BOOLEAN) : ((is_ssl ()) ? true : false);
412
+ /**/
413
+ if ($get_streamer_array && $streaming && ($cfx = "/cfx/st") && ($cfx_pos = strpos ($_url, $cfx)) !== false && ($streamer = substr ($_url, 0, $cfx_pos + strlen ($cfx))) && ($url = c_ws_plugin__s2member_files_in::check_file_download_access (array_merge ($config, array ("file_stream" => false, "ignore_user" => true)))))
414
+ $return = array ("streamer" => $streamer, "file" => preg_replace ("/^" . preg_quote ($streamer, "/") . "\//", "", $_url), "url" => preg_replace ("/^.+?\:/", (($ssl) ? "https:" : "http:"), $url));
415
+ /**/
416
+ else if ($get_streamer_array && $streaming && is_array ($ups = @parse_url ($_url)) && ($streamer = $ups["scheme"] . "://" . $ups["host"] . ((!empty ($ups["port"])) ? ":" . $ups["port"] : "")) && ($url = c_ws_plugin__s2member_files_in::check_file_download_access (array_merge ($config, array ("file_stream" => false, "ignore_user" => true)))))
417
+ $return = array ("streamer" => $streamer, "file" => preg_replace ("/^" . preg_quote ($streamer, "/") . "\//", "", $_url), "url" => preg_replace ("/^.+?\:/", (($ssl) ? "https:" : "http:"), $url));
418
+ /**/
419
+ else if ($get_streamer_array) /* Else, we MUST return false here, unable to acquire streamer/file. */
420
+ $return = false; /* We MUST return false here, unable to acquire streamer. */
421
+ /**/
422
+ else /* Else return URL string ( ``$get_streamer_array`` is false ). */
423
+ $return = $_url; /* Else return URL string. */
424
+ }
425
+ /**/
426
+ return apply_filters ("ws_plugin__s2member_create_file_download_url", ((isset ($return)) ? $return : false), get_defined_vars ());
427
+ }
428
+ /**
429
+ * Checks Header Authorization for Remote File Downloads.
430
+ *
431
+ * @package s2Member\Files
432
+ * @since 110926
433
+ *
434
+ * @attaches-to: ``add_filter("ws_plugin__s2member_check_file_download_access_user");``
435
+ *
436
+ * @param obj $user Expects a WP_User object passed in by the Filter.
437
+ * @return obj A `WP_User` object, possibly obtained through Header Authorization.
438
+ */
439
+ public static function check_file_remote_authorization ($user = FALSE)
440
+ {
441
+ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
442
+ do_action ("ws_plugin__s2member_before_check_file_remote_authorization", get_defined_vars ());
443
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
444
+ /**/
445
+ $_g = c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep (((!empty ($_GET)) ? $_GET : array ())));
446
+ /**/
447
+ if (!is_object ($user) && isset ($_g["s2member_file_remote"]) && filter_var ($_g["s2member_file_remote"], FILTER_VALIDATE_BOOLEAN))
448
+ {
449
+ do_action ("ws_plugin__s2member_during_check_file_remote_authorization_before", get_defined_vars ());
450
+ /**/
451
+ if (empty ($_SERVER["PHP_AUTH_USER"]) || empty ($_SERVER["PHP_AUTH_PW"]) || !user_pass_ok ($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]))
452
+ {
453
+ header('WWW-Authenticate: Basic realm="' . _x ("Members Only", "s2member-front", "s2member") . '"');
454
+ status_header(401); /* Unauthorized status header. */
455
+ exit(_x ("Access Denied", "s2member-front", "s2member"));
456
+ }
457
+ else if (is_object ($_user = new WP_User ($_SERVER["PHP_AUTH_USER"])) && !empty ($_user->ID))
458
+ $user = $_user; /* Now assign ``$user``. */
459
+ /**/
460
+ do_action ("ws_plugin__s2member_during_check_file_remote_authorization_after", get_defined_vars ());
461
+ }
462
+ /**/
463
+ return apply_filters ("ws_plugin__s2member_check_file_remote_authorization", $user, get_defined_vars ());
464
+ }
465
+ /**
466
+ * Checks a File Download Key for validity.
467
+ *
468
+ * @package s2Member\Files
469
+ * @since 110926
470
+ *
471
+ * @param str $file Input File Download to validate.
472
+ * @param str $key Input File Download Key to validate.
473
+ * @return bool True if valid, else false.
474
+ */
475
+ public static function check_file_download_key ($file = FALSE, $key = FALSE)
476
+ {
477
+ eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$__v;');
478
+ do_action ("_ws_plugin__s2member_before_check_file_download_key", get_defined_vars ());
479
+ unset ($__refs, $__v); /* Unset defined __refs, __v. */
480
+ /**/
481
+ if ($file && is_string ($file) && ($file = trim ($file, "/")) && $key && is_string ($key)) /* Requirements to properly validate. */
482
+ {
483
+ if ($key === c_ws_plugin__s2member_files::file_download_key ($file) || $key === c_ws_plugin__s2member_files::file_download_key ("/" . $file))
484
+ $valid = true; /* File Download Key is valid. */
485
+ else if ($key === c_ws_plugin__s2member_files::file_download_key ($file, "ip-forever") || $key === c_ws_plugin__s2member_files::file_download_key ("/" . $file, "ip-forever"))
486
+ $valid = true; /* File Download Key is valid. */
487
+ else if ($key === c_ws_plugin__s2member_files::file_download_key ($file, "universal") || $key === c_ws_plugin__s2member_files::file_download_key ("/" . $file, "universal"))
488
+ $valid = true; /* File Download Key is valid. */
489
+ }
490
+ /**/
491
+ return apply_filters ("ws_plugin__s2member_check_file_download_key", ((isset ($valid) && $valid) ? true : false), get_defined_vars ());
492
+ }
493
+ /**
494
+ * Creates an Amazon® S3 HMAC-SHA1 signature.
495
+ *
496
+ * @package s2Member\Files
497
+ * @since 110524RC
498
+ *
499
+ * @param str $string Input string/data, to be signed by this routine.
500
+ * @return str An HMAC-SHA1 signature for Amazon® S3.
501
+ */
502
+ public static function amazon_s3_sign ($string = FALSE)
503
+ {
504
+ $s3c["secret_key"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_secret_key"];
505
+ /**/
506
+ $s3_signature = str_pad (((strlen ($s3c["secret_key"]) > 64) ? pack ('H*', sha1 ($s3c["secret_key"])) : $s3c["secret_key"]), 64, chr (0x00));
507
+ return pack ('H*', sha1 (($s3_signature ^ str_repeat (chr (0x5c), 64)) . pack ('H*', sha1 (($s3_signature ^ str_repeat (chr (0x36), 64)) . (string)$string))));
508
+ }
509
+ /**
510
+ * Creates an Amazon® S3 HMAC-SHA1 signature URL.
511
+ *
512
+ * @package s2Member\Files
513
+ * @since 110926
514
+ *
515
+ * @param str $file Input file path, to be signed by this routine.
516
+ * @param bool $stream Is this resource file to be served as streaming media?
517
+ * @param bool $inline Is this resource file to be served inline, or no?
518
+ * @param bool $ssl Is this resource file to be served via SSL, or no?
519
+ * @param str $basename The absolute basename of the resource file.
520
+ * @param str $mimetype The MIME content-type of the resource file.
521
+ * @return str An HMAC-SHA1 signature URL for Amazon® S3.
522
+ */
523
+ public static function amazon_s3_url ($file = FALSE, $stream = FALSE, $inline = FALSE, $ssl = FALSE, $basename = FALSE, $mimetype = FALSE)
524
+ {
525
+ $file = trim ((string)$file, "/"); /* Trim / force string. */
526
+ /**/
527
+ foreach ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"] as $option => $option_value)
528
+ if (preg_match ("/^amazon_s3_files_/", $option) && ($option = preg_replace ("/^amazon_s3_files_/", "", $option)))
529
+ $s3c[$option] = $option_value;
530
+ /**/
531
+ $s3c["expires"] = strtotime ("+" . apply_filters ("ws_plugin__s2member_amazon_s3_file_expires_time", "30 seconds", get_defined_vars ()));
532
+ /**/
533
+ $s3_file = add_query_arg (urlencode_deep (array ("response-cache-control" => ($s3_cache_control = "no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0"), "response-content-disposition" => ($s3_content_disposition = (((bool)$inline) ? "inline" : "attachment") . '; filename="' . (string)$basename . '"'), "response-content-type" => ($s3_content_type = (string)$mimetype), "response-expires" => ($s3_expires = gmdate ("D, d M Y H:i:s", strtotime ("-1 week")) . " GMT"))), "/" . $file);
534
+ $s3_raw_file = add_query_arg (array ("response-cache-control" => $s3_cache_control, "response-content-disposition" => $s3_content_disposition, "response-content-type" => $s3_content_type, "response-expires" => $s3_expires), "/" . $file);
535
+ $s3_signature = base64_encode (c_ws_plugin__s2member_files_in::amazon_s3_sign ("GET\n\n\n" . $s3c["expires"] . "\n" . "/" . $s3c["bucket"] . $s3_raw_file));
536
+ /**/
537
+ $s3_url = ((strtolower ($s3c["bucket"]) !== $s3c["bucket"])) ? "http" . (($ssl) ? "s" : "") . "://s3.amazonaws.com/" . $s3c["bucket"] . $s3_file : "http" . (($ssl) ? "s" : "") . "://" . $s3c["bucket"] . ".s3.amazonaws.com" . $s3_file;
538
+ return add_query_arg (urlencode_deep (array ("AWSAccessKeyId" => $s3c["access_key"], "Expires" => $s3c["expires"], "Signature" => $s3_signature)), $s3_url);
539
+ }
540
+ /**
541
+ * Auto-configures an Amazon® S3 Bucket's ACLs.
542
+ *
543
+ * @package s2Member\Files
544
+ * @since 110926
545
+ *
546
+ * @return array Array containing a true `success` element on success, else a failure array.
547
+ * Failure array will contain a failure `code`, and a failure `message`.
548
+ */
549
+ public static function amazon_s3_auto_configure_acls ()
550
+ {
551
+ foreach ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"] as $option => $option_value)
552
+ if (preg_match ("/^amazon_s3_files_/", $option) && ($option = preg_replace ("/^amazon_s3_files_/", "", $option)))
553
+ $s3c[$option] = $option_value;
554
+ /**/
555
+ $cfc["distros_s3_access_id"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_cf_files_distros_s3_access_id"];
556
+ /**/
557
+ if ($s3c["bucket"] && $s3c["access_key"] && $s3c["secret_key"]) /* Must have Amazon® S3 Bucket/Keys. */
558
+ {
559
+ $s3_date = gmdate ("D, d M Y H:i:s") . " GMT";
560
+ $s3_location = ((strtolower ($s3c["bucket"]) !== $s3c["bucket"])) ? "/" . $s3c["bucket"] . "/?acl" : "/?acl";
561
+ $s3_domain = ((strtolower ($s3c["bucket"]) !== $s3c["bucket"])) ? "s3.amazonaws.com" : $s3c["bucket"] . ".s3.amazonaws.com";
562
+ $s3_signature = base64_encode (c_ws_plugin__s2member_files_in::amazon_s3_sign ("GET\n\n\n" . $s3_date . "\n/" . $s3c["bucket"] . "/?acl"));
563
+ $s3_args = array ("method" => "GET", "headers" => array ("Host" => $s3_domain, "Date" => $s3_date, "Authorization" => "AWS " . $s3c["access_key"] . ":" . $s3_signature));
564
+ /**/
565
+ if (($s3_response = c_ws_plugin__s2member_utils_urls::remote ("https://" . $s3_domain . $s3_location, false, array_merge ($s3_args, array ("timeout" => 20)), "array")) && $s3_response["code"] === 200)
566
+ {
567
+ if (preg_match ("/\<Owner\>(.+?)\<\/Owner\>/is", $s3_response["body"], $s3_owner_tag) && preg_match ("/\<ID\>(.+?)\<\/ID\>/is", $s3_owner_tag[1], $s3_owner_id_tag) && (preg_match ("/\<DisplayName\>(.*?)\<\/DisplayName\>/is", $s3_owner_tag[1], $s3_owner_display_name_tag) || ($s3_owner_display_name_tag = array ("-", "Owner"))))
568
+ {
569
+ $s3_owner = array ("access_id" => trim ($s3_owner_id_tag[1]), "display_name" => trim ($s3_owner_display_name_tag[1]));
570
+ $s3_acls_xml = '<AccessControlPolicy><Owner><ID>' . esc_html ($s3_owner["access_id"]) . '</ID><DisplayName>' . esc_html ($s3_owner["display_name"]) . '</DisplayName></Owner><AccessControlList><Grant><Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser"><ID>' . esc_html ($s3_owner["access_id"]) . '</ID><DisplayName>' . esc_html ($s3_owner["display_name"]) . '</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant>' . (($cfc["distros_s3_access_id"]) ? '<Grant><Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser"><ID>' . esc_html ($cfc["distros_s3_access_id"]) . '</ID><DisplayName>s2Member/CloudFront</DisplayName></Grantee><Permission>READ</Permission></Grant>' : '') . '</AccessControlList></AccessControlPolicy>';
571
+ $s3_signature = base64_encode (c_ws_plugin__s2member_files_in::amazon_s3_sign ("PUT\n\napplication/xml\n" . $s3_date . "\n/" . $s3c["bucket"] . "/?acl"));
572
+ $s3_args = array ("method" => "PUT", "body" => $s3_acls_xml, "headers" => array ("Host" => $s3_domain, "Content-Type" => "application/xml", "Date" => $s3_date, "Authorization" => "AWS " . $s3c["access_key"] . ":" . $s3_signature));
573
/**/
574
+ if (($s3_response = c_ws_plugin__s2member_utils_urls::remote ("https://" . $s3_domain . $s3_location, false, array_merge ($s3_args, array ("timeout" => 20)), "array")) && $s3_response["code"] === 200)
575
{
576
+ $s3_location = ((strtolower ($s3c["bucket"]) !== $s3c["bucket"])) ? "/" . $s3c["bucket"] . "/?policy" : "/?policy";
577
+ $s3_policy_json = '{"Version":"2008-10-17","Id":"' . md5 ("s2Member/CloudFront") . '","Statement":[{"Sid":"s2Member/CloudFront","Effect":"Allow","Principal":{"CanonicalUser":"' . c_ws_plugin__s2member_utils_strings::esc_dq ($cfc["distros_s3_access_id"]) . '"},"Action":"s3:GetObject","Resource":"arn:aws:s3:::' . c_ws_plugin__s2member_utils_strings::esc_dq ($s3c["bucket"]) . '/*"}]}';
578
+ $s3_signature = base64_encode (c_ws_plugin__s2member_files_in::amazon_s3_sign ("PUT\n\napplication/json\n" . $s3_date . "\n/" . $s3c["bucket"] . "/?policy"));
579
+ $s3_args = array ("method" => "PUT", "body" => $s3_policy_json, "headers" => array ("Host" => $s3_domain, "Content-Type" => "application/json", "Date" => $s3_date, "Authorization" => "AWS " . $s3c["access_key"] . ":" . $s3_signature));
580
/**/
581
+ if (!$cfc["distros_s3_access_id"] || (($s3_response = c_ws_plugin__s2member_utils_urls::remote ("https://" . $s3_domain . $s3_location, false, array_merge ($s3_args, array ("timeout" => 20)), "array")) && ($s3_response["code"] === 200 || $s3_response["code"] === 204 /* Also OK. */)))
582
{
583
+ $s3_location = ((strtolower ($s3c["bucket"]) !== $s3c["bucket"])) ? "/" . $s3c["bucket"] . "/crossdomain.xml" : "/crossdomain.xml";
584
+ $s3_policy_xml = trim (c_ws_plugin__s2member_utilities::evl (file_get_contents (dirname (dirname (__FILE__)) . "/templates/cfg-files/s2-cross-xml.php")));
585
+ $s3_signature = base64_encode (c_ws_plugin__s2member_files_in::amazon_s3_sign ("PUT\n\ntext/xml\n" . $s3_date . "\nx-amz-acl:public-read\n/" . $s3c["bucket"] . "/crossdomain.xml"));
586
+ $s3_args = array ("method" => "PUT", "body" => $s3_policy_xml, "headers" => array ("Host" => $s3_domain, "Content-Type" => "text/xml", "Date" => $s3_date, "X-Amz-Acl" => "public-read", "Authorization" => "AWS " . $s3c["access_key"] . ":" . $s3_signature));
587
+ /**/
588
+ if (($s3_response = c_ws_plugin__s2member_utils_urls::remote ("https://" . $s3_domain . $s3_location, false, array_merge ($s3_args, array ("timeout" => 20)), "array")) && $s3_response["code"] === 200)
589
+ return array ("success" => true, "code" => null, "message" => null); /* Successfully configured Amazon® S3 Bucket ACLs and Policy. */
590
+ /**/
591
+ else if (isset ($s3_response["code"], $s3_response["message"]))
592
+ /* translators: In this translation, `%s` may be filled with an English message, which comes from the Amazon® S3 API call. Feel free to exclude `%s` if you like. */
593
+ return array ("success" => false, "code" => $s3_response["code"], "message" => sprintf (_x ("Unable to update existing Amazon® S3 Cross-Domain Policy. %s", "s2member-admin", "s2member"), $s3_response["message"]));
594
+ /**/
595
+ else /* Else, we use a default error code and message. */
596
+ return array ("success" => false, "code" => -94, "message" => _x ("Unable to update existing Amazon® S3 Cross-Domain Policy. Connection failed.", "s2member-admin", "s2member"));
597
}
598
+ else if (isset ($s3_response["code"], $s3_response["message"]))
599
+ /* translators: In this translation, `%s` may be filled with an English message, which comes from the Amazon® S3 API call. Feel free to exclude `%s` if you like. */
600
+ return array ("success" => false, "code" => $s3_response["code"], "message" => sprintf (_x ("Unable to update existing Amazon® S3 Bucket Policy. %s", "s2member-admin", "s2member"), $s3_response["message"]));
601
/**/
602
+ else /* Else, we use a default error code and message. */
603
+ return array ("success" => false, "code" => -95, "message" => _x ("Unable to update existing Amazon® S3 Bucket Policy. Connection failed.", "s2member-admin", "s2member"));
604
+ }
605
+ else if (isset ($s3_response["code"], $s3_response["message"]))
606
+ /* translators: In this translation, `%s` may be filled with an English message, which comes from the Amazon® S3 API call. Feel free to exclude `%s` if you like. */
607
+ return array ("success" => false, "code" => $s3_response["code"], "message" => sprintf (_x ("Unable to update existing Amazon® S3 Bucket ACLs. %s", "s2member-admin", "s2member"), $s3_response["message"]));
608
+ /**/
609
+ else /* Else, we use a default error code and message. */
610
+ return array ("success" => false, "code" => -96, "message" => _x ("Unable to update existing Amazon® S3 Bucket ACLs. Connection failed.", "s2member-admin", "s2member"));
611
+ }
612
+ else /* Else, we use a default error code and message. */
613
+ return array ("success" => false, "code" => -97, "message" => _x ("Unable to acquire/read existing Amazon® S3 Bucket ACLs. Unexpected response.", "s2member-admin", "s2member"));
614
+ }
615
+ else if (isset ($s3_response["code"], $s3_response["message"]))
616
+ /* translators: In this translation, `%s` may be filled with an English message, which comes from the Amazon® S3 API call. Feel free to exclude `%s` if you like. */
617
+ return array ("success" => false, "code" => $s3_response["code"], "message" => sprintf (_x ("Unable to acquire existing Amazon® S3 Bucket ACLs. %s", "s2member-admin", "s2member"), $s3_response["message"]));
618
+ /**/
619
+ else /* Else, we use a default error code and message. */
620
+ return array ("success" => false, "code" => -98, "message" => _x ("Unable to acquire existing Amazon® S3 Bucket ACLs. Connection failed.", "s2member-admin", "s2member"));
621
+ }
622
+ else /* Else, we use a default error code and message. */
623
+ return array ("success" => false, "code" => -99, "message" => _x ("Unable to auto-configure existing Amazon® S3 Bucket ACLs. Incomplete Amazon® S3 configuration options. Missing one of: Amazon® S3 Bucket, Access Key, or Secret Key.", "s2member-admin", "s2member"));
624
+ }
625
+ /**
626
+ * Creates an Amazon® CloudFront HMAC-SHA1 signature.
627
+ *
628
+ * @package s2Member\Files
629
+ * @since 110926
630
+ *
631
+ * @param str $string Input string/data, to be signed by this routine.
632
+ * @return str An HMAC-SHA1 signature for Amazon® CloudFront.
633
+ */
634
+ public static function amazon_cf_sign ($string = FALSE)
635
+ {
636
+ $cfc["secret_key"] = $s3c["secret_key"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_secret_key"];
637
+ /**/
638
+ $cf_signature = str_pad (((strlen ($cfc["secret_key"]) > 64) ? pack ('H*', sha1 ($cfc["secret_key"])) : $cfc["secret_key"]), 64, chr (0x00));
639
+ return pack ('H*', sha1 (($cf_signature ^ str_repeat (chr (0x5c), 64)) . pack ('H*', sha1 (($cf_signature ^ str_repeat (chr (0x36), 64)) . (string)$string))));
640
+ }
641
+ /**
642
+ * Creates an Amazon® CloudFront RSA-SHA1 signature.
643
+ *
644
+ * @package s2Member\Files
645
+ * @since 110926
646
+ *
647
+ * @param str $string Input string/data, to be signed by this routine.
648
+ * @return str|bool An RSA-SHA1 signature for Amazon® CloudFront, else false on failure.
649
+ */
650
+ public static function amazon_cf_rsa_sign ($string = FALSE)
651
+ {
652
+ $cfc["private_key"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_cf_files_private_key"];
653
+ /**/
654
+ if (stripos (PHP_SAPI, "apache") !== false) /* PHP is running as an Apache module? */
655
+ if ( /* Some `mod_php` installs have issues with OpenSSL version conflicts. See: <http://www.apachelounge.com/viewtopic.php?t=4180>. */
656
+ ($signature = c_ws_plugin__s2member_files_in::amazon_cf_rsa_shell_sign ($string)) /* Also try some other OpenSSL locations on Windows®. */
657
+ || (stripos (PHP_OS, "win") === 0 && ($signature = c_ws_plugin__s2member_files_in::amazon_cf_rsa_shell_sign ($string, "C:\openssl-win32\bin\openssl.exe"))) #
658
+ || (stripos (PHP_OS, "win") === 0 && ($signature = c_ws_plugin__s2member_files_in::amazon_cf_rsa_shell_sign ($string, "C:\openssl-win64\bin\openssl.exe"))))
659
+ return $signature;
660
+ /**/
661
+ if (function_exists ("openssl_get_privatekey") && function_exists ("openssl_sign") && is_resource ($private_key = openssl_get_privatekey ($cfc["private_key"])))
662
+ openssl_sign ((string)$string, $signature, $private_key, OPENSSL_ALGO_SHA1) . openssl_free_key ($private_key);
663
+ /**/
664
+ else if (function_exists ("shell_exec")) /* Last ditch effort here. */
665
+ $signature = c_ws_plugin__s2member_files_in::amazon_cf_rsa_shell_sign ($string);
666
+ /**/
667
+ return (!empty ($signature)) ? $signature : false;
668
+ }
669
+ /**
670
+ * Creates an Amazon® CloudFront RSA-SHA1 signature via ``shell_exec()`` to `openssl`.
671
+ *
672
+ * @package s2Member\Files
673
+ * @since 110926
674
+ *
675
+ * @param str $string Input string/data, to be signed by this routine.
676
+ * @param str $openssl Optional. A specific absolute path to OpenSSL application.
677
+ * @return str|bool An RSA-SHA1 signature for Amazon® CloudFront, else false on failure.
678
+ */
679
+ public static function amazon_cf_rsa_shell_sign ($string = FALSE, $openssl = FALSE)
680
+ {
681
+ $cfc["private_key"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_cf_files_private_key"];
682
+ /**/
683
+ if (function_exists ("shell_exec") && ($openssl = (($openssl && is_string ($openssl)) ? $openssl : "openssl")) && ($esa = "escapeshellarg"))
684
+ {
685
+ file_put_contents (($cf_string_file = get_temp_dir () . wp_unique_filename (get_temp_dir (), md5 (time () . "cf-string") . ".tmp")), (string)$string);
686
+ file_put_contents (($cf_private_key_file = get_temp_dir () . wp_unique_filename (get_temp_dir (), md5 (time () . "cf-private-key") . ".tmp")), $cfc["private_key"]);
687
+ file_put_contents (($cf_rsa_sha1_sig_file = get_temp_dir () . wp_unique_filename (get_temp_dir (), md5 (time () . "cf-rsa-sha1-signature-file") . ".tmp")), "");
688
+ /**/
689
+ @shell_exec($esa ($openssl) . " sha1 -sign " . $esa ($cf_private_key_file) . " -out " . $esa ($cf_rsa_sha1_sig_file) . " " . $esa ($cf_string_file));
690
+ $signature = trim (file_get_contents ($cf_rsa_sha1_sig_file)); /* Now try to obtain signature file contents. */
691
+ unlink($cf_rsa_sha1_sig_file) . unlink ($cf_private_key_file) . unlink ($cf_string_file); /* Cleanup. */
692
+ }
693
+ /**/
694
+ return (!empty ($signature)) ? $signature : false;
695
+ }
696
+ /**
697
+ * Creates an Amazon® CloudFront RSA-SHA1 signature URL.
698
+ *
699
+ * @package s2Member\Files
700
+ * @since 110926
701
+ *
702
+ * @param str $file Input file path, to be signed by this routine.
703
+ * @param bool $stream Is this resource file to be served as streaming media?
704
+ * @param bool $inline Is this resource file to be served inline, or no?
705
+ * @param bool $ssl Is this resource file to be served via SSL, or no?
706
+ * @param str $basename The absolute basename of the resource file.
707
+ * @param str $mimetype The MIME content-type of the resource file.
708
+ * @return str An RSA-SHA1 signature URL for Amazon® CloudFront.
709
+ */
710
+ public static function amazon_cf_url ($file = FALSE, $stream = FALSE, $inline = FALSE, $ssl = FALSE, $basename = FALSE, $mimetype = FALSE)
711
+ {
712
+ $file = trim ((string)$file, "/"); /* Trim / force string. */
713
+ /**/
714
+ foreach ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"] as $option => $option_value)
715
+ if (preg_match ("/^amazon_cf_files_/", $option) && ($option = preg_replace ("/^amazon_cf_files_/", "", $option)))
716
+ $cfc[$option] = $option_value;
717
+ /**/
718
+ $cfc["expires"] = strtotime ("+" . apply_filters ("ws_plugin__s2member_amazon_cf_file_expires_time", "24 hours", get_defined_vars ()));
719
+ /**/
720
+ $cf_extn = strtolower (substr ($file, strrpos ($file, ".") + 1)); /* Parses the file extension out so we can scan it in some special scenarios. */
721
+ $cf_stream_extn_resource_exclusions = array_unique ((array)apply_filters ("ws_plugin__s2member_amazon_cf_file_streaming_extension_resource_exclusions", array ("mp3" /* MP3 files should NOT include an extension in their resource reference. */), get_defined_vars ()));
722
+ $cf_resource = ($stream) ? ((in_array ($cf_extn, $cf_stream_extn_resource_exclusions)) ? substr ($file, 0, strrpos ($file, ".")) : $file) : "http" . (($ssl) ? "s" : "") . "://" . (($cfc["distro_downloads_cname"]) ? $cfc["distro_downloads_cname"] : $cfc["distro_downloads_dname"]) . "/" . $file;
723
+ $cf_url = ($stream) ? "rtmp" . (($ssl) ? "e" : "") . "://" . (($cfc["distro_streaming_cname"]) ? $cfc["distro_streaming_cname"] : $cfc["distro_streaming_dname"]) . "/cfx/st/" . $file : "http" . (($ssl) ? "s" : "") . "://" . (($cfc["distro_downloads_cname"]) ? $cfc["distro_downloads_cname"] : $cfc["distro_downloads_dname"]) . "/" . $file;
724
+ $cf_ip_res = (stripos ($_SERVER["HTTP_HOST"], "localhost") === false && strpos ($_SERVER["HTTP_HOST"], "127.0.0.1") === false && (!defined ("LOCALHOST") || !LOCALHOST)) ? true : false; /* Don NOT restrict access to a particular IP during `localhost` development. The IP will NOT be the same one Amazon® CloudFront sees ( so will NOT jive ). */
725
+ $cf_policy = '{"Statement":[{"Resource":"' . c_ws_plugin__s2member_utils_strings::esc_dq ($cf_resource) . '","Condition":{' . (($cf_ip_res) ? '"IpAddress":{"AWS:SourceIp":"' . c_ws_plugin__s2member_utils_strings::esc_dq ($_SERVER["REMOTE_ADDR"]) . '/32"},' : '') . '"DateLessThan":{"AWS:EpochTime":' . (int)$cfc["expires"] . '}}}]}';
726
+ /**/
727
+ $cf_signature = c_ws_plugin__s2member_files_in::amazon_cf_rsa_sign ($cf_policy);
728
+ $cf_base64_url_safe_policy = c_ws_plugin__s2member_utils_strings::base64_url_safe_encode ($cf_policy, array ("+", "=", "/"), array ("-", "_", "~"), false);
729
+ $cf_base64_url_safe_signature = c_ws_plugin__s2member_utils_strings::base64_url_safe_encode ($cf_signature, array ("+", "=", "/"), array ("-", "_", "~"), false);
730
+ /**/
731
+ return add_query_arg (urlencode_deep (array ("Policy" => $cf_base64_url_safe_policy, "Signature" => $cf_base64_url_safe_signature, "Key-Pair-Id" => $cfc["private_key_id"])), $cf_url);
732
+ }
733
+ /**
734
+ * Auto-configures Amazon® S3/CloudFront distros.
735
+ *
736
+ * @package s2Member\Files
737
+ * @since 110926
738
+ *
739
+ * @return array Array containing a true `success` element on success, else a failure array.
740
+ * Failure array will contain a failure `code`, and a failure `message`.
741
+ */
742
+ public static function amazon_cf_auto_configure_distros ()
743
+ {
744
+ foreach ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"] as $option => $option_value)
745
+ if (preg_match ("/^amazon_cf_files_/", $option) && ($option = preg_replace ("/^amazon_cf_files_/", "", $option)))
746
+ $cfc[$option] = $option_value;
747
+ /**/
748
+ $s3c["bucket"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_bucket"];
749
+ $cfc["access_key"] = $s3c["access_key"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_access_key"];
750
+ $cfc["secret_key"] = $s3c["secret_key"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_secret_key"];
751
+ /**/
752
+ if ($s3c["bucket"] && $s3c["access_key"] && $s3c["secret_key"]) /* We MUST have an Amazon® S3 Bucket and Keys. */
753
+ {
754
+ if ($cfc["private_key"] && $cfc["private_key_id"]) /* We MUST have Amazon® CloudFront Keys in order to auto-configure. */
755
+ {
756
+ if (!$cfc["distro_downloads_id"] || ($cfc["distro_downloads_id"] && ($cf_get_response = c_ws_plugin__s2member_files_in::amazon_cf_get_distro ($cfc["distro_downloads_id"], "downloads")) && ($cf_get_response["success"] || $cf_get_response["code"] === 404)))
757
+ {
758
+ if (!$cfc["distro_downloads_id"] || ($cfc["distro_downloads_id"] && $cf_get_response && !$cf_get_response["success"] && $cf_get_response["code"] === 404))
759
+ $cf_distro_downloads_clear = true; /* Clear, ready for a new one. */
760
+ /**/
761
+ else if ($cfc["distro_downloads_id"] && $cf_get_response && $cf_get_response["success"] && !$cf_get_response["deployed"])
762
+ return array ("success" => false, "code" => -86, "message" => _x ("Unable to delete existing Amazon® CloudFront Downloads Distro. Still in a `pending` state. Please wait 15 minutes, then try again. There is a certain process that s2Member must strictly adhere to when re-configuring your Amazon® CloudFront Distros. You may have to tick the auto-configure checkbox again, and re-run s2Member's auto-configuration routine many times, because s2Member will likely run into several `pending` challenges, as it works to completely re-configure your Amazon® CloudFront Distros for you. Thanks for your patience. Please wait 15 minutes, then try again.", "s2member-admin", "s2member"));
763
+ /**/
764
+ else if ($cfc["distro_downloads_id"] && $cf_get_response && $cf_get_response["success"] && $cf_get_response["deployed"] && ($cf_del_response = c_ws_plugin__s2member_files_in::amazon_cf_del_distro ($cfc["distro_downloads_id"], $cf_get_response["etag"], $cf_get_response["xml"])) && $cf_del_response["success"])
765
+ $cf_distro_downloads_clear = true; /* Clear, ready for a new one. */
766
+ /**/
767
+ else if (isset ($cf_del_response["code"], $cf_del_response["message"]))
768
+ /* translators: In this translation, `%s` may be filled with an English message, which comes from the Amazon® CloudFront API call. Feel free to exclude `%s` if you like. */
769
+ return array ("success" => false, "code" => $cf_del_response["code"], "message" => sprintf (_x ("Unable to delete existing Amazon® CloudFront Downloads Distro. %s", "s2member-admin", "s2member"), $cf_del_response["message"]));
770
+ /**/
771
+ if (isset ($cf_distro_downloads_clear) && $cf_distro_downloads_clear) /* Successfully cleared? Ready for a new one? */
772
+ {
773
+ unset ($cf_get_response, $cf_del_response); /* Unset these before processing additional routines. Prevents problems in error reporting. */
774