Пример #1
0
function annadir_newsletter($mail = false)
{
    $handle = new Mensajes();
    $mail = (string) $mail;
    if (!$mail || !is_email($mail)) {
        $handle->add_error('No se ha recibido un mail válido');
    } else {
        require_once '../classes/php-sdk-development/src/Ctct/autoload.php';
        $cc = new ConstantContact(APIKEY_CONSTANT);
        $contacts = $cc->getContacts(ACCESS_TOKEN_CONSTANT);
        $lists = $cc->getLists(ACCESS_TOKEN_CONSTANT);
        $list = '2021474646';
        try {
            $response = $cc->getContactByEmail(ACCESS_TOKEN_CONSTANT, $mail);
            if (empty($response->results)) {
                $contact = new Contact();
                $contact->addEmail($mail);
                $contact->addList($list);
                $returnContact = $cc->addContact(ACCESS_TOKEN_CONSTANT, $contact, true);
            } else {
                $contact = $response->results[0];
                $contact->addList($list);
                $returnContact = $cc->updateContact(ACCESS_TOKEN_CONSTANT, $contact, true);
            }
            $handle->add_mensaje('Tu correo se ha añadido correctamente a la lista de Bunch of Makers');
        } catch (CtctException $ex) {
            $errores = reset($ex->getErrors());
            $handle->add_error($errores['error_message']);
        }
    }
    return $handle->imprimir(false, true) . '<script>finalizar_subscripcion();</script>';
}
 public function getLists($array = false, $only = false)
 {
     $config = SiteConfig::current_site_config();
     $cc = new ConstantContact($config->CcApiKey);
     try {
         $lists = $cc->getLists($config->CcAccessToken);
         if ($array) {
             $array = array();
             foreach ($lists as $list) {
                 if ($only) {
                     if (in_array($list->id, $only)) {
                         $array[$list->id] = $list->name;
                     }
                 } else {
                     $array[$list->id] = $list->name;
                 }
             }
             return $array;
         }
         return $cc->getLists($config->CcAccessToken);
     } catch (CtctException $ex) {
     }
     return '';
 }
        die;
    }
    // attempt to schedule a campaign with the fields submitted, displaying any errors that occur
    try {
        $schedule = createSchedule($campaign->id, $_POST['schedule_time']);
    } catch (CtctException $ex) {
        echo '<span class="label label-important">Error Scheduling Campaign</span>';
        echo '<div class="container alert-error"><pre class="failure-pre">';
        print_r($ex->getErrors());
        echo '</pre></div>';
        die;
    }
}
// attempt to get the lists in this account, displaying any errors that occur
try {
    $lists = $cc->getLists(ACCESS_TOKEN);
} catch (CtctException $ex) {
    echo '<div class="container alert-error"><pre class="failure-pre">';
    print_r($ex->getErrors());
    echo '</pre></div>';
    die;
}
?>

