Version Description
Download this release
Release Info
Developer | mc_jesse |
Plugin | MailChimp List Subscribe Form |
Version | 0.5 |
Comparing to | |
See all releases |
Code changes from version 0.4 to 0.5
- MCAPI.class.php +428 -100
- mailchimp.php +1 -1
- readme.txt +1 -1
MCAPI.class.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
|
3 |
class MCAPI {
|
4 |
-
var $version = "1.
|
5 |
var $errorMessage;
|
6 |
var $errorCode;
|
7 |
|
@@ -21,9 +21,9 @@ class MCAPI {
|
|
21 |
var $chunkSize = 8192;
|
22 |
|
23 |
/**
|
24 |
-
* Cache the user
|
25 |
*/
|
26 |
-
var $
|
27 |
|
28 |
/**
|
29 |
* Connect to the MailChimp API for a given list. All MCAPI calls require login before functioning
|
@@ -32,8 +32,14 @@ class MCAPI {
|
|
32 |
* @param string $password Your MailChimp login password - always required
|
33 |
*/
|
34 |
function MCAPI($username, $password) {
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
}
|
38 |
|
39 |
/**
|
@@ -42,7 +48,7 @@ class MCAPI {
|
|
42 |
* @section Campaign Related
|
43 |
* @example xml-rpc_campaignUnschedule.php
|
44 |
*
|
45 |
-
* @param string $cid the id
|
46 |
* @return boolean true on success
|
47 |
*/
|
48 |
function campaignUnschedule($cid) {
|
@@ -57,24 +63,53 @@ class MCAPI {
|
|
57 |
* @section Campaign Related
|
58 |
* @example xml-rpc_campaignSchedule.php
|
59 |
*
|
60 |
-
* @param string $cid the id
|
61 |
-
* @param string $schedule_time the time to schedule the campaign - in YYYY-MM-DD HH:II:SS format in GMT
|
|
|
62 |
* @return boolean true on success
|
63 |
*/
|
64 |
-
function campaignSchedule($cid, $schedule_time) {
|
65 |
$params = array();
|
66 |
$params["cid"] = $cid;
|
67 |
$params["schedule_time"] = $schedule_time;
|
|
|
68 |
return $this->callServer("campaignSchedule", $params);
|
69 |
}
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
/**
|
72 |
* Send a given campaign immediately
|
73 |
*
|
74 |
* @section Campaign Related
|
75 |
-
* @example xml-rpc_campaignSend.php
|
76 |
*
|
77 |
-
* @param string $cid the id
|
78 |
* @return boolean true on success
|
79 |
*/
|
80 |
function campaignSendNow($cid) {
|
@@ -89,9 +124,9 @@ class MCAPI {
|
|
89 |
* @section Campaign Related
|
90 |
* @example xml-rpc_campaignSendTest.php
|
91 |
*
|
92 |
-
* @param string $cid the id
|
93 |
-
* @param
|
94 |
-
* @param string $send_type optional default (null)
|
95 |
* @return boolean true on success
|
96 |
*/
|
97 |
function campaignSendTest($cid, $test_emails=array (
|
@@ -120,49 +155,134 @@ class MCAPI {
|
|
120 |
return $this->callServer("campaignTemplates", $params);
|
121 |
}
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
/**
|
124 |
* Create a new draft campaign to send
|
125 |
*
|
126 |
* @section Campaign Related
|
127 |
-
* @example
|
128 |
-
*
|
129 |
-
* @
|
130 |
-
* @
|
131 |
-
*
|
132 |
-
* @param string $
|
133 |
-
* @param array $
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
* @return string the ID for the created campaign
|
140 |
*/
|
141 |
-
function campaignCreate($
|
142 |
-
'opens' => true,
|
143 |
-
'html_clicks' => true,
|
144 |
-
'text_clicks' => false,
|
145 |
-
), $title=NULL, $authenticate=false, $analytics=NULL) {
|
146 |
$params = array();
|
147 |
-
$params["
|
148 |
-
$params["
|
149 |
-
$params["from_email"] = $from_email;
|
150 |
-
$params["from_name"] = $from_name;
|
151 |
$params["content"] = $content;
|
152 |
-
$params["
|
153 |
-
$params["
|
154 |
-
$params["title"] = $title;
|
155 |
-
$params["authenticate"] = $authenticate;
|
156 |
-
$params["analytics"] = $analytics;
|
157 |
return $this->callServer("campaignCreate", $params);
|
158 |
}
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
/**
|
161 |
-
* Get the list of campaigns and
|
162 |
*
|
163 |
* @section Campaign Related
|
|
|
164 |
*
|
165 |
-
* @param string $filter_id optional - only show campaigns from this list id - get lists using
|
166 |
* @param integer $filter_folder optional - only show campaigns from this folder id - get folders using campaignFolders()
|
167 |
* @param string $filter_fromname optional - only show campaigns that have this "From Name"
|
168 |
* @param string $filter_fromemail optional - only show campaigns that have this "Reply-to Email"
|
@@ -171,20 +291,22 @@ class MCAPI {
|
|
171 |
* @param string $filter_sendtimestart optional - only show campaigns that have been sent since this date/time
|
172 |
* @param string $filter_sendtimeend optional - only show campaigns that have been sent before this date/time
|
173 |
* @param boolean $filter_exact optional - flag for whether to filter on exact values when filtering, or search within content for filter values
|
174 |
-
* @param integer $start optional - control paging of campaigns, start results at this campaign #, defaults to
|
175 |
* @param integer $limit optional - control paging of campaigns, number of campaigns to return with each call, defaults to 25 (max=5000)
|
176 |
* @return array list of campaigns and their associated information (see Returned Fields for description)
|
177 |
* @returnf string id Campaign Id (used for all other campaign functions)
|
178 |
* @returnf string title Title of the campaign
|
|
|
179 |
* @returnf date create_time Creation time for the campaign
|
180 |
* @returnf date send_time Send time for the campaign
|
181 |
-
* @returnf
|
182 |
* @returnf string status Status of the given campaign (sent,scheduled,etc.)
|
183 |
* @returnf string from_name From name of the given campaign
|
184 |
* @returnf string from_email Reply-to email of the given campaign
|
185 |
* @returnf string subject Subject of the given campaign
|
186 |
-
* @returnf string to_email To email string
|
187 |
* @returnf string archive_url Archive link for the given campaign
|
|
|
188 |
*/
|
189 |
function campaigns($filter_id=NULL, $filter_folder=NULL, $filter_fromname=NULL, $filter_fromemail=NULL, $filter_title=NULL, $filter_subject=NULL, $filter_sendtimestart=NULL, $filter_sendtimeend=NULL, $filter_exact=true, $start=0, $limit=25) {
|
190 |
$params = array();
|
@@ -206,6 +328,7 @@ class MCAPI {
|
|
206 |
* List all the folders for a user account
|
207 |
*
|
208 |
* @section Campaign Related
|
|
|
209 |
*
|
210 |
* @return array Array of folder structs (see Returned Fields for details)
|
211 |
* @returnf integer folder_id Folder Id for the given folder, this can be used in the campaigns() function to filter on.
|
@@ -220,8 +343,9 @@ class MCAPI {
|
|
220 |
* Given a list and a campaign, get all the relevant campaign statistics (opens, bounces, clicks, etc.)
|
221 |
*
|
222 |
* @section Campaign Stats
|
|
|
223 |
*
|
224 |
-
* @param string $cid the campaign id to pull stats for (can be gathered using campaigns(
|
225 |
* @return array struct of the statistics for this campaign
|
226 |
* @returnf integer syntax_errors Number of email addresses in campaign that had syntactical errors.
|
227 |
* @returnf integer hard_bounces Number of email addresses in campaign that hard bounced.
|
@@ -250,7 +374,7 @@ class MCAPI {
|
|
250 |
*
|
251 |
* @section Campaign Stats
|
252 |
*
|
253 |
-
* @param string $cid the campaign id to pull stats for (can be gathered using campaigns(
|
254 |
* @return struct list of urls and their associated statistics
|
255 |
* @returnf integer clicks Number of times the specific link was clicked
|
256 |
* @returnf integer unique Number of unique people who clicked on the specific link
|
@@ -261,33 +385,14 @@ class MCAPI {
|
|
261 |
return $this->callServer("campaignClickStats", $params);
|
262 |
}
|
263 |
|
264 |
-
/**
|
265 |
-
* Get all bounced email addresses for a given campaign<br/>
|
266 |
-
* <strong>DEPRECATED:</strong> campaignBounces() has been deprecated and will be removed completely in a future release. see campaignHardBounces() and campaignSoftBounces() for replacements.
|
267 |
-
*
|
268 |
-
* @section Campaign Stats
|
269 |
-
*
|
270 |
-
* @deprecated See campaignHardBounces() and campaignSoftBounces() for replacements
|
271 |
-
* @param string $cid the campaign id to pull bounces for (can be gathered using campaigns($id))
|
272 |
-
* @return struct Struct of arrays of bounced email addresses (hard and soft)
|
273 |
-
* @returnf array hard Array of all email addresses that had Hard bounces for this campaign
|
274 |
-
* @returnf array soft Array of all email addresses that had Soft bounces for this campaign
|
275 |
-
* @returnf array syntax Array of all email addresses that had syntax errors in them (historical - always empty)
|
276 |
-
*/
|
277 |
-
function campaignBounces($cid) {
|
278 |
-
$params = array();
|
279 |
-
$params["cid"] = $cid;
|
280 |
-
return $this->callServer("campaignBounces", $params);
|
281 |
-
}
|
282 |
-
|
283 |
/**
|
284 |
* Get all email addresses with Hard Bounces for a given campaign
|
285 |
*
|
286 |
* @section Campaign Stats
|
287 |
*
|
288 |
-
* @param string $cid the campaign id to pull bounces for (can be gathered using campaigns(
|
289 |
-
* @param
|
290 |
-
* @param
|
291 |
* @return array Arrays of email addresses with Hard Bounces
|
292 |
*/
|
293 |
function campaignHardBounces($cid, $start=0, $limit=1000) {
|
@@ -303,9 +408,9 @@ class MCAPI {
|
|
303 |
*
|
304 |
* @section Campaign Stats
|
305 |
*
|
306 |
-
* @param string $cid the campaign id to pull bounces for (can be gathered using campaigns(
|
307 |
-
* @param
|
308 |
-
* @param
|
309 |
* @return array Arrays of email addresses with Soft Bounces
|
310 |
*/
|
311 |
function campaignSoftBounces($cid, $start=0, $limit=1000) {
|
@@ -321,9 +426,9 @@ class MCAPI {
|
|
321 |
*
|
322 |
* @section Campaign Stats
|
323 |
*
|
324 |
-
* @param string $cid the campaign id to pull bounces for (can be gathered using campaigns(
|
325 |
-
* @param
|
326 |
-
* @param
|
327 |
* @return array list of email addresses that unsubscribed from this campaign
|
328 |
*/
|
329 |
function campaignUnsubscribes($cid, $start=0, $limit=1000) {
|
@@ -339,9 +444,9 @@ class MCAPI {
|
|
339 |
*
|
340 |
* @section Campaign Stats
|
341 |
*
|
342 |
-
* @param string $cid the campaign id to pull bounces for (can be gathered using campaigns(
|
343 |
-
* @param
|
344 |
-
* @param
|
345 |
* @return array list of email addresses that complained (filed abuse reports) about this campaign
|
346 |
*/
|
347 |
function campaignAbuseReports($cid, $start=0, $limit=1000) {
|
@@ -357,7 +462,7 @@ class MCAPI {
|
|
357 |
*
|
358 |
* @section Campaign Related
|
359 |
*
|
360 |
-
* @param string $cid the campaign id to get content for (can be gathered using campaigns(
|
361 |
* @return struct Struct containing all content for the campaign (see Returned Fields for details
|
362 |
* @returnf string html The HTML content used for the campgain with merge tags intact
|
363 |
* @returnf string text The Text content used for the campgain with merge tags intact
|
@@ -373,9 +478,9 @@ class MCAPI {
|
|
373 |
*
|
374 |
* @section Campaign AIM
|
375 |
*
|
376 |
-
* @param string $cid the campaign id to get opens for (can be gathered using campaigns(
|
377 |
-
* @param
|
378 |
-
* @param
|
379 |
* @return array Array of structs containing email addresses and open counts
|
380 |
* @returnf string email Email address that opened the campaign
|
381 |
* @returnf integer open_count Total number of times the campaign was opened by this email address
|
@@ -393,9 +498,9 @@ class MCAPI {
|
|
393 |
*
|
394 |
* @section Campaign AIM
|
395 |
*
|
396 |
-
* @param string $cid the campaign id to get no opens for (can be gathered using campaigns(
|
397 |
-
* @param
|
398 |
-
* @param
|
399 |
* @return array list of email addresses that did not open a campaign
|
400 |
*/
|
401 |
function campaignNotOpenedAIM($cid, $start=0, $limit=1000) {
|
@@ -411,10 +516,10 @@ class MCAPI {
|
|
411 |
*
|
412 |
* @section Campaign AIM
|
413 |
*
|
414 |
-
* @param string $cid the campaign id to get click stats for (can be gathered using campaigns(
|
415 |
* @param string $url the URL of the link that was clicked on
|
416 |
-
* @param
|
417 |
-
* @param
|
418 |
* @return array Array of structs containing email addresses and click counts
|
419 |
* @returnf string email Email address that opened the campaign
|
420 |
* @returnf integer clicks Total number of times the URL was clicked on by this email address
|
@@ -433,7 +538,7 @@ class MCAPI {
|
|
433 |
*
|
434 |
* @section Campaign AIM
|
435 |
*
|
436 |
-
* @param string $cid the campaign id to get stats for (can be gathered using campaigns(
|
437 |
* @param string $email_address the email address to get activity history for
|
438 |
* @return array Array of structs containing actions (opens and clicks) that the email took, with timestamps
|
439 |
* @returnf string action The action taken (open or click)
|
@@ -468,6 +573,7 @@ class MCAPI {
|
|
468 |
* Get the list of merge tags for a given list, including their name, tag, and required setting
|
469 |
*
|
470 |
* @section List Related
|
|
|
471 |
*
|
472 |
* @param string $id the list id to connect to
|
473 |
* @return array list of merge tags for the list
|
@@ -481,10 +587,50 @@ class MCAPI {
|
|
481 |
return $this->callServer("listMergeVars", $params);
|
482 |
}
|
483 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
484 |
/**
|
485 |
* Get the list of interest groups for a given list, including the label and form information
|
486 |
*
|
487 |
* @section List Related
|
|
|
488 |
*
|
489 |
* @param string $id the list id to connect to
|
490 |
* @return struct list of interest groups for the list
|
@@ -498,6 +644,38 @@ class MCAPI {
|
|
498 |
return $this->callServer("listInterestGroups", $params);
|
499 |
}
|
500 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
501 |
/**
|
502 |
* Subscribe the provided email to a list
|
503 |
*
|
@@ -508,9 +686,11 @@ class MCAPI {
|
|
508 |
*
|
509 |
* @param string $id the list id to connect to
|
510 |
* @param string $email_address the email address to subscribe
|
511 |
-
* @param array $merge_vars array of merges for the email (FNAME, LNAME, etc.) (see examples below for handling "blank" arrays)
|
|
|
|
|
512 |
* @param string $email_type optional - email type preference for the email (html or text, defaults to html)
|
513 |
-
* @param boolean $double_optin optional - flag to control whether a double opt-in confirmation message is sent, defaults to true
|
514 |
* @return boolean true on success, false on failure. When using MCAPI.class.php, the value can be tested and error messages pulled from the MCAPI object (see below)
|
515 |
*/
|
516 |
function listSubscribe($id, $email_address, $merge_vars, $email_type='html', $double_optin=true) {
|
@@ -528,6 +708,7 @@ class MCAPI {
|
|
528 |
*
|
529 |
* @section List Related
|
530 |
* @example mcapi_listUnsubscribe.php
|
|
|
531 |
*
|
532 |
* @param string $id the list id to connect to
|
533 |
* @param string $email_address the email address to unsubscribe
|
@@ -550,6 +731,7 @@ class MCAPI {
|
|
550 |
* Edit the email address, merge fields, and interest groups for a list member
|
551 |
*
|
552 |
* @section List Related
|
|
|
553 |
*
|
554 |
* @param string $id the list id to connect to
|
555 |
* @param string $email_address the current email address of the member to update
|
@@ -582,7 +764,7 @@ class MCAPI {
|
|
582 |
* @return struct Array of result counts and any errors that occurred
|
583 |
* @returnf integer success_count Number of email addresses that were succesfully added/updated
|
584 |
* @returnf integer error_count Number of email addresses that failed during addition/updating
|
585 |
-
* @returnf array errors Array of error structs. Each error struct will contain "code", "message", and
|
586 |
*/
|
587 |
function listBatchSubscribe($id, $batch, $double_optin=true, $update_existing=false, $replace_interests=true) {
|
588 |
$params = array();
|
@@ -598,6 +780,7 @@ class MCAPI {
|
|
598 |
* Unsubscribe a batch of email addresses to a list
|
599 |
*
|
600 |
* @section List Related
|
|
|
601 |
*
|
602 |
* @param string $id the list id to connect to
|
603 |
* @param array $emails array of email addresses to unsubscribe
|
@@ -607,7 +790,7 @@ class MCAPI {
|
|
607 |
* @return struct Array of result counts and any errors that occurred
|
608 |
* @returnf integer success_count Number of email addresses that were succesfully added/updated
|
609 |
* @returnf integer error_count Number of email addresses that failed during addition/updating
|
610 |
-
* @returnf array errors Array of error structs. Each error struct will contain "code", "message", and "
|
611 |
*/
|
612 |
function listBatchUnsubscribe($id, $emails, $delete_member=false, $send_goodbye=true, $send_notify=false) {
|
613 |
$params = array();
|
@@ -620,15 +803,15 @@ class MCAPI {
|
|
620 |
}
|
621 |
|
622 |
/**
|
623 |
-
* Get all of the list members
|
624 |
*
|
625 |
* @section List Related
|
626 |
* @example mcapi_listMembers.php
|
627 |
*
|
628 |
* @param string $id the list id to connect to
|
629 |
* @param string $status the status to get members for - one of(subscribed, unsubscribed, or cleaned), defaults to subscribed
|
630 |
-
* @param
|
631 |
-
* @param
|
632 |
* @return array Array of list member structs (see Returned Fields for details)
|
633 |
* @returnf string email Member email address
|
634 |
* @returnf date timestamp timestamp of their associated status(date subscribed, unsubscribed, or cleaned)
|
@@ -647,6 +830,8 @@ class MCAPI {
|
|
647 |
*
|
648 |
* @section List Related
|
649 |
* @example mcapi_listMemberInfo.php
|
|
|
|
|
650 |
* @param string $id the list id to connect to
|
651 |
* @param string $email_address the member email address to get information for
|
652 |
* @return array array of list member info (see Returned Fields for details)
|
@@ -654,6 +839,8 @@ class MCAPI {
|
|
654 |
* @returnf string email_type The type of emails this customer asked to get: html or text
|
655 |
* @returnf array merges An associative array of all the merge tags and the data for those tags for this email address
|
656 |
* @returnf string status The subscription status for this email address, either subscribed, unsubscribed or cleaned
|
|
|
|
|
657 |
* @returnf date timestamp The time this email address was added to the list
|
658 |
*/
|
659 |
function listMemberInfo($id, $email_address) {
|
@@ -663,6 +850,147 @@ class MCAPI {
|
|
663 |
return $this->callServer("listMemberInfo", $params);
|
664 |
}
|
665 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
666 |
/**
|
667 |
* Internal function - proxy method for certain XML-RPC calls | DO NOT CALL
|
668 |
* @param mixed Method to call, with any parameters to pass along
|
@@ -680,14 +1008,14 @@ class MCAPI {
|
|
680 |
function callServer($method, $params) {
|
681 |
//Always include the user id if we're not loggin in
|
682 |
if($method != "login") {
|
683 |
-
$params["
|
684 |
}
|
685 |
|
686 |
$post_vars = $this->httpBuildQuery($params);
|
687 |
|
688 |
$payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
|
689 |
$payload .= "Host: " . $this->apiUrl["host"] . "\r\n";
|
690 |
-
$payload .= "User-Agent: MCAPI-Wordpress/"
|
691 |
$payload .= "Content-type: application/x-www-form-urlencoded\r\n";
|
692 |
$payload .= "Content-length: " . strlen($post_vars) . "\r\n";
|
693 |
$payload .= "Connection: close \r\n\r\n";
|
@@ -697,7 +1025,7 @@ class MCAPI {
|
|
697 |
$sock = fsockopen($this->apiUrl["host"], 80, $errno, $errstr, $this->timeout);
|
698 |
if(!$sock) {
|
699 |
$this->errorMessage = "Could not connect (ERR $errno: $errstr)";
|
700 |
-
$this->errorCode = "
|
701 |
ob_end_clean();
|
702 |
return false;
|
703 |
}
|
@@ -716,7 +1044,7 @@ class MCAPI {
|
|
716 |
|
717 |
$serial = unserialize($response);
|
718 |
if($response && $serial === false) {
|
719 |
-
$response = array("error" => "Bad Response. Got This: " . $response, "code" => "
|
720 |
} else {
|
721 |
$response = $serial;
|
722 |
}
|
1 |
<?php
|
2 |
|
3 |
class MCAPI {
|
4 |
+
var $version = "1.1";
|
5 |
var $errorMessage;
|
6 |
var $errorCode;
|
7 |
|
21 |
var $chunkSize = 8192;
|
22 |
|
23 |
/**
|
24 |
+
* Cache the user api_key so we only have to log in once per client instantiation
|
25 |
*/
|
26 |
+
var $api_key;
|
27 |
|
28 |
/**
|
29 |
* Connect to the MailChimp API for a given list. All MCAPI calls require login before functioning
|
32 |
* @param string $password Your MailChimp login password - always required
|
33 |
*/
|
34 |
function MCAPI($username, $password) {
|
35 |
+
//do more "caching" of the uuid for those people that keep instantiating this...
|
36 |
+
if (isset($GLOBALS["mc_api_key"]) && $GLOBALS["mc_api_key"]!=""){
|
37 |
+
$this->api_key = $GLOBALS["mc_api_key"];
|
38 |
+
} else {
|
39 |
+
$this->apiUrl = parse_url("http://api.mailchimp.com/" . $this->version . "/?output=php");
|
40 |
+
$this->api_key = $this->callServer("login", array("username" => $username, "password" => $password));
|
41 |
+
$GLOBALS["mc_api_key"] = $this->api_key;
|
42 |
+
}
|
43 |
}
|
44 |
|
45 |
/**
|
48 |
* @section Campaign Related
|
49 |
* @example xml-rpc_campaignUnschedule.php
|
50 |
*
|
51 |
+
* @param string $cid the id of the campaign to unschedule
|
52 |
* @return boolean true on success
|
53 |
*/
|
54 |
function campaignUnschedule($cid) {
|
63 |
* @section Campaign Related
|
64 |
* @example xml-rpc_campaignSchedule.php
|
65 |
*
|
66 |
+
* @param string $cid the id of the campaign to schedule
|
67 |
+
* @param string $schedule_time the time to schedule the campaign. For A/B Split "schedule" campaigns, the time for Group A - in YYYY-MM-DD HH:II:SS format in <strong>GMT</strong>
|
68 |
+
* @param string $schedule_time_b optional -the time to schedule Group B of an A/B Split "schedule" campaign - in YYYY-MM-DD HH:II:SS format in <strong>GMT</strong>
|
69 |
* @return boolean true on success
|
70 |
*/
|
71 |
+
function campaignSchedule($cid, $schedule_time, $schedule_time_b=NULL) {
|
72 |
$params = array();
|
73 |
$params["cid"] = $cid;
|
74 |
$params["schedule_time"] = $schedule_time;
|
75 |
+
$params["schedule_time_b"] = $schedule_time_b;
|
76 |
return $this->callServer("campaignSchedule", $params);
|
77 |
}
|
78 |
|
79 |
+
/**
|
80 |
+
* Resume sending a RSS campaign
|
81 |
+
*
|
82 |
+
* @section Campaign Related
|
83 |
+
*
|
84 |
+
* @param string $cid the id of the campaign to pause
|
85 |
+
* @return boolean true on success
|
86 |
+
*/
|
87 |
+
function campaignResume($cid) {
|
88 |
+
$params = array();
|
89 |
+
$params["cid"] = $cid;
|
90 |
+
return $this->callServer("campaignResume", $params);
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Pause a RSS campaign from sending
|
95 |
+
*
|
96 |
+
* @section Campaign Related
|
97 |
+
*
|
98 |
+
* @param string $cid the id of the campaign to pause
|
99 |
+
* @return boolean true on success
|
100 |
+
*/
|
101 |
+
function campaignPause($cid) {
|
102 |
+
$params = array();
|
103 |
+
$params["cid"] = $cid;
|
104 |
+
return $this->callServer("campaignPause", $params);
|
105 |
+
}
|
106 |
+
|
107 |
/**
|
108 |
* Send a given campaign immediately
|
109 |
*
|
110 |
* @section Campaign Related
|
|
|
111 |
*
|
112 |
+
* @param string $cid the id of the campaign to resume
|
113 |
* @return boolean true on success
|
114 |
*/
|
115 |
function campaignSendNow($cid) {
|
124 |
* @section Campaign Related
|
125 |
* @example xml-rpc_campaignSendTest.php
|
126 |
*
|
127 |
+
* @param string $cid the id of the campaign to test
|
128 |
+
* @param array $test_emails an array of email address to receive the test message
|
129 |
+
* @param string $send_type optional by default (null) both formats are sent - "html" or "text" send just that format
|
130 |
* @return boolean true on success
|
131 |
*/
|
132 |
function campaignSendTest($cid, $test_emails=array (
|
155 |
return $this->callServer("campaignTemplates", $params);
|
156 |
}
|
157 |
|
158 |
+
/**
|
159 |
+
* Allows one to test their segmentation rules before creating a campaign using them
|
160 |
+
*
|
161 |
+
* @section Campaign Related
|
162 |
+
* @example xml-rpc_campaignSegmentTest.php
|
163 |
+
*
|
164 |
+
* @param string $list_id the list to test segmentation on - get lists using lists()
|
165 |
+
* @param array $options with 2 keys:
|
166 |
+
string "match" controls whether to use AND or OR when applying your options - expects "<strong>any</strong>" (for OR) or "<strong>all</strong>" (for AND)
|
167 |
+
array "conditions" - up to 10 different criteria to apply while segmenting. Each criteria row should contain 3 keys - "<strong>field</strong>", "<strong>op</strong>", or "<strong>value</strong>" based on these definitions:
|
168 |
+
|
169 |
+
Field = "<strong>date</strong>" : Select based on various dates we track
|
170 |
+
Valid Op(eration): <strong>eq</strong> (is) / <strong>gt</strong> (after) / <strong>lt</strong> (before)
|
171 |
+
Valid Values:
|
172 |
+
string last_campaign_sent uses the date of the last campaign sent
|
173 |
+
string campaign_id - uses the send date of the campaign that carriers the Id submitted - see campaigns()
|
174 |
+
string YYYY-MM-DD - ny date in the form of YYYY-MM-DD - <i>note:</i> anything that appears to start with YYYY will be treated as a date
|
175 |
+
|
176 |
+
Field = "<strong>interests</strong>":
|
177 |
+
Valid Op(erations): <strong>one</strong> / <strong>none</strong> / <strong>all</strong>
|
178 |
+
Valid Values: a comma delimited of interest groups for the list - see listInterestGroups()
|
179 |
+
|
180 |
+
Field = "<strong>aim</strong>"
|
181 |
+
Valid Op(erations): <strong>open</strong> / <strong>noopen</strong> / <strong>click</strong> / <strong>noclick</strong>
|
182 |
+
Valid Values: "<strong>any</strong>" or a valid AIM-enabled Campaign that has been sent
|
183 |
+
|
184 |
+
Default Field = A Merge Var. Use <strong>Merge0-Merge15</strong> or the <strong>Custom Tag</strong> you've setup for your merge field - see listMergeVars()
|
185 |
+
Valid Op(erations):
|
186 |
+
<strong>eq</strong> (=)/<strong>ne</strong>(!=)/<strong>gt</strong>(>)/<strong>lt</strong>(<)/<strong>like</strong>(like '%blah%')/<strong>nlike</strong>(not like '%blah%')/<strong>starts</strong>(like 'blah%')/<strong>ends</strong>(like '%blah')
|
187 |
+
Valid Values: any string
|
188 |
+
* @return integer total The total number of subscribers matching your segmentation options
|
189 |
+
*/
|
190 |
+
function campaignSegmentTest($list_id, $options) {
|
191 |
+
$params = array();
|
192 |
+
$params["list_id"] = $list_id;
|
193 |
+
$params["options"] = $options;
|
194 |
+
return $this->callServer("campaignSegmentTest", $params);
|
195 |
+
}
|
196 |
+
|
197 |
/**
|
198 |
* Create a new draft campaign to send
|
199 |
*
|
200 |
* @section Campaign Related
|
201 |
+
* @example mcapi_campaignCreate.php
|
202 |
+
* @example xml-rpc_campaignCreate.php
|
203 |
+
* @example xml-rpc_campaignCreateABSplit.php
|
204 |
+
* @example xml-rpc_campaignCreateRss.php
|
205 |
+
*
|
206 |
+
* @param string $type the Campaign Type to create - one of "regular", "plaintext", "absplit", "rss"
|
207 |
+
* @param array $opts a hash of the standard options for this campaign :
|
208 |
+
string list_id the list to send this campaign to- get lists using lists()
|
209 |
+
string subject the subject line for your campaign message
|
210 |
+
string from_email the From: email address for your campaign message
|
211 |
+
string from_name the From: name for your campaign message (not an email address)
|
212 |
+
integer template_id optional - use this template to generate the HTML content of the campaign
|
213 |
+
array tracking optional - set which recipient actions will be tracked, as a struct of boolean values with the following keys: "opens", "html_clicks", and "text_clicks". By default, opens and HTML clicks will be tracked.
|
214 |
+
string title optional - an internal name to use for this campaign. By default, the campaign subject will be used.
|
215 |
+
boolean authenticate optional - set to true to enable SenderID, DomainKeys, and DKIM authentication, defaults to false.
|
216 |
+
array analytics optional - if provided, use a struct with "service type" as a key and the "service tag" as a value. For Google, this should be "google"=>"your_google_analytics_key_here". Note that only "google" is currently supported - a Google Analytics tags will be added to all links in the campaign with this string attached. Others may be added in the future
|
217 |
+
boolean inline_css optional Whether or not css should be automatically inlined when this campaign is sent, defaults to false.
|
218 |
+
boolean generate_text optional Whether of not to auto-generate your Text content from the HTML content. Note that this will be ignored if the Text part of the content passed is not empty, defaults to false.
|
219 |
+
|
220 |
+
* @param array $content the content for this campaign - use a struct with the following keys:
|
221 |
+
"html" for pasted HTML content
|
222 |
+
"text" for the plain-text version
|
223 |
+
"url" to have us pull in content from a URL (will replace any "html" content you pass in - can be used with "generate_text" option as well).
|
224 |
+
|
225 |
+
If you chose a template instead of pasting in your HTML content, then use "html_" followed by the template sections as keys - for example, use a key of "html_MAIN" to fill in the "MAIN" section of a template. Supported template sections include: "html_HEADER", "html_MAIN", "html_SIDECOLUMN", and "html_FOOTER"
|
226 |
+
* @param array $segment_opts optional - if you wish to do Segmentation with this campaign this array should contain: see campaignSegmentTest(). You should test your options against campaignSegmentTest() as campaignCreate() will not allow you to set a segment that includes no members.
|
227 |
+
* @param array $type_opts optional -
|
228 |
+
For RSS Campaigns this, array should contain:
|
229 |
+
string url the URL to pull RSS content from - it will be verified and must exist
|
230 |
+
|
231 |
+
For A/B Split campaigns, this array should contain:
|
232 |
+
string split_test The values to segment based on. Currently, one of: "subject", "from_name", "schedule". NOTE, for "schedule", you will need to call campaignSchedule() separately!
|
233 |
+
string pick_wineer How the winner will be picked, one of: "opens" (by the open_rate), "clicks" (by the click rate), "manual" (you pick manually)
|
234 |
+
integer wait_units optional the default time unit to wait before auto-selecting a winner - use "3600" for hours, "86400" for days. Defaults to 86400.
|
235 |
+
integer wait_time optional the number of units to wait before auto-selecting a winner - defaults to 1, so if not set, a winner will be selected after 1 Day.
|
236 |
+
integer split_size optional this is a percentage of what size the Campaign's List plus any segmentation options results in. "schedule" type forces 50%, all others default to 10%
|
237 |
+
string from_name_a optional sort of, required when split_test is "from_name"
|
238 |
+
string from_name_b optional sort of, required when split_test is "from_name"
|
239 |
+
string from_email_a optional sort of, required when split_test is "from_name"
|
240 |
+
string from_email_b optional sort of, required when split_test is "from_name"
|
241 |
+
string subject_a optional sort of, required when split_test is "subject"
|
242 |
+
string subject_b optional sort of, required when split_test is "subject"
|
243 |
+
*
|
244 |
* @return string the ID for the created campaign
|
245 |
*/
|
246 |
+
function campaignCreate($type, $options, $content, $segment_opts=NULL, $type_opts=NULL) {
|
|
|
|
|
|
|
|
|
247 |
$params = array();
|
248 |
+
$params["type"] = $type;
|
249 |
+
$params["options"] = $options;
|
|
|
|
|
250 |
$params["content"] = $content;
|
251 |
+
$params["segment_opts"] = $segment_opts;
|
252 |
+
$params["type_opts"] = $type_opts;
|
|
|
|
|
|
|
253 |
return $this->callServer("campaignCreate", $params);
|
254 |
}
|
255 |
|
256 |
+
/** Update just about any setting for a campaign that has <i>not</i> been sent. See campaignCreate() for details
|
257 |
+
*
|
258 |
+
* Caveats:<br/><ul>
|
259 |
+
* <li>If you set list_id, all segmentation options will be deleted and must be re-added.</li>
|
260 |
+
* <li>If you set template_id, you need to follow that up by setting it's 'content'</li>
|
261 |
+
* <li>If you set segment_opts, you should have tested your options against campaignSegmentTest() as campaignUpdate() will not allow you to set a segment that includes no members.</li></ul>
|
262 |
+
* @section Campaign Related
|
263 |
+
* @example xml-rpc_campaignUpdate.php
|
264 |
+
* @example xml-rpc_campaignUpdateAB.php
|
265 |
+
*
|
266 |
+
* @param string $cid the Campaign Id to update
|
267 |
+
* @param string $name the parameter name ( see campaignCreate() )
|
268 |
+
* @param mixed $value an appropriate value for the parameter ( see campaignCreate() )
|
269 |
+
* @return boolean true if the update succeeds, otherwise an error will be thrown
|
270 |
+
*/
|
271 |
+
function campaignUpdate($cid, $name, $value) {
|
272 |
+
$params = array();
|
273 |
+
$params["cid"] = $cid;
|
274 |
+
$params["name"] = $name;
|
275 |
+
$params["value"] = $value;
|
276 |
+
return $this->callServer("campaignUpdate", $params);
|
277 |
+
}
|
278 |
+
|
279 |
/**
|
280 |
+
* Get the list of campaigns and their details matching the specified filters
|
281 |
*
|
282 |
* @section Campaign Related
|
283 |
+
* @example xml-rpc_campaigns.php
|
284 |
*
|
285 |
+
* @param string $filter_id optional - only show campaigns from this list id - get lists using lists()
|
286 |
* @param integer $filter_folder optional - only show campaigns from this folder id - get folders using campaignFolders()
|
287 |
* @param string $filter_fromname optional - only show campaigns that have this "From Name"
|
288 |
* @param string $filter_fromemail optional - only show campaigns that have this "Reply-to Email"
|
291 |
* @param string $filter_sendtimestart optional - only show campaigns that have been sent since this date/time
|
292 |
* @param string $filter_sendtimeend optional - only show campaigns that have been sent before this date/time
|
293 |
* @param boolean $filter_exact optional - flag for whether to filter on exact values when filtering, or search within content for filter values
|
294 |
+
* @param integer $start optional - control paging of campaigns, start results at this campaign #, defaults to 1st page of data (page 0)
|
295 |
* @param integer $limit optional - control paging of campaigns, number of campaigns to return with each call, defaults to 25 (max=5000)
|
296 |
* @return array list of campaigns and their associated information (see Returned Fields for description)
|
297 |
* @returnf string id Campaign Id (used for all other campaign functions)
|
298 |
* @returnf string title Title of the campaign
|
299 |
+
* @returnf string type The type of campaign this is (regular, plaintext, absplit, rss, etc.)
|
300 |
* @returnf date create_time Creation time for the campaign
|
301 |
* @returnf date send_time Send time for the campaign
|
302 |
+
* @returnf integer emails_sent Number of emails email was sent to
|
303 |
* @returnf string status Status of the given campaign (sent,scheduled,etc.)
|
304 |
* @returnf string from_name From name of the given campaign
|
305 |
* @returnf string from_email Reply-to email of the given campaign
|
306 |
* @returnf string subject Subject of the given campaign
|
307 |
+
* @returnf string to_email Custom "To:" email string using merge variables
|
308 |
* @returnf string archive_url Archive link for the given campaign
|
309 |
+
* @returnf boolean inline_css Whether or not the campaigns content auto-css-lined
|
310 |
*/
|
311 |
function campaigns($filter_id=NULL, $filter_folder=NULL, $filter_fromname=NULL, $filter_fromemail=NULL, $filter_title=NULL, $filter_subject=NULL, $filter_sendtimestart=NULL, $filter_sendtimeend=NULL, $filter_exact=true, $start=0, $limit=25) {
|
312 |
$params = array();
|
328 |
* List all the folders for a user account
|
329 |
*
|
330 |
* @section Campaign Related
|
331 |
+
* @example xml-rpc_campaignFolders.php
|
332 |
*
|
333 |
* @return array Array of folder structs (see Returned Fields for details)
|
334 |
* @returnf integer folder_id Folder Id for the given folder, this can be used in the campaigns() function to filter on.
|
343 |
* Given a list and a campaign, get all the relevant campaign statistics (opens, bounces, clicks, etc.)
|
344 |
*
|
345 |
* @section Campaign Stats
|
346 |
+
* @example xml-rpc_campaignStats.php
|
347 |
*
|
348 |
+
* @param string $cid the campaign id to pull stats for (can be gathered using campaigns())
|
349 |
* @return array struct of the statistics for this campaign
|
350 |
* @returnf integer syntax_errors Number of email addresses in campaign that had syntactical errors.
|
351 |
* @returnf integer hard_bounces Number of email addresses in campaign that hard bounced.
|
374 |
*
|
375 |
* @section Campaign Stats
|
376 |
*
|
377 |
+
* @param string $cid the campaign id to pull stats for (can be gathered using campaigns())
|
378 |
* @return struct list of urls and their associated statistics
|
379 |
* @returnf integer clicks Number of times the specific link was clicked
|
380 |
* @returnf integer unique Number of unique people who clicked on the specific link
|
385 |
return $this->callServer("campaignClickStats", $params);
|
386 |
}
|
387 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
388 |
/**
|
389 |
* Get all email addresses with Hard Bounces for a given campaign
|
390 |
*
|
391 |
* @section Campaign Stats
|
392 |
*
|
393 |
+
* @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
|
394 |
+
* @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
|
395 |
+
* @param integer $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
|
396 |
* @return array Arrays of email addresses with Hard Bounces
|
397 |
*/
|
398 |
function campaignHardBounces($cid, $start=0, $limit=1000) {
|
408 |
*
|
409 |
* @section Campaign Stats
|
410 |
*
|
411 |
+
* @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
|
412 |
+
* @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
|
413 |
+
* @param integer $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
|
414 |
* @return array Arrays of email addresses with Soft Bounces
|
415 |
*/
|
416 |
function campaignSoftBounces($cid, $start=0, $limit=1000) {
|
426 |
*
|
427 |
* @section Campaign Stats
|
428 |
*
|
429 |
+
* @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
|
430 |
+
* @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
|
431 |
+
* @param integer $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
|
432 |
* @return array list of email addresses that unsubscribed from this campaign
|
433 |
*/
|
434 |
function campaignUnsubscribes($cid, $start=0, $limit=1000) {
|
444 |
*
|
445 |
* @section Campaign Stats
|
446 |
*
|
447 |
+
* @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
|
448 |
+
* @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
|
449 |
+
* @param integer $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
|
450 |
* @return array list of email addresses that complained (filed abuse reports) about this campaign
|
451 |
*/
|
452 |
function campaignAbuseReports($cid, $start=0, $limit=1000) {
|
462 |
*
|
463 |
* @section Campaign Related
|
464 |
*
|
465 |
+
* @param string $cid the campaign id to get content for (can be gathered using campaigns())
|
466 |
* @return struct Struct containing all content for the campaign (see Returned Fields for details
|
467 |
* @returnf string html The HTML content used for the campgain with merge tags intact
|
468 |
* @returnf string text The Text content used for the campgain with merge tags intact
|
478 |
*
|
479 |
* @section Campaign AIM
|
480 |
*
|
481 |
+
* @param string $cid the campaign id to get opens for (can be gathered using campaigns())
|
482 |
+
* @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
|
483 |
+
* @param integer $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
|
484 |
* @return array Array of structs containing email addresses and open counts
|
485 |
* @returnf string email Email address that opened the campaign
|
486 |
* @returnf integer open_count Total number of times the campaign was opened by this email address
|
498 |
*
|
499 |
* @section Campaign AIM
|
500 |
*
|
501 |
+
* @param string $cid the campaign id to get no opens for (can be gathered using campaigns())
|
502 |
+
* @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
|
503 |
+
* @param integer $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
|
504 |
* @return array list of email addresses that did not open a campaign
|
505 |
*/
|
506 |
function campaignNotOpenedAIM($cid, $start=0, $limit=1000) {
|
516 |
*
|
517 |
* @section Campaign AIM
|
518 |
*
|
519 |
+
* @param string $cid the campaign id to get click stats for (can be gathered using campaigns())
|
520 |
* @param string $url the URL of the link that was clicked on
|
521 |
+
* @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
|
522 |
+
* @param integer $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
|
523 |
* @return array Array of structs containing email addresses and click counts
|
524 |
* @returnf string email Email address that opened the campaign
|
525 |
* @returnf integer clicks Total number of times the URL was clicked on by this email address
|
538 |
*
|
539 |
* @section Campaign AIM
|
540 |
*
|
541 |
+
* @param string $cid the campaign id to get stats for (can be gathered using campaigns())
|
542 |
* @param string $email_address the email address to get activity history for
|
543 |
* @return array Array of structs containing actions (opens and clicks) that the email took, with timestamps
|
544 |
* @returnf string action The action taken (open or click)
|
573 |
* Get the list of merge tags for a given list, including their name, tag, and required setting
|
574 |
*
|
575 |
* @section List Related
|
576 |
+
* @example xml-rpc_listMergeVars.php
|
577 |
*
|
578 |
* @param string $id the list id to connect to
|
579 |
* @return array list of merge tags for the list
|
587 |
return $this->callServer("listMergeVars", $params);
|
588 |
}
|
589 |
|
590 |
+
/**
|
591 |
+
* Delete a merge tag from a given list and all it's members
|
592 |
+
*
|
593 |
+
* @section List Related
|
594 |
+
* @example xml-rpc_listMergeVarAdd.php
|
595 |
+
*
|
596 |
+
* @param string $id the list id to connect to
|
597 |
+
* @param string $tag The merge tag to add, e.g. FNAME
|
598 |
+
* @param string $name The long description of the tag being added, used for user displays
|
599 |
+
* @param boolean $req optional Whether or not to require this field to be filled in, defaults to false
|
600 |
+
* @return bool true if the request succeeds, otherwise an error will be thrown
|
601 |
+
*/
|
602 |
+
function listMergeVarAdd($id, $tag, $name, $req=false) {
|
603 |
+
$params = array();
|
604 |
+
$params["id"] = $id;
|
605 |
+
$params["tag"] = $tag;
|
606 |
+
$params["name"] = $name;
|
607 |
+
$params["req"] = $req;
|
608 |
+
return $this->callServer("listMergeVarAdd", $params);
|
609 |
+
}
|
610 |
+
|
611 |
+
/**
|
612 |
+
* Delete a merge tag from a given list and all it's members. Note that on large lists this method
|
613 |
+
* may seem a bit slower than calls you typical make.
|
614 |
+
*
|
615 |
+
* @section List Related
|
616 |
+
* @example xml-rpc_listMergeVarDel.php
|
617 |
+
*
|
618 |
+
* @param string $id the list id to connect to
|
619 |
+
* @param string $tag The merge tag to delete
|
620 |
+
* @return bool true if the request succeeds, otherwise an error will be thrown
|
621 |
+
*/
|
622 |
+
function listMergeVarDel($id, $tag) {
|
623 |
+
$params = array();
|
624 |
+
$params["id"] = $id;
|
625 |
+
$params["tag"] = $tag;
|
626 |
+
return $this->callServer("listMergeVarDel", $params);
|
627 |
+
}
|
628 |
+
|
629 |
/**
|
630 |
* Get the list of interest groups for a given list, including the label and form information
|
631 |
*
|
632 |
* @section List Related
|
633 |
+
* @example xml-rpc_listInterestGroups.php
|
634 |
*
|
635 |
* @param string $id the list id to connect to
|
636 |
* @return struct list of interest groups for the list
|
644 |
return $this->callServer("listInterestGroups", $params);
|
645 |
}
|
646 |
|
647 |
+
/** Add a single Interest Group
|
648 |
+
*
|
649 |
+
* @section List Related
|
650 |
+
* @example xml-rpc_listInterestGroupAdd.php
|
651 |
+
*
|
652 |
+
* @param string $id the list id to connect to
|
653 |
+
* @param string $group_name the interest group to add
|
654 |
+
* @return bool true if the request succeeds, otherwise an error will be thrown
|
655 |
+
*/
|
656 |
+
function listInterestGroupAdd($id, $group_name) {
|
657 |
+
$params = array();
|
658 |
+
$params["id"] = $id;
|
659 |
+
$params["group_name"] = $group_name;
|
660 |
+
return $this->callServer("listInterestGroupAdd", $params);
|
661 |
+
}
|
662 |
+
|
663 |
+
/** Delete a single Interest Group
|
664 |
+
*
|
665 |
+
* @section List Related
|
666 |
+
* @example xml-rpc_listInterestGroupDel.php
|
667 |
+
*
|
668 |
+
* @param string $id the list id to connect to
|
669 |
+
* @param string $group_name the interest group to delete
|
670 |
+
* @return bool true if the request succeeds, otherwise an error will be thrown
|
671 |
+
*/
|
672 |
+
function listInterestGroupDel($id, $group_name) {
|
673 |
+
$params = array();
|
674 |
+
$params["id"] = $id;
|
675 |
+
$params["group_name"] = $group_name;
|
676 |
+
return $this->callServer("listInterestGroupDel", $params);
|
677 |
+
}
|
678 |
+
|
679 |
/**
|
680 |
* Subscribe the provided email to a list
|
681 |
*
|
686 |
*
|
687 |
* @param string $id the list id to connect to
|
688 |
* @param string $email_address the email address to subscribe
|
689 |
+
* @param array $merge_vars array of merges for the email (FNAME, LNAME, etc.) (see examples below for handling "blank" arrays). 2 "special" keys:
|
690 |
+
string INTERESTS Set Interest Groups by passing a field named "INTERESTS" that contains a comma delimited list of Interest Groups to add.
|
691 |
+
string OPTINIP Set the Opt-in IP fields. <i>Abusing this may cause your account to be suspended.</i>
|
692 |
* @param string $email_type optional - email type preference for the email (html or text, defaults to html)
|
693 |
+
* @param boolean $double_optin optional - flag to control whether a double opt-in confirmation message is sent, defaults to true. <i>Abusing this may cause your account to be suspended.</i>
|
694 |
* @return boolean true on success, false on failure. When using MCAPI.class.php, the value can be tested and error messages pulled from the MCAPI object (see below)
|
695 |
*/
|
696 |
function listSubscribe($id, $email_address, $merge_vars, $email_type='html', $double_optin=true) {
|
708 |
*
|
709 |
* @section List Related
|
710 |
* @example mcapi_listUnsubscribe.php
|
711 |
+
* @example xml-rpc_listUnsubscribe.php
|
712 |
*
|
713 |
* @param string $id the list id to connect to
|
714 |
* @param string $email_address the email address to unsubscribe
|
731 |
* Edit the email address, merge fields, and interest groups for a list member
|
732 |
*
|
733 |
* @section List Related
|
734 |
+
* @example mcapi_listUpdateMember.php
|
735 |
*
|
736 |
* @param string $id the list id to connect to
|
737 |
* @param string $email_address the current email address of the member to update
|
764 |
* @return struct Array of result counts and any errors that occurred
|
765 |
* @returnf integer success_count Number of email addresses that were succesfully added/updated
|
766 |
* @returnf integer error_count Number of email addresses that failed during addition/updating
|
767 |
+
* @returnf array errors Array of error structs. Each error struct will contain "code", "message", and the full struct that failed
|
768 |
*/
|
769 |
function listBatchSubscribe($id, $batch, $double_optin=true, $update_existing=false, $replace_interests=true) {
|
770 |
$params = array();
|
780 |
* Unsubscribe a batch of email addresses to a list
|
781 |
*
|
782 |
* @section List Related
|
783 |
+
* @example mcapi_listBatchUnsubscribe.php
|
784 |
*
|
785 |
* @param string $id the list id to connect to
|
786 |
* @param array $emails array of email addresses to unsubscribe
|
790 |
* @return struct Array of result counts and any errors that occurred
|
791 |
* @returnf integer success_count Number of email addresses that were succesfully added/updated
|
792 |
* @returnf integer error_count Number of email addresses that failed during addition/updating
|
793 |
+
* @returnf array errors Array of error structs. Each error struct will contain "code", "message", and "email"
|
794 |
*/
|
795 |
function listBatchUnsubscribe($id, $emails, $delete_member=false, $send_goodbye=true, $send_notify=false) {
|
796 |
$params = array();
|
803 |
}
|
804 |
|
805 |
/**
|
806 |
+
* Get all of the list members for a list that are of a particular status
|
807 |
*
|
808 |
* @section List Related
|
809 |
* @example mcapi_listMembers.php
|
810 |
*
|
811 |
* @param string $id the list id to connect to
|
812 |
* @param string $status the status to get members for - one of(subscribed, unsubscribed, or cleaned), defaults to subscribed
|
813 |
+
* @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
|
814 |
+
* @param integer $limit optional for large data sets, the number of results to return - defaults to 100, upper limit set at 15000
|
815 |
* @return array Array of list member structs (see Returned Fields for details)
|
816 |
* @returnf string email Member email address
|
817 |
* @returnf date timestamp timestamp of their associated status(date subscribed, unsubscribed, or cleaned)
|
830 |
*
|
831 |
* @section List Related
|
832 |
* @example mcapi_listMemberInfo.php
|
833 |
+
* @example xml-rpc_listMemberInfo.php
|
834 |
+
*
|
835 |
* @param string $id the list id to connect to
|
836 |
* @param string $email_address the member email address to get information for
|
837 |
* @return array array of list member info (see Returned Fields for details)
|
839 |
* @returnf string email_type The type of emails this customer asked to get: html or text
|
840 |
* @returnf array merges An associative array of all the merge tags and the data for those tags for this email address
|
841 |
* @returnf string status The subscription status for this email address, either subscribed, unsubscribed or cleaned
|
842 |
+
* @returnf string ip_opt IP Address this address opted in from.
|
843 |
+
* @returnf string ip_signup IP Address this address signed up from.
|
844 |
* @returnf date timestamp The time this email address was added to the list
|
845 |
*/
|
846 |
function listMemberInfo($id, $email_address) {
|
850 |
return $this->callServer("listMemberInfo", $params);
|
851 |
}
|
852 |
|
853 |
+
/**
|
854 |
+
* Retrieve your User Unique Id and your Affiliate link to display/use for <a href="/monkeyrewards/" target="_blank">Monkey Rewards</a>. While
|
855 |
+
* we don't use the User Id for any API functions, it can be useful if building up URL strings for things such as the profile editor and sub/unsub links.
|
856 |
+
* @section Helper
|
857 |
+
*
|
858 |
+
* @return array containing your Affilliate Id and full link.
|
859 |
+
* @returnf string user_id Your User Unique Id.
|
860 |
+
* @returnf string url Your Monkey Rewards link for our Affiliate program
|
861 |
+
*/
|
862 |
+
function getAffiliateInfo() {
|
863 |
+
$params = array();
|
864 |
+
return $this->callServer("getAffiliateInfo", $params);
|
865 |
+
}
|
866 |
+
|
867 |
+
/**
|
868 |
+
* Have HTML content auto-converted to a text-only format. You can send: plain HTML, an array of Template content, an existing Campaign Id, or an existing Template Id. Note that this will <b>not</b> save anything to or update any of your lists, campaigns, or templates.
|
869 |
+
*
|
870 |
+
* @section Helper
|
871 |
+
* @example xml-rpc_generateText.php
|
872 |
+
*
|
873 |
+
* @param string $type The type of content to parse. Must be one of: "html", "template", "url", "cid" (Campaign Id), or "tid" (Template Id)
|
874 |
+
* @param mixed $content The content to use. For "html" expects a single string value, "template" expects an array like you send to campaignCreate, "url" expects a valid & public URL to pull from, "cid" expects a valid Campaign Id, and "tid" expects a valid Template Id on your account.
|
875 |
+
* @return string the content pass in converted to text.
|
876 |
+
*/
|
877 |
+
function generateText($type, $content) {
|
878 |
+
$params = array();
|
879 |
+
$params["type"] = $type;
|
880 |
+
$params["content"] = $content;
|
881 |
+
return $this->callServer("generateText", $params);
|
882 |
+
}
|
883 |
+
|
884 |
+
/**
|
885 |
+
* Send your HTML content to have the CSS inlined and optionally remove the original styles.
|
886 |
+
*
|
887 |
+
* @section Helper
|
888 |
+
* @example xml-rpc_inlineCss.php
|
889 |
+
*
|
890 |
+
* @param string $html Your HTML content
|
891 |
+
* @param bool $strip_css Whether you want the CSS <style> tags stripped from the returned document
|
892 |
+
* @return string Your HTML content with all CSS inlined, just like if we sent it.
|
893 |
+
*/
|
894 |
+
function inlineCss($html, $strip_css=false) {
|
895 |
+
$params = array();
|
896 |
+
$params["html"] = $html;
|
897 |
+
$params["strip_css"] = $strip_css;
|
898 |
+
return $this->callServer("inlineCss", $params);
|
899 |
+
}
|
900 |
+
|
901 |
+
/**
|
902 |
+
* Retrieve a list of all MailChimp API Keys for this User
|
903 |
+
*
|
904 |
+
* @section Security Related
|
905 |
+
* @example xml-rpc_apikeyAdd.php
|
906 |
+
*
|
907 |
+
* @param string $username Your MailChimp user name
|
908 |
+
* @param string $password Your MailChimp password
|
909 |
+
* @param boolean $expired optional - whether or not to include expired keys, defaults to false
|
910 |
+
* @return array an array of API keys including:
|
911 |
+
* @returnf string apikey The api key that can be used
|
912 |
+
* @returnf string created_at The date the key was created
|
913 |
+
* @returnf string expired_at The date the key was expired
|
914 |
+
*/
|
915 |
+
function apikeys($username, $password, $expired=false) {
|
916 |
+
$params = array();
|
917 |
+
$params["username"] = $username;
|
918 |
+
$params["password"] = $password;
|
919 |
+
$params["expired"] = $expired;
|
920 |
+
return $this->callServer("apikeys", $params);
|
921 |
+
}
|
922 |
+
|
923 |
+
/**
|
924 |
+
* Add an API Key to your account. We will generate a new key for you and return it.
|
925 |
+
*
|
926 |
+
* @section Security Related
|
927 |
+
* @example xml-rpc_apikeyAdd.php
|
928 |
+
*
|
929 |
+
* @param string $username Your MailChimp user name
|
930 |
+
* @param string $password Your MailChimp password
|
931 |
+
* @return string a new API Key that can be immediately used.
|
932 |
+
*/
|
933 |
+
function apikeyAdd($username, $password) {
|
934 |
+
$params = array();
|
935 |
+
$params["username"] = $username;
|
936 |
+
$params["password"] = $password;
|
937 |
+
return $this->callServer("apikeyAdd", $params);
|
938 |
+
}
|
939 |
+
|
940 |
+
/**
|
941 |
+
* Expire a Specific API Key. Note that if you expire all of your keys, a new, valid one will be created and returned
|
942 |
+
* next time you call login(). If you are trying to shut off access to your account for an old developer, change your
|
943 |
+
* MailChimp password, then expire all of the keys they had access to. Note that this takes effect immediately, so make
|
944 |
+
* sure you replace the keys in any working application before expiring them! Consider yourself warned...
|
945 |
+
*
|
946 |
+
* @section Security Related
|
947 |
+
* @example xml-rpc_apikeyExpire.php
|
948 |
+
*
|
949 |
+
* @param string $username Your MailChimp user name
|
950 |
+
* @param string $password Your MailChimp password
|
951 |
+
* @return boolean true if it worked, otherwise an error is thrown.
|
952 |
+
*/
|
953 |
+
function apikeyExpire($username, $password) {
|
954 |
+
$params = array();
|
955 |
+
$params["username"] = $username;
|
956 |
+
$params["password"] = $password;
|
957 |
+
return $this->callServer("apikeyExpire", $params);
|
958 |
+
}
|
959 |
+
|
960 |
+
/**
|
961 |
+
* Disable a pretty bad security hole that exists in our 1.0 version of the API. If you have never used
|
962 |
+
* the API, we close this hole for you automatically. If you are an existing user, even if you upgraded to
|
963 |
+
* version 1.1, you should run this once anyways. Running this will *not* prevent you from using version 1.0 if you need to.
|
964 |
+
*
|
965 |
+
* @section Security Related
|
966 |
+
* @example xml-rpc_login.php
|
967 |
+
*
|
968 |
+
* @param string $username Your MailChimp user name
|
969 |
+
* @param string $password Your MailChimp password
|
970 |
+
* @return boolean true if it works, otherwise an exception is thrown
|
971 |
+
*/
|
972 |
+
function closeOneOhSecurityHole($username, $password) {
|
973 |
+
$params = array();
|
974 |
+
$params["username"] = $username;
|
975 |
+
$params["password"] = $password;
|
976 |
+
return $this->callServer("closeOneOhSecurityHole", $params);
|
977 |
+
}
|
978 |
+
|
979 |
+
/**
|
980 |
+
* "Ping" the MailChimp API - a simple method you can call that will return a constant value as long as everything is good. Note
|
981 |
+
* than unlike most all of our methods, we don't throw an Exception if we are having issues. You will simply receive a different
|
982 |
+
* string back that will explain our view on what is going on.
|
983 |
+
*
|
984 |
+
* @section Helper
|
985 |
+
* @example xml-rpc_ping.php
|
986 |
+
*
|
987 |
+
* @return string returns "Everything's Chimpy!" if everything is chimpy, otherwise returns an error message
|
988 |
+
*/
|
989 |
+
function ping() {
|
990 |
+
$params = array();
|
991 |
+
return $this->callServer("ping", $params);
|
992 |
+
}
|
993 |
+
|
994 |
/**
|
995 |
* Internal function - proxy method for certain XML-RPC calls | DO NOT CALL
|
996 |
* @param mixed Method to call, with any parameters to pass along
|
1008 |
function callServer($method, $params) {
|
1009 |
//Always include the user id if we're not loggin in
|
1010 |
if($method != "login") {
|
1011 |
+
$params["apikey"] = $this->api_key;
|
1012 |
}
|
1013 |
|
1014 |
$post_vars = $this->httpBuildQuery($params);
|
1015 |
|
1016 |
$payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
|
1017 |
$payload .= "Host: " . $this->apiUrl["host"] . "\r\n";
|
1018 |
+
$payload .= "User-Agent: MCAPI-Wordpress/" . $this->version ."\r\n";
|
1019 |
$payload .= "Content-type: application/x-www-form-urlencoded\r\n";
|
1020 |
$payload .= "Content-length: " . strlen($post_vars) . "\r\n";
|
1021 |
$payload .= "Connection: close \r\n\r\n";
|
1025 |
$sock = fsockopen($this->apiUrl["host"], 80, $errno, $errstr, $this->timeout);
|
1026 |
if(!$sock) {
|
1027 |
$this->errorMessage = "Could not connect (ERR $errno: $errstr)";
|
1028 |
+
$this->errorCode = "-99";
|
1029 |
ob_end_clean();
|
1030 |
return false;
|
1031 |
}
|
1044 |
|
1045 |
$serial = unserialize($response);
|
1046 |
if($response && $serial === false) {
|
1047 |
+
$response = array("error" => "Bad Response. Got This: " . $response, "code" => "-99");
|
1048 |
} else {
|
1049 |
$response = $serial;
|
1050 |
}
|
mailchimp.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: MailChimp
|
4 |
Plugin URI: http://mailchimp.com/api/plugins/wordpress
|
5 |
Description: The MailChimp plugin allows you to easily setup a Subscribe box for your MailChimp list - So easy a chimp could do it!
|
6 |
-
Version: 0.
|
7 |
Author: MailChimp API Support Team
|
8 |
Author URI: http://mailchimp.com/api/
|
9 |
*/
|
3 |
Plugin Name: MailChimp
|
4 |
Plugin URI: http://mailchimp.com/api/plugins/wordpress
|
5 |
Description: The MailChimp plugin allows you to easily setup a Subscribe box for your MailChimp list - So easy a chimp could do it!
|
6 |
+
Version: 0.5
|
7 |
Author: MailChimp API Support Team
|
8 |
Author URI: http://mailchimp.com/api/
|
9 |
*/
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: mc_jesse
|
|
3 |
Tags: mailchimp, email, newsletter, signup, marketing, plugin, widget
|
4 |
Requires at least: 2.3
|
5 |
Tested up to: 2.6
|
6 |
-
Stable tag: 0.
|
7 |
Author URI: http://www.mailchimp.com/api/
|
8 |
Plugin URI: http://www.mailchimp.com/plugins/wordpress.phtml
|
9 |
|
3 |
Tags: mailchimp, email, newsletter, signup, marketing, plugin, widget
|
4 |
Requires at least: 2.3
|
5 |
Tested up to: 2.6
|
6 |
+
Stable tag: 0.5
|
7 |
Author URI: http://www.mailchimp.com/api/
|
8 |
Plugin URI: http://www.mailchimp.com/plugins/wordpress.phtml
|
9 |
|