| 1 |
<?php |
| 2 |
// @codingStandardsIgnoreFile |
| 3 |
/** |
| 4 |
* Registration Access Links. |
| 5 |
* |
| 6 |
* Copyright: © 2009-2011 |
| 7 |
* {@link http://websharks-inc.com/ WebSharks, Inc.} |
| 8 |
* (coded in the USA) |
| 9 |
* |
| 10 |
* Released under the terms of the GNU General Public License. |
| 11 |
* You should have received a copy of the GNU General Public License, |
| 12 |
* along with this software. In the main directory, see: /licensing/ |
| 13 |
* If not, see: {@link http://www.gnu.org/licenses/}. |
| 14 |
* |
| 15 |
* @package s2Member\Registrations |
| 16 |
* @since 3.5 |
| 17 |
*/ |
| 18 |
if(!defined('WPINC')) // MUST have WordPress. |
| 19 |
exit('Do not access this file directly.'); |
| 20 |
|
| 21 |
if(!class_exists('c_ws_plugin__s2member_register_access')) |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Registration Access Links. |
| 25 |
* |
| 26 |
* @package s2Member\Registrations |
| 27 |
* @since 3.5 |
| 28 |
*/ |
| 29 |
class c_ws_plugin__s2member_register_access |
| 30 |
{ |
| 31 |
/** |
| 32 |
* Generates Registration Access Links. |
| 33 |
* |
| 34 |
* @package s2Member\Registrations |
| 35 |
* @since 3.5 |
| 36 |
* |
| 37 |
* @param string $subscr_gateway Payment Gateway associated with a Customer. |
| 38 |
* @param string $subscr_id Unique Subscr. ID associated with Payment Gateway; associated with a Customer. |
| 39 |
* @param string $custom Custom String value *(as supplied in Shortcode)*; must start with installation domain name. |
| 40 |
* @param int|string $item_number An s2Member-generated `item_number` *( i.e., `1` for Level 1, or `level|ccaps|fixed-term`, or `sp|ids|expiration` )*. |
| 41 |
* @param bool $shrink Optional. Defaults to true. If false, the raw registration link will NOT be reduced in size by s2Member's URL shortening system. |
| 42 |
* |
| 43 |
* @return string|bool A Registration Access Link on success, else false on failure. |
| 44 |
*/ |
| 45 |
public static function register_link_gen($subscr_gateway = '', $subscr_id = '', $custom = '', $item_number = '', $shrink = TRUE) |
| 46 |
{ |
| 47 |
foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v; |
| 48 |
do_action('ws_plugin__s2member_before_register_link_gen', get_defined_vars()); |
| 49 |
unset($__refs, $__v); |
| 50 |
|
| 51 |
if($subscr_gateway && is_string($subscr_gateway) && $subscr_id && is_string($subscr_id) && $custom && is_string($custom) && $item_number && (is_string($item_number) || is_numeric($item_number))) |
| 52 |
{ |
| 53 |
$register = c_ws_plugin__s2member_utils_encryption::encrypt('subscr_gateway_subscr_id_custom_item_number_time:.:|:.:'.$subscr_gateway.':.:|:.:'.$subscr_id.':.:|:.:'.$custom.':.:|:.:'.$item_number.':.:|:.:'.strtotime('now')); |
| 54 |
|
| 55 |
$register_link = home_url('/?s2member_register='.urlencode($register)); // Generate long URL/link. |
| 56 |
$now = strtotime('now'); |
| 57 |
$register_link_exp_time = apply_filters('ws_plugin__s2member_register_link_exp_time', '2 days', get_defined_vars()); |
| 58 |
$register_link_expiration = strtotime('+'.$register_link_exp_time, $now); |
| 59 |
$register_link_expiration = ($register_link_expiration && $register_link_expiration > $now) ? max(7 * DAY_IN_SECONDS, ($register_link_expiration - $now) + DAY_IN_SECONDS) : 7 * DAY_IN_SECONDS; //260612 Allow for custom registration link expiration. |
| 60 |
|
| 61 |
if($shrink && ($shorter_url = c_ws_plugin__s2member_utils_urls::shorten($register_link, '', TRUE, $register_link_expiration))) |
| 62 |
{ |
| 63 |
$shorter_url_host = c_ws_plugin__s2member_utils_urls::parse_url($shorter_url, PHP_URL_HOST); |
| 64 |
$home_url_host = c_ws_plugin__s2member_utils_urls::parse_url(home_url('/'), PHP_URL_HOST); |
| 65 |
$domain_tag = ($shorter_url_host && $home_url_host && strcasecmp($shorter_url_host, $home_url_host) !== 0) ? '#'.$home_url_host : ''; //260612 Personalize external short links only. |
| 66 |
$register_link = $shorter_url.$domain_tag; |
| 67 |
} |
| 68 |
} |
| 69 |
return apply_filters('ws_plugin__s2member_register_link_gen', ((!empty($register_link)) ? $register_link : FALSE), get_defined_vars()); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Generates Registration Access Links via AJAX. |
| 74 |
* |
| 75 |
* @package s2Member\Registrations |
| 76 |
* @since 3.5 |
| 77 |
* |
| 78 |
* @attaches-to ``add_action('wp_ajax_ws_plugin__s2member_reg_access_link_via_ajax');`` |
| 79 |
* |
| 80 |
* @return null Exits script execution after output is generated for AJAX caller. |
| 81 |
*/ |
| 82 |
public static function reg_access_link_via_ajax() |
| 83 |
{ |
| 84 |
do_action('ws_plugin__s2member_before_reg_access_link_via_ajax', get_defined_vars()); |
| 85 |
|
| 86 |
status_header(200); // Send a 200 OK status header. |
| 87 |
header('Content-Type: text/plain; charset=UTF-8'); // Content-Type with UTF-8. |
| 88 |
while(@ob_end_clean()) ; // Clean any existing output buffers. |
| 89 |
|
| 90 |
if(current_user_can('create_users')) // Check privileges as well. Ability to create Users? |
| 91 |
|
| 92 |
if(!empty($_POST['ws_plugin__s2member_reg_access_link_via_ajax']) && is_string($nonce = $_POST['ws_plugin__s2member_reg_access_link_via_ajax']) && wp_verify_nonce($nonce, 'ws-plugin--s2member-reg-access-link-via-ajax')) |
| 93 |
|
| 94 |
if(($_p = c_ws_plugin__s2member_utils_strings::trim_deep(stripslashes_deep($_POST))) && isset ($_p['s2member_reg_access_link_subscr_gateway'], $_p['s2member_reg_access_link_subscr_id'], $_p['s2member_reg_access_link_custom'], $_p['s2member_reg_access_link_item_number'])) |
| 95 |
$register_link = c_ws_plugin__s2member_register_access::register_link_gen((string)$_p['s2member_reg_access_link_subscr_gateway'], (string)$_p['s2member_reg_access_link_subscr_id'], (string)$_p['s2member_reg_access_link_custom'], (string)$_p['s2member_reg_access_link_item_number']); |
| 96 |
|
| 97 |
exit(apply_filters('ws_plugin__s2member_reg_access_link_via_ajax', ((!empty($register_link)) ? $register_link : ''), get_defined_vars())); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Checks registration cookies. |
| 102 |
* |
| 103 |
* @package s2Member\Registrations |
| 104 |
* @since 110707 |
| 105 |
* |
| 106 |
* @return array|bool An array of cookies if they're OK, else false. |
| 107 |
*/ |
| 108 |
public static function reg_cookies_ok() |
| 109 |
{ |
| 110 |
global $wpdb; |
| 111 |
/** @var $wpdb \wpdb */ |
| 112 |
|
| 113 |
do_action('ws_plugin__s2member_before_reg_cookies_ok', get_defined_vars()); |
| 114 |
|
| 115 |
if(isset ($_COOKIE['s2member_subscr_gateway'], $_COOKIE['s2member_subscr_id'], $_COOKIE['s2member_custom'], $_COOKIE['s2member_item_number'])) |
| 116 |
if(($subscr_gateway = c_ws_plugin__s2member_utils_encryption::decrypt((string)$_COOKIE['s2member_subscr_gateway'])) && ($subscr_id = c_ws_plugin__s2member_utils_encryption::decrypt((string)$_COOKIE['s2member_subscr_id'])) && preg_match('/^'.preg_quote(preg_replace('/\:([0-9]+)$/', '', $_SERVER['HTTP_HOST']), '/').'/i', ($custom = c_ws_plugin__s2member_utils_encryption::decrypt((string)$_COOKIE['s2member_custom']))) && preg_match($GLOBALS['WS_PLUGIN__']['s2member']['c']['membership_item_number_w_level_regex'], ($item_number = c_ws_plugin__s2member_utils_encryption::decrypt((string)$_COOKIE['s2member_item_number']))) && !$wpdb->get_var("SELECT `user_id` FROM `".$wpdb->usermeta."` WHERE `meta_key` = '".$wpdb->prefix."s2member_subscr_id' AND `meta_value` = '".esc_sql($subscr_id)."' LIMIT 1")) |
| 117 |
$reg_cookies_ok = $reg_cookies = array('subscr_gateway' => $subscr_gateway, 'subscr_id' => $subscr_id, 'custom' => $custom, 'item_number' => $item_number); |
| 118 |
|
| 119 |
return apply_filters('ws_plugin__s2member_reg_cookies_ok', !empty($reg_cookies_ok) && !empty($reg_cookies) ? $reg_cookies : FALSE, get_defined_vars()); |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
|