function snp_ml_get_ic_lists($ml_ic_username = '', $ml_ic_addid = '', $ml_ic_apppass = '')
{
    require_once SNP_DIR_PATH . '/include/icontact/iContactApi.php';
    $list = array();
    if (snp_get_option('ml_ic_username') && snp_get_option('ml_ic_addid') && snp_get_option('ml_ic_apppass') || $ml_ic_username && $ml_ic_addid && $ml_ic_apppass) {
        if (!$ml_ic_username || !$ml_ic_addid || !$ml_ic_apppass) {
            $ml_ic_username = snp_get_option('ml_ic_username');
            $ml_ic_addid = snp_get_option('ml_ic_addid');
            $ml_ic_apppass = snp_get_option('ml_ic_apppass');
        }
        iContactApi::getInstance()->setConfig(array('appId' => $ml_ic_addid, 'apiPassword' => $ml_ic_apppass, 'apiUsername' => $ml_ic_username));
        $oiContact = iContactApi::getInstance();
        try {
            $res = $oiContact->getLists();
            foreach ((array) $res as $v) {
                $list[$v->listId] = array('name' => $v->name);
            }
            //var_dump($oiContact->getLists());
        } catch (Exception $oException) {
            // Error
            // Catch any exceptions
            // Dump errors
            //var_dump($oiContact->getErrors());
            // Grab the last raw request data
            //var_dump($oiContact->getLastRequest());
            // Grab the last raw response data
            //var_dump($oiContact->getLastResponse());
        }
    }
    if (count($list) == 0) {
        $list[0] = array('name' => 'Nothing Found...');
    }
    return $list;
}
Esempio n. 2
0
 /**
  * Returns iContact API client
  * @return iClientApi
  */
 public function getClient()
 {
     if (null === $this->client) {
         $this->client = iContactApi::getInstance()->setConfig(array('appId' => OP_ICONTACT_APP_ID, 'apiUsername' => $this->username, 'apiPassword' => $this->password));
     }
     return $this->client;
 }
 /**
  * Get an instance of the API.
  *
  * @since 1.5.4
  * @param array $data {
  *      @type string $username A valid username.
  *      @type string $app_id A valid app ID.
  *      @type string $app_password A valid app password.
  * }
  * @return object The API instance.
  */
 public function get_api($data)
 {
     if ($this->api_instance) {
         return $this->api_instance;
     }
     if (!class_exists('iContactApi')) {
         require_once FL_BUILDER_DIR . 'includes/vendor/icontact/iContactApi.php';
     }
     iContactApi::getInstance()->setConfig($data);
     $this->api_instance = iContactApi::getInstance();
     return $this->api_instance;
 }
 public function indeed_iContact($apiUser, $appId, $apiPass, $listId, $e_mail, $first_name = '', $last_name = '')
 {
     require_once $this->dir_path . '/email_services/icontact/iContactApi.php';
     iContactApi::getInstance()->setConfig(array('appId' => $appId, 'apiPassword' => $apiPass, 'apiUsername' => $apiUser));
     $oiContact = iContactApi::getInstance();
     $res1 = $oiContact->addContact($e_mail, null, null, $first_name, $last_name, null, null, null, null, null, null, null, null, null);
     if ($res1->contactId) {
         if ($oiContact->subscribeContactToList($res1->contactId, $listId, 'normal')) {
             return 1;
         } else {
             return 0;
         }
     } else {
         return 0;
     }
 }
 public static function donation_button_icontact_handler($posted)
 {
     if (!isset($posted) || empty($posted)) {
         return;
     }
     $ic_api_key = get_option("icontact_api_id");
     $app_password = get_option("icontact_api_password");
     $app_username = get_option("icontact_api_username");
     $icontact_list = get_option("icontact_lists");
     $fname = isset($posted['first_name']) ? $posted['first_name'] : '';
     $lname = isset($posted['last_name']) ? $posted['last_name'] : '';
     $email = isset($posted['payer_email']) ? $posted['payer_email'] : $posted['receiver_email'];
     $debug = get_option('log_enable_icontact') == 'yes' ? 'yes' : 'no';
     if ('yes' == $debug) {
         $log = new Donation_Button_Logger();
     }
     if (isset($ic_api_key) && !empty($ic_api_key) && (isset($app_username) && !empty($app_username)) && (isset($app_password) && !empty($app_password))) {
         if (isset($icontact_list) && !empty($icontact_list)) {
             include_once DBP_PLUGIN_DIR_PATH . '/admin/partials/lib/icontact/icontact.php';
             iContactApi::getInstance()->setConfig(array('appId' => $ic_api_key, 'apiUsername' => $app_username, 'apiPassword' => $app_password));
             $iContact = iContactApi::getInstance();
             try {
                 $contactid = $iContact->addContact($email, 'normal', null, $fname, $lname, null, null, null, null, null, null, null, null, null);
                 $subscribed = $iContact->subscribeContactToList($contactid->contactId, $icontact_list, 'normal');
                 if ('yes' == $debug) {
                     if ($subscribed) {
                         $log->add('Icontact', $email . ' Successfully Add Contact in iContact');
                     } else {
                         $log->add('Icontact', $email . ' Contact already added to target campaign in iContact');
                     }
                 }
             } catch (Exception $e) {
                 if ('yes' == $debug) {
                     $log->add('Icontact', prin_r($e, true));
                 }
             }
         }
     }
 }
