MailChimp Forms by MailMunch - Version 2.0.0

Version Description

Download this release

Release Info

Developer mailmunch
Plugin Icon 128x128 MailChimp Forms by MailMunch
Version 2.0.0
Comparing to
See all releases

Code changes from version 1.0.9 to 2.0.0

admin/class-mailchimp-mailmunch-admin.php ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * The admin-specific functionality of the plugin.
5
+ *
6
+ * @link http://www.mailmunch.co
7
+ * @since 2.0.0
8
+ *
9
+ * @package Mailchimp_Mailmunch
10
+ * @subpackage Mailchimp_Mailmunch/admin
11
+ */
12
+
13
+ /**
14
+ * The admin-specific functionality of the plugin.
15
+ *
16
+ * Defines the plugin name, version, and two examples hooks for how to
17
+ * enqueue the admin-specific stylesheet and JavaScript.
18
+ *
19
+ * @package Mailchimp_Mailmunch
20
+ * @subpackage Mailchimp_Mailmunch/admin
21
+ * @author MailMunch <info@mailmunch.co>
22
+ */
23
+ class Mailchimp_Mailmunch_Admin {
24
+
25
+ /**
26
+ * The ID of this plugin.
27
+ *
28
+ * @since 2.0.0
29
+ * @access private
30
+ * @var string $plugin_name The ID of this plugin.
31
+ */
32
+ private $plugin_name;
33
+
34
+ /**
35
+ * The ID of this plugin's 3rd party integration.
36
+ *
37
+ * @since 2.0.0
38
+ * @access private
39
+ * @var string $integration_name The ID of this plugin's 3rd party integration.
40
+ */
41
+ private $integration_name;
42
+
43
+ /**
44
+ * The version of this plugin.
45
+ *
46
+ * @since 2.0.0
47
+ * @access private
48
+ * @var string $version The current version of this plugin.
49
+ */
50
+ private $version;
51
+
52
+ /**
53
+ * The MailMunch Api object.
54
+ *
55
+ * @since 2.0.0
56
+ * @access private
57
+ * @var string $mailmunch_api The MailMunch Api object.
58
+ */
59
+ private $mailmunch_api;
60
+
61
+
62
+ public function __construct( $plugin_name, $integration_name, $version ) {
63
+
64
+ $this->plugin_name = $plugin_name;
65
+ $this->integration_name = $integration_name;
66
+ $this->version = $version;
67
+ $this->mailmunch_api = new Mailmunch_Api();
68
+ }
69
+
70
+ /**
71
+ * Register the stylesheets for the admin area.
72
+ *
73
+ * @since 2.0.0
74
+ */
75
+ public function enqueue_styles() {
76
+
77
+ /**
78
+ * This function is provided for demonstration purposes only.
79
+ *
80
+ * An instance of this class should be passed to the run() function
81
+ * defined in Mailchimp_Mailmunch_Loader as all of the hooks are defined
82
+ * in that particular class.
83
+ *
84
+ * The Mailchimp_Mailmunch_Loader will then create the relationship
85
+ * between the defined hooks and the functions defined in this
86
+ * class.
87
+ */
88
+
89
+ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/mailchimp-mailmunch-admin.css', array(), $this->version, 'all' );
90
+
91
+ }
92
+
93
+ /**
94
+ * Register the JavaScript for the admin area.
95
+ *
96
+ * @since 2.0.0
97
+ */
98
+ public function enqueue_scripts() {
99
+
100
+ /**
101
+ * This function is provided for demonstration purposes only.
102
+ *
103
+ * An instance of this class should be passed to the run() function
104
+ * defined in Mailchimp_Mailmunch_Loader as all of the hooks are defined
105
+ * in that particular class.
106
+ *
107
+ * The Mailchimp_Mailmunch_Loader will then create the relationship
108
+ * between the defined hooks and the functions defined in this
109
+ * class.
110
+ */
111
+
112
+ wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/mailchimp-mailmunch-admin.js', array( 'jquery' ), $this->version, false );
113
+
114
+ }
115
+
116
+ public function sign_up() {
117
+ $email = $_POST['email'];
118
+ $password = $_POST['password'];
119
+ echo json_encode($this->mailmunch_api->signUpUser($email, $password, $_POST['site_name'], $_POST['site_url']));
120
+ exit;
121
+ }
122
+
123
+ public function sign_in() {
124
+ $email = $_POST['email'];
125
+ $password = $_POST['password'];
126
+ echo json_encode($this->mailmunch_api->signInUser($email, $password));
127
+ exit;
128
+ }
129
+
130
+ public function delete_widget() {
131
+ echo json_encode($this->mailmunch_api->deleteWidget($_POST['widget_id']));
132
+ exit;
133
+ }
134
+
135
+ /**
136
+ * Register menu for the admin area
137
+ *
138
+ * @since 2.0.0
139
+ */
140
+ public function menu() {
141
+ add_options_page( $this->integration_name, $this->integration_name, 'manage_options', MAILCHIMP_MAILMUNCH_SLUG, array($this, 'get_dashboard_html'));
142
+ add_menu_page( $this->integration_name, $this->integration_name, 'manage_options', MAILCHIMP_MAILMUNCH_SLUG, array($this, 'get_dashboard_html'), plugins_url( 'img/icon.png', __FILE__ ), 103.786);
143
+ }
144
+
145
+ /**
146
+ * Adds settings link for plugin
147
+ *
148
+ * @since 2.0.0
149
+ */
150
+ public function settings_link($links) {
151
+ $settings_link = '<a href="options-general.php?page='.MAILCHIMP_MAILMUNCH_SLUG.'">Settings</a>';
152
+ array_unshift($links, $settings_link);
153
+ return $links;
154
+ }
155
+
156
+ /**
157
+ * Register sidebar widget
158
+ *
159
+ * @since 2.0.0
160
+ */
161
+ public function sidebar_widget() {
162
+ register_widget( 'Mailchimp_Mailmunch_Sidebar_Widget' );
163
+ }
164
+
165
+ /**
166
+ * Get current step
167
+ *
168
+ * @since 2.0.0
169
+ */
170
+ public function getStep() {
171
+ if (isset($_GET['step'])) { $step = $_GET['step']; }
172
+ elseif ($this->mailmunch_api->skipOnBoarding()) { $step = ''; }
173
+ else {
174
+ $step = 'connect';
175
+ $mcAccessToken = get_option($this->mailmunch_api->getPrefix(). 'mailchimp_access_token');
176
+ $mcListId = get_option($this->mailmunch_api->getPrefix(). 'mailchimp_list_id');
177
+ if (!empty($mcAccessToken)) $step = 'integrate';
178
+ if (!empty($mcListId)) $step = '';
179
+ }
180
+ return $step;
181
+ }
182
+
183
+ /**
184
+ * Get Dashboard HTML
185
+ *
186
+ * @since 2.0.0
187
+ */
188
+ public function get_dashboard_html() {
189
+
190
+ switch ($this->getStep()) {
191
+ case 'sign_out':
192
+ $this->mailmunch_api->signOutUser();
193
+ require_once(plugin_dir_path(__FILE__) . 'partials/mailchimp-mailmunch-connect.php');
194
+ break;
195
+
196
+ case 'connect':
197
+ require_once(plugin_dir_path(__FILE__) . 'partials/mailchimp-mailmunch-connect.php');
198
+ break;
199
+
200
+ case 'integrate':
201
+ if ($_POST['access_token']) {
202
+ update_option($this->mailmunch_api->getPrefix(). 'mailchimp_access_token', $_POST['access_token']);
203
+ }
204
+
205
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/drewm_mailchimp.php';
206
+ $mailchimpApi = new \Drewm\MailChimp(get_option($this->mailmunch_api->getPrefix(). 'mailchimp_access_token'));
207
+ $lists = $mailchimpApi->call('lists/list');
208
+ require_once(plugin_dir_path( __FILE__ ) . 'partials/mailchimp-mailmunch-integrate.php');
209
+ break;
210
+
211
+ default:
212
+ if ($_POST['list_id']) {
213
+ update_option($this->mailmunch_api->getPrefix(). 'mailchimp_list_id', $_POST['list_id']);
214
+
215
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/drewm_mailchimp.php';
216
+ $mailchimpApi = new \Drewm\MailChimp(get_option($this->mailmunch_api->getPrefix(). 'mailchimp_access_token'));
217
+ $lists = $mailchimpApi->call('lists/list');
218
+ $listName = '';
219
+ if ($lists['total'] > 0) {
220
+ foreach ($lists['data'] as $list) {
221
+ if ($list['id'] == $_POST['list_id'] ) { $listName = $list['name']; }
222
+ }
223
+ }
224
+ $accessToken = get_option($this->mailmunch_api->getPrefix(). 'mailchimp_access_token');
225
+
226
+ $this->mailmunch_api->createListAndIntegration($accessToken, $listName, $_POST['list_id']);
227
+ }
228
+ require_once(plugin_dir_path( __FILE__ ) . 'partials/mailchimp-mailmunch-admin-display.php');
229
+ }
230
+
231
+ require_once(plugin_dir_path( __FILE__ ) . 'partials/mailchimp-mailmunch-modals.php');
232
+ }
233
+
234
+ }
css/admin.css → admin/css/mailchimp-mailmunch-admin.css RENAMED
@@ -1,3 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #signup-signin-box-overlay {
2
  background-color: #000;
3
  opacity: 0.8;
@@ -41,6 +144,10 @@
41
  display: none;
42
  }
43
 
 
 
 
 
44
  #sign-in-form.active, #sign-up-form.active {
45
  display: block;
46
  }
@@ -67,67 +174,7 @@
67
  cursor: pointer;
68
  }
69
 
70
- #mailmunch_frame {
71
- width: 720px;
72
- height: 650px;
73
- margin: 15px 15px 0 5px;
74
- }
75
-
76
- #mailmuch-designer-ui {
77
- background: rgba(255, 255, 255, 0.9);
78
- z-index: 500000;
79
- position: fixed;
80
- overflow: visible;
81
- top: 0;
82
- bottom: 0;
83
- left: 0;
84
- right: 0;
85
- height: 100%;
86
- width: 100%;
87
- min-width: 0;
88
- cursor: default;
89
- display: none;
90
- }
91
-
92
- #mailmuch-designer-ui #mailmunch_designer_frame {
93
- width: 100%;
94
- height: 100%;
95
- }
96
-
97
- .container {
98
- max-width: 700px;
99
- padding: 0px 10px;
100
- }
101
-
102
- .page-header {
103
- margin: 20px 0;
104
- border-bottom: 1px solid #CCC;
105
- padding-bottom: 5px;
106
- }
107
-
108
- .action-btns {
109
- width: 220px;
110
- }
111
-
112
- #unlink-account {
113
- margin-top: 20px;
114
- }
115
-
116
- .unlink-btn {
117
- background:none!important;
118
- border:none;
119
- padding:0!important;
120
- border-bottom:1px solid #0074a2;
121
- cursor: pointer;
122
- color: #0074a2;
123
- font-size: 12px;
124
- }
125
 
126
- .new-optin-btn {
127
- margin-left: 20px;
128
- margin-top: 16px;
129
- display: inline-block;
130
- }
131
 
132
 
133
  /* Style Guide */
1
+ #loader {
2
+ display: none;
3
+ }
4
+
5
+ .warning {
6
+ font-weight: bold;
7
+ padding: 0px 10px 10px;
8
+ }
9
+
10
+ .integration-steps thead th {
11
+ text-align: center;
12
+ border-right: 1px solid #EEE;
13
+ vertical-align: middle;
14
+ }
15
+
16
+ .integration-steps thead th img {
17
+ height: 16px;
18
+ vertical-align: middle;
19
+ }
20
+
21
+ .integration-steps thead th a {
22
+ color: #000;
23
+ text-decoration: none;
24
+ vertical-align: middle;
25
+ }
26
+
27
+ .integration-steps thead th.active {
28
+ background-color: #428bca;
29
+ color: #FFF;
30
+ }
31
+
32
+ .integration-steps thead th.active a {
33
+ color: #FFF;
34
+ }
35
+
36
+ .integration-steps thead th:last-child {
37
+ border-right: 0px;
38
+ }
39
+
40
+ .integration-steps thead .btn {
41
+ padding: 5px;
42
+ }
43
+
44
+ .integration-steps tbody td {
45
+ text-align: center;
46
+ }
47
+
48
+ .mailchimp-status {
49
+ margin-bottom: 15px;
50
+ }
51
+
52
+ .mailchimp-status div {
53
+ font-weight: bold;
54
+ color: green;
55
+ margin-top: -10px;
56
+ }
57
+
58
+ .inside-container {
59
+ padding: 20px;
60
+ }
61
+
62
+ #connect-mailchimp {
63
+ text-align: center;
64
+ display: inline-block;
65
+ margin: 10px auto;
66
+ outline: none;
67
+ }
68
+
69
+ #connect-mailchimp img {
70
+ width: 100px;
71
+ display: block;
72
+ margin: 10px auto;
73
+ }
74
+
75
+ .video-trigger img {
76
+ width: 100%;
77
+ max-width: 100%;
78
+ cursor: pointer;
79
+ }
80
+
81
+ #mailmunch-demo-video {
82
+ position: fixed;
83
+ width: 100%;
84
+ height: 100%;
85
+ background-color: rgba(0,0,0,0.8);
86
+ z-index: 10000;
87
+ left: 0;
88
+ top: 0;
89
+ text-align: center;
90
+ padding-top: 100px;
91
+ display: none;
92
+ }
93
+
94
+ #mailmunch-demo-video a {
95
+ display: block;
96
+ text-align: center;
97
+ color: #FFF;
98
+ margin-top: 10px;
99
+ font-weight: bold;
100
+ font-size: 20px;
101
+ cursor: pointer;
102
+ }
103
+
104
  #signup-signin-box-overlay {
105
  background-color: #000;
106
  opacity: 0.8;
144
  display: none;
145
  }
146
 
147
+ #sign-in-form .signin-alert, #sign-up-form .signup-alert {
148
+ display: none;
149
+ }
150
+
151
  #sign-in-form.active, #sign-up-form.active {
152
  display: block;
153
  }
174
  cursor: pointer;
175
  }
176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
 
 
 
 
 
 
178
 
179
 
180
  /* Style Guide */
