1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210:
<?php
if(!class_exists('Inbound_Confirm_Double_Optin')){
class Inbound_Confirm_Double_Optin{
function __construct(){
self::add_hooks();
}
public static function add_hooks(){
add_action( 'init' , array( __CLASS__, 'process_confrimation' ), 20 );
add_shortcode( 'list-double-optin-link', array( __CLASS__, 'render_confirm_link' ) );
}
public static function process_confrimation(){
global $inbound_settings;
if (!isset($_REQUEST['inbound-action']) || $_REQUEST['inbound-action'] != 'confirm' ) {
return;
}
$lead_lists = Inbound_Leads::get_lead_lists_as_array();
$params = Inbound_API::get_args_from_token( sanitize_text_field($_GET['token'] ));
if ( !isset( $params['lead_id'] ) ) {
return;
}
self::confirm_being_added_to_lists($params);
}
public static function render_confirm_link( $params ) {
$params = shortcode_atts( array(
'lead_id' => '',
'list_ids' => '-1',
'email_id' => '-1'
), $params, 'list-double-optin-link');
if ( isset($params['lead_id']) ) {
$params['lead_id'] = intval($params['lead_id']);
} else if ( isset($_REQUEST['lead_id']) ) {
$params['lead_id'] = intval($_REQUEST['lead_id']);
} else if ( isset($_COOKIE['wp_lead_id']) ) {
$params['lead_id'] = intval($_COOKIE['wp_lead_id']);
}
$params['variation_id'] = ( isset($_REQUEST['inbvid']) ) ? intval($_REQUEST['inbvid']) : intval(0);
$confirm_link = self::generate_confirm_link( $params );
return $confirm_link;
}
public static function generate_confirm_link( $params ) {
if (!isset($params['lead_id']) || !$params['lead_id']) {
return __( '#confirm-not-available-in-online-mode' , 'inbound-pro' );
}
if (isset($_GET['lead_lists']) && !is_array($_GET['lead_lists'])){
$params['list_ids'] = explode( ',' , $_GET['lead_lists']);
} else if (isset($params['list_ids']) && !is_array($params['list_ids'])) {
$params['list_ids'] = explode( ',' , $params['list_ids']);
}
$args = array_merge( $params , $_GET );
$token = Inbound_API::analytics_get_tracking_code( $args );
if(!defined('INBOUND_PRO_CURRENT_VERSION')){
$double_optin_page_id = get_option('wpl-main-list-double-optin-page-id', '');
}else{
$settings = Inbound_Options_API::get_option('inbound-pro', 'settings', array());
$double_optin_page_id = $settings['leads']['list-double-optin-page-id'];
}
if ( empty($double_optin_page_id) ) {
$post = get_page_by_title( __( 'Confirm Subscription' , 'inbound-pro' ) );
$double_optin_page_id = $post->ID;
}
$base_url = get_permalink( $double_optin_page_id );
return add_query_arg( array( 'token'=>$token , 'inbound-action' => 'confirm' ) , $base_url );
}
public static function decode_confirm_token( $token ) {
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decrypted_string =
trim(
mcrypt_decrypt(
MCRYPT_RIJNDAEL_256 , substr( SECURE_AUTH_KEY , 0 , 16 ) , base64_decode( str_replace(array('-', '_', '^'), array('+', '/', '='), $token ) ) , MCRYPT_MODE_ECB, $iv
)
);
return json_decode($decrypted_string , true);
}
public static function confirm_being_added_to_lists($params, $all = false){
if(!defined('INBOUND_PRO_CURRENT_VERSION')){
$double_optin_list_id = get_option('list-double-optin-list-id', '');
}else{
$settings = Inbound_Options_API::get_option('inbound-pro', 'settings', array());
$double_optin_list_id = $settings['leads']['list-double-optin-list-id'];
}
$stored_double_optin_lists = get_post_meta($params['lead_id'], 'double_optin_lists', true);
if(empty($stored_double_optin_lists)){
return;
}
if($all){
$params['list_ids'] = $stored_double_optin_lists;
}
foreach($params['list_ids'] as $list_id){
Inbound_Leads::add_lead_to_list($params['lead_id'], $list_id);
if(in_array($list_id, $stored_double_optin_lists)){
$index = array_search($list_id, $stored_double_optin_lists);
unset($stored_double_optin_lists[$index]);
}
}
if(!empty($stored_double_optin_lists)){
update_post_meta($params['lead_id'], 'double_optin_lists', array_values($stored_double_optin_lists));
}else{
delete_post_meta($params['lead_id'], 'double_optin_lists');
wp_remove_object_terms($params['lead_id'], $double_optin_list_id, 'wplead_list_category');
update_post_meta( $params['lead_id'], 'wp_lead_status', 'active');
}
unset($params['wp_lead_status']);
unset($params['variation_id']);
unset($params['wpleads_raw_post_data']);
do_action('inbound_double_optin_confirm' , $params);
}
}
new Inbound_Confirm_Double_Optin;
}