WordPress Page Builder – Beaver Builder - Version 1.6.4.4

Version Description

Download this release

Release Info

Developer justinbusa
Plugin Icon 128x128 WordPress Page Builder – Beaver Builder
Version 1.6.4.4
Comparing to
See all releases

Code changes from version 1.6.4.3 to 1.6.4.4

changelog.txt CHANGED
@@ -1,3 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <h4>1.6.4.3 - 11/23/2015</h4>
2
  <p><strong>Enhancements</strong></p>
3
  <ul>
1
+ <h4>1.6.4.4 - 12/08/2015</h4>
2
+ <p><strong>Enhancements</strong></p>
3
+ <ul>
4
+ <li>Added Success Action setting to the Contact Form module to show a message or redirect to a URL when the form is submitted.</li>
5
+ <li>The from email address for Contact Form module submissions is now set to the email of the person that filled out the form.</li>
6
+ <li>Added WebM fallback support to the Video module.</li>
7
+ <li>Added srcset support to the Photo module for better responsiveness of images in anticipation of WordPress 4.4.</li>
8
+ <li>Added ConvertKit integration to the Subscribe Form module.</li>
9
+ <li>Added Drip integration to the Subscribe Form module.</li>
10
+ <li>Added Campayn integration to the Subscribe Form module.</li>
11
+ <li>Added Mailrelay integration to the Subscribe Form module.</li>
12
+ <li>Added Sendy integration to the Subscribe Form module.</li>
13
+ <li>Added two new filters for working with post types that the builder is enabled on.</li>
14
+ <li>Added JavaScript event to the Accordion module for when sections are toggled.</li>
15
+ <li>Updated Font Awesome.</li>
16
+ </ul>
17
+ <p><strong>Bug Fixes</strong></p>
18
+ <ul>
19
+ <li>Fixed a bug with theme white labeling and child themes.</li>
20
+ <li>Fixed a bug with theme white labeling and the Customizer.</li>
21
+ <li>Fixed a bug with Gantry framework compatibility.</li>
22
+ <li>Fixed a bug with floating content in the Tabs module.</li>
23
+ <li>Fixed a bug with blurry background photos in the Post Slider module.</li>
24
+ <li>Fixed a bug causing global translations to be overridden by local translations.</li>
25
+ <li>Fixed a bug with cache flushing in the Widget module.</li>
26
+ </ul>
27
+
28
  <h4>1.6.4.3 - 11/23/2015</h4>
29
  <p><strong>Enhancements</strong></p>
30
  <ul>
