MCAPI::campaignEmailStatsAIMAll()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 3
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class MCAPI {
4
    var $version = "1.2";
5
    var $errorMessage;
6
    var $errorCode;
7
8
    /**
9
     * Cache the information on the API location on the server
10
     */
11
    var $apiUrl;
12
13
    /**
14
     * Default to a 300 second timeout on server calls
15
     */
16
    var $timeout = 300;
17
18
    /**
19
     * Default to a 8K chunk size
20
     */
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
     * Cache the user api_key so we only have to log in once per client instantiation
30
     */
31
    var $secure = false;
32
33
    /**
34
     * Connect to the MailChimp API for a given list. All MCAPI calls require login before functioning
35
     *
36
     * @param string $username_or_apikey Your MailChimp login user name OR apikey - always required
37
     * @param string $password Your MailChimp login password - only required when username passed instead of API Key
38
     */
39
    function __construct($username_or_apikey, $password=null, $secure=false) {
40
        //do more "caching" of the uuid for those people that keep instantiating this...
41
        $this->secure = $secure;
42
        $this->apiUrl = parse_url("http://api.mailchimp.com/" . $this->version . "/?output=php");
43
        if ( isset($GLOBALS["mc_api_key"]) && $GLOBALS["mc_api_key"]!="" ){
44
            $this->api_key = $GLOBALS["mc_api_key"];
45
        } elseif( $username_or_apikey && !$password ){
0 ignored issues
show
Bug Best Practice introduced by
The expression $password of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
46
            $this->api_key = $GLOBALS["mc_api_key"] = $username_or_apikey;
47
        }  else {
48
            $this->api_key = $this->callServer("login", array("username" => $username_or_apikey, "password" => $password));
49
            $GLOBALS["mc_api_key"] = $this->api_key;
50
        }
51
    }
52
    function setTimeout($seconds){
53
        if (is_int($seconds)){
54
            $this->timeout = $seconds;
55
            return true;
56
        }
57
    }
58
    function getTimeout(){
59
        return $this->timeout;
60
    }
61
    function useSecure($val){
62
        if ($val===true){
63
            $this->secure = true;
64
        } else {
65
            $this->secure = false;
66
        }
67
    }
68
69
    /**
70
     * Unschedule a campaign that is scheduled to be sent in the future
71
     *
72
     * @section Campaign  Related
73
     * @example mcapi_campaignUnschedule.php
74
     * @example xml-rpc_campaignUnschedule.php
75
     *
76
     * @param string $cid the id of the campaign to unschedule
77
     * @return boolean true on success
78
     */
79
    function campaignUnschedule($cid) {
80
        $params = array();
81
        $params["cid"] = $cid;
82
        return $this->callServer("campaignUnschedule", $params);
83
    }
84
85
    /**
86
     * Schedule a campaign to be sent in the future
87
     *
88
     * @section Campaign  Related
89
     * @example mcapi_campaignSchedule.php
90
     * @example xml-rpc_campaignSchedule.php
91
     *
92
     * @param string $cid the id of the campaign to schedule
93
     * @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>
94
     * @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>
95
     * @return boolean true on success
96
     */
97
    function campaignSchedule($cid, $schedule_time, $schedule_time_b=NULL) {
98
        $params = array();
99
        $params["cid"] = $cid;
100
        $params["schedule_time"] = $schedule_time;
101
        $params["schedule_time_b"] = $schedule_time_b;
102
        return $this->callServer("campaignSchedule", $params);
103
    }
104
105
    /**
106
     * Resume sending an AutoResponder or RSS campaign
107
     *
108
     * @section Campaign  Related
109
     *
110
     * @param string $cid the id of the campaign to pause
111
     * @return boolean true on success
112
     */
113
    function campaignResume($cid) {
114
        $params = array();
115
        $params["cid"] = $cid;
116
        return $this->callServer("campaignResume", $params);
117
    }
118
119
    /**
120
     * Pause an AutoResponder orRSS campaign from sending
121
     *
122
     * @section Campaign  Related
123
     *
124
     * @param string $cid the id of the campaign to pause
125
     * @return boolean true on success
126
     */
127
    function campaignPause($cid) {
128
        $params = array();
129
        $params["cid"] = $cid;
130
        return $this->callServer("campaignPause", $params);
131
    }
132
133
    /**
134
     * Send a given campaign immediately
135
     *
136
     * @section Campaign  Related
137
     *
138
     * @example mcapi_campaignSendNow.php
139
     * @example xml-rpc_campaignSendNow.php
140
     *
141
     * @param string $cid the id of the campaign to resume
142
     * @return boolean true on success
143
     */
144
    function campaignSendNow($cid) {
145
        $params = array();
146
        $params["cid"] = $cid;
147
        return $this->callServer("campaignSendNow", $params);
148
    }
149
150
    /**
151
     * Send a test of this campaign to the provided email address
152
     *
153
     * @section Campaign  Related
154
     *
155
     * @example mcapi_campaignSendTest.php
156
     * @example xml-rpc_campaignSendTest.php
157
     *
158
     * @param string $cid the id of the campaign to test
159
     * @param array $test_emails an array of email address to receive the test message
160
     * @param string $send_type optional by default (null) both formats are sent - "html" or "text" send just that format
161
     * @return boolean true on success
162
     */
163
    function campaignSendTest($cid, $test_emails=array (
164
), $send_type=NULL) {
165
        $params = array();
166
        $params["cid"] = $cid;
167
        $params["test_emails"] = $test_emails;
168
        $params["send_type"] = $send_type;
169
        return $this->callServer("campaignSendTest", $params);
170
    }
171
172
    /**
173
     * Retrieve all templates defined for your user account
174
     *
175
     * @section Campaign  Related
176
     * @example mcapi_campaignTemplates.php
177
     * @example xml-rpc_campaignTemplates.php
178
     *
179
     * @return array An array of structs, one for each template (see Returned Fields for details)
180
     * @returnf integer id Id of the template
181
     * @returnf string name Name of the template
182
     * @returnf string layout Layout of the template - "basic", "left_column", "right_column", or "postcard"
183
     * @returnf array sections associative array of editable sections in the template that can accept custom HTML when sending a campaign
184
     */
185
    function campaignTemplates() {
186
        $params = array();
187
        return $this->callServer("campaignTemplates", $params);
188
    }
189
190
    /**
191
     * Allows one to test their segmentation rules before creating a campaign using them
192
     *
193
     * @section Campaign  Related
194
     * @example mcapi_campaignSegmentTest.php
195
     * @example xml-rpc_campaignSegmentTest.php
196
     *
197
     * @param string $list_id the list to test segmentation on - get lists using lists()
198
     * @param array $options with 2 keys:
199
             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)
200
             array "conditions" - up to 10 different criteria to apply while segmenting. Each criteria row must contain 3 keys - "<strong>field</strong>", "<strong>op</strong>", and "<strong>value</strong>" - and possibly a fourth, "<strong>extra</strong>", based on these definitions:
201
202
            Field = "<strong>date</strong>" : Select based on various dates we track
203
                Valid Op(eration): <strong>eq</strong> (is) / <strong>gt</strong> (after) / <strong>lt</strong> (before)
204
                Valid Values:
205
                string last_campaign_sent  uses the date of the last campaign sent
206
                string campaign_id - uses the send date of the campaign that carriers the Id submitted - see campaigns()
207
                string YYYY-MM-DD - any date in the form of YYYY-MM-DD - <em>note:</em> anything that appears to start with YYYY will be treated as a date
208
209
            Field = "<strong>interests</strong>":
210
                Valid Op(erations): <strong>one</strong> / <strong>none</strong> / <strong>all</strong>
211
                Valid Values: a comma delimited of interest groups for the list - see listInterestGroups()
212
213
            Field = "<strong>aim</strong>"
214
                Valid Op(erations): <strong>open</strong> / <strong>noopen</strong> / <strong>click</strong> / <strong>noclick</strong>
215
                Valid Values: "<strong>any</strong>" or a valid AIM-enabled Campaign that has been sent
216
217
            Field = "<strong>rating</strong>" : allows matching based on list member ratings
218
                Valid Op(erations):  <strong>eq</strong> (=) / <strong>ne</strong> (!=) / <strong>gt</strong> (&gt;) / <strong>lt</strong> (&lt;)
219
                Valid Values: a number between 0 and 5
220
221
            Field = "<strong>ecomm_prod</strong>" or "<strong>ecomm_prod</strong>": allows matching product and category names from purchases
222
                Valid Op(erations):
223
                 <strong>eq</strong> (=) / <strong>ne</strong> (!=) / <strong>gt</strong> (&gt;) / <strong>lt</strong> (&lt;) / <strong>like</strong> (like '%blah%') / <strong>nlike</strong> (not like '%blah%') / <strong>starts</strong> (like 'blah%') / <strong>ends</strong> (like '%blah')
224
                Valid Values: any string
225
226
            Field = "<strong>ecomm_spent_one</strong>" or "<strong>ecomm_spent_all</strong>" : allows matching purchase amounts on a single order or all orders
227
                Valid Op(erations): <strong>gt</strong> (&gt;) / <strong>lt</strong> (&lt;)
228
                Valid Values: a number
229
230
            Field = "<strong>ecomm_date</strong>" : allow matching based on order dates
231
                Valid Op(eration): <strong>eq</strong> (is) / <strong>gt</strong> (after) / <strong>lt</strong> (before)
232
                Valid Values:
233
                string YYYY-MM-DD - any date in the form of YYYY-MM-DD
234
235
            Field = An <strong>Address</strong> Merge Var. Use <strong>Merge0-Merge30</strong> or the <strong>Custom Tag</strong> you've setup for your merge field - see listMergeVars(). Note, Address fields can still be used with the default operations below - this section is broken out solely to highlight the differences in using the geolocation routines.
236
                Valid Op(erations): <strong>geoin</strong>
237
                Valid Values: The number of miles an address should be within
238
                Extra Value: The Zip Code to be used as the center point
239
240
            Default Field = A Merge Var. Use <strong>Merge0-Merge30</strong> or the <strong>Custom Tag</strong> you've setup for your merge field - see listMergeVars()
241
                Valid Op(erations):
242
                 <strong>eq</strong> (=) / <strong>ne</strong> (!=) / <strong>gt</strong> (&gt;) / <strong>lt</strong> (&lt;) / <strong>like</strong> (like '%blah%') / <strong>nlike</strong> (not like '%blah%') / <strong>starts</strong> (like 'blah%') / <strong>ends</strong> (like '%blah')
243
                Valid Values: any string
244
     * @return integer total The total number of subscribers matching your segmentation options
245
     */
246
    function campaignSegmentTest($list_id, $options) {
247
        $params = array();
248
        $params["list_id"] = $list_id;
249
        $params["options"] = $options;
250
        return $this->callServer("campaignSegmentTest", $params);
251
    }
252
253
    /**
254
     * Create a new draft campaign to send
255
     *
256
     * @section Campaign  Related
257
     * @example mcapi_campaignCreate.php
258
     * @example xml-rpc_campaignCreate.php
259
     * @example xml-rpc_campaignCreateABSplit.php
260
     * @example xml-rpc_campaignCreateRss.php
261
     *
262
     * @param string $type the Campaign Type to create - one of "regular", "plaintext", "absplit", "rss", "trans", "auto"
263
     * @param array $options a hash of the standard options for this campaign :
264
            string list_id the list to send this campaign to- get lists using lists()
265
            string subject the subject line for your campaign message
266
            string from_email the From: email address for your campaign message
267
            string from_name the From: name for your campaign message (not an email address)
268
            string to_email the To: name recipients will see (not email address)
269
            integer template_id optional - use this template to generate the HTML content of the campaign
270
            integer folder_id optional - automatically file the new campaign in the folder_id passed
271
            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.
272
            string title optional - an internal name to use for this campaign.  By default, the campaign subject will be used.
273
            boolean authenticate optional - set to true to enable SenderID, DomainKeys, and DKIM authentication, defaults to false.
274
            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
275
            boolean auto_footer optional Whether or not we should auto-generate the footer for your content. Mostly useful for content from URLs or Imports
276
            boolean inline_css optional Whether or not css should be automatically inlined when this campaign is sent, defaults to false.
277
            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.
278
279
    * @param array $content the content for this campaign - use a struct with the following keys:
280
                "html" for pasted HTML content
281
                "text" for the plain-text version
282
                "url" to have us pull in content from a URL. Note, this will override any other content options - for lists with Email Format options, you'll need to turn on generate_text as well
283
                "archive" to send a Base64 encoded archive file for us to import all media from. Note, this will override any other content options - for lists with Email Format options, you'll need to turn on generate_text as well
284
                "archive_type" optional - only necessary for the "archive" option. Supported formats are: zip, tar.gz, tar.bz2, tar, tgz, tbz . If not included, we will default to zip
285
286
287
                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"
288
    * @param array $segment_opts optional - if you wish to do Segmentation with this campaign this array should contain: see campaignSegmentTest(). It's suggested that you test your options against campaignSegmentTest(). Also, "trans" campaigns <strong>do not</strong> support segmentation.
289
    * @param array $type_opts optional -
290
            For RSS Campaigns this, array should contain:
291
                string url the URL to pull RSS content from - it will be verified and must exist
292
                string schedule optional one of "daily", "weekly", "monthly" - defaults to "daily"
293
                string schedule_hour optional an hour between 0 and 24 - default to 4 (4am <em>local time</em>) - applies to all schedule types
294
                string schedule_weekday optional for "weekly" only, a number specifying the day of the week to send: 0 (Sunday) - 6 (Saturday) - defaults to 1 (Monday)
295
                string schedule_monthday optional for "monthly" only, a number specifying the day of the month to send (1 - 28) or "last" for the last day of a given month. Defaults to the 1st day of the month
296
297
            For A/B Split campaigns, this array should contain:
298
                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!
299
                string pick_winner How the winner will be picked, one of: "opens" (by the open_rate), "clicks" (by the click rate), "manual" (you pick manually)
300
                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.
301
                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.
302
                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%
303
                string from_name_a optional sort of, required when split_test is "from_name"
304
                string from_name_b optional sort of, required when split_test is "from_name"
305
                string from_email_a optional sort of, required when split_test is "from_name"
306
                string from_email_b optional sort of, required when split_test is "from_name"
307
                string subject_a optional sort of, required when split_test is "subject"
308
                string subject_b optional sort of, required when split_test is "subject"
309
310
            For AutoResponder campaigns, this array should contain:
311
                string offset-units one of "day", "week", "month", "year" - required
312
                string offset-time the number of units, must be a number greater than 0 - required
313
                string offset-dir either "before" or "after"
314
                string event optional "signup" (default) to base this on double-optin signup, "date" or "annual" to base this on merge field in the list
315
                string event-datemerge optional sort of, this is required if the event is "date" or "annual"
316
317
     *
318
     * @return string the ID for the created campaign
319
     */
320
    function campaignCreate($type, $options, $content, $segment_opts=NULL, $type_opts=NULL) {
321
        $params = array();
322
        $params["type"] = $type;
323
        $params["options"] = $options;
324
        $params["content"] = $content;
325
        $params["segment_opts"] = $segment_opts;
326
        $params["type_opts"] = $type_opts;
327
        return $this->callServer("campaignCreate", $params);
328
    }
329
330
    /** Update just about any setting for a campaign that has <em>not</em> been sent. See campaignCreate() for details
331
     *
332
     *  Caveats:<br/><ul>
333
     *        <li>If you set list_id, all segmentation options will be deleted and must be re-added.</li>
334
     *        <li>If you set template_id, you need to follow that up by setting it's 'content'</li>
335
     *        <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>
336
     * @section Campaign  Related
337
     *
338
     * @example mcapi_campaignUpdate.php
339
     * @example mcapi_campaignUpdateAB.php
340
     * @example xml-rpc_campaignUpdate.php
341
     * @example xml-rpc_campaignUpdateAB.php
342
     *
343
     * @param string $cid the Campaign Id to update
344
     * @param string $name the parameter name ( see campaignCreate() )
345
     * @param mixed  $value an appropriate value for the parameter ( see campaignCreate() )
346
     * @return boolean true if the update succeeds, otherwise an error will be thrown
347
     */
348
    function campaignUpdate($cid, $name, $value) {
349
        $params = array();
350
        $params["cid"] = $cid;
351
        $params["name"] = $name;
352
        $params["value"] = $value;
353
        return $this->callServer("campaignUpdate", $params);
354
    }
355
356
    /** Replicate a campaign.
357
    *
358
    * @section Campaign  Related
359
    *
360
    * @example mcapi_campaignReplicate.php
361
    *
362
    * @param string $cid the Campaign Id to replicate
363
    * @return string the id of the replicated Campaign created, otherwise an error will be thrown
364
    */
365
    function campaignReplicate($cid) {
366
        $params = array();
367
        $params["cid"] = $cid;
368
        return $this->callServer("campaignReplicate", $params);
369
    }
370
371
    /** Delete a campaign. Seriously, "poof, gone!" - be careful!
372
    *
373
    * @section Campaign  Related
374
    *
375
    * @example mcapi_campaignDelete.php
376
    *
377
    * @param string $cid the Campaign Id to delete
378
    * @return boolean true if the delete succeeds, otherwise an error will be thrown
379
    */
380
    function campaignDelete($cid) {
381
        $params = array();
382
        $params["cid"] = $cid;
383
        return $this->callServer("campaignDelete", $params);
384
    }
385
386
    /**
387
     * Get the list of campaigns and their details matching the specified filters
388
     *
389
     * @section Campaign  Related
390
     * @example mcapi_campaigns.php
391
     * @example xml-rpc_campaigns.php
392
     *
393
     * @param array $filters a hash of filters to apply to this query - all are optional:
394
            string  campaign_id optional - return a single campaign using a know campaign_id
395
            string  list_id optional - the list to send this campaign to- get lists using lists()
396
            integer folder_id optional - only show campaigns from this folder id - get folders using campaignFolders()
397
            string  type optional - return campaigns of a specific type - one of "regular", "plaintext", "absplit", "rss", "trans", "auto"
398
            string  from_name optional - only show campaigns that have this "From Name"
399
            string  from_email optional - only show campaigns that have this "Reply-to Email"
400
            string  title optional - only show campaigns that have this title
401
            string  subject optional - only show campaigns that have this subject
402
            string  sendtime_start optional - only show campaigns that have been sent since this date/time (in GMT) - format is YYYY-MM-DD HH:mm:ss (24hr)
403
            string  sendtime_end optional - only show campaigns that have been sent before this date/time (in GMT) - format is YYYY-MM-DD HH:mm:ss (24hr)
404
            boolean exact optional - flag for whether to filter on exact values when filtering, or search within content for filter values - defaults to true
405
     * @param integer $start optional - control paging of campaigns, start results at this campaign #, defaults to 1st page of data  (page 0)
406
     * @param integer $limit optional - control paging of campaigns, number of campaigns to return with each call, defaults to 25 (max=1000)
407
     * @return array list of campaigns and their associated information (see Returned Fields for description)
408
     * @returnf string id Campaign Id (used for all other campaign functions)
409
     * @returnf integer web_id The Campaign id used in our web app, allows you to create a link directly to it
410
     * @returnf string title Title of the campaign
411
     * @returnf string type The type of campaign this is (regular,plaintext,absplit,rss,inspection,trans,auto)
412
     * @returnf date create_time Creation time for the campaign
413
     * @returnf date send_time Send time for the campaign
414
     * @returnf integer emails_sent Number of emails email was sent to
415
     * @returnf string status Status of the given campaign (save,paused,schedule,sending,sent)
416
     * @returnf string from_name From name of the given campaign
417
     * @returnf string from_email Reply-to email of the given campaign
418
     * @returnf string subject Subject of the given campaign
419
     * @returnf string to_email Custom "To:" email string using merge variables
420
     * @returnf string archive_url Archive link for the given campaign
421
     * @returnf boolean inline_css Whether or not the campaigns content auto-css-lined
422
     * @returnf string analytics Either "google" if enabled or "N" if disabled
423
     * @returnf string analytcs_tag The name/tag the campaign's links were tagged with if analytics were enabled.
424
     * @returnf boolean track_clicks_text Whether or not links in the text version of the campaign were tracked
425
     * @returnf boolean track_clicks_html Whether or not links in the html version of the campaign were tracked
426
     * @returnf boolean track_opens Whether or not opens for the campaign were tracked
427
     * @returnf array segment_opts the segment used for the campaign - can be passed to campaignSegmentTest() or campaignCreate()
428
     */
429
    function campaigns($filters=array (
430
), $start=0, $limit=25) {
431
        $params = array();
432
        $params["filters"] = $filters;
433
        $params["start"] = $start;
434
        $params["limit"] = $limit;
435
        return $this->callServer("campaigns", $params);
436
    }
437
438
    /**
439
     * List all the folders for a user account
440
     *
441
     * @section Campaign  Related
442
     * @example mcapi_campaignFolders.php
443
     * @example xml-rpc_campaignFolders.php
444
     *
445
     * @return array Array of folder structs (see Returned Fields for details)
446
     * @returnf integer folder_id Folder Id for the given folder, this can be used in the campaigns() function to filter on.
447
     * @returnf string name Name of the given folder
448
     */
449
    function campaignFolders() {
450
        $params = array();
451
        return $this->callServer("campaignFolders", $params);
452
    }
453
454
    /**
455
     * Given a list and a campaign, get all the relevant campaign statistics (opens, bounces, clicks, etc.)
456
     *
457
     * @section Campaign  Stats
458
     *
459
     * @example mcapi_campaignStats.php
460
     * @example xml-rpc_campaignStats.php
461
     *
462
     * @param string $cid the campaign id to pull stats for (can be gathered using campaigns())
463
     * @return array struct of the statistics for this campaign
464
     * @returnf integer syntax_errors Number of email addresses in campaign that had syntactical errors.
465
     * @returnf integer hard_bounces Number of email addresses in campaign that hard bounced.
466
     * @returnf integer soft_bounces Number of email addresses in campaign that soft bounced.
467
     * @returnf integer unsubscribes Number of email addresses in campaign that unsubscribed.
468
     * @returnf integer abuse_reports Number of email addresses in campaign that reported campaign for abuse.
469
     * @returnf integer forwards Number of times email was forwarded to a friend.
470
     * @returnf integer forwards_opens Number of times a forwarded email was opened.
471
     * @returnf integer opens Number of times the campaign was opened.
472
     * @returnf date last_open Date of the last time the email was opened.
473
     * @returnf integer unique_opens Number of people who opened the campaign.
474
     * @returnf integer clicks Number of times a link in the campaign was clicked.
475
     * @returnf integer unique_clicks Number of unique recipient/click pairs for the campaign.
476
     * @returnf date last_click Date of the last time a link in the email was clicked.
477
     * @returnf integer users_who_clicked Number of unique recipients who clicked on a link in the campaign.
478
     * @returnf integer emails_sent Number of email addresses campaign was sent to.
479
     */
480
    function campaignStats($cid) {
481
        $params = array();
482
        $params["cid"] = $cid;
483
        return $this->callServer("campaignStats", $params);
484
    }
485
486
    /**
487
     * Get an array of the urls being tracked, and their click counts for a given campaign
488
     *
489
     * @section Campaign  Stats
490
     *
491
     * @example mcapi_campaignClickStats.php
492
     * @example xml-rpc_campaignClickStats.php
493
     *
494
     * @param string $cid the campaign id to pull stats for (can be gathered using campaigns())
495
     * @return struct urls will be keys and contain their associated statistics:
496
     * @returnf integer clicks Number of times the specific link was clicked
497
     * @returnf integer unique Number of unique people who clicked on the specific link
498
     */
499
    function campaignClickStats($cid) {
500
        $params = array();
501
        $params["cid"] = $cid;
502
        return $this->callServer("campaignClickStats", $params);
503
    }
504
505
    /**
506
     * Get the top 5 performing email domains for this campaign. Users want more than 5 should use campaign campaignEmailStatsAIM()
507
     * or campaignEmailStatsAIMAll() and generate any additional stats they require.
508
     *
509
     * @section Campaign  Stats
510
     *
511
     * @example mcapi_campaignEmailDomainPerformance.php
512
     *
513
     * @param string $cid the campaign id to pull email domain performance for (can be gathered using campaigns())
514
     * @return array domains email domains and their associated stats
515
     * @returnf string domain Domain name or special "Other" to roll-up stats past 5 domains
516
     * @returnf integer total_sent Total Email across all domains - this will be the same in every row
517
     * @returnf integer emails Number of emails sent to this domain
518
     * @returnf integer bounces Number of bounces
519
     * @returnf integer opens Number of opens
520
     * @returnf integer clicks Number of clicks
521
     * @returnf integer unsubs Number of unsubs
522
     * @returnf integer delivered Number of deliveries
523
     * @returnf integer emails_pct Percentage of emails that went to this domain (whole number)
524
     * @returnf integer bounces_pct Percentage of bounces from this domain (whole number)
525
     * @returnf integer opens_pct Percentage of opens from this domain (whole number)
526
     * @returnf integer clicks_pct Percentage of clicks from this domain (whole number)
527
     * @returnf integer unsubs_pct Percentage of unsubs from this domain (whole number)
528
     */
529
    function campaignEmailDomainPerformance($cid) {
530
        $params = array();
531
        $params["cid"] = $cid;
532
        return $this->callServer("campaignEmailDomainPerformance", $params);
533
    }
534
535
    /**
536
     * Get all email addresses with Hard Bounces for a given campaign
537
     *
538
     * @section Campaign  Stats
539
     *
540
     * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
541
     * @param integer    $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
542
     * @param integer    $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
543
     * @return array Arrays of email addresses with Hard Bounces
544
     */
545
    function campaignHardBounces($cid, $start=0, $limit=1000) {
546
        $params = array();
547
        $params["cid"] = $cid;
548
        $params["start"] = $start;
549
        $params["limit"] = $limit;
550
        return $this->callServer("campaignHardBounces", $params);
551
    }
552
553
    /**
554
     * Get all email addresses with Soft Bounces for a given campaign
555
     *
556
     * @section Campaign  Stats
557
     *
558
     * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
559
     * @param integer    $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
560
     * @param integer    $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
561
     * @return array Arrays of email addresses with Soft Bounces
562
     */
563
    function campaignSoftBounces($cid, $start=0, $limit=1000) {
564
        $params = array();
565
        $params["cid"] = $cid;
566
        $params["start"] = $start;
567
        $params["limit"] = $limit;
568
        return $this->callServer("campaignSoftBounces", $params);
569
    }
570
571
    /**
572
     * Get all unsubscribed email addresses for a given campaign
573
     *
574
     * @section Campaign  Stats
575
     *
576
     * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
577
     * @param integer    $start optional for large data sets, the page number to start at - defaults to 1st page of data  (page 0)
578
     * @param integer    $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
579
     * @return array list of email addresses that unsubscribed from this campaign
580
     */
581
    function campaignUnsubscribes($cid, $start=0, $limit=1000) {
582
        $params = array();
583
        $params["cid"] = $cid;
584
        $params["start"] = $start;
585
        $params["limit"] = $limit;
586
        return $this->callServer("campaignUnsubscribes", $params);
587
    }
588
589
    /**
590
     * Get all email addresses that complained about a given campaign
591
     *
592
     * @section Campaign  Stats
593
     *
594
     * @example mcapi_campaignAbuseReports.php
595
     *
596
     * @param string $cid the campaign id to pull abuse reports for (can be gathered using campaigns())
597
     * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data  (page 0)
598
     * @param integer $limit optional for large data sets, the number of results to return - defaults to 500, upper limit set at 1000
599
     * @param string $since optional pull only messages since this time - use YYYY-MM-DD HH:II:SS format in <strong>GMT</strong>
600
     * @return array reports the abuse reports for this campaign
601
     * @returnf string date date/time the abuse report was received and processed
602
     * @returnf string email the email address that reported abuse
603
     * @returnf string type an internal type generally specifying the orginating mail provider - may not be useful outside of filling report views
604
     */
605 View Code Duplication
    function campaignAbuseReports($cid, $since=NULL, $start=0, $limit=500) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
606
        $params = array();
607
        $params["cid"] = $cid;
608
        $params["since"] = $since;
609
        $params["start"] = $start;
610
        $params["limit"] = $limit;
611
        return $this->callServer("campaignAbuseReports", $params);
612
    }
