function snp_ml_get_aw_lists()
{
    require_once SNP_DIR_PATH . '/include/aweber/aweber_api.php';
    $list = array();
    if (get_option('snp_ml_aw_auth_info')) {
        $aw = get_option('snp_ml_aw_auth_info');
        try {
            $aweber = new AWeberAPI($aw['consumer_key'], $aw['consumer_secret']);
            $account = $aweber->getAccount($aw['access_key'], $aw['access_secret']);
            $res = $account->lists;
            if ($res) {
                foreach ((array) $res->data['entries'] as $v) {
                    $list[$v['id']] = array('name' => $v['name']);
                }
            }
        } catch (AWeberException $e) {
            //echo $e;
        }
    }
    if (count($list) == 0) {
        $list[0] = array('name' => 'Nothing Found...');
    }
    return $list;
}
function eMember_aweber_new_signup_user($full_target_list_name, $fname, $lname, $email_to_subscribe)
{
    eMember_log_debug("Attempting to signup the user via AWeber API", true);
    $emember_config = Emember_Config::getInstance();
    $eMember_aweber_access_keys = $emember_config->getValue('eMember_aweber_access_keys');
    if (empty($eMember_aweber_access_keys['consumer_key'])) {
        eMember_log_debug("Missing AWeber access keys! You need to first make a conntect before you can use this API", false);
        return;
    }
    if (!class_exists('AWeberAPI')) {
        //TODO - change the class name to "eMember_AWeberAPI" to avoid conflict with others
        include_once 'lib/auto-responder/aweber_api/aweber_api.php';
        eMember_log_debug("AWeber API library inclusion succeeded.", true);
    } else {
        eMember_log_debug("AWeber API library is already included from another plugin.", true);
    }
    try {
        $aweber = new AWeberAPI($eMember_aweber_access_keys['consumer_key'], $eMember_aweber_access_keys['consumer_secret']);
        $account = $aweber->getAccount($eMember_aweber_access_keys['access_key'], $eMember_aweber_access_keys['access_secret']);
        //Get Aweber account
        $account_id = $account->id;
        $mylists = $account->lists;
    } catch (Exception $e) {
        eMember_log_debug($e->getMessage(), false);
        return;
    }
    eMember_log_debug("AWeber account retrieved. Account ID: " . $account_id, true);
    $target_list_name = str_replace("@aweber.com", "", $full_target_list_name);
    eMember_log_debug("Attempting to signup the user to the AWeber list: " . $target_list_name, true);
    $list_name_found = false;
    foreach ($mylists as $list) {
        if ($list->name == $target_list_name || $list->unique_list_id == $target_list_name) {
            $list_name_found = true;
            try {
                //Create a subscriber
                $params = array('email' => $email_to_subscribe, 'name' => $fname . ' ' . $lname);
                $subscribers = $list->subscribers;
                $new_subscriber = $subscribers->create($params);
                eMember_log_debug("User with email address " . $email_to_subscribe . " was added to the AWeber list: " . $target_list_name, true);
            } catch (Exception $exc) {
                eMember_log_debug("Failed to complete the AWeber signup! Error Details Below.", false);
                eMember_log_debug_array($exc, true);
            }
        }
    }
    if (!$list_name_found) {
        eMember_log_debug("Error! Could not find the AWeber list (" . $full_target_list_name . ") in your AWeber Account! Please double check your list name value for typo.", false);
    }
}
 public function verify_auth_data($verify_code = null)
 {
     if ($this->consumer_key == null) {
         if ($verify_code != null && !empty($verify_code)) {
             try {
                 ////error_log( $verify_code );
                 $auth = AWeberAPI::getDataFromAweberID($verify_code);
                 list($this->consumer_key, $this->consumer_secret, $this->access_key, $this->access_secret) = $auth;
                 update_option('stepify_aw_consumer_key', $this->consumer_key);
                 update_option('stepify_aw_consumer_secret', $this->consumer_secret);
                 update_option('stepify_aw_access_key', $this->access_key);
                 update_option('stepify_aw_access_secret', $this->access_secret);
                 return true;
             } catch (Exception $e) {
                 var_dump($e->getMessage());
             }
         }
         return false;
     } else {
         return true;
     }
 }
Exemple #4
0
                 $mailchimp_lists[$mclist['id']] = $mclist['name'];
             }
             $mailchimp_lists_serialized = serialize($mailchimp_lists);
             update_option('wpcb_mailchimp_api_key',$api_key);
             update_option('wpcb_mailchimp_lists',$mailchimp_lists_serialized);
             $showresponse_2 = "<div class='wpcb_success' style='margin: 0px 10px 10px 10px;'><p>". __('Connected to API successfully.', 'wp-conversion-boxes') ."<a href='' style='float:right;' onclick='jQuery(this).parent().parent().fadeOut(300).hide();'>Close</a></p></div>";
         }
         break;
         
 // Aweber                
 case 3: if (!class_exists('AWeberAPI')) {
             include_once(plugin_dir_path(dirname(__FILE__)).'mailers/aweber_api/aweber_api.php');
         }
         try {
                 $aweber_data = AWeberAPI::getDataFromAweberID($api_key);
                 $aweber = new AWeberAPI($aweber_data[0], $aweber_data[1]);
                 $account = $aweber->getAccount($aweber_data[2], $aweber_data[3]);
                 $allaweberlists = $account->lists;
                 foreach($allaweberlists as $aweberlist){
                     $aweber_lists[$aweberlist->id] = $aweberlist->name;
                 }
                 $aweber_data_serialized = serialize($aweber_data);
                 $aweber_lists_serialized = serialize($aweber_lists);
                 update_option('wpcb_aweber_api_key',$aweber_data_serialized);
                 update_option('wpcb_aweber_lists',$aweber_lists_serialized);
                 $showresponse_3 = "<div class='wpcb_success' style='margin: 0px 10px 10px 10px;'><p>". __('Connected to Aweber successfully.', 'wp-conversion-boxes') ."<a href='' style='float:right;' onclick='jQuery(this).parent().parent().fadeOut(300).hide();'>Close</a></p></div>";
         }
         catch (Exception $ex) {
                 $showresponse_3 = "<div id='wpcb_error' style='margin: 0px 10px 10px 10px;'><p>". __('Invalid authorization Key. Please try again.', 'wp-conversion-boxes') ."<a href='' style='float:right;' onclick='jQuery(this).parent().parent().fadeOut(300).hide();'>Close</a></p></div>";
         }
         break;
Exemple #5
0
 function get_aweber_account()
 {
     $this->initialize_aweber();
     $settings = $this->get_settings();
     $info = $settings['optin']['aweber-account-info'];
     $aweber = new AWeberAPI($info['consumer_key'], $info['consumer_secret']);
     try {
         $account = $aweber->getAccount($info['access_key'], $info['access_secret']);
     } catch (AWeberException $e) {
         $account = null;
     }
     return $account;
 }
Exemple #6
0
 function validateAweberAuthorizationCode($code)
 {
     $this->initializeAweberApi();
     try {
         list($consumer_key, $consumer_secret, $access_key, $access_secret) = AWeberAPI::getDataFromAweberID($code);
     } catch (AWeberException $e) {
         list($consumer_key, $consumer_secret, $access_key, $access_secret) = null;
     }
     if (!$access_secret) {
         return array('error' => __('Invalid Aweber authorization code.  Please make sure you entered it correctly.', 'premise'));
     }
     $aweber = new AWeberAPI($consumer_key, $consumer_secret);
     try {
         $account = $aweber->getAccount($access_key, $access_secret);
     } catch (AWeberResponseError $e) {
         $account = null;
     }
     if (!$account) {
         return array('error' => __('Unable to connect to Aweber account.  Please try again.', 'premise'));
     }
     return compact('consumer_key', 'consumer_secret', 'access_key', 'access_secret');
 }