classes/class-fl-builder-admin.php CHANGED
@@ -279,7 +279,14 @@ final class FLBuilderAdmin {
279
  $theme_data = FLBuilderModel::get_theme_branding();
280
 
281
  if ( ! empty( $theme_data['name'] ) ) {
 
282
  $themes['bb-theme']['name'] = $theme_data['name'];
 
 
 
 
 
 
283
  }
284
  if ( ! empty( $theme_data['description'] ) ) {
285
  $themes['bb-theme']['description'] = $theme_data['description'];
@@ -296,4 +303,25 @@ final class FLBuilderAdmin {
296
 
297
  return $themes;
298
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  }
279
  $theme_data = FLBuilderModel::get_theme_branding();
280
 
281
  if ( ! empty( $theme_data['name'] ) ) {
282
+
283
  $themes['bb-theme']['name'] = $theme_data['name'];
284
+
285
+ foreach ( $themes as $theme_key => $theme ) {
286
+ if ( isset( $theme['parent'] ) && $theme['parent'] == 'Beaver Builder Theme' ) {
287
+ $themes[ $theme_key ]['parent'] = $theme_data['name'];
288
+ }
289
+ }
290
  }
291
  if ( ! empty( $theme_data['description'] ) ) {
292
  $themes['bb-theme']['description'] = $theme_data['description'];
303
 
304
  return $themes;
305
  }
306
+
307
+ /**
308
+ * White labels the builder theme using the gettext filter
309
+ * to cover areas that we can't access like the Customizer.
310
+ *
311
+ * @since 1.6.4.4
312
+ * @return string
313
+ */
314
+ static public function white_label_theme_gettext( $text )
315
+ {
316
+ if ( is_admin() && 'Beaver Builder Theme' == $text ) {
317
+
318
+ $theme_data = FLBuilderModel::get_theme_branding();
319
+
320
+ if ( ! empty( $theme_data['name'] ) ) {
321
+ $text = $theme_data['name'];
322
+ }
323
+ }
324
+
325
+ return $text;
326
+ }
327
  }
classes/class-fl-builder-model.php CHANGED
@@ -227,12 +227,13 @@ final class FLBuilderModel {
227
  $value = self::get_admin_settings_option( '_fl_builder_post_types', true );
228
 
229
  if ( ! $value ) {
230
- return array( 'page', 'fl-builder-template' );
231
  }
232
  else {
233
  $value[] = 'fl-builder-template';
234
- return $value;
235
  }
 
 
236
  }
237
 
238
  /**
227
  $value = self::get_admin_settings_option( '_fl_builder_post_types', true );
228
 
229
  if ( ! $value ) {
230
+ $value = array( 'page', 'fl-builder-template' );
231
  }
232
  else {
233
  $value[] = 'fl-builder-template';
 
234
  }
235
+
236
+ return apply_filters( 'fl_builder_post_types', $value );
237
  }
238
 
239
  /**
classes/class-fl-builder-service-campayn.php ADDED
@@ -0,0 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Helper class for the Campayn API.
5
+ *
6
+ * @since 1.5.4
7
+ */
8
+ final class FLBuilderServiceCampayn extends FLBuilderService {
9
+
10
+ /**
11
+ * The ID for this service.
12
+ *
13
+ * @since 1.5.4
14
+ * @var string $id
15
+ */
16
+ public $id = 'campayn';
17
+
18
+ /**
19
+ * The HTTP protocal
20
+ *
21
+ * @since 1.5.8
22
+ * @access private
23
+ * @var string $api_protocol
24
+ */
25
+ private $api_protocol = 'http';
26
+
27
+ /**
28
+ * The API version
29
+ *
30
+ * @since 1.5.8
31
+ * @access private
32
+ * @var string $api_version
33
+ */
34
+ private $api_version = 1;
35
+
36
+ /**
37
+ * Request data from the thir party API.
38
+ *
39
+ * @since 1.5.4
40
+ * @param string $base_url Base URL where API is available
41
+ * @param string $api_key API Key provided by this service
42
+ * @param string $endpoint Method to request available from this service.
43
+ * @param array $params Data to be passed to API
44
+ * @return array|object The API response.
45
+ */
46
+ private function get_api_response( $base_url, $api_key, $endpoint, $params = array() )
47
+ {
48
+ // Exclude http:// from the user's input
49
+ $request_uri = $this->api_protocol .'://'. preg_replace('#^https?://#', '', $base_url) .'/api/v' .$this->api_version . $endpoint;
50
+
51
+ $params['timeout'] = 60;
52
+ $params['body'] = isset($params['data']) && $params['data'] ? json_encode($params['data']) : '';
53
+ $params['headers'] = array('Authorization' => 'TRUEREST apikey='. $api_key);
54
+ $response = wp_remote_get( $request_uri, $params );
55
+ $response_code = wp_remote_retrieve_response_code( $response );
56
+ $response_message = wp_remote_retrieve_response_message( $response );
57
+ $get_response = json_decode(wp_remote_retrieve_body( $response ), true);
58
+
59
+ if ( is_wp_error($response) || (200 != $response_code) ) {
60
+
61
+ if ( is_wp_error( $response ) ) {
62
+ $data['error'] = $response->get_error_message();
63
+ }
64
+ else {
65
+ $data['error'] = isset($get_response['msg']) ? $get_response['msg'] : $response_code .' - '. $response_message;
66
+ }
67
+
68
+ }
69
+ else {
70
+ if ($get_response) {
71
+ $data = $get_response;
72
+ }
73
+ else {
74
+ $data = $response;
75
+ }
76
+ }
77
+ return $data;
78
+ }
79
+
80
+ /**
81
+ * Test the API connection.
82
+ *
83
+ * @since 1.5.4
84
+ * @param array $fields {
85
+ * @type string $api_host A valid Host.
86
+ * @type string $api_key A valid API key.
87
+ * }
88
+ * @return array{
89
+ * @type bool|string $error The error message or false if no error.
90
+ * @type array $data An array of data used to make the connection.
91
+ * }
92
+ */
93
+ public function connect( $fields = array() )
94
+ {
95
+ $response = array(
96
+ 'error' => false,
97
+ 'data' => array()
98
+ );
99
+
100
+ // Make sure we have the Host.
101
+ if ( ! isset( $fields['api_host'] ) || empty( $fields['api_host'] ) ) {
102
+ $response['error'] = __( 'Error: You must provide a Host.', 'fl-builder' );
103
+ }
104
+ // Make sure we have an API key.
105
+ else if ( ! isset( $fields['api_key'] ) || empty( $fields['api_key'] ) ) {
106
+ $response['error'] = __( 'Error: You must provide an API key.', 'fl-builder' );
107
+ }
108
+ // Try to connect and store the connection data.
109
+ else {
110
+
111
+ $result = $this->get_api_response( $fields['api_host'], $fields['api_key'], '/lists.json' );
112
+
113
+ if (!isset($result['error'])) {
114
+ $response['data'] = array( 'api_host' => $fields['api_host'], 'api_key' => $fields['api_key'] );
115
+ }
116
+ else {
117
+ $response['error'] = sprintf(__( 'Error: Could not connect to Campayn. %s', 'fl-builder' ), $result['error']);
118
+ }
119
+ }
120
+
121
+ return $response;
122
+ }
123
+
124
+ /**
125
+ * Renders the markup for the connection settings.
126
+ *
127
+ * @since 1.5.4
128
+ * @return string The connection settings markup.
129
+ */
130
+ public function render_connect_settings()
131
+ {
132
+ ob_start();
133
+
134
+ FLBuilder::render_settings_field( 'api_host', array(
135
+ 'row_class' => 'fl-builder-service-connect-row',
136
+ 'class' => 'fl-builder-service-connect-input',
137
+ 'type' => 'text',
138
+ 'label' => __( 'Host', 'fl-builder' ),
139
+ 'help' => __( 'The host you chose when you signed up for your account. Check your welcome email if you forgot it. Please enter it without the initial http:// (for example: demo.campayn.com).', 'fl-builder' ),
140
+ 'preview' => array(
141
+ 'type' => 'none'
142
+ )
143
+ ));
144
+
145
+ FLBuilder::render_settings_field( 'api_key', array(
146
+ 'row_class' => 'fl-builder-service-connect-row',
147
+ 'class' => 'fl-builder-service-connect-input',
148
+ 'type' => 'text',
149
+ 'label' => __( 'API Key', 'fl-builder' ),
150
+ 'help' => __( 'Your API key can be found in your Campayn account under Settings > API Key.', 'fl-builder' ),
151
+ 'preview' => array(
152
+ 'type' => 'none'
153
+ )
154
+ ));
155
+
156
+ return ob_get_clean();
157
+ }
158
+
159
+ /**
160
+ * Render the markup for service specific fields.
161
+ *
162
+ * @since 1.5.4
163
+ * @param string $account The name of the saved account.
164
+ * @param object $settings Saved module settings.
165
+ * @return array {
166
+ * @type bool|string $error The error message or false if no error.
167
+ * @type string $html The field markup.
168
+ * }
169
+ */
170
+ public function render_fields( $account, $settings )
171
+ {
172
+ $account_data = $this->get_account_data( $account );
173
+ $results = $this->get_api_response( $account_data['api_host'], $account_data['api_key'], '/lists.json' );
174
+
175
+ $response = array(
176
+ 'error' => false,
177
+ 'html' => ''
178
+ );
179
+
180
+ if ( isset($results['error']) ) {
181
+ $response['error'] = sprintf(__( 'Error: Please check your API key. %s', 'fl-builder' ), $results['error']);
182
+ }
183
+ else {
184
+ $response['html'] = $this->render_list_field( $results, $settings );
185
+ }
186
+
187
+ return $response;
188
+ }
189
+
190
+ /**
191
+ * Render markup for the list field.
192
+ *
193
+ * @since 1.5.4
194
+ * @param array $lists List data from the API.
195
+ * @param object $settings Saved module settings.
196
+ * @return string The markup for the list field.
197
+ * @access private
198
+ */
199
+ private function render_list_field( $lists, $settings )
200
+ {
201
+ ob_start();
202
+
203
+ $options = array( '' => __( 'Choose...', 'fl-builder' ) );
204
+
205
+ foreach ( $lists as $list ) {
206
+ $options[ $list['id'] ] = $list['list_name'];
207
+ }
208
+
209
+ FLBuilder::render_settings_field( 'list_id', array(
210
+ 'row_class' => 'fl-builder-service-field-row',
211
+ 'class' => 'fl-builder-service-list-select',
212
+ 'type' => 'select',
213
+ 'label' => _x( 'List', 'An email list from third party provider.', 'fl-builder' ),
214
+ 'options' => $options,
215
+ 'preview' => array(
216
+ 'type' => 'none'
217
+ )
218
+ ), $settings);
219
+
220
+ return ob_get_clean();
221
+ }
222
+
223
+ /**
224
+ * Subscribe an email address to Campayn.
225
+ *
226
+ * @since 1.5.4
227
+ * @param object $settings A module settings object.
228
+ * @param string $email The email to subscribe.
229
+ * @param string $name Optional. The full name of the person subscribing.
230
+ * @return array {
231
+ * @type bool|string $error The error message or false if no error.
232
+ * }
233
+ */
234
+ public function subscribe( $settings, $email, $name = '' )
235
+ {
236
+ $account_data = $this->get_account_data( $settings->service_account );
237
+ $response = array( 'error' => false );
238
+ $contact_id = null;
239
+
240
+ if ( ! $account_data ) {
241
+ $response['error'] = __( 'There was an error subscribing to Campayn. The account is no longer connected.', 'fl-builder' );
242
+ }
243
+ else {
244
+
245
+ // Build data array
246
+ $data = array('email' => $email);
247
+
248
+ // Add the name to the data array if we have one.
249
+ if ( $name ) {
250
+
251
+ $names = explode( ' ', $name );
252
+
253
+ if ( isset( $names[0] ) ) {
254
+ $data['first_name'] = $names[0];
255
+ }
256
+ if ( isset( $names[1] ) ) {
257
+ $data['last_name'] = $names[1];
258
+ }
259
+ }
260
+
261
+ // Check if email already exists
262
+ $result = $this->get_api_response( $account_data['api_host'], $account_data['api_key'],
263
+ "/lists/{$settings->list_id}/contacts.json?filter[contact]=". $email
264
+ );
265
+
266
+ // Already exists
267
+ if ( ! isset($result['error']) && (is_array($result) && isset($result[0]['id'])) ) {
268
+ $contact_id = $result[0]['id'];
269
+ }
270
+
271
+ // Add the contact if it doesn't exist.
272
+ if ( ! $contact_id ) {
273
+ $endpoint = "/lists/{$settings->list_id}/contacts.json";
274
+ $method = 'POST';
275
+ }
276
+ else {
277
+ $endpoint = "/contacts/{$contact_id}.json";
278
+ $method = 'PUT';
279
+ $data['id'] = $contact_id;
280
+ }
281
+
282
+ $result = $this->get_api_response( $account_data['api_host'], $account_data['api_key'], $endpoint, array(
283
+ 'data' => $data,
284
+ 'method' => $method
285
+ ) );
286
+
287
+ if ( isset($result['error']) ) {
288
+ $response['error'] = sprintf(__( 'There was an error subscribing to Campayn. %s', 'fl-builder' ), $result['error']);
289
+ }
290
+ }
291
+
292
+ return $response;
293
+ }
294
+ }
classes/class-fl-builder-service-convertkit.php ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Helper class for the ConvertKit API.
5
+ *
6
+ * @since 1.5.4
7
+ */
8
+ final class FLBuilderServiceConvertKit extends FLBuilderService {
9
+
10
+ /**
11
+ * The ID for this service.
12
+ *
13
+ * @since 1.5.4
14
+ * @var string $id
15
+ */
16
+ public $id = 'convertkit';
17
+
18
+ /**
19
+ * @since 1.5.4
20
+ * @var object $api_instance
21
+ * @access private
22
+ */
23
+ private $api_instance = null;
24
+
25
+ /**
26
+ * Get an instance of the API.
27
+ *
28
+ * @since 1.5.4
29
+ * @param string $api_key A valid API key.
30
+ * @return object The API instance.
31
+ */
32
+ public function get_api( $api_key )
33
+ {
34
+ if ( $this->api_instance ) {
35
+ return $this->api_instance;
36
+ }
37
+ if ( ! class_exists( 'ConvertKit' ) ) {
38
+ require_once FL_BUILDER_DIR . 'includes/vendor/convertkit/ConvertKit.php';
39
+ }
40
+
41
+ $this->api_instance = new ConvertKit( $api_key );
42
+
43
+ return $this->api_instance;
44
+ }
45
+
46
+ /**
47
+ * Test the API connection.
48
+ *
49
+ * @since 1.5.4
50
+ * @param array $fields {
51
+ * @type string $api_key A valid API key.
52
+ * }
53
+ * @return array{
54
+ * @type bool|string $error The error message or false if no error.
55
+ * @type array $data An array of data used to make the connection.
56
+ * }
57
+ */
58
+ public function connect( $fields = array() )
59
+ {
60
+ $response = array(
61
+ 'error' => false,
62
+ 'data' => array()
63
+ );
64
+
65
+ // Make sure we have an API key.
66
+ if ( ! isset( $fields['api_key'] ) || empty( $fields['api_key'] ) ) {
67
+ $response['error'] = __( 'Error: You must provide an API key.', 'fl-builder' );
68
+ }
69
+ // Try to connect and store the connection data.
70
+ else {
71
+
72
+ $api = $this->get_api( $fields['api_key'] );
73
+
74
+ if ($api->is_authenticated()) {
75
+ $response['data'] = array( 'api_key' => $fields['api_key'] );
76
+ }
77
+ else {
78
+ $response['error'] = sprintf(__( 'Error: Please check your API key. %s', 'fl-builder' ), $api::$response['error_message']);
79
+ }
80
+ }
81
+
82
+ return $response;
83
+ }
84
+
85
+ /**
86
+ * Renders the markup for the connection settings.
87
+ *
88
+ * @since 1.5.4
89
+ * @return string The connection settings markup.
90
+ */
91
+ public function render_connect_settings()
92
+ {
93
+ ob_start();
94
+
95
+ FLBuilder::render_settings_field( 'api_key', array(
96
+ 'row_class' => 'fl-builder-service-connect-row',
97
+ 'class' => 'fl-builder-service-connect-input',
98
+ 'type' => 'text',
99
+ 'label' => __( 'API Key', 'fl-builder' ),
100
+ 'help' => __( 'Your API key can be found in your ConvertKit account under Account > Account Settings > API Key.', 'fl-builder' ),
101
+ 'preview' => array(
102
+ 'type' => 'none'
103
+ )
104
+ ));
105
+
106
+ return ob_get_clean();
107
+ }
108
+
109
+ /**
110
+ * Render the markup for service specific fields.
111
+ *
112
+ * @since 1.5.4
113
+ * @param string $account The name of the saved account.
114
+ * @param object $settings Saved module settings.
115
+ * @return array {
116
+ * @type bool|string $error The error message or false if no error.
117
+ * @type string $html The field markup.
118
+ * }
119
+ */
120
+ public function render_fields( $account, $settings )
121
+ {
122
+ $account_data = $this->get_account_data( $account );
123
+ $api = $this->get_api( $account_data['api_key'] );
124
+ $forms = $api->get_resources('forms');
125
+ $response = array(
126
+ 'error' => false,
127
+ 'html' => ''
128
+ );
129
+
130
+ if ( ! $forms ) {
131
+ $response['error'] = __( 'Error: Please check your API key.', 'fl-builder' );
132
+ }
133
+ else {
134
+ $response['html'] = $this->render_list_field( $forms, $settings );
135
+ }
136
+
137
+ return $response;
138
+ }
139
+
140
+ /**
141
+ * Render markup for the list field.
142
+ *
143
+ * @since 1.5.4
144
+ * @param array $lists List data from the API.
145
+ * @param object $settings Saved module settings.
146
+ * @return string The markup for the list field.
147
+ * @access private
148
+ */
149
+ private function render_list_field( $forms, $settings )
150
+ {
151
+ ob_start();
152
+
153
+ $options = array( '' => __( 'Choose...', 'fl-builder' ) );
154
+
155
+ foreach ( $forms as $form ) {
156
+ $options[ $form['id'] ] = $form['name'];
157
+ }
158
+
159
+ FLBuilder::render_settings_field( 'list_id', array(
160
+ 'row_class' => 'fl-builder-service-field-row',
161
+ 'class' => 'fl-builder-service-list-select',
162
+ 'type' => 'select',
163
+ 'label' => _x( 'List', 'An email list from a third party provider.', 'fl-builder' ),
164
+ 'options' => $options,
165
+ 'preview' => array(
166
+ 'type' => 'none'
167
+ )
168
+ ), $settings);
169
+
170
+ return ob_get_clean();
171
+ }
172
+
173
+ /**
174
+ * Subscribe an email address to ConvertKit.
175
+ *
176
+ * @since 1.5.4
177
+ * @param object $settings A module settings object.
178
+ * @param string $email The email to subscribe.
179
+ * @param string $name Optional. The full name of the person subscribing.
180
+ * @return array {
181
+ * @type bool|string $error The error message or false if no error.
182
+ * }
183
+ */
184
+ public function subscribe( $settings, $email, $name = '' )
185
+ {
186
+ $account_data = $this->get_account_data( $settings->service_account );
187
+ $response = array( 'error' => false );
188
+
189
+ if ( ! $account_data ) {
190
+ $response['error'] = __( 'There was an error subscribing to ConvertKit. The account is no longer connected.', 'fl-builder' );
191
+ }
192
+ else {
193
+
194
+ $api = $this->get_api( $account_data['api_key'] );
195
+
196
+ $result = $api->form_subscribe( $settings->list_id, array('email' => $email, 'fname' => $name) );
197
+ if ($result->status != "created") {
198
+ $response['error'] = __( 'There was an error subscribing to ConvertKit.', 'fl-builder' );
199
+ }
200
+ }
201
+
202
+ return $response;
203
+ }
204
+ }
classes/class-fl-builder-service-drip.php ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Helper class for the Drip API.
5
+ *
6
+ * @since 1.5.4
7
+ */
8
+ final class FLBuilderServiceDrip extends FLBuilderService {
9
+
10
+ /**
11
+ * The ID for this service.
12
+ *
13
+ * @since 1.5.4
14
+ * @var string $id
15
+ */
16
+ public $id = 'drip';
17
+
18
+ /**
19
+ * @since 1.5.4
20
+ * @var object $api_instance
21
+ * @access private
22
+ */
23
+ private $api_instance = null;
24
+
25
+ /**
26
+ * Get an instance of the API.
27
+ *
28
+ * @since 1.5.4
29
+ * @param string $api_key A valid API token.
30
+ * @return object The API instance.
31
+ */
32
+ public function get_api( $api_key )
33
+ {
34
+ if ( $this->api_instance ) {
35
+ return $this->api_instance;
36
+ }
37
+ if ( ! class_exists( 'Drip_Api' ) ) {
38
+ require_once FL_BUILDER_DIR . 'includes/vendor/drip/Drip_API.class.php';
39
+ }
40
+
41
+ $this->api_instance = new Drip_Api( $api_key );
42
+
43
+ return $this->api_instance;
44
+ }
45
+
46
+ /**
47
+ * Test the API connection.
48
+ *
49
+ * @since 1.5.4
50
+ * @param array $fields {
51
+ * @type string $api_key A valid API key.
52
+ * }
53
+ * @return array{
54
+ * @type bool|string $error The error message or false if no error.
55
+ * @type array $data An array of data used to make the connection.
56
+ * }
57
+ */
58
+ public function connect( $fields = array() )
59
+ {
60
+ $response = array(
61
+ 'error' => false,
62
+ 'data' => array()
63
+ );
64
+
65
+ // Make sure we have an API token.
66
+ if ( ! isset( $fields['api_key'] ) || empty( $fields['api_key'] ) ) {
67
+ $response['error'] = __( 'Error: You must provide an API token.', 'fl-builder' );
68
+ }
69
+ // Make sure we have an Account ID.
70
+ elseif ( ! isset( $fields['api_account_id'] ) || empty( $fields['api_account_id'] ) ) {
71
+ $response['error'] = __( 'Error: You must provide an Account ID.', 'fl-builder' );
72
+ }
73
+ // Try to connect and store the connection data.
74
+ else {
75
+ try {
76
+
77
+ $api = $this->get_api( $fields['api_key'] );
78
+ try {
79
+
80
+ $account = $api->fetch_account( $fields['api_account_id'] );
81
+ $error_message = $api->get_error_message();
82
+
83
+ if ( ! empty( $error_message ) ) {
84
+ $response['error'] = $error_message;
85
+ }
86
+ else {
87
+ $response['data'] = array( 'api_key' => $fields['api_key'], 'api_account_id' => $fields['api_account_id'] );
88
+ }
89
+ }
90
+ catch (Exception $e) {
91
+ $response['error'] = sprintf(
92
+ __( 'Error: Please check your Account ID. %s', 'fl-builder' ),
93
+ $e->getMessage()
94
+ );
95
+ }
96
+ }
97
+ catch (Exception $e) {
98
+ $response['error'] = sprintf(
99
+ __( 'Error: Please check your API token. %s', 'fl-builder' ),
100
+ $e->getMessage()
101
+ );
102
+ }
103
+ }
104
+
105
+ return $response;
106
+ }
107
+
108
+ /**
109
+ * Renders the markup for the connection settings.
110
+ *
111
+ * @since 1.5.4
112
+ * @return string The connection settings markup.
113
+ */
114
+ public function render_connect_settings()
115
+ {
116
+ ob_start();
117
+
118
+ FLBuilder::render_settings_field( 'api_key', array(
119
+ 'row_class' => 'fl-builder-service-connect-row',
120
+ 'class' => 'fl-builder-service-connect-input',
121
+ 'type' => 'text',
122
+ 'label' => __( 'API Token', 'fl-builder' ),
123
+ 'description' => sprintf( __( 'Your API Token can be found in your Drip account under Settings > My User Settings. Or, you can click this <a%s>direct link</a>.', 'fl-builder' ), ' href="https://www.getdrip.com/user/edit" target="_blank"' ),
124
+ 'preview' => array(
125
+ 'type' => 'none'
126
+ )
127
+ ));
128
+
129
+ FLBuilder::render_settings_field( 'api_account_id', array(
130
+ 'row_class' => 'fl-builder-service-connect-row',
131
+ 'class' => 'fl-builder-service-connect-input',
132
+ 'type' => 'text',
133
+ 'label' => __( 'Account ID', 'fl-builder' ),
134
+ 'help' => __( 'Your Account ID can be found in your Drip account under Settings > Site Setup.', 'fl-builder' ),
135
+ 'preview' => array(
136
+ 'type' => 'none'
137
+ )
138
+ ));
139
+
140
+ return ob_get_clean();
141
+ }
142
+
143
+ /**
144
+ * Render the markup for service specific fields.
145
+ *
146
+ * @since 1.5.4
147
+ * @param string $account The name of the saved account.
148
+ * @param object $settings Saved module settings.
149
+ * @return array {
150
+ * @type bool|string $error The error message or false if no error.
151
+ * @type string $html The field markup.
152
+ * }
153
+ */
154
+ public function render_fields( $account, $settings )
155
+ {
156
+ $response = array(
157
+ 'error' => false,
158
+ 'html' => $this->render_tag_field( $settings )
159
+ );
160
+
161
+ return $response;
162
+ }
163
+
164
+ /**
165
+ * Render markup for the tag field.
166
+ *
167
+ * @since 1.5.4
168
+ * @param object $settings Saved module settings.
169
+ * @return string The markup for the tag field.
170
+ * @access private
171
+ */
172
+ private function render_tag_field( $settings )
173
+ {
174
+ ob_start();
175
+
176
+ FLBuilder::render_settings_field( 'list_id', array(
177
+ 'row_class' => 'fl-builder-service-field-row',
178
+ 'class' => 'fl-builder-service-list-select',
179
+ 'type' => 'text',
180
+ 'label' => _x( 'Tags', 'A tag to add to contacts in Drip when they subscribe.', 'fl-builder' ),
181
+ 'help' => __('For multiple tags, separate with comma.', 'fl-builder'),
182
+ 'preview' => array(
183
+ 'type' => 'none'
184
+ )
185
+ ), $settings);
186
+
187
+ return ob_get_clean();
188
+ }
189
+
190
+ /**
191
+ * Subscribe an email address to Drip.
192
+ *
193
+ * @since 1.5.4
194
+ * @param object $settings A module settings object.
195
+ * @param string $email The email to subscribe.
196
+ * @param string $name Optional. The full name of the person subscribing.
197
+ * @return array {
198
+ * @type bool|string $error The error message or false if no error.
199
+ * }
200
+ */
201
+ public function subscribe( $settings, $email, $name = '' )
202
+ {
203
+ $account_data = $this->get_account_data( $settings->service_account );
204
+ $response = array( 'error' => false );
205
+ $subscriber_id = null;
206
+
207
+ if ( ! $account_data ) {
208
+ $response['error'] = __( 'There was an error subscribing to Drip. The account is no longer connected.', 'fl-builder' );
209
+ }
210
+ else {
211
+
212
+ $api = $this->get_api( $account_data['api_key'] );
213
+ $args = array(
214
+ 'account_id' => $account_data['api_account_id'],
215
+ 'email' => $email
216
+ );
217
+
218
+ // Check if the contact already exists
219
+ try {
220
+ $result = $api->fetch_subscriber( $args );
221
+
222
+ if ( $result && isset($result['id']) ) {
223
+ $subscriber_id = $result['id'];
224
+ }
225
+
226
+ }
227
+ catch ( Exception $e ) {
228
+ $response['error'] = sprintf(
229
+ __( 'There was an error searching contact from Drip. %s', 'fl-builder' ),
230
+ $e->getMessage()
231
+ );
232
+ return $response;
233
+ }
234
+
235
+ if ( $subscriber_id ) {
236
+ $args['user_id'] = $subscriber_id;
237
+ }
238
+
239
+ if ( $settings->list_id ) {
240
+ $args['tags'] = explode(',', $settings->list_id);
241
+ }
242
+
243
+ if ( $name ) {
244
+ $args['custom_fields'] = array( 'name' => $name );
245
+ }
246
+
247
+ // Create or update contact
248
+ try {
249
+
250
+ $result = $api->create_or_update_subscriber( $args );
251
+ }
252
+ catch ( Exception $e ) {
253
+ $response['error'] = sprintf(
254
+ __( 'There was an error subscribing to Drip. %s', 'fl-builder' ),
255
+ $e->getMessage()
256
+ );
257
+ }
258
+ }
259
+
260
+ return $response;
261
+ }
262
+ }
classes/class-fl-builder-service-mailrelay.php ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Helper class for the Mailrelay API.
5
+ *
6
+ * @since 1.5.4
7
+ */
8
+ final class FLBuilderServiceMailrelay extends FLBuilderService {
9
+
10
+ /**
11
+ * The ID for this service.
12
+ *
13
+ * @since 1.5.4
14
+ * @var string $id
15
+ */
16
+ public $id = 'mailrelay';
17
+
18
+ /**
19
+ * The API url suffix for this service.
20
+ *
21
+ * @since 1.5.8
22
+ * @access private
23
+ * @var string $api_url
24
+ */
25
+ private $api_url = '/ccm/admin/api/version/2/&type=json';
26
+
27
+ /**
28
+ * Request data from the thir party API.
29
+ *
30
+ * @since 1.5.4
31
+ * @param string $base_url Base URL where API is available
32
+ * @param string $method Method to request available from this service.
33
+ * @param array $params Data to be passed to API
34
+ * @return array|object The API response.
35
+ */
36
+ private function get_api_response( $base_url, $params )
37
+ {
38
+ // Exclude http:// for the specific service
39
+ $base_url = preg_replace('#^https?://#', '', $base_url);
40
+ $response = wp_remote_post( 'https://'. $base_url . $this->api_url, array( 'timeout' => 60, 'body' => $params ) );
41
+
42
+ if (is_wp_error($response) || (isset($response->status) && $response->status == 0)) {
43
+ if (isset($response->status)) {
44
+ $data = json_decode($response, true);
45
+ }
46
+ else {
47
+ $data['error'] = $response->get_error_message();
48
+ }
49
+
50
+ } else {
51
+ $data = json_decode(wp_remote_retrieve_body( $response ), true);
52
+ }
53
+ return $data;
54
+ }
55
+
56
+ /**
57
+ * Test the API connection.
58
+ *
59
+ * @since 1.5.4
60
+ * @param array $fields {
61
+ * @type string $api_host A valid Host.
62
+ * @type string $api_key A valid API key.
63
+ * }
64
+ * @return array{
65
+ * @type bool|string $error The error message or false if no error.
66
+ * @type array $data An array of data used to make the connection.
67
+ * }
68
+ */
69
+ public function connect( $fields = array() )
70
+ {
71
+ $response = array(
72
+ 'error' => false,
73
+ 'data' => array()
74
+ );
75
+
76
+ // Make sure we have the Host.
77
+ if ( ! isset( $fields['api_host'] ) || empty( $fields['api_host'] ) ) {
78
+ $response['error'] = __( 'Error: You must provide a Host.', 'fl-builder' );
79
+ }
80
+ // Make sure we have an API key.
81
+ else if ( ! isset( $fields['api_key'] ) || empty( $fields['api_key'] ) ) {
82
+ $response['error'] = __( 'Error: You must provide an API key.', 'fl-builder' );
83
+ }
84
+ // Try to connect and store the connection data.
85
+ else {
86
+
87
+ $result = $this->get_api_response( $fields['api_host'], array(
88
+ 'function' => 'getGroups',
89
+ 'apiKey' => $fields['api_key'],
90
+ 'offset' => 0,
91
+ 'count' => 1
92
+ ) );
93
+
94
+ if (!isset($result['error'])) {
95
+ $response['data'] = array( 'api_host' => $fields['api_host'], 'api_key' => $fields['api_key'] );
96
+ }
97
+ else {
98
+ $response['error'] = sprintf(__( 'Error: Could not connect to Mailrelay. %s', 'fl-builder' ), $result['error']);
99
+ }
100
+ }
101
+
102
+ return $response;
103
+ }
104
+
105
+ /**
106
+ * Renders the markup for the connection settings.
107
+ *
108
+ * @since 1.5.4
109
+ * @return string The connection settings markup.
110
+ */
111
+ public function render_connect_settings()
112
+ {
113
+ ob_start();
114
+
115
+ FLBuilder::render_settings_field( 'api_host', array(
116
+ 'row_class' => 'fl-builder-service-connect-row',
117
+ 'class' => 'fl-builder-service-connect-input',
118
+ 'type' => 'text',
119
+ 'label' => __( 'Host', 'fl-builder' ),
120
+ 'help' => __( 'The host you chose when you signed up for your account. Check your welcome email if you forgot it. Please enter it without the initial http:// (e.g. demo.ip-zone.com).', 'fl-builder' ),
121
+ 'preview' => array(
122
+ 'type' => 'none'
123
+ )
124
+ ));
125
+
126
+ FLBuilder::render_settings_field( 'api_key', array(
127
+ 'row_class' => 'fl-builder-service-connect-row',
128
+ 'class' => 'fl-builder-service-connect-input',
129
+ 'type' => 'text',
130
+ 'label' => __( 'API Key', 'fl-builder' ),
131
+ 'help' => __( 'Your API key can be found in your Mailrelay account under Menu > Settings > API access.', 'fl-builder' ),
132
+ 'preview' => array(
133
+ 'type' => 'none'
134
+ )
135
+ ));
136
+
137
+ return ob_get_clean();
138
+ }
139
+
140
+ /**
141
+ * Render the markup for service specific fields.
142
+ *
143
+ * @since 1.5.4
144
+ * @param string $account The name of the saved account.
145
+ * @param object $settings Saved module settings.
146
+ * @return array {
147
+ * @type bool|string $error The error message or false if no error.
148
+ * @type string $html The field markup.
149
+ * }
150
+ */
151
+ public function render_fields( $account, $settings )
152
+ {
153
+ $account_data = $this->get_account_data( $account );
154
+ $result = $this->get_api_response( $account_data['api_host'], array(
155
+ 'function' => 'getGroups',
156
+ 'apiKey' => $account_data['api_key']
157
+ ) );
158
+
159
+ $response = array(
160
+ 'error' => false,
161
+ 'html' => ''
162
+ );
163
+
164
+ if ( isset($result['error']) ) {
165
+ $response['error'] = sprintf(__( 'Error: Please check your API key. %s', 'fl-builder' ), $result['error']);
166
+ }
167
+ else {
168
+ $response['html'] = $this->render_list_field( $result['data'], $settings );
169
+ }
170
+
171
+ return $response;
172
+ }
173
+
174
+ /**
175
+ * Render markup for the list field.
176
+ *
177
+ * @since 1.5.4
178
+ * @param array $lists List data from the API.
179
+ * @param object $settings Saved module settings.
180
+ * @return string The markup for the list field.
181
+ * @access private
182
+ */
183
+ private function render_list_field( $groups, $settings )
184
+ {
185
+ ob_start();
186
+
187
+ $options = array( '' => __( 'Choose...', 'fl-builder' ) );
188
+
189
+ foreach ( $groups as $group ) {
190
+ $options[ $group['id'] ] = $group['name'];
191
+ }
192
+
193
+ FLBuilder::render_settings_field( 'list_id', array(
194
+ 'row_class' => 'fl-builder-service-field-row',
195
+ 'class' => 'fl-builder-service-list-select',
196
+ 'type' => 'select',
197
+ 'multi-select' => true,
198
+ 'label' => _x( 'Group', 'A list of subscribers group from a Mailrelay account.', 'fl-builder' ),
199
+ 'options' => $options,
200
+ 'preview' => array(
201
+ 'type' => 'none'
202
+ )
203
+ ), $settings);
204
+
205
+ return ob_get_clean();
206
+ }
207
+
208
+ /**
209
+ * Subscribe an email address to Mailrelay.
210
+ *
211
+ * @since 1.5.4
212
+ * @param object $settings A module settings object.
213
+ * @param string $email The email to subscribe.
214
+ * @param string $name Optional. The full name of the person subscribing.
215
+ * @return array {
216
+ * @type bool|string $error The error message or false if no error.
217
+ * }
218
+ */
219
+ public function subscribe( $settings, $email, $name = '' )
220
+ {
221
+ $account_data = $this->get_account_data( $settings->service_account );
222
+ $response = array( 'error' => false );
223
+
224
+ if ( ! $account_data ) {
225
+ $response['error'] = __( 'There was an error subscribing to Mailrelay. The account is no longer connected.', 'fl-builder' );
226
+ }
227
+ else {
228
+
229
+ $result = $this->get_api_response( $account_data['api_host'], array(
230
+ 'function' => 'addSubscriber',
231
+ 'apiKey' => $account_data['api_key'],
232
+ 'email' => $email,
233
+ 'name' => $name,
234
+ 'groups' => $settings->list_id,
235
+ ) );
236
+
237
+ if (isset($result['error'])) {
238
+ $response['error'] = sprintf(__( 'There was an error subscribing to Mailrelay. %s', 'fl-builder' ), $result['error']);
239
+ }
240
+ }
241
+
242
+ return $response;
243
+ }
244
+ }
classes/class-fl-builder-service-sendy.php ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Helper class for the Sendy API.
5
+ *
6
+ * @since 1.5.4
7
+ */
8
+ final class FLBuilderServiceSendy extends FLBuilderService {
9
+
10
+ /**
11
+ * The ID for this service.
12
+ *
13
+ * @since 1.5.4
14
+ * @var string $id
15
+ */
16
+ public $id = 'sendy';
17
+
18
+ /**
19
+ * @since 1.5.4
20
+ * @var object $api_instance
21
+ * @access private
22
+ */
23
+ private $api_instance = null;
24
+
25
+ /**
26
+ * Get an instance of the API.
27
+ *
28
+ * @since 1.5.4
29
+ * @param array $args A valid API authentication data.
30
+ * @return object The API instance.
31
+ */
32
+ public function get_api( array $args )
33
+ {
34
+ if ( $this->api_instance ) {
35
+ return $this->api_instance;
36
+ }
37
+ if ( ! class_exists( '\\SendyPHP\\SendyPHP' ) ) {
38
+ require_once FL_BUILDER_DIR . 'includes/vendor/sendy/SendyPHP.php';
39
+ }
40
+
41
+ $this->api_instance = new \SendyPHP\SendyPHP( $args );
42
+
43
+ return $this->api_instance;
44
+ }
45
+
46
+ /**
47
+ * Test the API connection.
48
+ *
49
+ * @since 1.5.4
50
+ * @param array $fields {
51
+ * @type string $api_host A valid Host.
52
+ * @type string $api_key A valid API key.
53
+ * }
54
+ * @return array{
55
+ * @type bool|string $error The error message or false if no error.
56
+ * @type array $data An array of data used to make the connection.
57
+ * }
58
+ */
59
+ public function connect( $fields = array() )
60
+ {
61
+ $response = array(
62
+ 'error' => false,
63
+ 'data' => array()
64
+ );
65
+
66
+ // Make sure we have the Host.
67
+ if ( ! isset( $fields['api_host'] ) || empty( $fields['api_host'] ) ) {
68
+ $response['error'] = __( 'Error: You must provide your Sendy installation URL.', 'fl-builder' );
69
+ }
70
+ // Make sure we have an API key.
71
+ if ( ! isset( $fields['api_key'] ) || empty( $fields['api_key'] ) ) {
72
+ $response['error'] = __( 'Error: You must provide an API key.', 'fl-builder' );
73
+ }
74
+ // Make sure we have the list ID.
75
+ if ( ! isset( $fields['list_id'] ) || empty( $fields['list_id'] ) ) {
76
+ $response['error'] = __( 'Error: You must provide a list ID.', 'fl-builder' );
77
+ }
78
+ // Try to connect and store the connection data.
79
+ else {
80
+
81
+ $api = $this->get_api( array(
82
+ 'installation_url' => $fields['api_host'],
83
+ 'api_key' => $fields['api_key'],
84
+ 'list_id' => $fields['list_id']
85
+ ) );
86
+
87
+ // Send request for list ID validation
88
+ $get_api_response = $api->subcount();
89
+
90
+ if ( true === $get_api_response['status'] ) {
91
+ $response['data'] = array('api_host' => $fields['api_host'], 'api_key' => $fields['api_key'], 'list_id' => $fields['list_id']);
92
+ }
93
+ else {
94
+ $response['error'] = sprintf(__( 'Error: Could not connect to Sendy. %s', 'fl-builder' ), $get_api_response['message']);
95
+ }
96
+ }
97
+
98
+ return $response;
99
+ }
100
+
101
+ /**
102
+ * Renders the markup for the connection settings.
103
+ *
104
+ * @since 1.5.4
105
+ * @return string The connection settings markup.
106
+ */
107
+ public function render_connect_settings()
108
+ {
109
+ ob_start();
110
+
111
+ FLBuilder::render_settings_field( 'api_host', array(
112
+ 'row_class' => 'fl-builder-service-connect-row',
113
+ 'class' => 'fl-builder-service-connect-input',
114
+ 'type' => 'text',
115
+ 'label' => __( 'Installation URL', 'fl-builder' ),
116
+ 'help' => __( 'The URL where your Sendy application is installed (e.g. http://mywebsite.com/sendy).', 'fl-builder' ),
117
+ 'preview' => array(
118
+ 'type' => 'none'
119
+ )
120
+ ));
121
+
122
+ FLBuilder::render_settings_field( 'api_key', array(
123
+ 'row_class' => 'fl-builder-service-connect-row',
124
+ 'class' => 'fl-builder-service-connect-input',
125
+ 'type' => 'text',
126
+ 'label' => __( 'API Key', 'fl-builder' ),
127
+ 'help' => __( 'Found in your Sendy application under Settings.', 'fl-builder' ),
128
+ 'preview' => array(
129
+ 'type' => 'none'
130
+ )
131
+ ));
132
+
133
+ FLBuilder::render_settings_field( 'list_id', array(
134
+ 'row_class' => 'fl-builder-service-connect-row',
135
+ 'class' => 'fl-builder-service-connect-input',
136
+ 'type' => 'text',
137
+ 'label' => __( 'List ID', 'fl-builder' ),
138
+ 'help' => __( 'The ID of the list you would like users to subscribe to. The ID of a list can be found under "View all lists" in the section named ID.', 'fl-builder' ),
139
+ 'preview' => array(
140
+ 'type' => 'none'
141
+ )
142
+ ));
143
+
144
+ return ob_get_clean();
145
+ }
146
+
147
+ /**
148
+ * Render the markup for service specific fields.
149
+ *
150
+ * @since 1.5.4
151
+ * @param string $account The name of the saved account.
152
+ * @param object $settings Saved module settings.
153
+ * @return array {
154
+ * @type bool|string $error The error message or false if no error.
155
+ * @type string $html The field markup.
156
+ * }
157
+ */
158
+ public function render_fields( $account, $settings )
159
+ {
160
+
161
+ $response = array(
162
+ 'error' => false,
163
+ 'html' => ''
164
+ );
165
+
166
+ return $response;
167
+ }
168
+
169
+ /**
170
+ * Subscribe an email address to Sendy.
171
+ *
172
+ * @since 1.5.4
173
+ * @param object $settings A module settings object.
174
+ * @param string $email The email to subscribe.
175
+ * @param string $name Optional. The full name of the person subscribing.
176
+ * @return array {
177
+ * @type bool|string $error The error message or false if no error.
178
+ * }
179
+ */
180
+ public function subscribe( $settings, $email, $name = '' )
181
+ {
182
+ $account_data = $this->get_account_data( $settings->service_account );
183
+ $response = array( 'error' => false );
184
+
185
+ if ( ! $account_data ) {
186
+ $response['error'] = __( 'There was an error subscribing to Sendy. The account is no longer connected.', 'fl-builder' );
187
+ }
188
+ else {
189
+
190
+ $api = $this->get_api( array(
191
+ 'installation_url' => $account_data['api_host'],
192
+ 'api_key' => $account_data['api_key'],
193
+ 'list_id' => $account_data['list_id']
194
+ ) );
195
+
196
+ // Send request for list ID validation
197
+ $get_api_response = $api->subscribe(array('name' => $name, 'email' => $email));
198
+
199
+ if ( false === $get_api_response['status'] ) {
200
+ $response['error'] = sprintf(__( 'There was an error subscribing to Sendy. %s', 'fl-builder' ), $get_api_response['message']);
201
+ }
202
+ }
203
+
204
+ return $response;
205
+ }
206
+ }
classes/class-fl-builder-services.php CHANGED
@@ -30,11 +30,26 @@ final class FLBuilderServices {
30
  'name' => 'Campaign Monitor',
31
  'class' => 'FLBuilderServiceCampaignMonitor'
32
  ),
 
 
 
 
 
33
  'constant-contact' => array(
34
  'type' => 'autoresponder',
35
  'name' => 'Constant Contact',
36
  'class' => 'FLBuilderServiceConstantContact'
37
  ),
 
 
 
 
 
 
 
 
 
 
38
  'email-address' => array(
39
  'type' => 'autoresponder',
40
  'name' => 'Email Address',
@@ -75,10 +90,20 @@ final class FLBuilderServices {
75
  'name' => 'MailPoet',
76
  'class' => 'FLBuilderServiceMailPoet'
77
  ),
 
 
 
 
 
78
  'sendinblue' => array(
79
  'type' => 'autoresponder',
80
  'name' => 'SendinBlue',
81
  'class' => 'FLBuilderServiceSendinBlue'
 
 
 
 
 
82
  )
83
  );
84
 
30
  'name' => 'Campaign Monitor',
31
  'class' => 'FLBuilderServiceCampaignMonitor'
32
  ),