613
614
    /**
615
     * Retrieve the text presented in our app for how a campaign performed and any advice we may have for you - best
616
     * suited for display in customized reports pages. Note: some messages will contain HTML - clean tags as necessary
617
     *
618
     * @section Campaign  Stats
619
     *
620
     * @example mcapi_campaignAdvice.php
621
     *
622
     * @param string $cid the campaign id to pull advice text for (can be gathered using campaigns())
623
     * @return array advice on the campaign's performance
624
     * @returnf msg the advice message
625
     * @returnf type the "type" of the message. one of: negative, positive, or neutral
626
     */
627
    function campaignAdvice($cid) {
628
        $params = array();
629
        $params["cid"] = $cid;
630
        return $this->callServer("campaignAdvice", $params);
631
    }
632
633
    /**
634
     * Retrieve the Google Analytics data we've collected for this campaign. Note, requires Google Analytics Add-on to be installed and configured.
635
     *
636
     * @section Campaign  Stats
637
     *
638
     * @example mcapi_campaignAnalytics.php
639
     *
640
     * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
641
     * @return array analytics we've collected for the passed campaign.
642
     * @returnf integer visits number of visits
643
     * @returnf integer pages number of page views
644
     * @returnf integer new_visits new visits recorded
645
     * @returnf integer bounces vistors who "bounced" from your site
646
     * @returnf double time_on_site
647
     * @returnf integer goal_conversions number of goals converted
648
     * @returnf double goal_value value of conversion in dollars
649
     * @returnf double revenue revenue generated by campaign
650
     * @returnf integer transactions number of transactions tracked
651
     * @returnf integer ecomm_conversions number Ecommerce transactions tracked
652
     * @returnf array goals an array containing goal names and number of conversions
653
     */
