protected function loadFullDetails()
 {
     $interface = new CS_REST_Clients($this->ClientID, $this->apiKey);
     $result = $interface->get_campaign();
     $response = $this->parseResult($result);
     $this->populateFrom($response);
 }
Exemplo n.º 2
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;
}
    //Get the appropriate wrapper to check
    //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)
Exemplo n.º 6
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;
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
0
<?php

require_once '../../csrest_clients.php';
$auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token');
$wrap = new CS_REST_Clients('Client ID', $auth);
$transfer_details = array('Credits' => 200, 'CanUseMyCreditsWhenTheyRunOut' => false);
$result = $wrap->transfer_credits($transfer_details);
echo "Result of POST /api/v3.1/clients/{id}/credits\n<br />";
if ($result->was_successful()) {
    echo "Transferred with response\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>';
}
<?php

require_once '../../csrest_clients.php';
$auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token');
$wrap = new CS_REST_Clients('Your client ID', $auth);
$result = $wrap->set_monthly_billing(array('Currency' => 'USD', 'ClientPays' => true, 'MarkupPercentage' => 100));
echo "Result of PUT /api/v3.1/clients/{id}/setmonthlybilling\n<br />";
if ($result->was_successful()) {
    echo "Updated with Code " . $result->http_status_code;
} else {
    echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>";
    var_dump($result->response);
    echo '</pre>';
}
Exemplo n.º 10
0
<?php