Esempio n. 6
0
 function UpdateUserToIcontact($user, $iID)
 {
     // Load the iContact library
     require_once APPPATH . 'libraries/iContactApi.php';
     // Give the API your information
     iContactApi::getInstance()->setConfig(array('appId' => 'CxbI1WVaDqdqXsDkGIcKNmJgnfzQZcFN', 'apiPassword' => 'Policy321', 'apiUsername' => '*****@*****.**'));
     // Store the singleton
     $oiContact = iContactApi::getInstance();
     // Try to make the call(s)
     try {
         //  are examples on how to call the  iContact PHP API class
         // Grab all contacts
         //	var_dump($oiContact->getContacts());
         // Grab a contact
         //	var_dump($oiContact->getContact(42094396));
         //	// Create a contact
         $update = $oiContact->updateContact($iID, $user['email'], null, $user['first_name'], $user['last_name'], null, null, null, null, null, null, $user['phone'], null, null, null);
         //	// Get messages
         //	var_dump($oiContact->getMessages());
         //	// Create a list
         //	var_dump($oiContact->addList('somelist', 1698, true, false, false, 'Just an example list', 'Some List'));
         //	// Subscribe contact to list
         //	$subscribe=$oiContact->subscribeContactToList(contactId, listId, status);
         //	$subscribe=$oiContact->subscribeContactToList($contact->contactId, 17234, 'normal');
         //	// Grab all campaigns
         //	var_dump($oiContact->getCampaigns());
         //	// Create message
         //	var_dump($oiContact->addMessage('An Example Message', 585, '<h1>An Example Message</h1>', 'An Example Message', 'ExampleMessage', 33765, 'normal'));
         //	// Schedule send
         //	var_dump($oiContact->sendMessage(array(33765), 179962, null, null, null, mktime(12, 0, 0, 1, 1, 2012)));
         //	// Upload data by sending a filename (execute a PUT based on file contents)
         //	var_dump($oiContact->uploadData('/path/to/file.csv', 179962));
         //	// Upload data by sending a string of file contents
         //	$sFileData = file_get_contents('/path/to/file.csv');  // Read the file
         //	var_dump($oiContact->uploadData($sFileData, 179962)); // Send the data to the API
     } catch (Exception $oException) {
         // Catch any exceptions
         // Dump errors
         var_dump($oiContact->getErrors());
         // Grab the last raw request data
         var_dump($oiContact->getLastRequest());
         // Grab the last raw response data
         var_dump($oiContact->getLastResponse());
     }
 }