654
    function campaignAnalytics($cid) {
655
        $params = array();
656
        $params["cid"] = $cid;
657
        return $this->callServer("campaignAnalytics", $params);
658
    }
659
660
    /**
661
     * Retrieve the full bounce messages for the given campaign. Note that this can return very large amounts
662
     * of data depending on how large the campaign was and how much cruft the bounce provider returned. Also,
663
     * message over 30 days old are subject to being removed
664
     *
665
     * @section Campaign  Stats
666
     *
667
     * @example mcapi_campaignBounceMessages.php
668
     *
669
     * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
670
     * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data  (page 0)
671
     * @param integer $limit optional for large data sets, the number of results to return - defaults to 25, upper limit set at 50
672
     * @param string $since optional pull only messages since this time - use YYYY-MM-DD format in <strong>GMT</strong> (we only store the date, not the time)
673
     * @return array bounces the full bounce messages for this campaign
674
     * @returnf string date date/time the bounce was received and processed
675
     * @returnf string email the email address that bounced
676
     * @returnf string message the entire bounce message received
677
     */
678 View Code Duplication
    function campaignBounceMessages($cid, $start=0, $limit=25, $since=NULL) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
679
        $params = array();
680
        $params["cid"] = $cid;
681
        $params["start"] = $start;
682
        $params["limit"] = $limit;
