예제 #1
0
 public function get_lists()
 {
     $client_id = get_option('campaignmonitor_client_id');
     $auth = array('api_key' => $this->api_key);
     $wrap = new CS_REST_Clients($client_id, $auth);
     $result = $wrap->get_lists();
     $list_name = $result->response;
     return $list_name;
 }
 /**
  * Retrieves the lists via Campaign Monitor API and updates the data in DB.
  * @return string
  */
 function get_campaign_monitor_lists($api_key, $name)
 {
     require_once RAD_RAPIDOLOGY_PLUGIN_DIR . 'subscription/createsend-php-4.0.2/csrest_clients.php';
     require_once RAD_RAPIDOLOGY_PLUGIN_DIR . 'subscription/createsend-php-4.0.2/csrest_lists.php';
     $auth = array('api_key' => $api_key);
     $request_url = esc_url_raw('https://api.createsend.com/api/v3.1/clients.json?pretty=true');
     $all_clients_id = array();
     $all_lists = array();
     if (!function_exists('curl_init')) {
         return __('curl_init is not defined ', 'rapidology');
     }
     // Get cURL resource
     $curl = curl_init();
     // Set some options
     curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $request_url, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_USERPWD => $api_key . ':x'));
     // Send the request & save response to $resp
     $resp = curl_exec($curl);
     $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     // Close request to clear up some resources
     curl_close($curl);
     $clients_array = json_decode($resp, true);
     if ('200' == $httpCode) {
         $error_message = 'success';
         foreach ($clients_array as $client => $client_details) {
             $all_clients_id[] = $client_details['ClientID'];
         }
         if (!empty($all_clients_id)) {
             foreach ($all_clients_id as $client) {
                 $wrap = new CS_REST_Clients($client, $auth);
                 $lists_data = $wrap->get_lists();
                 foreach ($lists_data->response as $list => $single_list) {
                     $all_lists[$single_list->ListID]['name'] = $single_list->Name;
                     $wrap_stats = new CS_REST_Lists($single_list->ListID, $auth);
                     $result_stats = $wrap_stats->get_stats();
                     $all_lists[$single_list->ListID]['subscribers_count'] = sanitize_text_field($result_stats->response->TotalActiveSubscribers);
                     $all_lists[$single_list->ListID]['growth_week'] = sanitize_text_field($this->calculate_growth_rate('campaign_monitor_' . $single_list->ListID));
                 }
             }
         }
         $this->update_account('campaign_monitor', sanitize_text_field($name), array('api_key' => sanitize_text_field($api_key), 'lists' => $all_lists, 'is_authorized' => 'true'));
     } else {
         if ('401' == $httpCode) {
             $error_message = __('invalid API key', 'rapidology');
         } else {
             $error_message = $httpCode;
         }
     }
     return $error_message;
 }
/**
 *  Get List from CampaignMonitor
 */
function cspv4_get_campaignmonitor_lists($apikey = null)
{
    global $seed_cspv4;
    extract($seed_cspv4);
    $o = $seed_cspv4;
    $lists = array();
    if ($o['emaillist'] == 'campaignmonitor' || defined('DOING_AJAX') && DOING_AJAX && isset($_GET['action']) && $_GET['action'] == 'seed_cspv4_refresh_list') {
        $lists = maybe_unserialize(get_transient('seed_cspv4_campaignmonitor_lists'));
        if (empty($lists)) {
            if (class_exists('CS_REST_Clients')) {
                //trigger_error("Duplicate: Another Campaign Moniter client library is already in scope.", E_USER_WARNING);
            } else {
                require_once SEED_CSPV4_PLUGIN_PATH . 'extentions/campaignmonitor/campaign_monitor/csrest_clients.php';
            }
            if (!isset($apikey) && isset($campaignmonitor_api_key)) {
                $apikey = $campaignmonitor_api_key;
            }
            if (!isset($clientid) && isset($campaignmonitor_clientid)) {
                $clientid = $campaignmonitor_clientid;
            }
            if (empty($apikey) || empty($clientid)) {
                return array();
            }
            $api = new CS_REST_Clients($clientid, $apikey);
            $response = $api->get_lists();
            if ($response->was_successful()) {
                foreach ($response->response as $k => $v) {
                    $lists[$v->ListID] = $v->Name;
                }
                if (!empty($lists)) {
                    set_transient('seed_cspv4_campaignmonitor_lists', serialize($lists), 86400);
                }
            } else {
                $lists['false'] = __("Unable to load Campaign Monitor lists", 'seedprod');
            }
        }
    }
    return $lists;
}
예제 #4
0
 public static function get_lists($client_id, $list_id = "")
 {
     self::include_api();
     $api = new CS_REST_Clients($client_id, self::get_api_key());
     //getting list of all Campaign Monitor merge variables for the selected contact list
     $response = $api->get_lists();
     //$lists = $lists["anyType"]["List"];
     //if(!empty($lists["ListID"]))
     //    $lists = array($lists);
     $str = "<option value=''>" . __("Select a List", "gravityformscampaignmonitor") . "</option>";
     if (!$response->was_successful()) {
         return $str;
     }
     $lists = $response->response;
     if (is_array($lists)) {
         foreach ($lists as $list) {
             $selected = $list->ListID == $list_id ? "selected='selected'" : "";
             $str .= "<option value='" . esc_attr($list->ListID) . "|:|" . esc_attr($list->Name) . "' " . $selected . " >" . esc_html($list->Name) . "</option>";
         }
     }
     return $str;
 }