<body>
<div class="well">
    <h3>Create and Schedule a Campaign</h3>

    <form class="form-horizontal" name="emailForm" id="emailForm" method="POST" action="createAndScheduleCampaign.php">
        <div class="span6">
            <fieldset>
 public static function donation_button_get_constantcontact_lists()
 {
     $donation_button_constantcontact_lists = array();
     $enable_constant_contact = get_option('enable_constant_contact');
     if (isset($enable_constant_contact) && $enable_constant_contact == 'yes') {
         $concontact_api_key = get_option('constantcontact_api_key');
         $constantcontact_access_token = get_option('constantcontact_access_token');
         $constant_contact_debug = get_option('log_enable_constant_contact') == 'yes' ? 'yes' : 'no';
         $log = new Donation_Button_Logger();
         if (isset($concontact_api_key) && !empty($concontact_api_key) && (isset($constantcontact_access_token) && !empty($constantcontact_access_token))) {
             $donation_button_constantcontact_lists = unserialize(get_transient('constantcontact_lists'));
             if (empty($donation_button_constantcontact_lists) || get_option('donation_button_constantcontact_force_refresh') == 'yes') {
                 try {
                     $cc = new ConstantContact($concontact_api_key);
                     $list_name = $cc->getLists($constantcontact_access_token);
                     if (isset($list_name) && !empty($list_name)) {
                         unset($donation_button_constantcontact_lists);
                         $donation_button_constantcontact_lists = array();
                         foreach ($list_name as $list_namekey => $list_namevalue) {
                             $donation_button_constantcontact_lists[$list_namevalue->id] = $list_namevalue->name;
                         }
                         set_transient('constantcontact_lists', serialize($donation_button_constantcontact_lists), 86400);
                         if ('yes' == $constant_contact_debug) {
                             $log->add('ConstantContact', 'ConstantContact Get List Success..');
                         }
                         update_option('donation_button_constantcontact_force_refresh', 'no');
                     } else {
                         if ('yes' == $constant_contact_debug) {
                             $log->add('ConstantContact', 'No ConstantContact List Available, check your API Key.');
                         }
                         $donation_button_constantcontact_lists['false'] = __("Unable to load Constant Contact lists, check your API Key.", 'paypal-ipn-for-wordpress-constant-contact');
                     }
                 } catch (CtctException $ex) {
                     unset($donation_button_constantcontact_lists);
                     $donation_button_constantcontact_lists = array();
                     $donation_button_constantcontact_lists['false'] = __("Unable to load Constant Contact lists, check your API Key.", 'paypal-ipn-for-wordpress-constant-contact');
                     set_transient('constantcontact_lists', serialize($donation_button_constantcontact_lists), 86400);
                     if ('yes' == $constant_contact_debug) {
                         $log->add('ConstantContact', 'Unable to load Constant Contact lists, check your API Key.');
                     }
                 }
             }
         }
     }
     return $donation_button_constantcontact_lists;
 }
 /**
  * @since    1.2.0
  * @return type
  */
 public function angelleye_get_constantcontact_lists()
 {
     $constantcontact_lists = array();
     $concontact_api_key = get_option('ofw_constantcontact_api_key');
     $constantcontact_access_token = get_option('ofw_constantcontact_access_token');
     if (isset($concontact_api_key) && !empty($concontact_api_key) && (isset($constantcontact_access_token) && !empty($constantcontact_access_token))) {
         $constant_contact_debug_log = get_option('ofw_log_enable_constant_contact') == 'yes' ? 'yes' : 'no';
         if ('yes' == $constant_contact_debug_log) {
             if (!class_exists('Angelleye_Offers_For_Woocommerce_Logger')) {
                 require_once OFFERS_FOR_WOOCOMMERCE_PLUGIN_DIR . '/includes/class-offers-for-woocommerce-logger.php';
             }
             $log = new Angelleye_Offers_For_Woocommerce_Logger();
         }
         $constantcontact_lists = unserialize(get_transient('ofw_constantcontact_mailinglist'));
         if (empty($constantcontact_lists) || get_option('ofw_constantcontact_force_refresh') == 'yes') {
             try {
                 $cc = new ConstantContact($concontact_api_key);
                 $list_name = $cc->getLists($constantcontact_access_token);
                 if (isset($list_name) && !empty($list_name)) {
                     unset($constantcontact_lists);
                     $constantcontact_lists = array();
                     foreach ($list_name as $list_namekey => $list_namevalue) {
                         $constantcontact_lists[$list_namevalue->id] = $list_namevalue->name;
                     }
                     set_transient('ofw_constantcontact_mailinglist', serialize($constantcontact_lists), 86400);
                     update_option('ofw_constantcontact_force_refresh', 'no');
                 } else {
                     $constantcontact_lists['false'] = __("Unable to load Constant Contact lists, check your API Key.", $this->plugin_slug);
                 }
             } catch (CtctException $ex) {
                 unset($constantcontact_lists);
                 $constantcontact_lists = array();
                 $constantcontact_lists['false'] = __("Unable to load Constant Contact lists, check your API Key.", $this->plugin_slug);
                 set_transient('ofw_constantcontact_mailinglist', serialize($constantcontact_lists), 86400);
             }
         }
         return $constantcontact_lists;
     }
 }
 public static function GetLists()
 {
     $cc = new ConstantContact(NewsletterHelper::ApiKey());
     return $cc->getLists(NewsletterHelper::AccessToken());
 }