683
        $params["since"] = $since;
684
        return $this->callServer("campaignBounceMessages", $params);
685
    }
686
687
    /**
688
     * Retrieve the Ecommerce Orders tracked by campaignEcommAddOrder()
689
     *
690
     * @section Campaign  Stats
691
     *
692
     * @param string $cid the campaign id to pull bounces for (can be gathered using campaigns())
693
     * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data  (page 0)
694
     * @param integer $limit optional for large data sets, the number of results to return - defaults to 100, upper limit set at 500
695
     * @param string $since optional pull only messages since this time - use YYYY-MM-DD HH:II:SS format in <strong>GMT</strong>
696
     * @return array orders the orders and their details that we've collected for this campaign
697
     * @returnf store_id string the store id generated by the plugin used to uniquely identify a store
698
     * @returnf store_name string the store name collected by the plugin - often the domain name
699
     * @returnf order_id string the internal order id the store tracked this order by
700
     * @returnf email string the email address that received this campaign and is associated with this order
701
     * @returnf order_total double the order total
702
     * @returnf tax_total double the total tax for the order (if collected)
703
     * @returnf ship_total double the shipping total for the order (if collected)
704
     * @returnf order_date string the date the order was tracked - from the store if possible, otherwise the GMT time we recieved it
705
     * @returnf lines array containing detail of the order - product, category, quantity, item cost
706
     */
707 View Code Duplication
    function campaignEcommOrders($cid, $start=0, $limit=100, $since=NULL) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
708
        $params = array();
709
        $params["cid"] = $cid;
710
        $params["start"] = $start;
711
        $params["limit"] = $limit;
712
        $params["since"] = $since;
713
        return $this->callServer("campaignEcommOrders", $params);
714
    }
715
716
    /**
717
     * Get the URL to a customized VIP Report for the specified campaign and optionally send an email to someone with links to it. Note subsequent calls will overwrite anything already set for the same campign (eg, the password)
718
     *
719
     * @section Campaign  Related
720
     *
721
     * @param string $cid the campaign id to share a report for (can be gathered using campaigns())
722
     * @param array  $opts optional various parameters which can be used to configure the shared report
723
            string  header_type optional - "text" or "image', defaults to "text'
724
            string  header_data optional - if "header_type" is text, the text to display. if "header_type" is "image" a valid URL to an image file. Note that images will be resized to be no more than 500x150. Defaults to the Accounts Company Name.
725
            bool    secure optional - whether to require a password for the shared report. defaults to "true"
726
            string  password optional - if secure is true and a password is not included, we will generate one. It is always returned.
727
            string  to_email optional - optional, email address to share the report with - no value means an email will not be sent
728
            array   theme  optional - an array containing either 3 or 6 character color code values for: "bg_color", "header_color", "current_tab", "current_tab_text", "normal_tab", "normal_tab_text", "hover_tab", "hover_tab_text"
729
            string  css_url    optional - a link to an external CSS file to be included after our default CSS (http://vip-reports.net/css/vip.css) <strong>only if</strong> loaded in an IFRAME - max 255 characters
730
     * @return struct Struct containing details for the shared report
731
     * @returnf string title The Title of the Campaign being shared
732
     * @returnf string url The URL to the shared report
733
     * @returnf string secure_url The URL to the shared report, including the password (good for loading in an IFRAME). For non-secure reports, this will not be returned
734
     * @returnf string password If secured, the password for the report, otherwise this field will not be returned
735
     */
736
    function campaignShareReport($cid, $opts=array (
737
)) {
738
        $params = array();
739
        $params["cid"] = $cid;
740
        $params["opts"] = $opts;
741
        return $this->callServer("campaignShareReport", $params);
742
    }
743
744
    /**
745
     * Get the content (both html and text) for a campaign either as it would appear in the campaign archive or as the raw, original content
746
     *
747
     * @section Campaign  Related
748
     *
749
     * @param string $cid the campaign id to get content for (can be gathered using campaigns())
750
     * @param bool   $for_archive optional controls whether we return the Archive version (true) or the Raw version (false), defaults to true
751
     * @return struct Struct containing all content for the campaign (see Returned Fields for details
752
     * @returnf string html The HTML content used for the campgain with merge tags intact
753
     * @returnf string text The Text content used for the campgain with merge tags intact
754
     */
755
    function campaignContent($cid, $for_archive=true) {
756
        $params = array();
757
        $params["cid"] = $cid;
758
        $params["for_archive"] = $for_archive;
759
        return $this->callServer("campaignContent", $params);
760
    }
761
762
    /**
763
     * Retrieve the list of email addresses that opened a given campaign with how many times they opened - note: this AIM function is free and does
764
     * not actually require the AIM module to be installed
765
     *
766
     * @section Campaign AIM
767
     *
768
     * @param string $cid the campaign id to get opens for (can be gathered using campaigns())
769
     * @param integer    $start optional for large data sets, the page number to start at - defaults to 1st page of data  (page 0)
770
     * @param integer    $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
771
     * @return array Array of structs containing email addresses and open counts
772
     * @returnf string email Email address that opened the campaign
773
     * @returnf integer open_count Total number of times the campaign was opened by this email address
774
     */
775
    function campaignOpenedAIM($cid, $start=0, $limit=1000) {
776
        $params = array();
777
        $params["cid"] = $cid;
778
        $params["start"] = $start;
779
        $params["limit"] = $limit;
780
        return $this->callServer("campaignOpenedAIM", $params);
781
    }
782
783
    /**
784
     * Retrieve the list of email addresses that did not open a given campaign
785
     *
786
     * @section Campaign AIM
787
     *
788
     * @param string $cid the campaign id to get no opens for (can be gathered using campaigns())
789
     * @param integer    $start optional for large data sets, the page number to start at - defaults to 1st page of data  (page 0)
790
     * @param integer    $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
791
     * @return array list of email addresses that did not open a campaign
792
     */
793
    function campaignNotOpenedAIM($cid, $start=0, $limit=1000) {
794
        $params = array();
795
        $params["cid"] = $cid;
796
        $params["start"] = $start;
797
        $params["limit"] = $limit;
798
        return $this->callServer("campaignNotOpenedAIM", $params);
799
    }
800
801
    /**
802
     * Return the list of email addresses that clicked on a given url, and how many times they clicked
803
     *
804
     * @section Campaign AIM
805
     *
806
     * @param string $cid the campaign id to get click stats for (can be gathered using campaigns())
807
     * @param string $url the URL of the link that was clicked on
808
     * @param integer    $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
809
     * @param integer    $limit optional for large data sets, the number of results to return - defaults to 1000, upper limit set at 15000
810
     * @return array Array of structs containing email addresses and click counts
811
     * @returnf string email Email address that opened the campaign
812
     * @returnf integer clicks Total number of times the URL was clicked on by this email address
813
     */
814
    function campaignClickDetailAIM($cid, $url, $start=0, $limit=1000) {
815
        $params = array();
816
        $params["cid"] = $cid;
817
        $params["url"] = $url;
818
        $params["start"] = $start;
819
        $params["limit"] = $limit;
820
        return $this->callServer("campaignClickDetailAIM", $params);
821
    }
822
823
    /**
824
     * Given a campaign and email address, return the entire click and open history with timestamps, ordered by time
825
     *
826
     * @section Campaign AIM
827
     *
828
     * @param string $cid the campaign id to get stats for (can be gathered using campaigns())
829
     * @param string $email_address the email address to check
830
     * @return array Array of structs containing the actions (opens and clicks) that the email took, with timestamps
831
     * @returnf string action The action taken (open or click)
832
     * @returnf date timestamp Time the action occurred
833
     * @returnf string url For clicks, the URL that was clicked
834
     */
835
    function campaignEmailStatsAIM($cid, $email_address) {
836
        $params = array();
837
        $params["cid"] = $cid;
838
        $params["email_address"] = $email_address;
839
        return $this->callServer("campaignEmailStatsAIM", $params);
840
    }
