diff --git a/code/MCAPI.php b/code/MCAPI.php index 3ffc966..f169a75 100644 --- a/code/MCAPI.php +++ b/code/MCAPI.php @@ -1,34 +1,35 @@ secure = $secure; $this->apiUrl = parse_url("http://api.mailchimp.com/" . $this->version . "/?output=php"); $this->api_key = $apikey; } - function setTimeout($seconds){ - if (is_int($seconds)){ + public function setTimeout($seconds) + { + if (is_int($seconds)) { $this->timeout = $seconds; return true; } } - function getTimeout(){ + public function getTimeout() + { return $this->timeout; } - function useSecure($val){ - if ($val===true){ + public function useSecure($val) + { + if ($val===true) { $this->secure = true; } else { $this->secure = false; @@ -68,7 +73,8 @@ function useSecure($val){ * @param string $cid the id of the campaign to unschedule * @return boolean true on success */ - function campaignUnschedule($cid) { + public function campaignUnschedule($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignUnschedule", $params); @@ -86,7 +92,8 @@ function campaignUnschedule($cid) { * @param string $schedule_time_b optional -the time to schedule Group B of an A/B Split "schedule" campaign - 24 hour format in GMT, eg "2013-12-30 20:30:00" * @return boolean true on success */ - function campaignSchedule($cid, $schedule_time, $schedule_time_b=NULL) { + public function campaignSchedule($cid, $schedule_time, $schedule_time_b=null) + { $params = array(); $params["cid"] = $cid; $params["schedule_time"] = $schedule_time; @@ -105,7 +112,8 @@ function campaignSchedule($cid, $schedule_time, $schedule_time_b=NULL) { * @param int $stagger_mins optional - the number of minutes between each batch - 5, 10, 15, 20, 25, 30, or 60. defaults to 5 * @return boolean true on success */ - function campaignScheduleBatch($cid, $schedule_time, $num_batches=2, $stagger_mins=5) { + public function campaignScheduleBatch($cid, $schedule_time, $num_batches=2, $stagger_mins=5) + { $params = array(); $params["cid"] = $cid; $params["schedule_time"] = $schedule_time; @@ -122,7 +130,8 @@ function campaignScheduleBatch($cid, $schedule_time, $num_batches=2, $stagger_mi * @param string $cid the id of the campaign to pause * @return boolean true on success */ - function campaignResume($cid) { + public function campaignResume($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignResume", $params); @@ -136,7 +145,8 @@ function campaignResume($cid) { * @param string $cid the id of the campaign to pause * @return boolean true on success */ - function campaignPause($cid) { + public function campaignPause($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignPause", $params); @@ -153,7 +163,8 @@ function campaignPause($cid) { * @param string $cid the id of the campaign to send * @return boolean true on success */ - function campaignSendNow($cid) { + public function campaignSendNow($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignSendNow", $params); @@ -172,8 +183,9 @@ function campaignSendNow($cid) { * @param string $send_type optional by default (null) both formats are sent - "html" or "text" send just that format * @return boolean true on success */ - function campaignSendTest($cid, $test_emails=array ( -), $send_type=NULL) { + public function campaignSendTest($cid, $test_emails=array( +), $send_type=null) + { $params = array(); $params["cid"] = $cid; $params["test_emails"] = $test_emails; @@ -290,7 +302,8 @@ function campaignSendTest($cid, $test_emails=array ( Valid Values: any string * @return int total The total number of subscribers matching your segmentation options */ - function campaignSegmentTest($list_id, $options) { + public function campaignSegmentTest($list_id, $options) + { $params = array(); $params["list_id"] = $list_id; $params["options"] = $options; @@ -398,7 +411,8 @@ function campaignSegmentTest($list_id, $options) { * * @return string the ID for the created campaign */ - function campaignCreate($type, $options, $content, $segment_opts=NULL, $type_opts=NULL) { + public function campaignCreate($type, $options, $content, $segment_opts=null, $type_opts=null) + { $params = array(); $params["type"] = $type; $params["options"] = $options; @@ -429,7 +443,8 @@ function campaignCreate($type, $options, $content, $segment_opts=NULL, $type_opt * @param mixed $value an appropriate value for the parameter ( see campaignCreate() ). For items in the options array, this will be that parameter's value. For additional parameters, this is the same value passed to them. * @return boolean true if the update succeeds, otherwise an error will be thrown */ - function campaignUpdate($cid, $name, $value) { + public function campaignUpdate($cid, $name, $value) + { $params = array(); $params["cid"] = $cid; $params["name"] = $name; @@ -446,7 +461,8 @@ function campaignUpdate($cid, $name, $value) { * @param string $cid the Campaign Id to replicate * @return string the id of the replicated Campaign created, otherwise an error will be thrown */ - function campaignReplicate($cid) { + public function campaignReplicate($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignReplicate", $params); @@ -461,7 +477,8 @@ function campaignReplicate($cid) { * @param string $cid the Campaign Id to delete * @return boolean true if the delete succeeds, otherwise an error will be thrown */ - function campaignDelete($cid) { + public function campaignDelete($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignDelete", $params); @@ -533,8 +550,9 @@ function campaignDelete($cid) { array segment_opts the segment used for the campaign - can be passed to campaignSegmentTest() or campaignCreate() array type_opts the type-specific options for the campaign - can be passed to campaignCreate() */ - function campaigns($filters=array ( -), $start=0, $limit=25, $sort_field='create_time', $sort_dir='DESC') { + public function campaigns($filters=array( +), $start=0, $limit=25, $sort_field='create_time', $sort_dir='DESC') + { $params = array(); $params["filters"] = $filters; $params["start"] = $start; @@ -608,7 +626,8 @@ function campaigns($filters=array ( int recipients_click unique clicks seen during the hour */ - function campaignStats($cid) { + public function campaignStats($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignStats", $params); @@ -627,7 +646,8 @@ function campaignStats($cid) { int clicks Number of times the specific link was clicked int unique Number of unique people who clicked on the specific link */ - function campaignClickStats($cid) { + public function campaignClickStats($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignClickStats", $params); @@ -657,7 +677,8 @@ function campaignClickStats($cid) { int clicks_pct Percentage of clicks from this domain (whole number) int unsubs_pct Percentage of unsubs from this domain (whole number) */ - function campaignEmailDomainPerformance($cid) { + public function campaignEmailDomainPerformance($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignEmailDomainPerformance", $params); @@ -680,7 +701,8 @@ function campaignEmailDomainPerformance($cid) { string absplit_group if this was an absplit campaign, one of 'a','b', or 'winner' string tz_group if this was an timewarp campaign the timezone GMT offset the member was included in */ - function campaignMembers($cid, $status=NULL, $start=0, $limit=1000) { + public function campaignMembers($cid, $status=null, $start=0, $limit=1000) + { $params = array(); $params["cid"] = $cid; $params["status"] = $status; @@ -703,7 +725,8 @@ function campaignMembers($cid, $status=NULL, $start=0, $limit=1000) { int total the total number of hard bounces for the campaign array data array of the full email addresses that bounced */ - function campaignHardBounces($cid, $start=0, $limit=1000) { + public function campaignHardBounces($cid, $start=0, $limit=1000) + { $params = array(); $params["cid"] = $cid; $params["start"] = $start; @@ -725,7 +748,8 @@ function campaignHardBounces($cid, $start=0, $limit=1000) { int total the total number of soft bounces for the campaign array data array of the full email addresses that bounced */ - function campaignSoftBounces($cid, $start=0, $limit=1000) { + public function campaignSoftBounces($cid, $start=0, $limit=1000) + { $params = array(); $params["cid"] = $cid; $params["start"] = $start; @@ -748,7 +772,8 @@ function campaignSoftBounces($cid, $start=0, $limit=1000) { string reason For unsubscribes only - the reason collected for the unsubscribe. If populated, one of 'NORMAL','NOSIGNUP','INAPPROPRIATE','SPAM','OTHER' string reason_text For unsubscribes only - if the reason is OTHER, the text entered. */ - function campaignUnsubscribes($cid, $start=0, $limit=1000) { + public function campaignUnsubscribes($cid, $start=0, $limit=1000) + { $params = array(); $params["cid"] = $cid; $params["start"] = $start; @@ -774,7 +799,8 @@ function campaignUnsubscribes($cid, $start=0, $limit=1000) { string email the email address that reported abuse string type an internal type generally specifying the orginating mail provider - may not be useful outside of filling report views */ - function campaignAbuseReports($cid, $since=NULL, $start=0, $limit=500) { + public function campaignAbuseReports($cid, $since=null, $start=0, $limit=500) + { $params = array(); $params["cid"] = $cid; $params["since"] = $since; @@ -796,7 +822,8 @@ function campaignAbuseReports($cid, $since=NULL, $start=0, $limit=500) { msg the advice message type the "type" of the message. one of: negative, positive, or neutral */ - function campaignAdvice($cid) { + public function campaignAdvice($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignAdvice", $params); @@ -825,7 +852,8 @@ function campaignAdvice($cid) { string name the name of the goal int conversions the number of conversions for the goal */ - function campaignAnalytics($cid) { + public function campaignAnalytics($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignAnalytics", $params); @@ -844,7 +872,8 @@ function campaignAnalytics($cid) { int opens The total number of opens that occurred in the country boolean region_detail Whether or not a subsequent call to campaignGeoOpensByCountry() will return anything */ - function campaignGeoOpens($cid) { + public function campaignGeoOpens($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignGeoOpens", $params); @@ -863,7 +892,8 @@ function campaignGeoOpens($cid) { string name The name of the region, if we have one. For blank "code" values, this will be "Rest of Country" int opens The total number of opens that occurred in the country */ - function campaignGeoOpensForCountry($cid, $code) { + public function campaignGeoOpensForCountry($cid, $code) + { $params = array(); $params["cid"] = $cid; $params["code"] = $code; @@ -905,7 +935,8 @@ function campaignGeoOpensForCountry($cid, $code) { string first_click date and time of the first click seen from this referrer string last_click date and time of the first click seen from this referrer */ - function campaignEepUrlStats($cid) { + public function campaignEepUrlStats($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignEepUrlStats", $params); @@ -925,7 +956,8 @@ function campaignEepUrlStats($cid) { string email the email address that bounced string message the entire bounce message received */ - function campaignBounceMessage($cid, $email) { + public function campaignBounceMessage($cid, $email) + { $params = array(); $params["cid"] = $cid; $params["email"] = $email; @@ -952,7 +984,8 @@ function campaignBounceMessage($cid, $email) { string email the email address that bounced string message the entire bounce message received */ - function campaignBounceMessages($cid, $start=0, $limit=25, $since=NULL) { + public function campaignBounceMessages($cid, $start=0, $limit=25, $since=null) + { $params = array(); $params["cid"] = $cid; $params["start"] = $start; @@ -991,7 +1024,8 @@ function campaignBounceMessages($cid, $start=0, $limit=25, $since=NULL) { double qty optional the quantity of the item ordered - defaults to 1 double cost optional the cost of a single item (ie, not the extended cost of the line) - defaults to 0 */ - function campaignEcommOrders($cid, $start=0, $limit=100, $since=NULL) { + public function campaignEcommOrders($cid, $start=0, $limit=100, $since=null) + { $params = array(); $params["cid"] = $cid; $params["start"] = $start; @@ -1017,8 +1051,9 @@ function campaignEcommOrders($cid, $start=0, $limit=100, $since=NULL) { 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 string password If secured, the password for the report, otherwise this field will not be returned */ - function campaignShareReport($cid, $opts=array ( -)) { + public function campaignShareReport($cid, $opts=array( +)) + { $params = array(); $params["cid"] = $cid; $params["opts"] = $opts; @@ -1036,7 +1071,8 @@ function campaignShareReport($cid, $opts=array ( string html The HTML content used for the campaign with merge tags intact string text The Text content used for the campaign with merge tags intact */ - function campaignContent($cid, $for_archive=true) { + public function campaignContent($cid, $for_archive=true) + { $params = array(); $params["cid"] = $cid; $params["for_archive"] = $for_archive; @@ -1052,7 +1088,8 @@ function campaignContent($cid, $for_archive=true) { * @param string $cid the campaign id to get content for (can be gathered using campaigns()) * @return array array containing all content section for the campaign - section name are dependent upon the template used and thus can't be documented */ - function campaignTemplateContent($cid) { + public function campaignTemplateContent($cid) + { $params = array(); $params["cid"] = $cid; return $this->callServer("campaignTemplateContent", $params); @@ -1072,7 +1109,8 @@ function campaignTemplateContent($cid) { string email Email address that opened the campaign int open_count Total number of times the campaign was opened by this email address */ - function campaignOpenedAIM($cid, $start=0, $limit=1000) { + public function campaignOpenedAIM($cid, $start=0, $limit=1000) + { $params = array(); $params["cid"] = $cid; $params["start"] = $start; @@ -1092,7 +1130,8 @@ function campaignOpenedAIM($cid, $start=0, $limit=1000) { int total the total number of records matched array data the email addresses that did not open the campaign */ - function campaignNotOpenedAIM($cid, $start=0, $limit=1000) { + public function campaignNotOpenedAIM($cid, $start=0, $limit=1000) + { $params = array(); $params["cid"] = $cid; $params["start"] = $start; @@ -1115,7 +1154,8 @@ function campaignNotOpenedAIM($cid, $start=0, $limit=1000) { string email Email address that opened the campaign int clicks Total number of times the URL was clicked on by this email address */ - function campaignClickDetailAIM($cid, $url, $start=0, $limit=1000) { + public function campaignClickDetailAIM($cid, $url, $start=0, $limit=1000) + { $params = array(); $params["cid"] = $cid; $params["url"] = $url; @@ -1139,7 +1179,8 @@ function campaignClickDetailAIM($cid, $url, $start=0, $limit=1000) { string timestamp Time the action occurred string url For clicks, the URL that was clicked */ - function campaignEmailStatsAIM($cid, $email_address) { + public function campaignEmailStatsAIM($cid, $email_address) + { $params = array(); $params["cid"] = $cid; $params["email_address"] = $email_address; @@ -1163,7 +1204,8 @@ function campaignEmailStatsAIM($cid, $email_address) { string timestamp Time the action occurred string url For clicks, the URL that was clicked */ - function campaignEmailStatsAIMAll($cid, $start=0, $limit=100) { + public function campaignEmailStatsAIMAll($cid, $start=0, $limit=100) + { $params = array(); $params["cid"] = $cid; $params["start"] = $start; @@ -1199,7 +1241,8 @@ function campaignEmailStatsAIMAll($cid, $start=0, $limit=100) { * @return bool true if the data is saved, otherwise an error is thrown. */ - function campaignEcommOrderAdd($order) { + public function campaignEcommOrderAdd($order) + { $params = array(); $params["order"] = $order; return $this->callServer("campaignEcommOrderAdd", $params); @@ -1261,8 +1304,9 @@ function campaignEcommOrderAdd($order) { double click_rate the average click rate per campaign for the list (empty value if we haven't calculated this yet) array modules Any list specific modules installed for this list (example is SocialPro) */ - function lists($filters=array ( -), $start=0, $limit=25, $sort_field='created', $sort_dir='DESC') { + public function lists($filters=array( +), $start=0, $limit=25, $sort_field='created', $sort_dir='DESC') + { $params = array(); $params["filters"] = $filters; $params["start"] = $start; @@ -1292,7 +1336,8 @@ function lists($filters=array ( array choices For radio and dropdown field types, an array of the options available int id an unchanging id for the merge var */ - function listMergeVars($id) { + public function listMergeVars($id) + { $params = array(); $params["id"] = $id; return $this->callServer("listMergeVars", $params); @@ -1321,8 +1366,9 @@ function listMergeVars($id) { * @return bool true if the request succeeds, otherwise an error will be thrown */ - function listMergeVarAdd($id, $tag, $name, $options=array ( -)) { + public function listMergeVarAdd($id, $tag, $name, $options=array( +)) + { $params = array(); $params["id"] = $id; $params["tag"] = $tag; @@ -1341,7 +1387,8 @@ function listMergeVarAdd($id, $tag, $name, $options=array ( * @param array $options The options to change for a merge var. See listMergeVarAdd() for valid options. "tag" and "name" may also be used here. * @return bool true if the request succeeds, otherwise an error will be thrown */ - function listMergeVarUpdate($id, $tag, $options) { + public function listMergeVarUpdate($id, $tag, $options) + { $params = array(); $params["id"] = $id; $params["tag"] = $tag; @@ -1360,7 +1407,8 @@ function listMergeVarUpdate($id, $tag, $options) { * @param string $tag The merge tag to delete * @return bool true if the request succeeds, otherwise an error will be thrown */ - function listMergeVarDel($id, $tag) { + public function listMergeVarDel($id, $tag) + { $params = array(); $params["id"] = $id; $params["tag"] = $tag; @@ -1376,7 +1424,8 @@ function listMergeVarDel($id, $tag) { * @param string $tag The merge tag to reset * @return bool true if the request succeeds, otherwise an error will be thrown */ - function listMergeVarReset($id, $tag) { + public function listMergeVarReset($id, $tag) + { $params = array(); $params["id"] = $id; $params["tag"] = $tag; @@ -1400,7 +1449,8 @@ function listMergeVarReset($id, $tag) { string display_order the display order of the group, if set int subscribers total number of subscribers who have this group */ - function listInterestGroupings($id) { + public function listInterestGroupings($id) + { $params = array(); $params["id"] = $id; return $this->callServer("listInterestGroupings", $params); @@ -1417,7 +1467,8 @@ function listInterestGroupings($id) { * @param int $grouping_id optional The grouping to add the new group to - get using listInterestGrouping() . If not supplied, the first grouping on the list is used. * @return bool true if the request succeeds, otherwise an error will be thrown */ - function listInterestGroupAdd($id, $group_name, $grouping_id=NULL) { + public function listInterestGroupAdd($id, $group_name, $grouping_id=null) + { $params = array(); $params["id"] = $id; $params["group_name"] = $group_name; @@ -1435,7 +1486,8 @@ function listInterestGroupAdd($id, $group_name, $grouping_id=NULL) { * @param int $grouping_id The grouping to delete the group from - get using listInterestGrouping() . If not supplied, the first grouping on the list is used. * @return bool true if the request succeeds, otherwise an error will be thrown */ - function listInterestGroupDel($id, $group_name, $grouping_id=NULL) { + public function listInterestGroupDel($id, $group_name, $grouping_id=null) + { $params = array(); $params["id"] = $id; $params["group_name"] = $group_name; @@ -1453,7 +1505,8 @@ function listInterestGroupDel($id, $group_name, $grouping_id=NULL) { * @param int $grouping_id optional The grouping to delete the group from - get using listInterestGrouping() . If not supplied, the first grouping on the list is used. * @return bool true if the request succeeds, otherwise an error will be thrown */ - function listInterestGroupUpdate($id, $old_name, $new_name, $grouping_id=NULL) { + public function listInterestGroupUpdate($id, $old_name, $new_name, $grouping_id=null) + { $params = array(); $params["id"] = $id; $params["old_name"] = $old_name; @@ -1474,7 +1527,8 @@ function listInterestGroupUpdate($id, $old_name, $new_name, $grouping_id=NULL) { * @param array $groups The lists of initial group names to be added - at least 1 is required and the names must be unique within a grouping. If the number takes you over the 60 group limit, an error will be thrown. * @return int the new grouping id if the request succeeds, otherwise an error will be thrown */ - function listInterestGroupingAdd($id, $name, $type, $groups) { + public function listInterestGroupingAdd($id, $name, $type, $groups) + { $params = array(); $params["id"] = $id; $params["name"] = $name; @@ -1493,7 +1547,8 @@ function listInterestGroupingAdd($id, $name, $type, $groups) { * @param string $value The new value of the field. Grouping names must be unique - only "hidden" and "checkboxes" grouping types can be converted between each other. * @return bool true if the request succeeds, otherwise an error will be thrown */ - function listInterestGroupingUpdate($grouping_id, $name, $value) { + public function listInterestGroupingUpdate($grouping_id, $name, $value) + { $params = array(); $params["grouping_id"] = $grouping_id; $params["name"] = $name; @@ -1509,7 +1564,8 @@ function listInterestGroupingUpdate($grouping_id, $name, $value) { * @param int $grouping_id the interest grouping id - get from listInterestGroupings() * @return bool true if the request succeeds, otherwise an error will be thrown */ - function listInterestGroupingDel($grouping_id) { + public function listInterestGroupingDel($grouping_id) + { $params = array(); $params["grouping_id"] = $grouping_id; return $this->callServer("listInterestGroupingDel", $params); @@ -1534,7 +1590,8 @@ function listInterestGroupingDel($grouping_id) { bool admin whether admin (manual, in-app) triggered actions are returned bool api whether api triggered actions are returned */ - function listWebhooks($id) { + public function listWebhooks($id) + { $params = array(); $params["id"] = $id; return $this->callServer("listWebhooks", $params); @@ -1559,9 +1616,10 @@ function listWebhooks($id) { bool api optional actions that happen via API calls, defaults to false * @return bool true if the call succeeds, otherwise an exception will be thrown */ - function listWebhookAdd($id, $url, $actions=array ( -), $sources=array ( -)) { + public function listWebhookAdd($id, $url, $actions=array( +), $sources=array( +)) + { $params = array(); $params["id"] = $id; $params["url"] = $url; @@ -1578,7 +1636,8 @@ function listWebhookAdd($id, $url, $actions=array ( * @param string $url the URL of a Webhook on this list * @return boolean true if the call succeeds, otherwise an exception will be thrown */ - function listWebhookDel($id, $url) { + public function listWebhookDel($id, $url) + { $params = array(); $params["id"] = $id; $params["url"] = $url; @@ -1598,7 +1657,8 @@ function listWebhookDel($id, $url) { string last_update the date/time the segment was last updated (add or del) string last_reset the date/time the segment was last reset (ie had all members cleared from it) */ - function listStaticSegments($id) { + public function listStaticSegments($id) + { $params = array(); $params["id"] = $id; return $this->callServer("listStaticSegments", $params); @@ -1615,7 +1675,8 @@ function listStaticSegments($id) { * @param string $name a unique name per list for the segment - 50 byte maximum length, anything longer will throw an error * @return int the id of the new segment, otherwise an error will be thrown. */ - function listStaticSegmentAdd($id, $name) { + public function listStaticSegmentAdd($id, $name) + { $params = array(); $params["id"] = $id; $params["name"] = $name; @@ -1630,7 +1691,8 @@ function listStaticSegmentAdd($id, $name) { * @param int $seg_id the id of the static segment to reset - get from listStaticSegments() * @return bool true if it worked, otherwise an error is thrown. */ - function listStaticSegmentReset($id, $seg_id) { + public function listStaticSegmentReset($id, $seg_id) + { $params = array(); $params["id"] = $id; $params["seg_id"] = $seg_id; @@ -1645,7 +1707,8 @@ function listStaticSegmentReset($id, $seg_id) { * @param int $seg_id the id of the static segment to delete - get from listStaticSegments() * @return bool true if it worked, otherwise an error is thrown. */ - function listStaticSegmentDel($id, $seg_id) { + public function listStaticSegmentDel($id, $seg_id) + { $params = array(); $params["id"] = $id; $params["seg_id"] = $seg_id; @@ -1667,7 +1730,8 @@ function listStaticSegmentDel($id, $seg_id) { string code the error code string msg the full error message */ - function listStaticSegmentMembersAdd($id, $seg_id, $batch) { + public function listStaticSegmentMembersAdd($id, $seg_id, $batch) + { $params = array(); $params["id"] = $id; $params["seg_id"] = $seg_id; @@ -1690,7 +1754,8 @@ function listStaticSegmentMembersAdd($id, $seg_id, $batch) { string code the error code string msg the full error message */ - function listStaticSegmentMembersDel($id, $seg_id, $batch) { + public function listStaticSegmentMembersDel($id, $seg_id, $batch) + { $params = array(); $params["id"] = $id; $params["seg_id"] = $seg_id; @@ -1743,7 +1808,8 @@ function listStaticSegmentMembersDel($id, $seg_id, $batch) { * @param bool $send_welcome optional 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. If double_optin is true, this has no effect. defaults to false. * @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) */ - function listSubscribe($id, $email_address, $merge_vars=NULL, $email_type='html', $double_optin=true, $update_existing=false, $replace_interests=true, $send_welcome=false) { + public function listSubscribe($id, $email_address, $merge_vars=null, $email_type='html', $double_optin=true, $update_existing=false, $replace_interests=true, $send_welcome=false) + { $params = array(); $params["id"] = $id; $params["email_address"] = $email_address; @@ -1770,7 +1836,8 @@ function listSubscribe($id, $email_address, $merge_vars=NULL, $email_type='html' * @param boolean $send_notify flag to send the unsubscribe notification email to the address defined in the list email notification settings, defaults to true * @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) */ - function listUnsubscribe($id, $email_address, $delete_member=false, $send_goodbye=true, $send_notify=true) { + public function listUnsubscribe($id, $email_address, $delete_member=false, $send_goodbye=true, $send_notify=true) + { $params = array(); $params["id"] = $id; $params["email_address"] = $email_address; @@ -1794,7 +1861,8 @@ function listUnsubscribe($id, $email_address, $delete_member=false, $send_goodby * @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) * @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 */ - function listUpdateMember($id, $email_address, $merge_vars, $email_type='', $replace_interests=true) { + public function listUpdateMember($id, $email_address, $merge_vars, $email_type='', $replace_interests=true) + { $params = array(); $params["id"] = $id; $params["email_address"] = $email_address; @@ -1828,7 +1896,8 @@ function listUpdateMember($id, $email_address, $merge_vars, $email_type='', $rep int code the error code string message the full error message */ - function listBatchSubscribe($id, $batch, $double_optin=true, $update_existing=false, $replace_interests=true) { + public function listBatchSubscribe($id, $batch, $double_optin=true, $update_existing=false, $replace_interests=true) + { $params = array(); $params["id"] = $id; $params["batch"] = $batch; @@ -1858,7 +1927,8 @@ function listBatchSubscribe($id, $batch, $double_optin=true, $update_existing=fa string message the full error message */ - function listBatchUnsubscribe($id, $emails, $delete_member=false, $send_goodbye=true, $send_notify=false) { + public function listBatchUnsubscribe($id, $emails, $delete_member=false, $send_goodbye=true, $send_notify=false) + { $params = array(); $params["id"] = $id; $params["emails"] = $emails; @@ -1889,7 +1959,8 @@ function listBatchUnsubscribe($id, $emails, $delete_member=false, $send_goodbye= string reason For unsubscribes only - the reason collected for the unsubscribe. If populated, one of 'NORMAL','NOSIGNUP','INAPPROPRIATE','SPAM','OTHER' string reason_text For unsubscribes only - if the reason is OTHER, the text entered. */ - function listMembers($id, $status='subscribed', $since=NULL, $start=0, $limit=100, $sort_dir='ASC') { + public function listMembers($id, $status='subscribed', $since=null, $start=0, $limit=100, $sort_dir='ASC') + { $params = array(); $params["id"] = $id; $params["status"] = $status; @@ -1953,7 +2024,8 @@ function listMembers($id, $status='subscribed', $since=NULL, $start=0, $limit=10 string updated the date the note was last updated string created_by_name the name of the user who created the note. This can change as users update their profile. */ - function listMemberInfo($id, $email_address) { + public function listMemberInfo($id, $email_address) + { $params = array(); $params["id"] = $id; $params["email_address"] = $email_address; @@ -1978,7 +2050,8 @@ function listMemberInfo($id, $email_address) { string bounce_type For backwards compat, this will exist and be the same data as "type" string campaign_id The campaign id the action was related to, if it exists - otherwise empty (ie, direct unsub from list) */ - function listMemberActivity($id, $email_address) { + public function listMemberActivity($id, $email_address) + { $params = array(); $params["id"] = $id; $params["email_address"] = $email_address; @@ -2004,7 +2077,8 @@ function listMemberActivity($id, $email_address) { string campaign_id the unique id for the campaign that report was made against string type an internal type generally specifying the orginating mail provider - may not be useful outside of filling report views */ - function listAbuseReports($id, $start=0, $limit=500, $since=NULL) { + public function listAbuseReports($id, $start=0, $limit=500, $since=null) + { $params = array(); $params["id"] = $id; $params["start"] = $start; @@ -2027,7 +2101,8 @@ function listAbuseReports($id, $start=0, $limit=500, $since=NULL) { int imports number of subscribers imported during the month int optins number of subscribers who opted-in during the month */ - function listGrowthHistory($id) { + public function listGrowthHistory($id) + { $params = array(); $params["id"] = $id; return $this->callServer("listGrowthHistory", $params); @@ -2053,7 +2128,8 @@ function listGrowthHistory($id) { int other_adds number of non-double optin subscribes for the list (manual, API, or import) int other_removes number of non-manual unsubscribes for the list (deletions, empties, soft-bounce removals) */ - function listActivity($id) { + public function listActivity($id) + { $params = array(); $params["id"] = $id; return $this->callServer("listActivity", $params); @@ -2071,7 +2147,8 @@ function listActivity($id) { double percent the percent of subscribers in the country double total the total number of subscribers in the country */ - function listLocations($id) { + public function listLocations($id) + { $params = array(); $params["id"] = $id; return $this->callServer("listLocations", $params); @@ -2099,7 +2176,8 @@ function listLocations($id) { string percent percent of list using the client string members total members using the client */ - function listClients($id) { + public function listClients($id) + { $params = array(); $params["id"] = $id; return $this->callServer("listClients", $params); @@ -2128,9 +2206,10 @@ function listClients($id) { string date_created The date/time the template was created boolean edit_source Whether or not you are able to edit the source of a template. */ - function templates($types=array ( -), $category=NULL, $inactives=array ( -)) { + public function templates($types=array( +), $category=null, $inactives=array( +)) + { $params = array(); $params["types"] = $types; $params["category"] = $category; @@ -2151,7 +2230,8 @@ function templates($types=array ( string source the full source of the template as if you exported it via our template editor string preview similar to the source, but the rendered version of the source from our popup preview */ - function templateInfo($tid, $type='user') { + public function templateInfo($tid, $type='user') + { $params = array(); $params["tid"] = $tid; $params["type"] = $type; @@ -2169,7 +2249,8 @@ function templateInfo($tid, $type='user') { * @param string $html a string specifying the entire template to be created. This is NOT campaign content. They are intended to utilize our template language. * @return int the new template id, otherwise an error is thrown. */ - function templateAdd($name, $html) { + public function templateAdd($name, $html) + { $params = array(); $params["name"] = $name; $params["html"] = $html; @@ -2188,7 +2269,8 @@ function templateAdd($name, $html) { * @return boolean true if the template was updated, otherwise an error will be thrown */ - function templateUpdate($id, $values) { + public function templateUpdate($id, $values) + { $params = array(); $params["id"] = $id; $params["values"] = $values; @@ -2203,7 +2285,8 @@ function templateUpdate($id, $values) { * @param int $id the id of the user template to delete * @return boolean true if the template was deleted, otherwise an error will be thrown */ - function templateDel($id) { + public function templateDel($id) + { $params = array(); $params["id"] = $id; return $this->callServer("templateDel", $params); @@ -2217,7 +2300,8 @@ function templateDel($id) { * @param int $id the id of the user template to reactivate * @return boolean true if the template was deleted, otherwise an error will be thrown */ - function templateUndel($id) { + public function templateUndel($id) + { $params = array(); $params["id"] = $id; return $this->callServer("templateUndel", $params); @@ -2296,8 +2380,9 @@ function templateUndel($id) { int order_id the order number credits were applied to string order_desc the order description */ - function getAccountDetails($exclude=array ( -)) { + public function getAccountDetails($exclude=array( +)) + { $params = array(); $params["exclude"] = $exclude; return $this->callServer("getAccountDetails", $params); @@ -2313,7 +2398,8 @@ function getAccountDetails($exclude=array ( string status the status of the verification - either "verified" or "pending" string email the email address used for verification */ - function getVerifiedDomains() { + public function getVerifiedDomains() + { $params = array(); return $this->callServer("getVerifiedDomains", $params); } @@ -2328,7 +2414,8 @@ function getVerifiedDomains() { * @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. * @return string the content pass in converted to text. */ - function generateText($type, $content) { + public function generateText($type, $content) + { $params = array(); $params["type"] = $type; $params["content"] = $content; @@ -2345,7 +2432,8 @@ function generateText($type, $content) { * @param bool $strip_css optional Whether you want the CSS <style> tags stripped from the returned document. Defaults to false. * @return string Your HTML content with all CSS inlined, just like if we sent it. */ - function inlineCss($html, $strip_css=false) { + public function inlineCss($html, $strip_css=false) + { $params = array(); $params["html"] = $html; $params["strip_css"] = $strip_css; @@ -2366,7 +2454,8 @@ function inlineCss($html, $strip_css=false) { string date_created The date/time the folder was created string type The type of the folders being returned, just to make sure you know. */ - function folders($type='campaign') { + public function folders($type='campaign') + { $params = array(); $params["type"] = $type; return $this->callServer("folders", $params); @@ -2383,7 +2472,8 @@ function folders($type='campaign') { * @param string $type optional the type of folder to create - either "campaign" or "autoresponder". Defaults to "campaign" * @return int the folder_id of the newly created folder. */ - function folderAdd($name, $type='campaign') { + public function folderAdd($name, $type='campaign') + { $params = array(); $params["name"] = $name; $params["type"] = $type; @@ -2400,7 +2490,8 @@ function folderAdd($name, $type='campaign') { * @param string $type optional the type of folder to create - either "campaign" or "autoresponder". Defaults to "campaign" * @return bool true if the update worked, otherwise an exception is thrown */ - function folderUpdate($fid, $name, $type='campaign') { + public function folderUpdate($fid, $name, $type='campaign') + { $params = array(); $params["fid"] = $fid; $params["name"] = $name; @@ -2417,7 +2508,8 @@ function folderUpdate($fid, $name, $type='campaign') { * @param string $type optional the type of folder to create - either "campaign" or "autoresponder". Defaults to "campaign" * @return bool true if the delete worked, otherwise an exception is thrown */ - function folderDel($fid, $type='campaign') { + public function folderDel($fid, $type='campaign') + { $params = array(); $params["fid"] = $fid; $params["type"] = $type; @@ -2453,7 +2545,8 @@ function folderDel($fid, $type='campaign') { int qty the quantity ordered double cost the cost of the item */ - function ecommOrders($start=0, $limit=100, $since=NULL) { + public function ecommOrders($start=0, $limit=100, $since=null) + { $params = array(); $params["start"] = $start; $params["limit"] = $limit; @@ -2490,7 +2583,8 @@ function ecommOrders($start=0, $limit=100, $since=NULL) { * @return bool true if the data is saved, otherwise an error is thrown. */ - function ecommOrderAdd($order) { + public function ecommOrderAdd($order) + { $params = array(); $params["order"] = $order; return $this->callServer("ecommOrderAdd", $params); @@ -2505,7 +2599,8 @@ function ecommOrderAdd($order) { * @param string $order_id the order id (generated by the store) to delete * @return bool true if an order is deleted, otherwise an error is thrown. */ - function ecommOrderDel($store_id, $order_id) { + public function ecommOrderDel($store_id, $order_id) + { $params = array(); $params["store_id"] = $store_id; $params["order_id"] = $order_id; @@ -2520,7 +2615,8 @@ function ecommOrderDel($store_id, $order_id) { * @param string $email_address the email address to check OR the email "id" returned from listMemberInfo, Webhooks, and Campaigns * @return array An array of list_ids the member is subscribed to. */ - function listsForEmail($email_address) { + public function listsForEmail($email_address) + { $params = array(); $params["email_address"] = $email_address; return $this->callServer("listsForEmail", $params); @@ -2537,7 +2633,8 @@ function listsForEmail($email_address) { bool verbose optional Whether or not to return verbose data (beta - this will change the return format into something undocumented, but consistent). defaults to false * @return array An array of campaign_ids the member received */ - function campaignsForEmail($email_address, $options=NULL) { + public function campaignsForEmail($email_address, $options=null) + { $params = array(); $params["email_address"] = $email_address; $params["options"] = $options; @@ -2557,7 +2654,8 @@ function campaignsForEmail($email_address, $options=NULL) { string campaign_id the list_id a message relates to, if applicable string update_time The date/time the message was last updated */ - function chimpChatter() { + public function chimpChatter() + { $params = array(); return $this->callServer("chimpChatter", $params); } @@ -2578,7 +2676,8 @@ function chimpChatter() { int total total members matching array members each entry will match the data format for a single member as returned by listMemberInfo() */ - function searchMembers($query, $id=NULL, $offset=0) { + public function searchMembers($query, $id=null, $offset=0) + { $params = array(); $params["query"] = $query; $params["id"] = $id; @@ -2601,7 +2700,8 @@ function searchMembers($query, $id=NULL, $offset=0) { string snippet the matching snippet for the campaign array campaign the matching campaign's details - will return same data as single campaign from campaigns() */ - function searchCampaigns($query, $offset=0, $snip_start=NULL, $snip_end=NULL) { + public function searchCampaigns($query, $offset=0, $snip_start=null, $snip_end=null) + { $params = array(); $params["query"] = $query; $params["offset"] = $offset; @@ -2625,7 +2725,8 @@ function searchCampaigns($query, $offset=0, $snip_start=NULL, $snip_end=NULL) { string created_at The date the key was created string expired_at The date the key was expired */ - function apikeys($username, $password, $expired=false) { + public function apikeys($username, $password, $expired=false) + { $params = array(); $params["username"] = $username; $params["password"] = $password; @@ -2643,7 +2744,8 @@ function apikeys($username, $password, $expired=false) { * @param string $password Your MailChimp password * @return string a new API Key that can be immediately used. */ - function apikeyAdd($username, $password) { + public function apikeyAdd($username, $password) + { $params = array(); $params["username"] = $username; $params["password"] = $password; @@ -2664,7 +2766,8 @@ function apikeyAdd($username, $password) { * @param string $password Your MailChimp password * @return boolean true if it worked, otherwise an error is thrown. */ - function apikeyExpire($username, $password) { + public function apikeyExpire($username, $password) + { $params = array(); $params["username"] = $username; $params["password"] = $password; @@ -2681,7 +2784,8 @@ function apikeyExpire($username, $password) { * * @return string returns "Everything's Chimpy!" if everything is chimpy, otherwise returns an error message */ - function ping() { + public function ping() + { $params = array(); return $this->callServer("ping", $params); } @@ -2696,7 +2800,8 @@ function ping() { * @return array the method completion status string status The status (success) of the call if it completed. Otherwise an error is thrown. */ - function deviceRegister($mobile_key, $details) { + public function deviceRegister($mobile_key, $details) + { $params = array(); $params["mobile_key"] = $mobile_key; $params["details"] = $details; @@ -2713,7 +2818,8 @@ function deviceRegister($mobile_key, $details) { * @return array the method completion status string status The status (success) of the call if it completed. Otherwise an error is thrown. */ - function deviceUnregister($mobile_key, $device_id) { + public function deviceUnregister($mobile_key, $device_id) + { $params = array(); $params["mobile_key"] = $mobile_key; $params["device_id"] = $device_id; @@ -2734,7 +2840,8 @@ function deviceUnregister($mobile_key, $device_id) { string email_address the email address which errored out string error an error message explaining the error */ - function gmonkeyAdd($id, $email_address) { + public function gmonkeyAdd($id, $email_address) + { $params = array(); $params["id"] = $id; $params["email_address"] = $email_address; @@ -2755,7 +2862,8 @@ function gmonkeyAdd($id, $email_address) { string email_address the email address which errored out string error an error message explaining the error */ - function gmonkeyDel($id, $email_address) { + public function gmonkeyDel($id, $email_address) + { $params = array(); $params["id"] = $id; $params["email_address"] = $email_address; @@ -2776,7 +2884,8 @@ function gmonkeyDel($id, $email_address) { int member_rating the rating of the subscriber. This will be 1 - 5 as described here string member_since the datetime the member was added and/or confirmed */ - function gmonkeyMembers() { + public function gmonkeyMembers() + { $params = array(); return $this->callServer("gmonkeyMembers", $params); } @@ -2807,7 +2916,8 @@ function gmonkeyMembers() { string cc 2 digit ISO-3166 country code string region generally state, province, or similar */ - function gmonkeyActivity() { + public function gmonkeyActivity() + { $params = array(); return $this->callServer("gmonkeyActivity", $params); } @@ -2817,7 +2927,8 @@ function gmonkeyActivity() { * @param mixed Method to call, with any parameters to pass along * @return mixed the result of the call */ - function callMethod() { + public function callMethod() + { $params = array(); return $this->callServer("callMethod", $params); } @@ -2826,26 +2937,29 @@ function callMethod() { * Actually connect to the server and call the requested methods, parsing the result * You should never have to call this function manually */ - function callServer($method, $params) { - $dc = "us1"; - if (strstr($this->api_key,"-")){ - list($key, $dc) = explode("-",$this->api_key,2); - if (!$dc) $dc = "us1"; + public function callServer($method, $params) + { + $dc = "us1"; + if (strstr($this->api_key, "-")) { + list($key, $dc) = explode("-", $this->api_key, 2); + if (!$dc) { + $dc = "us1"; + } } $host = $dc.".".$this->apiUrl["host"]; - $params["apikey"] = $this->api_key; + $params["apikey"] = $this->api_key; $this->errorMessage = ""; $this->errorCode = ""; $sep_changed = false; //sigh, apparently some distribs change this to & by default - if (ini_get("arg_separator.output")!="&"){ + if (ini_get("arg_separator.output")!="&") { $sep_changed = true; $orig_sep = ini_get("arg_separator.output"); ini_set("arg_separator.output", "&"); } $post_vars = http_build_query($params); - if ($sep_changed){ + if ($sep_changed) { ini_set("arg_separator.output", $orig_sep); } @@ -2858,12 +2972,12 @@ function callServer($method, $params) { $payload .= $post_vars; ob_start(); - if ($this->secure){ + if ($this->secure) { $sock = fsockopen("ssl://".$host, 443, $errno, $errstr, 30); } else { $sock = fsockopen($host, 80, $errno, $errstr, 30); } - if(!$sock) { + if (!$sock) { $this->errorMessage = "Could not connect (ERR $errno: $errstr)"; $this->errorCode = "-99"; ob_end_clean(); @@ -2889,27 +3003,29 @@ function callServer($method, $params) { list($headers, $response) = explode("\r\n\r\n", $response, 2); $headers = explode("\r\n", $headers); $errored = false; - foreach($headers as $h){ - if (substr($h,0,26)==="X-MailChimp-API-Error-Code"){ + foreach ($headers as $h) { + if (substr($h, 0, 26)==="X-MailChimp-API-Error-Code") { $errored = true; - $error_code = trim(substr($h,27)); + $error_code = trim(substr($h, 27)); break; } } - if(ini_get("magic_quotes_runtime")) $response = stripslashes($response); + if (ini_get("magic_quotes_runtime")) { + $response = stripslashes($response); + } $serial = unserialize($response); - if($response && $serial === false) { - $response = array("error" => "Bad Response. Got This: " . $response, "code" => "-99"); + if ($response && $serial === false) { + $response = array("error" => "Bad Response. Got This: " . $response, "code" => "-99"); } else { - $response = $serial; + $response = $serial; } - if($errored && is_array($response) && isset($response["error"])) { + if ($errored && is_array($response) && isset($response["error"])) { $this->errorMessage = $response["error"]; $this->errorCode = $response["code"]; return false; - } elseif($errored){ + } elseif ($errored) { $this->errorMessage = "No error message was found"; $this->errorCode = $error_code; return false; @@ -2917,7 +3033,4 @@ function callServer($method, $params) { return $response; } - } - -?> \ No newline at end of file diff --git a/code/SilverChimpSiteConfig.php b/code/SilverChimpSiteConfig.php index 692a95b..ce8c214 100644 --- a/code/SilverChimpSiteConfig.php +++ b/code/SilverChimpSiteConfig.php @@ -16,7 +16,8 @@ * @subpackage * @category */ -class SilverChimpSiteConfig extends DataExtension { +class SilverChimpSiteConfig extends DataExtension +{ private static $db = array( 'ChimpApiKey' => 'Text', @@ -39,7 +40,8 @@ class SilverChimpSiteConfig extends DataExtension { - public function updateCMSFields(FieldList $fields) { + public function updateCMSFields(FieldList $fields) + { $fields->addFieldToTab("Root.SilverChimp", new TextField( 'ChimpApiKey', _t('SilverChimp.APIKEY', 'API Key') @@ -47,10 +49,10 @@ public function updateCMSFields(FieldList $fields) { $fields->addFieldToTab("Root.SilverChimp", new DropdownField( 'ChimpEmailType', - _t('SilverChimp.SENDEMAILAS','Send Emails As'), + _t('SilverChimp.SENDEMAILAS', 'Send Emails As'), array( - 'html' => _t('SilverChimp.SENDTYPEHTML','HTML'), - 'text' => _t('SilverChimp.SENDTYPETEXT','Text'), + 'html' => _t('SilverChimp.SENDTYPEHTML', 'HTML'), + 'text' => _t('SilverChimp.SENDTYPETEXT', 'Text'), ) )); @@ -78,8 +80,5 @@ public function updateCMSFields(FieldList $fields) { 'ChimpReplaceGroups', _t('SilverChimp.REPLACEGROUPSSETTING', 'Replace Groups') )); - - - } -} \ No newline at end of file +} diff --git a/code/SilverChimpSubscriptionPage.php b/code/SilverChimpSubscriptionPage.php index 42ce3b0..db29bfb 100644 --- a/code/SilverChimpSubscriptionPage.php +++ b/code/SilverChimpSubscriptionPage.php @@ -1,430 +1,430 @@ - - * @package SilverChimp - */ -class SilverChimpSubscriptionPage extends Page { - - /** - * Definition of additional data fields required for SilverChimp - * @var array - */ - private static $db = array( - 'ListID' => 'Varchar(50)', // list_unique_id - 'SubscribeSuccess' => 'HTMLText', - 'DisableGroupSelection' => 'Boolean', // prevent frontend selection of groups - 'AllowUpdateExisting' => 'Boolean', // Allow a subscriber to update an existing subscription overrides setting fom SiteConfig - 'DefaultGroupSelections' => 'Text', // serialised array containing default group selections - 'SubscribeButtonText' => 'Text', - ); - - private static $defaults = array( - "DisableGroupSelection" => 0, - "AllowUpdateExisting" => 0, - "DefaultGroupSelections" => 'a:0:{}', // use serialize to prevent dependency for json support - "SubscribeButtonText" => 'Subscribe', - ); - - /** - * Add SilverShimp Specific fields to administration area - * @see Page::getCMSFields() - */ - public function getCMSFields() - { - $fields = parent::getCMSFields(); - - // get api key - $siteConfig = $this->getSiteConfig(); - $api_key = $siteConfig->ChimpApiKey; - if (!$api_key && strlen($api_key) == 0) { - $fields->addFieldsToTab('Root.ChimpSettings',array( - new LiteralField("ChimpFieldsInto", _t('SilverChimp.APIKEYNOTSET', 'You must configure your MailChimp API Key in site settings')), - )); - return $fields; - } - - $api = new MCAPI($api_key, $siteConfig->ChimpSecureConnection); - $lists = $api->lists(); - - $listSource = array(); - foreach ($lists['data'] AS $l) { - $listSource[$l['id']] = $l['name']; - } - - $settingsTab = 'Root.ChimpSettings'; - $fields->findOrMakeTab($settingsTab); - - $message = "
"; - $message .= _t('SilverChimp.SETTINGSNOTE', "You must save your changes to display/update the Chimp Fields tab"); - $message .= "
"; - - $fields->addFieldsToTab($settingsTab,array( - new DropdownField('ListID', _t('SilverChimp.LISTLABEL', 'Select the list you wish to use'),$listSource), - new OptionsetField("DisableGroupSelection", _t('SilverChimp.DISABLEGROUPS', "Disable groups from appearing on the frontend"), array(0 => 'Enable', 1 => 'Disable')), - new OptionsetField("AllowUpdateExisting", _t('SilverChimp.UPDATEEXISTING', "Allow a subscriber to update an existing subscription"), array(0 => 'No', 1 => 'Yes'), $siteConfig->ChimpUpdateExisting), - new TextField('SubscribeButtonText', _t('SilverChimp.BUTTONTEXT', "What text do you want to appear on the Subscribe button")), - new LiteralField("ChimpFieldsInto", $message), - new HtmlEditorField('SubscribeSuccess', _t('SilverChimp.SUBSCRIBESUCCESS', 'Enter something to display when a subscription has been sucessful')) - - )); - - if ($this->ListID && strlen($this->ListID)) { - // set up fields - $mergeVars = $api->listMergeVars($this->ListID); - $fieldsTab = 'Root.ChimpFields'; - $fields->findOrMakeTab($fieldsTab); - - $message = ""; - $message .= _t('SilverChimp.FIELDSINTRO', "These fields have been generated by Mail Chimp and will be used in your subscription form"); - $message .= "
"; - $fields->addFieldsToTab($fieldsTab, new LiteralField("ChimpFieldsIntro", $message)); - - foreach ($mergeVars as $var) { - $fields->addFieldToTab($fieldsTab, new ReadonlyField('SC-' . $var['tag'], $var['tag'], $var['name'] , ' (' . $var['field_type'] . ')')); - } - - - - // set up groups - $groupData = $api->listInterestGroupings($this->ListID); - $groupsTab = 'Root.ChimpGroups'; - $fields->findOrMakeTab($groupsTab); - - $message = ""; - $message .= _t('SilverChimp.GROUPSINTRO', "These groups have been set up for the selected list and will be displayed in your subscription form unless disabled. From here you may select the default values to use for this page"); - - $message .= "
"; - $fields->addFieldsToTab($groupsTab, new LiteralField("ChimpGroupssIntro", $message)); - - $groupDefaults = unserialize($this->DefaultGroupSelections); - - if (is_array($groupData) || $groupData instanceof Traversable) { - foreach ($groupData AS $gr) { - $source = array(); - foreach ($gr['groups'] as $opt) { - $source[$opt['bit']] = $opt['name']; - } - $name = 'SCG-' . preg_replace('/[^0-9A-Za-z]/', '-', $gr['name']); - $values = (isset($groupDefaults[$name])) ? $groupDefaults[$name] : null; - - $displayName = $gr['name']; - if ($gr['form_field'] == 'hidden') { - $displayName .= _t('SilverChimp.HIDDENGROUP', ' (Hidden by MailChimp)'); - } - - $fields->addFieldToTab($groupsTab, new CheckboxSetField($name, $displayName, $source, $values)); - } - } - } - - $this->extend('updateSilverChimpCMSFields'); - - return $fields; - } - - /** - * grab selected defaults from $_REQUEST and populate defaults - * @see SiteTree::onBeforeWrite() - */ - protected function onBeforeWrite() - { - $api_key = $this->getSiteConfig()->ChimpApiKey; - if ($api_key && strlen($api_key) && $this->ListID) { - $api = new MCAPI($api_key, $this->getSiteConfig()->ChimpSecureConnection); - - $defaults = array(); - // get list of grroups - $groupData = $api->listInterestGroupings($this->ListID); - // loop - if ($groupData && !empty($groupData)) { - foreach ($groupData AS $gr) { - // evaluate the field name used - $name = 'SCG-' . preg_replace('/[^0-9A-Za-z]/', '-', $gr['name']); - // get field value && set into defaults array - if (isset($_REQUEST[$name])) { - $defaults[$name] = $_REQUEST[$name]; - } - } - $this->DefaultGroupSelections = serialize($defaults); - } - } - parent::onBeforeWrite(); - } -} - -/** - * SilverChimp page controller - * @author Matt Cockayne"; + $message .= _t('SilverChimp.SETTINGSNOTE', "You must save your changes to display/update the Chimp Fields tab"); + $message .= "
"; + + $fields->addFieldsToTab($settingsTab, array( + new DropdownField('ListID', _t('SilverChimp.LISTLABEL', 'Select the list you wish to use'), $listSource), + new OptionsetField("DisableGroupSelection", _t('SilverChimp.DISABLEGROUPS', "Disable groups from appearing on the frontend"), array(0 => 'Enable', 1 => 'Disable')), + new OptionsetField("AllowUpdateExisting", _t('SilverChimp.UPDATEEXISTING', "Allow a subscriber to update an existing subscription"), array(0 => 'No', 1 => 'Yes'), $siteConfig->ChimpUpdateExisting), + new TextField('SubscribeButtonText', _t('SilverChimp.BUTTONTEXT', "What text do you want to appear on the Subscribe button")), + new LiteralField("ChimpFieldsInto", $message), + new HtmlEditorField('SubscribeSuccess', _t('SilverChimp.SUBSCRIBESUCCESS', 'Enter something to display when a subscription has been sucessful')) + + )); + + if ($this->ListID && strlen($this->ListID)) { + // set up fields + $mergeVars = $api->listMergeVars($this->ListID); + $fieldsTab = 'Root.ChimpFields'; + $fields->findOrMakeTab($fieldsTab); + + $message = ""; + $message .= _t('SilverChimp.FIELDSINTRO', "These fields have been generated by Mail Chimp and will be used in your subscription form"); + $message .= "
"; + $fields->addFieldsToTab($fieldsTab, new LiteralField("ChimpFieldsIntro", $message)); + + foreach ($mergeVars as $var) { + $fields->addFieldToTab($fieldsTab, new ReadonlyField('SC-' . $var['tag'], $var['tag'], $var['name'], ' (' . $var['field_type'] . ')')); + } + + + + // set up groups + $groupData = $api->listInterestGroupings($this->ListID); + $groupsTab = 'Root.ChimpGroups'; + $fields->findOrMakeTab($groupsTab); + + $message = ""; + $message .= _t('SilverChimp.GROUPSINTRO', "These groups have been set up for the selected list and will be displayed in your subscription form unless disabled. From here you may select the default values to use for this page"); + + $message .= "
"; + $fields->addFieldsToTab($groupsTab, new LiteralField("ChimpGroupssIntro", $message)); + + $groupDefaults = unserialize($this->DefaultGroupSelections); + + if (is_array($groupData) || $groupData instanceof Traversable) { + foreach ($groupData as $gr) { + $source = array(); + foreach ($gr['groups'] as $opt) { + $source[$opt['bit']] = $opt['name']; + } + $name = 'SCG-' . preg_replace('/[^0-9A-Za-z]/', '-', $gr['name']); + $values = (isset($groupDefaults[$name])) ? $groupDefaults[$name] : null; + + $displayName = $gr['name']; + if ($gr['form_field'] == 'hidden') { + $displayName .= _t('SilverChimp.HIDDENGROUP', ' (Hidden by MailChimp)'); + } + + $fields->addFieldToTab($groupsTab, new CheckboxSetField($name, $displayName, $source, $values)); + } + } + } + + $this->extend('updateSilverChimpCMSFields'); + + return $fields; + } + + /** + * grab selected defaults from $_REQUEST and populate defaults + * @see SiteTree::onBeforeWrite() + */ + protected function onBeforeWrite() + { + $api_key = $this->getSiteConfig()->ChimpApiKey; + if ($api_key && strlen($api_key) && $this->ListID) { + $api = new MCAPI($api_key, $this->getSiteConfig()->ChimpSecureConnection); + + $defaults = array(); + // get list of grroups + $groupData = $api->listInterestGroupings($this->ListID); + // loop + if ($groupData && !empty($groupData)) { + foreach ($groupData as $gr) { + // evaluate the field name used + $name = 'SCG-' . preg_replace('/[^0-9A-Za-z]/', '-', $gr['name']); + // get field value && set into defaults array + if (isset($_REQUEST[$name])) { + $defaults[$name] = $_REQUEST[$name]; + } + } + $this->DefaultGroupSelections = serialize($defaults); + } + } + parent::onBeforeWrite(); + } +} + +/** + * SilverChimp page controller + * @author Matt Cockayne