<?php

require_once 'Ctct/autoload.php';
use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\Contacts\EmailAddress;
use Ctct\Exceptions\CtctException;
$concontact_api_key = get_option('constantcontact_api_key');
$constantcontact_access_token = get_option('constantcontact_access_token');
define("APIKEY", $concontact_api_key);
define("ACCESS_TOKEN", $constantcontact_access_token);
if (isset($concontact_api_key) && !empty($concontact_api_key) && (isset($constantcontact_access_token) && !empty($constantcontact_access_token))) {
    $cc = new ConstantContact(APIKEY);
    try {
        $lists_tmp = $cc->getLists(ACCESS_TOKEN);
    } catch (CtctException $ex) {
    }
} else {
    $donation_button_constantcontact_lists['false'] = __("API Key is empty.", 'eddms');
}
 function getLists()
 {
     $errors = array();
     $cc = new ConstantContact(ConstantContactV2::$cckey);
     // attempt to fetch lists in the account, catching any exceptions
     try {
         $lists = $cc->getLists(ConstantContactV2::$cctoken);
     } catch (CtctException $ex) {
         foreach ($ex->getErrors() as $error) {
             $errors[] = $error;
         }
         return $errors;
     }
     return $lists;
 }
Пример #9
0
 public function addEmailToNewsLetter()
 {
     if ($this->request->is('POST') || $this->request->is('PUT')) {
         $api_key = Configure::read('constant_contact_key');
         $api_token = Configure::read('constant_contact_token');
         $cc = new ConstantContact($api_key);
         // attempt to fetch lists in the account, catching any exceptions and printing the errors to screen
         try {
             $lists = $cc->getLists($api_token);
         } catch (Exception $ex) {
             throw new Exception();
         }
         // check if the form was submitted
         $action = "Getting Contact By Email Address";
         try {
             // check to see if a contact with the email addess already exists in the account
             $response = $cc->getContactByEmail($api_token, $_POST['data']['email']);
             // create a new contact if one does not exist
             if (empty($response->results)) {
                 $action = "Creating Contact";
                 $contact = new Contact();
                 $contact->addEmail($_POST['data']['email']);
                 $contact->addList('1339315632');
                 $contact->first_name = $_POST['data']['first_name'];
                 $contact->last_name = $_POST['data']['last_name'];
                 /*
                  * The third parameter of addContact defaults to false, but if this were set to true it would tell Constant Contact that this action is being performed by the contact themselves, and gives the ability to opt contacts back in and trigger Welcome/Change-of-interest emails. See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
                  */
                 $returnContact = $cc->addContact($api_token, $contact, true);
                 // update the existing contact if address already existed
             } else {
                 $action = "Updating Contact";
                 $contact = $response->results[0];
                 $contact->addList('1339315632');
                 $contact->first_name = $_POST['data']['first_name'];
                 $contact->last_name = $_POST['data']['last_name'];
                 $returnContact = $cc->updateContact($api_token, $contact, true);
             }
             // catch any exceptions thrown during the process and print the errors to screen
         } catch (Exception $ex) {
             $this->Session->setFlash('ニュースレターの配信登録に失敗しました。お問い合わせください。', 'default', array('class' => 'message error'));
             $this->redirect('/');
             exit;
         }
         if ($returnContact) {
             $this->Session->setFlash('ニュースレターの配信登録を完了しました。', 'default', array('class' => 'message success'));
             $this->redirect('/');
         }
         exit;
     } else {
         throw new Exception();
     }
 }