/**
	 * 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
	}
<?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;
}
Exemple #3
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;
     }
 }
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;
}
 /**
  * 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
 }