public function view() { //Page options $this->setPageType('table'); $this->setTitle(__('%1$s – %2$s', array(__('Symphony'), __('Campaign Monitor Subscribers')))); $this->appendSubheading(__('Campaign Monitor Subscribers')); //Form action $this->Form->setAttribute('action', $this->_Parent->getCurrentPageURL()); //Get Campaign Monitor preferences $api_key = $this->_Parent->Configuration->get('api_key', 'campaign_monitor'); $list_id = $this->_Parent->Configuration->get('list_id', 'campaign_monitor'); //New Campaign Monitor instance $cm = new CampaignMonitor($api_key); //Get subscriber list $result = $cm->subscribersGetActive(0, $list_id); $subscribers = $result['anyType']['Subscriber']; //Subscriber table headers $aTableHead = array(array(__('Name'), 'col'), array(__('Email Address'), 'col'), array(__('Date Subscribed'), 'col'), array(__('Status'), 'col')); $aTableBody = array(); if (!is_array($subscribers) || empty($subscribers)) { $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('You currently have no subscribers.'), 'inactive', NULL, count($aTableHead))), 'odd')); } else { if (is_array($subscribers[0])) { //Check if the subscriber list is longer than one, in which case it's an array of arrays foreach ($subscribers as $subscriber) { $td1 = Widget::TableData($subscriber["Name"]); $td2 = Widget::TableData($subscriber["EmailAddress"]); $td2->appendChild(Widget::Input('items[' . $subscriber["EmailAddress"] . ']', 'on', 'checkbox')); $td3 = Widget::TableData(date("d F Y H:i", strtotime($subscriber["Date"]))); $td4 = Widget::TableData($subscriber["State"]); //Add table data to row and body $aTableBody[] = Widget::TableRow(array($td1, $td2, $td3, $td4)); } } else { //Single subscriber $td1 = Widget::TableData($subscribers["Name"]); $td2 = Widget::TableData($subscribers["EmailAddress"]); $td2->appendChild(Widget::Input('items[' . $subscribers["EmailAddress"] . ']', 'on', 'checkbox')); $td3 = Widget::TableData(date("d F Y H:i", strtotime($subscribers["Date"]))); $td4 = Widget::TableData($subscribers["State"]); //Add table data to row and body $aTableBody[] = Widget::TableRow(array($td1, $td2, $td3, $td4)); } } $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody), 'orderable'); //Append the subscriber table to the page $this->Form->appendChild($table); //Actions for this page $tableActions = new XMLElement('div'); $tableActions->setAttribute('class', 'actions'); $options = array(array(NULL, false, __('With Selected...')), array('unsubscribe', false, __('Unsubscribe'))); $tableActions->appendChild(Widget::Select('with-selected', $options)); $tableActions->appendChild(Widget::Input('action[apply]', __('Apply'), 'submit')); //Append actions to the page $this->Form->appendChild($tableActions); }
/** * Get subscribed users to a list * * @param string $listid * @return void * @author Dan Chadwick */ public function get_list($listid = null) { $listid = $listid == null ? $this->list_id : $listid; $cm = new CampaignMonitor($this->api_key); // Optional statement to include debugging information in the result $cm->debug_level = 1; // This is the actual call to the method $result = $cm->subscribersGetActive(0, $listid); return $result; }
<?php //Sample using the CMBase.php wrapper to call Subscribers.GetActive from any version of PHP //Relative path to CMBase.php. This example assumes the file is in the same folder require_once 'CMBase.php'; //Your API Key. Go to http://www.campaignmonitor.com/api/required/ to see where to find this and other required keys $api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $client_id = null; $campaign_id = null; $list_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $date = '2000-01-01'; // Subscribers added after this date will be returned. Use the format YYYY-MM-DD HH:MM:SS $cm = new CampaignMonitor($api_key, $client_id, $campaign_id, $list_id); //Optional statement to include debugging information in the result //$cm->debug_level = 1; $result = $cm->subscribersGetActive($date, $list_id); if ($result['anyType']['Code'] == 0) { echo 'Success'; print_r($result); } else { echo 'Error : ' . $result['anyType']['Message']; } //Print out the debugging info //print_r($cm);