예제 #5
0
 /**
  * Retrieval method for getting lists.
  *
  * @since 2.0.0
  *
  * @param array  $args    Args to be passed for list retrieval.
  * @param string $list_id The list ID to check for selection.
  * @param string $uniqid  The account ID to target.
  * @param string $optin_id The current optin ID
  *
  * @return  string|WP_Error Output of the email lists or WP_Error.
  */
 public function get_lists($args = array(), $list_id = '', $uniqid = '', $optin_id = '')
 {
     if (!$this->api) {
         if (isset($args['access']) && isset($args['refresh']) && isset($args['expires'])) {
             $this->api['access'] = $args['access'];
             $this->api['refresh'] = $args['refresh'];
             $this->api['expires'] = $args['expires'];
         }
         if (isset($args['client'])) {
             $this->api['client'] = $args['client'];
         }
     }
     // If needed, get a new access token.
     if (isset($this->api['expires']) && isset($this->api['refresh']) && time() > $this->api['expires']) {
         $this->api['access'] = $this->refresh_access_token($uniqid, $this->api['refresh']);
     }
     // Possibly get data via OAuth or API key for backwards compat.
     if (isset($this->api['access']) && isset($this->api['refresh'])) {
         $auth = array('access_token' => $this->api['access'], 'refresh_token' => $this->api['refresh']);
     } else {
         if (isset($args['api'])) {
             $auth = array('api_key' => $args['api']);
         } else {
             $auth = array();
         }
     }
     $api = new CS_REST_Clients($this->api['client'], $auth);
     $lists = $api->get_lists();
     return $this->build_list_html($lists, $list_id, $optin_id);
 }