Esempio n. 7
0
 public function subscribeNewsletter(array $info)
 {
     $kuler = Kuler::getInstance();
     $mail_service = $kuler->getSkinOption('mail_service');
     $result = false;
     $contact_list = $kuler->getSkinOption('contact_list');
     if (empty($contact_list)) {
         throw new Exception(_t('error_the_newsletter_system_is_not_configured_please_contact_to_site_admin'));
     }
     switch ($mail_service) {
         case 'mailchimp':
             require_once 'mail_service/mailchimp.php';
             $api_key = $kuler->getSkinOption('mailchimp_api_key');
             if (empty($api_key)) {
                 throw new Exception(_t('error_the_newsletter_system_is_not_configured_please_contact_to_site_admin'));
             }
             $api = new MCAPI($api_key);
             $mail = $info['mail'];
             $merge = array('FNAME' => 'Email', 'LNAME' => ' :' . $mail);
             $api->listSubscribe($contact_list, $mail, $merge);
             if ($api->errorCode) {
                 $message = $api->errorMessage;
                 if ($api->errorCode == 214) {
                     $message = _t('error_your_email_is_already_subscribed_to_list');
                 }
                 throw new Exception($message);
             }
             $result = true;
             break;
         case 'icontact':
             require_once 'mail_service/icontact.php';
             $key = $kuler->getSkinOption('icontact_app_key');
             $username = $kuler->getSkinOption('icontact_username');
             $password = $kuler->getSkinOption('icontact_password');
             if (empty($key) || empty($username) || empty($password)) {
                 throw new Exception(_t('error_the_newsletter_system_is_not_configured_please_contact_to_site_admin'));
             }
             iContactApi::getInstance()->setConfig(array('appId' => $key, 'apiUsername' => $username, 'apiPassword' => $password));
             $oiContact = iContactApi::getInstance();
             try {
                 $result = $oiContact->addContact($info['mail']);
                 $result = $oiContact->subscribeContactToList($result->contactId, $contact_list, 'normal');
             } catch (Exception $e) {
                 throw new Exception($e->getMessage());
             }
             $result = true;
             break;
     }
     return $result;
 }
Esempio n. 8
0
 public function getNewsletterLists($type, array $info)
 {
     $mail_service_path = dirname(__FILE__) . '/mail_service/' . $type . '.php';
     if (file_exists($mail_service_path)) {
         require_once $mail_service_path;
         if ($type == 'icontact') {
             // Give the API your information
             iContactApi::getInstance()->setConfig(array('appId' => $info['icontact_app_key'], 'apiUsername' => $info['icontact_username'], 'apiPassword' => $info['icontact_password']));
             // Store the singleton
             $oiContact = iContactApi::getInstance();
             try {
                 $lists = $oiContact->getLists();
                 $results = array();
                 foreach ($lists as $list) {
                     $results[$list->listId] = $list->name;
                 }
             } catch (Exception $e) {
                 $errors = $oiContact->getErrors();
                 throw new Exception(current($errors));
             }
         } else {
             if ($type == 'mailchimp') {
                 $api = new MCAPI($info['mailchimp_api_key']);
                 $results = array();
                 if ($api) {
                     $lists = $api->lists();
                     if ($lists && !empty($lists['data'])) {
                         foreach ($lists['data'] as $list) {
                             $results[$list['id']] = $list['name'];
                         }
                     }
                 }
             }
         }
     } else {
         throw new Exception(_t('This mail service is not available!'));
     }
     return $results;
 }
