Beispiel #1
0
 /**
  * Signs a user up to the email optin list for Thomas Griffin Media.
  *
  * @since 1.0.0
  */
 public function signup()
 {
     // Validate the fields before loading the API .
     if (!isset($_REQUEST['email']) || isset($_REQUEST['email']) && empty($_REQUEST['email']) || !is_email($_REQUEST['email'])) {
         echo json_encode(array('error' => Tgmsp_Lite_Strings::get_instance()->strings['email_error']));
         die;
     }
     // Add the user to the email newsletter list.
     require_once plugin_dir_path(dirname(dirname(__FILE__))) . 'madmimi/MadMimi.class.php';
     $mimi = new MadMimi('*****@*****.**', '709d4d36e5690d97382f36ee11d7a268');
     // Add to general email list.
     $info = array('email' => $_REQUEST['email'], 'add_list' => 'Soliloquy Lite');
     $mimi->AddUser($info);
     // Ensure that we properly die at the end of processing the request.
     echo json_encode(array('success' => Tgmsp_Lite_Strings::get_instance()->strings['email_success']));
     die;
 }
<?php

require 'MadMimi.class.php';
$mimi = new MadMimi('*****@*****.**', 'f745b56de62ab9b46f613173a10806fb');
print $mimi->Search('nicholas');
$arr = array('rock' => 'roll', 'all' => 'night');
print http_build_query($arr);
Beispiel #3
0
<?php

require dirname(__FILE__) . '/madmimi/MadMimi.class.php';
$mailer = new MadMimi('*****@*****.**', '24cb537d19cf1169d2074ba06984ab4a');
if (isset($_REQUEST['email'])) {
    $list = isset($_REQUEST['list']) ? $_REQUEST['list'] : 'Cutting Edge Stencils List';
    $user = array('email' => $_REQUEST['email'], 'add_list' => $list);
    $mailer->AddUser($user);
}
Beispiel #4
0
<?php

require dirname(__FILE__) . '/../MadMimi.class.php';
// There are a total of four arguments that can be used on the next line. The first two are shown here, the second two
// are optional. The first of them is a debugger, which defaults to false, and the second, allows you to print
// the transaction ID when sending a message. It also defaults to false.
$mailer = new MadMimi('email', 'APIKEY');
$options = array('recipients' => 'Nicholas Young <*****@*****.**>', 'promotion_name' => 'Untitled Promotion', 'subject' => 'You Gotta Read This', 'from' => 'Mad Mailer <*****@*****.**>');
$body = array('greeting' => 'Hello', 'name' => 'Nicholas');
$mailer->SendMessage($options, $body);
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('');
}
<?php

require dirname(__FILE__) . '/../MadMimi.class.php';
// There are a total of four arguments that can be used on the next line. The first two are shown here, the second two
// are optional. The first of them is a debugger, which defaults to false, and the second, allows you to print
// the transaction ID when sending a message. It also defaults to false.
$mailer = new MadMimi('', '');
// Create a list
$mailer->NewList('My Awesome List');
// Adding an audience member with just an email address
// NOTE: This list must exist
$mailer->AddMembership('My Awesome List', '*****@*****.**');
// Adding an audience member with some additional fields
// NOTE:
$mailer->AddMembership('My Awesome List', '*****@*****.**', array('first_name' => 'Mad Mimi', 'last_name' => 'Help!'));
// Removing an audience member
// NOTE: This does not delete the audience member, just removes them from the list
$mailer->RemoveMembership('My Awesome List', '*****@*****.**');
// Deleting the list
// NOTE: This does not delete the audience members
$mailer->DeleteList('My Awesome List');
<?php

