MailMunch – Grow your Email List - Version 2.0.0

Version Description

Download this release

Release Info

Developer mailmunch
Plugin Icon 128x128 MailMunch – Grow your Email List
Version 2.0.0
Comparing to
See all releases

Code changes from version 1.4.4 to 2.0.0

admin/class-mailmunch-admin.php ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Mailmunch
10
+ * @subpackage 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 Mailmunch
20
+ * @subpackage Mailmunch/admin
21
+ * @author MailMunch <info@mailmunch.co>
22
+ */
23
+ class 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
+ }
68
+
69
+ /**
70
+ * Register the stylesheets for the admin area.
71
+ *
72
+ * @since 2.0.0
73
+ */
74
+ public function enqueue_styles() {
75
+
76
+ /**
77
+ * This function is provided for demonstration purposes only.
78
+ *
79
+ * An instance of this class should be passed to the run() function
80
+ * defined in Mailmunch_Loader as all of the hooks are defined
81
+ * in that particular class.
82
+ *
83
+ * The Mailmunch_Loader will then create the relationship
84
+ * between the defined hooks and the functions defined in this
85
+ * class.
86
+ */
87
+
88
+ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/mailmunch-admin.css', array(), $this->version, 'all' );
89
+
90
+ }
91
+
92
+ /**
93
+ * Register the JavaScript for the admin area.
94
+ *
95
+ * @since 2.0.0
96
+ */
97
+ public function enqueue_scripts() {
98
+
99
+ /**
100
+ * This function is provided for demonstration purposes only.
101
+ *
102
+ * An instance of this class should be passed to the run() function
103
+ * defined in Mailmunch_Loader as all of the hooks are defined
104
+ * in that particular class.
105
+ *
106
+ * The Mailmunch_Loader will then create the relationship
107
+ * between the defined hooks and the functions defined in this
108
+ * class.
109
+ */
110
+
111
+ wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/mailmunch-admin.js', array( 'jquery' ), $this->version, false );
112
+
113
+ }
114
+
115
+ public function sign_up() {
116
+ $this->initiate_api();
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
+ $this->initiate_api();
125
+ $email = $_POST['email'];
126
+ $password = $_POST['password'];
127
+ echo json_encode($this->mailmunch_api->signInUser($email, $password));
128
+ exit;
129
+ }
130
+
131
+ public function delete_widget() {
132
+ $this->initiate_api();
133
+ echo json_encode($this->mailmunch_api->deleteWidget($_POST['widget_id']));
134
+ exit;
135
+ }
136
+
137
+ /**
138
+ * Register menu for the admin area
139
+ *
140
+ * @since 2.0.0
141
+ */
142
+ public function menu() {
143
+ add_options_page( $this->integration_name, $this->integration_name, 'manage_options', MAILMUNCH_SLUG, array($this, 'get_dashboard_html'));
144
+ add_menu_page( $this->integration_name, $this->integration_name, 'manage_options', MAILMUNCH_SLUG, array($this, 'get_dashboard_html'), plugins_url( 'img/icon.png', __FILE__ ), 105.786);
145
+
146
+ add_submenu_page( MAILMUNCH_SLUG, $this->integration_name, 'Forms', 'manage_options', MAILMUNCH_SLUG, array($this, 'get_dashboard_html') );
147
+ add_submenu_page( MAILMUNCH_SLUG, $this->integration_name. ' Settings', 'Settings', 'manage_options', MAILMUNCH_SLUG. '-settings', array($this, 'settings_page') );
148
+ }
149
+
150
+ /**
151
+ * Activation notice for admin area
152
+ *
153
+ * @since 2.0.8
154
+ */
155
+ function activation_notice() {
156
+ $current_screen = get_current_screen();
157
+ $siteId = get_option(MAILMUNCH_PREFIX. '_'. 'site_id');
158
+
159
+ if (empty($siteId) && strpos($current_screen->id, MAILMUNCH_SLUG) == false) {
160
+ echo '<div class="updated"><p>'.$this->plugin_name.' is activated. <a href="admin.php?page='.MAILMUNCH_SLUG.'">Click here</a> to create your first form.</p></div>';
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Adds settings link for plugin
166
+ *
167
+ * @since 2.0.0
168
+ */
169
+ public function settings_link($links) {
170
+ $settings_link = '<a href="admin.php?page='.MAILMUNCH_SLUG.'">Settings</a>';
171
+ array_unshift($links, $settings_link);
172
+ return $links;
173
+ }
174
+
175
+ public function initiate_api() {
176
+ if (empty($this->mailmunch_api)) {
177
+ $this->mailmunch_api = new Mailmunch_Api();
178
+ }
179
+ return $this->mailmunch_api;
180
+ }
181
+
182
+ /**
183
+ * Settings Page
184
+ *
185
+ * @since 2.0.8
186
+ */
187
+ public function settings_page() {
188
+ $this->initiate_api();
189
+ if ($_POST) {
190
+ $this->mailmunch_api->setSetting('auto_embed', $_POST['auto_embed']);
191
+ }
192
+ require_once(plugin_dir_path(__FILE__) . 'partials/mailmunch-settings.php');
193
+ }
194
+
195
+ public function init() {
196
+ $step = isset($_GET['step']) ? $_GET['step'] : '';
197
+ if ($step == 'sign_out') {
198
+ $this->initiate_api();
199
+ $this->mailmunch_api->signOutUser();
200
+ $url = admin_url('admin.php?page='. MAILMUNCH_SLUG);
201
+ wp_redirect($url);
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Get Dashboard HTML
207
+ *
208
+ * @since 2.0.0
209
+ */
210
+ public function get_dashboard_html() {
211
+ $this->initiate_api();
212
+ require_once(plugin_dir_path( __FILE__ ) . 'partials/mailmunch-admin-display.php');
213
+ require_once(plugin_dir_path( __FILE__ ) . 'partials/mailmunch-modals.php');
214
+ }
215
+
216
+ }
css/admin.css → admin/css/mailmunch-admin.css RENAMED
@@ -1,3 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #signup-signin-box-overlay {
2
  background-color: #000;
3
  opacity: 0.8;
@@ -41,6 +149,10 @@
41
  display: none;
42
  }
43
 
 
 
 
 
44
  #sign-in-form.active, #sign-up-form.active {
45
  display: block;
46
  }
@@ -67,67 +179,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
+ .settings-table .inside-container p {
49
+ font-size: 11px;
50
+ padding: 0px 12px;
51
+ color: #999;
52
+ }
53
+
54
+ .settings-table .button {
55
+ margin: 0px 12px 12px;
56
+ }
57
+
58
+ .mailmunch-status {
59
+ margin-bottom: 15px;
60
+ }
61
+
62
+ .mailmunch-status div {
63
+ font-weight: bold;
64
+ color: green;
65
+ margin-top: -10px;
66
+ }
67
+
68
+ .inside-container {
69
+ padding: 20px;
70
+ }
71
+
72
+ .inside-container .skip-link-container {
73
+ margin-bottom: 25px;
74
+ }
75
+
76
+ .integrate-step .inside-container .skip-link-container {
77
+ margin-top: 25px;
78
+ }
79
+
80
+ .video-trigger img {
81
+ width: 100%;
82
+ max-width: 100%;
83
+ cursor: pointer;
84
+ }
85
+
86
+ #mailmunch-demo-video {
87
+ position: fixed;
88
+ width: 100%;
89
+ height: 100%;
90
+ background-color: rgba(0,0,0,0.8);
91
+ z-index: 10000;
92
+ left: 0;
93
+ top: 0;
94
+ text-align: center;
95
+ padding-top: 100px;
96
+ display: none;
97
+ }
98
+
99
+ #mailmunch-demo-video a {
100
+ display: block;
101
+ text-align: center;
102
+ color: #FFF;
103
+ margin-top: 10px;
104
+ font-weight: bold;
105
+ font-size: 20px;
106
+ cursor: pointer;
107
+ }
108
+
109
  #signup-signin-box-overlay {