841
842
    /**
843
     * Given a campaign and correct paging limits, return the entire click and open history with timestamps, ordered by time,
844
     * for every user a campaign was delivered to.
845
     *
846
     * @section Campaign AIM
847
     * @example mcapi_campaignEmailStatsAIMAll.php
848
     *
849
     * @param string $cid the campaign id to get stats for (can be gathered using campaigns())
850
     * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
851
     * @param integer $limit optional for large data sets, the number of results to return - defaults to 100, upper limit set at 1000
852
     * @return array Array of structs containing actions  (opens and clicks) for each email, with timestamps
853
     * @returnf string action The action taken (open or click)
854
     * @returnf date timestamp Time the action occurred
855
     * @returnf string url For clicks, the URL that was clicked
856
     */
857
    function campaignEmailStatsAIMAll($cid, $start=0, $limit=100) {
858
        $params = array();
859
        $params["cid"] = $cid;
860
        $params["start"] = $start;
861
        $params["limit"] = $limit;
862
        return $this->callServer("campaignEmailStatsAIMAll", $params);
863
    }
864
865
    /**
866
     * Attach Ecommerce Order Information to a Campaign. This will generall be used by ecommerce package plugins
867
     * <a href="/plugins/ecomm360.phtml">that we provide</a> or by 3rd part system developers.
868
     * @section Campaign  Related
869
     *
870
     * @param array $order an array of information pertaining to the order that has completed. Use the following keys:
871
                string id the Order Id
872
                string campaign_id the Campaign Id to track this order with (see the "mc_cid" query string variable a campaign passes)
873
                string email_id the Email Id of the subscriber we should attach this order to (see the "mc_eid" query string variable a campaign passes)
874
                double total The Order Total (ie, the full amount the customer ends up paying)
875
                double shipping optional the total paid for Shipping Fees
876
                double tax optional the total tax paid
877
                string store_id a unique id for the store sending the order in
878
                string store_name optional a "nice" name for the store - typically the base web address (ie, "store.mailchimp.com"). We will automatically update this if it changes (based on store_id)
879
                string plugin_id the MailChimp assigned Plugin Id. Get yours by <a href="/api/register.php">registering here</a>
880
                array items the individual line items for an order using these keys:
881
                <div style="padding-left:30px"><table><tr><td colspan=*>
882
                    integer line_num optional the line number of the item on the order. We will generate these if they are not passed
883
                    integer product_id the store's internal Id for the product. Lines that do no contain this will be skipped
884
                    string product_name the product name for the product_id associated with this item. We will auto update these as they change (based on product_id)
885
                    integer category_id the store's internal Id for the (main) category associated with this product. Our testing has found this to be a "best guess" scenario
886
                    string category_name the category name for the category_id this product is in. Our testing has found this to be a "best guess" scenario. Our plugins walk the category heirarchy up and send "Root - SubCat1 - SubCat4", etc.
887
                    double qty the quantity of the item ordered
888
                    double cost the cost of a single item (ie, not the extended cost of the line)
889
                </td></tr></table></div>
890
     * @return bool true if the data is saved, otherwise an error is thrown.
891
     */
892
    function campaignEcommAddOrder($order) {
893
        $params = array();
894
        $params["order"] = $order;
895
        return $this->callServer("campaignEcommAddOrder", $params);
896
    }
897
898
    /**
899
     * Retrieve all of the lists defined for your user account
900
     *
901
     * @section List Related
902
     * @example mcapi_lists.php
903
     * @example xml-rpc_lists.php
904
     *
905
     * @return array list of your Lists and their associated information (see Returned Fields for description)
906
     * @returnf string id The list id for this list. This will be used for all other list management functions.
907
     * @returnf integer web_id The list id used in our web app, allows you to create a link directly to it
908
     * @returnf string name The name of the list.
909
     * @returnf date date_created The date that this list was created.
910
     * @returnf integer member_count The number of active members in the given list.
911
     * @returnf integer unsubscribe_count The number of members who have unsubscribed from the given list.
912
     * @returnf integer cleaned_count The number of members cleaned from the given list.
913
     * @returnf boolean email_type_option Whether or not the List supports multiple formats for emails or just HTML
914
     * @returnf string default_from_name Default From Name for campaigns using this list
915
     * @returnf string default_from_email Default From Email for campaigns using this list
916
     * @returnf string default_subject Default Subject Line for campaigns using this list
917
     * @returnf string default_language Default Language for this list's forms
918
     */
919
    function lists() {
920
        $params = array();
921
        return $this->callServer("lists", $params);
922
    }
923
924
    /**
925
     * Get the list of merge tags for a given list, including their name, tag, and required setting
926
     *
927
     * @section List Related
928
     * @example xml-rpc_listMergeVars.php
929
     *
930
     * @param string $id the list id to connect to. Get by calling lists()
931
     * @return array list of merge tags for the list
932
     * @returnf string name Name of the merge field
933
     * @returnf char req Denotes whether the field is required (Y) or not (N)
934
     * @returnf string tag The merge tag that's used for forms and listSubscribe() and listUpdateMember()
935
     */
936
    function listMergeVars($id) {
937
        $params = array();
938
        $params["id"] = $id;
939
        return $this->callServer("listMergeVars", $params);
940
    }
941
942
    /**
943
     * Add a new merge tag to a given list
944
     *
945
     * @section List Related
946
     * @example xml-rpc_listMergeVarAdd.php
947
     *
948
     * @param string $id the list id to connect to. Get by calling lists()
949
     * @param string $tag The merge tag to add, e.g. FNAME
950
     * @param string $name The long description of the tag being added, used for user displays
951
     * @param array $req optional Various options for this merge var. <em>note:</em> for historical purposes this can also take a "boolean"
952
                    string field_type optional one of: text, number, radio, dropdownn, date, address, phone, url, imageurl - defaults to text
953
                    boolean req optional indicates whether the field is required - defaults to false
954
                    boolean public optional indicates whether the field is displayed in public - defaults to true
955
                    boolean show optional indicates whether the field is displayed in the app's list member view - defaults to true
956
                    string default_value optional the default value for the field. See listSubscribe() for formatting info. Defaults to blank
957
                    array choices optional kind of - an array of strings to use as the choices for radio and dropdown type fields
958
959
     * @return bool true if the request succeeds, otherwise an error will be thrown
960
     */
961
    function listMergeVarAdd($id, $tag, $name, $req=array (
962
)) {
963
        $params = array();
964
        $params["id"] = $id;
965
        $params["tag"] = $tag;
966
        $params["name"] = $name;
967
        $params["req"] = $req;
968
        return $this->callServer("listMergeVarAdd", $params);
969
    }
970
971
    /**
972
     * Update most parameters for a merge tag on a given list. You cannot currently change the merge type
973
     *
974
     * @section List Related
975
     *
976
     * @param string $id the list id to connect to. Get by calling lists()
977
     * @param string $tag The merge tag to update
978
     * @param array $options The options to change for a merge var. See listMergeVarAdd() for valid options
979
     * @return bool true if the request succeeds, otherwise an error will be thrown
980
     */
981
    function listMergeVarUpdate($id, $tag, $options) {
982
        $params = array();
983
        $params["id"] = $id;
984
        $params["tag"] = $tag;
985
        $params["options"] = $options;
986
        return $this->callServer("listMergeVarUpdate", $params);
987
    }
988
989
    /**
990
     * Delete a merge tag from a given list and all its members. Seriously - the data is removed from all members as well!
991
     * Note that on large lists this method may seem a bit slower than calls you typically make.
992
     *
993
     * @section List Related
994
     * @example xml-rpc_listMergeVarDel.php
995
     *
996
     * @param string $id the list id to connect to. Get by calling lists()
997
     * @param string $tag The merge tag to delete
998
     * @return bool true if the request succeeds, otherwise an error will be thrown
999
     */
1000
    function listMergeVarDel($id, $tag) {
1001
        $params = array();
1002
        $params["id"] = $id;
1003
        $params["tag"] = $tag;
1004
        return $this->callServer("listMergeVarDel", $params);
1005
    }
1006
1007
    /**
1008
     * Get the list of interest groups for a given list, including the label and form information
1009
     *
1010
     * @section List Related
1011
     * @example xml-rpc_listInterestGroups.php
1012
     *
1013
     * @param string $id the list id to connect to. Get by calling lists()
1014
     * @return struct list of interest groups for the list
1015
     * @returnf string name Name for the Interest groups
1016
     * @returnf string form_field Gives the type of interest group: checkbox,radio,select
1017
     * @returnf array groups Array of the group names
1018
     */
1019
    function listInterestGroups($id) {
1020
        $params = array();
1021
        $params["id"] = $id;
1022
        return $this->callServer("listInterestGroups", $params);
1023
    }
1024
1025
    /** Add a single Interest Group - if interest groups for the List are not yet enabled, adding the first
1026
     *  group will automatically turn them on.
1027
     *
1028
     * @section List Related
1029
     * @example xml-rpc_listInterestGroupAdd.php
1030
     *
1031
     * @param string $id the list id to connect to. Get by calling lists()
1032
     * @param string $group_name the interest group to add
1033
     * @return bool true if the request succeeds, otherwise an error will be thrown
1034
     */
1035
    function listInterestGroupAdd($id, $group_name) {
1036
        $params = array();
1037
        $params["id"] = $id;
1038
        $params["group_name"] = $group_name;
1039
        return $this->callServer("listInterestGroupAdd", $params);
1040
    }
1041
1042
    /** Delete a single Interest Group - if the last group for a list is deleted, this will also turn groups for the list off.
1043
     *
1044
     * @section List Related
1045
     * @example xml-rpc_listInterestGroupDel.php
1046
     *
1047
     * @param string $id the list id to connect to. Get by calling lists()
1048
     * @param string $group_name the interest group to delete
1049
     * @return bool true if the request succeeds, otherwise an error will be thrown
1050
     */
1051
    function listInterestGroupDel($id, $group_name) {
1052
        $params = array();
1053
        $params["id"] = $id;
1054
        $params["group_name"] = $group_name;
1055
        return $this->callServer("listInterestGroupDel", $params);
1056
    }