require dirname(__FILE__) . '/../MadMimi.class.php';
// There are a total of four arguments that can be used on the next line. The first two are shown here, the second two
// are optional. The first of them is a debugger, which defaults to false, and the second, allows you to print
// the transaction ID when sending a message. It also defaults to false.
$mailer = new MadMimi('YOUR USERNAME (OR E-MAIL ADDRESS)', 'YOUR API KEY');
if ($mailer->Authenticate()) {
    // Get all lists for this account..
    $lists = $mailer->Lists();
    $lists = new SimpleXMLElement($lists);
    // ...and loop through them.
    foreach ($lists as $list) {
        echo $list['name'] . "<br />";
    }
    // Now, let's check a user's membership status...
    $memberships = $mailer->Memberships('*****@*****.**');
    $memberships = new SimpleXMLElement($memberships);
    foreach ($memberships as $list) {
        echo $list['name'] . "<br />";
    }
    // Maybe we just want to send a message?
    $options = array('recipients' => 'Nicholas Young <*****@*****.**>', 'promotion_name' => 'My Awesome Promotion', 'subject' => 'You Gotta Read This', 'from' => 'Mad Mailer <*****@*****.**>');
    $body = array('Greeting' => 'Hello From MadMailer!');
    $mailer->SendMessage($options, $body);
} else {
    echo 'Wrong username or api key' . '<br />' . PHP_EOL;
}
Beispiel #8
0
	/**
	 * Get all Mad Mimi Lists and display in settings
	 *
	 */
	public function get_madmimi_lists() {

		$options = '';

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

			require_once( 'includes/madmimi/MadMimi.class.php');

			$mailer = new MadMimi(sanitize_text_field( $_POST['username'] ), sanitize_text_field( $_POST['api_key'] ) );

			if (isset($mailer)) {
				try {
					$lists = $mailer->Lists();
					$lists  = new SimpleXMLElement($lists);

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

				    if (isset($_POST['list']) && $_POST['list'] != '') {
					    $options = '';
						foreach ($lists->list as $l) {

							if ($_POST['list'] == $l->attributes()->{'name'}->{0}) {
								$options .= '<option value="' . $l->attributes()->{'name'}->{0} . '" selected="selected">' .  $l->attributes()->{'name'}->{0} . '</option>';
							} else {
								$options .= '<option value="' . $l->attributes()->{'name'}->{0} . '">' .  $l->attributes()->{'name'}->{0} . '</option>';
							}
						}
					}
				} catch (Exception $exc) {}
			}
		}

		echo $options;

		die(); // this is required to terminate immediately and return a proper response
	}
function snp_ml_get_madm_lists($ml_madm_username = '', $ml_madm_apikey = '')
{
    require_once SNP_DIR_PATH . '/include/madmimi/MadMimi.class.php';
    $list = array();
    if (snp_get_option('ml_madm_username') && snp_get_option('ml_madm_apikey') || $ml_madm_username && $ml_madm_apikey) {
        try {
            if ($ml_madm_username && $ml_madm_apikey) {
                $mailer = new MadMimi($ml_madm_username, $ml_madm_apikey);
            } else {
                $mailer = new MadMimi(snp_get_option('ml_madm_username'), snp_get_option('ml_madm_apikey'));
            }
            $lists = new SimpleXMLElement($mailer->Lists());
            if ($lists->list) {
                foreach ($lists->list as $l) {
                    $list[(string) $l->attributes()->{'name'}->{0}] = array('name' => (string) $l->attributes()->{'name'}->{0});
                }
            }
        } catch (Exception $exc) {
        }
    }
    if (count($list) == 0) {
        $list[0] = array('name' => 'Nothing Found...');
    }
    return $list;
}
 public function indeed_madMimi($username, $api_key, $listName, $e_mail, $first_name = '', $last_name = '')
 {
     require $this->dir_path . '/email_services/madmimi/MadMimi.class.php';
     $mailer = new MadMimi($username, $api_key);
     $user = array('email' => $e_mail, 'firstName' => $first_name, 'lastName' => $last_name, 'add_list' => $listName);
     if ($mailer) {
         $mailer->AddUser($user);
         return 1;
     } else {
         return 0;
     }
 }
Beispiel #11
0
<?php