33
+ 'campayn' => array(
34
+ 'type' => 'autoresponder',
35
+ 'name' => 'Campayn',
36
+ 'class' => 'FLBuilderServiceCampayn'
37
+ ),
38
  'constant-contact' => array(
39
  'type' => 'autoresponder',
40
  'name' => 'Constant Contact',
41
  'class' => 'FLBuilderServiceConstantContact'
42
  ),
43
+ 'convertkit' => array(
44
+ 'type' => 'autoresponder',
45
+ 'name' => 'ConvertKit',
46
+ 'class' => 'FLBuilderServiceConvertKit'
47
+ ),
48
+ 'drip' => array(
49
+ 'type' => 'autoresponder',
50
+ 'name' => 'Drip',
51
+ 'class' => 'FLBuilderServiceDrip'
52
+ ),
53
  'email-address' => array(
54
  'type' => 'autoresponder',
55
  'name' => 'Email Address',
90
  'name' => 'MailPoet',
91
  'class' => 'FLBuilderServiceMailPoet'
92
  ),
93
+ 'mailrelay' => array(
94
+ 'type' => 'autoresponder',
95
+ 'name' => 'Mailrelay',
96
+ 'class' => 'FLBuilderServiceMailrelay'
97
+ ),
98
  'sendinblue' => array(
99
  'type' => 'autoresponder',
100
  'name' => 'SendinBlue',
101
  'class' => 'FLBuilderServiceSendinBlue'
102
+ ),
103
+ 'sendy' => array(
104
+ 'type' => 'autoresponder',
105
+ 'name' => 'Sendy',
106
+ 'class' => 'FLBuilderServiceSendy'
107
  )
108
  );
109
 
classes/class-fl-builder.php CHANGED
@@ -30,17 +30,17 @@ final class FLBuilder {
30
  $locale = apply_filters( 'plugin_locale', get_locale(), 'fl-builder' );
31
 
32
  //Setup paths to current locale file
 
33
  $mofile_local = trailingslashit( FL_BUILDER_DIR ) . 'languages/' . $locale . '.mo';
34
- $mofile_global = trailingslashit( WP_LANG_DIR ) . 'plugins/beaver-builder/' . $locale . '.mo';
35
 
36
- if ( file_exists( $mofile_local ) ) {
37
- //Look in local /wp-content/plugins/beaver-builder/languages/ folder
38
- return load_textdomain( 'fl-builder', $mofile_local );
39
- }
40
- else if ( file_exists( $mofile_global ) ) {
41
- //Look in global /wp-content/languages/plugins/beaver-builder/ folder
42
  return load_textdomain( 'fl-builder', $mofile_global );
43
  }
 
 
 
 
44
 
45
  //Nothing found
46
  return false;
@@ -761,7 +761,7 @@ final class FLBuilder {
761
  // Do the wp_enqueue_scripts action here to register any scripts or
762
  // styles that might need to be registered for shortcodes or widgets.
763