1057
1058
    /** Change the name of an Interest Group
1059
     *
1060
     * @section List Related
1061
     *
1062
     * @param string $id the list id to connect to. Get by calling lists()
1063
     * @param string $old_name the interest group name to be changed
1064
     * @param string $new_name the new interest group name to be set
1065
     * @return bool true if the request succeeds, otherwise an error will be thrown
1066
     */
1067
    function listInterestGroupUpdate($id, $old_name, $new_name) {
1068
        $params = array();
1069
        $params["id"] = $id;
1070
        $params["old_name"] = $old_name;
1071
        $params["new_name"] = $new_name;
1072
        return $this->callServer("listInterestGroupUpdate", $params);
1073
    }
1074
1075
    /** Return the Webhooks configured for the given list
1076
     *
1077
     * @section List Related
1078
     *
1079
     * @param string $id the list id to connect to. Get by calling lists()
1080
     * @return array list of webhooks
1081
     * @returnf string url the URL for this Webhook
1082
     * @returnf array actions the possible actions and whether they are enabled
1083
     * @returnf array sources the possible sources and whether they are enabled
1084
     */
1085
    function listWebhooks($id) {
1086
        $params = array();
1087
        $params["id"] = $id;
1088
        return $this->callServer("listWebhooks", $params);
1089
    }
1090
1091
    /** Add a new Webhook URL for the given list
1092
     *
1093
     * @section List Related
1094
     *
1095
     * @param string $id the list id to connect to. Get by calling lists()
1096
     * @param string $url a valid URL for the Webhook - it will be validated. note that a url may only exist on a list once.
1097
     * @param array $actions optional a hash of actions to fire this Webhook for
1098
            boolean subscribe optional as subscribes occur, defaults to true
1099
            boolean unsubscribe optional as subscribes occur, defaults to true
1100
            boolean profile optional as profile updates occur, defaults to true
1101
            boolean cleaned optional as emails are cleaned from the list, defaults to true
1102
            boolean upemail optional when  subscribers change their email address, defaults to true
1103
     * @param array $sources optional a hash of sources to fire this Webhook for
1104
            boolean user optional user/subscriber initiated actions, defaults to true
1105
            boolean admin optional admin actions in our web app, defaults to true
1106
            boolean api optional actions that happen via API calls, defaults to false
1107
     * @return bool true if the call succeeds, otherwise an exception will be thrown
1108
     */
1109
    function listWebhookAdd($id, $url, $actions=array (
1110
), $sources=array (
1111
)) {
1112
        $params = array();
1113
        $params["id"] = $id;
1114
        $params["url"] = $url;
1115
        $params["actions"] = $actions;
1116
        $params["sources"] = $sources;
1117
        return $this->callServer("listWebhookAdd", $params);
1118
    }
1119
1120
    /** Delete an existing Webhook URL from a given list
1121
     *
1122
     * @section List Related
1123
     *
1124
     * @param string $id the list id to connect to. Get by calling lists()
1125
     * @param string $url the URL of a Webhook on this list
1126
     * @return boolean true if the call succeeds, otherwise an exception will be thrown
1127
     */
1128
    function listWebhookDel($id, $url) {
1129
        $params = array();
1130
        $params["id"] = $id;
1131
        $params["url"] = $url;
1132
        return $this->callServer("listWebhookDel", $params);
1133
    }
1134
1135
    /**
1136
     * Subscribe the provided email to a list. By default this sends a confirmation email - you will not see new members until the link contained in it is clicked!
1137
     *
1138
     * @section List Related
1139
     *
1140
     * @example mcapi_listSubscribe.php
1141
     * @example xml-rpc_listSubscribe.php
1142
     *
1143
     * @param string $id the list id to connect to. Get by calling lists()
1144
     * @param string $email_address the email address to subscribe
1145
     * @param array $merge_vars array of merges for the email (FNAME, LNAME, etc.) (see examples below for handling "blank" arrays). Note that a merge field can only hold up to 255 characters. Also, there are 2 "special" keys:
1146
                        string INTERESTS Set Interest Groups by passing a field named "INTERESTS" that contains a comma delimited list of Interest Groups to add. Commas in Interest Group names should be escaped with a backslash. ie, "," =&gt; "\,"
1147
                        string OPTINIP Set the Opt-in IP fields. <em>Abusing this may cause your account to be suspended.</em> We do validate this and it must not be a private IP address.
1148
1149
                        <strong>Handling Field Data Types</strong> - most fields you can just pass a string and all is well. For some, though, that is not the case...
1150
                        Field values should be formatted as follows:
1151
                        string address For the string version of an Address, the fields should be delimited by <strong>2</strong> spaces. Address 2 can be skipped. The Country should be a 2 character ISO-3166-1 code and will default to your default country if not set
1152
                        array address For the array version of an Address, the requirements for Address 2 and Country are the same as with the string version. Then simply pass us an array with the keys <strong>addr1</strong>, <strong>addr2</strong>, <strong>city</strong>, <strong>state</strong>, <strong>zip</strong>, <strong>country</strong> and appropriate values for each
1153
1154
                        string date use YYYY-MM-DD to be safe. Generally, though, anything strtotime() understands we'll understand - <a href="http://us2.php.net/strtotime" target="_blank">http://us2.php.net/strtotime</a>
1155
                        string dropdown can be a normal string - we <em>will</em> validate that the value is a valid option
1156
                        string image must be a valid, existing url. we <em>will</em> check its existence
1157
                        string multi_choice can be a normal string - we <em>will</em> validate that the value is a valid option
1158
                        double number pass in a valid number - anything else will turn in to zero (0). Note, this will be rounded to 2 decimal places
1159
                        string phone If your account has the US Phone numbers option set, this <em>must</em> be in the form of NPA-NXX-LINE (404-555-1212). If not, we assume an International number and will simply set the field with what ever number is passed in.
1160
                        string website This is a standard string, but we <em>will</em> verify that it looks like a valid URL
1161
1162
1163
1164
     * @param string $email_type optional - email type preference for the email (html, text, or mobile defaults to html)
1165
     * @param boolean $double_optin optional - flag to control whether a double opt-in confirmation message is sent, defaults to true. <em>Abusing this may cause your account to be suspended.</em>
1166
     * @param boolean $update_existing optional - flag to control whether a existing subscribers should be updated instead of throwing and error
1167
     * @param boolean $replace_interests - flag to determine whether we replace the interest groups with the groups provided, or we add the provided groups to the member's interest groups (optional, defaults to true)
1168
     * @param boolean $send_welcome - if your double_optin is false and this is true, we will send your lists Welcome Email if this subscribe succeeds - this will *not* fire if we end up updating an existing subscriber. defaults to false
1169
1170
     * @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)
1171
     */
1172
    function listSubscribe($id, $email_address, $merge_vars, $email_type='html', $double_optin=true, $update_existing=false, $replace_interests=true, $send_welcome=false) {
1173
        $params = array();
1174
        $params["id"] = $id;
1175
        $params["email_address"] = $email_address;
1176
        $params["merge_vars"] = $merge_vars;
1177
        $params["email_type"] = $email_type;
1178
        $params["double_optin"] = $double_optin;
1179
        $params["update_existing"] = $update_existing;
1180
        $params["replace_interests"] = $replace_interests;
1181
        $params["send_welcome"] = $send_welcome;
1182
        return $this->callServer("listSubscribe", $params);
1183
    }
1184
1185
    /**
1186
     * Unsubscribe the given email address from the list
1187
     *
1188
     * @section List Related
1189
     * @example mcapi_listUnsubscribe.php
1190
     * @example xml-rpc_listUnsubscribe.php
1191
     *
1192
     * @param string $id the list id to connect to. Get by calling lists()
1193
     * @param string $email_address the email address to unsubscribe
1194
     * @param boolean $delete_member flag to completely delete the member from your list instead of just unsubscribing, default to false
1195
     * @param boolean $send_goodbye flag to send the goodbye email to the email address, defaults to true
1196
     * @param boolean $send_notify flag to send the unsubscribe notification email to the address defined in the list email notification settings, defaults to true
1197
     * @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)
1198
     */
1199 View Code Duplication
    function listUnsubscribe($id, $email_address, $delete_member=false, $send_goodbye=true, $send_notify=true) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1200
        $params = array();
1201
        $params["id"] = $id;
1202
        $params["email_address"] = $email_address;
1203
        $params["delete_member"] = $delete_member;
1204
        $params["send_goodbye"] = $send_goodbye;
1205
        $params["send_notify"] = $send_notify;
1206
        return $this->callServer("listUnsubscribe", $params);
1207
    }
1208
1209
    /**
1210
     * Edit the email address, merge fields, and interest groups for a list member
1211
     *
1212
     * @section List Related
1213
     * @example mcapi_listUpdateMember.php
1214
     *
1215
     * @param string $id the list id to connect to. Get by calling lists()
1216
     * @param string $email_address the current email address of the member to update
1217
     * @param array $merge_vars array of new field values to update the member with.  Use "EMAIL" to update the email address and "INTERESTS" to update the interest groups
1218
     * @param string $email_type change the email type preference for the member ("html", "text", or "mobile").  Leave blank to keep the existing preference (optional)
1219
     * @param boolean $replace_interests flag to determine whether we replace the interest groups with the updated groups provided, or we add the provided groups to the member's interest groups (optional, defaults to true)
1220
     * @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
1221
     */
1222
    function listUpdateMember($id, $email_address, $merge_vars, $email_type='', $replace_interests=true) {
1223
        $params = array();
1224
        $params["id"] = $id;
1225
        $params["email_address"] = $email_address;
1226
        $params["merge_vars"] = $merge_vars;
1227
        $params["email_type"] = $email_type;
1228
        $params["replace_interests"] = $replace_interests;
1229
        return $this->callServer("listUpdateMember", $params);
1230
    }