require dirname(__FILE__) . '/../MadMimi.class.php';
// There are a total of four arguments that can be used on the next line. The first two are shown here, the second two
// are optional. The first of them is a debugger, which defaults to false, and the second, allows you to print
// the transaction ID when sending a message. It also defaults to false.
$mailer = new MadMimi('YOUR USERNAME (OR E-MAIL ADDRESS)', 'YOUR API KEY');
// Let's make a new list...
$mailer->NewList('Test');
// ...and then get all of the lists on this account (which should include the one we just created.)
$lists = $mailer->Lists();
// ...and loop through them.
foreach ($lists as $list) {
    echo $list['name'] . " => " . $list['id'] . "<br />";
}
Beispiel #12
0
 /**
  * Set Madmimi list transient and return the list
  *
  * @param $username string Madmimi user
  * @param $apikey  string Madmimi apikey
  * @param $post_id int Post id
  *
  * @return boolean|mixed array()
  * @since  1.0.0
  * @author Antonio La Rocca <*****@*****.**>
  */
 public function set_madmimi_lists($username, $apikey, $post_id)
 {
     if (isset($apikey) && strcmp($apikey, '') != 0) {
         // include libraries
         include_once $this->plugin_path . '/lib/vendor/madmimi/MadMimi.class.php';
         // initialize mailchimp wrapper
         $madmimi_wrapper = new MadMimi($username, $apikey);
         // fetch list
         $xml = $madmimi_wrapper->Lists();
         $result = new SimpleXMLElement($xml);
         // generate result array
         $lists = array();
         foreach ($result->list as $list) {
             $attrs = $list->attributes();
             $id = (string) $attrs['id'];
             $name = (string) $attrs['name'];
             $lists[$id] = $name;
         }
         // memorize result array in a transient
         set_transient('yit-madmimi-newsletter-' . $post_id . '-list', $lists, WEEK_IN_SECONDS);
         return $lists;
     } else {
         return false;
     }
 }
<?php