예제 #6
0
	/**
	 * Update all Campaign Monitor Lists and display in settings
	 *
	 */
	public function update_campaignmonitor_lists() {

		$lists = '';

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

			require_once( 'includes/campaignmonitor/csrest_general.php');
			require_once( 'includes/campaignmonitor/csrest_clients.php');


			$wrap = new CS_REST_Clients(sanitize_text_field( $_POST['client_id'] ), sanitize_text_field( $_POST['api_key'] ));
			$result = $wrap->get_lists();


			if ($result->was_successful()) {
				foreach ($result->response as $list) {
					$lists .= '<option value="' . $list->ListID . '">' .  $list->Name . '</option>';
				}
			}
		}

		echo $lists;

		die(); // this is required to terminate immediately and return a proper response
	}
 /**
  * Render markup for the list field. 
  *
  * @since 1.5.4
  * @param array $account_data Saved account data.
  * @param object $settings Saved module settings.
  * @return string The markup for the list field.
  * @access private
  */
 private function render_list_field($account_data, $settings)
 {
     $post_data = FLBuilderModel::get_post_data();
     // Get the client ID. Return an empty string if we don't have one yet.
     if (isset($post_data['client'])) {
         $client_id = $post_data['client'];
     } else {
         if (isset($settings->client_id)) {
             $client_id = $settings->client_id;
         } else {
             return '';
         }
     }
     // Get the list data.
     $api = new CS_REST_Clients($client_id, $account_data);
     $lists = $api->get_lists();
     // Render the list field.
     ob_start();
     $options = array('' => __('Choose...', 'fl-builder'));
     foreach ($lists->response as $list) {
         $options[$list->ListID] = $list->Name;
     }
     FLBuilder::render_settings_field('list_id', array('row_class' => 'fl-builder-service-field-row', 'class' => 'fl-builder-service-list-select', 'type' => 'select', 'label' => _x('List', 'An email list from a third party provider.', 'fl-builder'), 'options' => $options, 'preview' => array('type' => 'none')), $settings);
     return ob_get_clean();
 }
 /**
  * Retrieves all lists for this client
  * 
  * @return ArrayList[CMList]
  */
 public function Lists()
 {
     $interface = new CS_REST_Clients($this->ID, $this->apiKey);
     $result = $interface->get_lists();
     $response = $this->parseResult($result);
     $lists = new ArrayList();
     foreach ($response as $listData) {
         $lists->push(new CMList($this->apiKey, $listData));
     }
     return $lists;
 }
 /**
  * Define the markup for the contact_list type field.
  *
  * @param array $field The field properties.
  * @param bool|true $echo Should the setting markup be echoed.
  *
  * @return string|void
  */
 public function settings_contact_list($field, $echo = true)
 {
     $client_id = $this->get_setting('client');
     if (empty($client_id)) {
         $clients = $this->get_clients();
         if (!empty($clients)) {
             $client_id = $clients[0]->ClientID;
         }
     }
     if (!empty($client_id)) {
         $this->include_api();
         $api = new CS_REST_Clients($client_id, $this->get_key());
         $response = $api->get_lists();
         if (!$response->was_successful()) {
             return;
         }
         $lists[] = array('label' => 'Select List', 'value' => '');
         $retrieved_lists = $response->response;
         foreach ($retrieved_lists as $list) {
             $lists[] = array('label' => $list->Name, 'value' => $list->ListID);
         }
         $field['type'] = 'select';
         $field['choices'] = $lists;
         $html = $this->settings_select($field, false);
     } else {
         $html = '<div class="gfield_error" style="width:49%">' . sprintf(esc_html__('No clients found. Please configure one or more clients in your %sCampaign Monitor%s account.', 'gravityformscampaignmonitor'), '<a href="http://www.campaignmonitor.com" target="_blank">', '</a>') . '</div>';
     }
     if ($echo) {
         echo $html;
     }
     return $html;
 }
    //if there is the given CLIENT_ID
    $wrap_general = new CS_REST_General($auth);
    $clients = $wrap_general->get_clients();
    foreach ($clients->response as $client) {
        if (CLIENT_ID == $client->ClientID) {
            $client_id = CLIENT_ID;
            break;
        } else {
            echo "There is not such a client id!";
        }
    }
    //If client found
    if (isset($client_id)) {
        //Get the appropriate wrapper to get the available client's Lists
        $wrap_client = new CS_REST_Clients($client_id, $auth);
        $lists = $wrap_client->get_lists();
        //JSON manipiulation of the response
        $output = "[";
        foreach ($lists->response as $list) {
            $output .= "{\"ListID\": \"{$list->ListID}\", ";
            $output .= "\"Name\": \"{$list->Name}\"";
            $output .= "},";
        }
        //subs the last comma
        $output = substr($output, 0, -1);
        $output .= "]";
        echo $output;
    }
} elseif ($req == "list" && isset($_GET["list_id"])) {
    //View active subscribers from a list(list_id)
    $list_id = $_GET["list_id"];
예제 #11
0
 public function getLists()
 {
     if (empty($this->cmListIds)) {
         require_once 'lib/csrest_clients.php';
         $wrap = new CS_REST_Clients($this->getConfig('client_api_id'), array('api_key' => $this->getConfig('api_key')));
         $result = $wrap->get_lists();
         if (!$result->was_successful()) {
             throw new Am_Exception_InputError("Bad API Key or Client API Id");
         }
         foreach ($result->response as $r) {
             $this->cmListIds[$r->ListID] = array('title' => $r->Name);
         }
     }
     return $this->cmListIds;
 }
예제 #12
0
 function getLists()
 {
     $filename = 'subscriber_lists.json';
     $this->loadWrapperClass('csrest_clients');
     $list = array();
     // Check for fresh cached results
     if ($this->cacheNotExpired($filename) && $this->_force_flush === 'false') {
         $list = $this->getCached($filename);
     }
     // Uncached Results
     if (empty($list) || $this->_force_flush === 'true') {
         $list = array();
         $wrap = new CS_REST_Clients($this->_client_id, $this->_api_key);
         $result = $wrap->get_lists();
         foreach ($result->response as $item) {
             array_push($list, $this->objectToArray($item));
         }
         FB::log($list);
         $this->setCached($filename, $list);
         $this->setCacheExpiry($filename);
     }
     $this->resultCount = count($list);
     return $list;
 }
예제 #13
0
 /**
  * Update all Campaign Monitor Lists and display in settings
  *
  * @access public
  * @return void
  */
 function nnr_new_int_update_campaignmonitor_lists_v1()
 {
     do_action('nnr_news_int_before_update_campaignmonitor_lists_v1');
     $lists = '';
     if (isset($_POST['api_key']) && $_POST['api_key'] != '' && isset($_POST['client_id']) && $_POST['client_id'] != '') {
         require_once dirname(dirname(__FILE__)) . '/services/campaignmonitor/csrest_general.php';
         require_once dirname(dirname(__FILE__)) . '/services/campaignmonitor/csrest_clients.php';
         $wrap = new CS_REST_Clients($_POST['client_id'], $_POST['api_key']);
         $result = $wrap->get_lists();
         if ($result->was_successful()) {
             foreach ($result->response as $list) {
                 $lists .= '<option value="' . $list->ListID . '">' . $list->Name . '</option>';
             }
         }
     }
     do_action('nnr_news_int_after_update_campaignmonitor_lists_v1');
     echo apply_filters('nnr_news_int_update_campaignmonitor_lists_v1', $lists);
     die;
     // this is required to terminate immediately and return a proper response
 }
예제 #14
0
<?php

require_once '../../csrest_clients.php';
$auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token');
$wrap = new CS_REST_Clients('ClientID to get Lists for', $auth);
$result = $wrap->get_lists();
echo "Result of /api/v3.1/clients/{id}/lists\n<br />";
if ($result->was_successful()) {
    echo "Got lists\n<br /><pre>";
    var_dump($result->response);
} else {
    echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>";
    var_dump($result->response);
}
echo '</pre>';
예제 #15
0
function snp_ml_get_cm_lists($ml_cm_clientid = '', $ml_cm_apikey = '')
{
    require_once SNP_DIR_PATH . '/include/campaignmonitor/csrest_clients.php';
    $list = array();
    if (snp_get_option('ml_cm_clientid') && snp_get_option('ml_cm_apikey') || $ml_cm_clientid && $ml_cm_apikey) {
        if ($ml_cm_clientid && $ml_cm_apikey) {
            $wrap = new CS_REST_Clients($ml_cm_clientid, $ml_cm_apikey);
        } else {
            $wrap = new CS_REST_Clients(snp_get_option('ml_cm_clientid'), snp_get_option('ml_cm_apikey'));
        }
        $res = $wrap->get_lists();
        if ($res->was_successful()) {
            foreach ((array) $res->response as $v) {
                $list[$v->ListID] = array('name' => $v->Name);
            }
        } else {
            // Error
            //echo 'Failed with code ' . $res->http_status_code . "\n<br /><pre>";
            //var_dump($res->response);
        }
    }
    if (count($list) == 0) {
        $list[0] = array('name' => 'Nothing Found...');
    }
    return $list;
}
예제 #16
0
 /**
  * Processes campaignmonitor list field. Called by AJAX script.
  */
 public static function field_campaignmonitor_list_ajax()
 {
     if (!class_exists(CS_REST_Clients)) {
         require CH_Manager::$plugin_dir . 'lib/campaign_monitor/csrest_clients.php';
     }
     $api_key = $_POST['apikey'];
     $client_id = $_POST['client'];
     $cmapi = new CS_REST_Clients($client_id, $api_key);
     $lists = $cmapi->get_lists();
     if (!$lists->was_successful()) {
         die;
     }
     $value = '';
     if (!empty($_POST['value'])) {
         $value = $_POST['value'];
     }
     $output = '';
     $lists = $lists->response;
     if (is_array($lists)) {
         foreach ($lists as $list) {
             $selected = '';
             if ($list->ListID == $value) {
                 $selected = ' selected="selected"';
             }
             $output .= '<option value="' . esc_attr($list->ListID) . '"' . $selected . '>' . esc_html(trim($list->Name)) . ' </option>';
         }
     }
     echo $output;
     die;
 }
 /**
  * @return ArrayList
  */
 public function getLists()
 {
     require_once '../vendor/campaignmonitor/createsend-php/csrest_clients.php';
     $auth = array('api_key' => $this->config()->get('api_key'));
     $wrap = new CS_REST_Clients($this->config()->get('client_id'), $auth);
     $result = $wrap->get_lists();
     $cLists = array();
     if ($result->was_successful()) {
         foreach ($result->response as $list) {
             $cLists[] = new ArrayData(array("ListID" => $list->ListID, "Name" => $list->Name));
         }
     }
     $this->extend('updateLists', $cLists);
     return new ArrayList($cLists);
 }