1231
1232
    /**
1233
     * Subscribe a batch of email addresses to a list at once
1234
     *
1235
     * @section List Related
1236
     *
1237
     * @example mcapi_listBatchSubscribe.php
1238
     * @example xml-rpc_listBatchSubscribe.php
1239
     *
1240
     * @param string $id the list id to connect to. Get by calling lists()
1241
     * @param array $batch an array of structs for each address to import with two special keys: "EMAIL" for the email address, and "EMAIL_TYPE" for the email type option (html, text, or mobile)
1242
     * @param boolean $double_optin flag to control whether to send an opt-in confirmation email - defaults to true
1243
     * @param boolean $update_existing flag to control whether to update members that are already subscribed to the list or to return an error, defaults to false (return error)
1244
     * @param boolean $replace_interests flag to determine whether we replace the interest groups with the updated groups provided, or we add the provided groups to the member's interest groups (optional, defaults to true)
1245
     * @return struct Array of result counts and any errors that occurred
1246
     * @returnf integer success_count Number of email addresses that were succesfully added/updated
1247
     * @returnf integer error_count Number of email addresses that failed during addition/updating
1248
     * @returnf array errors Array of error structs. Each error struct will contain "code", "message", and the full struct that failed
1249
     */
1250
    function listBatchSubscribe($id, $batch, $double_optin=true, $update_existing=false, $replace_interests=true) {
1251
        $params = array();
1252
        $params["id"] = $id;
1253
        $params["batch"] = $batch;
1254
        $params["double_optin"] = $double_optin;
1255
        $params["update_existing"] = $update_existing;
1256
        $params["replace_interests"] = $replace_interests;
1257
        return $this->callServer("listBatchSubscribe", $params);
1258
    }
1259
1260
    /**
1261
     * Unsubscribe a batch of email addresses to a list
1262
     *
1263
     * @section List Related
1264
     * @example mcapi_listBatchUnsubscribe.php
1265
     *
1266
     * @param string $id the list id to connect to. Get by calling lists()
1267
     * @param array $emails array of email addresses to unsubscribe
1268
     * @param boolean $delete_member flag to completely delete the member from your list instead of just unsubscribing, default to false
1269
     * @param boolean $send_goodbye flag to send the goodbye email to the email addresses, defaults to true
1270
     * @param boolean $send_notify flag to send the unsubscribe notification email to the address defined in the list email notification settings, defaults to false
1271
     * @return struct Array of result counts and any errors that occurred
1272
     * @returnf integer success_count Number of email addresses that were succesfully added/updated
1273
     * @returnf integer error_count Number of email addresses that failed during addition/updating
1274
     * @returnf array errors Array of error structs. Each error struct will contain "code", "message", and "email"
1275
     */
1276 View Code Duplication
    function listBatchUnsubscribe($id, $emails, $delete_member=false, $send_goodbye=true, $send_notify=false) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1277
        $params = array();
1278
        $params["id"] = $id;
1279
        $params["emails"] = $emails;
1280
        $params["delete_member"] = $delete_member;
1281
        $params["send_goodbye"] = $send_goodbye;
1282
        $params["send_notify"] = $send_notify;
1283
        return $this->callServer("listBatchUnsubscribe", $params);
1284
    }
1285
1286
    /**
1287
     * Get all of the list members for a list that are of a particular status
1288
     *
1289
     * @section List Related
1290
     * @example mcapi_listMembers.php
1291
     *
1292
     * @param string $id the list id to connect to. Get by calling lists()
1293
     * @param string $status the status to get members for - one of(subscribed, unsubscribed, cleaned, updated), defaults to subscribed
1294
     * @param string $since optional pull all members whose status (subscribed/unsubscribed/cleaned) has changed or whose profile (updated) has changed since this date/time (in GMT) - format is YYYY-MM-DD HH:mm:ss (24hr)
1295
     * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
1296
     * @param integer $limit optional for large data sets, the number of results to return - defaults to 100, upper limit set at 15000
1297
     * @return array Array of list member structs (see Returned Fields for details)
1298
     * @returnf string email Member email address
1299
     * @returnf date timestamp timestamp of their associated status date (subscribed, unsubscribed, cleaned, or updated) in GMT
1300
     */
1301
    function listMembers($id, $status='subscribed', $since=NULL, $start=0, $limit=100) {
1302
        $params = array();
1303
        $params["id"] = $id;
1304
        $params["status"] = $status;
1305
        $params["since"] = $since;
1306
        $params["start"] = $start;
1307
        $params["limit"] = $limit;
1308
        return $this->callServer("listMembers", $params);
1309
    }
1310
1311
    /**
1312
     * Get all the information for a particular member of a list
1313
     *
1314
     * @section List Related
1315
     * @example mcapi_listMemberInfo.php
1316
     * @example xml-rpc_listMemberInfo.php
1317
     *
1318
     * @param string $id the list id to connect to. Get by calling lists()
1319
     * @param string $email_address the member email address to get information for
1320
     * @return array array of list member info (see Returned Fields for details)
1321
     * @returnf string id The unique id for this email address on an account
1322
     * @returnf string email The email address associated with this record
1323
     * @returnf string email_type The type of emails this customer asked to get: html, text, or mobile
1324
     * @returnf array merges An associative array of all the merge tags and the data for those tags for this email address. <em>Note</em>: Interest Groups are returned as comma delimited strings - if a group name contains a comma, it will be escaped with a backslash. ie, "," =&gt; "\,"
1325
     * @returnf string status The subscription status for this email address, either subscribed, unsubscribed or cleaned
1326
     * @returnf string ip_opt IP Address this address opted in from.
1327
     * @returnf string ip_signup IP Address this address signed up from.
1328
     * @returnf array lists An associative array of the other lists this member belongs to - the key is the list id and the value is their status in that list.
1329
     * @returnf date timestamp The time this email address was added to the list
1330
     */
1331
    function listMemberInfo($id, $email_address) {
1332
        $params = array();
1333
        $params["id"] = $id;
1334
        $params["email_address"] = $email_address;
1335
        return $this->callServer("listMemberInfo", $params);
1336
    }
1337
1338
    /**
1339
     * Get all email addresses that complained about a given campaign
1340
     *
1341
     * @section List Related
1342
     *
1343
     * @example mcapi_listAbuseReports.php
1344
     *
1345
     * @param string $id the list id to pull abuse reports for (can be gathered using lists())
1346
     * @param integer $start optional for large data sets, the page number to start at - defaults to 1st page of data  (page 0)
1347
     * @param integer $limit optional for large data sets, the number of results to return - defaults to 500, upper limit set at 1000
1348
     * @param string $since optional pull only messages since this time - use YYYY-MM-DD HH:II:SS format in <strong>GMT</strong>
1349
     * @return array reports the abuse reports for this campaign
1350
     * @returnf string date date/time the abuse report was received and processed
1351
     * @returnf string email the email address that reported abuse
1352
     * @returnf string campaign_id the unique id for the campaign that reporte was made against
1353
     * @returnf string type an internal type generally specifying the orginating mail provider - may not be useful outside of filling report views
1354
     */
1355 View Code Duplication
    function listAbuseReports($id, $start=0, $limit=500, $since=NULL) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1356
        $params = array();
1357
        $params["id"] = $id;
1358
        $params["start"] = $start;
1359
        $params["limit"] = $limit;
1360
        $params["since"] = $since;
1361
        return $this->callServer("listAbuseReports", $params);
1362
    }
1363
1364
    /**
1365
     * Access the Growth History by Month for a given list.
1366
     *
1367
     * @section List Related
1368
     *
1369
     * @example mcapi_listGrowthHistory.php
1370
     *
1371
     * @param string $id the list id to connect to. Get by calling lists()
1372
     * @return array array of months and growth
1373
     * @returnf string month The Year and Month in question using YYYY-MM format
1374
     * @returnf integer existing number of existing subscribers to start the month
1375
     * @returnf integer imports number of subscribers imported during the month
1376
     * @returnf integer optins number of subscribers who opted-in during the month
1377
     */
1378
    function listGrowthHistory($id) {
1379
        $params = array();
1380
        $params["id"] = $id;
1381
        return $this->callServer("listGrowthHistory", $params);
1382
    }
1383
1384
    /**
1385
     * <strong>DEPRECATED:</strong> Retrieve your User Unique Id and your Affiliate link to display/use for
1386
     * <a href="/monkeyrewards/" target="_blank">Monkey Rewards</a>. While
1387
     * 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.
1388
     *
1389
     * @section Helper
1390
     *
1391
     * @deprecated See getAccountDetails() for replacement
1392
     *
1393
     * @example mcapi_getAffiliateInfo.php
1394
     * @example xml-rpc_getAffiliateInfo.php
1395
     *
1396
     * @return array containing your Affilliate Id and full link.
1397
     * @returnf string user_id Your User Unique Id.
1398
     * @returnf string url Your Monkey Rewards link for our Affiliate program
1399
     */
1400
    function getAffiliateInfo() {
1401
        $params = array();
1402
        return $this->callServer("getAffiliateInfo", $params);
1403
    }
1404
1405
    /**
1406
     * Retrieve lots of account information including payments made, plan info, some account stats, installed modules,
1407
     * contact info, and more. No private information like Credit Card numbers is available.
1408
     *
1409
     * @section Helper
1410
     *
1411
     * @return array containing the details for the account tied to this API Key
1412
     * @returnf string username The Account username
1413
     * @returnf string user_id The Account user unique id (for building some links)
1414
     * @returnf bool is_trial Whether the Account is in Trial mode (can only send campaigns to less than 100 emails)
1415
     * @returnf string timezone The timezone for the Account - default is "US/Eastern"
1416
     * @returnf string plan_type Plan Type - "monthly", "payasyougo", or "free"
1417
     * @returnf int plan_low <em>only for Monthly plans</em> - the lower tier for list size
1418
     * @returnf int plan_high <em>only for Monthly plans</em> - the upper tier for list size
1419
     * @returnf datetime plan_start_date <em>only for Monthly plans</em> - the start date for a monthly plan
1420
     * @returnf int emails_left <em>only for Free and Pay-as-you-go plans</em> emails credits left for the account
1421
     * @returnf bool pending_monthly Whether the account is finishing Pay As You Go credits before switching to a Monthly plan
1422
     * @returnf datetime first_payment date of first payment
1423
     * @returnf datetime last_payment date of most recent payment
1424
     * @returnf int times_logged_in total number of times the account has been logged into via the web
1425
     * @returnf datetime last_login date/time of last login via the web
1426
     * @returnf string affiliate_link Monkey Rewards link for our Affiliate program
1427
     * @returnf array contact Contact details for the account, including: First & Last name, email, company name, address, phone, and url
1428
     * @returnf array addons Addons installed in the account and the date they were installed.
1429
     * @returnf array orders Order details for the account, include order_id, type, cost, date/time, and any credits applied to the order
1430
     */