/*
	In this file, we're going to make some checkboxes, and auto-select which ones the user belongs to.
	Note: My execution probably isn't the prettiest, and I encourage you to modify this for your own usage,
	rather than just using it as-is.
*/
require dirname(__FILE__) . '/../MadMimi.class.php';
// There are a total of four arguments that can be used on the next line. The first two are shown here, the second two
// are optional. The first of them is a debugger, which defaults to false, and the second, allows you to print
// the transaction ID when sending a message. It also defaults to false.
$mailer = new MadMimi('YOUR USERNAME (OR E-MAIL ADDRESS)', 'YOUR API KEY');
// Get all lists for this account..
$lists = $mailer->Lists();
$memberships = $mailer->Memberships('*****@*****.**');
echo '<form name="user_lists" method="POST" action="">';
foreach ($lists as $list) {
    foreach ($memberships as $membership) {
        if ((int) $list['id'] == (int) $membership['id']) {
            echo $list['name'] . ' <input type="checkbox" name="' . $list['name'] . '" checked="true"> <br />';
        } else {
            echo $list['name'] . ' <input type="checkbox" name="' . $list['name'] . '"> <br />';
        }
    }
}
echo '<input type="submit" value="Submit">';
echo '</form>';
 /**
  * Get all Mad Mimi Lists and display in settings
  *
  * @access public
  * @return void
  */
 function nnr_new_int_get_madmimi_lists_v1()
 {
     do_action('nnr_news_int_before_get_madmimi_lists_v1');
     $options = '';
     if (isset($_POST['api_key']) && $_POST['api_key'] != '' && isset($_POST['username']) && $_POST['username'] != '') {
         require_once dirname(dirname(__FILE__)) . '/services/madmimi/MadMimi.class.php';
         $mailer = new MadMimi($_POST['username'], $_POST['api_key']);
         if (isset($mailer)) {
             try {
                 $lists = $mailer->Lists();
                 $lists = new SimpleXMLElement($lists);
                 if ($lists->list) {
                     foreach ($lists->list as $l) {
                         $options .= '<option value="' . $l->attributes()->{'name'}->{0} . '">' . $l->attributes()->{'name'}->{0} . '</option>';
                     }
                 }
                 if (isset($_POST['list']) && $_POST['list'] != '') {
                     $options = '';
                     foreach ($lists->list as $l) {
                         if ($_POST['list'] == $l->attributes()->{'name'}->{0}) {
                             $options .= '<option value="' . $l->attributes()->{'name'}->{0} . '" selected="selected">' . $l->attributes()->{'name'}->{0} . '</option>';
                         } else {
                             $options .= '<option value="' . $l->attributes()->{'name'}->{0} . '">' . $l->attributes()->{'name'}->{0} . '</option>';
                         }
                     }
                 }
             } catch (Exception $exc) {
             }
         }
     }
     do_action('nnr_news_int_after_get_madmimi_lists_v1');
     echo apply_filters('nnr_news_int_get_madmimi_lists_v1', $options);
     die;
     // this is required to terminate immediately and return a proper response
 }
 /**
  * Record an impression made by a optin fire
  * This function is called via PHP.
  *
  * @access public
  * @static
  * @return void
  */
 function nnr_new_int_add_email_v1()
 {
     do_action('nnr_news_int_before_submission_add_email_v1');
     // No First Name
     if (!isset($_POST['first_name'])) {
         $_POST['first_name'] = '';
     }
     // No Last Name
     if (!isset($_POST['last_name'])) {
         $_POST['last_name'] = '';
     }
     // Could not find Data ID
     if (!isset($_POST['data_id']) || $_POST['data_id'] == '') {
         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('Could not find Data ID.', $_POST['text_domain'])));
         die;
     }
     // Get all newsletter data for this data instance
     $data_manager = new NNR_Data_Manager_v1($_POST['table_name']);
     $data_instance = $data_manager->get_data_from_id($_POST['data_id']);
     $success_action = isset($data_instance['args']['newsletter']['success_action']) ? stripcslashes($data_instance['args']['newsletter']['success_action']) : 'message';
     $success_mesage = isset($data_instance['args']['newsletter']['success_message']) ? stripcslashes($data_instance['args']['newsletter']['success_message']) : __('Welcome to the community!', $_POST['text_domain']);
     $success_url = isset($data_instance['args']['newsletter']['success_url']) ? stripcslashes($data_instance['args']['newsletter']['success_url']) : '';
     // No Email
     if (!isset($_POST['email']) || $_POST['email'] == '') {
         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('No Email address provided.', $_POST['text_domain'])));
         die;
     }
     // Invalid Email Address
     if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('Invalid Email provided.', $_POST['text_domain'])));
         die;
     }
     // WordPress
     if ($_POST['type'] == 'wordpress') {
         $newsletter_db = new NNR_Newsletter_Integrations_Submission_v1($_POST['news_table_name']);
         $result = $newsletter_db->add_data(array('data_id' => $_POST['data_id'], 'email' => $_POST['email'], 'first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name']));
         if ($result) {
             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
             die;
         } else {
             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'message' => __('We already have your email!', $_POST['text_domain'])));
             die;
         }
     } else {
         if ($_POST['type'] == 'mailchimp') {
             require_once dirname(dirname(__FILE__)) . '/services/mailchimp/MailChimp.php';
             if (!isset($data_instance['args']['newsletter']['mailchimp']['api_key']) || $data_instance['args']['newsletter']['mailchimp']['api_key'] == '') {
                 echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('MailChimp account is not setup properly.', $_POST['text_domain'])));
                 die;
             }
             if (!isset($data_instance['args']['newsletter']['mailchimp']['list']) || $data_instance['args']['newsletter']['mailchimp']['list'] == '') {
                 echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('MailChimp: No list specified.', $_POST['text_domain'])));
                 die;
             }
             if (!isset($data_instance['args']['newsletter']['mailchimp']['optin'])) {
                 $data_instance['args']['newsletter']['mailchimp']['optin'] = true;
             }
             $MailChimp = new NNR_New_Int_MailChimp($data_instance['args']['newsletter']['mailchimp']['api_key']);
             $result = $MailChimp->call('lists/subscribe', array('id' => $data_instance['args']['newsletter']['mailchimp']['list'], 'email' => array('email' => $_POST['email']), 'merge_vars' => array('FNAME' => $_POST['first_name'], 'LNAME' => $_POST['last_name']), 'double_optin' => $data_instance['args']['newsletter']['mailchimp']['optin'], 'update_existing' => false, 'replace_interests' => false, 'send_welcome' => true));
             if ($result) {
                 if (isset($result['email'])) {
                     echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                     die;
                 } else {
                     if (isset($result['status']) && $result['status'] == 'error') {
                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $result['error']));
                         die;
                     }
                 }
             } else {
                 echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('Unable to subscribe.', $_POST['text_domain'])));
                 die;
             }
         } else {
             if ($_POST['type'] == 'aweber') {
                 require_once dirname(dirname(__FILE__)) . '/services/aweber/aweber_api.php';
                 $aweber = new AWeberAPI($data_instance['args']['newsletter']['aweber']['consumer_key'], $data_instance['args']['newsletter']['aweber']['consumer_secret']);
                 try {
                     $account = $aweber->getAccount($data_instance['args']['newsletter']['aweber']['access_key'], $data_instance['args']['newsletter']['aweber']['access_secret']);
                     $list = $account->loadFromUrl('/accounts/' . $account->id . '/lists/' . $data_instance['args']['newsletter']['aweber']['list_id']);
                     $subscriber = array('email' => $_POST['email'], 'name' => $_POST['first_name'] . ' ' . $_POST['last_name'], 'ip' => $_SERVER['REMOTE_ADDR']);
                     $newSubscriber = $list->subscribers->create($subscriber);
                     echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                     die;
                 } catch (AWeberAPIException $exc) {
                     echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $exc->message));
                     die;
                 }
             } else {
                 if ($_POST['type'] == 'getresponse') {
                     require_once dirname(dirname(__FILE__)) . '/services/getresponse/jsonRPCClient.php';
                     $api = new jsonRPCClient('http://api2.getresponse.com');
                     try {
                         $api->add_contact($data_instance['args']['newsletter']['getresponse']['api_key'], array('campaign' => $data_instance['args']['newsletter']['getresponse']['campaign'], 'name' => $_POST['first_name'] . ' ' . $_POST['last_name'], 'email' => $_POST['email']));
                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                         die;
                     } catch (RuntimeException $exc) {
                         $msg = $exc->getMessage();
                         $msg = substr($msg, 0, strpos($msg, ";"));
                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $msg));
                         die;
                     }
                 } else {
                     if ($_POST['type'] == 'campaignmonitor') {
                         require_once dirname(dirname(__FILE__)) . '/services/campaignmonitor/csrest_subscribers.php';
                         $wrap = new CS_REST_Subscribers($data_instance['args']['newsletter']['campaignmonitor']['list'], $data_instance['args']['newsletter']['campaignmonitor']['api_key']);
                         // Check if subscriber is already subscribed
                         $result = $wrap->get($_POST['email']);
                         if ($result->was_successful()) {
                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('You are already subscribed to this list.', $_POST['text_domain'])));
                             die;
                         }
                         $result = $wrap->add(array('EmailAddress' => $_POST['email'], 'Name' => $_POST['first_name'] . ' ' . $_POST['last_name'], 'Resubscribe' => true));
                         if ($result->was_successful()) {
                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                             die;
                         } else {
                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $result->response->Message));
                             die;
                         }
                     } else {
                         if ($_POST['type'] == 'madmimi') {
                             require_once dirname(dirname(__FILE__)) . '/services/madmimi/MadMimi.class.php';
                             $mailer = new MadMimi($data_instance['args']['newsletter']['madmimi']['username'], $data_instance['args']['newsletter']['madmimi']['api_key']);
                             try {
                                 // Check if user is already in list
                                 $result = $mailer->Memberships($_POST['email']);
                                 $lists = new SimpleXMLElement($result);
                                 if ($lists->list) {
                                     foreach ($lists->list as $l) {
                                         if ($l->attributes()->{'name'}->{0} == $data_instance['args']['newsletter']['madmimi']['list']) {
                                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'message' => __('You are already subscribed to this list.', $_POST['text_domain'])));
                                             die;
                                         }
                                     }
                                 }
                                 $result = $mailer->AddMembership($data_instance['args']['newsletter']['madmimi']['list'], $_POST['email'], array('first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name']));
                                 echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                                 die;
                             } catch (RuntimeException $exc) {
                                 echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $msg));
                                 die;
                             }
                         } else {
                             if ($_POST['type'] == 'infusionsoft') {
                                 require_once dirname(dirname(__FILE__)) . '/services/infusionsoft/isdk.php';
                                 try {
                                     $infusion_app = new iSDK();
                                     $infusion_app->cfgCon($data_instance['args']['newsletter']['infusionsoft']['app_id'], $data_instance['args']['newsletter']['infusionsoft']['api_key'], 'throw');
                                 } catch (iSDKException $e) {
                                     echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $e->getMessage()));
                                     die;
                                 }
                                 if (empty($error_message)) {
                                     $contact_data = $infusion_app->dsQuery('Contact', 1, 0, array('Email' => $_POST['email']), array('Id', 'Groups'));
                                     // Check if contact already exists
                                     if (0 < count($contact_data)) {
                                         if (false === strpos($contact_data[0]['Groups'], $data_instance['args']['newsletter']['infusionsoft']['list'])) {
                                             $infusion_app->grpAssign($contact_data[0]['Id'], $data_instance['args']['newsletter']['infusionsoft']['list']);
                                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                                             die;
                                         } else {
                                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'message' => __('You are already subscribed to this list.', $_POST['text_domain'])));
                                             die;
                                         }
                                     } else {
                                         $new_contact_id = $infusion_app->dsAdd('Contact', array('FirstName' => $_POST['first_name'], 'LastName' => $_POST['last_name'], 'Email' => $_POST['email']));
                                         $infusion_app->grpAssign($new_contact_id, $data_instance['args']['newsletter']['infusionsoft']['list']);
                                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                                         die;
                                     }
                                 }
                             } else {
                                 if ($_POST['type'] == 'mymail') {
                                     // Check if plugin is activated
                                     if (!function_exists('mymail')) {
                                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('MyMail is not activated.', $_POST['text_domain'])));
                                         die;
                                     }
                                     // Add subscriber
                                     $subscriber_id = mymail('subscribers')->add(array('email' => $_POST['email'], 'firstname' => $_POST['first_name'], 'lastname' => $_POST['last_name']), false);
                                     // Add to List
                                     if (!is_wp_error($subscriber_id)) {
                                         mymail('subscribers')->assign_lists($subscriber_id, array($data_instance['args']['newsletter']['mymail']['list']));
                                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                                         die;
                                     } else {
                                         echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'message' => __('You are already subscribed to this list.', $_POST['text_domain'])));
                                         die;
                                     }
                                 } else {
                                     if ($_POST['type'] == 'activecampaign') {
                                         require_once dirname(dirname(__FILE__)) . '/services/activecampaign/ActiveCampaign.class.php';
                                         $ac = new ActiveCampaign($data_instance['args']['newsletter']['activecampaign']['app_url'], $data_instance['args']['newsletter']['activecampaign']['api_key']);
                                         if (!(int) $ac->credentials_test()) {
                                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('Unable to to connect to Active Campaign.', $_POST['text_domain'])));
                                             die;
                                         }
                                         // Add subscriber
                                         $contact_sync = $ac->api("contact/add", array("email" => $_POST['email'], "first_name" => $_POST['first_name'], "last_name" => $_POST['last_name'], "p[" . $data_instance['args']['newsletter']['activecampaign']['list'] . "]" => $data_instance['args']['newsletter']['activecampaign']['list'], "status[" . $data_instance['args']['newsletter']['activecampaign']['list'] . "]" => 1));
                                         if ((int) $contact_sync->success) {
                                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'check', 'success_action' => $success_action, 'url' => $success_url, 'message' => $success_mesage, 'conversion' => apply_filters('nnr_news_int_submission_success_v1', array('data_id' => $_POST['data_id'], 'table_name' => $_POST['stats_table_name']))));
                                             die;
                                         } else {
                                             echo json_encode(array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => $contact_sync->error));
                                             die;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     do_action('nnr_news_int_after_submission_add_email_v1');
     echo json_encode(apply_filters('nnr_news_int_submission_add_email_v1', array('id' => $_POST['data_id'], 'status' => 'warning', 'message' => __('Unable to subscribe user. Newsletter not setup properly.', $_POST['text_domain']))));
     die;
     // this is required to terminate immediately and return a proper response
 }