110
  background-color: #000;
111
  opacity: 0.8;
149
  display: none;
150
  }
151
 
152
+ #sign-in-form .signin-alert, #sign-up-form .signup-alert {
153
+ display: none;
154
+ }
155
+
156
  #sign-in-form.active, #sign-up-form.active {
157
  display: block;
158
  }
179
  cursor: pointer;
180
  }
181
 
 
 
 
 
 
182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
 
184
 
185
  /* Style Guide */
admin/img/check.png ADDED
Binary file
{img → admin/img}/close.png RENAMED
File without changes
admin/img/icon.png ADDED
Binary file
admin/img/loader.gif 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/mailmunch-admin.js ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $('.delete-widget').click(function() {
34
+ if (!confirm('Are you sure you want to delete this optin form?')) return false;
35
+ $.ajax({
36
+ url: ajaxurl,
37
+ type: 'POST',
38
+ data: {action: 'delete_widget', widget_id: $(this).data('widget-id')},
39
+ dataType: 'json',
40
+ success: function(data) {
41
+ if (data.success) {
42
+ $(this).parents('tr').slideUp();
43
+ }
44
+ else {
45
+ alert('There was an error. Please try again later.');
46
+ }
47
+ }.bind(this),
48
+ error: function(data) {
49
+ alert('There was an error. Please try again later.');
50
+ }
51
+ })
52
+ return false;
53
+ })
54
+
55
+ $('#signup_form').submit(function(e) {
56
+ e.preventDefault();
57
+
58
+ var data = {
59
+ email: $(this).find('input[name=email]').val(),
60
+ password: $(this).find('input[name=password]').val(),
61
+ site_name: $(this).find('input[name=site_name]').val(),
62
+ site_url: $(this).find('input[name=site_url]').val(),
63
+ action: 'sign_up',
64
+ };
65
+
66
+ $.ajax({
67
+ url: ajaxurl,
68
+ type: 'POST',
69
+ data: data,
70
+ dataType: 'json',
71
+ beforeSend: function() {
72
+ $('.signup-alert').hide();
73
+ },
74
+ success: function(data) {
75
+ if (!data.success) {
76
+ $('.signup-alert').html(data.message).show();
77
+ } else {
78
+ window.location.reload();
79
+ }
80
+ },
81
+ error: function(data) {
82
+ alert('There was an error. Please try again later.');
83
+ }
84
+ })
85
+ return false;
86
+ })
87
+
88
+ $('#signin_form').submit(function(e) {
89
+ e.preventDefault();
90
+
91
+ var data = {
92
+ email: $(this).find('input[name=email]').val(),
93
+ password: $(this).find('input[name=password]').val(),
94
+ action: 'sign_in',
95
+ };
96
+
97
+ $.ajax({
98
+ url: ajaxurl,
99
+ type: 'POST',
100
+ data: data,
101
+ dataType: 'json',
102
+ beforeSend: function() {
103
+ $('.signin-alert').hide();
104
+ },
105
+ success: function(data) {
106
+ if (!data.success) {
107
+ $('.signin-alert').html(data.message).show();
108
+ } else {
109
+ window.location.reload();
110
+ }
111
+ },
112
+ error: function(data) {
113
+ alert('There was an error. Please try again later.');
114
+ }
115
+ })
116
+ return false;
117
+ })
118
+
119
+ });
120
+
121
+ })( jQuery );
122
+
123
+ function showVideo() {
124
+ 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>';
125
+ document.getElementById('mailmunch-demo-video').style.display = 'block';
126
+ }
127
+
128
+ function hideVideo() {
129
+ document.getElementById('mailmunch-demo-video').innerHTML = "";
130
+ document.getElementById('mailmunch-demo-video').style.display = 'none';
131
+ }
132
+
133
+ window.onmessage = function (e) {
134
+ if (e.data === 'refresh') {
135
+ top.location.reload();
136
+ }
137
+ };
138
+
139
+ function repositionSignupBox() {
140
+ divId = 'signup-signin-box';
141
+ var divWidth, divHeight;
142
+ var objDiv = document.getElementById(divId);
143
+
144
+ if (objDiv.clientWidth) {
145
+ divWidth = objDiv.clientWidth;
146
+ divHeight = objDiv.clientHeight;
147
+ }
148
+ else if (objDiv.offsetWidth)
149
+ {
150
+ divWidth = objDiv.offsetWidth;
151
+ divHeight = objDiv.offsetHeight;
152
+ }
153
+
154
+ // Get the x and y coordinates of the center in output browser's window
155
+ var centerX, centerY;
156
+ if (window.innerHeight)
157
+ {
158
+ centerX = window.innerWidth;
159
+ centerY = window.innerHeight;
160
+ }
161
+ else if (document.documentElement && document.documentElement.clientHeight)
162
+ {
163
+ centerX = document.documentElement.clientWidth;
164
+ centerY = document.documentElement.clientHeight;
165
+ }
166
+ else if (document.body)
167
+ {
168
+ centerX = document.body.clientWidth;
169
+ centerY = document.body.clientHeight;
170
+ }
171
+
172
+ var offsetLeft = (centerX - divWidth) / 2;
173
+ var offsetTop = (centerY - divHeight) / 2;
174
+
175
+ objDiv.style.top = offsetTop + 'px';
176
+ objDiv.style.left = offsetLeft + 'px';
177
+ }
178
+
179
+ function showSignInForm() {
180
+ document.getElementById("sign-up-form").style.display = 'none';
181
+ document.getElementById("sign-in-form").style.display = 'block';
182
+ document.getElementById('why-account').style.display = 'none';
183
+ showSignupBox();
184
+ }
185
+
186
+ function showSignUpForm() {
187
+ document.getElementById("sign-in-form").style.display = 'none';
188
+ document.getElementById("sign-up-form").style.display = 'block';
189
+ document.getElementById('why-account').style.display = 'none';
190
+ showSignupBox();
191
+ }
192
+
193
+ function showSignupBox(width, height) {
194
+ document.getElementById("signup-signin-box-overlay").style.display = 'block';
195
+ document.getElementById("signup-signin-box").style.display = 'block';
196
+ repositionSignupBox();
197
+
198
+ return false;
199
+ }
200
+
201
+ function hideSignupBox() {
202
+ document.getElementById("signup-signin-box-overlay").style.display = 'none';
203
+ document.getElementById("signup-signin-box").style.display = 'none';
204
+ }
205
+
206
+ function showWhyAccount() {
207
+ document.getElementById('why-account').style.display = 'block';
208
+ repositionSignupBox();
209
+ }
admin/partials/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 Mailmunch
12
+ * @subpackage 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/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 MailMunch 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 MailMunch 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 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>
admin/partials/mailmunch-settings.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <form method="POST" id="mailmunch-settings">
2
+ <?php $autoEmbed = $this->mailmunch_api->getSetting('auto_embed'); ?>
3
+ <div id="poststuff" class="wrap">
4
+ <div id="post-body" class="metabox-holder columns-2">
5
+ <div id="post-body-content">
6
+ <h2>
7
+ Settings | <?php echo $this->plugin_name; ?>
8
+ </h2>
9
+
10
+ <table class="wp-list-table widefat fixed posts settings-table">
11
+ <tbody>
12
+ <tr>
13
+ <td class="inside-container" width="30%">
14
+ <h3>Auto Embedding</h3>
15
+ <p>If enabled, it will add blank div tags in your posts and pages so you can embed forms more easily.</p>
16
+ </td>
17
+ <td class="setting">
18
+ <select name="auto_embed">
19
+ <option value="yes"<?php if ($autoEmbed == 'yes' || empty($autoEmbed)) echo "selected=\"selected\""; ?>>Yes</option>
20
+ <option value="no"<?php if ($autoEmbed == 'no') echo "selected=\"selected\""; ?>>No</option>
21
+ </select>
22
+ </td>
23
+ </tr>
24
+ <tr>
25
+ <td colspan="2">
26
+ <input type="submit" name="Save" value="Save Settings" class="button button-primary" />
27
+ </td>
28
+ </tr>
29
+ </tbody>
30
+ </table>
31
+ </div>
32
+
33
+ <div id="postbox-container-1" class="postbox-container">
34
+ <div id="side-sortables" class="meta-box-sortables ui-sortable">
35
+ <div class="postbox">
36
+ <h3><span>Need Support?</span></h3>
37
+
38
+ <div class="inside">
39
+ <p>Need Help? <a href="https://mailmunch.zendesk.com/hc" target="_blank">Contact Support</a></p>
40
+
41
+ <div class="video-trigger">
42
+ <p>Watch our quick tour video:</p>
43
+ <img src="<?php echo plugins_url( 'img/video.jpg', dirname(__FILE__) ) ?>" onclick="showVideo()" />
44
+ </div>
45
+ </div>
46
+ </div>
47
+ </div>
48
+
49
+ </div>
50
+ </div>
51
+ </div>
52
+ </form>
img/icon.png DELETED
Binary file
inc/common.php DELETED
@@ -1,73 +0,0 @@
1
- <?php
2
- class MailmunchHelpers {
3
- function __construct() {
4
- }
5
-
6
- function getEmailPassword() {
7
- $mailmunch_email = get_option("mailmunch_user_email");
8
- $mailmunch_password = get_option("mailmunch_user_password");
9
-
10
- if (empty($mailmunch_email)) {
11
- $current_user = wp_get_current_user();
12
- update_option("mailmunch_user_email", $current_user->user_email);
13
- }
14
-
15
- if (empty($mailmunch_password)) {
16
- update_option("mailmunch_user_password", base64_encode(uniqid()));
17
- }
18
-
19
- $mailmunch_email = get_option("mailmunch_user_email");
20
- $mailmunch_password = get_option("mailmunch_user_password");
21
-
22
- return array('email' => $mailmunch_email, 'password' => $mailmunch_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 MailmunchApi {
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=mailmunch');
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("mailmunch_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("mailmunch_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' => "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' => "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 Mailmunch_Sidebar_Widget extends WP_Widget {
3
-
4
- /**
5
- * Register widget with WordPress.
6
- */
7
- function __construct() {
8
- parent::__construct(
9
- 'mailmunch_widget', // Base ID
10
- __('Sidebar MailMunch 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
- $mailmunch_data = unserialize(get_option("mailmunch_data"));
58
- $mailmunch_user_email = get_option("mailmunch_user_email");
59
- $mailmunch_user_password = get_option("mailmunch_user_password");
60
- if (!empty($mailmunch_user_email) && !empty($mailmunch_user_password) && !empty($mailmunch_data["site_id"])) {
61
- $mailmunch_site_id = $mailmunch_data["site_id"];
62
- $mm = new MailmunchApi($mailmunch_user_email, $mailmunch_user_password, "http://".MAILMUNCH_URL);
63
- $result = $mm->widgets($mailmunch_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='.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 MAILMUNCH_URL ?>/sso?email=<?php echo urlencode($mailmunch_user_email) ?>&password=<?php echo urlencode($mailmunch_user_password) ?>&next_url=<?php echo urlencode("/sites/".$mailmunch_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 MAILMUNCH_URL ?>/sso?email=<?php echo urlencode($mailmunch_user_email) ?>&password=<?php echo urlencode($mailmunch_user_password) ?>&next_url=<?php echo urlencode("/sites/".$mailmunch_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-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 Mailmunch
10
+ * @subpackage 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 Mailmunch
20
+ * @subpackage Mailmunch/includes
21
+ * @author MailMunch <info@mailmunch.co>
22
+ */
23
+ class 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-mailmunch-api.php ADDED
@@ -0,0 +1,377 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mailmunch_Api {
3
+ protected $base_url = MAILMUNCH_URL;
4
+ protected $headers = array('Accept' => 'application/json');
5
+ protected $requestType = 'get';
6
+ protected $mailmunch_prefix;
7
+ protected $referral = 'mailmunch-wordpress-plugin';
8
+
9
+ function __construct() {
10
+ $this->mailmunch_prefix = MAILMUNCH_PREFIX.'_';
11
+ $this->ensureUser();
12
+ $this->findOrCreateSite();
13
+ }
14
+
15
+ function ensureUser() {
16
+ $userToken = $this->getUserToken();
17
+ if (empty($userToken)) {
18
+ $userToken = $this->generateUserToken();
19
+ if( is_wp_error( $userToken ) ) {
20
+ return new WP_Error( 'broke', "Unable to connect to MailMunch. Please try again later." );
21
+ }
22
+
23
+ $this->setUserToken($userToken);
24
+ }
25
+ }
26
+
27
+ function getSetting($settingName) {
28
+ return get_option($this->getPrefix(). $settingName);
29
+ }
30
+
31
+ function setSetting($settingName, $value=null) {
32
+ return update_option($this->getPrefix(). $settingName, $value);
33
+ }
34
+
35
+ function getUserToken() {
36
+ return get_option($this->getPrefix(). 'user_token');
37
+ }
38
+
39
+ function setUserToken($userToken) {
40
+ return update_option($this->getPrefix(). 'user_token', $userToken );
41
+ }
42
+
43
+ function widgets($widgetTypeName, $siteId=null) {
44
+ if (empty($siteId)) { $siteId = $this->getSiteId(); }
45
+ $this->requestType = 'get';
46
+ if (!empty($widgetTypeName)) {
47
+ return $this->ping('/sites/'.$siteId.'/widgets?widget_type_name='.$widgetTypeName);
48
+ } else {
49
+ return $this->ping('/sites/'.$siteId.'/widgets');
50
+ }
51
+ }
52
+
53
+ function getPrefix() {
54
+ return $this->mailmunch_prefix;
55
+ }
56
+
57
+ function getSites() {
58
+ $this->requestType = 'get';
59
+ $request = $this->ping('/sites');
60
+
61
+ if( is_wp_error( $request ) ) {
62
+ return new WP_Error( 'broke', "Unable to get sites. Please try again later." );
63
+ }
64
+
65
+ $sites = $request['body'];
66
+ $result = json_decode($sites);
67
+ return $result;
68
+ }
69
+
70
+ function getSite($siteId=null) {
71
+ if (empty($siteId)) $siteId = $this->getSiteId();
72
+ if (empty($siteId)) return false;
73
+
74
+ $this->requestType = 'get';
75
+ $request = $this->ping('/sites/'. $siteId);
76
+
77
+ if( is_wp_error( $request ) ) {
78
+ return false;
79
+ }
80
+
81
+ $site = $request['body'];
82
+ $result = json_decode($site);
83
+ return $result;
84
+ }
85
+
86
+ function getLists($siteId=null) {
87
+ if (empty($siteId)) { $siteId = $this->getSiteId(); }
88
+ $this->requestType = 'get';
89
+ $request = $this->ping('/sites/'. $siteId. '/lists');
90
+ if( is_wp_error( $request ) ) {
91
+ return new WP_Error( 'broke', "Unable to get lists. Please try again later." );
92
+ }
93
+
94
+ return json_decode($request['body']);
95
+ }
96
+
97
+ function findOrCreateSite() {
98
+ $site = $this->getSite();
99
+ if (empty($site)) {
100
+ $site = $this->createSite(get_bloginfo(), home_url());
101
+ if (!empty($site)) $this->setSiteId($site->id);
102
+ }
103
+ return $site;
104
+ }
105
+
106
+ function createList($listName, $siteId=null) {
107
+ if (empty($listName)) $listName = 'General';
108
+ if (empty($siteId)) { $siteId = $this->getSiteId(); }
109
+ $this->requestType = 'post';
110
+ $response = $this->ping('/sites/'. $siteId. '/lists', array(
111
+ 'list' => array(
112
+ 'name' => $listName,
113
+ )
114
+ ));
115
+ $list = json_decode($response['body']);
116
+ return $list;
117
+ }
118
+
119
+ function createSite($siteName, $domain) {
120
+ if (empty($siteName)) $siteName = 'WordPress';
121
+ $this->requestType = 'post';
122
+ $request = $this->ping('/sites', array(
123
+ 'site' => array(
124
+ 'name' => $siteName,
125
+ 'domain' => $domain,
126
+ 'wordpress' => true
127
+ )
128
+ ));
129
+ if( is_wp_error( $request ) ) {
130
+ return new WP_Error( 'broke', "Unable to create site. Please try again later." );
131
+ }
132
+
133
+ $site = json_decode($request['body']);
134
+ return $site;
135
+ }
136
+
137
+ function updateSite($sitename, $domain) {
138
+ $this->requestType = 'post';
139
+ return $this->ping('/wordpress/update_site', array(
140
+ 'id' => $this->getSiteId(),
141
+ 'site' => array(
142
+ 'name' => $sitename,
143
+ 'domain' => $domain
144
+ )
145
+ ));
146
+ }
147
+
148
+ function isLegacyUser() {
149
+ $email = get_option($this->getPrefix(). "user_email");
150
+ $password = get_option($this->getPrefix(). "user_password");
151
+
152
+ if (!empty($email) && !empty($password)) {
153
+ return true;
154
+ }
155
+
156
+ return false;
157
+ }
158
+
159
+ function migrateUser() {
160
+ $currentHeaders = $this->headers;
161
+ $email = get_option($this->getPrefix(). "user_email");
162
+ $password = get_option($this->getPrefix(). "user_password");
163
+
164
+ if (empty($email) || empty($password)) {
165
+ return false;
166
+ }
167
+
168
+ $this->headers = array_merge($this->headers, array(
169
+ 'Authorization' => 'Basic ' . base64_encode( $email . ':' . $password )
170
+ )
171
+ );
172
+
173
+ $this->requestType = 'post';
174
+ $request = $this->ping('/wordpress/migrate_user.json', array(), false);
175
+ $this->headers = $currentHeaders;
176
+
177
+ if( is_wp_error( $request ) ) {
178
+ return false;
179
+ }
180
+
181
+ $request = json_decode($request['body']);
182
+ if ($request->success == true && !empty($request->token)) {
183
+ $this->setUserToken($request->token);
184
+
185
+ // Migrate Site ID
186
+ $old_data = $this->deep_unserialize(get_option($this->getPrefix(). "data"));
187
+ if (isset($old_data["site_id"])) {
188
+ $this->setSiteId($old_data["site_id"]);
189
+ delete_option($this->getPrefix(). 'data');
190
+ }
191
+
192
+ // Delete options for old site
193
+ delete_option($this->getPrefix(). 'user_email');
194
+ delete_option($this->getPrefix(). 'user_password');
195
+ delete_option($this->getPrefix(). 'guest_user');
196
+ delete_option($this->getPrefix(). 'wordpress_instance_id');
197
+
198
+ return true;
199
+ }
200
+
201
+ return false;
202
+ }
203
+
204
+ function deep_unserialize($value, $retries=0) {
205
+ $retries++;
206
+ if ($retries > 3) return $value;
207
+
208
+ if (is_string($value)) {
209
+ $value = unserialize($value);
210
+ if (is_string($value)) $value = $this->deep_unserialize($value, $retries);
211
+ }
212
+ return $value;
213
+ }
214
+
215
+ function generateUserToken() {
216
+ if ($this->isLegacyUser()) {
217
+ if ($this->migrateUser()) {
218
+ return $this->getUserToken();
219
+ }
220
+ }
221
+
222
+ $guestUser = $this->createGuestUser();
223
+ if( is_wp_error( $guestUser ) ) {
224
+ return new WP_Error( 'broke', "Unable to create user. Please try again later." );
225
+ }
226
+ return json_decode($guestUser['body'])->user_token;
227
+ }
228
+
229
+ function createGuestUser() {
230
+ $this->requestType = 'post';
231
+ return $this->ping('/users', array(
232
+ 'user' => array(
233
+ 'email' => 'guest_' . uniqid() . '@mailmunch.co',
234
+ 'password' => uniqid(),
235
+ 'guest_user' => true,
236
+ 'referral' => $this->referral,
237
+ )
238
+ ));
239
+ }
240
+
241
+ function getWidgetsHtml($siteId=null) {
242
+ if (empty($siteId)) { $siteId = $this->getSiteId(); }
243
+
244
+ $this->requestType = 'get';
245
+ $request = $this->ping('/sites/'.$siteId.'/widgets/wordpress?plugin=mailmunch');
246
+ if( is_wp_error( $request ) ) {
247
+ return $request->get_error_message();
248
+ }
249
+
250
+ $body = str_replace('{{TOKEN}}', $this->getUserToken(), $request['body']);
251
+ return $body;
252
+ }
253
+
254
+ function getSiteId() {
255
+ return get_option($this->getPrefix(). 'site_id');
256
+ }
257
+
258
+ function setSiteId($siteId) {
259
+ return update_option($this->getPrefix(). 'site_id', $siteId);
260
+ }
261
+
262
+ function getListId() {
263
+ return get_option($this->getPrefix(). 'list_id');
264
+ }
265
+
266
+ function setListId($listId) {
267
+ return update_option($this->getPrefix(). 'list_id', $listId);
268
+ }
269
+
270
+ function deleteWidget($widgetId) {
271
+ $this->requestType = 'post';
272
+ $request = $this->ping('/sites/'.$this->getSiteId().'/widgets/'.$widgetId.'/delete');
273
+ if ( is_wp_error( $request ) ) {
274
+ return array('success' => false);
275
+ }
276
+ return array('success' => true);
277
+ }
278
+
279
+ function signInUser($email, $password) {
280
+ $this->requestType = 'post';
281
+ $request = $this->ping('/wordpress/sign_in.json', array(
282
+ 'user' => array(
283
+ 'email' => $email,
284
+ 'password' => $password
285
+ ),
286
+ 'site_id' => $this->getSiteId()
287
+ )
288
+ );
289
+
290
+ if( is_wp_error( $request ) ) {
291
+ return false;
292
+ }
293
+
294
+ $newUser = json_decode($request['body']);
295
+ if (intval($newUser->site_id) && $newUser->site_id != $this->getSiteId()) {
296
+ $this->setSiteId($newUser->site_id);
297
+ }
298
+ return $newUser;
299
+ }
300
+
301
+ function signUpUser($email, $password, $siteName, $siteDomain) {
302
+ $this->requestType = 'post';
303
+ $request = $this->ping('/wordpress/sign_up.json', array(
304
+ 'user' => array(
305
+ 'email' => $email,
306
+ 'password' => $password,
307
+ 'guest_user' => false
308
+ ),
309
+ 'site' => array(
310
+ 'id' => $this->getSiteId(),
311
+ 'name' => $siteName,
312
+ 'domain' => $siteDomain
313
+ )
314
+ )
315
+ );
316
+
317
+ if( is_wp_error( $request ) ) {
318
+ return false;
319
+ }
320
+
321
+ $newUser = json_decode($request['body']);
322
+ if (intval($newUser->site_id) && $newUser->site_id != $this->getSiteId()) {
323
+ $this->setSiteId($newUser->site_id);
324
+ }
325
+ return $newUser;
326
+ }
327
+
328
+ function signOutUser() {
329
+ delete_option($this->getPrefix(). 'user_token');
330
+ delete_option($this->getPrefix(). 'site_id');
331
+ delete_option($this->getPrefix(). 'class-mailmunchaccess_token');
332
+ delete_option($this->getPrefix(). 'class-mailmunchlist_id');
333
+ }
334
+
335
+ function ping($path, $options=array(), $useTokenAuth=true) {
336
+ $type = $this->requestType;
337
+ $url = $this->base_url. $path;
338
+
339
+ $parsedUrl = parse_url($url);
340
+ $parseUrlQuery = isset($parsedUrl['query']) ? $parsedUrl['query'] : null;
341
+ if (!empty($parseUrlQuery)) {
342
+ $url .= '&version='. MAILMUNCH_VERSION;
343
+ }
344
+ else {
345
+ $url .= '?version='. MAILMUNCH_VERSION;
346
+ }
347
+
348
+ if ($useTokenAuth) { $url .= '&token='. $this->getUserToken(); }
349
+
350
+ $args = array(
351
+ 'headers' => $this->headers,
352
+ 'timeout' => 120,
353
+ );
354
+
355
+ if ($type != 'post') {
356
+ $request = wp_remote_get($url, $args);
357
+ }
358
+ else {
359
+ $args = array_merge($args, array('method' => 'POST', 'body' => $options));
360
+ $request = wp_remote_post($url, $args);
361
+ }
362
+
363
+ if ( !is_wp_error( $request ) && ( $request['response']['code'] == 500 || $request['response']['code'] == 503 ) ) {
364
+ return new WP_Error( 'broke', "Internal Server Error" );
365
+ }
366
+
367
+ if ($useTokenAuth) {
368
+ if (!is_wp_error( $request ) && isset($request['response']['code']) && $request['response']['code'] == 401) {
369
+ $this->signOutUser();
370
+ return new WP_Error( 'broke', 'Unauthorized. Please try again.');
371
+ }
372
+ }
373
+
374
+ return $request;
375
+ }
376
+ }
377
+ ?>
includes/class-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 Mailmunch
10
+ * @subpackage 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 Mailmunch
20
+ * @subpackage Mailmunch/includes
21
+ * @author MailMunch <info@mailmunch.co>
22
+ */
23
+ class 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-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 Mailmunch
13
+ * @subpackage 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 Mailmunch
24
+ * @subpackage Mailmunch/includes
25
+ * @author MailMunch <info@mailmunch.co>
26
+ */
27
+ class 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-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 Mailmunch
10
+ * @subpackage 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 Mailmunch
21
+ * @subpackage Mailmunch/includes
22
+ * @author MailMunch <info@mailmunch.co>
23
+ */
24
+ class 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-mailmunch-sidebar-widget.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mailmunch_Sidebar_Widget extends WP_Widget {
3
+
4
+ /**
5
+ * Register widget with WordPress.
6
+ */
7
+ function __construct() {
8
+ parent::__construct(
9
+ MAILMUNCH_PREFIX.'_widget', // Base ID
10
+ __('Sidebar MailMunch 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
+ $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 MAILMUNCH_URL ?>/sso?token=<?php echo get_option(MAILMUNCH_PREFIX."_user_token") ?>&next_url=<?php echo urlencode("/sites/".get_option(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 MAILMUNCH_URL ?>/sso?token=<?php echo get_option(MAILMUNCH_PREFIX."_user_token") ?>&next_url=<?php echo urlencode("/sites/".get_option(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-mailmunch.php ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Mailmunch
13
+ * @subpackage Mailmunch/includes
14
+ */
15
+
16
+ // Define some class constants.
17
+ define( 'MAILMUNCH_URL', "http://wordpress.mailmunch.co" );
18
+ define( 'MAILMUNCH_HOME_URL', "http://app.mailmunch.co" );
19
+ define( 'MAILMUNCH_SLUG', "mailmunch" );
20
+ define( 'MAILMUNCH_PREFIX', 'mailmunch' );
21
+ define( 'MAILMUNCH_VERSION', '2.0.0' );
22
+
23
+ /**
24
+ * The core plugin class.
25
+ *
26
+ * This is used to define internationalization, admin-specific hooks, and
27
+ * public-facing site hooks.
28
+ *
29
+ * Also maintains the unique identifier of this plugin as well as the current
30
+ * version of the plugin.
31
+ *
32
+ * @since 2.0.0
33
+ * @package Mailmunch
34
+ * @subpackage Mailmunch/includes
35
+ * @author MailMunch <info@mailmunch.co>
36
+ */
37
+ class Mailmunch {
38
+
39
+ /**
40
+ * The loader that's responsible for maintaining and registering all hooks that power
41
+ * the plugin.
42
+ *
43
+ * @since 2.0.0
44
+ * @access protected
45
+ * @var Mailmunch_Loader $loader Maintains and registers all hooks for the plugin.
46
+ */
47
+ protected $loader;
48
+
49
+ /**
50
+ * The unique identifier of this plugin.
51
+ *
52
+ * @since 2.0.0
53
+ * @access protected
54
+ * @var string $plugin_name The string used to uniquely identify this plugin.
55
+ */
56
+ protected $plugin_name;
57
+
58
+ /**
59
+ * The unique identifier for the plugin's intended 3rd party integration
60
+ *
61
+ * @since 2.0.0
62
+ * @access protected
63
+ * @var string $integration_name The string used to uniquely identify the integration.
64
+ */
65
+ protected $integration_name;
66
+
67
+ /**
68
+ * The current version of the plugin.
69
+ *
70
+ * @since 2.0.0
71
+ * @access protected
72
+ * @var string $version The current version of the plugin.
73
+ */
74
+ protected $version;
75
+
76
+ /**
77
+ * The MailMunch api.
78
+ *
79
+ * @since 2.0.0
80
+ * @access protected
81
+ * @var string $mailmunch_api MailMunch API
82
+ */
83
+ protected $mailmunch_api;
84
+
85
+ /**
86
+ * Define the core functionality of the plugin.
87
+ *
88
+ * Set the plugin name and the plugin version that can be used throughout the plugin.
89
+ * Load the dependencies, define the locale, and set the hooks for the admin area and
90
+ * the public-facing side of the site.
91
+ *
92
+ * @since 2.0.0
93
+ */
94
+ public function __construct() {
95
+
96
+ $this->plugin_name = 'MailMunch';
97
+ $this->integration_name = 'MailMunch';
98
+ $this->version = '2.0.9';
99
+
100
+ $this->load_dependencies();
101
+ $this->set_locale();
102
+ if (is_admin()) {
103
+ $this->define_admin_hooks();
104
+ }
105
+ $this->define_public_hooks();
106
+
107
+
108
+ }
109
+
110
+ /**
111
+ * Load the required dependencies for this plugin.
112
+ *
113
+ * Include the following files that make up the plugin:
114
+ *
115
+ * - Mailmunch_Loader. Orchestrates the hooks of the plugin.
116
+ * - Mailmunch_i18n. Defines internationalization functionality.
117
+ * - Mailmunch_Admin. Defines all hooks for the admin area.
118
+ * - Mailmunch_Public. Defines all hooks for the public side of the site.
119
+ *
120
+ * Create an instance of the loader which will be used to register the hooks
121
+ * with WordPress.
122
+ *
123
+ * @since 2.0.0
124
+ * @access private
125
+ */
126
+ private function load_dependencies() {
127
+
128
+ /**
129
+ * The class responsible for communicating with MailMunch's Public API
130
+ */
131
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-mailmunch-api.php';
132
+
133
+ /**
134
+ * The class responsible for adding the sidebar widget
135
+ */
136
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-mailmunch-sidebar-widget.php';
137
+
138
+ /**
139
+ * The class responsible for orchestrating the actions and filters of the
140
+ * core plugin.
141
+ */
142
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-mailmunch-loader.php';
143
+
144
+ /**
145
+ * The class responsible for defining internationalization functionality
146
+ * of the plugin.
147
+ */
148
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-mailmunch-i18n.php';
149
+
150
+ /**
151
+ * The class responsible for defining all actions that occur in the admin area.
152
+ */
153
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-mailmunch-admin.php';
154
+
155
+ /**
156
+ * The class responsible for defining all actions that occur in the public-facing
157
+ * side of the site.
158
+ */
159
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-mailmunch-public.php';
160
+
161
+ $this->loader = new Mailmunch_Loader();
162
+
163
+ }
164
+
165
+ /**
166
+ * Define the locale for this plugin for internationalization.
167
+ *
168
+ * Uses the Mailmunch_i18n class in order to set the domain and to register the hook
169
+ * with WordPress.
170
+ *
171
+ * @since 2.0.0
172
+ * @access private
173
+ */
174
+ private function set_locale() {
175
+
176
+ $plugin_i18n = new Mailmunch_i18n();
177
+ $plugin_i18n->set_domain( $this->get_plugin_name() );
178
+
179
+ $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
180
+
181
+ }
182
+
183
+ /**
184
+ * Register all of the hooks related to the admin area functionality
185
+ * of the plugin.
186
+ *
187
+ * @since 2.0.0
188
+ * @access private
189
+ */
190
+ private function define_admin_hooks() {
191
+
192
+ $plugin_admin = new Mailmunch_Admin( $this->get_plugin_name(), $this->get_intgration_name(), $this->get_version() );
193
+
194
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
195
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
196
+ $this->loader->add_action( 'admin_menu', $plugin_admin, 'menu' );
197
+ $this->loader->add_action( 'init', $plugin_admin, 'init' );
198
+ $this->loader->add_action( 'admin_notices', $plugin_admin, 'activation_notice' );
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]. '/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 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
+ $this->loader->add_action( 'wp_head', $plugin_public, 'append_head' );
227
+
228
+ $autoEmbed = get_option(MAILMUNCH_PREFIX. '_auto_embed');
229
+ if (empty($autoEmbed) || $autoEmbed == 'yes') {
230
+ $this->loader->add_filter( 'the_content', $plugin_public, 'add_post_containers' );
231
+ }
232
+
233
+ // Sidebar widget
234
+ $this->loader->add_action( 'widgets_init', $plugin_public, 'sidebar_widget' );
235
+
236
+ }
237
+
238
+ /**
239
+ * Run the loader to execute all of the hooks with WordPress.
240
+ *
241
+ * @since 2.0.0
242
+ */
243
+ public function run() {
244
+ $this->loader->run();
245
+ }
246
+
247
+ /**
248
+ * The name of the plugin used to uniquely identify it within the context of
249
+ * WordPress and to define internationalization functionality.
250
+ *
251
+ * @since 2.0.0
252
+ * @return string The name of the plugin.
253
+ */
254
+ public function get_plugin_name() {
255
+ return $this->plugin_name;
256
+ }
257
+
258
+ /**
259
+ * The name of the 3rd party integration
260
+ * e.g. MailChimp, Constant Contact, etc.
261
+ *
262
+ * @since 2.0.0
263
+ * @return string The name of the plugin.
264
+ */
265
+ public function get_intgration_name() {
266
+ return $this->integration_name;
267
+ }
268
+
269
+ /**
270
+ * The reference to the class that orchestrates the hooks with the plugin.
271
+ *
272
+ * @since 2.0.0
273
+ * @return Mailmunch_Loader Orchestrates the hooks of the plugin.
274
+ */
275
+ public function get_loader() {
276
+ return $this->loader;
277
+ }
278
+
279
+ /**
280
+ * Retrieve the version number of the plugin.
281
+ *
282
+ * @since 2.0.0
283
+ * @return string The version number of the plugin.
284
+ */
285
+ public function get_version() {
286
+ return $this->version;
287
+ }
288
+ }
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/mailmunch.pot ADDED
File without changes
mailmunch.php CHANGED
@@ -1,485 +1,75 @@
1
  <?php
2
- /*
3
- Plugin Name: MailMunch - Increase your Email Subscribers by over 500%
4
- Plugin URI: http://www.mailmunch.co
5
- Description: Collect email addresses from website visitors and grow your subscribers with our attention grabbing optin-forms, entry/exit intent technology, and other effective lead-generation forms.
6
- Version: 1.4.4
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( 'MAILMUNCH_SLUG', "mailmunch");
17
- define( 'MAILMUNCH_VER', "1.4.4");
18
- define( 'MAILMUNCH_URL', "www.mailmunch.co");
19
-
20
- // Create unique WordPress instance ID
21
- if (get_option("mailmunch_wordpress_instance_id") == "") {
22
- update_option("mailmunch_wordpress_instance_id", uniqid());
23
- }
24
-
25
- // Adding Admin Menu
26
- add_action( 'admin_menu', 'mailmunch_register_page' );
27
-
28
- function mailmunch_register_page(){
29
- add_options_page('MailMunch', 'MailMunch', 'manage_options', MAILMUNCH_SLUG, 'mailmunch_setup');
30
- $menu_page = add_menu_page( 'MailMunch Settings', 'MailMunch', 'manage_options', MAILMUNCH_SLUG, 'mailmunch_setup', plugins_url( 'img/icon.png', __FILE__ ), 102.786 );
31
- // If successful, load admin assets only on that page.
32
- if ($menu_page) add_action('load-' . $menu_page, 'mailmunch_load_plugin_assets');
33
- }
34
-
35
- function mailmunch_plugin_settings_link($links) {
36
- $settings_link = '<a href="options-general.php?page='.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, 'mailmunch_plugin_settings_link');
43
-
44
- function mailmunch_load_plugin_assets() {
45
- add_action( 'admin_enqueue_scripts', 'mailmunch_enqueue_admin_styles' );
46
- add_action( 'admin_enqueue_scripts', 'mailmunch_enqueue_admin_scripts' );
47
- }
48
-
49
- function mailmunch_enqueue_admin_styles() {
50
- wp_enqueue_style(MAILMUNCH_SLUG . '-admin-styles', plugins_url( 'css/admin.css', __FILE__ ), array(), MAILMUNCH_VER );
51
- }
52
-
53
- function mailmunch_enqueue_admin_scripts() {
54
- wp_enqueue_script(MAILMUNCH_SLUG . '-admin-script', plugins_url( 'js/admin.js', __FILE__ ), array( 'jquery' ), MAILMUNCH_VER );
55
- }
56
-
57
- // Adding MailMunch Asset Files (JS + CSS)
58
- function mailmunch_load_asset_code() {
59
- $mailmunch_data = unserialize(get_option("mailmunch_data"));
60
- if (!$mailmunch_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="'.$mailmunch_data["site_id"].'" async></script>');
79
- }
80
-
81
- add_action('init', 'mailmunch_assets');
82
-
83
- function mailmunch_assets() {
84
- $mailmunch_data = unserialize(get_option("mailmunch_data"));
85
- if (count($mailmunch_data) == 0) return;
86
-
87
- if (function_exists('wp_head')) {
88
- add_action( 'wp_head', 'mailmunch_load_asset_code' );
89
- }
90
- elseif (function_exists('wp_footer')) {
91
- add_action( 'wp_footer', 'mailmunch_load_asset_code' );
92
- }
93
- }
94
-
95
- function mailmunch_add_post_containers($content) {
96
- if (is_single() || is_page()) {
97
- $content = mailmunch_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 mailmunch_register_sidebar_widget() {
105
- register_widget( 'Mailmunch_Sidebar_Widget' );
106
- }
107
- add_action( 'widgets_init', 'mailmunch_register_sidebar_widget' );
108
-
109
- function mailmunch_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', 'mailmunch_add_post_containers' );
129
-
130
- function mailmunch_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', 'mailmunch_shortcode_form');
135
-
136
- function mailmunch_setup() {
137
- $mm_helpers = new MailmunchHelpers();
138
- $mailmunch_data = unserialize(get_option("mailmunch_data"));
139
- $mailmunch_data["site_url"] = home_url();
140
- $mailmunch_data["site_name"] = get_bloginfo();
141
- update_option("mailmunch_data", serialize($mailmunch_data));
142
-
143
- // This is a POST request. Let's save data first.
144
- if ($_POST) {
145
- $post_data = (isset($_POST["mailmunch_data"]) ? $_POST["mailmunch_data"] : array());
146
- $post_action = $_POST["action"];
147
-
148
- if ($post_action == "save_settings") {
149
-
150
- $mailmunch_data = array_merge(unserialize(get_option('mailmunch_data')), $post_data);
151
- update_option("mailmunch_data", serialize($mailmunch_data));
152
-
153
- } else if ($post_action == "sign_in") {
154
-
155
- $mm = new MailmunchApi($_POST["email"], $_POST["password"], "http://".MAILMUNCH_URL);
156
- if ($mm->validPassword()) {
157
- update_option("mailmunch_user_email", $_POST["email"]);
158
- update_option("mailmunch_user_password", base64_encode($_POST["password"]));
159
- delete_option("mailmunch_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
- $mailmunch_email = $account_info['email'];
169
- $mailmunch_password = $account_info['password'];
170
-
171
- $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".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("mailmunch_user_email", $result->email);
176
- update_option("mailmunch_user_password", base64_encode($_POST['password']));
177
- if (!$result->guest_user) { delete_option("mailmunch_guest_user"); }
178
- $mailmunch_email = $result->email;
179
- $mailmunch_password = $_POST['password'];
180
-
181
- // We have update the guest with real email address, let's create a site now
182
- $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
183
-
184
- $update_result = $mm->updateSite($mailmunch_data["site_name"], $mailmunch_data["site_url"]);
185
- $result = json_decode($update_result['body']);
186
- $mailmunch_data = unserialize(get_option("mailmunch_data"));
187
- $mailmunch_data["site_url"] = $result->domain;
188
- $mailmunch_data["site_name"] = $result->name;
189
- update_option("mailmunch_data", serialize($mailmunch_data));
190
- } else {
191
- $user_exists = true;
192
- }
193
- }
194
-
195
- } else if ($post_action == "unlink_account") {
196
-
197
- $mailmunch_data = array();
198
- $mailmunch_data["site_url"] = home_url();
199
- $mailmunch_data["site_name"] = get_bloginfo();
200
- update_option("mailmunch_data", serialize($mailmunch_data));
201
- delete_option("mailmunch_user_email");
202
- delete_option("mailmunch_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
- $mailmunch_email = $account_info['email'];
209
- $mailmunch_password = $account_info['password'];
210
- $mm = new MailmunchApi($account_info['email'], $account_info["password"], "http://".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 MailmunchApi($account_info['email'], $account_info["password"], "http://".MAILMUNCH_URL);
220
- $request = $mm->createSite($site_name, $site_url);
221
- $site = json_decode($request['body']);
222
-
223
- if (!empty($site->id)) {
224
- $mailmunch_data = unserialize(get_option("mailmunch_data"));
225
- $mailmunch_data["site_id"] = $site->id;
226
- $mailmunch_data["script_src"] = $site->javascript_url;
227
- update_option("mailmunch_data", serialize($mailmunch_data));
228
- }
229
- }
230
- }
231
-
232
- // If the user does not exists, create a GUEST user
233
- if (get_option("mailmunch_user_email") == "") {
234
- $mailmunch_email = "guest_".uniqid()."@mailmunch.co";
235
- $mailmunch_password = uniqid();
236
- $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
237
- $mm->createGuestUser();
238
- update_option("mailmunch_user_email", $mailmunch_email);
239
- update_option("mailmunch_user_password", base64_encode($mailmunch_password));
240
- update_option("mailmunch_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("mailmunch_user_email") != "") {
246
- $account_info = $mm_helpers->getEmailPassword();
247
- $mailmunch_email = $account_info['email'];
248
- $mailmunch_password = $account_info['password'];
249
-
250
- $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".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
- $mailmunch_email = "guest_".uniqid()."@mailmunch.co";
261
- $mailmunch_password = uniqid();
262
- $mm = new MailmunchApi($mailmunch_email, $mailmunch_password, "http://".MAILMUNCH_URL);
263
- $mm->createGuestUser();
264
- update_option("mailmunch_user_email", $mailmunch_email);
265
- update_option("mailmunch_user_password", base64_encode($mailmunch_password));
266
- update_option("mailmunch_guest_user", true);
267
- }
268
- }
269
-
270
- $mailmunch_guest_user = get_option("mailmunch_guest_user");
271
-
272
-
273
- if ($mailmunch_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($mailmunch_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, $mailmunch_data["site_id"]);
283
-
284
- if ($site) {
285
- $mailmunch_data = array_merge(unserialize(get_option('mailmunch_data')), array("script_src" => $site->javascript_url));
286
- update_option("mailmunch_data", serialize($mailmunch_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
- $mailmunch_data = unserialize(get_option('mailmunch_data'));
291
- unset($mailmunch_data["site_id"]);
292
- unset($mailmunch_data["script_src"]);
293
- update_option("mailmunch_data", serialize($mailmunch_data));
294
- }
295
- }
296
-
297
- if (!isset($mailmunch_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
- $mailmunch_data = array_merge(unserialize(get_option('mailmunch_data')), array("site_id" => $site->id, "script_src" => $site->javascript_url));
307
- update_option("mailmunch_data", serialize($mailmunch_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="mailmunch_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($mailmunch_data["site_id"]);
371
- $widgets = $request['body'];
372
- $widgets = str_replace("{{EMAIL}}", $mailmunch_email, $widgets);
373
- $widgets = str_replace("{{PASSWORD}}", $mailmunch_password, $widgets);
374
- echo $widgets;
375
-
376
- if ($mailmunch_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 MailMunch 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 MailMunch 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 $mailmunch_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 $mailmunch_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 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 Mailmunch
14
+ *
15
+ * @wordpress-plugin
16
+ * Plugin Name: MailMunch - Increase your Email Subscribers by over 500%
17
+ * Plugin URI: http://www.mailmunch.co
18
+ * Description: Collect email addresses from website visitors and grow your subscribers with our attention grabbing optin-forms, entry/exit intent technology, and other effective lead-generation forms.
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: 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-mailmunch-activator.php
36
+ */
37
+ function activate_mailmunch() {
38
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-mailmunch-activator.php';
39
+ Mailmunch_Activator::activate();
40
+ }
41
+
42
+ /**
43
+ * The code that runs during plugin deactivation.
44
+ * This action is documented in includes/class-mailmunch-deactivator.php
45
+ */
46
+ function deactivate_mailmunch() {
47
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-mailmunch-deactivator.php';
48
+ Mailmunch_Deactivator::deactivate();
49
+ }
50
+
51
+ register_activation_hook( __FILE__, 'activate_mailmunch' );
52
+ register_deactivation_hook( __FILE__, 'deactivate_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-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_mailmunch() {
70
+
71
+ $plugin = new Mailmunch();
72
+ $plugin->run();
73
+
74
+ }
75
+ run_mailmunch();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
public/class-mailmunch-public.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Mailmunch
10
+ * @subpackage 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 Mailmunch
20
+ * @subpackage Mailmunch/public
21
+ * @author MailMunch <info@mailmunch.co>
22
+ */
23
+ class 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
+ add_shortcode('mailmunch-form', array($this, 'shortcode_form'));
56
+ }
57
+
58
+ public function shortcode_form($atts) {
59
+ return "<div class='mailmunch-forms-short-code mailmunch-forms-widget-".$atts['id']."' style='display: none !important;'></div>";
60
+ }
61
+
62
+ /**
63
+ * Register sidebar widget
64
+ *
65
+ * @since 2.0.0
66
+ */
67
+ public function sidebar_widget() {
68
+ register_widget( 'Mailmunch_Sidebar_Widget' );
69
+ }
70
+
71
+ /**
72
+ * Register the stylesheets for the public-facing side of the site.
73
+ *
74
+ * @since 2.0.0
75
+ */
76
+ public function enqueue_styles() {
77
+
78
+ /**
79
+ * This function is provided for demonstration purposes only.
80
+ *
81
+ * An instance of this class should be passed to the run() function
82
+ * defined in Mailmunch_Loader as all of the hooks are defined
83
+ * in that particular class.
84
+ *
85
+ * The Mailmunch_Loader will then create the relationship
86
+ * between the defined hooks and the functions defined in this
87
+ * class.
88
+ */
89
+
90
+ }
91
+
92
+ /**
93
+ * Register the stylesheets for the public-facing side of the site.
94
+ *
95
+ * @since 2.0.0
96
+ */
97
+ public function enqueue_scripts() {
98
+
99
+ /**
100
+ * This function is provided for demonstration purposes only.
101
+ *
102
+ * An instance of this class should be passed to the run() function
103
+ * defined in Mailmunch_Loader as all of the hooks are defined
104
+ * in that particular class.
105
+ *
106
+ * The Mailmunch_Loader will then create the relationship
107
+ * between the defined hooks and the functions defined in this
108
+ * class.
109
+ */
110
+
111
+ }
112
+
113
+ /**
114
+ * Appends code for wp_head in the public-facing side of the site.
115
+ *
116
+ * @since 2.0.9
117
+ */
118
+ public function append_head() {
119
+ $siteID = get_option(MAILMUNCH_PREFIX. '_site_id');
120
+
121
+ if (is_single() || is_page()) {
122
+ $post = get_post();
123
+ $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);
124
+ }
125
+
126
+ echo "<script type='text/javascript' data-cfasync='false'>";
127
+ echo "var _mmunch = {'front': false, 'page': false, 'post': false, 'category': false, 'author': false, 'search': false, 'attachment': false, 'tag': false};";
128
+ if (is_front_page() || is_home()) { echo "_mmunch['front'] = true;"; }
129
+ if (is_page()) { echo "_mmunch['page'] = true; _mmunch['pageData'] = ".json_encode($post_data).";"; }
130
+ 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"))).";"; }
131
+ if (is_category()) { echo "_mmunch['category'] = true; _mmunch['categoryData'] = ".json_encode(get_category(get_query_var('cat'))).";"; }
132
+ if (is_search()) { echo "_mmunch['search'] = true;"; }
133
+ if (is_author()) { echo "_mmunch['author'] = true;"; }
134
+ if (is_tag()) { echo "_mmunch['tag'] = true;"; }
135
+ if (is_attachment()) { echo "_mmunch['attachment'] = true;"; }
136
+ echo "</script>";
137
+ echo('<script data-cfasync="false" src="//s3.amazonaws.com/mailmunch/static/site.js" id="mailmunch-script" data-mailmunch-site-id="'.$siteID.'" async></script>');
138
+
139
+ }
140
+
141
+ /**
142
+ * Adds MailMunch form container in middle of paragraphs
143
+ *
144
+ * @since 2.0.0
145
+ */
146
+ function insert_form_after_paragraph($insertion, $paragraph_id, $content) {
147
+ $closing_p = '</p>';
148
+ $paragraphs = explode($closing_p, $content);
149
+ if ($paragraph_id == "middle") {
150
+ $paragraph_id = round(sizeof($paragraphs)/2);
151
+ }
152
+
153
+ foreach ($paragraphs as $index => $paragraph) {
154
+ if (trim($paragraph)) {
155
+ $paragraphs[$index] .= $closing_p;
156
+ }
157
+
158
+ if ($paragraph_id == $index + 1) {
159
+ $paragraphs[$index] .= $insertion;
160
+ }
161
+ }
162
+ return implode('', $paragraphs);
163
+ }
164
+
165
+ /**
166
+ * Adds post containers for before, after and in the middle of post
167
+ *
168
+ * @since 2.0.0
169
+ */
170
+ public function add_post_containers($content) {
171
+ if (is_single() || is_page()) {
172
+ $content = $this->insert_form_after_paragraph("<div class='mailmunch-forms-in-post-middle' style='display: none !important;'></div>", "middle", $content);
173
+ $content = "<div class='mailmunch-forms-before-post' style='display: none !important;'></div>" . $content . "<div class='mailmunch-forms-after-post' style='display: none !important;'></div>";
174
+ }
175
+
176
+ return $content;
177
+ }
178
+
179
+ }
public/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
public/partials/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 Mailmunch
12
+ * @subpackage Mailmunch/public/partials
13
+ */
14
+ ?>
15
+
16
+ <!-- This file should primarily consist of HTML with a little bit of PHP. -->
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: mailmunch
3
  Tags: signup form, newsletter, newsletters, subscribe, popup, exit popup, exit intent, subscribers, subscription, popover, lightbox, analytics, collect email, optin, optin form, optin forms, double optin, list builder, email form, lead, leads, mailchimp, mailchimp form, mailchimp newsletter, mailchimp plugin, mailchimp signup, mailchimp signup forms, mailchimp signup form, mailchimp widget, mailchimp subscribe, constant contact, contact contact form, constant contact newsletter, constant contact plugin, constant contact signup, constant contact signup forms, constant contact signup form, constant contact widget, constant contact subscribe, aweber, aweber form, aweber forms, aweber signup form, aweber plugin
4
  Requires at least: 3.0.1
5
  Tested up to: 4.2
6
- Stable tag: 1.4.4
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
3
  Tags: signup form, newsletter, newsletters, subscribe, popup, exit popup, exit intent, subscribers, subscription, popover, lightbox, analytics, collect email, optin, optin form, optin forms, double optin, list builder, email form, lead, leads, mailchimp, mailchimp form, mailchimp newsletter, mailchimp plugin, mailchimp signup, mailchimp signup forms, mailchimp signup form, mailchimp widget, mailchimp subscribe, constant contact, contact contact form, constant contact newsletter, constant contact plugin, constant contact signup, constant contact signup forms, constant contact signup form, constant contact widget, constant contact subscribe, aweber, aweber form, aweber forms, aweber signup form, aweber plugin
4
  Requires at least: 3.0.1
5
  Tested up to: 4.2
6
+ Stable tag: 2.0.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
uninstall.php CHANGED
@@ -1,9 +1,34 @@
1
  <?php
2
- if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
3
- exit();
4
 
5
- delete_option("mailmunch_data");
6
- delete_option("mailmunch_user_email");
7
- delete_option("mailmunch_user_password");
8
- delete_option("mailmunch_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 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('mailmunch_user_token');
34
+ delete_option('mailmunch_site_id');