public function indeed_mailChimp($mailchimp_api, $mailchimp_id_list, $e_mail, $first_name = '', $last_name = '')
 {
     if ($mailchimp_api != '' && $mailchimp_id_list != '') {
         if (!class_exists('MailChimp')) {
             require_once $this->dir_path . '/email_services/mailchimp/MailChimp.php';
         }
         $MailChimp = new MailChimp($mailchimp_api);
         $result = $MailChimp->call('lists/subscribe', array('id' => $mailchimp_id_list, 'email' => array('email' => $e_mail), 'double_optin' => 0, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => 0, 'merge_vars' => array('FNAME' => $first_name, 'LNAME' => $last_name)));
         if (!empty($result['email']) && !empty($result['euid']) && !empty($result['leid'])) {
             return 1;
         } else {
             return 0;
         }
     }
 }
 /**
  * get campaign data from the API and store it in our table
  */
 public function populate($api_key, $list_id, $echo_feedback = false)
 {
     $MailChimp = new MailChimp($api_key);
     if ($echo_feedback) {
         $API = new PerchAPI(1.0, 'perch_mailchimp');
         $Lang = $API->get('Lang');
     }
     $opts = array('apikey' => $api_key, 'filters' => array('list_id' => $list_id, 'status' => 'sent'));
     $result = $MailChimp->call('campaigns/list', $opts);
     if ($result && isset($result['total']) && $result['total'] > 0) {
         foreach ($result['data'] as $item) {
             $campaignID = $item['id'];
             //get the content
             $content_opts = array('apikey' => $api_key, 'cid' => $campaignID);
             $content = $MailChimp->call('campaigns/content', $content_opts);
             if (isset($content['html'])) {
                 $campaignHTML = $content['html'];
             }
             if (isset($content['text'])) {
                 $campaignText = $content['text'];
             }
             // array for insertion
             $campaign = array('campaignCID' => $campaignID, 'campaignWebID' => $item['web_id'], 'campaignTitle' => $item['title'], 'campaignCreateTime' => $item['create_time'], 'campaignSendTime' => $item['send_time'], 'campaignSent' => $item['emails_sent'], 'campaignSubject' => $item['subject'], 'campaignArchiveURL' => $item['archive_url'], 'campaignHTML' => $campaignHTML, 'campaignText' => $campaignText, 'campaignSlug' => PerchUtil::urlify(date('d M Y', strtotime($item['create_time'])) . ' ' . $item['subject']));
             //insert into our table
             $this->db->insert($this->table, $campaign);
             if ($echo_feedback) {
                 echo '<li class="icon success">';
                 echo $Lang->get('Importing campaign %s (%s)', $item['title'], $item['create_time']);
                 echo '</li>';
                 flush();
             }
         }
     }
 }