admin/img/check.png ADDED
Binary file
{img → admin/img}/close.png RENAMED
File without changes
{img → admin/img}/icon.png RENAMED
File without changes
admin/img/loader.gif ADDED
Binary file
admin/img/mailchimp_logo.png ADDED
Binary file
admin/img/smallcheck.png ADDED
Binary file
admin/img/video.jpg ADDED
Binary file
admin/img/warning.png ADDED
Binary file
admin/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
admin/js/mailchimp-mailmunch-admin.js ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function( $ ) {
2
+ 'use strict';
3
+
4
+ /**
5
+ * All of the code for your admin-specific JavaScript source
6
+ * should reside in this file.
7
+ *
8
+ * Note that this assume you're going to use jQuery, so it prepares
9
+ * the $ function reference to be used within the scope of this
10
+ * function.
11
+ *
12
+ * From here, you're able to define handlers for when the DOM is
13
+ * ready:
14
+ *
15
+ * $(function() {
16
+ *
17
+ * });
18
+ *
19
+ * Or when the window is loaded:
20
+ *
21
+ * $( window ).load(function() {
22
+ *
23
+ * });
24
+ *
25
+ * ...and so on.
26
+ *
27
+ * Remember that ideally, we should not attach any more than a single DOM-ready or window-load handler
28
+ * for any particular page. Though other scripts in WordPress core, other plugins, and other themes may
29
+ * be doing this, we should try to minimize doing that in our own work.
30
+ */
31
+
32
+ $(function() {
33
+ $("#connect-mailchimp").click(function() {
34
+ var width = 500;
35
+ var height = 650;
36
+ window.open($(this).attr("href"), "MailMunchIntegration", "top="+ (($(window).height()/2)-(height/2)) +", left="+ (($(window).width()/2)-(width/2)) +", width="+width+", height="+height);
37
+ return false;
38
+ });
39
+
40
+ window.addEventListener("message", function(event) {
41
+ if (typeof(event.data) != 'undefined' && event.data.access_token) {
42
+ $("#connect-mailchimp").hide();
43
+ $("#loader").show();
44
+ var form = $('#mailchimp-access-token-form');
45
+ form.find('input[name=access_token]').val(event.data.access_token);
46
+ form.submit();
47
+ }
48
+ }, false);
49
+
50
+ $('.delete-widget').click(function() {
51
+ if (!confirm('Are you sure you want to delete this optin form?')) return false;
52
+ $.ajax({
53
+ url: ajaxurl,
54
+ type: 'POST',
55
+ data: {action: 'delete_widget', widget_id: $(this).data('widget-id')},
56
+ dataType: 'json',
57
+ success: function(data) {
58
+ if (data.success) {
59
+ $(this).parents('tr').slideUp();
60
+ }
61
+ else {
62
+ alert('There was an error. Please try again later.');
63
+ }
64
+ }.bind(this),
65
+ error: function(data) {
66
+ alert('There was an error. Please try again later.');
67
+ }
68
+ })
69
+ return false;
70
+ })
71
+
72
+ $('#signup_form').submit(function(e) {
73
+ e.preventDefault();
74
+
75
+ var data = {
76
+ email: $(this).find('input[name=email]').val(),
77
+ password: $(this).find('input[name=password]').val(),
78
+ site_name: $(this).find('input[name=site_name]').val(),
79
+ site_url: $(this).find('input[name=site_url]').val(),
80
+ action: 'sign_up',
81
+ };
82
+
83
+ $.ajax({
84
+ url: ajaxurl,
85
+ type: 'POST',
86
+ data: data,
87
+ dataType: 'json',
88
+ beforeSend: function() {
89
+ $('.signup-alert').hide();
90
+ },
91
+ success: function(data) {
92
+ if (!data.success) {
93
+ $('.signup-alert').html(data.message).show();
94
+ } else {
95
+ window.location.reload();
96
+ }
97
+ },
98
+ error: function(data) {
99
+ alert('There was an error. Please try again later.');
100
+ }
101
+ })
102
+ return false;
103
+ })
104
+
105
+ $('#signin_form').submit(function(e) {
106
+ e.preventDefault();
107
+
108
+ var data = {
109
+ email: $(this).find('input[name=email]').val(),
110
+ password: $(this).find('input[name=password]').val(),
111
+ action: 'sign_in',
112
+ };
113
+
114
+ $.ajax({
115
+ url: ajaxurl,
116
+ type: 'POST',
117
+ data: data,
118
+ dataType: 'json',
119
+ beforeSend: function() {
120
+ $('.signin-alert').hide();
121
+ },
122
+ success: function(data) {
123
+ if (!data.success) {
124
+ $('.signin-alert').html(data.message).show();
125
+ } else {
126
+ window.location.reload();
127
+ }
128
+ },
129
+ error: function(data) {
130
+ alert('There was an error. Please try again later.');
131
+ }
132
+ })
133
+ return false;
134
+ })
135
+
136
+ });
137
+
138
+ })( jQuery );
139
+
140
+ function showVideo() {
141
+ document.getElementById('mailmunch-demo-video').innerHTML = '<iframe src="//player.vimeo.com/video/117103275?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="720" height="405" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
142
+ document.getElementById('mailmunch-demo-video').style.display = 'block';
143
+ }
144
+
145
+ function hideVideo() {
146
+ document.getElementById('mailmunch-demo-video').innerHTML = "";
147
+ document.getElementById('mailmunch-demo-video').style.display = 'none';
148
+ }
149
+
150
+ window.onmessage = function (e) {
151
+ if (e.data === 'refresh') {
152
+ top.location.reload();
153
+ }
154
+ };
155
+
156
+ function repositionSignupBox() {
157
+ divId = 'signup-signin-box';
158
+ var divWidth, divHeight;
159
+ var objDiv = document.getElementById(divId);
160
+
161
+ if (objDiv.clientWidth) {
162
+ divWidth = objDiv.clientWidth;
163
+ divHeight = objDiv.clientHeight;
164
+ }
165
+ else if (objDiv.offsetWidth)
166
+ {
167
+ divWidth = objDiv.offsetWidth;
168
+ divHeight = objDiv.offsetHeight;
169
+ }
170
+
171
+ // Get the x and y coordinates of the center in output browser's window
172
+ var centerX, centerY;
173
+ if (window.innerHeight)
174
+ {
175
+ centerX = window.innerWidth;
176
+ centerY = window.innerHeight;
177
+ }
178
+ else if (document.documentElement && document.documentElement.clientHeight)
179
+ {
180
+ centerX = document.documentElement.clientWidth;
181
+ centerY = document.documentElement.clientHeight;
182
+ }
183
+ else if (document.body)
184
+ {
185
+ centerX = document.body.clientWidth;
186
+ centerY = document.body.clientHeight;
187
+ }
188
+
189
+ var offsetLeft = (centerX - divWidth) / 2;
190
+ var offsetTop = (centerY - divHeight) / 2;
191
+
192
+ objDiv.style.top = offsetTop + 'px';
193
+ objDiv.style.left = offsetLeft + 'px';
194
+ }
195
+
196
+ function showSignInForm() {
197
+ document.getElementById("sign-up-form").style.display = 'none';
198
+ document.getElementById("sign-in-form").style.display = 'block';
199
+ document.getElementById('why-account').style.display = 'none';
200
+ showSignupBox();
201
+ }
202
+
203
+ function showSignUpForm() {
204
+ document.getElementById("sign-in-form").style.display = 'none';
205
+ document.getElementById("sign-up-form").style.display = 'block';
206
+ document.getElementById('why-account').style.display = 'none';
207
+ showSignupBox();
208
+ }
209
+
210
+ function showSignupBox(width, height) {
211
+ document.getElementById("signup-signin-box-overlay").style.display = 'block';
212
+ document.getElementById("signup-signin-box").style.display = 'block';
213
+ repositionSignupBox();
214
+
215
+ return false;
216
+ }
217
+
218
+ function hideSignupBox() {
219
+ document.getElementById("signup-signin-box-overlay").style.display = 'none';
220
+ document.getElementById("signup-signin-box").style.display = 'none';
221
+ }
222
+
223
+ function showWhyAccount() {
224
+ document.getElementById('why-account').style.display = 'block';
225
+ repositionSignupBox();
226
+ }
admin/partials/mailchimp-mailmunch-admin-display.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Provide a admin area view for the plugin
5
+ *
6
+ * This file is used to markup the admin-facing aspects of the plugin.
7
+ *
8
+ * @link http://www.mailmunch.co
9
+ * @since 2.0.0
10
+ *
11
+ * @package Mailchimp_Mailmunch
12
+ * @subpackage Mailchimp_Mailmunch/admin/partials
13
+ */
14
+ ?>
15
+
16
+ <form id="unlink-account" action="<?php echo add_query_arg( array('step' => 'sign_out') ); ?>" method="POST"></form>
17
+
18
+ <?php echo $this->mailmunch_api->getWidgetsHtml(); ?>
admin/partials/mailchimp-mailmunch-connect.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <form action="<?php echo add_query_arg( array('step' => 'integrate') ); ?>" method="POST" id="mailchimp-access-token-form">
2
+ <input type="hidden" name="access_token" value="" />
3
+ </form>
4
+
5
+ <div id="mailmunch-demo-video" onclick="hideVideo()">
6
+ </div>
7
+
8
+ <div id="poststuff" class="wrap">
9
+ <div id="post-body" class="metabox-holder columns-2">
10
+ <div id="post-body-content">
11
+ <h2>
12
+ MailChimp Forms
13
+ </h2>
14
+
15
+ <table class="wp-list-table widefat fixed posts integration-steps">
16
+ <thead>
17
+ <tr>
18
+ <th class="active">
19
+ <a href="<?php echo add_query_arg( array('step' => 'connect') ); ?>">Connect to MailChimp</a>
20
+ </th>
21
+ <th>Choose MailChimp List</th>
22
+ <th>Create Opt-In Form</th>
23
+ </tr>
24
+ </thead>
25
+ <tbody>
26
+ <tr height="50">
27
+ <td colspan="3" class="inside-container">
28
+ <img id="loader" src="<?php echo plugins_url( 'img/loader.gif', dirname(__FILE__) ) ?>" />
29
+
30
+ <a id="connect-mailchimp" href="<?php echo MAILCHIMP_MAILMUNCH_HOME_URL ?>/wordpress/mailchimp/new?token=<?php echo $this->mailmunch_api->getUserToken(); ?>">
31
+ <img src="<?php echo plugins_url( 'img/mailchimp_logo.png', dirname(__FILE__) ) ?>" />
32
+ <span class="button button-primary">Connect to MailChimp</span>
33
+ </a>
34
+ </td>
35
+ </tr>
36
+ </tbody>
37
+ </table>
38
+ </div>
39
+
40
+ <div id="postbox-container-1" class="postbox-container">
41
+ <div id="side-sortables" class="meta-box-sortables ui-sortable">
42
+ <div class="postbox">
43
+ <h3><span>Need Support?</span></h3>
44
+
45
+ <div class="inside">
46
+ <p>Need Help? <a href="https://mailmunch.zendesk.com/hc" target="_blank">Contact Support</a></p>
47
+
48
+ <div class="video-trigger">
49
+ <p>Watch our quick tour video:</p>
50
+ <img src="<?php echo plugins_url( 'img/video.jpg', dirname(__FILE__) ) ?>" onclick="showVideo()" />
51
+ </div>
52
+ </div>
53
+ </div>
54
+ </div>
55
+
56
+ </div>
57
+ </div>
58
+ </div>
admin/partials/mailchimp-mailmunch-integrate.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="mailmunch-demo-video" onclick="hideVideo()">
2
+ </div>
3
+
4
+ <div id="poststuff" class="wrap">
5
+ <div id="post-body" class="metabox-holder columns-2">
6
+ <div id="post-body-content">
7
+ <h2>
8
+ MailChimp Forms
9
+ </h2>
10
+
11
+ <table class="wp-list-table widefat fixed posts integration-steps">
12
+ <thead>
13
+ <tr>
14
+ <th>
15
+ <a href="<?php echo add_query_arg( array('step' => 'connect') ); ?>">
16
+ <img src="<?php echo plugins_url( 'img/smallcheck.png', dirname(__FILE__) ) ?>" />
17
+ Connect to MailChimp
18
+ </a>
19
+ </th>
20
+ <th class="active">
21
+ <a href="<?php echo add_query_arg( array('step' => 'integrate') ); ?>">Choose MailChimp List</a>
22
+ </th>
23
+ <th>Create Opt-In Form</th>
24
+ </tr>
25
+ </thead>
26
+ <tbody>
27
+ <tr height="50">
28
+ <td colspan="3">
29
+ <div class="inside-container">
30
+ <?php if ($lists['total'] > 0) { ?>
31
+ <div class="mailchimp-status">
32
+ <img src="<?php echo plugins_url( 'img/check.png', dirname(__FILE__) ) ?>" />
33
+ <div>Connected to MailChimp</div>
34
+ </div>
35
+
36
+ <p>Choose a list to save your subscribers in:</p>
37
+ <form action="<?php echo add_query_arg( array('step' => 'final') ); ?>" method="POST">
38
+ <select name="list_id">
39
+ <?php foreach ($lists['data'] as $list) { ?>
40
+ <option value="<?php echo $list['id']; ?>"><?php echo $list['name']; ?></option>
41
+ <?php } ?>
42
+ </select>
43
+ <input type="submit" name="action" value="Choost List" class="button button-primary" />
44
+ </form>
45
+ <?php } else { ?>
46
+ <img src="<?php echo plugins_url( 'img/warning.png', dirname(__FILE__) ) ?>" />
47
+ <div class="warning">You do not have a list on MailChimp. Please create one and refresh this page.</div>
48
+ <?php } ?>
49
+ </div>
50
+ </td>
51
+ </tr>
52
+ </tbody>
53
+ </table>
54
+ </div>
55
+
56
+ <div id="postbox-container-1" class="postbox-container">
57
+ <div id="side-sortables" class="meta-box-sortables ui-sortable">
58
+ <div class="postbox">
59
+ <h3><span>Need Support?</span></h3>
60
+
61
+ <div class="inside">
62
+ <p>Need Help? <a href="https://mailmunch.zendesk.com/hc" target="_blank">Contact Support</a></p>
63
+
64
+ <div class="video-trigger">
65
+ <p>Watch our quick tour video:</p>
66
+ <img src="<?php echo plugins_url( 'img/video.jpg', dirname(__FILE__) ) ?>" onclick="showVideo()" />
67
+ </div>
68
+ </div>
69
+ </div>
70
+ </div>
71
+
72
+ </div>
73
+ </div>
74
+ </div>
admin/partials/mailchimp-mailmunch-modals.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="signup-signin-box-overlay" onclick="hideSignupBox();" style="display: none;"></div>
2
+
3
+ <div id="signup-signin-box" style="display:none;">
4
+ <a id="signup-signin-close" onclick="hideSignupBox();">
5
+ <img src="<?php echo plugins_url( 'img/close.png', dirname(__FILE__) ) ?>" />
6
+ </a>
7
+
8
+ <div id="sign-up-form">
9
+ <div class="form-container">
10
+ <h2 class="modal-header">Sign Up</h2>
11
+ <p>To activate your MailChimp forms, we will now create your account on MailMunch (<a onclick="showWhyAccount();" id="why-account-btn">Why?</a>).</p>
12
+
13
+ <div id="why-account" class="alert alert-warning" style="display: none;">
14
+ <h4>Why do I need a MailMunch account?</h4>
15
+
16
+ <p>
17
+ MailMunch is a not just a WordPress plugin but a standalone service. An account is required to identify your WordPress and serve your MailChimp forms.
18
+ </p>
19
+ </div>
20
+
21
+ <div class="alert alert-danger signup-alert" role="alert">Account with this email already exists. Please sign in using your password.</div>
22
+
23
+ <form action="" method="POST" id="signup_form">
24
+ <div class="form-group">
25
+ <label>Wordpress Name</label>
26
+ <input type="text" placeholder="Site Name" name="site_name" value="<?php echo get_bloginfo(); ?>" class="form-control">
27
+ </div>
28
+
29
+ <div class="form-group">
30
+ <label>Wordpress URL</label>
31
+ <input type="text" placeholder="Site URL" name="site_url" value="<?php echo home_url() ?>" class="form-control">
32
+ </div>
33
+
34
+ <div class="form-group">
35
+ <label>Email Address</label>
36
+ <input type="email" placeholder="Email Address" name="email" value="<?php echo wp_get_current_user()->user_email; ?>" class="form-control">
37
+ </div>
38
+
39
+ <div class="form-group">
40
+ <label>Password</label>
41
+ <input type="password" placeholder="Password" name="password" class="form-control" />
42
+ </div>
43
+
44
+ <div class="form-group">
45
+ <input type="submit" value="Sign Up &raquo;" class="btn btn-success btn-lg" />
46
+ </div>
47
+ </form>
48
+ </div>
49
+
50
+ <p>Already have an account? <a id="show-sign-in" onclick="showSignInForm();">Sign In</a></p>
51
+ </div>
52
+
53
+ <div id="sign-in-form" class="active">
54
+ <h2 class="modal-header">Sign In</h2>
55
+ <p>Sign in using your email and password below.</p>
56
+
57
+ <div class="alert alert-danger signin-alert" role="alert">Invalid Email or Password. Please try again.</div>
58
+
59
+ <div class="form-container">
60
+ <form action="" method="POST" id="signin_form">
61
+
62
+ <div class="form-group">
63
+ <label>Email Address</label>
64
+ <input type="email" placeholder="Email Address" name="email" class="form-control" value="" />
65
+ </div>
66
+ <div class="form-group">
67
+ <label>Password</label>
68
+ <input type="password" placeholder="Password" name="password" class="form-control" />
69
+ </div>
70
+
71
+ <div class="form-group">
72
+ <input type="submit" value="Sign In &raquo;" class="btn btn-success btn-lg" />
73
+ </div>
74
+ </form>
75
+ </div>
76
+
77
+ <p>Forgot your password? <a href="<?php echo MAILCHIMP_MAILMUNCH_URL; ?>/users/password/new" target="_blank">Click here</a> to retrieve it.</p>
78
+ <p>Don't have an account? <a id="show-sign-up" onclick="showSignUpForm();">Sign Up</a></p>
79
+ </div>
80
+ </div>
inc/common.php DELETED
@@ -1,73 +0,0 @@
1
- <?php
2
- class MailchimpMailmunchHelpers {
3
- function __construct() {
4
- }
5
-
6
- function getEmailPassword() {
7
- $mc_mm_email = get_option("mc_mm_user_email");
8
- $mc_mm_password = get_option("mc_mm_user_password");
9
-
10
- if (empty($mc_mm_email)) {
11
- $current_user = wp_get_current_user();
12
- update_option("mc_mm_user_email", $current_user->user_email);
13
- }
14
-
15
- if (empty($mc_mm_password)) {
16
- update_option("mc_mm_user_password", base64_encode(uniqid()));
17
- }
18
-
19
- $mc_mm_email = get_option("mc_mm_user_email");
20
- $mc_mm_password = get_option("mc_mm_user_password");
21
-
22
- return array('email' => $mc_mm_email, 'password' => $mc_mm_password);
23
- }
24
-
25
- function getSite($sites, $site_id) {
26
- foreach ($sites as $s) {
27
- if ($s->id == intval($site_id)) {
28
- $site = $s;
29
- break;
30
- }
31
- }
32
-
33
- return (isset($site) ? $site : false);
34
- }
35
-
36
- function createAndGetSites($mm) {
37
- $site_url = home_url();
38
- $site_name = get_bloginfo();
39
-
40
- if (!$mm->hasSite()) {
41
- $mm->createSite($site_name, $site_url);
42
- }
43
- $request = $mm->sites();
44
- if ($request['response']['code'] == 200){
45
- $sites = $request['body'];
46
-
47
- return json_decode($sites);
48
- }
49
- else {
50
- return array();
51
- }
52
- }
53
-
54
- function createAndGetGuestSites($mm) {
55
- // This is for GUEST users. Do NOT collect any user data.
56
- $site_url = "";
57
- $site_name = "WordPress";
58
-
59
- if (!$mm->hasSite()) {
60
- $mm->createSite($site_name, $site_url);
61
- }
62
- $request = $mm->sites();
63
- if ($request['response']['code'] == 200){
64
- $sites = $request['body'];
65
-
66
- return json_decode($sites);
67
- }
68
- else {
69
- return array();
70
- }
71
- }
72
- }
73
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/mailmunchapi.php DELETED
@@ -1,160 +0,0 @@
1
- <?php
2
- class MailchimpMailmunchApi {
3
- protected $base_url = '';
4
- protected $email = '';
5
- protected $password = '';
6
- protected $headers = array('Accept' => 'application/json');
7
- protected $requestType = 'get';
8
-
9
- function __construct($email, $password, $url) {
10
- $this->email = $email;
11
- $this->password = $password;
12
- $this->base_url = $url;
13
- }
14
-
15
- function sites() {
16
- $this->requestType = 'get';
17
- return $this->ping('/sites');
18
- }
19
-
20
- function widgets($site_id, $widget_type_name) {
21
- $this->requestType = 'get';
22
- if (!empty($widget_type_name)) {
23
- return $this->ping('/sites/'.$site_id.'/widgets?widget_type_name='.$widget_type_name);
24
- } else {
25
- return $this->ping('/sites/'.$site_id.'/widgets');
26
- }
27
- }
28
-
29
- function getWidgetsHtml($site_id) {
30
- $this->requestType = 'get';
31
- return $this->ping('/sites/'.$site_id.'/widgets/wordpress?plugin=mailchimp');
32
- }
33
-
34
- function deleteWidget($site_id, $widget_id) {
35
- $this->requestType = 'post';
36
- return $this->ping('/sites/'.$site_id.'/widgets/'.$widget_id.'/delete');
37
- }
38
-
39
- function hasSite() {
40
- $request = $this->sites();
41
- $sites = $request['body'];
42
- $result = json_decode($sites);
43
-
44
- return (sizeof($result) > 0);
45
- }
46
-
47
- function createSite($sitename, $domain) {
48
- $this->requestType = 'post';
49
- return $this->ping('/sites', array(
50
- 'site' => array(
51
- 'name' => $sitename,
52
- 'domain' => $domain,
53
- 'wordpress' => true,
54
- 'external_id' => get_option("mc_mm_wordpress_instance_id")
55
- )
56
- ));
57
- }
58
-
59
- function updateSite($sitename, $domain) {
60
- $this->requestType = 'post';
61
- return $this->ping('/wordpress/update_site', array(
62
- 'external_id' => get_option("mc_mm_wordpress_instance_id"),
63
- 'site' => array(
64
- 'name' => $sitename,
65
- 'domain' => $domain
66
- )
67
- ));
68
- }
69
-
70
- function createGuestUser() {
71
- $this->requestType = 'post';
72
- return $this->ping('/users', array(
73
- 'user' => array(
74
- 'email' => $this->email,
75
- 'password' => $this->password,
76
- 'guest_user' => true,
77
- 'referral' => "mailchimp-wordpress-plugin"
78
- )
79
- ), true);
80
- }
81
-
82
- function signUp() {
83
- $this->requestType = 'post';
84
- return $this->ping('/users', array(
85
- 'user' => array(
86
- 'email' => $this->email,
87
- 'password' => $this->password,
88
- 'referral' => "mailchimp-wordpress-plugin"
89
- )
90
- ), true);
91
- }
92
-
93
- function updateGuest($new_email, $new_password) {
94
- $this->requestType = 'post';
95
- return $this->ping('/wordpress/update_guest', array(
96
- 'user' => array(
97
- 'email' => $new_email,
98
- 'password' => $new_password,
99
- 'guest_user' => false
100
- )
101
- ), true);
102
- }
103
-
104
- function signIn() {
105
- $this->requestType = 'post';
106
- return $this->ping('/users/sign_in');
107
- }
108
-
109
- function validPassword() {
110
- $this->requestType = 'get';
111
- $request = $this->ping('/sites');
112
- if( is_wp_error( $request ) ) {
113
- return new WP_Error( 'broke', "Unable to connect to MailMunch. Please try again later." );
114
- }
115
-
116
- if ($request['response']['code'] == 200){
117
- return true;
118
- }
119
- else {
120
- return false;
121
- }
122
- }
123
-
124
- function isNewUser($email) {
125
- if (empty($email)) {
126
- $email = $this->email;
127
- }
128
- $this->requestType = 'get';
129
- $result = $this->ping('/users/exists?user[email]='. $email, array(), true);
130
- return $result['body'] == 'false';
131
- }
132
-
133
- function ping($path, $options=array(), $skipAuth=false) {
134
- $auth = array('auth' => array($this->email, $this->password));
135
- $type = $this->requestType;
136
- $url = $this->base_url. $path;
137
- $args = array(
138
- 'headers' => array_merge($this->headers, array(
139
- 'Authorization' => 'Basic ' . base64_encode( $this->email . ':' . $this->password )
140
- )
141
- ),
142
- 'timeout' => 120
143
- );
144
-
145
- if ($type != 'post') {
146
- $request = wp_remote_get($url, $args);
147
- }
148
- else {
149
- $args = array_merge($args, array('method' => 'POST', 'body' => $options));
150
- $request = wp_remote_post($url, $args);
151
- }
152
-
153
- if ( !is_wp_error( $request ) && ( $request['response']['code'] == 500 || $request['response']['code'] == 503 ) ) {
154
- return new WP_Error( 'broke', "Internal Server Error" );
155
- }
156
-
157
- return $request;
158
- }
159
- }
160
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/sidebar_widget.php DELETED
@@ -1,131 +0,0 @@
1
- <?php
2
- class MC_MM_Sidebar_Widget extends WP_Widget {
3
-
4
- /**
5
- * Register widget with WordPress.
6
- */
7
- function __construct() {
8
- parent::__construct(
9
- 'mc_mm_widget', // Base ID
10
- __('Sidebar MailChimp Form', 'text_domain'), // Name
11
- array( 'description' => __( 'Displays a MailMunch optin form in Sidebar', 'text_domain' ), ) // Args
12
- );
13
- }
14
-
15
- /**
16
- * Front-end display of widget.
17
- *
18
- * @see WP_Widget::widget()
19
- *
20
- * @param array $args Widget arguments.
21
- * @param array $instance Saved values from database.
22
- */
23
- public function widget( $args, $instance ) {
24
- if ( isset( $instance[ 'form_id' ] ) ) {
25
- $form_id = $instance[ 'form_id' ];
26
- }
27
-
28
- if (!empty($form_id)) {
29
- echo $args['before_widget'];
30
- if ( ! empty( $instance['title'] ) ) {
31
- echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
32
- }
33
- echo "<div class='mailmunch-wordpress-widget mailmunch-wordpress-widget-".$form_id."' style='display: none !important;'></div>";
34
- echo $args['after_widget'];
35
- }
36
- }
37
-
38
- /**
39
- * Back-end widget form.
40
- *
41
- * @see WP_Widget::form()
42
- *
43
- * @param array $instance Previously saved values from database.
44
- */
45
- public function form( $instance ) {
46
- if ( isset( $instance[ 'title' ] ) ) {
47
- $title = $instance[ 'title' ];
48
- }
49
- else {
50
- $title = __( 'Optin Form', 'text_domain' );
51
- }
52
-
53
- if ( isset( $instance[ 'form_id' ] ) ) {
54
- $form_id = $instance[ 'form_id' ];
55
- }
56
-
57
- $mc_mm_data = unserialize(get_option("mc_mm_data"));
58
- $mc_mm_user_email = get_option("mc_mm_user_email");
59
- $mc_mm_user_password = get_option("mc_mm_user_password");
60
- if (!empty($mc_mm_user_email) && !empty($mc_mm_user_password) && !empty($mc_mm_data["site_id"])) {
61
- $mc_mm_site_id = $mc_mm_data["site_id"];
62
- $mm = new MailchimpMailmunchApi($mc_mm_user_email, $mc_mm_user_password, "http://".MAILCHIMP_MAILMUNCH_URL);
63
- $result = $mm->widgets($mc_mm_site_id, "Sidebar");
64
- if ( !is_wp_error( $result ) ) {
65
- $widgets = json_decode($result['body']);
66
- }
67
- } else {
68
- ?>
69
- <p>No MailMunch account found. <a href="<?php echo admin_url( 'admin.php?page='.MAILCHIMP_MAILMUNCH_SLUG ); ?>">Go Here First</a></p>
70
- <?php
71
- return;
72
- }
73
- ?>
74
- <script type="text/javascript">
75
- window.onmessage = function (e) {
76
- if (e.data === 'refresh') {
77
- top.location.reload();
78
- }
79
- };
80
- </script>
81
- <?php
82
- if (sizeof($widgets) > 0) {
83
- ?>
84
- <p>
85
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
86
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
87
- </p>
88
-
89
- <p>
90
- <label for="<?php echo $this->get_field_id( 'form_id' ); ?>"><?php _e( 'Optin Form:' ); ?></label>
91
- <select class="widefat" id="<?php echo $this->get_field_id( 'form_id' ); ?>" name="<?php echo $this->get_field_name( 'form_id' ); ?>">
92
- <option value="">None</option>
93
- <?php
94
- foreach ($widgets as $widget) {
95
- echo "<option value='".$widget->id."'";
96
- if ($form_id == $widget->id) { echo " selected"; };
97
- echo ">".$widget->name."</option>";
98
- }
99
- ?>
100
- </select>
101
- </p>
102
-
103
- <p><a href="//<?php echo MAILCHIMP_MAILMUNCH_URL ?>/sso?email=<?php echo urlencode($mc_mm_user_email) ?>&password=<?php echo urlencode($mc_mm_user_password) ?>&next_url=<?php echo urlencode("/sites/".$mc_mm_data["site_id"]."/widgets/new?wp_layout=1&widget_type=Sidebar") ?>" target="_blank">Create New Sidebar Form</a></p>
104
- <?php
105
- } else {
106
- ?>
107
- <p>No sidebar forms found. <a href="//<?php echo MAILCHIMP_MAILMUNCH_URL ?>/sso?email=<?php echo urlencode($mc_mm_user_email) ?>&password=<?php echo urlencode($mc_mm_user_password) ?>&next_url=<?php echo urlencode("/sites/".$mc_mm_data["site_id"]."/widgets/new?wp_layout=1&widget_type=Sidebar") ?>" target="_blank">Create Your First One</a></p>
108
- <?php
109
- }
110
-
111
- }
112
-
113
- /**
114
- * Sanitize widget form values as they are saved.
115
- *
116
- * @see WP_Widget::update()
117
- *
118
- * @param array $new_instance Values just sent to be saved.
119
- * @param array $old_instance Previously saved values from database.
120
- *
121
- * @return array Updated safe values to be saved.
122
- */
123
- public function update( $new_instance, $old_instance ) {
124
- $instance = array();
125
- $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
126
- $instance['form_id'] = ( ! empty( $new_instance['form_id'] ) ) ? strip_tags( $new_instance['form_id'] ) : '';
127
-
128
- return $instance;
129
- }
130
-
131
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-mailchimp-mailmunch-activator.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Fired during plugin activation
5
+ *
6
+ * @link http://www.mailmunch.co
7
+ * @since 2.0.0
8
+ *
9
+ * @package Mailchimp_Mailmunch
10
+ * @subpackage Mailchimp_Mailmunch/includes
11
+ */
12
+
13
+ /**
14
+ * Fired during plugin activation.
15
+ *
16
+ * This class defines all code necessary to run during the plugin's activation.
17
+ *
18
+ * @since 2.0.0
19
+ * @package Mailchimp_Mailmunch
20
+ * @subpackage Mailchimp_Mailmunch/includes
21
+ * @author MailMunch <info@mailmunch.co>
22
+ */
23
+ class Mailchimp_Mailmunch_Activator {
24
+
25
+ /**
26
+ * Short Description. (use period)
27
+ *
28
+ * Long Description.
29
+ *
30
+ * @since 2.0.0
31
+ */
32
+ public static function activate() {
33
+
34
+ }
35
+
36
+ }
includes/class-mailchimp-mailmunch-deactivator.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Fired during plugin deactivation
5
+ *
6
+ * @link http://www.mailmunch.co
7
+ * @since 2.0.0
8
+ *
9
+ * @package Mailchimp_Mailmunch
10
+ * @subpackage Mailchimp_Mailmunch/includes
11
+ */
12
+
13
+ /**
14
+ * Fired during plugin deactivation.
15
+ *
16
+ * This class defines all code necessary to run during the plugin's deactivation.
17
+ *
18
+ * @since 2.0.0
19
+ * @package Mailchimp_Mailmunch
20
+ * @subpackage Mailchimp_Mailmunch/includes
21
+ * @author MailMunch <info@mailmunch.co>
22
+ */
23
+ class Mailchimp_Mailmunch_Deactivator {
24
+
25
+ /**
26
+ * Short Description. (use period)
27
+ *
28
+ * Long Description.
29
+ *
30
+ * @since 2.0.0
31
+ */
32
+ public static function deactivate() {
33
+
34
+ }
35
+
36
+ }
includes/class-mailchimp-mailmunch-i18n.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Define the internationalization functionality
5
+ *
6
+ * Loads and defines the internationalization files for this plugin
7
+ * so that it is ready for translation.
8
+ *
9
+ * @link http://www.mailmunch.co
10
+ * @since 2.0.0
11
+ *
12
+ * @package Mailchimp_Mailmunch
13
+ * @subpackage Mailchimp_Mailmunch/includes
14
+ */
15
+
16
+ /**
17
+ * Define the internationalization functionality.
18
+ *
19
+ * Loads and defines the internationalization files for this plugin
20
+ * so that it is ready for translation.
21
+ *
22
+ * @since 2.0.0
23
+ * @package Mailchimp_Mailmunch
24
+ * @subpackage Mailchimp_Mailmunch/includes
25
+ * @author MailMunch <info@mailmunch.co>
26
+ */
27
+ class Mailchimp_Mailmunch_i18n {
28
+
29
+ /**
30
+ * The domain specified for this plugin.
31
+ *
32
+ * @since 2.0.0
33
+ * @access private
34
+ * @var string $domain The domain identifier for this plugin.
35
+ */
36
+ private $domain;
37
+
38
+ /**
39
+ * Load the plugin text domain for translation.
40
+ *
41
+ * @since 2.0.0
42
+ */
43
+ public function load_plugin_textdomain() {
44
+
45
+ load_plugin_textdomain(
46
+ $this->domain,
47
+ false,
48
+ dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
49
+ );
50
+
51
+ }
52
+
53
+ /**
54
+ * Set the domain equal to that of the specified domain.
55
+ *
56
+ * @since 2.0.0
57
+ * @param string $domain The domain that represents the locale of this plugin.
58
+ */
59
+ public function set_domain( $domain ) {
60
+ $this->domain = $domain;
61
+ }
62
+
63
+ }
includes/class-mailchimp-mailmunch-loader.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Register all actions and filters for the plugin
5
+ *
6
+ * @link http://www.mailmunch.co
7
+ * @since 2.0.0
8
+ *
9
+ * @package Mailchimp_Mailmunch
10
+ * @subpackage Mailchimp_Mailmunch/includes
11
+ */
12
+
13
+ /**
14
+ * Register all actions and filters for the plugin.
15
+ *
16
+ * Maintain a list of all hooks that are registered throughout
17
+ * the plugin, and register them with the WordPress API. Call the
18
+ * run function to execute the list of actions and filters.
19
+ *
20
+ * @package Mailchimp_Mailmunch
21
+ * @subpackage Mailchimp_Mailmunch/includes
22
+ * @author MailMunch <info@mailmunch.co>
23
+ */
24
+ class Mailchimp_Mailmunch_Loader {
25
+
26
+ /**
27
+ * The array of actions registered with WordPress.
28
+ *
29
+ * @since 2.0.0
30
+ * @access protected
31
+ * @var array $actions The actions registered with WordPress to fire when the plugin loads.
32
+ */
33
+ protected $actions;
34
+
35
+ /**
36
+ * The array of filters registered with WordPress.
37
+ *
38
+ * @since 2.0.0
39
+ * @access protected
40
+ * @var array $filters The filters registered with WordPress to fire when the plugin loads.
41
+ */
42
+ protected $filters;
43
+
44
+ /**
45
+ * Initialize the collections used to maintain the actions and filters.
46
+ *
47
+ * @since 2.0.0
48
+ */
49
+ public function __construct() {
50
+
51
+ $this->actions = array();
52
+ $this->filters = array();
53
+
54
+ }
55
+
56
+ /**
57
+ * Add a new action to the collection to be registered with WordPress.
58
+ *
59
+ * @since 2.0.0
60
+ * @param string $hook The name of the WordPress action that is being registered.
61
+ * @param object $component A reference to the instance of the object on which the action is defined.
62
+ * @param string $callback The name of the function definition on the $component.
63
+ * @param int Optional $priority The priority at which the function should be fired.
64
+ * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
65
+ */
66
+ public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
67
+ $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
68
+ }
69
+
70
+ /**
71
+ * Add a new filter to the collection to be registered with WordPress.
72
+ *
73
+ * @since 2.0.0
74
+ * @param string $hook The name of the WordPress filter that is being registered.
75
+ * @param object $component A reference to the instance of the object on which the filter is defined.
76
+ * @param string $callback The name of the function definition on the $component.
77
+ * @param int Optional $priority The priority at which the function should be fired.
78
+ * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
79
+ */
80
+ public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
81
+ $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
82
+ }
83
+
84
+ /**
85
+ * A utility function that is used to register the actions and hooks into a single
86
+ * collection.
87
+ *
88
+ * @since 2.0.0
89
+ * @access private
90
+ * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
91
+ * @param string $hook The name of the WordPress filter that is being registered.
92
+ * @param object $component A reference to the instance of the object on which the filter is defined.
93
+ * @param string $callback The name of the function definition on the $component.
94
+ * @param int Optional $priority The priority at which the function should be fired.
95
+ * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
96
+ * @return type The collection of actions and filters registered with WordPress.
97
+ */
98
+ private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
99
+
100
+ $hooks[] = array(
101
+ 'hook' => $hook,
102
+ 'component' => $component,
103
+ 'callback' => $callback,
104
+ 'priority' => $priority,
105
+ 'accepted_args' => $accepted_args
106
+ );
107
+
108
+ return $hooks;
109
+
110
+ }
111
+
112
+ /**
113
+ * Register the filters and actions with WordPress.
114
+ *
115
+ * @since 2.0.0
116
+ */
117
+ public function run() {
118
+
119
+ foreach ( $this->filters as $hook ) {
120
+ add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
121
+ }
122
+
123
+ foreach ( $this->actions as $hook ) {
124
+ add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
125
+ }
126
+
127
+ }
128
+
129
+ }
includes/class-mailchimp-mailmunch-sidebar-widget.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mailchimp_Mailmunch_Sidebar_Widget extends WP_Widget {
3
+
4
+ /**
5
+ * Register widget with WordPress.
6
+ */
7
+ function __construct() {
8
+ parent::__construct(
9
+ MAILCHIMP_MAILMUNCH_PREFIX.'_widget', // Base ID
10
+ __('Sidebar MailChimp Form', 'text_domain'), // Name
11
+ array( 'description' => __( 'Displays a MailChimp optin form in Sidebar', 'text_domain' ), ) // Args
12
+ );
13
+ }
14
+
15
+ /**
16
+ * Front-end display of widget.
17
+ *
18
+ * @see WP_Widget::widget()
19
+ *
20
+ * @param array $args Widget arguments.
21
+ * @param array $instance Saved values from database.
22
+ */
23
+ public function widget( $args, $instance ) {
24
+ if ( isset( $instance[ 'form_id' ] ) ) {
25
+ $form_id = $instance[ 'form_id' ];
26
+ }
27
+
28
+ if (!empty($form_id)) {
29
+ echo $args['before_widget'];
30
+ if ( ! empty( $instance['title'] ) ) {
31
+ echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
32
+ }
33
+ echo "<div class='mailmunch-wordpress-widget mailmunch-wordpress-widget-".$form_id."' style='display: none !important;'></div>";
34
+ echo $args['after_widget'];
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Back-end widget form.
40
+ *
41
+ * @see WP_Widget::form()
42
+ *
43
+ * @param array $instance Previously saved values from database.
44
+ */
45
+ public function form( $instance ) {
46
+ if ( isset( $instance[ 'title' ] ) ) {
47
+ $title = $instance[ 'title' ];
48
+ }
49
+ else {
50
+ $title = __( 'Optin Form', 'text_domain' );
51
+ }
52
+
53
+ if ( isset( $instance[ 'form_id' ] ) ) {
54
+ $form_id = $instance[ 'form_id' ];
55
+ }
56
+
57
+ $mm = new Mailmunch_Api();
58
+ $result = $mm->widgets("Sidebar");
59
+ if ( !is_wp_error( $result ) ) {
60
+ $widgets = json_decode($result['body']);
61
+ }
62
+
63
+ ?>
64
+ <script type="text/javascript">
65
+ window.onmessage = function (e) {
66
+ if (e.data === 'refresh') {
67
+ top.location.reload();
68
+ }
69
+ };
70
+ </script>
71
+ <?php
72
+ if (sizeof($widgets) > 0) {
73
+ ?>
74
+ <p>
75
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
76
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
77
+ </p>
78
+
79
+ <p>
80
+ <label for="<?php echo $this->get_field_id( 'form_id' ); ?>"><?php _e( 'Optin Form:' ); ?></label>
81
+ <select class="widefat" id="<?php echo $this->get_field_id( 'form_id' ); ?>" name="<?php echo $this->get_field_name( 'form_id' ); ?>">
82
+ <option value="">None</option>
83
+ <?php
84
+ foreach ($widgets as $widget) {
85
+ echo "<option value='".$widget->id."'";
86
+ if ($form_id == $widget->id) { echo " selected"; };
87
+ echo ">".$widget->name."</option>";
88
+ }
89
+ ?>
90
+ </select>
91
+ </p>
92
+
93
+ <p><a href="<?php echo MAILCHIMP_MAILMUNCH_URL ?>/sso?token=<?php echo get_option(MAILCHIMP_MAILMUNCH_PREFIX."_user_token") ?>&next_url=<?php echo urlencode("/sites/".get_option(MAILCHIMP_MAILMUNCH_PREFIX."_site_id")."/widgets/new?wp_layout=1&widget_type=Sidebar") ?>" target="_blank">Create New Sidebar Form</a></p>
94
+ <?php
95
+ } else {
96
+ ?>
97
+ <p>No sidebar forms found. <a href="<?php echo MAILCHIMP_MAILMUNCH_URL ?>/sso?token=<?php echo get_option(MAILCHIMP_MAILMUNCH_PREFIX."_user_token") ?>&next_url=<?php echo urlencode("/sites/".get_option(MAILCHIMP_MAILMUNCH_PREFIX."_site_id")."/widgets/new?wp_layout=1&widget_type=Sidebar") ?>" target="_blank">Create Your First One</a></p>
98
+ <?php
99
+ }
100
+
101
+ }
102
+
103
+ /**
104
+ * Sanitize widget form values as they are saved.
105
+ *
106
+ * @see WP_Widget::update()
107
+ *
108
+ * @param array $new_instance Values just sent to be saved.
109
+ * @param array $old_instance Previously saved values from database.
110
+ *
111
+ * @return array Updated safe values to be saved.
112
+ */
113
+ public function update( $new_instance, $old_instance ) {
114
+ $instance = array();
115
+ $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
116
+ $instance['form_id'] = ( ! empty( $new_instance['form_id'] ) ) ? strip_tags( $new_instance['form_id'] ) : '';
117
+
118
+ return $instance;
119
+ }
120
+
121
+ }
includes/class-mailchimp-mailmunch.php ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * The file that defines the core plugin class
5
+ *
6
+ * A class definition that includes attributes and functions used across both the
7
+ * public-facing side of the site and the admin area.
8
+ *
9
+ * @link http://www.mailmunch.co
10
+ * @since 2.0.0
11
+ *
12
+ * @package Mailchimp_Mailmunch
13
+ * @subpackage Mailchimp_Mailmunch/includes
14
+ */
15
+
16
+ // Define some class constants.
17
+ define( 'MAILCHIMP_MAILMUNCH_URL', "http://wordpress.mailmunch.co" );
18
+ define( 'MAILCHIMP_MAILMUNCH_HOME_URL', "http://www.mailmunch.co" );
19
+ define( 'MAILCHIMP_MAILMUNCH_SLUG', "mailchimp-mailmunch" );
20
+ define( 'MAILCHIMP_MAILMUNCH_PREFIX', 'mc_mm' );
21
+
22
+ /**
23
+ * The core plugin class.
24
+ *
25
+ * This is used to define internationalization, admin-specific hooks, and
26
+ * public-facing site hooks.
27
+ *
28
+ * Also maintains the unique identifier of this plugin as well as the current
29
+ * version of the plugin.
30
+ *
31
+ * @since 2.0.0
32
+ * @package Mailchimp_Mailmunch
33
+ * @subpackage Mailchimp_Mailmunch/includes
34
+ * @author MailMunch <info@mailmunch.co>
35
+ */
36
+ class Mailchimp_Mailmunch {
37
+
38
+ /**
39
+ * The loader that's responsible for maintaining and registering all hooks that power
40
+ * the plugin.
41
+ *
42
+ * @since 2.0.0
43
+ * @access protected
44
+ * @var Mailchimp_Mailmunch_Loader $loader Maintains and registers all hooks for the plugin.
45
+ */
46
+ protected $loader;
47
+
48
+ /**
49
+ * The unique identifier of this plugin.
50
+ *
51
+ * @since 2.0.0
52
+ * @access protected
53
+ * @var string $plugin_name The string used to uniquely identify this plugin.
54
+ */
55
+ protected $plugin_name;
56
+
57
+ /**
58
+ * The unique identifier for the plugin's intended 3rd party integration
59
+ *
60
+ * @since 2.0.0
61
+ * @access protected
62
+ * @var string $integration_name The string used to uniquely identify the integration.
63
+ */
64
+ protected $integration_name;
65
+
66
+ /**
67
+ * The current version of the plugin.
68
+ *
69
+ * @since 2.0.0
70
+ * @access protected
71
+ * @var string $version The current version of the plugin.
72
+ */
73
+ protected $version;
74
+
75
+ /**
76
+ * The MailMunch api.
77
+ *
78
+ * @since 2.0.0
79
+ * @access protected
80
+ * @var string $mailmunch_api MailMunch API
81
+ */
82
+ protected $mailmunch_api;
83
+
84
+ /**
85
+ * Define the core functionality of the plugin.
86
+ *
87
+ * Set the plugin name and the plugin version that can be used throughout the plugin.
88
+ * Load the dependencies, define the locale, and set the hooks for the admin area and
89
+ * the public-facing side of the site.
90
+ *
91
+ * @since 2.0.0
92
+ */
93
+ public function __construct() {
94
+
95
+ $this->plugin_name = 'MailChimp Forms by MailMunch';
96
+ $this->integration_name = 'MailChimp';
97
+ $this->version = '2.0.0';
98
+
99
+ $this->load_dependencies();
100
+ $this->set_locale();
101
+ if (is_admin()) {
102
+ $this->define_admin_hooks();
103
+ }
104
+ $this->define_public_hooks();
105
+
106
+
107
+ }
108
+
109
+ /**
110
+ * Load the required dependencies for this plugin.
111
+ *
112
+ * Include the following files that make up the plugin:
113
+ *
114
+ * - Mailchimp_Mailmunch_Loader. Orchestrates the hooks of the plugin.
115
+ * - Mailchimp_Mailmunch_i18n. Defines internationalization functionality.
116
+ * - Mailchimp_Mailmunch_Admin. Defines all hooks for the admin area.
117
+ * - Mailchimp_Mailmunch_Public. Defines all hooks for the public side of the site.
118
+ *
119
+ * Create an instance of the loader which will be used to register the hooks
120
+ * with WordPress.
121
+ *
122
+ * @since 2.0.0
123
+ * @access private
124
+ */
125
+ private function load_dependencies() {
126
+
127
+ /**
128
+ * The class responsible for communicating with MailMunch's Public API
129
+ */
130
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-mailmunch-api.php';
131
+
132
+ /**
133
+ * The class responsible for adding the sidebar widget
134
+ */
135
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-mailchimp-mailmunch-sidebar-widget.php';
136
+
137
+ /**
138
+ * The class responsible for orchestrating the actions and filters of the
139
+ * core plugin.
140
+ */
141
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-mailchimp-mailmunch-loader.php';
142
+
143
+ /**
144
+ * The class responsible for defining internationalization functionality
145
+ * of the plugin.
146
+ */
147
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-mailchimp-mailmunch-i18n.php';
148
+
149
+ /**
150
+ * The class responsible for defining all actions that occur in the admin area.
151
+ */
152
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-mailchimp-mailmunch-admin.php';
153
+
154
+ /**
155
+ * The class responsible for defining all actions that occur in the public-facing
156
+ * side of the site.
157
+ */
158
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-mailchimp-mailmunch-public.php';
159
+
160
+ $this->loader = new Mailchimp_Mailmunch_Loader();
161
+
162
+ }
163
+
164
+ /**
165
+ * Define the locale for this plugin for internationalization.
166
+ *
167
+ * Uses the Mailchimp_Mailmunch_i18n class in order to set the domain and to register the hook
168
+ * with WordPress.
169
+ *
170
+ * @since 2.0.0
171
+ * @access private
172
+ */
173
+ private function set_locale() {
174
+
175
+ $plugin_i18n = new Mailchimp_Mailmunch_i18n();
176
+ $plugin_i18n->set_domain( $this->get_plugin_name() );
177
+
178
+ $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
179
+
180
+ }
181
+
182
+ /**
183
+ * Register all of the hooks related to the admin area functionality
184
+ * of the plugin.
185
+ *
186
+ * @since 2.0.0
187
+ * @access private
188
+ */
189
+ private function define_admin_hooks() {
190
+
191
+ $plugin_admin = new Mailchimp_Mailmunch_Admin( $this->get_plugin_name(), $this->get_intgration_name(), $this->get_version() );
192
+
193
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
194
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
195
+ $this->loader->add_action( 'admin_menu', $plugin_admin, 'menu' );
196
+
197
+ // Sidebar widget
198
+ $this->loader->add_action( 'widgets_init', $plugin_admin, 'sidebar_widget' );
199
+
200
+ // Ajax calls
201
+ $this->loader->add_action( 'wp_ajax_sign_up', $plugin_admin, 'sign_up' );
202
+ $this->loader->add_action( 'wp_ajax_sign_in', $plugin_admin, 'sign_in' );
203
+ $this->loader->add_action( 'wp_ajax_delete_widget', $plugin_admin, 'delete_widget' );
204
+
205
+ // Settings link
206
+ $pluginBaseName = plugin_basename(__FILE__);
207
+ $exploded = explode('/', $pluginBaseName);
208
+ $pluginFilePath = $exploded[0]. '/mailchimp-mailmunch.php';
209
+ $this->loader->add_filter( 'plugin_action_links_'. $pluginFilePath, $plugin_admin, 'settings_link');
210
+
211
+ }
212
+
213
+ /**
214
+ * Register all of the hooks related to the public-facing functionality
215
+ * of the plugin.
216
+ *
217
+ * @since 2.0.0
218
+ * @access private
219
+ */
220
+ private function define_public_hooks() {
221
+
222
+ $plugin_public = new Mailchimp_Mailmunch_Public( $this->get_plugin_name(), $this->get_version() );
223
+
224
+ $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
225
+ $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
226
+
227
+ $this->loader->add_filter( 'the_content', $plugin_public, 'add_post_containers' );
228
+
229
+ }
230
+
231
+ /**
232
+ * Run the loader to execute all of the hooks with WordPress.
233
+ *
234
+ * @since 2.0.0
235
+ */
236
+ public function run() {
237
+ $this->loader->run();
238
+ }
239
+
240
+ /**
241
+ * The name of the plugin used to uniquely identify it within the context of
242
+ * WordPress and to define internationalization functionality.
243
+ *
244
+ * @since 2.0.0
245
+ * @return string The name of the plugin.
246
+ */
247
+ public function get_plugin_name() {
248
+ return $this->plugin_name;
249
+ }
250
+
251
+ /**
252
+ * The name of the 3rd party integration
253
+ * e.g. MailChimp, Constant Contact, etc.
254
+ *
255
+ * @since 2.0.0
256
+ * @return string The name of the plugin.
257
+ */
258
+ public function get_intgration_name() {
259
+ return $this->integration_name;
260
+ }
261
+
262
+ /**
263
+ * The reference to the class that orchestrates the hooks with the plugin.
264
+ *
265
+ * @since 2.0.0
266
+ * @return Mailchimp_Mailmunch_Loader Orchestrates the hooks of the plugin.
267
+ */
268
+ public function get_loader() {
269
+ return $this->loader;
270
+ }
271
+
272
+ /**
273
+ * Retrieve the version number of the plugin.
274
+ *
275
+ * @since 2.0.0
276
+ * @return string The version number of the plugin.
277
+ */
278
+ public function get_version() {
279
+ return $this->version;
280
+ }
281
+ }
includes/class-mailmunch-api.php ADDED
@@ -0,0 +1,391 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mailmunch_Api {
3
+ protected $base_url = MAILCHIMP_MAILMUNCH_URL;
4
+ protected $headers = array('Accept' => 'application/json');
5
+ protected $requestType = 'get';
6
+ protected $mailmunch_prefix;
7
+ protected $referral = 'mailchimp-wordpress-plugin';
8
+ protected $site = null;
9
+
10
+ function __construct() {
11
+ $this->mailmunch_prefix = MAILCHIMP_MAILMUNCH_PREFIX.'_';
12
+ $this->ensureUser();
13
+ $this->site = $this->findOrCreateSite();
14
+ }
15
+
16
+ function ensureUser() {
17
+ $userToken = $this->getUserToken();
18
+ if (empty($userToken)) {
19
+ $userToken = $this->generateUserToken();
20
+ if( is_wp_error( $userToken ) ) {
21
+ return new WP_Error( 'broke', "Unable to connect to MailMunch. Please try again later." );
22
+ }
23
+
24
+ $this->setUserToken($userToken);
25
+ }
26
+ }
27
+
28
+ function getUserToken() {
29
+ return get_option($this->getPrefix(). 'user_token');
30
+ }
31
+
32
+ function setUserToken($userToken) {
33
+ return update_option($this->getPrefix(). 'user_token', $userToken );
34
+ }
35
+
36
+ function widgets($widgetTypeName, $siteId=null) {
37
+ if (empty($siteId)) { $siteId = $this->getSiteId(); }
38
+ $this->requestType = 'get';
39
+ if (!empty($widgetTypeName)) {
40
+ return $this->ping('/sites/'.$siteId.'/widgets?widget_type_name='.$widgetTypeName);
41
+ } else {
42
+ return $this->ping('/sites/'.$siteId.'/widgets');
43
+ }
44
+ }
45
+
46
+ function getPrefix() {
47
+ return $this->mailmunch_prefix;
48
+ }
49
+
50
+ function getSites() {
51
+ $this->requestType = 'get';
52
+ $request = $this->ping('/sites');
53
+
54
+ if( is_wp_error( $request ) ) {
55
+ return new WP_Error( 'broke', "Unable to get sites. Please try again later." );
56
+ }
57
+
58
+ $sites = $request['body'];
59
+ $result = json_decode($sites);
60
+ return $result;
61
+ }
62
+
63
+ function getSite($siteId=null) {
64
+ if (empty($siteId)) $siteId = $this->getSiteId();
65
+ $sites = $this->getSites();
66
+ $s = false;
67
+ if (count($sites)) {
68
+ foreach ($sites as $site) {
69
+ if ($site->id == $siteId) {
70
+ $s = $site;
71
+ break;
72
+ }
73
+ }
74
+ }
75
+ return $s;
76
+ }
77
+
78
+ function getLists($siteId=null) {
79
+ if (empty($siteId)) { $siteId = $this->getSiteId(); }
80
+ $this->requestType = 'get';
81
+ $request = $this->ping('/sites/'. $siteId. '/lists');
82
+ if( is_wp_error( $request ) ) {
83
+ return new WP_Error( 'broke', "Unable to get lists. Please try again later." );
84
+ }
85
+
86
+ return json_decode($request['body']);
87
+ }
88
+
89
+ function createListAndIntegration($accessToken, $listName, $externalListId) {
90
+ $list = $this->createList($listName);
91
+ if ($list) {
92
+ $site = $this->getSite();
93
+ $integration = $this->createIntegration($site->id, $list->id, $accessToken, $externalListId );
94
+ return $integration;
95
+ }
96
+ }
97
+
98
+ function findOrCreateSite() {
99
+ $site = $this->getSite($this->getSiteId());
100
+ if (empty($site)) {
101
+ $site = $this->createSite(get_bloginfo(), home_url());
102
+ $this->setSiteId($site->id);
103
+ }
104
+ return $site;
105
+ }
106
+
107
+ function createIntegration($siteId, $listId, $accessToken, $externalListId) {
108
+ $this->requestType = 'post';
109
+ $response = $this->ping('/wordpress/integrations/mailchimp', array(
110
+ 'site_id' => $siteId,
111
+ 'list_id' => $listId,
112
+ 'access_token' => $accessToken,
113
+ 'active_list_id' => $externalListId
114
+ ));
115
+ $site = json_decode($response['body']);
116
+ return $site;
117
+ }
118
+
119
+ function createList($listName, $siteId=null) {
120
+ if (empty($listName)) $listName = 'General';
121
+ if (empty($siteId)) { $siteId = $this->getSiteId(); }
122
+ $this->requestType = 'post';
123
+ $response = $this->ping('/sites/'. $siteId. '/lists', array(
124
+ 'list' => array(
125
+ 'name' => $listName,
126
+ )
127
+ ));
128
+ $list = json_decode($response['body']);
129
+ return $list;
130
+ }
131
+
132
+ function createSite($siteName, $domain) {
133
+ if (empty($siteName)) $siteName = 'WordPress';
134
+ $this->requestType = 'post';
135
+ $request = $this->ping('/sites', array(
136
+ 'site' => array(
137
+ 'name' => $siteName,
138
+ 'domain' => $domain,
139
+ 'wordpress' => true
140
+ )
141
+ ));
142
+ if( is_wp_error( $request ) ) {
143
+ return new WP_Error( 'broke', "Unable to create site. Please try again later." );
144
+ }
145
+
146
+ $site = json_decode($request['body']);
147
+ update_option($this->getPrefix(). 'site_id', $site->id);
148
+ return $site;
149
+ }
150
+
151
+ function updateSite($sitename, $domain) {
152
+ $this->requestType = 'post';
153
+ return $this->ping('/wordpress/update_site', array(
154
+ 'id' => $this->getSiteId(),
155
+ 'site' => array(
156
+ 'name' => $sitename,
157
+ 'domain' => $domain
158
+ )
159
+ ));
160
+ }
161
+
162
+ function isLegacyUser() {
163
+ $email = get_option($this->getPrefix(). "user_email");
164
+ $password = get_option($this->getPrefix(). "user_password");
165
+
166
+ if (!empty($email) && !empty($password)) {
167
+ return true;
168
+ }
169
+
170
+ return false;
171
+ }
172
+
173
+ function skipOnBoarding() {
174
+ $skipOnBoarding = get_option($this->getPrefix(). 'skip_onboarding');
175
+ return $skipOnBoarding == true;
176
+ }
177
+
178
+ function migrateUser() {
179
+ $currentHeaders = $this->headers;
180
+ $email = get_option($this->getPrefix(). "user_email");
181
+ $password = get_option($this->getPrefix(). "user_password");
182
+
183
+ if (empty($email) || empty($password)) {
184
+ return false;
185
+ }
186
+
187
+ $this->headers = array_merge($this->headers, array(
188
+ 'Authorization' => 'Basic ' . base64_encode( $email . ':' . $password )
189
+ )
190
+ );
191
+
192
+ $this->requestType = 'post';
193
+ $request = $this->ping('/wordpress/migrate_user.json', array(), true);
194
+ $this->headers = $currentHeaders;
195
+
196
+ if( is_wp_error( $request ) ) {
197
+ return false;
198
+ }
199
+
200
+ $request = json_decode($request['body']);
201
+ if ($request->success == true && !empty($request->token)) {
202
+ $this->setUserToken($request->token);
203
+
204
+ // Migrate Site ID
205
+ $old_data = unserialize(get_option($this->getPrefix(). "data"));
206
+ if (isset($old_data["site_id"])) {
207
+ $this->setSiteId($old_data["site_id"]);
208
+ }
209
+
210
+ // Delete options for old site
211
+ delete_option($this->getPrefix(). 'data');
212
+ delete_option($this->getPrefix(). 'user_email');
213
+ delete_option($this->getPrefix(). 'user_password');
214
+ delete_option($this->getPrefix(). 'guest_user');
215
+ delete_option($this->getPrefix(). 'wordpress_instance_id');
216
+
217
+ update_option($this->getPrefix(). 'skip_onboarding', true);
218
+
219
+ return true;
220
+ }
221
+
222
+ return false;
223
+ }
224
+
225
+ function generateUserToken() {
226
+ if ($this->isLegacyUser()) {
227
+ if ($this->migrateUser()) {
228
+ return $this->getUserToken();
229
+ }
230
+ }
231
+
232
+ $guestUser = $this->createGuestUser();
233
+ if( is_wp_error( $guestUser ) ) {
234
+ return new WP_Error( 'broke', "Unable to create user. Please try again later." );
235
+ }
236
+ return json_decode($guestUser['body'])->user_token;
237
+ }
238
+
239
+ function createGuestUser() {
240
+ $this->requestType = 'post';
241
+ return $this->ping('/users', array(
242
+ 'user' => array(
243
+ 'email' => 'guest_' . uniqid() . '@mailmunch.co',
244
+ 'password' => uniqid(),
245
+ 'guest_user' => true,
246
+ 'referral' => $this->referral,
247
+ )
248
+ ));
249
+ }
250
+
251
+ function getWidgetsHtml($siteId=null) {
252
+ if (empty($siteId)) { $siteId = $this->getSiteId(); }
253
+
254
+ $this->requestType = 'get';
255
+ $request = $this->ping('/sites/'.$siteId.'/widgets/wordpress?plugin=mailchimp');
256
+ if( is_wp_error( $request ) ) {
257
+ return $request->get_error_message();
258
+ }
259
+
260
+ $body = str_replace('{{TOKEN}}', $this->getUserToken(), $request['body']);
261
+ return $body;
262
+ }
263
+
264
+ function getSiteId() {
265
+ return get_option($this->getPrefix(). 'site_id');
266
+ }
267
+
268
+ function setSiteId($siteId) {
269
+ return update_option($this->getPrefix(). 'site_id', $siteId);
270
+ }
271
+
272
+ function getListId() {
273
+ return get_option($this->getPrefix(). 'list_id');
274
+ }
275
+
276
+ function setListId($listId) {
277
+ return update_option($this->getPrefix(). 'list_id', $listId);
278
+ }
279
+
280
+ function deleteWidget($widgetId) {
281
+ $this->requestType = 'post';
282
+ $request = $this->ping('/sites/'.$this->getSiteId().'/widgets/'.$widgetId.'/delete');
283
+ if ( is_wp_error( $request ) ) {
284
+ return array('success' => false);
285
+ }
286
+ return array('success' => true);
287
+ }
288
+
289
+ function signInUser($email, $password) {
290
+ $this->requestType = 'post';
291
+ $request = $this->ping('/wordpress/sign_in.json', array(
292
+ 'user' => array(
293
+ 'email' => $email,
294
+ 'password' => $password
295
+ ),
296
+ 'site_id' => $this->getSiteId()
297
+ )
298
+ );
299
+
300
+ if( is_wp_error( $request ) ) {
301
+ return false;
302
+ }
303
+
304
+ $newUser = json_decode($request['body']);
305
+ if ($newUser->site_id != $this->getSiteId()) {
306
+ $this->setSiteId($newUser->site_id);
307
+ }
308
+ return $newUser;
309
+ }
310
+
311
+ function signUpUser($email, $password, $siteName, $siteDomain) {
312
+ $this->requestType = 'post';
313
+ $request = $this->ping('/wordpress/sign_up.json', array(
314
+ 'user' => array(
315
+ 'email' => $email,
316
+ 'password' => $password,
317
+ 'guest_user' => false
318
+ ),
319
+ 'site' => array(
320
+ 'id' => $this->getSiteId(),
321
+ 'name' => $siteName,
322
+ 'domain' => $siteDomain
323
+ )
324
+ )
325
+ );
326
+
327
+ if( is_wp_error( $request ) ) {
328
+ return false;
329
+ }
330
+
331
+ $newUser = json_decode($request['body']);
332
+ if ($newUser->site_id != $this->getSiteId()) {
333
+ $this->setSiteId($newUser->site_id);
334
+ }
335
+ return $newUser;
336
+ }
337
+
338
+ function signOutUser() {
339
+ delete_option($this->getPrefix(). 'user_token');
340
+ delete_option($this->getPrefix(). 'site_id');
341
+ delete_option($this->getPrefix(). 'mailchimp_access_token');
342
+ delete_option($this->getPrefix(). 'mailchimp_list_id');
343
+ }
344
+
345
+ function ping($path, $options=array(), $skipTokenAuth=false, $retries=0) {
346
+ $retries++;
347
+ if ($retries > 3) return new WP_Error('broke', 'Internal Server Error');
348
+
349
+ $type = $this->requestType;
350
+ $url = $this->base_url. $path;
351
+
352
+ if (!$skipTokenAuth) {
353
+ $parsedUrl = parse_url($url);
354
+ $parseUrlQuery = $parsedUrl['query'];
355
+ if (!empty($parseUrlQuery)) {
356
+ $url .= '&token='. $this->getUserToken();
357
+ }
358
+ else {
359
+ $url .= '?token='. $this->getUserToken();
360
+ }
361
+ }
362
+
363
+ $args = array(
364
+ 'headers' => $this->headers,
365
+ 'timeout' => 120,
366
+ );
367
+
368
+ if ($type != 'post') {
369
+ $request = wp_remote_get($url, $args);
370
+ }
371
+ else {
372
+ $args = array_merge($args, array('method' => 'POST', 'body' => $options));
373
+ $request = wp_remote_post($url, $args);
374
+ }
375
+
376
+ if ( !is_wp_error( $request ) && ( $request['response']['code'] == 500 || $request['response']['code'] == 503 ) ) {
377
+ return new WP_Error( 'broke', "Internal Server Error" );
378
+ }
379
+
380
+ if (!$skipTokenAuth) {
381
+ if (!is_wp_error( $request ) && isset($request['response']['code']) && $request['response']['code'] == 401) {
382
+ $this->signOutUser();
383
+ $this->ensureUser();
384
+ return $this->ping($path, $options, $skipTokenAuth, $retries);
385
+ }
386
+ }
387
+
388
+ return $request;
389
+ }
390
+ }
391
+ ?>
includes/drewm_mailchimp.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Drewm;
4
+
5
+ /**
6
+ * Super-simple, minimum abstraction MailChimp API v2 wrapper
7
+ *
8
+ * Uses curl if available, falls back to file_get_contents and HTTP stream.
9
+ * This probably has more comments than code.
10
+ *
11
+ * Contributors:
12
+ * Michael Minor <me@pixelbacon.com>
13
+ * Lorna Jane Mitchell, github.com/lornajane
14
+ *
15
+ * @author Drew McLellan <drew.mclellan@gmail.com>
16
+ * @version 1.1.1
17
+ */
18
+ class MailChimp
19
+ {
20
+ private $api_key;
21
+ private $api_endpoint = 'https://<dc>.api.mailchimp.com/2.0';
22
+ private $verify_ssl = false;
23
+
24
+ /**
25
+ * Create a new instance
26
+ * @param string $api_key Your MailChimp API key
27
+ */
28
+ public function __construct($api_key)
29
+ {
30
+ $this->api_key = $api_key;
31
+ list(, $datacentre) = explode('-', $this->api_key);
32
+ $this->api_endpoint = str_replace('<dc>', $datacentre, $this->api_endpoint);
33
+ }
34
+
35
+ /**
36
+ * Call an API method. Every request needs the API key, so that is added automatically -- you don't need to pass it in.
37
+ * @param string $method The API method to call, e.g. 'lists/list'
38
+ * @param array $args An array of arguments to pass to the method. Will be json-encoded for you.
39
+ * @return array Associative array of json decoded API response.
40
+ */
41
+ public function call($method, $args = array(), $timeout = 10)
42
+ {
43
+ return $this->makeRequest($method, $args, $timeout);
44
+ }
45
+
46
+ /**
47
+ * Performs the underlying HTTP request. Not very exciting
48
+ * @param string $method The API method to be called
49
+ * @param array $args Assoc array of parameters to be passed
50
+ * @return array Assoc array of decoded result
51
+ */
52
+ private function makeRequest($method, $args = array(), $timeout = 10)
53
+ {
54
+ $args['apikey'] = $this->api_key;
55
+
56
+ $url = $this->api_endpoint.'/'.$method.'.json';
57
+ $json_data = json_encode($args);
58
+
59
+ if (function_exists('curl_init') && function_exists('curl_setopt')) {
60
+ $ch = curl_init();
61
+ curl_setopt($ch, CURLOPT_URL, $url);
62
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
63
+ curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
64
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
65
+ curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
66
+ curl_setopt($ch, CURLOPT_POST, true);
67
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl);
68
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
69
+ $result = curl_exec($ch);
70
+ curl_close($ch);
71
+ } else {
72
+ $result = file_get_contents($url, null, stream_context_create(array(
73
+ 'http' => array(
74
+ 'protocol_version' => 1.1,
75
+ 'user_agent' => 'PHP-MCAPI/2.0',
76
+ 'method' => 'POST',
77
+ 'header' => "Content-type: application/json\r\n".
78
+ "Connection: close\r\n" .
79
+ "Content-length: " . strlen($json_data) . "\r\n",
80
+ 'content' => $json_data,
81
+ ),
82
+ )));
83
+ }
84
+
85
+ return $result ? json_decode($result, true) : false;
86
+ }
87
+ }
includes/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
js/admin.js DELETED
@@ -1,98 +0,0 @@
1
- jQuery.unparam = function (value) {
2
- var
3
- // Object that holds names => values.
4
- params = {},
5
- // Get query string pieces (separated by &)
6
- pieces = value.split('&'),
7
- // Temporary variables used in loop.
8
- pair, i, l;
9
-
10
- // Loop through query string pieces and assign params.
11
- for (i = 0, l = pieces.length; i < l; i++) {
12
- pair = pieces[i].split('=', 2);
13
- // Repeated parameters with the same name are overwritten. Parameters
14
- // with no value get set to boolean true.
15
- params[decodeURIComponent(pair[0])] = (pair.length == 2 ?
16
- decodeURIComponent(pair[1].replace(/\+/g, ' ')) : true);
17
- }
18
-
19
- return params;
20
- };
21
-
22
- window.onmessage = function (e) {
23
- if (e.data === 'refresh') {
24
- top.location.reload();
25
- }
26
- };
27
-
28
- function repositionSignupBox() {
29
- divId = 'signup-signin-box';
30
- var divWidth, divHeight;
31
- var objDiv = document.getElementById(divId);
32
-
33
- if (objDiv.clientWidth) {
34
- divWidth = objDiv.clientWidth;
35
- divHeight = objDiv.clientHeight;
36
- }
37
- else if (objDiv.offsetWidth)
38
- {
39
- divWidth = objDiv.offsetWidth;
40
- divHeight = objDiv.offsetHeight;
41
- }
42
-
43
- // Get the x and y coordinates of the center in output browser's window
44
- var centerX, centerY;
45
- if (window.innerHeight)
46
- {
47
- centerX = window.innerWidth;
48
- centerY = window.innerHeight;
49
- }
50
- else if (document.documentElement && document.documentElement.clientHeight)
51
- {
52
- centerX = document.documentElement.clientWidth;
53
- centerY = document.documentElement.clientHeight;
54
- }
55
- else if (document.body)
56
- {
57
- centerX = document.body.clientWidth;
58
- centerY = document.body.clientHeight;
59
- }
60
-
61
- var offsetLeft = (centerX - divWidth) / 2;
62
- var offsetTop = (centerY - divHeight) / 2;
63
-
64
- objDiv.style.top = offsetTop + 'px';
65
- objDiv.style.left = offsetLeft + 'px';
66
- }
67
-
68
- function showSignInForm() {
69
- document.getElementById("sign-up-form").style.display = 'none';
70
- document.getElementById("sign-in-form").style.display = 'block';
71
- document.getElementById('why-account').style.display = 'none';
72
- showSignupBox();
73
- }
74
-
75
- function showSignUpForm() {
76
- document.getElementById("sign-in-form").style.display = 'none';
77
- document.getElementById("sign-up-form").style.display = 'block';
78
- document.getElementById('why-account').style.display = 'none';
79
- showSignupBox();
80
- }
81
-
82
- function showSignupBox(width, height) {
83
- document.getElementById("signup-signin-box-overlay").style.display = 'block';
84
- document.getElementById("signup-signin-box").style.display = 'block';
85
- repositionSignupBox();
86
-
87
- return false;
88
- }
89
-
90
- function hideSignupBox() {
91
- document.getElementById("signup-signin-box-overlay").style.display = 'none';
92
- document.getElementById("signup-signin-box").style.display = 'none';
93
- }
94
-
95
- function showWhyAccount() {
96
- document.getElementById('why-account').style.display = 'block';
97
- repositionSignupBox();
98
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
languages/mailchimp-mailmunch.pot ADDED
File without changes
mailchimp-mailmunch.php CHANGED
@@ -1,485 +1,75 @@
1
  <?php
2
- /*
3
- Plugin Name: MailChimp Forms by MailMunch
4
- Plugin URI: http://connect.mailchimp.com/integrations/mailmunch-email-list-builder
5
- Description: The MailChimp plugin allows you to quickly and easily add signup forms for your MailChimp lists. Popup, Embedded, Top Bar and a variety of different options available.
6
- Version: 1.0.9
7
- Author: MailMunch
8
- Author URI: http://www.mailmunch.co
9
- License: GPL2
10
- */
11
 
12
- require_once( plugin_dir_path( __FILE__ ) . 'inc/mailmunchapi.php' );
13
- require_once( plugin_dir_path( __FILE__ ) . 'inc/common.php' );
14
- require_once( plugin_dir_path( __FILE__ ) . 'inc/sidebar_widget.php' );
15
-
16
- define( 'MAILCHIMP_MAILMUNCH_SLUG', "mailchimp-mailmunch");
17
- define( 'MAILCHIMP_MAILMUNCH_VER', "1.0.9");
18
- define( 'MAILCHIMP_MAILMUNCH_URL', "www.mailmunch.co");
19
-
20
- // Create unique WordPress instance ID
21
- if (get_option("mc_mm_wordpress_instance_id") == "") {
22
- update_option("mc_mm_wordpress_instance_id", uniqid());
23
- }
24
-
25
- // Adding Admin Menu
26
- add_action( 'admin_menu', 'mc_mm_register_page' );
27
-
28
- function mc_mm_register_page(){
29
- add_options_page('MailChimp', 'MailChimp', 'manage_options', MAILCHIMP_MAILMUNCH_SLUG, 'mc_mm_setup');
30
- $menu_page = add_menu_page( 'MailChimp Settings', 'MailChimp', 'manage_options', MAILCHIMP_MAILMUNCH_SLUG, 'mc_mm_setup', plugins_url( 'img/icon.png', __FILE__ ), 103.786 );
31
- // If successful, load admin assets only on that page.
32
- if ($menu_page) add_action('load-' . $menu_page, 'mc_mm_load_plugin_assets');
33
- }
34
-
35
- function mc_mm_plugin_settings_link($links) {
36
- $settings_link = '<a href="options-general.php?page='.MAILCHIMP_MAILMUNCH_SLUG.'">Settings</a>';
37
- array_unshift($links, $settings_link);
38
- return $links;
39
- }
40
-
41
- $plugin = plugin_basename(__FILE__);
42
- add_filter('plugin_action_links_'.$plugin, 'mc_mm_plugin_settings_link');
43
-
44
- function mc_mm_load_plugin_assets() {
45
- add_action( 'admin_enqueue_scripts', 'mc_mm_enqueue_admin_styles' );
46
- add_action( 'admin_enqueue_scripts', 'mc_mm_enqueue_admin_scripts' );
47
- }
48
-
49
- function mc_mm_enqueue_admin_styles() {
50
- wp_enqueue_style(MAILCHIMP_MAILMUNCH_SLUG . '-admin-styles', plugins_url( 'css/admin.css', __FILE__ ), array(), MAILCHIMP_MAILMUNCH_VER );
51
- }
52
-
53
- function mc_mm_enqueue_admin_scripts() {
54
- wp_enqueue_script(MAILCHIMP_MAILMUNCH_SLUG . '-admin-script', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' ), MAILCHIMP_MAILMUNCH_VER );
55
- }
56
-
57
- // Adding MailMunch Asset Files (JS + CSS)
58
- function mc_mm_load_asset_code() {
59
- $mc_mm_data = unserialize(get_option("mc_mm_data"));
60
- if (!$mc_mm_data["script_src"]) return;
61
-
62
- if (is_single() || is_page()) {
63
- $post = get_post();
64
- $post_data = array("ID" => $post->ID, "post_name" => $post->post_name, "post_title" => $post->post_title, "post_type" => $post->post_type, "post_author" => $post->post_author, "post_status" => $post->post_status);
65
- }
66
-
67
- echo "<script type='text/javascript'>";
68
- echo "var _mmunch = {'front': false, 'page': false, 'post': false, 'category': false, 'author': false, 'search': false, 'attachment': false, 'tag': false};";
69
- if (is_front_page() || is_home()) { echo "_mmunch['front'] = true;"; }
70
- if (is_page()) { echo "_mmunch['page'] = true; _mmunch['pageData'] = ".json_encode($post_data).";"; }
71
- if (is_single()) { echo "_mmunch['post'] = true; _mmunch['postData'] = ".json_encode($post_data)."; _mmunch['postCategories'] = ".json_encode(get_the_category())."; _mmunch['postTags'] = ".json_encode(get_the_tags())."; _mmunch['postAuthor'] = ".json_encode(array("name" => get_the_author_meta("display_name"), "ID" => get_the_author_meta("ID"))).";"; }
72
- if (is_category()) { echo "_mmunch['category'] = true; _mmunch['categoryData'] = ".json_encode(get_category(get_query_var('cat'))).";"; }
73
- if (is_search()) { echo "_mmunch['search'] = true;"; }
74
- if (is_author()) { echo "_mmunch['author'] = true;"; }
75
- if (is_tag()) { echo "_mmunch['tag'] = true;"; }
76
- if (is_attachment()) { echo "_mmunch['attachment'] = true;"; }
77
- echo "</script>";
78
- echo('<script data-cfasync="false" src="//s3.amazonaws.com/mailmunch/static/site.js" id="mailmunch-script" data-mailmunch-site-id="'.$mc_mm_data["site_id"].'" async></script>');
79
- }
80
-
81
- add_action('init', 'mc_mm_assets');
82
-
83
- function mc_mm_assets() {
84
- $mc_mm_data = unserialize(get_option("mc_mm_data"));
85
- if (count($mc_mm_data) == 0) return;
86
-
87
- if (function_exists('wp_head')) {
88
- add_action( 'wp_head', 'mc_mm_load_asset_code' );
89
- }
90
- elseif (function_exists('wp_footer')) {
91
- add_action( 'wp_footer', 'mc_mm_load_asset_code' );
92
- }
93
- }
94
-
95
- function mc_mm_add_post_containers($content) {
96
- if (is_single() || is_page()) {
97
- $content = mc_mm_insert_form_after_paragraph("<div class='mailmunch-forms-in-post-middle' style='display: none !important;'></div>", "middle", $content);
98
- $content = "<div class='mailmunch-forms-before-post' style='display: none !important;'></div>" . $content . "<div class='mailmunch-forms-after-post' style='display: none !important;'></div>";
99
- }
100
-
101
- return $content;
102
- }
103
-
104
- function mc_mm_register_sidebar_widget() {
105
- register_widget( 'MC_MM_Sidebar_Widget' );
106
- }
107
- add_action( 'widgets_init', 'mc_mm_register_sidebar_widget' );
108
-
109
- function mc_mm_insert_form_after_paragraph($insertion, $paragraph_id, $content) {
110
- $closing_p = '</p>';
111
- $paragraphs = explode($closing_p, $content);
112
- if ($paragraph_id == "middle") {
113
- $paragraph_id = round(sizeof($paragraphs)/2);
114
- }
115
-
116
- foreach ($paragraphs as $index => $paragraph) {
117
- if (trim($paragraph)) {
118
- $paragraphs[$index] .= $closing_p;
119
- }
120
-
121
- if ($paragraph_id == $index + 1) {
122
- $paragraphs[$index] .= $insertion;
123
- }
124
- }
125
- return implode('', $paragraphs);
126
- }
127
-
128
- add_filter( 'the_content', 'mc_mm_add_post_containers' );
129
-
130
- function mc_mm_shortcode_form($atts) {
131
- return "<div class='mailmunch-forms-short-code mailmunch-forms-widget-".$atts['id']."' style='display: none !important;'></div>";
132
- }
133
-
134
- add_shortcode('mailmunch-form', 'mc_mm_shortcode_form');
135
-
136
- function mc_mm_setup() {
137
- $mm_helpers = new MailchimpMailmunchHelpers();
138
- $mc_mm_data = unserialize(get_option("mc_mm_data"));
139
- $mc_mm_data["site_url"] = home_url();
140
- $mc_mm_data["site_name"] = get_bloginfo();
141
- update_option("mc_mm_data", serialize($mc_mm_data));
142
-
143
- // This is a POST request. Let's save data first.
144
- if ($_POST) {
145
- $post_data = (isset($_POST["mc_mm_data"]) ? $_POST["mc_mm_data"] : array());
146
- $post_action = $_POST["action"];
147
-
148
- if ($post_action == "save_settings") {
149
-
150
- $mc_mm_data = array_merge(unserialize(get_option('mc_mm_data')), $post_data);
151
- update_option("mc_mm_data", serialize($mc_mm_data));
152
-
153
- } else if ($post_action == "sign_in") {
154
-
155
- $mm = new MailchimpMailmunchApi($_POST["email"], $_POST["password"], "http://".MAILCHIMP_MAILMUNCH_URL);
156
- if ($mm->validPassword()) {
157
- update_option("mc_mm_user_email", $_POST["email"]);
158
- update_option("mc_mm_user_password", base64_encode($_POST["password"]));
159
- delete_option("mc_mm_guest_user");
160
- }
161
-
162
- } else if ($post_action == "sign_up") {
163
-
164
- if (empty($_POST["email"]) || empty($_POST["password"])) {
165
- $invalid_email_password = true;
166
- } else {
167
- $account_info = $mm_helpers->getEmailPassword();
168
- $mc_mm_email = $account_info['email'];
169
- $mc_mm_password = $account_info['password'];
170
-
171
- $mm = new MailchimpMailmunchApi($mc_mm_email, $mc_mm_password, "http://".MAILCHIMP_MAILMUNCH_URL);
172
- if ($mm->isNewUser($_POST['email'])) {
173
- $update_result = $mm->updateGuest($_POST['email'], $_POST['password']);
174
- $result = json_decode($update_result['body']);
175
- update_option("mc_mm_user_email", $result->email);
176
- update_option("mc_mm_user_password", base64_encode($_POST['password']));
177
- if (!$result->guest_user) { delete_option("mc_mm_guest_user"); }
178
- $mc_mm_email = $result->email;
179
- $mc_mm_password = $_POST['password'];
180
-
181
- // We have update the guest with real email address, let's create a site now
182
- $mm = new MailchimpMailmunchApi($mc_mm_email, $mc_mm_password, "http://".MAILCHIMP_MAILMUNCH_URL);
183
-
184
- $update_result = $mm->updateSite($mc_mm_data["site_name"], $mc_mm_data["site_url"]);
185
- $result = json_decode($update_result['body']);
186
- $mc_mm_data = unserialize(get_option("mc_mm_data"));
187
- $mc_mm_data["site_url"] = $result->domain;
188
- $mc_mm_data["site_name"] = $result->name;
189
- update_option("mc_mm_data", serialize($mc_mm_data));
190
- } else {
191
- $user_exists = true;
192
- }
193
- }
194
-
195
- } else if ($post_action == "unlink_account") {
196
-
197
- $mc_mm_data = array();
198
- $mc_mm_data["site_url"] = home_url();
199
- $mc_mm_data["site_name"] = get_bloginfo();
200
- update_option("mc_mm_data", serialize($mc_mm_data));
201
- delete_option("mc_mm_user_email");
202
- delete_option("mc_mm_user_password");
203
-
204
- } else if ($post_action == "delete_widget") {
205
-
206
- if ($_POST["site_id"] && $_POST["widget_id"]) {
207
- $account_info = $mm_helpers->getEmailPassword();
208
- $mc_mm_email = $account_info['email'];
209
- $mc_mm_password = $account_info['password'];
210
- $mm = new MailchimpMailmunchApi($account_info['email'], $account_info["password"], "http://".MAILCHIMP_MAILMUNCH_URL);
211
- $request = $mm->deleteWidget($_POST["site_id"], $_POST["widget_id"]);
212
- }
213
-
214
- } else if ($post_action == "create_site") {
215
- $site_url = (empty($_POST["site_url"]) ? get_bloginfo() : $_POST["site_url"]);
216
- $site_name = (empty($_POST["site_name"]) ? home_url() : $_POST["site_name"]);
217
-
218
- $account_info = $mm_helpers->getEmailPassword();
219
- $mm = new MailchimpMailmunchApi($account_info['email'], $account_info["password"], "http://".MAILCHIMP_MAILMUNCH_URL);
220
- $request = $mm->createSite($site_name, $site_url);
221
- $site = json_decode($request['body']);
222
-
223
- if (!empty($site->id)) {
224
- $mc_mm_data = unserialize(get_option("mc_mm_data"));
225
- $mc_mm_data["site_id"] = $site->id;
226
- $mc_mm_data["script_src"] = $site->javascript_url;
227
- update_option("mc_mm_data", serialize($mc_mm_data));
228
- }
229
- }
230
- }
231
-
232
- // If the user does not exists, create a GUEST user
233
- if (get_option("mc_mm_user_email") == "") {
234
- $mc_mm_email = "guest_".uniqid()."@mailmunch.co";
235
- $mc_mm_password = uniqid();
236
- $mm = new MailchimpMailmunchApi($mc_mm_email, $mc_mm_password, "http://".MAILCHIMP_MAILMUNCH_URL);
237
- $mm->createGuestUser();
238
- update_option("mc_mm_user_email", $mc_mm_email);
239
- update_option("mc_mm_user_password", base64_encode($mc_mm_password));
240
- update_option("mc_mm_guest_user", true);
241
- }
242
-
243
- // If we already have the user's email stored, let's create the API instance
244
- // If we don't have it yet, make sure NOT to phone home any user data
245
- if (get_option("mc_mm_user_email") != "") {
246
- $account_info = $mm_helpers->getEmailPassword();
247
- $mc_mm_email = $account_info['email'];
248
- $mc_mm_password = $account_info['password'];
249
-
250
- $mm = new MailchimpMailmunchApi($mc_mm_email, $mc_mm_password, "http://".MAILCHIMP_MAILMUNCH_URL);
251
- $pass_check = $mm->validPassword();
252
-
253
- if( is_wp_error( $pass_check ) ) {
254
- echo $pass_check->get_error_message();
255
- return;
256
- }
257
-
258
- if (!$pass_check) {
259
- // Invalid user, create a GUEST user
260
- $mc_mm_email = "guest_".uniqid()."@mailmunch.co";
261
- $mc_mm_password = uniqid();
262
- $mm = new MailchimpMailmunchApi($mc_mm_email, $mc_mm_password, "http://".MAILCHIMP_MAILMUNCH_URL);
263
- $mm->createGuestUser();
264
- update_option("mc_mm_user_email", $mc_mm_email);
265
- update_option("mc_mm_user_password", base64_encode($mc_mm_password));
266
- update_option("mc_mm_guest_user", true);
267
- }
268
- }
269
-
270
- $mc_mm_guest_user = get_option("mc_mm_guest_user");
271
-
272
-
273
- if ($mc_mm_guest_user) {
274
- // This is a Guest USER. Do not collect any user data.
275
- $sites = $mm_helpers->createAndGetGuestSites($mm);
276
- } else {
277
- $sites = $mm_helpers->createAndGetSites($mm);
278
- }
279
-
280
- if (isset($mc_mm_data["site_id"])) {
281
- // If there's a site already chosen, we need to get and save it's script_src in WordPress
282
- $site = $mm_helpers->getSite($sites, $mc_mm_data["site_id"]);
283
-
284
- if ($site) {
285
- $mc_mm_data = array_merge(unserialize(get_option('mc_mm_data')), array("script_src" => $site->javascript_url));
286
- update_option("mc_mm_data", serialize($mc_mm_data));
287
- } else {
288
- // The chosen site does not exist in the mailmunch account any more, remove it locally
289
- $site_not_found = true;
290
- $mc_mm_data = unserialize(get_option('mc_mm_data'));
291
- unset($mc_mm_data["site_id"]);
292
- unset($mc_mm_data["script_src"]);
293
- update_option("mc_mm_data", serialize($mc_mm_data));
294
- }
295
- }
296
-
297
- if (!isset($mc_mm_data["site_id"])) {
298
- // If there's NO chosen site yet
299
-
300
- if (sizeof($sites) == 1 && ($sites[0]->name == get_bloginfo() || $sites[0]->name == "WordPress")) {
301
- // If this mailmunch account only has 1 site and its name matches this WordPress blogs
302
-
303
- $site = $sites[0];
304
-
305
- if ($site) {
306
- $mc_mm_data = array_merge(unserialize(get_option('mc_mm_data')), array("site_id" => $site->id, "script_src" => $site->javascript_url));
307
- update_option("mc_mm_data", serialize($mc_mm_data));
308
- }
309
- } else if (sizeof($sites) > 0) {
310
- // If this mailmunch account has one or more sites, let the user choose one
311
- ?>
312
- <div class="container">
313
- <div class="page-header">
314
- <h1>Choose Your Site</h1>
315
- </div>
316
-
317
- <p>Choose the site that you would like to link with your WordPress.</p>
318
-
319
- <div id="choose-site-form">
320
- <form action="" method="POST">
321
- <div class="form-group">
322
- <input type="hidden" name="action" value="save_settings" />
323
-
324
- <select name="mc_mm_data[site_id]">
325
- <?php foreach ($sites as $site) { ?>
326
- <option value="<?php echo $site->id ?>"><?php echo $site->name ?></option>
327
- <?php } ?>
328
- </select>
329
- </div>
330
-
331
- <div class="form-group">
332
- <input type="submit" value="Save Settings" class="button-primary" />
333
- </div>
334
- </form>
335
-
336
- <p>
337
- Don't see this site above? <a href="" onclick="document.getElementById('create-site-form').style.display = 'block'; document.getElementById('choose-site-form').style.display = 'none'; return false;">Create New Site</a>
338
- </p>
339
- </div>
340
-
341
- <div id="create-site-form" style="display: none;">
342
- <form action="" method="POST">
343
- <input type="hidden" name="action" value="create_site" />
344
-
345
- <div class="form-group">
346
- <label>Site Name</label>
347
- <input type="text" name="site_name" value="<?php echo get_bloginfo() ?>" />
348
- </div>
349
-
350
- <div class="form-group">
351
- <label>Site URL</label>
352
- <input type="text" name="site_url" value="<?php echo home_url() ?>" />
353
- </div>
354
-
355
- <div class="form-group">
356
- <input type="submit" value="Create Site" class="button-primary" />
357
- </div>
358
- </form>
359
-
360
- <p>
361
- Already have a site in your MailMunch account? <a href="" onclick="document.getElementById('create-site-form').style.display = 'none'; document.getElementById('choose-site-form').style.display = 'block'; return false;">Choose Site</a>
362
- </p>
363
- </div>
364
- </div>
365
- <?php
366
- return;
367
- }
368
- }
369
-
370
- $request = $mm->getWidgetsHtml($mc_mm_data["site_id"]);
371
- $widgets = $request['body'];
372
- $widgets = str_replace("{{EMAIL}}", $mc_mm_email, $widgets);
373
- $widgets = str_replace("{{PASSWORD}}", $mc_mm_password, $widgets);
374
- echo $widgets;
375
-
376
- if ($mc_mm_guest_user) {
377
- $current_user = wp_get_current_user();
378
- ?>
379
-
380
- <div id="signup-signin-box-overlay" onclick="hideSignupBox();" style="display: none;"></div>
381
-
382
- <div id="signup-signin-box" style="display:none;">
383
- <a id="signup-signin-close" onclick="hideSignupBox();">
384
- <img src="<?php echo plugins_url( 'img/close.png', __FILE__ ) ?>" />
385
- </a>
386
-
387
- <div id="sign-up-form" class="<?php if (!$_POST || ($_POST["action"] != "sign_in" && $_POST["action"] != "unlink_account")) { ?> active<?php } ?>">
388
- <div class="form-container">
389
- <h2 class="modal-header">Sign Up</h2>
390
- <p>To activate your MailChimp forms, we will now create your account on MailMunch (<a onclick="showWhyAccount();" id="why-account-btn">Why?</a>).</p>
391
-
392
- <div id="why-account" class="alert alert-warning" style="display: none;">
393
- <h4>Why do I need a MailMunch account?</h4>
394
-
395
- <p>
396
- MailMunch is a not just a WordPress plugin but a standalone service. An account is required to identify your WordPress and serve your MailChimp forms.
397
- </p>
398
- </div>
399
-
400
- <?php if (isset($user_exists)) { ?>
401
- <div id="invalid-alert" class="alert alert-danger signup-alert" role="alert">Account with this email already exists. Please sign in using your password.</div>
402
- <?php } else if (isset($invalid_email_password)) { ?>
403
- <div id="invalid-alert" class="alert alert-danger signup-alert" role="alert">Invalid email or password. Please enter a valid email and password below.</div>
404
- <?php } ?>
405
-
406
- <form action="" method="POST">
407
- <input type="hidden" name="action" value="sign_up" />
408
-
409
- <div class="form-group">
410
- <label>Wordpress Name</label>
411
- <input type="text" placeholder="Site Name" name="site_name" value="<?php echo $mc_mm_data["site_name"] ?>" class="form-control">
412
- </div>
413
-
414
- <div class="form-group">
415
- <label>Wordpress URL</label>
416
- <input type="text" placeholder="Site URL" name="site_url" value="<?php echo $mc_mm_data["site_url"] ?>" class="form-control">
417
- </div>
418
-
419
- <div class="form-group">
420
- <label>Email Address</label>
421
- <input type="email" placeholder="Email Address" name="email" value="<?php echo $current_user->user_email ?>" class="form-control">
422
- </div>
423
-
424
- <div class="form-group">
425
- <label>Password</label>
426
- <input type="password" placeholder="Password" name="password" class="form-control" />
427
- </div>
428
-
429
- <div class="form-group">
430
- <input type="submit" value="Sign Up &raquo;" class="btn btn-success btn-lg" />
431
- </div>
432
- </form>
433
- </div>
434
-
435
- <p>Already have an account? <a id="show-sign-in" onclick="showSignInForm();">Sign In</a></p>
436
- </div>
437
-
438
- <div id="sign-in-form" class="<?php if ($_POST && ($_POST["action"] == "sign_in" || $_POST["action"] == "unlink_account")) { ?> active<?php } ?>">
439
- <h2 class="modal-header">Sign In</h2>
440
- <p>Sign in using your email and password below.</p>
441
-
442
- <?php if ($_POST && $_POST["action"] == "sign_in") { ?>
443
- <div id="invalid-alert" class="alert alert-danger signin-alert" role="alert">Invalid Email or Password. Please try again.</div>
444
- <?php } ?>
445
-
446
- <div class="form-container">
447
- <form action="" method="POST">
448
- <input type="hidden" name="action" value="sign_in" />
449
-
450
- <div class="form-group">
451
- <label>Email Address</label>
452
- <input type="email" placeholder="Email Address" name="email" class="form-control" value="<?php if (isset($_POST["email"])) { echo $_POST["email"]; } ?>" />
453
- </div>
454
- <div class="form-group">
455
- <label>Password</label>
456
- <input type="password" placeholder="Password" name="password" class="form-control" />
457
- </div>
458
-
459
- <div class="form-group">
460
- <input type="submit" value="Sign In &raquo;" class="btn btn-success btn-lg" />
461
- </div>
462
- </form>
463
- </div>
464
-
465
- <p>Forgot your password? <a href="http://<?php echo MAILCHIMP_MAILMUNCH_URL; ?>/users/password/new" target="_blank">Click here</a> to retrieve it.</p>
466
- <p>Don't have an account? <a id="show-sign-up" onclick="showSignUpForm();">Sign Up</a></p>
467
- </div>
468
- </div>
469
-
470
- <?php
471
- if ($_POST) {
472
- ?>
473
- <script>
474
- jQuery(window).load(function() {
475
- <?php if ($_POST && ($_POST["action"] == "sign_in" || $_POST["action"] == "unlink_account")) { ?>
476
- showSignInForm();
477
- <?php } else { ?>
478
- showSignUpForm();
479
- <?php } ?>
480
- });
481
- </script>
482
- <?php
483
- }
484
- }
485
- }
1
  <?php
 
 
 
 
 
 
 
 
 
2
 
3
+ /**
4
+ * The plugin bootstrap file
5
+ *
6
+ * This file is read by WordPress to generate the plugin information in the plugin
7
+ * admin area. This file also includes all of the dependencies used by the plugin,
8
+ * registers the activation and deactivation functions, and defines a function
9
+ * that starts the plugin.
10
+ *
11
+ * @link http://www.mailmunch.co
12
+ * @since 2.0.0
13
+ * @package Mailchimp_Mailmunch
14
+ *
15
+ * @wordpress-plugin
16
+ * Plugin Name: MailChimp Forms by MailMunch
17
+ * Plugin URI: http://connect.mailchimp.com/integrations/mailmunch-email-list-builder
18
+ * Description: The MailChimp plugin allows you to quickly and easily add signup forms for your MailChimp lists. Popup, Embedded, Top Bar and a variety of different options available.
19
+ * Version: 2.0.0
20
+ * Author: MailMunch
21
+ * Author URI: http://www.mailmunch.co
22
+ * License: GPL-2.0+
23
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
24
+ * Text Domain: mailchimp-mailmunch
25
+ * Domain Path: /languages
26
+ */
27
+
28
+ // If this file is called directly, abort.
29
+ if ( ! defined( 'WPINC' ) ) {
30
+ die;
31
+ }
32
+
33
+ /**
34
+ * The code that runs during plugin activation.
35
+ * This action is documented in includes/class-mailchimp-mailmunch-activator.php
36
+ */
37
+ function activate_mailchimp_mailmunch() {
38
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-mailchimp-mailmunch-activator.php';
39
+ Mailchimp_Mailmunch_Activator::activate();
40
+ }
41
+
42
+ /**
43
+ * The code that runs during plugin deactivation.
44
+ * This action is documented in includes/class-mailchimp-mailmunch-deactivator.php
45
+ */
46
+ function deactivate_mailchimp_mailmunch() {
47
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-mailchimp-mailmunch-deactivator.php';
48
+ Mailchimp_Mailmunch_Deactivator::deactivate();
49
+ }
50
+
51
+ register_activation_hook( __FILE__, 'activate_mailchimp_mailmunch' );
52
+ register_deactivation_hook( __FILE__, 'deactivate_mailchimp_mailmunch' );
53
+
54
+ /**
55
+ * The core plugin class that is used to define internationalization,
56
+ * admin-specific hooks, and public-facing site hooks.
57
+ */
58
+ require plugin_dir_path( __FILE__ ) . 'includes/class-mailchimp-mailmunch.php';
59
+
60
+ /**
61
+ * Begins execution of the plugin.
62
+ *
63
+ * Since everything within the plugin is registered via hooks,
64
+ * then kicking off the plugin from this point in the file does
65
+ * not affect the page life cycle.
66
+ *
67
+ * @since 2.0.0
68
+ */
69
+ function run_mailchimp_mailmunch() {
70
+
71
+ $plugin = new Mailchimp_Mailmunch();
72
+ $plugin->run();
73
+
74
+ }
75
+ run_mailchimp_mailmunch();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
public/class-mailchimp-mailmunch-public.php ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * The public-facing functionality of the plugin.
5
+ *
6
+ * @link http://www.mailmunch.co
7
+ * @since 2.0.0
8
+ *
9
+ * @package Mailchimp_Mailmunch
10
+ * @subpackage Mailchimp_Mailmunch/public
11
+ */
12
+
13
+ /**
14
+ * The public-facing functionality of the plugin.
15
+ *
16
+ * Defines the plugin name, version, and two examples hooks for how to
17
+ * enqueue the admin-specific stylesheet and JavaScript.
18
+ *
19
+ * @package Mailchimp_Mailmunch
20
+ * @subpackage Mailchimp_Mailmunch/public
21
+ * @author MailMunch <info@mailmunch.co>
22
+ */
23
+ class Mailchimp_Mailmunch_Public {
24
+
25
+ /**
26
+ * The ID of this plugin.
27
+ *
28
+ * @since 2.0.0
29
+ * @access private
30
+ * @var string $plugin_name The ID of this plugin.
31
+ */
32
+ private $plugin_name;
33
+
34
+ /**
35
+ * The version of this plugin.
36
+ *
37
+ * @since 2.0.0
38
+ * @access private
39
+ * @var string $version The current version of this plugin.
40
+ */
41
+ private $version;
42
+
43
+ /**
44
+ * Initialize the class and set its properties.
45
+ *
46
+ * @since 2.0.0
47
+ * @param string $plugin_name The name of the plugin.
48
+ * @param string $version The version of this plugin.
49
+ */
50
+ public function __construct( $plugin_name, $version ) {
51
+
52
+ $this->plugin_name = $plugin_name;
53
+ $this->version = $version;
54
+
55
+ }
56
+
57
+ /**
58
+ * Register the stylesheets for the public-facing side of the site.
59
+ *
60
+ * @since 2.0.0
61
+ */
62
+ public function enqueue_styles() {
63
+
64
+ /**
65
+ * This function is provided for demonstration purposes only.
66
+ *
67
+ * An instance of this class should be passed to the run() function
68
+ * defined in Mailchimp_Mailmunch_Loader as all of the hooks are defined
69
+ * in that particular class.
70
+ *
71
+ * The Mailchimp_Mailmunch_Loader will then create the relationship
72
+ * between the defined hooks and the functions defined in this
73
+ * class.
74
+ */
75
+
76
+ }
77
+
78
+ /**
79
+ * Register the stylesheets for the public-facing side of the site.
80
+ *
81
+ * @since 2.0.0
82
+ */
83
+ public function enqueue_scripts() {
84
+
85
+ /**
86
+ * This function is provided for demonstration purposes only.
87
+ *
88
+ * An instance of this class should be passed to the run() function
89
+ * defined in Mailchimp_Mailmunch_Loader as all of the hooks are defined
90
+ * in that particular class.
91
+ *
92
+ * The Mailchimp_Mailmunch_Loader will then create the relationship
93
+ * between the defined hooks and the functions defined in this
94
+ * class.
95
+ */
96
+
97
+ $siteID = get_option(MAILCHIMP_MAILMUNCH_PREFIX. '_site_id');
98
+
99
+ if (is_single() || is_page()) {
100
+ $post = get_post();
101
+ $post_data = array("ID" => $post->ID, "post_name" => $post->post_name, "post_title" => $post->post_title, "post_type" => $post->post_type, "post_author" => $post->post_author, "post_status" => $post->post_status);
102
+ }
103
+
104
+ echo "<script type='text/javascript' data-cfasync='false'>";
105
+ echo "var _mmunch = {'front': false, 'page': false, 'post': false, 'category': false, 'author': false, 'search': false, 'attachment': false, 'tag': false};";
106
+ if (is_front_page() || is_home()) { echo "_mmunch['front'] = true;"; }
107
+ if (is_page()) { echo "_mmunch['page'] = true; _mmunch['pageData'] = ".json_encode($post_data).";"; }
108
+ if (is_single()) { echo "_mmunch['post'] = true; _mmunch['postData'] = ".json_encode($post_data)."; _mmunch['postCategories'] = ".json_encode(get_the_category())."; _mmunch['postTags'] = ".json_encode(get_the_tags())."; _mmunch['postAuthor'] = ".json_encode(array("name" => get_the_author_meta("display_name"), "ID" => get_the_author_meta("ID"))).";"; }
109
+ if (is_category()) { echo "_mmunch['category'] = true; _mmunch['categoryData'] = ".json_encode(get_category(get_query_var('cat'))).";"; }
110
+ if (is_search()) { echo "_mmunch['search'] = true;"; }
111
+ if (is_author()) { echo "_mmunch['author'] = true;"; }
112
+ if (is_tag()) { echo "_mmunch['tag'] = true;"; }
113
+ if (is_attachment()) { echo "_mmunch['attachment'] = true;"; }
114
+ echo "</script>";
115
+ echo('<script data-cfasync="false" src="//s3.amazonaws.com/mailmunch/static/site.js" id="mailmunch-script" data-mailmunch-site-id="'.$siteID.'" async></script>');
116
+
117
+ }
118
+
119
+ /**
120
+ * Adds MailMunch form container in middle of paragraphs
121
+ *
122
+ * @since 2.0.0
123
+ */
124
+ function insert_form_after_paragraph($insertion, $paragraph_id, $content) {
125
+ $closing_p = '</p>';
126
+ $paragraphs = explode($closing_p, $content);
127
+ if ($paragraph_id == "middle") {
128
+ $paragraph_id = round(sizeof($paragraphs)/2);
129
+ }
130
+
131
+ foreach ($paragraphs as $index => $paragraph) {
132
+ if (trim($paragraph)) {
133
+ $paragraphs[$index] .= $closing_p;
134
+ }
135
+
136
+ if ($paragraph_id == $index + 1) {
137
+ $paragraphs[$index] .= $insertion;
138
+ }
139
+ }
140
+ return implode('', $paragraphs);
141
+ }
142
+
143
+ /**
144
+ * Adds post containers for before, after and in the middle of post
145
+ *
146
+ * @since 2.0.0
147
+ */
148
+ public function add_post_containers($content) {
149
+ if (is_single() || is_page()) {
150
+ $content = $this->insert_form_after_paragraph("<div class='mailmunch-forms-in-post-middle' style='display: none !important;'></div>", "middle", $content);
151
+ $content = "<div class='mailmunch-forms-before-post' style='display: none !important;'></div>" . $content . "<div class='mailmunch-forms-after-post' style='display: none !important;'></div>";
152
+ }
153
+
154
+ return $content;
155
+ }
156
+
157
+ }
public/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
public/partials/mailchimp-mailmunch-public-display.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Provide a public-facing view for the plugin
5
+ *
6
+ * This file is used to markup the public-facing aspects of the plugin.
7
+ *
8
+ * @link http://www.mailmunch.co
9
+ * @since 2.0.0
10
+ *
11
+ * @package Mailchimp_Mailmunch
12
+ * @subpackage Mailchimp_Mailmunch/public/partials
13
+ */
14
+ ?>
15
+
16
+ <!-- This file should primarily consist of HTML with a little bit of PHP. -->
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: mailchimp,mailchimp form,mailchimp newsletter,mailchimp plugin,newsletter,
4
 
5
  Requires at least: 3.0.1
6
  Tested up to: 4.2
7
- Stable tag: 1.0.9
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
4
 
5
  Requires at least: 3.0.1
6
  Tested up to: 4.2
7
+ Stable tag: 2.0.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
uninstall.php CHANGED
@@ -1,9 +1,37 @@
1
  <?php
2
- if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
3
- exit();
4
 
5
- delete_option("mc_mm_data");
6
- delete_option("mc_mm_user_email");
7
- delete_option("mc_mm_user_password");
8
- delete_option("mc_mm_guest_user");
9
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
 
 
2
 
3
+ /**
4
+ * Fired when the plugin is uninstalled.
5
+ *
6
+ * When populating this file, consider the following flow
7
+ * of control:
8
+ *
9
+ * - This method should be static
10
+ * - Check if the $_REQUEST content actually is the plugin name
11
+ * - Run an admin referrer check to make sure it goes through authentication
12
+ * - Verify the output of $_GET makes sense
13
+ * - Repeat with other user roles. Best directly by using the links/query string parameters.
14
+ * - Repeat things for multisite. Once for a single site in the network, once sitewide.
15
+ *
16
+ * This file may be updated more in future version of the Boilerplate; however, this is the
17
+ * general skeleton and outline for how the file should work.
18
+ *
19
+ * For more information, see the following discussion:
20
+ * https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
21
+ *
22
+ * @link http://www.mailmunch.co
23
+ * @since 2.0.0
24
+ *
25
+ * @package Mailchimp_Mailmunch
26
+ */
27
+
28
+ // If uninstall not called from WordPress, then exit.
29
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
30
+ exit;
31
+ }
32
+
33
+ delete_option('mc_mm_user_token');
34
+ delete_option('mc_mm_site_id');
35
+ delete_option('mc_mm_mailchimp_access_token');
36
+ delete_option('mc_mm_mailchimp_list_id');
37
+ delete_option('mc_mm_skip_onboarding');