function sendAWeber($mailSubscribe)
{
    if (defined('AW_AUTHCODE') && defined('AW_LISTNAME')) {
        $token = 'api_aweber/' . substr(AW_AUTHCODE, 0, 10);
        if (!file_exists($token)) {
            try {
                $auth = AWeberAPI::getDataFromAweberID(AW_AUTHCODE);
                file_put_contents($token, json_encode($auth));
            } catch (AWeberAPIException $exc) {
                errorLog("AWeber", "[" . $exc->type . "] " . $exc->message . " Docs: " . $exc->documentation_url);
                throw new Exception("Authorization error", 5);
            }
        }
        if (file_exists($token)) {
            $key = file_get_contents($token);
        }
        list($consumerKey, $consumerSecret, $accessToken, $accessSecret) = json_decode($key);
        $aweber = new AWeberAPI($consumerKey, $consumerSecret);
        try {
            $account = $aweber->getAccount($accessToken, $accessSecret);
            $foundLists = $account->lists->find(array('name' => AW_LISTNAME));
            $lists = $foundLists[0];
            $params = array('email' => $mailSubscribe, 'name' => getName($mailSubscribe));
            if (isset($lists)) {
                $lists->subscribers->create($params);
            } else {
                errorLog("AWeber", "List is not found");
                throw new Exception("Error found Lists", 4);
            }
        } catch (AWeberAPIException $exc) {
            if ($exc->status == 400) {
                throw new Exception("Email exist", 2);
            } else {
                errorLog("AWeber", "[" . $exc->type . "] " . $exc->message . " Docs: " . $exc->documentation_url);
            }
        }
    }
}
Exemple #8
0
function et_aweber_submit_authorization_code()
{
    if (!wp_verify_nonce($_POST['et_load_nonce'], 'et_load_nonce')) {
        die(__('Nonce failed.', 'Divi'));
    }
    $et_authorization_code = $_POST['et_authorization_code'];
    if ('' === $et_authorization_code) {
        die(__('Authorization code is empty.', 'Divi'));
    }
    if (!class_exists('AWeberAPI')) {
        require_once ET_BUILDER_DIR . 'subscription/aweber/aweber_api.php';
    }
    try {
        $auth = AWeberAPI::getDataFromAweberID($et_authorization_code);
        if (!(is_array($auth) && 4 === count($auth))) {
            die(__('Authorization code is invalid. Try regenerating it and paste in the new code.', 'Divi'));
        }
        list($consumer_key, $consumer_secret, $access_key, $access_secret) = $auth;
        et_update_option('divi_aweber_consumer_key', $consumer_key);
        et_update_option('divi_aweber_consumer_secret', $consumer_secret);
        et_update_option('divi_aweber_access_key', $access_key);
        et_update_option('divi_aweber_access_secret', $access_secret);
        die('success');
    } catch (AWeberAPIException $exc) {
        printf('<p>%4$s.</p>
			<ul>
				<li>%5$s: %1$s</li>
				<li>%6$s: %2$s</li>
				<li>%7$s: %3$s</li>
			</ul>', esc_html($exc->type), esc_html($exc->message), esc_html($exc->documentation_url), esc_html__('Aweber API Exception', 'Divi'), esc_html__('Type', 'Divi'), esc_html__('Message', 'Divi'), esc_html__('Documentation', 'Divi'));
    }
    die;
}
Exemple #9
0
 /**
  * Uses the app's authorization code to fetch an access token
  *
  * @param String Authorization code from authorize app page
  */
 public static function getDataFromAweberID($string)
 {
     list($consumerKey, $consumerSecret, $requestToken, $tokenSecret, $verifier) = AWeberAPI::_parseAweberID($string);
     if (!$verifier) {
         return null;
     }
     $aweber = new AweberAPI($consumerKey, $consumerSecret);
     $aweber->adapter->user->requestToken = $requestToken;
     $aweber->adapter->user->tokenSecret = $tokenSecret;
     $aweber->adapter->user->verifier = $verifier;
     list($accessToken, $accessSecret) = $aweber->getAccessToken();
     return array($consumerKey, $consumerSecret, $accessToken, $accessSecret);
 }
function pmproaw_options_page()
{
    global $pmproaw_lists;
    //check for a valid API key and get lists
    $options = get_option("pmproaw_options");
    $authorization_code = $options['authorization_code'];
    $access_key = $options['access_key'];
    $access_secret = $options['access_secret'];
    //get token if needed
    if (!empty($authorization_code) && (empty($access_key) || empty($access_secret))) {
        try {
            # set $authorization_code to the code that is given to you from
            # https://auth.aweber.com/1.0/oauth/authorize_app/YOUR_APP_ID
            $auth = AWeberAPI::getDataFromAweberID($authorization_code);
            list($consumerKey, $consumerSecret, $accessKey, $accessSecret) = $auth;
            # Store the Consumer key/secret, as well as the AccessToken key/secret
            # in your app, these are the credentials you need to access the API.
            $access_key = $accessKey;
            $options['access_key'] = $access_key;
            $access_secret = $accessSecret;
            $options['access_secret'] = $access_secret;
            update_option('pmproaw_options', $options);
        } catch (AWeberAPIException $exc) {
            print "<h3>AWeberAPIException:</h3>";
            print " <li> Type: {$exc->type}              <br>";
            print " <li> Msg : {$exc->message}           <br>";
            print " <li> Docs: {$exc->documentation_url} <br>";
            print "<hr>";
        }
    }
    //get lists
    if (!empty($access_key) && !empty($access_secret)) {
        //get aweber account or fail
        $account = pmproaw_getAccount();
        if (!empty($account)) {
            try {
                $pmproaw_lists = $account->lists->data['entries'];
                $all_lists = array();
                //save all lists in an option
                $i = 0;
                foreach ($pmproaw_lists as $list) {
                    $all_lists[$i]['id'] = $list['id'];
                    $all_lists[$i]['account_id'] = $account->id;
                    $all_lists[$i]['name'] = $list['name'];
                    $i++;
                }
                /** Save all of our new data */
                update_option("pmproaw_all_lists", $all_lists);
            } catch (AWeberAPIException $exc) {
                print "<h3>AWeberAPIException:</h3>";
                print " <li> Type: {$exc->type}              <br>";
                print " <li> Msg : {$exc->message}           <br>";
                print " <li> Docs: {$exc->documentation_url} <br>";
                print "<hr>";
            }
        } else {
            global $pmproaw_exception;
            if (!empty($pmproaw_exception)) {
                print "<h3>AWeberAPIException:</h3>";
                print " <li> Type: {$pmproaw_exception->type}              <br>";
                print " <li> Msg : {$pmproaw_exception->message}           <br>";
                print " <li> Docs: {$pmproaw_exception->documentation_url} <br>";
                print "<hr>";
            }
        }
    }
    ?>
<div class="wrap">
	<div id="icon-options-general" class="icon32"><br></div>
	<h2>PMPro AWeber Integration Options</h2>		
	
	<?php 
    if (!empty($msg)) {
        ?>
		<div class="message <?php 
        echo $msgt;
        ?>
"><p><?php 
        echo $msg;
        ?>
</p></div>
	<?php 
    }
    ?>
	
	<form action="options.php" method="post">
		
		<p>This plugin will integrate your site with AWeber. You can choose one or more AWeber lists to have users subscribed to when they signup for your site.</p>
		<p>If you have <a href="http://www.paidmembershipspro.com">Paid Memberships Pro</a> installed, you can also choose one or more AWeber lists to have members subscribed to for each membership level.</p>
		<p>Don't have a AWeber account? <a href="http://www.aweber.com/?422729" target="_blank">Get one here</a>.</p>
		
		<?php 
    if (empty($authorization_code)) {
        ?>
			<div class="updated"><p>To get started, you must authorize this website to access your AWeber account. <a target="_blank" href="?page=pmproaw_options&oauth=1">Click here to authorize this site to access your AWeber account</a>. Then copy the "authorization code" given into the field below and click "Save Settings" to continue.</p></div>
			<?php 
    }
    settings_fields('pmproaw_options');
    do_settings_sections('pmproaw_options');
    ?>
		
		<p><br /></p>
						
		<div class="bottom-buttons">
			<input type="hidden" name="pmprot_options[set]" value="1" />
			<input type="submit" name="submit" class="button-primary" value="<?php 
    esc_attr_e('Save Settings');
    ?>
">				
		</div>
		
	</form>
</div>
<?php 
}
 /**
  * API instance.
  *
  * @since 141004
  * @package s2Member\List_Servers
  *
  * @return AWeberAPI|null AWeber API instance.
  */
 public static function aw_api()
 {
     if (!$GLOBALS['WS_PLUGIN__']['s2member']['o']['aweber_api_key']) {
         return NULL;
     }
     // Not possible.
     if (!class_exists('AWeberAPI')) {
         // Include the AWeber API class here.
         include_once dirname(dirname(__FILE__)) . '/externals/aweber/aweber_api.php';
     }
     if (count($key_parts = explode('|', $GLOBALS['WS_PLUGIN__']['s2member']['o']['aweber_api_key'])) < 5) {
         return NULL;
     }
     // It's an invalid API key; i.e., authorization code.
     list($consumerKey, $consumerSecret, $requestToken, $tokenSecret, $verifier) = $key_parts;
     $internal_api_key_checksum = md5($consumerKey . $consumerSecret . $requestToken . $tokenSecret . $verifier);
     if (count($internal_key_parts = explode('|', $GLOBALS['WS_PLUGIN__']['s2member']['o']['aweber_internal_api_key'])) >= 5) {
         list(, , , , $checksum) = $internal_key_parts;
     }
     // Only need checksum for now.
     if (empty($checksum) || $checksum !== $internal_api_key_checksum) {
         try {
             $aw_api = new AWeberAPI($consumerKey, $consumerSecret);
             $aw_api->user->requestToken = $requestToken;
             $aw_api->user->tokenSecret = $tokenSecret;
             $aw_api->user->verifier = $verifier;
             if (!is_array($accessToken = $aw_api->getAccessToken()) || count($accessToken) < 2) {
                 return NULL;
             }
             // Not possible.
             list($accessTokenKey, $accessTokenSecret) = $accessToken;
             if (!$accessTokenKey || !$accessTokenSecret) {
                 return NULL;
             }
             // Not possible.
             $GLOBALS['WS_PLUGIN__']['s2member']['o']['aweber_internal_api_key'] = $internal_api_key = $consumerKey . '|' . $consumerSecret . '|' . $accessTokenKey . '|' . $accessTokenSecret . '|' . $internal_api_key_checksum;
             c_ws_plugin__s2member_menu_pages::update_all_options(array('ws_plugin__s2member_aweber_internal_api_key' => $internal_api_key), TRUE, FALSE, FALSE, FALSE, FALSE);
         } catch (Exception $exception) {
             return NULL;
             // API initialization failure.
         }
     }
     if (count($internal_key_parts = explode('|', $GLOBALS['WS_PLUGIN__']['s2member']['o']['aweber_internal_api_key'])) < 5) {
         return NULL;
     }
     // It's an invalid internal API key. Cannot continue.
     list($consumerKey, $consumerSecret, $accessTokenKey, $accessTokenSecret, $checksum) = $internal_key_parts;
     try {
         $aw_api = new AWeberAPI($consumerKey, $consumerSecret);
         $aw_api->___account = $aw_api->getAccount($accessTokenKey, $accessTokenSecret);
         return $aw_api;
         // AWeberAPI instance.
     } catch (Exception $exception) {
         return NULL;
         // API initialization failure.
     }
 }
Exemple #12
0
 function getAweberLists($forceUpdate = false)
 {
     if (!$forceUpdate) {
         //check from cache
         $aweberLists = get_transient($this->_optin_AweberListsTransient);
         if ($aweberLists !== false) {
             return $aweberLists;
         }
     }
     $this->initializeAweberApi();
     $settings = $this->getSettings();
     $info = $settings['optin']['aweber-account-info'];
     $aweber = new AWeberAPI($info['consumer_key'], $info['consumer_secret']);
     try {
         $account = $aweber->getAccount($info['access_key'], $info['access_secret']);
     } catch (AWeberException $e) {
         $account = null;
     }
     $lists = array();
     $list_web_forms = array();
     if ($account) {
         foreach ($account->getWebForms() as $this_webform) {
             $link_parts = explode('/', $this_webform->url);
             $list_id = $link_parts[4];
             if (!array_key_exists($list_id, $list_web_forms)) {
                 $list_web_forms[$list_id] = array('web_forms' => array(), 'split_tests' => array());
             }
             $list_web_forms[$list_id]['web_forms'][] = $this_webform;
         }
         foreach ($account->getWebFormSplitTests() as $this_webform) {
             $link_parts = explode('/', $this_webform->url);
             $list_id = $link_parts[4];
             if (!array_key_exists($list_id, $list_web_forms)) {
                 $list_web_forms[$list_id] = array('web_forms' => array(), 'split_tests' => array());
             }
             $list_web_forms[$list_id]['split_tests'][] = $this_webform;
         }
         $lists = $account->lists;
         foreach ($lists as $this_list) {
             if (array_key_exists($this_list->id, $list_web_forms)) {
                 $list_web_forms[$this_list->id]['list'] = $this_list;
             }
         }
     }
     $return = array();
     /* still need to figure out why we need the block of code below.
     		foreach($list_web_forms as $id => $data) {
     			//$item = array('id' => $id, 'name' => $data['list']->name, 'forms' => array()); //original from premise
     			$item = array('id' => $data['list']->name, 'name' => $data['list']->name, 'forms' => array());
     			foreach($data['web_forms'] as $web_form) {
     				$item['forms'][] = array('id' => $web_form->id, 'url' => $web_form->url, 'name' => $web_form->name);
     			}
     			foreach($data['split_tests'] as $split_test) {
     				$item['forms'][] = array('id' => $split_test->id, 'url' => $split_test->url, 'name' => sprintf(__('Split Test: %s', 'mab' ), $web_form->name));
     			}
     			$return[] = $item;
     		}
     		//*/
     foreach ($lists as $this_list) {
         $return[] = array('id' => $this_list->unique_list_id, 'name' => $this_list->name);
     }
     set_transient($this->_optin_AweberListsTransient, $return, 24 * 60 * 60);
     //set for one day.
     return $return;
 }
 public function indeed_aWebberSubscribe($consumer_key, $consumer_secret, $access_key, $access_secret, $aw_list, $e_mail, $full_name = '')
 {
     require_once $this->dir_path . '/email_services/aweber/aweber_api.php';
     try {
         $aweber = new AWeberAPI($consumer_key, $consumer_secret);
         $account = $aweber->getAccount($access_key, $access_secret);
         $list = $account->loadFromUrl('/accounts/' . $account->id . '/lists/' . $aw_list);
         $subscriber = array('email' => $e_mail, 'ip' => $_SERVER['REMOTE_ADDR']);
         if (!empty($full_name)) {
             $subscriber['name'] = $full_name;
         }
         $list->subscribers->create($subscriber);
         return 1;
     } catch (AWeberException $e) {
         return 0;
     }
 }
function seed_cspv4_emaillist_aweber_add_subscriber($args)
{
    global $seed_cspv4, $seed_cspv4_post_result;
    extract($seed_cspv4);
    require_once SEED_CSPV4_PLUGIN_PATH . 'lib/nameparse.php';
    require_once SEED_CSPV4_PLUGIN_PATH . 'extentions/aweber/aweber_api/aweber_api.php';
    // If tracking enabled
    if (!empty($enable_reflink)) {
        seed_cspv4_emaillist_database_add_subscriber();
    }
    $aweber_auth = get_option('seed_cspv4_aweber_auth');
    extract($aweber_auth);
    if (!empty($consumer_key)) {
        $consumerKey = $consumer_key;
        $consumerSecret = $consumer_secret;
        $aweber = new AWeberAPI($consumerKey, $consumerSecret);
        $list_id = $aweber_listid;
        $name = '';
        if (!empty($_REQUEST['name'])) {
            $name = $_REQUEST['name'];
        }
        $email = $_REQUEST['email'];
        $fname = '';
        $lname = '';
        if (!empty($name)) {
            $name = seed_cspv4_parse_name($name);
            $fname = $name['first'];
            $lname = $name['last'];
        }
        $fullname = $fname . ' ' . $lname;
    }
    try {
        $account = $aweber->getAccount($access_key, $access_secret);
        $account_id = $account->id;
        $listURL = "/accounts/{$account_id}/lists/{$list_id}";
        $list = $account->loadFromUrl($listURL);
        # create a subscriber
        $params = array('email' => $email, 'name' => $fullname, 'ip_address' => seed_cspv4_get_ip());
        $subscribers = $list->subscribers;
        $new_subscriber = $subscribers->create($params);
        # success!
        //$this->add_subscriber($email,$fname,$lname);
        if (empty($seed_cspv4_post_result['status'])) {
            $seed_cspv4_post_result['status'] = '200';
        }
    } catch (AWeberAPIException $exc) {
        if ($exc->status == '400') {
            $seed_cspv4_post_result['status'] = '600';
            $seed_cspv4_post_result['msg'] = $txt_already_subscribed_msg;
            $seed_cspv4_post_result['msg_class'] = 'alert-danger';
        } else {
            $seed_cspv4_post_result['status'] = '500';
        }
        // var_dump($exc);
        // print "<h3>AWeberAPIException:</h3>";
        // print " <li> Type: $exc->type              <br>";
        // print " <li> Msg : $exc->message           <br>";
        // print " <li> Docs: $exc->documentation_url <br>";
        // print "<hr>";
    }
}
 /**
  * Processes integration with 3rd party APIs.
  * @param cf_Contest $contest
  * @param cf_Participant $participant
  */
 static function process_integration($contest, $participant)
 {
     // mailing lists
     $email = $participant->email;
     $name = '';
     $first_name = '';
     $last_name = '';
     if ($contest->cf_name_field == '1') {
         $name = $participant->first_name . ' ' . $participant->last_name;
         $first_name = $participant->first_name;
         $last_name = $participant->last_name;
     }
     if ($contest->cf_participants_export == 'campaignmonitor') {
         if (!class_exists(CS_REST_Subscribers)) {
             require cf_Manager::$plugin_dir . 'lib/campaign_monitor/csrest_subscribers.php';
         }
         $wrap = new CS_REST_Subscribers($contest->cf_campaignmonitor_list, $contest->cf_campaignmonitor_key);
         $res = $wrap->add(array('EmailAddress' => $email, 'Name' => $name, 'Resubscribe' => true));
         // $res->was_successful()
         // $res->http_status_code
         // $res->response
     } else {
         if ($contest->cf_participants_export == 'mailchimp') {
             if (!class_exists(MCAPI)) {
                 require cf_Manager::$plugin_dir . 'lib/MCAPI.class.php';
             }
             $double_optin = true;
             if ($contest->cf_double_optin == '1') {
                 $double_optin = false;
             }
             $api = new MCAPI($contest->cf_mailchimp_key);
             $api->listSubscribe($contest->cf_mailchimp_list, $email, array('FNAME' => $first_name, 'LNAME' => $last_name), 'html', $double_optin);
             // double optin;
             // if($api->errorCode)
             // $api->errorCode
             // $api->errorMessage
         } else {
             if ($contest->cf_participants_export == 'getresponse') {
                 require cf_Manager::$plugin_dir . 'lib/GetResponseAPI.class.php';
                 $api = new GetResponseAPI($contest->cf_getresponse_key);
                 $response = $api->addContact($contest->cf_getresponse_list, $name, $email);
                 // var_dump($response);
             } else {
                 if ($contest->cf_participants_export == 'aweber') {
                     require cf_Manager::$plugin_dir . 'lib/aweber/aweber_api.php';
                     $aweber_auth = $contest->cf_aweber_auth;
                     if (!empty($aweber_auth) && is_array($aweber_auth)) {
                         $api = new AWeberAPI($aweber_auth['consumer_key'], $aweber_auth['consumer_secret']);
                         try {
                             $account = $api->getAccount($aweber_auth['access_key'], $aweber_auth['access_secret']);
                             $listURL = "/accounts/{$account->id}/lists/{$contest->cf_aweber_list}";
                             $list = $account->loadFromUrl($listURL);
                             // create a subscriber
                             $params = array('email' => $email, 'ip_address' => $_SERVER['REMOTE_ADDR'], 'name' => $name);
                             $subscribers = $list->subscribers;
                             $new_subscriber = $subscribers->create($params);
                         } catch (AWeberAPIException $exc) {
                             // TODO log (post comments?)
                         }
                     }
                 }
             }
         }
     }
     do_action('cf_process_integration', $contest, $participant);
 }
 /**
  * Returns id of the subscriber
  */
 function subscribe($list_id, $sub)
 {
     $key = $this->auth_key;
     $auth = $this->parse_authkey($key);
     if (empty($auth)) {
         throw new Exception("Invalid Auth");
     }
     $access_tokens = $this->get_access_tokens();
     if (empty($access_tokens)) {
         throw new Exception("Auth keys have already expired");
     }
     list($access_token, $access_token_secret) = $access_tokens;
     $api = new AWeberAPI($auth['api_key'], $auth['api_secret']);
     $api->adapter->debug = $this->debug;
     $api->user->tokenSecret = $auth['token_secret'];
     $api->user->requestToken = $auth['request_token'];
     $api->user->verifier = $auth['auth_verifier'];
     try {
         $account = $api->getAccount($access_token, $access_token_secret);
         $list = $account->lists->getById($list_id);
         $subs = $list->subscribers;
         // now create a new subscriber
         $sub = $subs->create($sub);
         $attr = $sub->attrs();
         return $attr['id'];
     } catch (Exception $e) {
         error_log("An error occured while subscribing: " . $e->getMessage());
         return false;
     }
 }
        $options['create_subscriber_signup_text'] = get_option('aweber_signup_text_value');
    }
    update_option($this->widgetOptionsName, $options);
}
if ($authorization_removed) {
    $this->deauthorize();
    $pluginAdminOptions = get_option($this->adminOptionsName);
    $options = get_option($this->widgetOptionsName);
    echo '<div id="message" class="updated"><p>Your connection to your AWeber account has been closed.</p></div>';
    $error = $temp_error = null;
} elseif ($oauth_id and !$pluginAdminOptions['access_secret']) {
    // Then they just saved a key and didn't remove anything
    // Check it's validity then save it for later use
    $error_code = "";
    try {
        list($consumer_key, $consumer_secret, $access_key, $access_secret) = AWeberAPI::getDataFromAweberID($oauth_id);
    } catch (AWeberAPIException $exc) {
        list($consumer_key, $consumer_secret, $access_key, $access_secret) = null;
        # make error messages customer friendly.
        $descr = $exc->description;
        $descr = preg_replace('/http.*$/i', '', $descr);
        # strip labs.aweber.com documentation url from error message
        $descr = preg_replace('/[\\.\\!:]+.*$/i', '', $descr);
        # strip anything following a . : or ! character
        $error_code = " ({$descr})";
    } catch (AWeberOAuthDataMissing $exc) {
        list($consumer_key, $consumer_secret, $access_key, $access_secret) = null;
    } catch (AWeberException $exc) {
        list($consumer_key, $consumer_secret, $access_key, $access_secret) = null;
    }
    if (!$access_secret) {
Exemple #18
0
function aweber_form()
{
    $keys = get_option(THEME_NAME . "_aweber_keys");
    if (isset($_POST["email"])) {
        $email = is_email($_POST["email"]);
    }
    if (isset($_POST["u_name"])) {
        $u_name = esc_textarea($_POST["u_name"]);
    }
    if (isset($_POST["listID"])) {
        $listID = remove_html_slashes($_POST["listID"]);
    }
    $ip = $_SERVER['REMOTE_ADDR'];
    extract($keys);
    if ($email && $u_name && $listID) {
        try {
            $aweber = new AWeberAPI($consumer_key, $consumer_secret);
            $account = $aweber->getAccount($access_key, $access_secret);
            $account_id = $account->id;
            $listURL = "/accounts/{$account_id}/lists/{$listID}";
            $list = $account->loadFromUrl($listURL);
            # create a subscriber
            $params = array('email' => $email, 'ip_address' => $ip, 'name' => $u_name);
            $subscribers = $list->subscribers;
            $new_subscriber = $subscribers->create($params);
        } catch (AWeberAPIException $exc) {
            print 'Error: ' . $exc->message . '';
            exit(1);
        }
    }
    die;
}
     $contactform_obj->sendUserNotification();
 }
 $redirect_url = $contactform_obj->cfg['form_redirecturl'] ? $contactform_obj->cfg['form_redirecturl'] : '';
 // VALIDATION MESSAGE
 $json_response = array('status' => 'ok', 'message' => $contactform_obj->cfg['form_validationmessage'], 'redirect_url' => $redirect_url);
 /**************************************************************************************
  * AWEBER API
  **************************************************************************************/
 if (!empty($cfg['aweber']['consumerkey']) && !empty($cfg['aweber']['consumersecret']) && !empty($cfg['aweber']['accesstokenkey']) && !empty($cfg['aweber']['accesstokensecret']) && !empty($cfg['aweber']['lists'])) {
     $service_id = 'aweber';
     debugServiceSeparator($service_id, true);
     $service_requirements_status = $cfgenwpapi_obj->checkServiceRequirements($service_id);
     if ($service_requirements_status['status']) {
         include '../api/aweber/aweber_api.php';
         try {
             $aweber_api = new AWeberAPI($cfg[$service_id]['consumerkey'], $cfg[$service_id]['consumersecret']);
             $aweber_account = $aweber_api->getAccount($cfg[$service_id]['accesstokenkey'], $cfg[$service_id]['accesstokensecret']);
             //print_r($aweber_account);
             $aweber_account_id = $aweber_account->id;
             foreach ($cfg[$service_id]['lists'] as $list_v) {
                 $list_id = $list_v['list_id'];
                 $aweber_contact = array();
                 $aweber_contact['email'] = '';
                 $aweber_contact['name'] = '';
                 $aweber_contact['ipaddress'] = $_SERVER['REMOTE_ADDR'];
                 // FIELDS
                 if (!empty($list_v['fields'])) {
                     foreach ($list_v['fields'] as $field_v) {
                         if ($field_v['list_field_id'] == 'email' || $field_v['list_field_id'] == 'name') {
                             $aweber_contact[$field_v['list_field_id']] = getElementValue($field_v['element_id']);
                         }
	/**
	 * Get the Aweber lists for an account
	 *
	 */
	public function get_aweber_lists() {

		$options = '';
		$consumerKey = '';
		$consumerSecret = '';
		$accessKey = '';
		$accessSecret = '';

		if (isset($_POST['code']) && $_POST['code'] != '') {

			require_once( 'includes/aweber/aweber_api.php');

			try {
				$credentials = AWeberAPI::getDataFromAweberID(sanitize_text_field( $_POST['code'] ));
				list($consumerKey, $consumerSecret, $accessKey, $accessSecret) = $credentials;


				$consumerKey = isset($consumerKey) && !empty($consumerKey) ? $consumerKey : '';
				$consumerSecret = isset($consumerSecret) && !empty($consumerSecret) ? $consumerSecret : '';
				$accessKey = isset($accessKey) && !empty($accessKey) ? $accessKey : '';
				$accessSecret = isset($accessSecret) && !empty($accessSecret) ? $accessSecret : '';
			} catch (AWeberAPIException $exc) {
				error_log($exc);
			}

			try {

				$aweber = new AWeberAPI($consumerKey, $consumerSecret);
				$account = $aweber->getAccount($accessKey, $accessSecret);
				$lists = $account->loadFromUrl('/accounts/' . $account->id . '/lists/');

				foreach ($lists as $list) {
					$options .= '<option value="' . $list->id . '">' .  $list->name . '</option>';
				}

			} catch (AWeberAPIException $exc) { error_log($exc); }
		}

		if (isset($_POST['list']) && $_POST['list'] != '') {

			$consumerKey     = sanitize_text_field( $_POST['consumer_key'] );
			$consumerSecret  = sanitize_text_field( $_POST['consumer_secret'] );
			$accessKey       = sanitize_text_field( $_POST['access_key'] );
			$accessSecret    = sanitize_text_field( $_POST['access_secret'] );

			require_once( 'includes/aweber/aweber_api.php');

			try {

				$aweber = new AWeberAPI($consumerKey, $consumerSecret);
				$account = $aweber->getAccount($accessKey, $accessSecret);
				$lists = $account->loadFromUrl('/accounts/' . $account->id . '/lists/');

				$options = '';
				foreach ($lists as $list) {
					if ($_POST['list'] == $list->id) {
						$options .= '<option value="' . $list->id . '" selected="selected">' .  $list->name . '</option>';
					} else {
						$options .= '<option value="' . $list->id . '">' .  $list->name . '</option>';
					}
				}

			} catch (AWeberAPIException $exc) { error_log($exc); }
		}

		echo json_encode(array(
			'html'               => $options,
			'consumer_key'       => $consumerKey,
			'consumer_secret'    => $consumerSecret,
			'access_key'         => $accessKey,
			'access_secret'      => $accessSecret,
		));

		die(); // this is required to terminate immediately and return a proper response
	}
Exemple #21
0
 public function makeAweberSubscribeEntry($user_id)
 {
     include userpro_path . 'lib/aweber_api/aweber_api.php';
     $email = userpro_profile_data('user_email', $user_id);
     $fname = userpro_profile_data('first_name', $user_id);
     $credentials = array();
     if (get_option('userpro_aweber_credentials') === false) {
         $credentials = AWeberAPI::getDataFromAweberID(userpro_get_option('aweber_api'));
         if (!$credentials) {
             echo 'Incorrect aweber authorization code';
         } else {
             update_option('userpro_aweber_credentials', $credentials);
         }
     } else {
         $credentials = get_option('userpro_aweber_credentials');
     }
     list($consumerKey, $consumerSecret, $accessKey, $accessSecret) = $credentials;
     $aweber = new AWeberAPI($consumerKey, $consumerSecret);
     $account = $aweber->getAccount($accessKey, $accessSecret);
     $account_id = $account->id;
     $mylists = $account->lists;
     $list_name_found = false;
     foreach ($mylists as $list) {
         if ($list->id == userpro_get_option('aweber_listname')) {
             $list_name_found = true;
             try {
                 //Create a subscriber
                 $params = array('email' => $email, 'name' => $fname);
                 $subscribers = $list->subscribers;
                 $new_subscriber = $subscribers->create($params);
             } catch (Exception $exc) {
             }
         }
     }
 }
 public function get_authenticated_instance()
 {
     global $edd_options;
     $authorization_code = isset($edd_options['edd_aweb_api']) ? trim($edd_options['edd_aweb_api']) : '';
     $msg = '';
     if (!empty($authorization_code)) {
         if (!class_exists('AWeberAPI')) {
             require_once EDD_AWEBER_PATH . '/aweber/aweber_api.php';
         }
         $error_code = "";
         if (false !== get_option('aweber_secrets')) {
             $options = get_option('aweber_secrets');
             $msg = $options;
             try {
                 $api = new AWeberAPI($options['consumer_key'], $options['consumer_secret']);
             } catch (AWeberAPIException $exc) {
                 $api = false;
             }
             return $api;
         } else {
             try {
                 list($consumer_key, $consumer_secret, $access_key, $access_secret) = AWeberAPI::getDataFromAweberID($authorization_code);
             } catch (AWeberAPIException $exc) {
                 list($consumer_key, $consumer_secret, $access_key, $access_secret) = null;
                 # make error messages customer friendly.
                 $descr = $exc->message;
                 $descr = preg_replace('/http.*$/i', '', $descr);
                 # strip labs.aweber.com documentation url from error message
                 $descr = preg_replace('/[\\.\\!:]+.*$/i', '', $descr);
                 # strip anything following a . : or ! character
                 $error_code = " ({$descr})";
             } catch (AWeberOAuthDataMissing $exc) {
                 list($consumer_key, $consumer_secret, $access_key, $access_secret) = null;
             } catch (AWeberException $exc) {
                 list($consumer_key, $consumer_secret, $access_key, $access_secret) = null;
             }
             if (!$access_secret) {
                 $msg = '<div id="aweber_access_token_failed" class="error">';
                 $msg .= "Unable to connect to your AWeber Account{$error_code}:<br />";
                 # show oauth_id if it failed and an api exception was not raised
                 if (empty($error_code)) {
                     $msg .= "Authorization code entered was: {$authorization_code} <br />";
                 }
                 $msg .= "Please make sure you entered the complete authorization code and try again.</div>";
             } else {
                 $secrets = array('consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret, 'access_key' => $access_key, 'access_secret' => $access_secret);
                 update_option('aweber_secrets', $secrets);
             }
         }
     } else {
         delete_option('aweber_secrets');
     }
     $msg = isset($msg) ? $msg : $pluginAdminOptions;
     update_option('aweber_response', $msg);
 }
 /**
  * Creates Aweber account using the data saved to plugin's database.
  * @return object or false
  */
 function get_aweber_account($name)
 {
     if (!class_exists('AWeberAPI')) {
         require_once get_template_directory() . '/includes/subscription/aweber/aweber_api.php';
     }
     $options_array = RAD_Rapidology::get_rapidology_options();
     $account = false;
     if (isset($options_array['accounts']['aweber'][$name])) {
         $consumer_key = $options_array['accounts']['aweber'][$name]['consumer_key'];
         $consumer_secret = $options_array['accounts']['aweber'][$name]['consumer_secret'];
         $access_key = $options_array['accounts']['aweber'][$name]['access_key'];
         $access_secret = $options_array['accounts']['aweber'][$name]['access_secret'];
         try {
             // Aweber requires curl extension to be enabled
             if (!function_exists('curl_init')) {
                 return false;
             }
             $aweber = new AWeberAPI($consumer_key, $consumer_secret);
             if (!$aweber) {
                 return false;
             }
             $account = $aweber->getAccount($access_key, $access_secret);
         } catch (Exception $exc) {
             return false;
         }
     }
     return $account;
 }
 function update($new_instance, $old_instance)
 {
     $instance = $old_instance;
     $instance['title'] = strip_tags($new_instance['title']);
     $instance['text'] = strip_tags($new_instance['text']);
     $instance['list'] = strip_tags($new_instance['list']);
     $instance['color'] = strip_tags($new_instance['color']);
     if ($instance['code'] != $new_instance['code'] && $new_instance['code'] != get_option(THEME_NAME . "_footer_subscribe_code")) {
         $instance['code'] = strip_tags($new_instance['code']);
         update_option(THEME_NAME . "_footer_subscribe_code", $instance['code']);
         $oauth_id = $new_instance['code'];
         if ($oauth_id) {
             try {
                 list($consumerKey, $consumerSecret, $accessKey, $accessSecret) = AWeberAPI::getDataFromAweberID($oauth_id);
             } catch (AWeberAPIException $exc) {
                 list($consumerKey, $consumerSecret, $accessKey, $accessSecret) = null;
                 # make error messages customer friendly.
                 $descr = $exc->description;
                 $descr = preg_replace('/http.*$/i', '', $descr);
                 # strip labs.aweber.com documentation url from error message
                 $descr = preg_replace('/[\\.\\!:]+.*$/i', '', $descr);
                 # strip anything following a . : or ! character
                 $error_code = " ({$descr})";
             } catch (AWeberOAuthDataMissing $exc) {
                 list($consumerKey, $consumerSecret, $accessKey, $accessSecret) = null;
             } catch (AWeberException $exc) {
                 list($consumerKey, $consumerSecret, $accessKey, $accessSecret) = null;
             }
         }
         $keys = array('consumer_key' => $consumerKey, 'consumer_secret' => $consumerSecret, 'access_key' => $accessKey, 'access_secret' => $accessSecret);
         update_option(THEME_NAME . "_aweber_keys", $keys);
     }
     return $instance;
 }
    /**
     * Retrieves the tokens from AWeber
     * @return string
     */
    function aweber_authorization($api_key)
    {
        if (!class_exists('AWeberAPI')) {
            require_once ET_BUILDER_DIR . 'subscription/aweber/aweber_api.php';
        }
        try {
            $auth = AWeberAPI::getDataFromAweberID($api_key);
            if (!(is_array($auth) && 4 === count($auth))) {
                $error_message = esc_html__('Authorization code is invalid. Try regenerating it and paste in the new code.', 'et_builder_plugin');
            } else {
                $error_message = 'success';
                list($consumer_key, $consumer_secret, $access_key, $access_secret) = $auth;
                self::update_option(array('newsletter_main_aweber_key' => sanitize_text_field($api_key), 'aweber_consumer_key' => sanitize_text_field($consumer_key), 'aweber_consumer_secret' => sanitize_text_field($consumer_secret), 'aweber_access_key' => sanitize_text_field($access_key), 'aweber_access_secret' => sanitize_text_field($access_secret)));
            }
        } catch (AWeberAPIException $exc) {
            $error_message = sprintf('<p>%4$s</p>
				<ul>
					<li>%5$s: %1$s</li>
					<li>%6$s: %2$s</li>
					<li>%7$s: %3$s</li>
				</ul>', esc_html($exc->type), esc_html($exc->message), esc_html($exc->documentation_url), esc_html__('AWeberAPIException.', 'et_builder_plugin'), esc_html__('Type', 'et_builder_plugin'), esc_html__('Message', 'et_builder_plugin'), esc_html__('Documentation', 'et_builder_plugin'));
        }
        return $error_message;
    }
function snp_popup_submit()
{
    global $wpdb;
    $result = array();
    $errors = array();
    $_POST['email'] = trim($_POST['email']);
    if (isset($_POST['name'])) {
        $_POST['name'] = trim($_POST['name']);
    }
    if (!snp_is_valid_email($_POST['email'])) {
        $errors['email'] = 1;
    }
    if (isset($_POST['name']) && !$_POST['name']) {
        $errors['name'] = 1;
    }
    $post_id = intval($_POST['popup_ID']);
    if ($post_id) {
        $POPUP_META = get_post_meta($post_id);
    }
    $cf_data = array();
    if (isset($POPUP_META['snp_cf']) && $post_id) {
        $cf = unserialize($POPUP_META['snp_cf'][0]);
        if (isset($cf) && is_array($cf)) {
            foreach ($cf as $f) {
                if (isset($f['name'])) {
                    if (strpos($f['name'], '[')) {
                        $f['name'] = substr($f['name'], 0, strpos($f['name'], '['));
                    }
                    if (!empty($_POST[$f['name']])) {
                        $cf_data[$f['name']] = $_POST[$f['name']];
                    }
                }
                if (isset($f['required']) && $f['required'] == 'Yes' && !$cf_data[$f['name']]) {
                    $errors[$f['name']] = 1;
                }
            }
        }
    }
    if (count($errors) > 0) {
        $result['Errors'] = $errors;
        $result['Ok'] = false;
    } else {
        $Done = 0;
        if (!empty($_POST['name'])) {
            $names = snp_detect_names($_POST['name']);
        } else {
            $names = array('first' => '', 'last' => '');
        }
        $api_error_msg = '';
        if (snp_get_option('ml_manager') == 'directmail') {
            require_once SNP_DIR_PATH . '/include/directmail/class.directmail.php';
            $form_id = snp_get_option('ml_dm_form_id');
            if ($form_id) {
                $api = new DMSubscribe();
                $retval = $api->submitSubscribeForm($form_id, $_POST['email'], $error_message);
                if ($retval) {
                    $Done = 1;
                } else {
                    // Error... Send by email?
                    $api_error_msg = $error_message;
                }
            }
        } elseif (snp_get_option('ml_manager') == 'sendy') {
            $list_id = $POPUP_META['snp_ml_sendy_list'][0];
            if (!$list_id) {
                $list_id = snp_get_option('ml_sendy_list');
            }
            if ($list_id) {
                $options = array('list' => $list_id, 'boolean' => 'true');
                $args['email'] = $_POST['email'];
                if (!empty($_POST['name'])) {
                    $args['name'] = $_POST['name'];
                }
                if (count($cf_data) > 0) {
                    $args = array_merge($args, (array) $cf_data);
                }
                $content = array_merge($args, $options);
                $postdata = http_build_query($content);
                $ch = curl_init(snp_get_option('ml_sendy_url') . '/subscribe');
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
                $api_result = curl_exec($ch);
                curl_close($ch);
                if (strval($api_result) == 'true' || strval($api_result) == '1' || strval($api_result) == 'Already subscribed.') {
                    $Done = 1;
                } else {
                    $api_error_msg = $api_result;
                }
            }
        } elseif (snp_get_option('ml_manager') == 'mailchimp') {
            require_once SNP_DIR_PATH . '/include/mailchimp/Mailchimp.php';
            $ml_mc_list = $POPUP_META['snp_ml_mc_list'][0];
            if (!$ml_mc_list) {
                $ml_mc_list = snp_get_option('ml_mc_list');
            }
            if (snp_get_option('ml_mc_apikey') && $ml_mc_list) {
                $api = new Mailchimp(snp_get_option('ml_mc_apikey'));
                $args = array();
                if (!empty($_POST['name'])) {
                    $args = array('FNAME' => $names['first'], 'LNAME' => $names['last']);
                }
                if (count($cf_data) > 0) {
                    $args = array_merge($args, (array) $cf_data);
                }
                try {
                    $double_optin = snp_get_option('ml_mc_double_optin');
                    if ($double_optin == 1) {
                        $double_optin = true;
                    } else {
                        $double_optin = false;
                    }
                    $double_optin = snp_get_option('ml_mc_double_optin');
                    if ($double_optin == 1) {
                        $double_optin = true;
                    } else {
                        $double_optin = false;
                    }
                    $send_welcome = snp_get_option('ml_mc_send_welcome');
                    if ($send_welcome == 1) {
                        $send_welcome = true;
                    } else {
                        $send_welcome = false;
                    }
                    $retval = $api->lists->subscribe($ml_mc_list, array('email' => $_POST['email']), $args, 'html', $double_optin, false, true, $send_welcome);
                    $Done = 1;
                } catch (Exception $e) {
                    if ($e->getCode() == 214) {
                        $Done = 1;
                    } else {
                        $api_error_msg = $e->getMessage();
                    }
                }
            }
        } elseif (snp_get_option('ml_manager') == 'egoi') {
            $ml_egoi_apikey = snp_get_option('ml_egoi_apikey');
            $client = new SoapClient('http://api.e-goi.com/v2/soap.php?wsdl');
            try {
                $ml_egoi_list = $POPUP_META['snp_ml_egoi_list'][0];
                if (!$ml_egoi_list) {
                    $ml_egoi_list = snp_get_option('ml_egoi_list');
                }
                $args = array('apikey' => $ml_egoi_apikey, 'listID' => $ml_egoi_list, 'email' => $_POST['email']);
                if (!empty($_POST['name'])) {
                    $args['first_name'] = $names['first'];
                    $args['last_name'] = $names['last'];
                }
                if (count($cf_data) > 0) {
                    $CustomFields = array();
                    foreach ($cf_data as $k => $v) {
                        $args[$k] = $v;
                    }
                }
                $res = $client->addSubscriber($args);
                if (isset($res['UID'])) {
                    $Done = 1;
                }
            } catch (Exception $e) {
                // Error...
                // We'll send this by email.
            }
        } elseif (snp_get_option('ml_manager') == 'getresponse') {
            $ml_gr_apikey = snp_get_option('ml_gr_apikey');
            require_once SNP_DIR_PATH . '/include/getresponse/jsonRPCClient.php';
            $api = new jsonRPCClient('http://api2.getresponse.com');
            try {
                $ml_gr_list = $POPUP_META['snp_ml_gr_list'][0];
                if (!$ml_gr_list) {
                    $ml_gr_list = snp_get_option('ml_gr_list');
                }
                $args = array('campaign' => $ml_gr_list, 'email' => $_POST['email']);
                if (!empty($_POST['name'])) {
                    $args['name'] = $_POST['name'];
                }
                if (count($cf_data) > 0) {
                    $CustomFields = array();
                    foreach ($cf_data as $k => $v) {
                        $CustomFields[] = array('name' => $k, 'content' => $v);
                    }
                    $args['customs'] = $CustomFields;
                }
                $res = $api->add_contact($ml_gr_apikey, $args);
                $Done = 1;
            } catch (Exception $e) {
                // Error...
                // We'll send this by email.
                $api_error_msg = $e->getMessage();
            }
        } elseif (snp_get_option('ml_manager') == 'campaignmonitor') {
            require_once SNP_DIR_PATH . '/include/campaignmonitor/csrest_subscribers.php';
            $ml_cm_list = $POPUP_META['snp_ml_cm_list'][0];
            if (!$ml_cm_list) {
                $ml_cm_list = snp_get_option('ml_cm_list');
            }
            $wrap = new CS_REST_Subscribers($ml_cm_list, snp_get_option('ml_cm_apikey'));
            $args = array('EmailAddress' => $_POST['email'], 'Resubscribe' => true);
            if (!empty($_POST['name'])) {
                $args['Name'] = $_POST['name'];
            }
            if (count($cf_data) > 0) {
                $CustomFields = array();
                foreach ($cf_data as $k => $v) {
                    $CustomFields[] = array('Key' => $k, 'Value' => $v);
                }
                $args['CustomFields'] = $CustomFields;
            }
            $res = $wrap->add($args);
            if ($res->was_successful()) {
                $Done = 1;
            } else {
                // Error...
                // We'll send this by email.
                $api_error_msg = 'Failed with code ' . $res->http_status_code;
            }
        } elseif (snp_get_option('ml_manager') == 'icontact') {
            require_once SNP_DIR_PATH . '/include/icontact/iContactApi.php';
            iContactApi::getInstance()->setConfig(array('appId' => snp_get_option('ml_ic_addid'), 'apiPassword' => snp_get_option('ml_ic_apppass'), 'apiUsername' => snp_get_option('ml_ic_username')));
            $oiContact = iContactApi::getInstance();
            $res1 = $oiContact->addContact($_POST['email'], null, null, isset($names['first']) ? $names['first'] : '', isset($names['last']) ? $names['last'] : '', null, null, null, null, null, null, null, null, null);
            if ($res1->contactId) {
                $ml_ic_list = $POPUP_META['snp_ml_ic_list'][0];
                if (!$ml_ic_list) {
                    $ml_ic_list = snp_get_option('ml_ic_list');
                }
                if ($oiContact->subscribeContactToList($res1->contactId, $ml_ic_list, 'normal')) {
                    $Done = 1;
                }
            } else {
                // Error...
                // We'll send this by email.
                $api_error_msg = 'iContact Problem!';
            }
        } elseif (snp_get_option('ml_manager') == 'constantcontact') {
            require_once SNP_DIR_PATH . '/include/constantcontact/class.cc.php';
            $cc = new cc(snp_get_option('ml_cc_username'), snp_get_option('ml_cc_pass'));
            $send_welcome = snp_get_option('ml_cc_send_welcome');
            if ($send_welcome == 1) {
                $cc->set_action_type('contact');
            }
            $email = $_POST['email'];
            $contact_list = $POPUP_META['snp_ml_cc_list'][0];
            if (!$contact_list) {
                $contact_list = snp_get_option('ml_cc_list');
            }
            $extra_fields = array();
            if (!empty($names['first'])) {
                $extra_fields['FirstName'] = $names['first'];
            }
            if (!empty($names['last'])) {
                $extra_fields['LastName'] = $names['last'];
            }
            if (count($cf_data) > 0) {
                $extra_fields = array_merge($extra_fields, (array) $cf_data);
            }
            $contact = $cc->query_contacts($email);
            if ($contact) {
                $status = $cc->update_contact($contact['id'], $email, $contact_list, $extra_fields);
                if ($status) {
                    $Done = 1;
                } else {
                    $api_error_msg = "Contact Operation failed: " . $cc->http_get_response_code_error($cc->http_response_code);
                }
            } else {
                $new_id = $cc->create_contact($email, $contact_list, $extra_fields);
                if ($new_id) {
                    $Done = 1;
                } else {
                    $api_error_msg = "Contact Operation failed: " . $cc->http_get_response_code_error($cc->http_response_code);
                }
            }
        } elseif (snp_get_option('ml_manager') == 'madmimi') {
            require_once SNP_DIR_PATH . '/include/madmimi/MadMimi.class.php';
            if (snp_get_option('ml_madm_username') && snp_get_option('ml_madm_apikey')) {
                $mailer = new MadMimi(snp_get_option('ml_madm_username'), snp_get_option('ml_madm_apikey'));
                $user = array('email' => $_POST['email']);
                if (!empty($names['first'])) {
                    $user['FirstName'] = $names['first'];
                }
                if (!empty($names['last'])) {
                    $user['LastName'] = $names['last'];
                }
                if (count($cf_data) > 0) {
                    $user = array_merge($user, (array) $cf_data);
                }
                $ml_madm_list = $POPUP_META['snp_ml_madm_list'][0];
                if (!$ml_madm_list) {
                    $ml_madm_list = snp_get_option('ml_madm_list');
                }
                $user['add_list'] = $ml_madm_list;
                $res = $mailer->AddUser($user);
                $Done = 1;
            }
        } elseif (snp_get_option('ml_manager') == 'infusionsoft') {
            require_once SNP_DIR_PATH . '/include/infusionsoft/infusionsoft.php';
            if (snp_get_option('ml_inf_subdomain') && snp_get_option('ml_inf_apikey')) {
                $infusionsoft = new Infusionsoft(snp_get_option('ml_inf_subdomain'), snp_get_option('ml_inf_apikey'));
                $user = array('Email' => $_POST['email']);
                if (!empty($names['first'])) {
                    $user['FirstName'] = $names['first'];
                }
                if (!empty($names['last'])) {
                    $user['LastName'] = $names['last'];
                }
                if (count($cf_data) > 0) {
                    $user = array_merge($user, (array) $cf_data);
                }
                $ml_inf_list = $POPUP_META['snp_ml_inf_list'][0];
                if (!$ml_inf_list) {
                    $ml_inf_list = snp_get_option('ml_inf_list');
                }
                $contact_id = $infusionsoft->contact('add', $user);
                $r = $infusionsoft->APIEmail('optIn', $_POST['email'], "Ninja Popups on " . get_bloginfo());
                if ($contact_id && $ml_inf_list) {
                    $infusionsoft->contact('addToGroup', $contact_id, $ml_inf_list);
                }
                if ($contact_id) {
                    $Done = 1;
                }
            }
        } elseif (snp_get_option('ml_manager') == 'aweber') {
            require_once SNP_DIR_PATH . '/include/aweber/aweber_api.php';
            if (get_option('snp_ml_aw_auth_info')) {
                $aw = get_option('snp_ml_aw_auth_info');
                try {
                    $aweber = new AWeberAPI($aw['consumer_key'], $aw['consumer_secret']);
                    $account = $aweber->getAccount($aw['access_key'], $aw['access_secret']);
                    $aw_list = $POPUP_META['snp_ml_aw_lists'][0];
                    if (!$aw_list) {
                        $aw_list = snp_get_option('ml_aw_lists');
                    }
                    $list = $account->loadFromUrl('/accounts/' . $account->id . '/lists/' . $aw_list);
                    $subscriber = array('email' => $_POST['email'], 'ip' => $_SERVER['REMOTE_ADDR']);
                    if (!empty($_POST['name'])) {
                        $subscriber['name'] = $_POST['name'];
                    }
                    if (count($cf_data) > 0) {
                        $subscriber['custom_fields'] = $cf_data;
                    }
                    $r = $list->subscribers->create($subscriber);
                    $Done = 1;
                } catch (AWeberException $e) {
                    $api_error_msg = $e->getMessage();
                }
            }
        } elseif (snp_get_option('ml_manager') == 'wysija' && class_exists('WYSIJA')) {
            $ml_wy_list = $POPUP_META['snp_ml_wy_list'][0];
            if (!$ml_wy_list) {
                $ml_wy_list = snp_get_option('ml_wy_list');
            }
            $userData = array('email' => $_POST['email'], 'firstname' => $names['first'], 'lastname' => $names['last']);
            $data = array('user' => $userData, 'user_list' => array('list_ids' => array($ml_wy_list)));
            $userHelper =& WYSIJA::get('user', 'helper');
            if ($userHelper->addSubscriber($data)) {
                $Done = 1;
            } else {
                $api_error_msg = 'MailPoet Problem!';
            }
        } elseif (snp_get_option('ml_manager') == 'sendpress') {
            $ml_sp_list = $POPUP_META['snp_ml_sp_list'][0];
            if (!$ml_sp_list) {
                $ml_sp_list = snp_get_option('ml_sp_list');
            }
            try {
                SendPress_Data::subscribe_user($ml_sp_list, $_POST['email'], $names['first'], $names['last'], 2);
                $Done = 1;
            } catch (Exception $e) {
                $api_error_msg = 'SendPress Problem!';
            }
        } elseif (snp_get_option('ml_manager') == 'mymail') {
            $userdata = array('firstname' => $names['first'], 'lastname' => $names['last']);
            $ml_mm_list = $POPUP_META['snp_ml_mm_list'][0];
            if (!$ml_mm_list) {
                $ml_mm_list = snp_get_option('ml_mm_list');
            }
            $lists = array($ml_mm_list);
            if (function_exists('mymail')) {
                $entry = $userdata;
                $entry['email'] = $_POST['email'];
                $double_optin = snp_get_option('ml_mm_double_optin');
                if ($double_optin == 1) {
                    $entry['status'] = 0;
                } else {
                    $entry['status'] = 1;
                }
                if (count($cf_data) > 0) {
                    foreach ($cf_data as $k => $v) {
                        $entry[$k] = $v;
                    }
                }
                $subscriber_id = mymail('subscribers')->add($entry, true);
                if (!is_wp_error($subscriber_id)) {
                    $success = mymail('subscribers')->assign_lists($subscriber_id, $lists, false);
                }
                if ($success) {
                    $Done = 1;
                } else {
                    $api_error_msg = 'MyMail Problem!';
                }
            } else {
                $return = mymail_subscribe($_POST['email'], $userdata, $lists);
                if (!is_wp_error($return)) {
                    $Done = 1;
                } else {
                    $api_error_msg = 'MyMail Problem!';
                }
            }
        } elseif (snp_get_option('ml_manager') == 'csv' && snp_get_option('ml_csv_file') && is_writable(SNP_DIR_PATH . 'csv/')) {
            if (!isset($_POST['name'])) {
                $_POST['name'] = '';
            }
            if (count($cf_data) > 0) {
                $CustomFields = '';
                foreach ($cf_data as $k => $v) {
                    $CustomFields .= $k . ' = ' . $v . ';';
                }
            }
            $data = $_POST['email'] . ";" . $_POST['name'] . ";" . $CustomFields . get_the_title($_POST['popup_ID']) . " (" . $_POST['popup_ID'] . ");" . date('Y-m-d H:i') . ";" . $_SERVER['REMOTE_ADDR'] . ";\n";
            if (file_put_contents(SNP_DIR_PATH . 'csv/' . snp_get_option('ml_csv_file'), $data, FILE_APPEND | LOCK_EX) !== FALSE) {
                $Done = 1;
            } else {
                $api_error_msg = 'CSV Problem!';
            }
        }
        if (snp_get_option('ml_manager') == 'email' || !$Done) {
            $Email = snp_get_option('ml_email');
            if (!$Email) {
                $Email = get_bloginfo('admin_email');
            }
            if (!isset($_POST['name'])) {
                $_POST['name'] = '--';
            }
            $error_mgs = '';
            if ($api_error_msg != '') {
                $error_mgs .= "IMPORTANT! You have received this message because connection to your e-mail marketing software failed. Please check connection setting in the plugin configuration.\n";
                $error_mgs .= $api_error_msg . "\n";
            }
            $cf_msg = '';
            if (count($cf_data) > 0) {
                foreach ($cf_data as $k => $v) {
                    $cf_msg .= $k . ": " . $v . "\n";
                }
            }
            $msg = "New subscription on " . get_bloginfo() . "\n" . $error_mgs . "\n" . "E-mail: " . $_POST['email'] . "\n" . "Name: " . $_POST['name'] . "\n" . $cf_msg . "\n" . "Form: " . get_the_title($_POST['popup_ID']) . " (" . $_POST['popup_ID'] . ")\n" . "\n" . "Date: " . date('Y-m-d H:i') . "\n" . "IP: " . $_SERVER['REMOTE_ADDR'] . "";
            wp_mail($Email, "New subscription on " . get_bloginfo(), $msg);
        }
        $result['Ok'] = true;
    }
    echo json_encode($result);
    die('');
}
Exemple #27
0
 function et_pb_get_aweber_account()
 {
     if (!class_exists('AWeberAPI')) {
         require_once get_template_directory() . '/includes/subscription/aweber/aweber_api.php';
     }
     $consumer_key = et_get_option('divi_aweber_consumer_key');
     $consumer_secret = et_get_option('divi_aweber_consumer_secret');
     $access_key = et_get_option('divi_aweber_access_key');
     $access_secret = et_get_option('divi_aweber_access_secret');
     try {
         // Aweber requires curl extension to be enabled
         if (!function_exists('curl_init')) {
             return false;
         }
         $aweber = new AWeberAPI($consumer_key, $consumer_secret);
         if (!$aweber) {
             return false;
         }
         $account = $aweber->getAccount($access_key, $access_secret);
     } catch (Exception $exc) {
         return false;
     }
     return $account;
 }
function emember_auto_responder_settings()
{
    $emember_config = Emember_Config::getInstance();
    echo '<div class="wrap">';
    echo '<div id="poststuff"><div id="post-body">';
    if (isset($_POST['info_update'])) {
        $errors = "";
        if (isset($_POST['aweber_make_connection'])) {
            if ($emember_config->getValue('eMember_aweber_authorize_status') != 'authorized') {
                $authorization_code = trim($_POST['aweber_auth_code']);
                if (!class_exists('AWeberAPI')) {
                    include_once 'lib/auto-responder/aweber_api/aweber_api.php';
                }
                $auth = AWeberAPI::getDataFromAweberID($authorization_code);
                list($consumerKey, $consumerSecret, $accessKey, $accessSecret) = $auth;
                $eMember_aweber_access_keys = array('consumer_key' => $consumerKey, 'consumer_secret' => $consumerSecret, 'access_key' => $accessKey, 'access_secret' => $accessSecret);
                $emember_config->setValue('eMember_aweber_access_keys', $eMember_aweber_access_keys);
                if ($eMember_aweber_access_keys['access_key']) {
                    try {
                        $aweber = new AWeberAPI($consumerKey, $consumerSecret);
                        $account = $aweber->getAccount($accessKey, $accessSecret);
                    } catch (AWeberException $e) {
                        $account = null;
                    }
                    if (!$account) {
                        //$this->deauthorize();//TODO - remove the keys
                        $errors = 'AWeber authentication failed! Please try connecting again.';
                    } else {
                        $emember_config->setValue('eMember_aweber_authorize_status', 'authorized');
                        $_POST['eMember_use_new_aweber_integration'] = '1';
                        //Set the eMember_use_new_aweber_integration flag to enabled
                        echo '<div id="message" class="updated fade"><p><strong>';
                        echo 'AWeber authorization success!';
                        echo '</strong></p></div>';
                    }
                } else {
                    $errors = 'You need to specify a valid authorization code to establish an AWeber API connection';
                }
            } else {
                //Remove existing connection
                $eMember_aweber_access_keys = array('consumer_key' => '', 'consumer_secret' => '', 'access_key' => '', 'access_secret' => '');
                $emember_config->setValue('eMember_aweber_access_keys', $eMember_aweber_access_keys);
                $emember_config->setValue('eMember_aweber_authorize_status', '');
                $_POST['eMember_use_new_aweber_integration'] = '';
                //Set the eMember_use_new_aweber_integration flag to disabled
                echo '<div id="message" class="updated fade"><p><strong>';
                echo 'AWeber connection removed!';
                echo '</strong></p></div>';
            }
        }
        $emember_config->setValue('eMember_enable_aweber_int', $_POST['eMember_enable_aweber_int'] == '1' ? '1' : '');
        $emember_config->setValue('eMember_aweber_list_name', (string) $_POST["eMember_aweber_list_name"]);
        $emember_config->setValue('eMember_use_new_aweber_integration', $_POST['eMember_use_new_aweber_integration'] == '1' ? '1' : '');
        $emember_config->setValue('eMember_use_mailchimp', $_POST['eMember_use_mailchimp'] == '1' ? '1' : '');
        //$emember_config->setValue('eMember_enable_global_chimp_int', ($_POST['eMember_enable_global_chimp_int']=='1') ? '1':'' );
        $emember_config->setValue('eMember_chimp_list_name', trim($_POST["eMember_chimp_list_name"]));
        $emember_config->setValue('eMember_chimp_api_key', trim($_POST["eMember_chimp_api_key"]));
        $emember_config->setValue('eMember_mailchimp_disable_double_optin', $_POST['eMember_mailchimp_disable_double_optin'] == '1' ? '1' : '');
        $emember_config->setValue('eMember_mailchimp_disable_final_welcome_email', $_POST['eMember_mailchimp_disable_final_welcome_email'] == '1' ? '1' : '');
        $emember_config->setValue('eMember_mailchimp_signup_date_field_name', trim($_POST["eMember_mailchimp_signup_date_field_name"]));
        $emember_config->setValue('eMember_use_getresponse', $_POST['eMember_use_getresponse'] == '1' ? '1' : '');
        $emember_config->setValue('eMember_getResponse_campaign_name', (string) $_POST["eMember_getResponse_campaign_name"]);
        $emember_config->setValue('eMember_getResponse_api_key', (string) $_POST["eMember_getResponse_api_key"]);
        $emember_config->setValue('eMember_use_generic_autoresponder_integration', $_POST['eMember_use_generic_autoresponder_integration'] == '1' ? '1' : '');
        $emember_config->setValue('eMember_use_global_generic_autoresponder_integration', $_POST['eMember_use_global_generic_autoresponder_integration'] == '1' ? '1' : '');
        $emember_config->setValue('eMember_generic_autoresponder_target_list_email', trim($_POST["eMember_generic_autoresponder_target_list_email"]));
        $emember_config->saveConfig();
        if (!empty($errors)) {
            echo '<div id="message" class="error"><p>';
            echo $errors;
            echo '</p></div>';
        } else {
            echo '<div id="message" class="updated fade"><p><strong>';
            echo 'Autoresponder Options Updated!';
            echo '</strong></p></div>';
        }
    }
    ?>

    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
        <input type="hidden" name="info_update" id="info_update" value="true" />

        <div class="postbox">
            <h3><label for="title">AWeber Settings (<a href="http://www.tipsandtricks-hq.com/wordpress-membership/?p=151" target="_blank">AWeber Integration Instructions</a>)</label></h3>
            <div class="inside">

                <table width="100%" border="0" cellspacing="0" cellpadding="6">

                    <tr valign="top"><td width="25%" align="left">
                            <strong>Enable AWeber Signup:</strong>
                        </td><td align="left">
                            <input name="eMember_enable_aweber_int" type="checkbox"<?php 
    if ($emember_config->getValue('eMember_enable_aweber_int') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
                            <br /><i>When checked the plugin will automatically sign up the members at registration time to your AWeber List specified below. For membership level specific signup see the "Autoresponder List/Campaign Name" section of the membership level.</i><br /><br />
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            <strong>AWeber List Name:</strong>
                        </td><td align="left">
                            <input name="eMember_aweber_list_name" type="text" size="40" value="<?php 
    echo $emember_config->getValue('eMember_aweber_list_name');
    ?>
"/>
                            <br /><i>The name of the AWeber list where the members will be signed up to (eg. listname@aweber.com)</i><br /><br />
                        </td></tr>
                </table>

                <div style="border-bottom: 1px solid #dedede; height: 10px"></div>
                <table class="form-table">

                    <tr valign="top"><td width="25%" align="left">
                            Use the New AWeber Integration Option:
                        </td><td align="left">
                            <input name="eMember_use_new_aweber_integration" type="checkbox"<?php 
    if ($emember_config->getValue('eMember_use_new_aweber_integration') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
                            <br /><i>When checked the plugin will use the new AWeber integration method which uses the AWeber API (this method is recommended over the old method that uses the email parser).</i>
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            Step 1: Get Your AWeber Authorization Code:
                        </td><td align="left">
                            <a href="https://auth.aweber.com/1.0/oauth/authorize_app/999d6172" target="_blank">Click here to get your authorization code</a>
                            <br /><i>Clicking on the above link will take you to the AWeber site where you will need to log in using your AWeber username and password. Then give access to the Tips and Tricks HQ AWeber app.</i>
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            Step 2: Paste in Your Authorization Code:
                        </td><td align="left">
                            <input name="aweber_auth_code" type="text" size="140" value=""/>
                            <br /><i>Paste the long authorization code that you got from AWeber in the above field.</i>
                        </td></tr>

                    <tr valign="top"><td colspan="2" align="left">
                            <?php 
    if ($emember_config->getValue('eMember_aweber_authorize_status') == 'authorized') {
        echo '<input type="submit" name="aweber_make_connection" value="Remove Connection" class= "button button" />';
    } else {
        echo '<input type="submit" name="aweber_make_connection" value="Make Connection" class= "button-primary" />';
    }
    ?>
                        </td></tr>

                </table>
            </div></div>

        <div class="postbox">
            <h3><label for="title">MailChimp Settings (<a href="http://www.tipsandtricks-hq.com/wordpress-membership/?p=236" target="_blank">MailChimp Integration Instructions</a>)</label></h3>
            <div class="inside">

                <table width="100%" border="0" cellspacing="0" cellpadding="6">

                    <tr valign="top"><td width="25%" align="left">
                            <strong>Use MailChimp AutoResponder:</strong>
                        </td><td align="left">
                            <input name="eMember_use_mailchimp" type="checkbox"<?php 
    if ($emember_config->getValue('eMember_use_mailchimp') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
                            <br /><i>Check this if you want to use MailChimp Autoresponder service. For membership level specific signup see the "Autoresponder List/Campaign Name" section of the membership level.</i><br /><br />
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            <strong>MailChimp List Name:</strong>
                        </td><td align="left">
                            <input name="eMember_chimp_list_name" type="text" size="30" value="<?php 
    echo $emember_config->getValue('eMember_chimp_list_name');
    ?>
"/>
                            <br /><i>The name of the MailChimp list where the customers will be signed up to (e.g. Customer List)</i><br /><br />
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            <strong>MailChimp API Key:</strong>
                        </td><td align="left">
                            <input name="eMember_chimp_api_key" type="text" size="50" value="<?php 
    echo $emember_config->getValue('eMember_chimp_api_key');
    ?>
"/>
                            <br /><i>The API Key of your MailChimp account (can be found under the "Account" tab). By default the API Key is not active so make sure you activate it in your Mailchimp account. If you do not have the API Key then you can use the username and password option below but it is better to use the API key.</i>
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            <strong>Disable Double Opt-In:</strong>
                        </td><td align="left">
                            <input name="eMember_mailchimp_disable_double_optin" type="checkbox"<?php 
    if ($emember_config->getValue('eMember_mailchimp_disable_double_optin') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
                            Do not send double opt-in confirmation email
                            <br /><i>Use this checkbox if you do not wish to use the double opt-in option. Please note that abusing this option may cause your MailChimp account to be suspended.</i><br />

                            <input name="eMember_mailchimp_disable_final_welcome_email" type="checkbox"<?php 
    if ($emember_config->getValue('eMember_mailchimp_disable_final_welcome_email') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
                            Do not send welcome email
                            <br /><i>Use this checkbox if you do not wish to send the welcome email sent by MailChimp when a user subscribes to your list. This will only work if you disable the double opt-in option above.</i>
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            <strong>Signup Date Field Name (optional):</strong>
                        </td><td align="left">
                            <input name="eMember_mailchimp_signup_date_field_name" type="text" size="30" value="<?php 
    echo $emember_config->getValue('eMember_mailchimp_signup_date_field_name');
    ?>
"/>
                            <br /><i>If you have configured a signup date field for your mailchimp list then specify the name of the field here (example: SIGNUPDATE). <a href="http://kb.mailchimp.com/article/how-do-i-create-a-date-field-in-my-signup-form" target="_blank">More Info</a></i><br /><br />
                        </td></tr>

                </table>
            </div></div>

        <div class="postbox">
            <h3><label for="title">GetResponse Settings (<a href="http://www.tipsandtricks-hq.com/wordpress-membership/?p=283" target="_blank">GetResponse Integration Instructions</a>)</label></h3>
            <div class="inside">

                <table width="100%" border="0" cellspacing="0" cellpadding="6">

                    <tr valign="top"><td width="25%" align="left">
                            <strong>Use GetResponse AutoResponder:</strong>
                        </td><td align="left">
                            <input name="eMember_use_getresponse" type="checkbox"<?php 
    if ($emember_config->getValue('eMember_use_getresponse') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
                            <br /><i>Check this if you want to use GetResponse Autoresponder service.</i><br /><br />
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            <strong>GetResponse Campaign Name:</strong>
                        </td><td align="left">
                            <input name="eMember_getResponse_campaign_name" type="text" size="30" value="<?php 
    echo $emember_config->getValue('eMember_getResponse_campaign_name');
    ?>
"/>
                            <br /><i>The name of the GetResponse campaign where the customers will be signed up to (e.g. marketing)</i><br /><br />
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            <strong>GetResponse API Key:</strong>
                        </td><td align="left">
                            <input name="eMember_getResponse_api_key" type="text" size="50" value="<?php 
    echo $emember_config->getValue('eMember_getResponse_api_key');
    ?>
"/>
                            <br /><i>The API Key of your GetResponse account (can be found inside your GetResponse Account).</i><br /><br />
                        </td></tr>

                </table>
            </div></div>

        <div class="postbox">
            <h3><label for="title">Generic Autoresponder Integration Settings</label></h3>
            <div class="inside">

                <br /><strong>&nbsp; &nbsp; If your autoresponder provider allows you to signup users just by sending an email to the list email address with the user's email as the from address then you can use this method of integration</strong>

                <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">

                    <tr valign="top"><td width="25%" align="left">
                            Enable Generic Autoresponder Integration:
                        </td><td align="left">
                            <input name="eMember_use_generic_autoresponder_integration" type="checkbox"<?php 
    if ($emember_config->getValue('eMember_use_generic_autoresponder_integration') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
                            <br /><p class="description">Use this option if you want to use the generic auotoresponder integration option.</p>
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            Enable Global Integration:
                        </td><td align="left">
                            <input name="eMember_use_global_generic_autoresponder_integration" type="checkbox"<?php 
    if ($emember_config->getValue('eMember_use_global_generic_autoresponder_integration') != '') {
        echo ' checked="checked"';
    }
    ?>
 value="1"/>
                            <br /><p class="description">When checked the plugin will automatically sign up every member to your list/campaign specified below. If you want to selectively signup members on a per membership level basis then use the Autoresponder settings of that level.</p>
                        </td></tr>

                    <tr valign="top"><td width="25%" align="left">
                            Global List/Campaign Email Address:
                        </td><td align="left">
                            <input name="eMember_generic_autoresponder_target_list_email" type="text" size="40" value="<?php 
    echo $emember_config->getValue('eMember_generic_autoresponder_target_list_email');
    ?>
"/>
                            <br /><p class="description">The email address of the list where the member will be signed up to. The plugin will send the autoresponder signup request email to this address.</p>
                        </td></tr>

                </table>
            </div></div>

        <div class="submit">
            <input type="submit" name="info_update" class="button-primary" value="<?php 
    _e('Update options');
    ?>
 &raquo;" />
        </div>
    </form>

    <?php 
    echo '</div></div>';
    echo '</div>';
}
 /**
  * Processes aweber list field. Called by AJAX script.
  */
 public static function field_aweber_list_ajax()
 {
     require CH_Manager::$plugin_dir . 'lib/aweber/aweber_api.php';
     $contest = new CH_Contest($_POST['contest_id']);
     if (!$contest->_valid) {
         die;
     }
     $aweber_auth = $contest->ch_aweber_auth;
     if (empty($aweber_auth)) {
         die;
     }
     if (empty($aweber_auth['consumer_key']) || empty($aweber_auth['consumer_secret']) || empty($aweber_auth['access_key']) || empty($aweber_auth['access_secret'])) {
         die;
     }
     $consumerKey = $aweber_auth['consumer_key'];
     $consumerSecret = $aweber_auth['consumer_secret'];
     $access_key = $aweber_auth['access_key'];
     $access_secret = $aweber_auth['access_secret'];
     $aweber = new AWeberAPI($consumerKey, $consumerSecret);
     $account = $aweber->getAccount($access_key, $access_secret);
     $value = '';
     if (!empty($_POST['value'])) {
         $value = $_POST['value'];
     }
     $output = '';
     foreach ($account->lists as $list) {
         $selected = '';
         if ($list->id == $value) {
             $selected = ' selected="selected"';
         }
         $output .= '<option value="' . $list->id . '"' . $selected . '>' . $list->name . '</option>';
     }
     echo $output;
     die;
 }
function sendAWeber($mailSubscribe, $merge_vars = NULL)
{
    if (defined('AW_AUTHCODE') && defined('AW_LISTNAME') && $merge_vars) {
        $token = 'api_aweber/' . substr(AW_AUTHCODE, 0, 10);
        if (!file_exists($token)) {
            try {
                $auth = AWeberAPI::getDataFromAweberID(AW_AUTHCODE);
                file_put_contents($token, json_encode($auth));
            } catch (AWeberAPIException $exc) {
                errorLog("AWeber", "[" . $exc->type . "] " . $exc->message . " Docs: " . $exc->documentation_url);
                throw new Exception("Authorization error", 5);
            }
        }
        if (file_exists($token)) {
            $key = file_get_contents($token);
        }
        list($consumerKey, $consumerSecret, $accessToken, $accessSecret) = json_decode($key);
        $aweber = new AWeberAPI($consumerKey, $consumerSecret);
        try {
            $account = $aweber->getAccount($accessToken, $accessSecret);
            $foundLists = $account->lists->find(array('name' => AW_LISTNAME));
            $lists = $foundLists[0];
            if (!isset($merge_vars['name'])) {
                $pix_extra['name'] = getName($mailSubscribe);
            }
            $custom_arr = array();
            foreach ($merge_vars as $variable => $v) {
                if ($variable != 'name') {
                    $custom_arr[filter_var($variable, FILTER_SANITIZE_STRING)] = filter_var($v, FILTER_SANITIZE_STRING);
                }
            }
            $params = array('email' => $mailSubscribe, 'name' => $merge_vars['name'], 'custom_fields' => $custom_arr);
            if (isset($lists)) {
                $lists->subscribers->create($params);
                $output = json_encode(array('type' => 'message', 'text' => 'Thank you for your Subscription.'));
                die($output);
            } else {
                //errorLog("AWeber","List is not found");
                $output = json_encode(array('type' => 'error', 'text' => 'Error: List is not found'));
                die($output);
                //throw new Exception("Error found Lists",4);
            }
        } catch (AWeberAPIException $exc) {
            if ($exc->status == 400) {
                //throw new Exception("Email exist",2);
                $output = json_encode(array('type' => 'error', 'text' => 'Error: Email Already Exists'));
                die($output);
            } else {
                //errorLog("AWeber","[".$exc->type."] ". $exc->message ." Docs: ". $exc->documentation_url);
                $output = json_encode(array('type' => 'error', 'text' => 'Error: ' . "[" . $exc->type . "] " . $exc->message . " Docs: " . $exc->documentation_url));
                die($output);
            }
        }
    } else {
        $output = json_encode(array('type' => 'error', 'text' => 'Error: AWeber configuration Error, please check config.php settings!'));
        die($output);
    }
}