PluginProbe
GetResponse Forms by Optin Cat / 2.0.0
GetResponse Forms by Optin Cat v2.0.0
1.3.4 1.3.5 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 2.0.0 All 36 releases
getresponse / includes / eoi-functions.php

eoi-functions.php in GetResponse Forms by Optin Cat 2.0.0, at includes/eoi-functions.php

461 lines 15.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 require_once FCA_EOI_PLUGIN_DIR . 'includes/classes/k/k.php';
4
5
6 function fca_eoi_tooltip ( $text = 'Tooltip', $icon = 'dashicons dashicons-editor-help' ) {
7 return "<span class='$icon fca_eoi_tooltip' title='" . htmlentities( $text ) . "'></span>";
8 }
9
10
11 /* REMOVE LINKS FOR USERS WITH FEWER PERMISSIONS THAN EDITOR */
12
13 function fca_eoi_remove_admin_bar_link() {
14 if (!current_user_can( 'delete_others_pages' ) && function_exists( 'remove_meta_box' )){
15 remove_meta_box( 'fca_eoi_dashboard_widget', 'dashboard', 'normal' );
16 }
17 }
18 add_action( 'wp_dashboard_setup', 'fca_eoi_remove_admin_bar_link', 50 );
19
20 function fca_eoi_get_error_texts($post_meta) {
21
22 $name_error = empty ( $post_meta[ 'error_text_field_required' ] ) ? "Please enter a valid email address. For example \"hi@fatcatapps.com\"." : $post_meta[ 'error_text_field_required' ];
23 $email_error = empty ( $post_meta[ 'error_text_invalid_email' ] ) ? 'Please fill out this field to continue.' : $post_meta[ 'error_text_invalid_email' ];
24
25 $errorTexts = array(
26 'field_required' => $name_error,
27 'invalid_email' => $email_error,
28 );
29
30 return $errorTexts;
31 }
32
33 function fca_eoi_get_thanks_mode($post_meta) {
34
35 $mode = empty ( $post_meta[ 'thankyou_page_mode' ] ) ? 'ajax' : $post_meta[ 'thankyou_page_mode' ];
36 return $mode;
37 }
38
39
40 //CHECK IF USER HAS AN ACTIVE CUSTOM FORM IN ONE OF THEIR OPT INS, OTHERWISE TURN OFF THIS FEATURE
41 function fca_eoi_set_custom_form_depreciation() {
42
43 $optins_using_customform = get_posts( array(
44 'post_type' => 'easy-opt-ins',
45 'posts_per_page' => -1,
46 'post_status' => 'any',
47 'meta_key' => 'fca_eoi_provider',
48 'meta_value' => 'customform',
49
50 ));
51
52 $forms_in_trash = get_posts( array(
53 'post_type' => 'easy-opt-ins',
54 'posts_per_page' => -1,
55 'post_status' => 'trash',
56 'meta_key' => 'fca_eoi_provider',
57 'meta_value' => 'customform',
58
59 ));
60
61 if ( count ( $optins_using_customform ) > 0 OR count ( $forms_in_trash ) > 0) {
62 update_option ( 'fca_eoi_allow_customform', 'true' );
63 } else {
64 update_option ( 'fca_eoi_allow_customform', 'false' );
65 }
66
67 }
68
69 function fca_eoi_get_html( $form_id, $fca_eoi_meta ) {
70
71 $selected_layout = $fca_eoi_meta[ 'layout' ];
72
73 if( empty( $selected_layout ) OR empty ( $fca_eoi_meta ) ) {
74 return 'Form data missing';
75 }
76
77 $list_ids = array ( 'mailchimp_list_id', 'campaignmonitor_list_id', 'getresponse_list_id', 'aweber_list_id', 'drip_list_id' );
78 $list_id = 'Not Set';
79
80 forEach ($list_ids as $id ) {
81 if ( !empty ($fca_eoi_meta[$id]) ) {
82 $list_id = $fca_eoi_meta[$id];
83 break;
84 }
85 }
86
87 $errorTexts = fca_eoi_get_error_texts($fca_eoi_meta);
88
89 //determine if ajax or thank you page redirect
90 $thanks_mode = fca_eoi_get_thanks_mode($fca_eoi_meta);
91 if ( $thanks_mode === 'redirect' ) {
92 $mode = empty ( $fca_eoi_meta[ 'redirect_page_mode' ] ) ? 'page' : $fca_eoi_meta[ 'redirect_page_mode' ];
93 $home_url = get_site_url();
94 if ( $mode === 'page' ) {
95 $thanks_page = get_permalink( K::get_var( 'thank_you_page', $fca_eoi_meta, $home_url ) );
96 } else {
97 $thanks_page = empty ( $fca_eoi_meta[ 'thank_you_url' ] ) ? $home_url : $fca_eoi_meta[ 'thank_you_url' ];
98 }
99
100 } else {
101 $thanks_page = htmlentities ( K::get_var( 'thankyou_ajax', $fca_eoi_meta, 'Thank you! Please check your inbox for your confirmation email.' ), ENT_QUOTES, "UTF-8");
102 }
103
104 $sub_msg = htmlentities ( K::get_var( 'subscribing_message', $fca_eoi_meta, 'Subscribing...' ), ENT_QUOTES, "UTF-8");
105
106 $cookie_dur = K::get_var( 'success_duration', $fca_eoi_meta['publish_lightbox'], 0 );
107
108 $layout_helper = new EasyOptInsLayout( $selected_layout );
109 $php_path = $layout_helper->path_to_resource( 'layout', 'php' );
110 $html_path = $layout_helper->path_to_resource( 'layout', 'html' );
111 $html_wrap_path = $layout_helper->path_to_html_wrapper();
112 $scss_path = $layout_helper->path_to_resource( 'layout', 'scss' );
113
114 $form_wrapper = '';
115 $form_wrapper_end = '';
116
117 if ( $layout_helper->layout_type != 'lightbox' ) {
118 $form_wrapper =
119 '<div class="' .
120 'fca_eoi_form_wrapper ' .
121 $layout_helper->layout_class . '_wrapper ' .
122 'fca_eoi_layout_' . $layout_helper->layout_number . '_wrapper' .
123 '">';
124 $form_wrapper_end = '</div>';
125 }
126
127 //SET UP TEMPLATE
128
129 $layout_html = str_replace('{{{layout}}}', file_get_contents( $html_path ), file_get_contents( $html_wrap_path ));
130
131 global $dh_easy_opt_ins_plugin;
132
133 if ( $dh_easy_opt_ins_plugin->post_type_obj->settings[ 'distribution' ] === 'free' ) {
134 $banding = K::get_var( 'show_fatcatapps_link', $fca_eoi_meta, false );
135 $banding = $banding ? "<div class='fca_eoi_layout_fatcatapps_link_wrapper fca_eoi_form_text_element'><a href='https://fatcatapps.com/optincat/' target='_blank'>Powered by Optin Cat</a></div>" : '';
136 } else {
137 $banding = '';
138 }
139
140 $animation = get_post_meta( $form_id, 'fca_eoi_animation', true );
141 $animation_class = ( empty ( $animation ) || $animation == 'None' ) ? '' : "animated $animation";
142
143 if ( $layout_helper->layout_type === 'banner' ) {
144 $push_page = K::get_var( 'push_page', $fca_eoi_meta, on );
145 $toggle_position = K::get_var( 'toggle_overlay_position', $fca_eoi_meta, 'off' );
146
147 if ( $push_page === 'on' && $toggle_position === 'off' ) {
148 $push_page = 'down';
149 }
150
151 if ( $push_page === 'on' && $toggle_position === 'on' ) {
152 $push_page = 'up';
153 }
154 }
155
156 $form_head = $form_wrapper;
157 $form_head .= "<div id='fca_eoi_form_$form_id' class='fca_eoi_form_content'>";
158 $form_head .= "<form method='post' action='#' class='fca_eoi_form fca_eoi_layout_$layout_helper->layout_number $layout_helper->layout_class $animation_class' ";
159 $form_head .= "data-fca_eoi_list_id='$list_id' data-fca_eoi_push_page='$push_page' data-fca_eoi_success_cookie_duration='$cookie_dur' data-fca_eoi_thank_you_page='$thanks_page' data-fca_eoi_thank_you_mode='$thanks_mode' data-fca_eoi_sub_msg='$sub_msg' novalidate>";
160 $form_head .= "<input type='hidden' id='fca_eoi_form_id' name='fca_eoi_form_id' value='$form_id'>";
161
162 //FILL TEMPLATE
163 $layout_html = str_replace(
164 array(
165 '<form>',
166 '{{{description_copy}}}',
167 '{{{headline_copy}}}',
168 '{{{name_field}}}',
169 '{{{email_field}}}',
170 '{{{submit_button}}}',
171 '{{{privacy_copy}}}',
172 '{{{fatcatapps_link}}}',
173 '</form>',
174 ),
175 array(
176 $form_head,
177 '<div>{{{description_copy}}}</div>',
178 '<div>{{{headline_copy}}}</div>',
179 "<input class='fca_eoi_form_input_element' type='text' name='name' placeholder='{{{name_placeholder}}}'>",
180 '<input class="fca_eoi_form_input_element" type="email" name="email" placeholder="{{{email_placeholder}}}">',
181 '<input class="fca_eoi_form_button_element" type="submit" value="{{{button_copy}}}">',
182 '<div>{{{privacy_copy}}}</div>',
183 $banding,
184 '<input type="hidden" name="fca_eoi" value="1">
185 <input type="hidden" name="fca_eoi_error_texts_email" class="fca_eoi_error_texts_email" value="' . htmlspecialchars ($errorTexts['invalid_email']) . '">
186 <input type="hidden" name="fca_eoi_error_texts_required" class="fca_eoi_error_texts_required" value="' . htmlspecialchars ($errorTexts['field_required']) . '"></form></div>' . $form_wrapper_end,
187 ),
188 $layout_html
189 );
190
191 //ADD TEXTS
192 $show_headline = K::get_var( 'show_headline_field', $fca_eoi_meta, 'on' );
193 $show_description = K::get_var( 'show_description_field', $fca_eoi_meta, 'on' );
194 $show_privacy = K::get_var( 'show_privacy_field', $fca_eoi_meta, 'on' );
195
196 $headline_copy = $show_headline == 'off' ? '' : $fca_eoi_meta[ 'headline_copy' ];
197 $description_copy = $show_description == 'off' ? '' : $fca_eoi_meta[ 'description_copy' ];
198
199 $name_placeholder = $fca_eoi_meta[ 'name_placeholder' ];
200 $email_placeholder = $fca_eoi_meta[ 'email_placeholder' ];
201
202 $button_copy = $fca_eoi_meta[ 'button_copy' ];
203 $privacy_copy = $show_privacy == 'off' ? '' : $fca_eoi_meta[ 'privacy_copy' ];
204
205 $output = str_replace(
206 array(
207 '{{{headline_copy}}}',
208 '{{{description_copy}}}',
209 '{{{name_placeholder}}}',
210 '{{{email_placeholder}}}',
211 '{{{button_copy}}}',
212 '{{{privacy_copy}}}',
213 ),
214 array(
215 $headline_copy,
216 $description_copy,
217 $name_placeholder,
218 $email_placeholder,
219 $button_copy,
220 $privacy_copy,
221 ),
222 $layout_html
223 );
224
225 $output = apply_filters( 'fca_eoi_alter_form', $output, $fca_eoi_meta );
226
227 return $output;
228 }
229
230 //ADD KEYUP ACTION TO TINY MCE VISUAL EDITOR
231 function fca_eoi_tiny_mce_before_init( $initArray ) {
232 global $post;
233 if ( is_object ( $post ) && $post->post_type == 'easy-opt-ins' ) {
234 $initArray['setup'] = <<<JS
235 [function(ed) {
236 ed.on('keyup', function(ed, e) {
237 jQuery('[name="fca_eoi[description_copy]"]').html(tinymce.activeEditor.getContent()).trigger('keyup')
238 });
239
240 }][0]
241 JS;
242 return $initArray;
243 } else {
244 return $initArray;
245 }
246 }
247 add_filter( 'tiny_mce_before_init', 'fca_eoi_tiny_mce_before_init' );
248
249 //CONVERTS OLD EDITOR SAVE FORMAT TO NEW FORMAT
250 function fca_eoi_convert_post_meta() {
251 require_once FCA_EOI_PLUGIN_DIR . 'includes/eoi-layout.php';
252
253 $args = array(
254 'post_type' => 'easy-opt-ins',
255 'post_status' => 'publish',
256 'posts_per_page'=> -1,
257 );
258
259 $posts_array = get_posts( $args );
260
261 $settings = array (
262 'form_background_color_selector' => 'background-color',
263 'form_border_color_selector' => 'border-color',
264 'headline_font_size_selector' => 'font-size',
265 'headline_font_color_selector' => 'color',
266 'headline_background_color_selector' => 'background-color',
267 'description_font_size_selector' => 'font-size',
268 'description_font_color_selector' => 'color',
269 'name_font_size_selector' => 'font-size',
270 'name_font_color_selector' => 'color',
271 'name_background_color_selector' => 'background-color',
272 'name_border_color_selector' => 'border-color',
273 'email_font_size_selector' => 'font-size',
274 'email_font_color_selector' => 'color',
275 'email_background_color_selector' => 'background-color',
276 'email_border_color_selector' => 'border-color',
277 'button_font_size_selector' => 'font-size',
278 'button_font_color_selector' => 'color',
279 'button_background_color_selector' => 'background-color',
280 'button_wrapper_background_color_selector' => 'background-color',
281 'privacy_font_size_selector' => 'font-size',
282 'privacy_font_color_selector' => 'color',
283 'branding_font_color_selector' => 'color',
284
285 );
286
287 forEach ( $posts_array as $post ) {
288 $form_id = $post->ID;
289 $version = get_post_meta( $post->ID, 'fca_eoi_meta_format', true );
290
291 //ONLY CONVERT OLD VERSIONS
292 if ( $version != '2.0' ) {
293 $meta = get_post_meta( $post->ID, 'fca_eoi', true );
294 //FIX FOR EMPTY LAYOUT? SET THE DEFAULT
295 $layout = empty ( $meta['layout'] ) ? 'postbox_1' : $meta['layout'];
296 $new_meta['layout'] = $layout;
297
298 $new_meta = $meta;
299 unset ( $new_meta[$layout] );
300
301 $i = 0;
302
303 forEach ( $meta[$layout] as $selector => $array ) {
304 $type = '';
305
306 if ( $i == 0 ) {
307 $type = 'form';
308 } else if ( strpos($selector, 'headline') !== false ) {
309 $type = 'headline';
310 } else if ( strpos($selector, 'description') !== false ) {
311 $type = 'description';
312 } else if ( strpos($selector, 'name') !== false ) {
313 $type = 'name';
314 } else if ( strpos($selector, 'email') !== false ) {
315 $type = 'email';
316 } else if ( strpos($selector, 'submit_button_wrapper input:hover') !== false ) {
317 $type = 'hover';
318 } else if ( strpos($selector, 'submit_button_wrapper input') !== false && strpos($selector, 'hover') === false ) {
319 $type = 'button';
320 } else if ( strpos($selector, 'privacy') !== false ) {
321 $type = 'privacy';
322 } else if ( strpos($selector, 'fatcatapps') !== false ) {
323 $type = 'branding';
324 }
325
326 forEach ($array as $css_property => $value ) {
327 if ( !empty ( $type ) ) {
328
329 if ( $type == 'hover' ) {
330
331 $new_meta['button_wrapper_background_color_selector'] = '.fca_eoi_layout_submit_button_wrapper';
332 $new_meta['button_wrapper_background_color'] = $value;
333
334 } else {
335
336 $new_key = $type . '_' . str_replace ('-', '_', $css_property) . '_selector';
337 if ( strpos( $new_key, 'color' ) !== false && strpos( $new_key, 'border' ) === false && strpos( $new_key, 'background' ) === false ) {
338 $new_key = str_replace ('_color', '_font_color', $new_key);
339 }
340 $new_meta[trim($new_key)] = $selector;
341
342 $new_value_key = $type . '_' . str_replace ('-', '_', $css_property);
343
344 if ( strpos( $new_value_key, 'color' ) !== false && strpos( $new_value_key, 'border' ) === false && strpos( $new_value_key, 'background' ) === false ) {
345 $new_value_key = str_replace ('_color', '_font_color', $new_value_key);
346 }
347
348 $new_meta[trim($new_value_key)] = $value;
349 }
350 }
351 }
352
353 $i++;
354 }
355
356 //SOME SPECIAL CASES
357 if ( empty ( $new_meta['email_font_size'] ) ) {
358 $new_meta['email_font_size_selector'] = 'div.fca_eoi_layout_email_field_wrapper';
359 $new_meta['email_font_size'] = '13px';
360 }
361 if ( empty ( $new_meta['name_font_size'] ) ) {
362 $new_meta['name_font_size_selector'] = 'div.fca_eoi_layout_name_field_wrapper';
363 $new_meta['name_font_size'] = '13px';
364 }
365
366 //POSSIBLE FIX FOR PUBLICATION MODE
367 if ( stripos ( $new_meta[ 'layout' ], 'lightbox') === FALSE && array_key_exists( 'publish_lightbox_mode', $new_meta )) {
368 unset ( $new_meta['publish_lightbox_mode'] );
369 }
370
371 //COMPILE CSS AND SAVE INTO 'HEAD' META
372
373 // General CSS for all forms
374 $css = "<style type='text/css' class='fca-eoi-style'>.fca_eoi_form{ margin: auto; } .fca_eoi_form p { width: auto; } #fca_eoi_form_$form_id input{ max-width: 9999px; }";
375
376 // CACHE (ALMSOT) ALL THE OUTPUT HERE
377 $layout_helper = new EasyOptInsLayout( $new_meta[ 'layout' ] );
378 $scss_path = $layout_helper->path_to_resource( 'layout', 'scss' );
379
380 if ( file_exists( $scss_path ) ) {
381 $css_path = str_replace ( '.scss' , '_min.css', $scss_path );
382 $css_file = file_get_contents( $css_path );
383 }
384
385 $show_name = !empty( $new_meta['show_name_field'] ) ? $new_meta['show_name_field'] : false;
386
387 if ( !$show_name ) {
388 $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_email_field_wrapper {width: 100% !important;}";
389 $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_name_field_wrapper {display: none !important;}";
390 }
391
392 //ADD CSS FROM FILE
393 $css .= $css_file;
394
395 //ADD CUSTOM CSS FROM SAVE
396 $added_widget_3_css_rule = false;
397
398 foreach ( $settings as $key => $property ) {
399 $input = str_replace ( '_selector', '', $key);
400
401 $selector = empty ( $new_meta[$key] ) ? '' : $new_meta[$key];
402
403 if ( !empty ( $selector ) ) {
404
405
406 //SPECIAL CASE FOR WIDGET 3
407 if ( $selector == '.fca_eoi_layout_3.fca_eoi_layout_widget div.fca_eoi_layout_headline_copy_wrapper div' && !$added_widget_3_css_rule && $input == 'headline_background_color' ) {
408 $css .= "#fca_eoi_form_$form_id form.fca_eoi_layout_3.fca_eoi_layout_widget svg.fca_eoi_layout_headline_copy_triangle { fill: $new_meta[$input] !important; }";
409 $added_widget_3_css_rule = true;
410 }
411
412 $css .= "#fca_eoi_form_$form_id $selector { $property: $new_meta[$input] !important; }";
413 }
414 }
415
416 $head = $css . '</style>';
417
418 $html = fca_eoi_get_html ( $form_id, $new_meta );
419
420 $head = $head . $html;
421
422 update_post_meta( $post->ID, 'fca_eoi', $new_meta );
423 update_post_meta( $post->ID, 'fca_eoi_meta_format', '2.0' );
424 update_post_meta( $post->ID, 'fca_eoi_head', $head );
425
426 }
427 }
428 }
429
430 function fca_eoi_convert_option_save() {
431
432 $old_options = get_option('paf');
433 $license = get_option('fca_eoi_license_key');
434
435 $new_options = array(
436 'license_key' => $license,
437 );
438
439 $options = array (
440
441 'eoi_powerup_custom_css' => 'custom_css',
442 'eoi_powerup_optin_bait' => 'optin_bait',
443 'eoi_powerup_animation' => 'animation',
444 'eoi_powerup_mp_groups' => 'mailchimp_groups',
445
446 );
447
448 if ( !empty( $old_options ) ) {
449 forEach ( $options as $key => $value ) {
450 if ( !empty ( $old_options[$key] ) && $old_options[$key][0] == 'on' ) {
451 $new_options[$value] = 1;
452 }
453 }
454
455 update_option( 'fca_eoi_settings', $new_options );
456 delete_option ( 'paf' );
457 delete_option ( 'fca_eoi_license_key' );
458
459 }
460
461 }