| 1 |
<?php |
| 2 |
/** |
| 3 |
* List Server integrations. |
| 4 |
* |
| 5 |
* Copyright: © 2009-2011 |
| 6 |
* {@link http://www.websharks-inc.com/ WebSharks, Inc.} |
| 7 |
* ( coded in the USA ) |
| 8 |
* |
| 9 |
* Released under the terms of the GNU General Public License. |
| 10 |
* You should have received a copy of the GNU General Public License, |
| 11 |
* along with this software. In the main directory, see: /licensing/ |
| 12 |
* If not, see: {@link http://www.gnu.org/licenses/}. |
| 13 |
* |
| 14 |
* @package s2Member\List_Servers |
| 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_list_servers")) |
| 21 |
{ |
| 22 |
/** |
| 23 |
* List Server integrations. |
| 24 |
* |
| 25 |
* @package s2Member\List_Servers |
| 26 |
* @since 3.5 |
| 27 |
*/ |
| 28 |
class c_ws_plugin__s2member_list_servers |
| 29 |
{ |
| 30 |
/** |
| 31 |
* Determines whether or not any List Servers have been integrated. |
| 32 |
* |
| 33 |
* @package s2Member\List_Servers |
| 34 |
* @since 3.5 |
| 35 |
* |
| 36 |
* @return bool True if List Servers have been integrated, else false. |
| 37 |
*/ |
| 38 |
public static function list_servers_integrated () |
| 39 |
{ |
| 40 |
do_action ("ws_plugin__s2member_before_list_servers_integrated", get_defined_vars ()); |
| 41 |
/**/ |
| 42 |
for ($n = 0; $n <= $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["levels"]; $n++) /* Go through each Level; looking for a configured list. */ |
| 43 |
if (!empty ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_mailchimp_list_ids"]) || !empty ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_aweber_list_ids"])) |
| 44 |
return apply_filters ("ws_plugin__s2member_list_servers_integrated", true, get_defined_vars ()); |
| 45 |
/**/ |
| 46 |
return apply_filters ("ws_plugin__s2member_list_servers_integrated", false, get_defined_vars ()); |
| 47 |
} |
| 48 |
/** |
| 49 |
* Processes List Server integrations for s2Member. |
| 50 |
* |
| 51 |
* @package s2Member\List_Servers |
| 52 |
* @since 3.5 |
| 53 |
* |
| 54 |
* @param str $role A WordPress Role ID/Name, such as `subscriber`, or `s2member_level1`. |
| 55 |
* @param int|str $level A numeric s2Member Access Level number. |
| 56 |
* @param str $login Username for the User. |
| 57 |
* @param str $pass Plain Text Password for the User. |
| 58 |
* @param str $email Email Address for the User. |
| 59 |
* @param str $fname First Name for the User. |
| 60 |
* @param str $lname Last Name for the User. |
| 61 |
* @param str $ip IP Address for the User. |
| 62 |
* @param bool $opt_in Defaults to false; must be set to true. Indicates the User IS opting in. |
| 63 |
* @param bool $double_opt_in Defaults to true. If false, no email confirmation is required. Use at your own risk. |
| 64 |
* @param int|str $user_id A WordPress User ID, numeric string or integer. |
| 65 |
* @return bool True if at least one List Server is processed successfully, else false. |
| 66 |
* |
| 67 |
* @todo Integrate {@link https://labs.aweber.com/docs/php-library-walkthrough AWeber's API}. |
| 68 |
* @todo Add a separate option for mail debugging; or consolidate? |
| 69 |
* @todo Integrate AWeber® API ( much like the MailChimp® API ). |
| 70 |
*/ |
| 71 |
public static function process_list_servers ($role = FALSE, $level = FALSE, $login = FALSE, $pass = FALSE, $email = FALSE, $fname = FALSE, $lname = FALSE, $ip = FALSE, $opt_in = FALSE, $double_opt_in = TRUE, $user_id = FALSE) |
| 72 |
{ |
| 73 |
global $current_site, $current_blog; /* For Multisite support. */ |
| 74 |
/**/ |
| 75 |
eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 76 |
do_action ("ws_plugin__s2member_before_process_list_servers", get_defined_vars ()); |
| 77 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 78 |
/**/ |
| 79 |
if (($args = func_get_args ()) && $role && strlen ($level) && $login && is_email ($email) && $opt_in && $user_id && is_object ($user = new WP_User ($user_id)) && ($user_id = $user->ID)) |
| 80 |
{ |
| 81 |
$ccaps = implode (",", c_ws_plugin__s2member_user_access::user_access_ccaps ($user)); /* Get Custom Capabilities ( comma-delimited ). */ |
| 82 |
/**/ |
| 83 |
$email_configs_were_on = c_ws_plugin__s2member_email_configs::email_config_status (false); /* s2Member Filters enabled? */ |
| 84 |
c_ws_plugin__s2member_email_configs::email_config_release (true); /* Release all mail Filters before we begin this routine. */ |
| 85 |
/**/ |
| 86 |
if (!empty ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["mailchimp_api_key"]) && !empty ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $level . "_mailchimp_list_ids"])) |
| 87 |
{ |
| 88 |
if (!class_exists ("NC_MCAPI")) /* Include the MailChimp® API Class here. */ |
| 89 |
include_once dirname (dirname (__FILE__)) . "/_xtnls/mailchimp/nc-mcapi.inc.php"; /* MailChimp® API ( no-conflict version ). */ |
| 90 |
/**/ |
| 91 |
$mcapi = new NC_MCAPI ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["mailchimp_api_key"], true); /* MailChimp® API ( no-conflict ). */ |
| 92 |
/**/ |
| 93 |
foreach (preg_split ("/[\r\n\t;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $level . "_mailchimp_list_ids"]) as $mailchimp_list) |
| 94 |
{ |
| 95 |
$mailchimp = array ("function" => __FUNCTION__, "func_get_args" => $args, "api_method" => "listSubscribe"); |
| 96 |
/**/ |
| 97 |
if (($mailchimp["list"] = trim ($mailchimp_list))) /* Trim this up. NO trailing white space. */ |
| 98 |
{ |
| 99 |
if (strpos ($mailchimp["list"], "::") !== false) /* Also contains Interest Groups? */ |
| 100 |
{ |
| 101 |
list ($mailchimp["list_id"], $mailchimp["interest_groups_title"], $mailchimp["interest_groups"]) = preg_split ("/\:\:/", $mailchimp["list"], 3); |
| 102 |
/**/ |
| 103 |
if (($mailchimp["interest_groups_title"] = trim ($mailchimp["interest_groups_title"]))) /* This is a title configured by the list master. */ |
| 104 |
if (($mailchimp["interest_groups"] = (trim ($mailchimp["interest_groups"])) ? preg_split ("/\|/", trim ($mailchimp["interest_groups"])) : false)) |
| 105 |
$mailchimp["interest_groups"] = array ("GROUPINGS" => array (array ("name" => $mailchimp["interest_groups_title"], "groups" => implode (",", $mailchimp["interest_groups"])))); |
| 106 |
/**/ |
| 107 |
if (empty ($mailchimp["list_id"])) /* Need to double-check this. If empty, skip over this entry. */ |
| 108 |
continue; /* Continue to next List, if there is one. */ |
| 109 |
} |
| 110 |
else /* Else, it's just a List ID. */ |
| 111 |
$mailchimp["list_id"] = $mailchimp["list"]; |
| 112 |
/**/ |
| 113 |
$mailchimp["merge_array"] = array ("MERGE1" => $fname, "MERGE2" => $lname, "OPTIN_IP" => $ip, "OPTIN_TIME" => date ("Y-m-d H:i:s")); |
| 114 |
$mailchimp["merge_array"] = ($mailchimp["interest_groups"]) ? array_merge ($mailchimp["merge_array"], $mailchimp["interest_groups"]) : $mailchimp["merge_array"]; |
| 115 |
$mailchimp["merge_array"] = apply_filters ( /* Deprecated. */"ws_plugin__s2member_mailchimp_array", $mailchimp["merge_array"], get_defined_vars ()); |
| 116 |
/* Filter: `ws_plugin__s2member_mailchimp_array` deprecated in v110523. Please use Filter: `ws_plugin__s2member_mailchimp_merge_array`. */ |
| 117 |
/**/ |
| 118 |
if ($mailchimp["api_response"] = $mcapi->{$mailchimp["api_method"]}($mailchimp["list_id"], $email, /* See: `http://apidocs.mailchimp.com/` for full details. */ |
| 119 |
($mailchimp["api_merge_array"] = apply_filters ("ws_plugin__s2member_mailchimp_merge_array", $mailchimp["merge_array"], get_defined_vars ())), /* Configured merge array above. */ |
| 120 |
($mailchimp["api_email_type"] = apply_filters ("ws_plugin__s2member_mailchimp_email_type", "html", get_defined_vars ())), /* Type of email to receive ( i.e. html,text,mobile ).*/ |
| 121 |
($mailchimp["api_double_optin"] = apply_filters ("ws_plugin__s2member_mailchimp_double_optin", $double_opt_in, get_defined_vars ())), /* Abuse of this may cause account suspension. */ |
| 122 |
($mailchimp["api_update_existing"] = apply_filters ("ws_plugin__s2member_mailchimp_update_existing", false, get_defined_vars ())), /* Existing subscribers should be updated with this? */ |
| 123 |
($mailchimp["api_replace_interests"] = apply_filters ("ws_plugin__s2member_mailchimp_replace_interests", true, get_defined_vars ())), /* Replace interest groups? ( only if provided ) */ |
| 124 |
($mailchimp["api_send_welcome"] = apply_filters ("ws_plugin__s2member_mailchimp_send_welcome", false, get_defined_vars ())))) /* See documentation. This is a weird option. */ |
| 125 |
$mailchimp["api_success"] = $success = true; /* Flag indicating that we DO have a successful processing of a new List; affects the function's overall return value. */ |
| 126 |
$mailchimp["api_properties"] = $mcapi; /* Include API instance too; as it contains some additional information after each method is processed ( need this in the logs ). */ |
| 127 |
/**/ |
| 128 |
$logv = c_ws_plugin__s2member_utilities::ver_details (); |
| 129 |
$logm = c_ws_plugin__s2member_utilities::mem_details (); |
| 130 |
$log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"]; |
| 131 |
$log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4; |
| 132 |
$log2 = (is_multisite () && !is_main_site ()) ? "mailchimp-api-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "mailchimp-api.log"; |
| 133 |
/**/ |
| 134 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"]) |
| 135 |
if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"])) |
| 136 |
if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ()) |
| 137 |
file_put_contents ($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export ($mailchimp, true) . "\n\n", FILE_APPEND); |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
/**/ |
| 142 |
if (!empty ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $level . "_aweber_list_ids"])) |
| 143 |
{ |
| 144 |
foreach (preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $level . "_aweber_list_ids"]) as $aweber_list) |
| 145 |
{ |
| 146 |
$aweber = array ("function" => __FUNCTION__, "func_get_args" => $args, "wp_mail_method" => "listSubscribe"); |
| 147 |
/**/ |
| 148 |
if (($aweber["list_id"] = trim ($aweber_list))) /* Trim this up. NO trailing white space. */ |
| 149 |
{ |
| 150 |
$aweber["bcc"] = apply_filters ("ws_plugin__s2member_aweber_bcc", false, get_defined_vars ()); |
| 151 |
$aweber["pass_inclusion"] = (apply_filters ("ws_plugin__s2member_aweber_pass_inclusion", false, get_defined_vars ()) && $pass) ? "\nPass: " . $pass : false; |
| 152 |
/**/ |
| 153 |
if ($aweber["wp_mail_response"] = wp_mail ($aweber["list_id"] . "@aweber.com", /* AWeber® List ID converts to email address @aweber.com. */ |
| 154 |
($aweber["wp_mail_sbj"] = apply_filters ("ws_plugin__s2member_aweber_sbj", "s2Member Subscription Request", get_defined_vars ())), /* These Filters make it possible to customize these emails. */ |
| 155 |
($aweber["wp_mail_msg"] = apply_filters ("ws_plugin__s2member_aweber_msg", "s2Member Subscription Request\ns2Member w/ PayPal Email ID\nAd Tracking: s2Member-" . ((is_multisite () && !is_main_site ()) ? $current_blog->domain . $current_blog->path : $_SERVER["HTTP_HOST"]) . "\nEMail Address: " . $email . "\nBuyer: " . $fname . " " . $lname . "\nFull Name: " . $fname . " " . $lname . "\nFirst Name: " . $fname . "\nLast Name: " . $lname . "\nIP Address: " . $ip . "\nUser ID: " . $user_id . "\nLogin: " . $login . $aweber["pass_inclusion"] . "\nRole: " . $role . "\nLevel: " . $level . "\nCCaps: " . $ccaps . "\n - end.", get_defined_vars ())),/**/ |
| 156 |
($aweber["wp_mail_headers"] = "From: \"" . preg_replace ("/\"/", "", $fname . " " . $lname) . "\" <" . $email . ">" . (($aweber["bcc"]) ? "\r\nBcc: " . $aweber["bcc"] : "") . "\r\nContent-Type: text/plain; charset=utf-8"))) |
| 157 |
$aweber["wp_mail_success"] = $success = true; /* Flag indicating that we DO have a successful processing of a new List; affects the function's overall return value. */ |
| 158 |
/**/ |
| 159 |
$logv = c_ws_plugin__s2member_utilities::ver_details (); |
| 160 |
$logm = c_ws_plugin__s2member_utilities::mem_details (); |
| 161 |
$log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"]; |
| 162 |
$log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4; |
| 163 |
$log2 = (is_multisite () && !is_main_site ()) ? "aweber-api-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "aweber-api.log"; |
| 164 |
/**/ |
| 165 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"]) |
| 166 |
if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"])) |
| 167 |
if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ()) |
| 168 |
file_put_contents ($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export ($aweber, true) . "\n\n", FILE_APPEND); |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
/**/ |
| 173 |
eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 174 |
do_action ("ws_plugin__s2member_during_process_list_servers", get_defined_vars ()); |
| 175 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 176 |
/**/ |
| 177 |
if ($email_configs_were_on) /* Back on? */ |
| 178 |
c_ws_plugin__s2member_email_configs::email_config (); |
| 179 |
} |
| 180 |
/**/ |
| 181 |
eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 182 |
do_action ("ws_plugin__s2member_after_process_list_servers", get_defined_vars ()); |
| 183 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 184 |
/**/ |
| 185 |
return apply_filters ("ws_plugin__s2member_process_list_servers", (isset ($success) && $success), get_defined_vars ()); |
| 186 |
} |
| 187 |
/** |
| 188 |
* Processes List Server removals for s2Member. |
| 189 |
* |
| 190 |
* @package s2Member\List_Servers |
| 191 |
* @since 3.5 |
| 192 |
* |
| 193 |
* @param str $role A WordPress Role ID/Name, such as `subscriber`, or `s2member_level1`. |
| 194 |
* @param int|str $level A numeric s2Member Access Level number. |
| 195 |
* @param str $login Username for the User. |
| 196 |
* @param str $pass Plain Text Password for the User. |
| 197 |
* @param str $email Email address for the User. |
| 198 |
* @param str $fname First Name for the User. |
| 199 |
* @param str $lname Last Name for the User. |
| 200 |
* @param str $ip IP Address for the User. |
| 201 |
* @param bool $opt_out Defaults to false; must be set to true. Indicates the User IS opting out. |
| 202 |
* @param int|str $user_id A WordPress User ID, numeric string or integer. |
| 203 |
* @return bool True if at least one List Server is processed successfully, else false. |
| 204 |
* |
| 205 |
* @todo Integrate {@link https://labs.aweber.com/docs/php-library-walkthrough AWeber's API}. |
| 206 |
* @todo Add a separate option for mail debugging; or consolidate? |
| 207 |
* @todo Integrate AWeber® API ( much like the MailChimp® API ). |
| 208 |
*/ |
| 209 |
public static function process_list_server_removals ($role = FALSE, $level = FALSE, $login = FALSE, $pass = FALSE, $email = FALSE, $fname = FALSE, $lname = FALSE, $ip = FALSE, $opt_out = FALSE, $user_id = FALSE) |
| 210 |
{ |
| 211 |
global $current_site, $current_blog; /* For Multisite support. */ |
| 212 |
/**/ |
| 213 |
eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 214 |
do_action ("ws_plugin__s2member_before_process_list_server_removals", get_defined_vars ()); |
| 215 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 216 |
/**/ |
| 217 |
if (($args = func_get_args ()) && $role && strlen ($level) && $login && is_email ($email) && $opt_out && $user_id && is_object ($user = new WP_User ($user_id)) && ($user_id = $user->ID)) |
| 218 |
{ |
| 219 |
$email_configs_were_on = c_ws_plugin__s2member_email_configs::email_config_status (false); /* s2Member Filters enabled? */ |
| 220 |
c_ws_plugin__s2member_email_configs::email_config_release (true); /* Release all mail Filters before we begin this routine. */ |
| 221 |
/**/ |
| 222 |
if (!empty ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["mailchimp_api_key"]) && !empty ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $level . "_mailchimp_list_ids"])) |
| 223 |
{ |
| 224 |
if (!class_exists ("NC_MCAPI")) /* Include the MailChimp® API Class here. */ |
| 225 |
include_once dirname (dirname (__FILE__)) . "/_xtnls/mailchimp/nc-mcapi.inc.php"; /* MailChimp® API ( no-conflict version ). */ |
| 226 |
/**/ |
| 227 |
$mcapi = new NC_MCAPI ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["mailchimp_api_key"], true); /* MailChimp® API ( no-conflict ). */ |
| 228 |
/**/ |
| 229 |
foreach (preg_split ("/[\r\n\t;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $level . "_mailchimp_list_ids"]) as $mailchimp_list) |
| 230 |
{ |
| 231 |
$mailchimp = array ("function" => __FUNCTION__, "func_get_args" => $args, "api_removal_method" => "listUnsubscribe"); |
| 232 |
/**/ |
| 233 |
if (($mailchimp["list_id"] = trim (preg_replace ("/\:\:.*$/", "", $mailchimp_list)))) /* Trim & strip groups. */ |
| 234 |
{ |
| 235 |
if ($mailchimp["api_removal_response"] = $mcapi->{$mailchimp["api_removal_method"]}($mailchimp["list_id"], $email, /* See: `http://apidocs.mailchimp.com/`. */ |
| 236 |
($mailchimp["api_removal_delete_member"] = apply_filters ("ws_plugin__s2member_mailchimp_removal_delete_member", false, get_defined_vars ())), /* Completely delete? */ |
| 237 |
($mailchimp["api_removal_send_goodbye"] = apply_filters ("ws_plugin__s2member_mailchimp_removal_send_goodbye", false, get_defined_vars ())), /* Send goodbye letter? */ |
| 238 |
($mailchimp["api_removal_send_notify"] = apply_filters ("ws_plugin__s2member_mailchimp_removal_send_notify", false, get_defined_vars ())))) /* Send notification? */ |
| 239 |
$mailchimp["api_removal_success"] = $removal_success = true; /* Flag indicating that we DO have a successful removal; affects the function's overall return value. */ |
| 240 |
$mailchimp["api_removal_properties"] = $mcapi; /* Include API instance too; as it contains some additional information after each method is processed ( need this in the logs ). */ |
| 241 |
/**/ |
| 242 |
$logv = c_ws_plugin__s2member_utilities::ver_details (); |
| 243 |
$logm = c_ws_plugin__s2member_utilities::mem_details (); |
| 244 |
$log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"]; |
| 245 |
$log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4; |
| 246 |
$log2 = (is_multisite () && !is_main_site ()) ? "mailchimp-api-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "mailchimp-api.log"; |
| 247 |
/**/ |
| 248 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"]) |
| 249 |
if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"])) |
| 250 |
if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ()) |
| 251 |
file_put_contents ($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export ($mailchimp, true) . "\n\n", FILE_APPEND); |
| 252 |
} |
| 253 |
} |
| 254 |
} |
| 255 |
/**/ |
| 256 |
if (!empty ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $level . "_aweber_list_ids"])) |
| 257 |
{ |
| 258 |
foreach (preg_split ("/[\r\n\t\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $level . "_aweber_list_ids"]) as $aweber_list) |
| 259 |
{ |
| 260 |
$aweber = array ("function" => __FUNCTION__, "func_get_args" => $args, "wp_mail_removal_method" => "listUnsubscribe"); |
| 261 |
/**/ |
| 262 |
if (($aweber["list_id"] = trim ($aweber_list))) /* Trim this up. NO trailing white space. */ |
| 263 |
{ |
| 264 |
$aweber["removal_bcc"] = apply_filters ("ws_plugin__s2member_aweber_removal_bcc", false, get_defined_vars ()); |
| 265 |
/**/ |
| 266 |
if ($aweber["wp_mail_removal_response"] = wp_mail ($aweber["list_id"] . "@aweber.com", /* AWeber® List ID converts to email address @aweber.com. */ |
| 267 |
($aweber["wp_mail_removal_sbj"] = apply_filters ("ws_plugin__s2member_aweber_removal_sbj", "REMOVE#" . $email . "#s2Member#" . $aweber["list_id"], get_defined_vars ())), /* Bug fix. AWeber® does not like dots ( possibly other chars ) in the Ad Tracking field. Now using just: `s2Member`. */ |
| 268 |
($aweber["wp_mail_removal_msg"] = "REMOVE"), ($aweber["wp_mail_removal_headers"] = "From: \"" . preg_replace ('/"/', "'", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_name"]) . "\" <" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["reg_email_from_email"] . ">" . (($aweber["removal_bcc"]) ? "\r\nBcc: " . $aweber["removal_bcc"] : "") . "\r\nContent-Type: text/plain; charset=utf-8"))) |
| 269 |
$aweber["wp_mail_removal_success"] = $removal_success = true; /* Flag indicating that we DO have a successful removal; affects the function's overall return value. */ |
| 270 |
/**/ |
| 271 |
$logv = c_ws_plugin__s2member_utilities::ver_details (); |
| 272 |
$logm = c_ws_plugin__s2member_utilities::mem_details (); |
| 273 |
$log4 = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nUser-Agent: " . $_SERVER["HTTP_USER_AGENT"]; |
| 274 |
$log4 = (is_multisite () && !is_main_site ()) ? ($_log4 = $current_blog->domain . $current_blog->path) . "\n" . $log4 : $log4; |
| 275 |
$log2 = (is_multisite () && !is_main_site ()) ? "aweber-api-4-" . trim (preg_replace ("/[^a-z0-9]/i", "-", $_log4), "-") . ".log" : "aweber-api.log"; |
| 276 |
/**/ |
| 277 |
if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["gateway_debug_logs"]) |
| 278 |
if (is_dir ($logs_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["logs_dir"])) |
| 279 |
if (is_writable ($logs_dir) && c_ws_plugin__s2member_utils_logs::archive_oversize_log_files ()) |
| 280 |
file_put_contents ($logs_dir . "/" . $log2, $logv . "\n" . $logm . "\n" . $log4 . "\n" . var_export ($aweber, true) . "\n\n", FILE_APPEND); |
| 281 |
} |
| 282 |
} |
| 283 |
} |
| 284 |
/**/ |
| 285 |
eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 286 |
do_action ("ws_plugin__s2member_during_process_list_server_removals", get_defined_vars ()); |
| 287 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 288 |
/**/ |
| 289 |
if ($email_configs_were_on) /* Back on? */ |
| 290 |
c_ws_plugin__s2member_email_configs::email_config (); |
| 291 |
} |
| 292 |
/**/ |
| 293 |
eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 294 |
do_action ("ws_plugin__s2member_after_process_list_server_removals", get_defined_vars ()); |
| 295 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 296 |
/**/ |
| 297 |
return apply_filters ("ws_plugin__s2member_process_list_server_removals", (isset ($removal_success) && $removal_success), get_defined_vars ()); |
| 298 |
} |
| 299 |
/** |
| 300 |
* Listens to Collective EOT/MOD Events processed internally by s2Member. |
| 301 |
* |
| 302 |
* This is only applicable when ``["custom_reg_auto_opt_outs"]`` contains related Event(s). |
| 303 |
* |
| 304 |
* @package s2Member\List_Servers |
| 305 |
* @since 3.5 |
| 306 |
* |
| 307 |
* @attaches-to: ``add_action("ws_plugin__s2member_during_collective_mods");`` |
| 308 |
* @attaches-to: ``add_action("ws_plugin__s2member_during_collective_eots");`` |
| 309 |
* |
| 310 |
* @param int|str $user_id A WordPress® User ID, numeric string or integer. |
| 311 |
* @param array $vars An array of defined variables from the calling Action Hook. |
| 312 |
* @param str $event A specific event that triggered this call from the Action Hook. |
| 313 |
* @param str $event_spec A specific event specification *( a broader classification )*. |
| 314 |
* @param str $mod_new_role If it's a modification, the new Role they are being modified to. |
| 315 |
* @param str $mod_old_role If it's a modification, the old Role they had previously. |
| 316 |
* @param obj $user Optional. A WP_User object that can reduce database queries for this routine. |
| 317 |
* @return null |
| 318 |
* |
| 319 |
* @todo Make it possible to transition Users, even if they were not currently on a list? |
| 320 |
* One suggestion was to send a double-opt-in email in that case; or to provide an option for this? |
| 321 |
* @todo Tighten up the call to ``c_ws_plugin__s2member_utils_strings::wrap_deep()`` by using `^$`? |
| 322 |
*/ |
| 323 |
public static function auto_process_list_server_removals ($user_id = FALSE, $vars = FALSE, $event = FALSE, $event_spec = FALSE, $mod_new_role = FALSE, $mod_old_role = FALSE, $user = FALSE) |
| 324 |
{ |
| 325 |
global $current_site, $current_blog; /* For Multisite support. */ |
| 326 |
static $auto_processed = array (); /* Only process ONE time for each User ID. */ |
| 327 |
/**/ |
| 328 |
eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 329 |
do_action ("ws_plugin__s2member_before_auto_process_list_server_removals", get_defined_vars ()); |
| 330 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 331 |
/**/ |
| 332 |
$custom_reg_auto_op_outs = c_ws_plugin__s2member_utils_strings::wrap_deep ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_auto_opt_outs"], "/", "/i"); |
| 333 |
/**/ |
| 334 |
if ($user_id && !in_array ($user_id, $auto_processed) && (c_ws_plugin__s2member_utils_arrays::in_regex_array ($event, $custom_reg_auto_op_outs) || c_ws_plugin__s2member_utils_arrays::in_regex_array ($event_spec, $custom_reg_auto_op_outs)) && c_ws_plugin__s2member_list_servers::list_servers_integrated () && (is_object ($user) || is_object ($user = new WP_User ($user_id))) && ($user_id = $user->ID)) |
| 335 |
{ |
| 336 |
$role = ($event_spec === "modification" && $mod_new_role && $mod_old_role) ? $mod_old_role : c_ws_plugin__s2member_user_access::user_access_role ($user); |
| 337 |
$level = ($event_spec === "modification" && $mod_new_role && $mod_old_role) ? c_ws_plugin__s2member_user_access::user_access_role_to_level ($mod_old_role) : c_ws_plugin__s2member_user_access::user_access_level ($user); |
| 338 |
/**/ |
| 339 |
if (($event_spec !== "modification" || ($event_spec === "modification" && $mod_new_role && $mod_new_role !== $role && strtotime ($user->user_registered) < strtotime ("-10 seconds") && ($event !== "user-role-change" || ($event === "user-role-change" && !empty ($_POST["ws_plugin__s2member_custom_reg_auto_opt_out_transitions"]))))) && ($auto_processed[$user_id] = true)) |
| 340 |
{ |
| 341 |
$removal_success = c_ws_plugin__s2member_list_servers::process_list_server_removals ($role, $level, $user->user_login, false, $user->user_email, $user->first_name, $user->last_name, false, true, $user_id); |
| 342 |
if ( /* Only if removed successfully. */$removal_success && $event_spec === "modification" && $mod_new_role && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_auto_opt_out_transitions"]) /* Transition? */ |
| 343 |
c_ws_plugin__s2member_list_servers::process_list_servers ($mod_new_role, ($mod_new_level = c_ws_plugin__s2member_user_access::user_access_role_to_level ($mod_new_role)), $user->user_login, false, $user->user_email, $user->first_name, $user->last_name, false, true, false, $user_id); |
| 344 |
} |
| 345 |
} |
| 346 |
/**/ |
| 347 |
eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); |
| 348 |
do_action ("ws_plugin__s2member_after_auto_process_list_server_removals", get_defined_vars ()); |
| 349 |
unset ($__refs, $__v); /* Unset defined __refs, __v. */ |
| 350 |
/**/ |
| 351 |
return; /* Return for uniformity. */ |
| 352 |
} |
| 353 |
} |
| 354 |
} |
| 355 |
?> |