function mwpc_ajax_result()
{
    // check nonce
    $nonce = $_POST['nextNonce'];
    if (!wp_verify_nonce($nonce, 'mapajax-next-nonce')) {
        die('Sorry, Server is busy. Try again after few minutes!');
    }
    if ($_POST['url'] == '' and $_POST['email'] != '') {
        require_once 'MailChimp.php';
        $MailChimp = new MailChimp('6c58e9c609ac5cbb9d71f9358a1a834a-us8');
        $result = $MailChimp->call('lists/subscribe', array('id' => 'b90220a492', 'email' => array('email' => $_POST['email']), 'merge_vars' => array('FNAME' => $_POST['name']), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false));
        if ($result === FALSE) {
            echo 'no';
        } else {
            echo 'yes';
        }
        update_option('dv_subscribed', 'yes');
    } else {
        $url = $_POST['url'];
        $zip_file = str_replace(site_url(), ABSPATH, $url);
        $zip = new ZipArchive();
        if ($zip->open($zip_file) === TRUE) {
            $zip->extractTo(PLUGIN_BASE . DIRECTORY_SEPARATOR . 'templates');
            $zip->close();
            echo 'ok';
        } else {
            echo 'failed';
        }
    }
    die;
}
Part of the code from the book
Building Findable Websites: Web Standards, SEO, and Beyond
by Aarron Walter (aarron@buildingfindablewebsites.com)
http://buildingfindablewebsites.com
Distrbuted under Creative Commons license
http://creativecommons.org/licenses/by-sa/3.0/us/
///////////////////////////////////////////////////////////////////////*/
function storeAddress()
{
    // Validation
    if (empty($_REQUEST['email'])) {
        return "No email address provided";
    }
    if (!preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\$/i", $_REQUEST['email'])) {
        return "Email address is invalid";
    }
    // grab an API Key from http://admin.mailchimp.com/account/api/
    $api_key = 'your-api-code-here';
    // grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
    // Click the "settings" link for the list - the Unique Id is at the bottom of that page.
    $list_id = "your-list-id-here";
    require_once 'MailChimp.php';
    $dopt = !empty($_REQUEST['dopt']) && $_REQUEST['dopt'] == 'true' ? true : false;
    $email = $_REQUEST['email'];
    $merge_vars = array('FNAME' => !empty($_REQUEST['fname']) ? $_REQUEST['fname'] : '', 'LNAME' => !empty($_REQUEST['lname']) ? $_REQUEST['lname'] : '');
    $api = new MailChimp($api_key);
    $valid_key = $api->validateApiKey();
    if (!$valid_key) {
        return 'Error: please, check your api-key';
    }
    $result = $api->call('lists/subscribe', array('id' => $list_id, 'email' => array('email' => $email), 'merge_vars' => $merge_vars, 'double_optin' => $dopt, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false));
    if (!empty($result['email']) && !empty($result['euid']) && !empty($result['leid'])) {
        return 'Success! Check your email to confirm sign up.';
    } else {
示例#5
0
function smamo_ajax_newsletter()
{
    $response = array();
    $email = wp_strip_all_tags($_POST['email']);
    $api_key = wp_strip_all_tags($_POST['api_key']);
    $list_ID = wp_strip_all_tags($_POST['list_ID']);
    if (!$email || $email === '') {
        $response['error'] = 'Indtast venligst en email';
        echo json_encode($response);
        wp_die();
    }
    if (!$api_key || $api_key === '') {
        $response['error'] = 'Mangler API nøgle';
        echo json_encode($response);
        wp_die();
    }
    if (!$list_ID || $list_ID === '') {
        $response['error'] = 'Mangler liste ID';
        echo json_encode($response);
        wp_die();
    }
    $MailChimp = new MailChimp($api_key);
    $result = $MailChimp->call('lists/subscribe', array('id' => $list_ID, 'email' => array('email' => $email), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false));
    $response['mailchimp'] = $result;
    $response['destroy_self'] = '5000';
    $response['success'] = '<span class="subscribe-success">Thank you</span>';
    echo json_encode($response);
    wp_die();
}
示例#6
0
 public static function check_list_for_interest_groups($list_id = '', $integration_type = '', $load = false)
 {
     if (!$list_id) {
         $list_id = $_POST['list_id'];
     }
     if (!$integration_type) {
         $integration_type = $_POST['integration'];
     }
     $api_key = get_option('yikes-mc-api-key', '');
     // setup/check our transients
     if (WP_DEBUG || false === ($interest_groupings = get_transient($list_id . '_interest_group'))) {
         // It wasn't there, so regenerate the data and save the transient
         try {
             // initialize MailChimp Class
             $MailChimp = new MailChimp($api_key);
             // retreive our interest group data
             $interest_groupings = $MailChimp->call('lists/interest-groupings', array('apikey' => $api_key, 'id' => $list_id, 'counts' => false));
         } catch (Exception $error) {
             $interest_groupings = $error->getMessage();
         }
         // set the transient for 2 hours
         set_transient($list_id . '_interest_group', $interest_groupings, 2 * HOUR_IN_SECONDS);
     }
     if (isset($interest_groupings) && !empty($interest_groupings)) {
         require YIKES_MC_PATH . 'admin/partials/menu/options-sections/templates/integration-interest-groups.php';
     }
     // do not kill off execution on load, only on an ajax request
     if (!$load) {
         exit;
         wp_die();
     }
 }
 /**
  * Add new subscriber
  */
 public function subscriber_add()
 {
     // simple api class for MailChimp from https://github.com/drewm/mailchimp-api/blob/master/src/Drewm/MailChimp.php
     require_once Utils::api_path() . 'mailchimp-api.php';
     foreach ($this->instance_default as $key => $value) {
         ${$key} = !empty($instance[$key]) ? $instance[$key] : $value;
     }
     $return = array('status' => 'failed', 'message' => $failed_message);
     $email = sanitize_email($_POST['email']);
     $api_key = $_POST['api-key'];
     $list_id = $_POST['list-id'];
     // Create MailChimp API object
     $mailerAPI_obj = new MailChimp($api_key);
     if (is_email($email) && !empty($api_key) && $mailerAPI_obj->validate_api_key()) {
         // Call API
         $result = $mailerAPI_obj->call('/lists/subscribe', array('id' => $list_id, 'email' => array('email' => $email, 'euid' => time() . rand(1, 1000), 'leid' => time() . rand(1, 1000)), 'double_optin' => true), 20);
         if (!empty($result['leid'])) {
             // Success response
             $return = array('status' => 'success', 'message' => $success_message);
         } else {
             $return['message'] = $failed_message;
         }
         $return['result'] = $result;
     }
     // Send answer
     wp_send_json($return);
 }
 /**
  *
  */
 public function populate($api_key, $list_id, $echo_feedback = false)
 {
     $MailChimp = new MailChimp($api_key);
     if ($echo_feedback) {
         $API = new PerchAPI(1.0, 'perch_mailchimp');
         $Lang = $API->get('Lang');
     }
     $opts = array('apikey' => $api_key, 'filters' => array('list_id' => $list_id));
     $result = $MailChimp->call('lists/list', $opts);
     if ($result) {
         $this->db->execute('TRUNCATE TABLE ' . $this->table);
         //store title in data array
         $stats_array = array('title' => $result['data'][0]['name'], 'total' => $result['data'][0]['stats']['member_count']);
         $list_opts = array('apikey' => $api_key, 'id' => $list_id);
         $activity = $MailChimp->call('lists/activity', $list_opts);
         PerchUtil::debug($activity);
         foreach ($activity as $stat) {
             if ($stat['day'] == date('Y-m-d', strtotime('-1 days'))) {
                 $stats_array['yesterday'] = $stat['subs'] + $stat['other_adds'];
             } elseif ($stat['day'] == date('Y-m-d')) {
                 $stats_array['today'] = $stat['subs'] + $stat['other_adds'];
             }
         }
         //insert stats array
         $this->db->insert($this->table, $stats_array);
         if ($echo_feedback) {
             echo '<li class="icon success">';
             echo $Lang->get('Importing statistics for list %s', $list_id);
             echo '</li>';
             flush();
         }
         // history table
         $sql = 'SELECT * FROM ' . PERCH_DB_PREFIX . 'mailchimp_history WHERE historyDate = ' . $this->db->pdb(date('Y-m-d', strtotime('-1 days'))) . ' LIMIT 1';
         if (!($row = $this->db->get_row($sql))) {
             //insert a row for yesterday
             $history_data = array('historyDate' => date('Y-m-d', strtotime('-1 days')), 'historyTotal' => $stats_array['yesterday']);
             $this->db->insert(PERCH_DB_PREFIX . 'mailchimp_history', $history_data);
             if ($echo_feedback) {
                 echo '<li class="icon success">';
                 echo $Lang->get('Importing history for list %s', $list_id);
                 echo '</li>';
                 flush();
             }
         }
     }
     return true;
 }
示例#9
0
 public function executeSubscribe(sfWebRequest $request)
 {
     $this->forward404Unless($request->isXmlHttpRequest());
     $email = $request->getParameter('email');
     $validator = new sfValidatorEmail();
     $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
     try {
         $validator->clean($email);
         $MailChimp = new MailChimp(sfConfig::get('app_mailchimp_api_key'));
         $result = $MailChimp->call('lists/subscribe', array('id' => sfConfig::get('app_mailchimp_list_id'), 'email' => array('email' => $email), 'merge_vars' => array(), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false));
         return $this->renderText(json_encode(array('status' => 'ok')));
     } catch (sfValidatorError $e) {
         return $this->renderText(json_encode(array('status' => 'invalid')));
     }
 }
 public function subscribe_from_form($Form)
 {
     $Settings = $this->api->get('Settings');
     $api_key = $Settings->get('perch_mailchimp_api_key')->settingValue();
     $list_id = $Settings->get('perch_mailchimp_list_id')->settingValue();
     $merge_vars = array();
     $groupings = array();
     $confirmed = false;
     $double_optin = true;
     $send_welcome = true;
     $update_existing = true;
     $replace_interests = false;
     $FormTag = $Form->get_form_attributes();
     if ($FormTag->is_set('double_optin')) {
         $double_optin = $FormTag->double_optin();
     }
     if ($FormTag->is_set('send_welcome')) {
         $send_welcome = $FormTag->send_welcome();
     }
     $attr_map = $Form->get_attribute_map('mailer');
     if (PerchUtil::count($attr_map)) {
         foreach ($attr_map as $fieldID => $merge_var) {
             switch ($merge_var) {
                 case 'email':
                     $email = $Form->data[$fieldID];
                     break;
                 case 'confirm_subscribe':
                     $confirmed = PerchUtil::bool_val($Form->data[$fieldID]);
                     break;
                 default:
                     $merge_vars[$merge_var] = $Form->data[$fieldID];
                     break;
             }
         }
     }
     if ($confirmed) {
         $MailChimp = new MailChimp($api_key);
         $result = $MailChimp->call('lists/subscribe', array('id' => $list_id, 'email' => array('email' => $email), 'merge_vars' => $merge_vars, 'double_optin' => $double_optin, 'update_existing' => $update_existing, 'replace_interests' => $replace_interests, 'send_welcome' => $send_welcome));
         return $result;
     }
     return false;
 }
示例#11
0
function smamo_puzzle_form()
{
    $response = array();
    $post_vars = array('state' => isset($_POST['state']) && $_POST['state'] !== '' ? true : false, 'solve-time' => isset($_POST['solve-time']) ? wp_strip_all_tags($_POST['solve-time']) : false, 'name' => isset($_POST['name']) ? wp_strip_all_tags($_POST['name']) : false, 'email' => isset($_POST['email']) ? wp_strip_all_tags($_POST['email']) : false);
    // state og solve-time skal være sat til true
    if (!$post_vars['state'] || !$post_vars['solve-time']) {
        $response['error'] = 'cheats!';
        wp_die(json_encode($response));
    }
    // Navn skal udfyldes
    if (!$post_vars['name']) {
        $response['error'] = 'Indtast et navn';
        wp_die(json_encode($response));
    }
    // Email skal udfyldes
    if (!$post_vars['email']) {
        $response['error'] = 'Indtast en email';
        wp_die(json_encode($response));
    }
    if (!$post_vars['state'] === '3') {
        $response['error'] = 'you shouldnt be here, son';
        wp_die(json_encode($response));
    }
    // Opret slack notifikation
    if (function_exists('slack')) {
        $text = $post_vars['name'] . ' har lige tilmeld sig nyhedsbrevet!';
        $attachments = array(array('pretext' => '', 'color' => '#669999', 'fields' => array(array('title' => 'Navn', 'value' => $post_vars['name'], 'short' => false), array('title' => 'Email', 'value' => '<mailto:' . $post_vars['email'] . '|' . $post_vars['email'] . '>', 'short' => false), array('title' => 'Tid på puslespil', 'value' => $post_vars['solve-time'], 'short' => false))));
        $response['slack_curl'] = slack($text, $attachments);
    }
    // Opret subscriber
    if (class_exists('MailChimp')) {
        $api_key = '40bbbefd42e7b7fd5e22c5e0e9ca61b3-us10';
        $list_ID = '51f08ecfa7';
        $response['mc-creds'] = array('key' => $api_key, 'list' => $list_ID);
        $MailChimp = new MailChimp($api_key);
        $result = $MailChimp->call('lists/subscribe', array('id' => $list_ID, 'email' => array('email' => $post_vars['email']), 'merge_vars' => array('NAME' => $post_vars['name']), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false));
        $response['mailchimp'] = $result;
    }
    wp_die(json_encode($response));
}
示例#12
0
 /**
  * Display form allows users to change settings on subscription plan add/edit screen
  * @param object $row
  */
 function _drawSettingForm($row)
 {
     require_once dirname(__FILE__) . '/api/MailChimp.php';
     $mailchimp = new MailChimp($this->params->get('api_key'));
     $lists = $mailchimp->call('lists/list');
     if ($lists === false) {
     } else {
         $params = new JRegistry($row->params);
         $listIds = explode(',', $params->get('mailchimp_list_ids', ''));
         $options = array();
         $lists = $lists['data'];
         if (count($lists)) {
             foreach ($lists as $list) {
                 $options[] = JHtml::_('select.option', $list['id'], $list['name']);
             }
         }
         ?>
         <table class="admintable adminform" style="width: 90%;">
             <tr>
                 <td width="220" class="key">
                     <?php 
         echo JText::_('PLG_OSMEMBERSHIP_MAILCHIMP_ASSIGN_TO_LISTS');
         ?>
                 </td>
                 <td>
                     <?php 
         echo JHtml::_('select.genericlist', $options, 'mailchimp_list_ids[]', 'class="inputbox" multiple="multiple" size="10"', 'value', 'text', $listIds);
         ?>
                 </td>
                 <td>
                     <?php 
         echo JText::_('PLG_OSMEMBERSHIP_ACYMAILING_ASSIGN_TO_LISTS_EXPLAIN');
         ?>
                 </td>
             </tr>
         </table>
     <?php 
     }
 }
示例#13
0
 public static function handleRedirectReturn($data = false)
 {
     if (isset($data['error'])) {
         return 'There was an error. (general) Please try again.';
     } else {
         $connections = CASHSystem::getSystemSettings('system_connections');
         require_once CASH_PLATFORM_ROOT . '/lib/oauth2/OAuth2Client.php';
         require_once CASH_PLATFORM_ROOT . '/lib/oauth2/OAuth2Exception.php';
         require_once CASH_PLATFORM_ROOT . '/lib/mailchimp/MC_OAuth2Client.php';
         $oauth_options = array('redirect_uri' => $connections['com.mailchimp']['redirect_uri'], 'client_id' => $connections['com.mailchimp']['client_id'], 'client_secret' => $connections['com.mailchimp']['client_secret'], 'code' => $data['code']);
         $client = new MC_OAuth2Client($oauth_options);
         $session = $client->getSession();
         if ($session) {
             require_once CASH_PLATFORM_ROOT . '/lib/mailchimp/MailChimp.class.php';
             $cn = new MC_OAuth2Client($oauth_options);
             $cn->setSession($session, false);
             $odata = $cn->api('metadata', 'GET');
             $access_token = $session['access_token'];
             $api_key = $session['access_token'] . '-' . $odata['dc'];
             $api = new MailChimp($api_key);
             $lists = $api->call('lists/list');
             $return_markup = '<h4>Connect to MailChimp</h4>' . '<p>Now just choose a list and save the connection.</p>' . '<form accept-charset="UTF-8" method="post" action="">' . '<input type="hidden" name="dosettingsadd" value="makeitso" />' . '<input id="connection_name_input" type="hidden" name="settings_name" value="(MailChimp list)" />' . '<input type="hidden" name="settings_type" value="com.mailchimp" />' . '<input type="hidden" name="key" value="' . $api_key . '" />' . '<label for="list">Choose a list to connect to:</label>' . '<select id="list_select" name="list">';
             $selected = ' selected="selected"';
             $list_name = false;
             foreach ($lists['data'] as $list) {
                 if ($selected) {
                     $list_name = $list['name'];
                 }
                 $return_markup .= '<option value="' . $list['id'] . '"' . $selected . '>' . $list['name'] . '</option>';
                 $selected = false;
             }
             $return_markup .= '</select><br /><br />' . '<div><input class="button" type="submit" value="Add The Connection" /></div>' . '</form>' . '<script type="text/javascript">' . '$("#connection_name_input").val("' . $list_name . ' (MailChimp)");' . '$("#list_select").change(function() {' . '	var newvalue = this.options[this.selectedIndex].text + " (MailChimp)";' . '	$("#connection_name_input").val(newvalue);' . '});' . '</script>';
             return $return_markup;
         } else {
             return 'There was an error. (session) Please try again.';
         }
     }
 }
示例#14
0
function smamo_ajax_newsletter()
{
    $response = array();
    $email = wp_strip_all_tags($_POST['email']);
    $name = wp_strip_all_tags($_POST['name']);
    $company = wp_strip_all_tags($_POST['company']);
    if (!$email || $email === '') {
        $response['error'] = 'Indtast venligst en email';
        echo json_encode($response);
        exit;
    }
    if (!$name || $name === '') {
        $response['error'] = 'Indtast venligst et navn';
        echo json_encode($response);
        exit;
    }
    $MailChimp = new MailChimp('ba0b66dc16c9b1243fb3b398438407e7-us11');
    $result = $MailChimp->call('lists/subscribe', array('id' => 'f53e3e341b', 'email' => array('email' => $email), 'merge_vars' => array('NAME' => $name, 'COMPANY' => $company), 'double_optin' => true, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => true));
    $response['mailchimp'] = $result;
    $response['success'] = '<h3>Tjek din indbakke</h3><p>Tak for din tilmelding. Du vil modtage en endelig bekræftelsesmail på den indtastede e-mailadresse.</p>';
    echo json_encode($response);
    exit;
}
示例#15
0
function jio_ajax_newsletter()
{
    $response = array();
    $email = wp_strip_all_tags($_POST['email']);
    $name = wp_strip_all_tags($_POST['name']);
    if (!$email || $email === '') {
        $response['error'] = 'Indtast venligst en email';
        echo json_encode($response);
        exit;
    }
    if (!$name || $name === '') {
        $response['error'] = 'Indtast venligst et navn';
        echo json_encode($response);
        exit;
    }
    $MailChimp = new MailChimp('441ab7ecd918ac4ba432faba058ab24f-us11');
    $result = $MailChimp->call('lists/subscribe', array('id' => '3f31ffc20a', 'email' => array('email' => $email), 'merge_vars' => array('NAME' => $name), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => false));
    $response['mailchimp'] = $result;
    $response['destroy_self'] = '5000';
    $response['success'] = '<h2 class="dimitri">Godt Gået!</h2><p>Vi høres ved inden længe. I mellemtiden er du velkommen til at kigge dig omkring her på min blog.</p>';
    echo json_encode($response);
    exit;
}
示例#16
0
 /**
  * Signup
  *
  */
 function signup()
 {
     $opts = get_option($this->option_name);
     $opts = $opts[$this->number];
     $success = false;
     $message = '';
     $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
     try {
         $mailchimp = new MailChimp($opts['api_key']);
         $response = $mailchimp->call('lists/subscribe', array('email' => array('email' => $email), 'id' => $opts['list_id']));
     } catch (Exception $ex) {
         $message = __("Sorry! There was an error connecting to Mailchimp'", THEMENAME);
     }
     if (isset($response['email'])) {
         $success = true;
     } else {
         $message = $response['error'];
     }
     if (!$success && empty($message)) {
         $message = __("Sorry! There was an error in the newsletter configuration, contact the website admin", THEMENAME);
     }
     echo json_encode(array('success' => $success, 'message' => $message));
     die;
 }
示例#17
0
    }
    // Check for a transient, if not - set one up for one hour
    if (false === ($list_data = get_transient('yikes-easy-mailchimp-list-data'))) {
        // initialize MailChimp Class
        $MailChimp = new MailChimp(get_option('yikes-mc-api-key', ''));
        // retreive our list data
        $list_data = $MailChimp->call('lists/list', array('apikey' => get_option('yikes-mc-api-key', ''), 'limit' => 100));
        // set our transient
        set_transient('yikes-easy-mailchimp-list-data', $list_data, 1 * HOUR_IN_SECONDS);
    }
    // get the list data
    try {
        $api_key = get_option('yikes-mc-api-key', '');
        $MailChimp = new MailChimp($api_key);
        // retreive our list data
        $available_merge_variables = $MailChimp->call('lists/merge-vars', array('apikey' => $api_key, 'id' => array($form['list_id'])));
    } catch (Exception $e) {
        $merge_variable_error = '<p class="description error-descripion">' . __('Error', 'yikes-inc-easy-mailchimp-extender') . ' : ' . $e->getMessage() . '.</p>';
        wp_die(__("Uh Oh...It looks like we ran into an error! Please reload the page and try again. If the error persists, please contact the YIKES Inc. support team.", 'yikes-inc-easy-mailchimp-extender'), 500);
    }
    // get the interest group data
    try {
        $interest_groupings = $MailChimp->call('lists/interest-groupings', array('apikey' => $api_key, 'id' => $form['list_id']));
        $no_interest_groupings = '<p class="description error-descripion">' . __('No Interest Groups Found', 'yikes-inc-easy-mailchimp-extender') . '.</p>';
    } catch (Exception $error) {
        $no_interest_groupings = '<p class="description error-descripion">' . $error->getMessage() . '.</p>';
    }
} else {
    wp_die(__('Oh No!', 'yikes-inc-easy-mailchimp-extender'), __('Error', 'yikes-inc-easy-mailchimp-extender'));
}
/* Confirm we've retreived our form data */
 /**
  *	Hook to submit the data to MailChimp when 
  *	a new integration type is submitted
  *
  *	@since 6.0.0
  **/
 public function subscribe_user_integration($email, $type, $merge_vars)
 {
     // get checkbox data
     $checkbox_options = get_option('optin-checkbox-init', '');
     if ($type != 'registration_form') {
         $update = '1';
     } else {
         $update = '0';
     }
     // set ip address
     if (!isset($merge_vars['OPTIN_IP']) && isset($_SERVER['REMOTE_ADDR'])) {
         $merge_vars['OPTIN_IP'] = sanitize_text_field($_SERVER['REMOTE_ADDR']);
     }
     // set the optin time
     $merge_vars['OPTIN_TIME'] = current_time('Y-m-d H:i:s', 1);
     // check for interest groups
     $interest_groups = isset($checkbox_options[$type]['interest-groups']) ? $checkbox_options[$type]['interest-groups'] : false;
     // if interest groups were found, push them to the merge variable array
     if ($interest_groups) {
         $merge_vars['groupings'] = array();
         foreach ($interest_groups as $interest_group_id => $interest_group_selections) {
             // merge variable interest groups array
             $merge_vars['groupings'][] = array('id' => $interest_group_id, 'groups' => $interest_group_selections);
         }
         // replace the interest groups - to avoid any errors thrown if the admin switches lists, or interest groups
         $merge_vars['replace_interests'] = 1;
     }
     // initialize MailChimp API
     try {
         $MailChimp = new MailChimp(get_option('yikes-mc-api-key', ''));
         // subscribe the user
         $subscribe_response = $MailChimp->call('/lists/subscribe', apply_filters('yikes-mailchimp-checkbox-integration-subscibe-api-request', array('api_key' => get_option('yikes-mc-api-key', ''), 'id' => $checkbox_options[$type]['associated-list'], 'email' => array('email' => sanitize_email($email)), 'merge_vars' => apply_filters('yikes-mailchimp-checkbox-integration-merge-variables', $merge_vars, $type), 'double_optin' => 1, 'update_existing' => $update, 'send_welcome' => 1), $type));
     } catch (Exception $e) {
         $e->getMessage();
     }
     return;
 }
    do_action('yikes-mailchimp-form-submission-' . $form, sanitize_email($data['EMAIL']), $merge_variables, $form, $notifications);
    $default_success_response = $optin_settings['optin'] == 1 ? __("Thank you for subscribing! Check your email for the confirmation message.", 'yikes-inc-easy-mailchimp-extender') : __("Thank you for subscribing!", 'yikes-inc-easy-mailchimp-extender');
    wp_send_json(array('hide' => $submission_settings['hide_form_post_signup'], 'error' => $error, 'response' => !empty($error_messages['success']) ? $error_messages['success'] : $default_success_response, 'redirection' => isset($redirection) ? '1' : '0', 'redirect' => isset($redirect) ? $redirect : ''));
    // end successful submission
} catch (Exception $error) {
    // Something went wrong...
    $error_response = $error->getMessage();
    $error = 1;
    if (get_option('yikes-mailchimp-debug-status', '') == '1') {
        if (strpos($error_response, 'must be provided') !== false) {
            $boom = explode(' ', $error_response);
            $merge_variable = $boom[0];
            $api_key = get_option('yikes-mc-api-key', '');
            $MailChimp = new MailChimp($api_key);
            try {
                $available_merge_variables = $MailChimp->call('lists/merge-vars', array('apikey' => $api_key, 'id' => array($list_id)));
                foreach ($available_merge_variables['data'][0]['merge_vars'] as $merge_var) {
                    if ($merge_var['tag'] == $merge_variable) {
                        $field_name = $merge_var['name'];
                    }
                }
                $error_response = str_replace($merge_variable, '<strong>"' . $field_name . '"</strong>', $error_response);
            } catch (Exception $e) {
                $error_response = $e->getMessage();
            }
        }
        // send our error response back
        wp_send_json(array('hide' => '0', 'error' => $error, 'response' => $error_response));
    } else {
        if (strpos($error_response, 'should include an email') !== false) {
            // include a valid email please
// Validation messages
$error_messages = array('List_AlreadySubscribed' => 'The email you entered is already subscribed.', 'Email_NotExists' => 'The email you entered is invalid.', 'else' => 'An error occurred.');
$success_message = 'Success! Please check your e-mail to complete the subscription.';
// =============================================
// BEGIN SUBSCRIBE PROCESS
// =============================================
// Form's values
$email = isset($_REQUEST['email']) ? $_REQUEST['email'] : '';
// Initiate API object
require_once '../php/mailchimp/class.mailchimp-api.php';
$mailchimp = new MailChimp($api_key);
// Request parameters
$config = array('id' => $list_id, 'email' => array('email' => $email), 'merge_vars' => NULL, 'email_type' => 'html', 'double_optin' => true, 'update_existing' => false, 'replace_interests' => true, 'send_welcome' => false);
// Send request
// http://apidocs.mailchimp.com/api/2.0/lists/subscribe.php
$result = $mailchimp->call('lists/subscribe', $config);
if (array_key_exists('status', $result) && $result['status'] == 'error') {
    // If error occurs
    $result['message'] = array_key_exists($result['name'], $error_messages) ? $error_messages[$result['name']] : $error_messages['else'];
} else {
    // If success
    $result['message'] = $success_message;
}
// Send output
if (!empty($_REQUEST['ajax'])) {
    // called via AJAX
    echo json_encode($result);
} else {
    // no AJAX
    if (array_key_exists('status', $result) && $result['status'] == 'error') {
        echo 'Error: ' . $result['error'];
示例#21
0
<?php

require_once 'lib/Drewm/MailChimp.php';
if (!isset($_REQUEST['id']) || !isset($_REQUEST['FNAME']) || !isset($_REQUEST['LNAME']) || !isset($_REQUEST['EMAIL']) || !isset($_REQUEST['STATE']) || !isset($_REQUEST['POSTAL']) || !isset($_REQUEST['BIRTHDAY'])) {
    header('HTTP/1.1 400 Bad Request', true, 400);
    echo "All fields are required.\n\n";
    var_dump($_REQUEST);
} else {
    $MailChimp = new MailChimp('a538079e399f5a7cf0c99ccd8139d0ca-us3');
    $result = $MailChimp->call('lists/subscribe', array('id' => '2ef3db6c94', 'email' => array('email' => $_REQUEST['EMAIL']), 'merge_vars' => array('FNAME' => $_REQUEST['FNAME'], 'LNAME' => $_REQUEST['LNAME'], 'EMAIL' => $_REQUEST['EMAIL'], 'STATE' => $_REQUEST['STATE'], 'POSTAL' => $_REQUEST['POSTAL'], 'BIRTHDAY' => $_REQUEST['BIRTHDAY']), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => true));
    if ($result) {
        header('Location: /?subscribeSuccess=' . $_REQUEST['id']);
    } else {
        header('Location: /?subscribeFailure=' . $_REQUEST['id']);
    }
}
<?php

// lets confirm the user has a valid API key stored
if ($this->is_user_mc_api_valid_form(false) == 'valid') {
    // storethe API key
    $api_key = get_option('yikes-mc-api-key', '');
    // initialize MailChimp API
    $MailChimp = new MailChimp($api_key);
    /// Check for a transients, if not - set them up
    if (false === ($profile_info = get_transient('yikes-easy-mailchimp-profile-data'))) {
        // retreive our list data
        $profile_info = $MailChimp->call('/users/profile', array('api_key' => $api_key));
        // set our transient for one week
        set_transient('yikes-easy-mailchimp-profile-data', $profile_info, 1 * WEEK_IN_SECONDS);
    }
    if (false === ($account_details = get_transient('yikes-easy-mailchimp-account-data'))) {
        // retreive our list data
        $account_details = $MailChimp->call('/helper/account-details', array('api_key' => $api_key));
        // set our transient for one hour
        set_transient('yikes-easy-mailchimp-account-data', $account_details, 1 * HOUR_IN_SECONDS);
    }
    if (false === ($account_activity = get_transient('yikes-easy-mailchimp-account-activity'))) {
        // retreive our list data
        $account_activity = $MailChimp->call('/helper/chimp-chatter', array('api_key' => $api_key));
        // set our transient for one hour
        set_transient('yikes-easy-mailchimp-account-activity', $account_activity, 1 * HOUR_IN_SECONDS);
    }
} else {
    wp_die(__('It looks like you need to re-validate your MailChimp API key before you can continue.', 'yikes-inc-easy-mailchimp-extender'), 500);
}
?>
示例#23
0
function et_pb_submit_subscribe_form()
{
    if (!wp_verify_nonce($_POST['et_load_nonce'], 'et_load_nonce')) {
        die(json_encode(array('error' => __('Configuration error', 'Divi'))));
    }
    $service = sanitize_text_field($_POST['et_service']);
    $list_id = sanitize_text_field($_POST['et_list_id']);
    $email = sanitize_email($_POST['et_email']);
    $firstname = sanitize_text_field($_POST['et_firstname']);
    if ('' === $firstname) {
        die(json_encode(array('error' => __('Please enter first name', 'Divi'))));
    }
    if (!is_email(sanitize_email($_POST['et_email']))) {
        die(json_encode(array('error' => __('Incorrect email', 'Divi'))));
    }
    if ('' == $list_id) {
        die(json_encode(array('error' => __('Configuration error: List is not defined', 'Divi'))));
    }
    $success_message = __('<h2 class="et_pb_subscribed">Subscribed - look for the confirmation email!</h2>', 'Divi');
    switch ($service) {
        case 'mailchimp':
            $lastname = sanitize_text_field($_POST['et_lastname']);
            $email = array('email' => $email);
            if (!class_exists('MailChimp')) {
                require_once get_template_directory() . '/includes/subscription/mailchimp/mailchimp.php';
            }
            $mailchimp_api_key = et_get_option('divi_mailchimp_api_key');
            if ('' === $mailchimp_api_key) {
                die(json_encode(array('error' => __('Configuration error: api key is not defined', 'Divi'))));
            }
            $mailchimp = new MailChimp($mailchimp_api_key);
            $merge_vars = array('FNAME' => $firstname, 'LNAME' => $lastname);
            $retval = $mailchimp->call('lists/subscribe', array('id' => $list_id, 'email' => $email, 'merge_vars' => $merge_vars));
            if (isset($retval['error'])) {
                if ('214' == $retval['code']) {
                    $error_message = str_replace('Click here to update your profile.', '', $retval['error']);
                    $result = json_encode(array('success' => $error_message));
                } else {
                    $result = json_encode(array('success' => $retval['error']));
                }
            } else {
                $result = json_encode(array('success' => $success_message));
            }
            die($result);
            break;
        case 'aweber':
            if (!class_exists('AWeberAPI')) {
                require_once get_template_directory() . '/includes/subscription/aweber/aweber_api.php';
            }
            $account = et_pb_get_aweber_account();
            if (!$account) {
                die(json_encode(array('error' => __('Aweber: Wrong configuration data', 'Divi'))));
            }
            try {
                $list_url = "/accounts/{$account->id}/lists/{$list_id}";
                $list = $account->loadFromUrl($list_url);
                $new_subscriber = $list->subscribers->create(array('email' => $email, 'name' => $firstname));
                die(json_encode(array('success' => $success_message)));
            } catch (Exception $exc) {
                die(json_encode(array('error' => $exc->message)));
            }
            break;
    }
    die;
}
示例#24
0
<?php

require_once "MailChimp.php";
$MailChimp = new MailChimp('f412b2a0dc217fcd1ef71e19e4ee752d-us11');
$result = $MailChimp->call('lists/subscribe', array('id' => '9eed190e82', 'email' => array('email' => clean($_GET['mail'])), 'double_optin' => false, 'update_existing' => false, 'replace_interests' => false, 'send_welcome' => true));
print_r($result);
function clean($string)
{
    $string = str_replace(' ', '-', $string);
    // Replaces all spaces with hyphens.
    return preg_replace('/[^\\@\\.A-Za-z0-9\\-]/', '', $string);
    // Removes special chars.
}
<?php

// lets run an ajax request to get all of our field data, to either prepopulate
// or build our default selection arrays etc.
$api_key = get_option('yikes-mc-api-key', '');
$MailChimp = new MailChimp($api_key);
// get the interest group data
try {
    $interest_groupings = $MailChimp->call('lists/interest-groupings', array('apikey' => $api_key, 'id' => $form_data_array['list_id']));
    if ($interest_groupings) {
        // find and return the location of this merge field in the array
        $index = $this->findMCListIndex($form_data_array['group_id'], $interest_groupings, 'id');
        // check for our index...
        if (isset($index)) {
            // store it and use it to pre-populate field data (only on initial add to form)
            $merge_field_data = $interest_groupings[$index];
        }
    }
} catch (Exception $error) {
    $no_interest_groupings = $error->getMessage();
}
?>
<section class="draggable" id="<?php 
echo $form_data_array['group_id'];
?>
">
	<!-- top -->
	<a href="#" class="expansion-section-title settings-sidebar">
		<span class="dashicons dashicons-plus" title="<?php 
_e('Expand Field', 'yikes-inc-easy-mailchimp-extender');
?>
        $wpdb->update($wpdb->prefix . 'yikes_easy_mc_forms', array('submissions' => $form_data['submissions']), array('ID' => $form), array('%d'), array('%d'));
        // end successful submission
    } catch (Exception $error) {
        // Something went wrong...
        $error_response = $error->getMessage();
        ?>
 <p class="yikes-easy-mc-error-message"><?php 
        if (get_option('yikes-mailchimp-debug-status', '') == '1') {
            // If a field exists on the form, is required but isn't being displayed (current displays like "8YBR1 must be provided" , should be more user friendly)
            if (strpos($error_response, 'must be provided') !== false) {
                $boom = explode(' ', $error_response);
                $merge_variable = $boom[0];
                $api_key = get_option('yikes-mc-api-key', '');
                $MailChimp = new MailChimp($api_key);
                try {
                    $available_merge_variables = $MailChimp->call('lists/merge-vars', array('apikey' => $api_key, 'id' => array($_POST['yikes-mailchimp-associated-list-id'])));
                    foreach ($available_merge_variables['data'][0]['merge_vars'] as $merge_var) {
                        if ($merge_var['tag'] == $merge_variable) {
                            $field_name = $merge_var['name'];
                        }
                    }
                    $error_response = str_replace($merge_variable, '<strong>"' . $field_name . '"</strong>', $error_response);
                    echo $error_response;
                } catch (Exception $e) {
                    echo $e->getMessage();
                }
            } else {
                echo $error_response;
            }
        } else {
            if (strpos($error_response, 'should include an email') !== false) {
示例#27
0
<?php

// Your Account API & List ID
$api_key = "70537ba9706f593a5dc19cae64426914-us12";
// YOUR-API-KEY-HERE
$list_id = "9ae6e05048";
// YOUR-LIST-ID-HERE
// Check $recipient
if ($recipient === '' || $list_id === '') {
    returnAndExitAjaxResponse(constructAjaxResponseArray(FALSE, 'APIDATA_IS_NOT_SET', array('error_message' => 'API KEY / LIST ID is not set. Please configure the script.')));
}
// Include PHP wrapper
include_once 'Mailchimp.php';
$MailChimp = new MailChimp($api_key);
try {
    $result = $MailChimp->call('lists/subscribe', array('id' => $list_id, 'email' => array('email' => $_POST['email']), 'merge_vars' => array('FNAME' => $_POST['fname']), 'double_optin' => false, 'update_existing' => false, 'replace_interests' => false, 'send_welcome' => true));
    returnAndExitAjaxResponse(constructAjaxResponseArray(TRUE));
} catch (Exception $_e) {
    returnAndExitAjaxResponse(constructAjaxResponseArray(FALSE, 'ERROR_AT_MAILCHIMP', array('error_message' => $_e->getMessage())));
}
/*
	Construct ajax response array
	Input: Result (bool), Message (optional), Data to be sent back in array
*/
function constructAjaxResponseArray($_response, $_message = '', $_json = null)
{
    $_responseArray = array();
    $_response = $_response === TRUE ? TRUE : FALSE;
    $_responseArray['response'] = $_response;
    if (isset($_message)) {
        $_responseArray['message'] = $_message;
示例#28
0
 function cs_mailchimp()
 {
     global $cs_theme_options, $counter;
     $mailchimp_key = '';
     if (isset($cs_theme_options['cs_mailchimp_key'])) {
         $mailchimp_key = $cs_theme_options['cs_mailchimp_key'];
     }
     if (isset($_POST) and !empty($_POST['cs_list_id']) and $mailchimp_key != '') {
         if ($mailchimp_key != '') {
             $MailChimp = new MailChimp($mailchimp_key);
         }
         $email = $_POST['mc_email'];
         $list_id = $_POST['cs_list_id'];
         $result = $MailChimp->call('lists/subscribe', array('id' => $list_id, 'email' => array('email' => $email), 'merge_vars' => array(), 'double_optin' => false, 'update_existing' => false, 'replace_interests' => false, 'send_welcome' => true));
         if ($result != '') {
             if (isset($result['status']) and $result['status'] == 'error') {
                 echo balanceTags($result['error']);
             } else {
                 _e('subscribe successfully', 'LMS');
             }
         }
     } else {
         _e('please set API key', 'LMS');
     }
     die;
 }
示例#29
0
// Run our custom query to retreive our forms from the table we've created
global $wpdb;
/*********************/
/*	Get all forms	 */
/********************/
// return it as an array, so we can work with it to build our form below
$form_results = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'yikes_easy_mc_forms', ARRAY_A);
/* Store Data if User is Authorized */
if ($this->is_user_mc_api_valid_form(false) == 'valid') {
    /// Check for a transient, if not - set one up for one hour
    if (false === ($list_data = get_transient('yikes-easy-mailchimp-list-data'))) {
        // initialize MailChimp Class
        $MailChimp = new MailChimp(get_option('yikes-mc-api-key', ''));
        // retreive our list data
        $list_data = $MailChimp->call('lists/list', array('apikey' => get_option('yikes-mc-api-key', ''), 'limit' => 100));
        // set our transient
        set_transient('yikes-easy-mailchimp-list-data', $list_data, 1 * HOUR_IN_SECONDS);
    }
} else {
    $list_data = null;
}
?>
<div class="wrap">
	<!-- Freddie Logo -->
	<img src="<?php 
echo YIKES_MC_URL . 'includes/images/MailChimp_Assets/Freddie_60px.png';
?>
" alt="<?php 
_e('Freddie - MailChimp Mascot', 'yikes-inc-easy-mailchimp-extender');
?>
        $url = $this->api_endpoint . '/' . $method . '.json';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args));
        $result = curl_exec($ch);
        curl_close($ch);
        return $result ? json_decode($result, true) : false;
    }
}
$MailChimp = new MailChimp('YOURAPIKEY');
// enter your API-Key here
$member_count = $MailChimp->call('lists/list');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
		<meta http-equiv="Cache-control" content="no-cache" />	
		<style type="text/css">
			@font-face { font-family: "Roadgeek2005SeriesD";
						 src: url("http://panic.com/fonts/Roadgeek 2005 Series D/Roadgeek 2005 Series D.otf"); }		
			body, * { }
			body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, textarea, p, blockquote, th, td { margin: 0;
			                                                                                                                         padding: 0; }
			fieldset, img { border: 0; }
			html, body, #main { overflow: hidden; }