1431
    function getAccountDetails() {
1432
        $params = array();
1433
        return $this->callServer("getAccountDetails", $params);
1434
    }
1435
1436
    /**
1437
     * 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.
1438
     *
1439
     * @section Helper
1440
     * @example xml-rpc_generateText.php
1441
     *
1442
     * @param string $type The type of content to parse. Must be one of: "html", "template", "url", "cid" (Campaign Id), or "tid" (Template Id)
1443
     * @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.
1444
     * @return string the content pass in converted to text.
1445
     */
1446
    function generateText($type, $content) {
1447
        $params = array();
1448
        $params["type"] = $type;
1449
        $params["content"] = $content;
1450
        return $this->callServer("generateText", $params);
1451
    }
1452
1453
    /**
1454
     * Send your HTML content to have the CSS inlined and optionally remove the original styles.
1455
     *
1456
     * @section Helper
1457
     * @example xml-rpc_inlineCss.php
1458
     *
1459
     * @param string $html Your HTML content
1460
     * @param bool $strip_css optional Whether you want the CSS &lt;style&gt; tags stripped from the returned document. Defaults to false.
1461
     * @return string Your HTML content with all CSS inlined, just like if we sent it.
1462
     */
1463
    function inlineCss($html, $strip_css=false) {
1464
        $params = array();
1465
        $params["html"] = $html;
1466
        $params["strip_css"] = $strip_css;
1467
        return $this->callServer("inlineCss", $params);
1468
    }
1469
1470
    /**
1471
     * Create a new folder to file campaigns in
1472
     *
1473
     * @section Helper
1474
     * @example mcapi_createFolder.php
1475
     * @example xml-rpc_createFolder.php
1476
     *
1477
     * @param string $name a unique name for a folder
1478
     * @return integer the folder_id of the newly created folder.
1479
     */
1480
    function createFolder($name) {
1481
        $params = array();
1482
        $params["name"] = $name;
1483
        return $this->callServer("createFolder", $params);
1484
    }
1485
1486
    /**
1487
     * Retrieve a list of all MailChimp API Keys for this User
1488
     *
1489
     * @section Security Related
1490
     * @example xml-rpc_apikeyAdd.php
1491
     * @example mcapi_apikeyAdd.php
1492
     *
1493
     * @param string $username Your MailChimp user name
1494
     * @param string $password Your MailChimp password
1495
     * @param boolean $expired optional - whether or not to include expired keys, defaults to false
1496
     * @return array an array of API keys including:
1497
     * @returnf string apikey The api key that can be used
1498
     * @returnf string created_at The date the key was created
1499
     * @returnf string expired_at The date the key was expired
1500
     */
1501
    function apikeys($username, $password, $expired=false) {
1502
        $params = array();
1503
        $params["username"] = $username;
1504
        $params["password"] = $password;
1505
        $params["expired"] = $expired;
1506
        return $this->callServer("apikeys", $params);
1507
    }
1508
1509
    /**
1510
     * Add an API Key to your account. We will generate a new key for you and return it.
1511
     *
1512
     * @section Security Related
1513
     * @example xml-rpc_apikeyAdd.php
1514
     *
1515
     * @param string $username Your MailChimp user name
1516
     * @param string $password Your MailChimp password
1517
     * @return string a new API Key that can be immediately used.
1518
     */
1519 View Code Duplication
    function apikeyAdd($username, $password) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1520
        $params = array();
1521
        $params["username"] = $username;
1522
        $params["password"] = $password;
1523
        return $this->callServer("apikeyAdd", $params);
1524
    }
1525
1526
    /**
1527
     * Expire a Specific API Key. Note that if you expire all of your keys, a new, valid one will be created and returned
1528
     * next time you call login(). If you are trying to shut off access to your account for an old developer, change your
1529
     * MailChimp password, then expire all of the keys they had access to. Note that this takes effect immediately, so make
1530
     * sure you replace the keys in any working application before expiring them! Consider yourself warned...
1531
     *
1532
     * @section Security Related
1533
     * @example mcapi_apikeyExpire.php
1534
     * @example xml-rpc_apikeyExpire.php
1535
     *
1536
     * @param string $username Your MailChimp user name
1537
     * @param string $password Your MailChimp password
1538
     * @return boolean true if it worked, otherwise an error is thrown.
1539
     */
1540 View Code Duplication
    function apikeyExpire($username, $password) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1541
        $params = array();
1542
        $params["username"] = $username;
1543
        $params["password"] = $password;
1544
        return $this->callServer("apikeyExpire", $params);
1545
    }
1546
1547
    /**
1548
     * "Ping" the MailChimp API - a simple method you can call that will return a constant value as long as everything is good. Note
1549
     * than unlike most all of our methods, we don't throw an Exception if we are having issues. You will simply receive a different
1550
     * string back that will explain our view on what is going on.
1551
     *
1552
     * @section Helper
1553
     * @example xml-rpc_ping.php
1554
     *
1555
     * @return string returns "Everything's Chimpy!" if everything is chimpy, otherwise returns an error message
1556
     */
1557
    function ping() {
1558
        $params = array();
1559
        return $this->callServer("ping", $params);
1560
    }
1561
1562
    /**
1563
     * Internal function - proxy method for certain XML-RPC calls | DO NOT CALL
1564
     * @param mixed Method to call, with any parameters to pass along
1565
     * @return mixed the result of the call
1566
     */
1567
    function callMethod() {
1568
        $params = array();
1569
        return $this->callServer("callMethod", $params);
1570
    }
1571
1572
    /**
1573
     * Actually connect to the server and call the requested methods, parsing the result
1574
     * You should never have to call this function manually
1575
     */
1576
    function callServer($method, $params) {
1577
    	//Always include the apikey if we are not logging in
1578
    	if($method != "login") {
1579
    	    $dc = "us1";
1580
    	    if (strstr($this->api_key,"-")){
1581
            	list($key, $dc) = explode("-",$this->api_key,2);
0 ignored issues
show
Unused Code introduced by
The assignment to $key is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1582
                if (!$dc) $dc = "us1";
1583
            }
1584
            $host = $dc.".".$this->apiUrl["host"];
1585
    		$params["apikey"] = $this->api_key;
1586
    	} else {
1587
        	$host = $this->apiUrl["host"];
1588
    	}
1589
        $this->errorMessage = "";
1590
        $this->errorCode = "";
1591
        $post_vars = $this->httpBuildQuery($params);
1592
1593
        $payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
1594
        $payload .= "Host: " . $host . "\r\n";
1595
        $payload .= "User-Agent: MCAPI/" . $this->version ."\r\n";
1596
        $payload .= "Content-type: application/x-www-form-urlencoded\r\n";
1597
        $payload .= "Content-length: " . strlen($post_vars) . "\r\n";
1598
        $payload .= "Connection: close \r\n\r\n";
1599
        $payload .= $post_vars;
1600
1601
        ob_start();
1602
        if ($this->secure){
1603
            $sock = fsockopen("ssl://".$host, 443, $errno, $errstr, $this->timeout);
1604
        } else {
1605
            $sock = fsockopen($host, 80, $errno, $errstr, $this->timeout);
1606
        }
1607
        if(!$sock) {
1608
            $this->errorMessage = "Could not connect (ERR $errno: $errstr)";
1609
            $this->errorCode = "-99";
1610
            ob_end_clean();
1611
            return false;
1612
        }
1613
1614
        $response = "";
1615
        fwrite($sock, $payload);
1616
        while(!feof($sock)) {
1617
            $response .= fread($sock, $this->chunkSize);
1618
        }
1619
        fclose($sock);
1620
        ob_end_clean();
1621
1622
        list($throw, $response) = explode("\r\n\r\n", $response, 2);
0 ignored issues
show
Unused Code introduced by
The assignment to $throw is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1623
1624
        if(ini_get("magic_quotes_runtime")) $response = stripslashes($response);
1625
1626
        $serial = unserialize($response);
1627
        if($response && $serial === false) {
1628
        	$response = array("error" => "Bad Response.  Got This: " . $response, "code" => "-99");
1629
        } else {
1630
        	$response = $serial;
1631
        }
1632
        if(is_array($response) && isset($response["error"])) {
1633
            $this->errorMessage = $response["error"];
1634
            $this->errorCode = $response["code"];
1635
            return false;
1636
        }
1637
1638
        return $response;
1639
    }
1640
1641
    /**
1642
     * Re-implement http_build_query for systems that do not already have it
1643
     */
1644
    function httpBuildQuery($params, $key=null) {
1645
        $ret = array();
1646
1647
        foreach((array) $params as $name => $val) {
1648
            $name = urlencode($name);
1649
            if($key !== null) {
1650
                $name = $key . "[" . $name . "]";
1651
            }
1652
1653
            if(is_array($val) || is_object($val)) {
1654
                $ret[] = $this->httpBuildQuery($val, $name);
1655
            } elseif($val !== null) {
1656
                $ret[] = $name . "=" . urlencode($val);
1657
            }
1658
        }
1659
1660
        return implode("&", $ret);
1661
    }
1662
}
1663
1664
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...