require_once '../../csrest_clients.php';
$wrap = new CS_REST_Clients('ClientID to get segments for', 'Your API Key');
$result = $wrap->get_segments();
echo "Result of /api/v3/clients/{id}/segments\n<br />";
if ($result->was_successful()) {
    echo "Got segments\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>';
Exemplo n.º 11
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 scheduled campaigns for', $auth);
$result = $wrap->get_scheduled();
echo "Result of /api/v3.1/clients/{id}/scheduled\n<br />";
if ($result->was_successful()) {
    echo "Got scheduled campaigns\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>';
Exemplo n.º 12
0
<?php

require_once '../../csrest_clients.php';
$auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token');
$wrap = new CS_REST_Clients('Your client ID', $auth);
$emails = array('*****@*****.**', '*****@*****.**');
$result = $wrap->suppress($emails);
echo "Result of PUT /api/v3.1/clients/{id}/suppress\n<br />";
if ($result->was_successful()) {
    echo "Updated with Code " . $result->http_status_code;
} else {
    echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>";
    var_dump($result->response);
    echo '</pre>';
}
 /**
  * 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();
 }
Exemplo n.º 14
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;
}
 /**
  * Retrieves all campaigns for this client
  *
  * @return ArrayList[CMCampaign]
  */
 public function Campaigns()
 {
     $interface = new CS_REST_Clients($this->ID, $this->apiKey);
     $result = $interface->get_campaigns();
     $response = $this->parseResult($result);
     $campaigns = new ArrayList();
     foreach ($response as $campaignData) {
         $campaigns->push(new CMCampaign($this->apiKey, $campaignData));
     }
     return $campaigns;
 }
<?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 the templates of', $auth);
$result = $wrap->get_templates();
echo "Result of /api/v3.1/clients/{id}/templates\n<br />";
if ($result->was_successful()) {
    echo "Got templates\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>';
Exemplo n.º 17
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);
 }
Exemplo n.º 18
0
<?php

require_once '../../csrest_clients.php';
$wrap = new CS_REST_Clients('ClientID to get drafts for', 'Your API Key');
$result = $wrap->get_drafts();
echo "Result of /api/v3/clients/{id}/drafts\n<br />";
if ($result->was_successful()) {
    echo "Got drafts\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>';
Exemplo n.º 19
0
<?php

require_once '../../csrest_clients.php';
$auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token');
$wrap = new CS_REST_Clients('Client ID to Delete', $auth);
$result = $wrap->delete();
echo "Result of DELETE /api/v3.1/clients/{id}\n<br />";
if ($result->was_successful()) {
    echo 'Deleted';
} else {
    echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>";
    var_dump($result->response);
    echo '</pre>';
}
Exemplo n.º 20
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
	}
<?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);
$email_address = '*****@*****.**';
$result = $wrap->get_lists_for_email($email_address);
echo "Result of /api/v3.1/clients/{id}/listsforemail\n<br />";
if ($result->was_successful()) {
    echo "Got lists to which email address " . $email_address . " is subscribed\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>';
Exemplo n.º 22
0
<?php

require_once '../../csrest_clients.php';
$wrap = new CS_REST_Clients('ClientID to get the suppression list of', 'Your API Key');
$result = $wrap->get_suppressionlist(1, 50, 'email', 'asc');
//$result = $wrap->get_suppressionlist(page number, page size, order by, order direction);
echo "Result of /api/v3/clients/{id}/suppressionlist\n<br />";
if ($result->was_successful()) {
    echo "Got suppression list\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>';
Exemplo n.º 23
0
<?php

require_once '../../csrest_clients.php';
$auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token');
$wrap = new CS_REST_Clients('Your client ID', $auth);
$result = $wrap->set_basics(array('CompanyName' => 'Clients company name', 'Country' => 'Clients country', 'Timezone' => 'Clients timezone'));
echo "Result of PUT /api/v3.1/clients/{id}/setbasics\n<br />";
if ($result->was_successful()) {
    echo "Updated with Code " . $result->http_status_code;
} else {
    echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>";
    var_dump($result->response);
    echo '</pre>';
}
Exemplo n.º 24
0
<?php

require_once '../../csrest_clients.php';
$auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token');
$wrap = new CS_REST_Clients(NULL, $auth);
$result = $wrap->create(array('CompanyName' => 'Clients company name', 'Country' => 'Clients country', 'Timezone' => 'Clients timezone'));
echo "Result of POST /api/v3.1/clients\n<br />";
if ($result->was_successful()) {
    echo "Created with ID\n<br />" . $result->response;
} else {
    echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>";
    var_dump($result->response);
    echo '</pre>';
}
Exemplo n.º 25
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 Campaigns for', $auth);
$result = $wrap->get_campaigns();
echo "Result of /api/v3.1/clients/{id}/campaigns\n<br />";
if ($result->was_successful()) {
    echo "Got campaigns\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>';
Exemplo n.º 26
0
<?php

require_once '../../csrest_clients.php';
$wrap = new CS_REST_Clients('Your clients ID', 'Your API Key');
$result = $wrap->set_basics(array('CompanyName' => 'Clients company name', 'ContactName' => 'Clients contact name', 'EmailAddress' => 'Clients email', 'Country' => 'Clients country', 'Timezone' => 'Clients timezone'));
echo "Result of PUT /api/v3/clients/{id}/setbasics\n<br />";
if ($result->was_successful()) {
    echo "Updated with Code " . $result->http_status_code;
} else {
    echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>";
    var_dump($result->response);
    echo '</pre>';
}
Exemplo n.º 27
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>';
Exemplo n.º 28
0
<?php

require_once '../../csrest_clients.php';
$auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token');
$wrap = new CS_REST_Clients('Your client ID', $auth);
$result = $wrap->unsuppress('Email address to unsuppress');
echo "Result of PUT /api/v3.1/clients/{id}/unsuppress\n<br />";
if ($result->was_successful()) {
    echo "Updated with Code " . $result->http_status_code;
} else {
    echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>";
    var_dump($result->response);
    echo '</pre>';
}
Exemplo n.º 29
0
<?php

require_once '../../csrest_clients.php';
$auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token');
$wrap = new CS_REST_Clients('Your client ID', $auth);
$result = $wrap->get();
echo "Result of GET /api/v3.1/clients/{id}\n<br />";
if ($result->was_successful()) {
    echo "Got client <pre>";
    var_dump($result->response);
} else {
    echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>";
    var_dump($result->response);
}
echo '</pre>';
<?php

require_once '../../csrest_clients.php';
$auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token');
$wrap = new CS_REST_Clients('Your client ID', $auth);
/*
 * Specific markup values can be set via the
 *
 * MarkupOnDelivery
 * MarkupPerRecipient
 * MarkupOnDesignSpamTest
 *
 * fields
 */
$result = $wrap->set_payg_billing(array('Currency' => 'USD', 'ClientPays' => true, 'MarkupPercentage' => 100, 'CanPurchaseCredits' => false));
echo "Result of PUT /api/v3.1/clients/{id}/setpaygbilling\n<br />";
if ($result->was_successful()) {
    echo "Updated with Code " . $result->http_status_code;
} else {
    echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>";
    var_dump($result->response);
    echo '</pre>';
}