function sendiContact($mailSubscribe)
{
    if (defined('IC_APPID') && defined('IC_APIUSERNAME') && defined('IC_APIPASSWORD')) {
        iContactApi::getInstance()->setConfig(array('appId' => IC_APPID, 'apiPassword' => IC_APIPASSWORD, 'apiUsername' => IC_APIUSERNAME));
        $oiContact = iContactApi::getInstance();
        try {
            $oiContact->addContact($mailSubscribe);
        } catch (Exception $oException) {
            throw new Exception("Error found Lists", 4);
        }
    }
}
 $service_requirements_status = $cfgenwpapi_obj->checkServiceRequirements($service_id);
 if ($service_requirements_status['status']) {
     include '../api/icontact/iContactApi.php';
     try {
         iContactApi::getInstance()->setConfig(array('appId' => $cfgenwpapi_obj->icontact['applicationid'], 'apiUsername' => $cfg[$service_id]['username'], 'apiPassword' => $cfg[$service_id]['applicationpassword']));
     } catch (Exception $e) {
         $icontact_error = $oiContact->getErrors();
         $error = $icontact_error[0];
         $admin_api_error[$service_id]['error_message'] = $icontact_error[0];
         if ($contactform_obj->cfg['debug']) {
             echo 'iContact ERROR' . "\r\n";
             print_r($icontact_error);
         }
     }
     // try iContact connect
     $oiContact = iContactApi::getInstance();
     $ic_makecall_url_prefix = '/a/' . $oiContact->setAccountId() . '/c/' . $oiContact->setClientFolderId() . '/contacts';
     foreach ($cfg[$service_id]['lists'] as $list_v) {
         $list_id = $list_v['list_id'];
         $api_contact_email = '';
         $ic_contact_id = '';
         // returned when adding updating the contact into the account, this id is used to subscribe the contact to a list
         // FIELDS
         if (isset($list_v['fields']) && $list_v['fields']) {
             foreach ($list_v['fields'] as $field_v) {
                 $ic_contact[$field_v['list_field_id']] = getElementValue($field_v['element_id']);
                 if ($field_v['list_field_id'] == 'email') {
                     $api_contact_email = getElementValue($field_v['element_id']);
                 }
             }
             // Default values for add and update
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('');
}
 public static function donation_button_get_icontact_lists()
 {
     $icontact_lists = array();
     $enable_icontact = get_option('enable_icontact');
     if (isset($enable_icontact) && $enable_icontact == 'yes') {
         $icontact_lists = unserialize(get_transient('donation_button_icontact_list'));
         $icontact_debug = get_option('log_enable_icontact') == 'yes' ? 'yes' : 'no';
         $log = new Donation_Button_Logger();
         if (empty($icontact_lists) || get_option('donation_button_icontact_force_refresh') == 'yes') {
             include_once DBP_PLUGIN_DIR_PATH . '/admin/partials/lib/icontact/icontact.php';
             $icontact_api_id = get_option('icontact_api_id');
             $icontact_api_username = get_option('icontact_api_username');
             $icontact_api_password = get_option('icontact_api_password');
             if (isset($icontact_api_id) && !empty($icontact_api_id) && (isset($icontact_api_username) && !empty($icontact_api_username)) && (isset($icontact_api_password) && !empty($icontact_api_password))) {
                 iContactApi::getInstance()->setConfig(array('appId' => get_option('icontact_api_id'), 'apiUsername' => get_option('icontact_api_username'), 'apiPassword' => get_option('icontact_api_password')));
                 $oiContact = iContactApi::getInstance();
                 try {
                     $lists = $oiContact->getLists();
                 } catch (Exception $oException) {
                     unset($icontact_lists);
                     $icontact_lists['false'] = 'API details is invalid';
                     if ('yes' == $icontact_debug) {
                         $log->add('Icontact', 'Icontact API Details is Invalid.');
                     }
                 }
                 if (count($lists) > 0 and is_array($lists)) {
                     unset($icontact_lists);
                     foreach ($lists as $list) {
                         $icontact_lists[$list->listId] = $list->name;
                     }
                     delete_transient('donation_button_icontact_list');
                     set_transient('donation_button_icontact_list', serialize($icontact_lists), 86400);
                     if ('yes' == $icontact_debug) {
                         $log->add('Icontact', 'Icontact Get List Success..');
                     }
                     update_option('donation_button_icontact_force_refresh', 'no');
                 }
             } else {
                 $icontact_lists['false'] = __("Required information is empty.", 'donation-button');
                 if ('yes' == $icontact_debug) {
                     $log->add('Icontact', 'Required information is empty.');
                 }
             }
         }
     }
     return $icontact_lists;
 }
Esempio n. 13
0
 /**
  * Method for opting into the email service provider.
  *
  * @since 2.0.0
  *
  * @param array  $account Args to be passed when opting in.
  * @param string $list_id The list identifier.
  * @param array  $lead    The lead information. Should be sanitized.
  *
  * @return bool|WP_Error True on successful optin.
  */
 public function optin($account = array(), $list_id, $lead)
 {
     // Instantiate the API.
     iContactApi::getInstance()->setConfig(array('appId' => $account['app_id'], 'apiPassword' => $account['app_pass'], 'apiUsername' => $account['username']));
     $this->api = iContactApi::getInstance();
     // Setup the data to be passed.
     $data = array('email' => $lead['lead_email']);
     // Set name if provided.
     if ($lead['lead_name'] && 'false' !== $lead['lead_name']) {
         $data['first_name'] = null;
         $data['last_name'] = null;
         $names = explode(' ', $lead['lead_name']);
         if (isset($names[0])) {
             $data['first_name'] = $names[0];
         }
         if (isset($names[1])) {
             $data['last_name'] = $names[1];
         }
         $data = apply_filters('optin_monster_pre_optin_icontact', $data, $lead, $list_id, $this->api);
         $res = $this->api->addContact($data['email'], 'normal', null, $data['first_name'], $data['last_name']);
     } else {
         // No name provided.
         $data = apply_filters('optin_monster_pre_optin_icontact', $data, $lead, $list_id, $this->api);
         $res = $this->api->addContact($data['email']);
     }
     // Subscribe the contact to the list.
     $sub = $this->api->subscribeContactToList($res->contactId, $list_id);
     return true;
 }
Esempio n. 14
0
function icontact_addContact($info, $listId, $appId, $appUsername, $appPassword)
{
    require_once 'icontact_lib/iContactApi.php';
    iContactApi::getInstance()->setConfig(array('appId' => $appId, 'apiPassword' => $appPassword, 'apiUsername' => $appUsername));
    $oiContact = iContactApi::getInstance();
    try {
        $contact = $oiContact->addContact($info['email'], null, null, $info['first_name'], $info['last_name'], null, '123 Somewhere Ln', 'Apt 12', 'Somewhere', 'NW', '12345', '123-456-7890', '123-456-7890', null);
        $oiContact->subscribeContactToList($contact->contactId, $listId, 'normal');
        return true;
    } catch (Exception $oException) {
        // Catch any exceptions
        return null;
    }
    return false;
}
 public function saveIContact($user, $uid)
 {
     $email = $user['email'];
     $first_name = $user['first_name'];
     $last_name = $user['last_name'];
     $phone = $user['phone'];
     $address = $user['address'];
     $address2 = $user['address2'];
     $state = $user['state'];
     $city = $user['city'];
     $zip = $user['zip'];
     require_once APPPATH . 'third_party/iContactApi.php';
     // Give the API your information
     iContactApi::getInstance()->setConfig(array('appId' => 'jXjiMD9XP6EB4KOwRBqLI4D7MXE3MGDO', 'apiPassword' => '11111111', 'apiUsername' => '*****@*****.**'));
     // Store the singleton
     $oiContact = iContactApi::getInstance();
     // Try to make the call(s)
     try {
         $res = $oiContact->addContact($email, null, null, $first_name, $last_name, null, $address, $address2, $city, $state, $zip, $phone, $phone, null);
         $icon_id = $res->contactId;
         if ($icon_id) {
             $this->db->where('id', $uid);
             $this->db->update($this->table, array('i_contact_id' => $icon_id));
         }
     } catch (Exception $ex) {
         // Dump errors
         var_dump($oiContact->getErrors());
         // Grab the last raw request data
         var_dump($oiContact->getLastRequest());
         // Grab the last raw response data
         var_dump($oiContact->getLastResponse());
     }
 }