Version Description
- Rename MCAPI class to prevent collisions with other plugins using MCAPI
Download this release
Release Info
Developer | anderly |
Plugin | WooCommerce MailChimp |
Version | 1.3.9 |
Comparing to | |
See all releases |
Code changes from version 1.3.8 to 1.3.9
- README.md +3 -0
- WooCommerce-MailChimp.png +0 -0
- classes/api/class-MCAPI.php +0 -260
- classes/api/class-ss-wc-mailchimp-api.php +274 -0
- classes/class-ss-wc-integration-mailchimp.php +2 -3
- readme.txt +4 -1
- woocommerce-mailchimp.php +1 -1
README.md
CHANGED
@@ -69,6 +69,9 @@ If you need help, have problems, want to leave feedback or want to provide const
|
|
69 |
|
70 |
### Changelog
|
71 |
|
|
|
|
|
|
|
72 |
#### 1.3.8
|
73 |
* WordPress 4.6.x Compatible
|
74 |
* WooCommerce 2.6.x Compatible
|
69 |
|
70 |
### Changelog
|
71 |
|
72 |
+
#### 1.3.9
|
73 |
+
* Rename MCAPI class to prevent collisions with other plugins using MCAPI
|
74 |
+
|
75 |
#### 1.3.8
|
76 |
* WordPress 4.6.x Compatible
|
77 |
* WooCommerce 2.6.x Compatible
|
WooCommerce-MailChimp.png
DELETED
Binary file
|
classes/api/class-MCAPI.php
DELETED
@@ -1,260 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class MCAPI {
|
4 |
-
var $version = "1.3";
|
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.
|
35 |
-
*
|
36 |
-
* @param string $apikey Your MailChimp apikey
|
37 |
-
* @param string $secure Whether or not this should use a secure connection
|
38 |
-
*/
|
39 |
-
function __construct($apikey, $secure=false) {
|
40 |
-
$this->secure = $secure;
|
41 |
-
$this->apiUrl = parse_url("http://api.mailchimp.com/" . $this->version . "/?output=php");
|
42 |
-
$this->api_key = $apikey;
|
43 |
-
}
|
44 |
-
function setTimeout($seconds){
|
45 |
-
if (is_int($seconds)){
|
46 |
-
$this->timeout = $seconds;
|
47 |
-
return true;
|
48 |
-
}
|
49 |
-
}
|
50 |
-
function getTimeout(){
|
51 |
-
return $this->timeout;
|
52 |
-
}
|
53 |
-
function useSecure($val){
|
54 |
-
if ($val===true){
|
55 |
-
$this->secure = true;
|
56 |
-
} else {
|
57 |
-
$this->secure = false;
|
58 |
-
}
|
59 |
-
}
|
60 |
-
|
61 |
-
/**
|
62 |
-
* Actually connect to the server and call the requested methods, parsing the result
|
63 |
-
* You should never have to call this function manually
|
64 |
-
*/
|
65 |
-
function __call($method, $params) {
|
66 |
-
$dc = "us1";
|
67 |
-
if (strstr($this->api_key,"-")){
|
68 |
-
list($key, $dc) = explode("-",$this->api_key,2);
|
69 |
-
if (!$dc) $dc = "us1";
|
70 |
-
}
|
71 |
-
$host = $dc.".".$this->apiUrl["host"];
|
72 |
-
|
73 |
-
$this->errorMessage = "";
|
74 |
-
$this->errorCode = "";
|
75 |
-
$sep_changed = false;
|
76 |
-
//sigh, apparently some distribs change this to & by default
|
77 |
-
if (ini_get("arg_separator.output")!="&"){
|
78 |
-
$sep_changed = true;
|
79 |
-
$orig_sep = ini_get("arg_separator.output");
|
80 |
-
ini_set("arg_separator.output", "&");
|
81 |
-
}
|
82 |
-
//mutate params
|
83 |
-
$mutate = array();
|
84 |
-
$mutate["apikey"] = $this->api_key;
|
85 |
-
foreach($params as $k=>$v){
|
86 |
-
$mutate[$this->function_map[$method][$k]] = $v;
|
87 |
-
}
|
88 |
-
$post_vars = http_build_query($mutate);
|
89 |
-
if ($sep_changed){
|
90 |
-
ini_set("arg_separator.output", $orig_sep);
|
91 |
-
}
|
92 |
-
|
93 |
-
$payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
|
94 |
-
$payload .= "Host: " . $host . "\r\n";
|
95 |
-
$payload .= "User-Agent: MCAPImini/" . $this->version ."\r\n";
|
96 |
-
$payload .= "Content-type: application/x-www-form-urlencoded\r\n";
|
97 |
-
$payload .= "Content-length: " . strlen($post_vars) . "\r\n";
|
98 |
-
$payload .= "Connection: close \r\n\r\n";
|
99 |
-
$payload .= $post_vars;
|
100 |
-
|
101 |
-
ob_start();
|
102 |
-
if ($this->secure){
|
103 |
-
$sock = fsockopen("ssl://".$host, 443, $errno, $errstr, 30);
|
104 |
-
} else {
|
105 |
-
$sock = fsockopen($host, 80, $errno, $errstr, 30);
|
106 |
-
}
|
107 |
-
if(!$sock) {
|
108 |
-
$this->errorMessage = "Could not connect (ERR $errno: $errstr)";
|
109 |
-
$this->errorCode = "-99";
|
110 |
-
ob_end_clean();
|
111 |
-
return false;
|
112 |
-
}
|
113 |
-
|
114 |
-
$response = "";
|
115 |
-
fwrite($sock, $payload);
|
116 |
-
stream_set_timeout($sock, $this->timeout);
|
117 |
-
$info = stream_get_meta_data($sock);
|
118 |
-
while ((!feof($sock)) && (!$info["timed_out"])) {
|
119 |
-
$response .= fread($sock, $this->chunkSize);
|
120 |
-
$info = stream_get_meta_data($sock);
|
121 |
-
}
|
122 |
-
fclose($sock);
|
123 |
-
ob_end_clean();
|
124 |
-
if ($info["timed_out"]) {
|
125 |
-
$this->errorMessage = "Could not read response (timed out)";
|
126 |
-
$this->errorCode = -98;
|
127 |
-
|
128 |
-
return false;
|
129 |
-
}
|
130 |
-
|
131 |
-
list($headers, $response) = explode("\r\n\r\n", $response, 2);
|
132 |
-
$headers = explode("\r\n", $headers);
|
133 |
-
$errored = false;
|
134 |
-
foreach($headers as $h) {
|
135 |
-
if (substr($h,0,26)==="X-MailChimp-API-Error-Code"){
|
136 |
-
$errored = true;
|
137 |
-
$error_code = trim(substr($h,27));
|
138 |
-
break;
|
139 |
-
}
|
140 |
-
}
|
141 |
-
|
142 |
-
if(ini_get("magic_quotes_runtime")) $response = stripslashes($response);
|
143 |
-
|
144 |
-
$serial = unserialize($response);
|
145 |
-
if($response && $serial === false) {
|
146 |
-
$response = array("error" => "Bad Response. Got This: " . $response, "code" => "-99");
|
147 |
-
} else {
|
148 |
-
$response = $serial;
|
149 |
-
}
|
150 |
-
if($errored && is_array($response) && isset($response["error"])) {
|
151 |
-
$this->errorMessage = $response["error"];
|
152 |
-
$this->errorCode = $response["code"];
|
153 |
-
return false;
|
154 |
-
}
|
155 |
-
elseif($errored){
|
156 |
-
$this->errorMessage = "No error message was found";
|
157 |
-
$this->errorCode = $error_code;
|
158 |
-
return false;
|
159 |
-
}
|
160 |
-
|
161 |
-
return $response;
|
162 |
-
}
|
163 |
-
|
164 |
-
protected $function_map = array(
|
165 |
-
'campaignUnschedule' => array( "cid" ),
|
166 |
-
'campaignSchedule' => array( "cid", "schedule_time", "schedule_time_b" ),
|
167 |
-
'campaignResume' => array( "cid" ),
|
168 |
-
'campaignPause' => array( "cid" ),
|
169 |
-
'campaignSendNow' => array( "cid" ),
|
170 |
-
'campaignSendTest' => array( "cid", "test_emails", "send_type" ),
|
171 |
-
'campaignSegmentTest' => array( "list_id", "options" ),
|
172 |
-
'campaignCreate' => array( "type", "options", "content", "segment_opts", "type_opts" ),
|
173 |
-
'campaignUpdate' => array( "cid", "name", "value" ),
|
174 |
-
'campaignReplicate' => array( "cid" ),
|
175 |
-
'campaignDelete' => array( "cid" ),
|
176 |
-
'campaigns' => array( "filters", "start", "limit" ),
|
177 |
-
'campaignStats' => array( "cid" ),
|
178 |
-
'campaignClickStats' => array( "cid" ),
|
179 |
-
'campaignEmailDomainPerformance'=> array( "cid" ),
|
180 |
-
'campaignMembers' => array( "cid", "status", "start", "limit" ),
|
181 |
-
'campaignHardBounces' => array( "cid", "start", "limit" ),
|
182 |
-
'campaignSoftBounces' => array( "cid", "start", "limit" ),
|
183 |
-
'campaignUnsubscribes' => array( "cid", "start", "limit" ),
|
184 |
-
'campaignAbuseReports' => array( "cid", "since", "start", "limit" ),
|
185 |
-
'campaignAdvice' => array( "cid" ),
|
186 |
-
'campaignAnalytics' => array( "cid" ),
|
187 |
-
'campaignGeoOpens' => array( "cid" ),
|
188 |
-
'campaignGeoOpensForCountry' => array( "cid", "code" ),
|
189 |
-
'campaignEepUrlStats' => array( "cid" ),
|
190 |
-
'campaignBounceMessage' => array( "cid", "email" ),
|
191 |
-
'campaignBounceMessages' => array( "cid", "start", "limit", "since" ),
|
192 |
-
'campaignEcommOrders' => array( "cid", "start", "limit", "since" ),
|
193 |
-
'campaignShareReport' => array( "cid", "opts" ),
|
194 |
-
'campaignContent' => array( "cid", "for_archive" ),
|
195 |
-
'campaignTemplateContent' => array( "cid" ),
|
196 |
-
'campaignOpenedAIM' => array( "cid", "start", "limit" ),
|
197 |
-
'campaignNotOpenedAIM' => array( "cid", "start", "limit" ),
|
198 |
-
'campaignClickDetailAIM' => array( "cid", "url", "start", "limit" ),
|
199 |
-
'campaignEmailStatsAIM' => array( "cid", "email_address" ),
|
200 |
-
'campaignEmailStatsAIMAll' => array( "cid", "start", "limit" ),
|
201 |
-
'campaignEcommOrderAdd' => array( "order" ),
|
202 |
-
'lists' => array( "filters", "start", "limit" ),
|
203 |
-
'listMergeVars' => array( "id" ),
|
204 |
-
'listMergeVarAdd' => array( "id", "tag", "name", "options" ),
|
205 |
-
'listMergeVarUpdate' => array( "id", "tag", "options" ),
|
206 |
-
'listMergeVarDel' => array( "id", "tag" ),
|
207 |
-
'listInterestGroupings' => array( "id" ),
|
208 |
-
'listInterestGroupAdd' => array( "id", "group_name", "grouping_id" ),
|
209 |
-
'listInterestGroupDel' => array( "id", "group_name", "grouping_id" ),
|
210 |
-
'listInterestGroupUpdate' => array( "id", "old_name", "new_name", "grouping_id" ),
|
211 |
-
'listInterestGroupingAdd' => array( "id", "name", "type", "groups" ),
|
212 |
-
'listInterestGroupingUpdate' => array( "grouping_id", "name", "value" ),
|
213 |
-
'listInterestGroupingDel' => array( "grouping_id" ),
|
214 |
-
'listWebhooks' => array( "id" ),
|
215 |
-
'listWebhookAdd' => array( "id", "url", "actions", "sources" ),
|
216 |
-
'listWebhookDel' => array( "id", "url" ),
|
217 |
-
'listStaticSegments' => array( "id" ),
|
218 |
-
'listStaticSegmentAdd' => array( "id", "name" ),
|
219 |
-
'listStaticSegmentReset' => array( "id", "seg_id" ),
|
220 |
-
'listStaticSegmentDel' => array( "id", "seg_id" ),
|
221 |
-
'listStaticSegmentMembersAdd' => array( "id", "seg_id", "batch" ),
|
222 |
-
'listStaticSegmentMembersDel' => array( "id", "seg_id", "batch" ),
|
223 |
-
'listSubscribe' => array( "id", "email_address", "merge_vars", "email_type", "double_optin", "update_existing", "replace_interests", "send_welcome" ),
|
224 |
-
'listUnsubscribe' => array( "id", "email_address", "delete_member", "send_goodbye", "send_notify" ),
|
225 |
-
'listUpdateMember' => array( "id", "email_address", "merge_vars", "email_type", "replace_interests" ),
|
226 |
-
'listBatchSubscribe' => array( "id", "batch", "double_optin", "update_existing", "replace_interests" ),
|
227 |
-
'listBatchUnsubscribe' => array( "id", "emails", "delete_member", "send_goodbye", "send_notify" ),
|
228 |
-
'listMembers' => array( "id", "status", "since", "start", "limit" ),
|
229 |
-
'listMemberInfo' => array( "id", "email_address" ),
|
230 |
-
'listMemberActivity' => array( "id", "email_address" ),
|
231 |
-
'listAbuseReports' => array( "id", "start", "limit", "since" ),
|
232 |
-
'listGrowthHistory' => array( "id" ),
|
233 |
-
'listActivity' => array( "id" ),
|
234 |
-
'listLocations' => array( "id" ),
|
235 |
-
'listClients' => array( "id" ),
|
236 |
-
'templates' => array( "types", "category", "inactives" ),
|
237 |
-
'templateInfo' => array( "tid", "type" ),
|
238 |
-
'templateAdd' => array( "name", "html" ),
|
239 |
-
'templateUpdate' => array( "id", "values" ),
|
240 |
-
'templateDel' => array( "id" ),
|
241 |
-
'templateUndel' => array( "id" ),
|
242 |
-
'getAccountDetails' => array(),
|
243 |
-
'generateText' => array( "type", "content" ),
|
244 |
-
'inlineCss' => array( "html", "strip_css" ),
|
245 |
-
'folders' => array( "type" ),
|
246 |
-
'folderAdd' => array( "name", "type" ),
|
247 |
-
'folderUpdate' => array( "fid", "name", "type" ),
|
248 |
-
'folderDel' => array( "fid", "type" ),
|
249 |
-
'ecommOrders' => array( "start", "limit", "since" ),
|
250 |
-
'ecommOrderAdd' => array( "order" ),
|
251 |
-
'ecommOrderDel' => array( "store_id", "order_id" ),
|
252 |
-
'listsForEmail' => array( "email_address" ),
|
253 |
-
'campaignsForEmail' => array( "email_address" ),
|
254 |
-
'chimpChatter' => array(),
|
255 |
-
'apikeys' => array( "username", "password", "expired" ),
|
256 |
-
'apikeyAdd' => array( "username", "password" ),
|
257 |
-
'apikeyExpire' => array( "username", "password" ),
|
258 |
-
'ping' => array()
|
259 |
-
);
|
260 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/api/class-ss-wc-mailchimp-api.php
ADDED
@@ -0,0 +1,274 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Minimal MailChimp API v1.3 wrapper
|
7 |
+
*
|
8 |
+
* @class SS_WC_MailChimp_API
|
9 |
+
* @extends WC_Integration
|
10 |
+
* @version 1.3.9
|
11 |
+
* @package WooCommerce MailChimp
|
12 |
+
* @author Saint Systems
|
13 |
+
*/
|
14 |
+
class SS_WC_MailChimp_API {
|
15 |
+
var $version = "1.3";
|
16 |
+
var $errorMessage;
|
17 |
+
var $errorCode;
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Cache the information on the API location on the server
|
21 |
+
*/
|
22 |
+
var $apiUrl;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Default to a 300 second timeout on server calls
|
26 |
+
*/
|
27 |
+
var $timeout = 300;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Default to a 8K chunk size
|
31 |
+
*/
|
32 |
+
var $chunkSize = 8192;
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Cache the user api_key so we only have to log in once per client instantiation
|
36 |
+
*/
|
37 |
+
var $api_key;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Cache the user api_key so we only have to log in once per client instantiation
|
41 |
+
*/
|
42 |
+
var $secure = false;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Connect to the MailChimp API for a given list.
|
46 |
+
*
|
47 |
+
* @param string $apikey Your MailChimp apikey
|
48 |
+
* @param string $secure Whether or not this should use a secure connection
|
49 |
+
*/
|
50 |
+
function __construct($apikey, $secure=false) {
|
51 |
+
$this->secure = $secure;
|
52 |
+
$this->apiUrl = parse_url("http://api.mailchimp.com/" . $this->version . "/?output=php");
|
53 |
+
$this->api_key = $apikey;
|
54 |
+
}
|
55 |
+
|
56 |
+
function setTimeout($seconds){
|
57 |
+
if (is_int($seconds)){
|
58 |
+
$this->timeout = $seconds;
|
59 |
+
return true;
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
function getTimeout(){
|
64 |
+
return $this->timeout;
|
65 |
+
}
|
66 |
+
|
67 |
+
function useSecure($val){
|
68 |
+
if ($val===true){
|
69 |
+
$this->secure = true;
|
70 |
+
} else {
|
71 |
+
$this->secure = false;
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Actually connect to the server and call the requested methods, parsing the result
|
77 |
+
* You should never have to call this function manually
|
78 |
+
*/
|
79 |
+
function __call($method, $params) {
|
80 |
+
$dc = "us1";
|
81 |
+
if (strstr($this->api_key,"-")){
|
82 |
+
list($key, $dc) = explode("-",$this->api_key,2);
|
83 |
+
if (!$dc) $dc = "us1";
|
84 |
+
}
|
85 |
+
$host = $dc.".".$this->apiUrl["host"];
|
86 |
+
|
87 |
+
$this->errorMessage = "";
|
88 |
+
$this->errorCode = "";
|
89 |
+
$sep_changed = false;
|
90 |
+
//sigh, apparently some distribs change this to & by default
|
91 |
+
if (ini_get("arg_separator.output")!="&"){
|
92 |
+
$sep_changed = true;
|
93 |
+
$orig_sep = ini_get("arg_separator.output");
|
94 |
+
ini_set("arg_separator.output", "&");
|
95 |
+
}
|
96 |
+
//mutate params
|
97 |
+
$mutate = array();
|
98 |
+
$mutate["apikey"] = $this->api_key;
|
99 |
+
foreach($params as $k=>$v){
|
100 |
+
$mutate[$this->function_map[$method][$k]] = $v;
|
101 |
+
}
|
102 |
+
$post_vars = http_build_query($mutate);
|
103 |
+
if ($sep_changed){
|
104 |
+
ini_set("arg_separator.output", $orig_sep);
|
105 |
+
}
|
106 |
+
|
107 |
+
$payload = "POST " . $this->apiUrl["path"] . "?" . $this->apiUrl["query"] . "&method=" . $method . " HTTP/1.0\r\n";
|
108 |
+
$payload .= "Host: " . $host . "\r\n";
|
109 |
+
$payload .= "User-Agent: MCAPImini/" . $this->version ."\r\n";
|
110 |
+
$payload .= "Content-type: application/x-www-form-urlencoded\r\n";
|
111 |
+
$payload .= "Content-length: " . strlen($post_vars) . "\r\n";
|
112 |
+
$payload .= "Connection: close \r\n\r\n";
|
113 |
+
$payload .= $post_vars;
|
114 |
+
|
115 |
+
ob_start();
|
116 |
+
if ($this->secure){
|
117 |
+
$sock = fsockopen("ssl://".$host, 443, $errno, $errstr, 30);
|
118 |
+
} else {
|
119 |
+
$sock = fsockopen($host, 80, $errno, $errstr, 30);
|
120 |
+
}
|
121 |
+
if(!$sock) {
|
122 |
+
$this->errorMessage = "Could not connect (ERR $errno: $errstr)";
|
123 |
+
$this->errorCode = "-99";
|
124 |
+
ob_end_clean();
|
125 |
+
return false;
|
126 |
+
}
|
127 |
+
|
128 |
+
$response = "";
|
129 |
+
fwrite($sock, $payload);
|
130 |
+
stream_set_timeout($sock, $this->timeout);
|
131 |
+
$info = stream_get_meta_data($sock);
|
132 |
+
while ((!feof($sock)) && (!$info["timed_out"])) {
|
133 |
+
$response .= fread($sock, $this->chunkSize);
|
134 |
+
$info = stream_get_meta_data($sock);
|
135 |
+
}
|
136 |
+
fclose($sock);
|
137 |
+
ob_end_clean();
|
138 |
+
if ($info["timed_out"]) {
|
139 |
+
$this->errorMessage = "Could not read response (timed out)";
|
140 |
+
$this->errorCode = -98;
|
141 |
+
|
142 |
+
return false;
|
143 |
+
}
|
144 |
+
|
145 |
+
list($headers, $response) = explode("\r\n\r\n", $response, 2);
|
146 |
+
$headers = explode("\r\n", $headers);
|
147 |
+
$errored = false;
|
148 |
+
foreach($headers as $h) {
|
149 |
+
if (substr($h,0,26)==="X-MailChimp-API-Error-Code"){
|
150 |
+
$errored = true;
|
151 |
+
$error_code = trim(substr($h,27));
|
152 |
+
break;
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
if(ini_get("magic_quotes_runtime")) $response = stripslashes($response);
|
157 |
+
|
158 |
+
$serial = unserialize($response);
|
159 |
+
if($response && $serial === false) {
|
160 |
+
$response = array("error" => "Bad Response. Got This: " . $response, "code" => "-99");
|
161 |
+
} else {
|
162 |
+
$response = $serial;
|
163 |
+
}
|
164 |
+
if($errored && is_array($response) && isset($response["error"])) {
|
165 |
+
$this->errorMessage = $response["error"];
|
166 |
+
$this->errorCode = $response["code"];
|
167 |
+
return false;
|
168 |
+
}
|
169 |
+
elseif($errored){
|
170 |
+
$this->errorMessage = "No error message was found";
|
171 |
+
$this->errorCode = $error_code;
|
172 |
+
return false;
|
173 |
+
}
|
174 |
+
|
175 |
+
return $response;
|
176 |
+
}
|
177 |
+
|
178 |
+
protected $function_map = array(
|
179 |
+
'campaignUnschedule' => array( "cid" ),
|
180 |
+
'campaignSchedule' => array( "cid", "schedule_time", "schedule_time_b" ),
|
181 |
+
'campaignResume' => array( "cid" ),
|
182 |
+
'campaignPause' => array( "cid" ),
|
183 |
+
'campaignSendNow' => array( "cid" ),
|
184 |
+
'campaignSendTest' => array( "cid", "test_emails", "send_type" ),
|
185 |
+
'campaignSegmentTest' => array( "list_id", "options" ),
|
186 |
+
'campaignCreate' => array( "type", "options", "content", "segment_opts", "type_opts" ),
|
187 |
+
'campaignUpdate' => array( "cid", "name", "value" ),
|
188 |
+
'campaignReplicate' => array( "cid" ),
|
189 |
+
'campaignDelete' => array( "cid" ),
|
190 |
+
'campaigns' => array( "filters", "start", "limit" ),
|
191 |
+
'campaignStats' => array( "cid" ),
|
192 |
+
'campaignClickStats' => array( "cid" ),
|
193 |
+
'campaignEmailDomainPerformance'=> array( "cid" ),
|
194 |
+
'campaignMembers' => array( "cid", "status", "start", "limit" ),
|
195 |
+
'campaignHardBounces' => array( "cid", "start", "limit" ),
|
196 |
+
'campaignSoftBounces' => array( "cid", "start", "limit" ),
|
197 |
+
'campaignUnsubscribes' => array( "cid", "start", "limit" ),
|
198 |
+
'campaignAbuseReports' => array( "cid", "since", "start", "limit" ),
|
199 |
+
'campaignAdvice' => array( "cid" ),
|
200 |
+
'campaignAnalytics' => array( "cid" ),
|
201 |
+
'campaignGeoOpens' => array( "cid" ),
|
202 |
+
'campaignGeoOpensForCountry' => array( "cid", "code" ),
|
203 |
+
'campaignEepUrlStats' => array( "cid" ),
|
204 |
+
'campaignBounceMessage' => array( "cid", "email" ),
|
205 |
+
'campaignBounceMessages' => array( "cid", "start", "limit", "since" ),
|
206 |
+
'campaignEcommOrders' => array( "cid", "start", "limit", "since" ),
|
207 |
+
'campaignShareReport' => array( "cid", "opts" ),
|
208 |
+
'campaignContent' => array( "cid", "for_archive" ),
|
209 |
+
'campaignTemplateContent' => array( "cid" ),
|
210 |
+
'campaignOpenedAIM' => array( "cid", "start", "limit" ),
|
211 |
+
'campaignNotOpenedAIM' => array( "cid", "start", "limit" ),
|
212 |
+
'campaignClickDetailAIM' => array( "cid", "url", "start", "limit" ),
|
213 |
+
'campaignEmailStatsAIM' => array( "cid", "email_address" ),
|
214 |
+
'campaignEmailStatsAIMAll' => array( "cid", "start", "limit" ),
|
215 |
+
'campaignEcommOrderAdd' => array( "order" ),
|
216 |
+
'lists' => array( "filters", "start", "limit" ),
|
217 |
+
'listMergeVars' => array( "id" ),
|
218 |
+
'listMergeVarAdd' => array( "id", "tag", "name", "options" ),
|
219 |
+
'listMergeVarUpdate' => array( "id", "tag", "options" ),
|
220 |
+
'listMergeVarDel' => array( "id", "tag" ),
|
221 |
+
'listInterestGroupings' => array( "id" ),
|
222 |
+
'listInterestGroupAdd' => array( "id", "group_name", "grouping_id" ),
|
223 |
+
'listInterestGroupDel' => array( "id", "group_name", "grouping_id" ),
|
224 |
+
'listInterestGroupUpdate' => array( "id", "old_name", "new_name", "grouping_id" ),
|
225 |
+
'listInterestGroupingAdd' => array( "id", "name", "type", "groups" ),
|
226 |
+
'listInterestGroupingUpdate' => array( "grouping_id", "name", "value" ),
|
227 |
+
'listInterestGroupingDel' => array( "grouping_id" ),
|
228 |
+
'listWebhooks' => array( "id" ),
|
229 |
+
'listWebhookAdd' => array( "id", "url", "actions", "sources" ),
|
230 |
+
'listWebhookDel' => array( "id", "url" ),
|
231 |
+
'listStaticSegments' => array( "id" ),
|
232 |
+
'listStaticSegmentAdd' => array( "id", "name" ),
|
233 |
+
'listStaticSegmentReset' => array( "id", "seg_id" ),
|
234 |
+
'listStaticSegmentDel' => array( "id", "seg_id" ),
|
235 |
+
'listStaticSegmentMembersAdd' => array( "id", "seg_id", "batch" ),
|
236 |
+
'listStaticSegmentMembersDel' => array( "id", "seg_id", "batch" ),
|
237 |
+
'listSubscribe' => array( "id", "email_address", "merge_vars", "email_type", "double_optin", "update_existing", "replace_interests", "send_welcome" ),
|
238 |
+
'listUnsubscribe' => array( "id", "email_address", "delete_member", "send_goodbye", "send_notify" ),
|
239 |
+
'listUpdateMember' => array( "id", "email_address", "merge_vars", "email_type", "replace_interests" ),
|
240 |
+
'listBatchSubscribe' => array( "id", "batch", "double_optin", "update_existing", "replace_interests" ),
|
241 |
+
'listBatchUnsubscribe' => array( "id", "emails", "delete_member", "send_goodbye", "send_notify" ),
|
242 |
+
'listMembers' => array( "id", "status", "since", "start", "limit" ),
|
243 |
+
'listMemberInfo' => array( "id", "email_address" ),
|
244 |
+
'listMemberActivity' => array( "id", "email_address" ),
|
245 |
+
'listAbuseReports' => array( "id", "start", "limit", "since" ),
|
246 |
+
'listGrowthHistory' => array( "id" ),
|
247 |
+
'listActivity' => array( "id" ),
|
248 |
+
'listLocations' => array( "id" ),
|
249 |
+
'listClients' => array( "id" ),
|
250 |
+
'templates' => array( "types", "category", "inactives" ),
|
251 |
+
'templateInfo' => array( "tid", "type" ),
|
252 |
+
'templateAdd' => array( "name", "html" ),
|
253 |
+
'templateUpdate' => array( "id", "values" ),
|
254 |
+
'templateDel' => array( "id" ),
|
255 |
+
'templateUndel' => array( "id" ),
|
256 |
+
'getAccountDetails' => array(),
|
257 |
+
'generateText' => array( "type", "content" ),
|
258 |
+
'inlineCss' => array( "html", "strip_css" ),
|
259 |
+
'folders' => array( "type" ),
|
260 |
+
'folderAdd' => array( "name", "type" ),
|
261 |
+
'folderUpdate' => array( "fid", "name", "type" ),
|
262 |
+
'folderDel' => array( "fid", "type" ),
|
263 |
+
'ecommOrders' => array( "start", "limit", "since" ),
|
264 |
+
'ecommOrderAdd' => array( "order" ),
|
265 |
+
'ecommOrderDel' => array( "store_id", "order_id" ),
|
266 |
+
'listsForEmail' => array( "email_address" ),
|
267 |
+
'campaignsForEmail' => array( "email_address" ),
|
268 |
+
'chimpChatter' => array(),
|
269 |
+
'apikeys' => array( "username", "password", "expired" ),
|
270 |
+
'apikeyAdd' => array( "username", "password" ),
|
271 |
+
'apikeyExpire' => array( "username", "password" ),
|
272 |
+
'ping' => array()
|
273 |
+
);
|
274 |
+
}
|
classes/class-ss-wc-integration-mailchimp.php
CHANGED
@@ -86,7 +86,6 @@ class SS_WC_Integration_MailChimp extends WC_Integration {
|
|
86 |
public function load_settings() {
|
87 |
// We need the API key to set up for the lists in the form fields
|
88 |
$this->api_key = $this->get_option( 'api_key' );
|
89 |
-
// $this->get_api() = new MCAPI( $this->api_key );
|
90 |
$this->enabled = $this->get_option( 'enabled' );
|
91 |
|
92 |
// Get setting values
|
@@ -383,8 +382,8 @@ class SS_WC_Integration_MailChimp extends WC_Integration {
|
|
383 |
if ( $this->api_key == '' ) {
|
384 |
return false;
|
385 |
}
|
386 |
-
require_once( 'api/class-
|
387 |
-
self::$api = new
|
388 |
}
|
389 |
return self::$api;
|
390 |
}
|
86 |
public function load_settings() {
|
87 |
// We need the API key to set up for the lists in the form fields
|
88 |
$this->api_key = $this->get_option( 'api_key' );
|
|
|
89 |
$this->enabled = $this->get_option( 'enabled' );
|
90 |
|
91 |
// Get setting values
|
382 |
if ( $this->api_key == '' ) {
|
383 |
return false;
|
384 |
}
|
385 |
+
require_once( 'api/class-ss-wc-mailchimp-api.php' );
|
386 |
+
self::$api = new SS_WC_MailChimp_API( $this->api_key );
|
387 |
}
|
388 |
return self::$api;
|
389 |
}
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: anderly, saintsystems
|
|
3 |
Tags: woocommerce, mailchimp
|
4 |
Requires at least: 3.5.1
|
5 |
Tested up to: 4.6.1
|
6 |
-
Stable tag: 1.3.
|
7 |
License: GPLv3
|
8 |
|
9 |
Simple and flexible MailChimp integration for WooCommerce.
|
@@ -85,6 +85,9 @@ Also, if you enjoy using the software [we'd love it if you could give us a revie
|
|
85 |
|
86 |
== Changelog ==
|
87 |
|
|
|
|
|
|
|
88 |
= 1.3.8 =
|
89 |
* Tested up to WordPress 4.6.1
|
90 |
* Tested up to WooCommerce 2.6.4
|
3 |
Tags: woocommerce, mailchimp
|
4 |
Requires at least: 3.5.1
|
5 |
Tested up to: 4.6.1
|
6 |
+
Stable tag: 1.3.9
|
7 |
License: GPLv3
|
8 |
|
9 |
Simple and flexible MailChimp integration for WooCommerce.
|
85 |
|
86 |
== Changelog ==
|
87 |
|
88 |
+
= 1.3.9 =
|
89 |
+
* Rename MCAPI class to prevent collisions with other plugins using MCAPI
|
90 |
+
|
91 |
= 1.3.8 =
|
92 |
* Tested up to WordPress 4.6.1
|
93 |
* Tested up to WooCommerce 2.6.4
|
woocommerce-mailchimp.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* Description: WooCommerce MailChimp provides simple MailChimp integration for WooCommerce.
|
6 |
* Author: Adam Anderly
|
7 |
* Author URI: http://anderly.com
|
8 |
-
* Version: 1.3.
|
9 |
* Text Domain: ss_wc_mailchimp
|
10 |
* Domain Path: languages
|
11 |
*
|
5 |
* Description: WooCommerce MailChimp provides simple MailChimp integration for WooCommerce.
|
6 |
* Author: Adam Anderly
|
7 |
* Author URI: http://anderly.com
|
8 |
+
* Version: 1.3.9
|
9 |
* Text Domain: ss_wc_mailchimp
|
10 |
* Domain Path: languages
|
11 |
*
|