PluginProbe
GetResponse Forms by Optin Cat / 1.8.0
GetResponse Forms by Optin Cat v1.8.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 1.8.0, at includes/eoi-functions.php

443 lines 15.1 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 $layout_helper = new EasyOptInsLayout( $selected_layout );
107 $php_path = $layout_helper->path_to_resource( 'layout', 'php' );
108 $html_path = $layout_helper->path_to_resource( 'layout', 'html' );
109 $html_wrap_path = $layout_helper->path_to_html_wrapper();
110 $scss_path = $layout_helper->path_to_resource( 'layout', 'scss' );
111
112 $form_wrapper = '';
113 $form_wrapper_end = '';
114
115 if ( $layout_helper->layout_type != 'lightbox' ) {
116 $form_wrapper =
117 '<div class="' .
118 'fca_eoi_form_wrapper ' .
119 $layout_helper->layout_class . '_wrapper ' .
120 'fca_eoi_layout_' . $layout_helper->layout_number . '_wrapper' .
121 '">';
122 $form_wrapper_end = '</div>';
123 }
124
125 //SET UP TEMPLATE
126
127 $layout_html = str_replace('{{{layout}}}',file_get_contents( $html_path ),file_get_contents( $html_wrap_path ));
128
129 global $dh_easy_opt_ins_plugin;
130
131 if ( $dh_easy_opt_ins_plugin->post_type_obj->settings[ 'distribution' ] === 'free' ) {
132 $banding = K::get_var( 'show_fatcatapps_link', $fca_eoi_meta, false );
133 $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>" : '';
134 } else {
135 $banding = '';
136 }
137
138 $form_head = $form_wrapper;
139 $form_head .= "<div id='fca_eoi_form_$form_id' class='fca_eoi_form_content'>";
140 $form_head .= "<form method='post' action='#' class='fca_eoi_form fca_eoi_layout_$layout_helper->layout_number $layout_helper->layout_class' ";
141 $form_head .= "data-fca_eoi_list_id='$list_id' data-fca_eoi_thank_you_page='$thanks_page' data-fca_eoi_thank_you_mode='$thanks_mode' data-fca_eoi_sub_msg='$sub_msg' novalidate>";
142 $form_head .= "<input type='hidden' id='fca_eoi_form_id' name='fca_eoi_form_id' value='$form_id'>";
143
144 //FILL TEMPLATE
145 $layout_html = str_replace(
146 array(
147 '<form>',
148 '{{{description_copy}}}',
149 '{{{headline_copy}}}',
150 '{{{name_field}}}',
151 '{{{email_field}}}',
152 '{{{submit_button}}}',
153 '{{{privacy_copy}}}',
154 '{{{fatcatapps_link}}}',
155 '</form>',
156 ),
157 array(
158 $form_head,
159 '<div>{{{description_copy}}}</div>',
160 '<div>{{{headline_copy}}}</div>',
161 "<input class='fca_eoi_form_input_element' type='text' name='name' placeholder='{{{name_placeholder}}}'>",
162 '<input class="fca_eoi_form_input_element" type="email" name="email" placeholder="{{{email_placeholder}}}">',
163 '<div class="fca_eoi_spiner_div"><span class="fca_eoi_loading_spinner"></span></div><input class="fca_eoi_form_button_element" type="submit" value="{{{button_copy}}}">',
164 '<div>{{{privacy_copy}}}</div>',
165 $banding,
166 '<input type="hidden" name="fca_eoi" value="1">
167 <input type="hidden" name="fca_eoi_error_texts_email" class="fca_eoi_error_texts_email" value="' . htmlspecialchars ($errorTexts['invalid_email']) . '">
168 <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,
169 ),
170 $layout_html
171 );
172
173 //ADD TEXTS
174 $show_headline = K::get_var( 'show_headline_field', $fca_eoi_meta, 'on' );
175 $show_description = K::get_var( 'show_description_field', $fca_eoi_meta, 'on' );
176 $show_privacy = K::get_var( 'show_privacy_field', $fca_eoi_meta, 'on' );
177
178 $headline_copy = $show_headline == 'off' ? '' : $fca_eoi_meta[ 'headline_copy' ];
179 $description_copy = $show_description == 'off' ? '' : $fca_eoi_meta[ 'description_copy' ];
180
181 $name_placeholder = $fca_eoi_meta[ 'name_placeholder' ];
182 $email_placeholder = $fca_eoi_meta[ 'email_placeholder' ];
183
184 $button_copy = $fca_eoi_meta[ 'button_copy' ];
185 $privacy_copy = $show_privacy == 'off' ? '' : $fca_eoi_meta[ 'privacy_copy' ];
186
187 $output = str_replace(
188 array(
189 '{{{headline_copy}}}',
190 '{{{description_copy}}}',
191 '{{{name_placeholder}}}',
192 '{{{email_placeholder}}}',
193 '{{{button_copy}}}',
194 '{{{privacy_copy}}}',
195 ),
196 array(
197 $headline_copy,
198 $description_copy,
199 $name_placeholder,
200 $email_placeholder,
201 $button_copy,
202 $privacy_copy,
203 ),
204 $layout_html
205 );
206
207 $output = apply_filters( 'fca_eoi_alter_form', $output, $fca_eoi_meta );
208
209 return $output;
210 }
211
212 //ADD KEYUP ACTION TO TINY MCE VISUAL EDITOR
213 function fca_eoi_tiny_mce_before_init( $initArray ) {
214 global $post;
215 if ( is_object ( $post ) && $post->post_type == 'easy-opt-ins' ) {
216 $initArray['setup'] = <<<JS
217 [function(ed) {
218 ed.on('keyup', function(ed, e) {
219 jQuery('[name="fca_eoi[description_copy]"]').html(tinymce.activeEditor.getContent()).trigger('keyup')
220 });
221
222 }][0]
223 JS;
224 return $initArray;
225 } else {
226 return $initArray;
227 }
228 }
229 add_filter( 'tiny_mce_before_init', 'fca_eoi_tiny_mce_before_init' );
230
231 //CONVERTS OLD EDITOR SAVE FORMAT TO NEW FORMAT
232 function fca_eoi_convert_post_meta() {
233 require_once FCA_EOI_PLUGIN_DIR . 'includes/eoi-layout.php';
234
235 $args = array(
236 'post_type' => 'easy-opt-ins',
237 'post_status' => 'publish',
238 'posts_per_page'=> -1,
239 );
240
241 $posts_array = get_posts( $args );
242
243 $settings = array (
244 'form_background_color_selector' => 'background-color',
245 'form_border_color_selector' => 'border-color',
246 'headline_font_size_selector' => 'font-size',
247 'headline_font_color_selector' => 'color',
248 'headline_background_color_selector' => 'background-color',
249 'description_font_size_selector' => 'font-size',
250 'description_font_color_selector' => 'color',
251 'name_font_size_selector' => 'font-size',
252 'name_font_color_selector' => 'color',
253 'name_background_color_selector' => 'background-color',
254 'name_border_color_selector' => 'border-color',
255 'email_font_size_selector' => 'font-size',
256 'email_font_color_selector' => 'color',
257 'email_background_color_selector' => 'background-color',
258 'email_border_color_selector' => 'border-color',
259 'button_font_size_selector' => 'font-size',
260 'button_font_color_selector' => 'color',
261 'button_background_color_selector' => 'background-color',
262 'button_wrapper_background_color_selector' => 'background-color',
263 'privacy_font_size_selector' => 'font-size',
264 'privacy_font_color_selector' => 'color',
265 'branding_font_color_selector' => 'color',
266
267 );
268
269 forEach ( $posts_array as $post ) {
270 $form_id = $post->ID;
271 $version = get_post_meta( $post->ID, 'fca_eoi_meta_format', true );
272
273 //ONLY CONVERT OLD VERSIONS
274 if ( $version != '2.0' ) {
275 $meta = get_post_meta( $post->ID, 'fca_eoi', true );
276 //FIX FOR EMPTY LAYOUT? SET THE DEFAULT
277 $layout = empty ( $meta['layout'] ) ? 'postbox_1' : $meta['layout'];
278 $new_meta['layout'] = $layout;
279
280 $new_meta = $meta;
281 unset ( $new_meta[$layout] );
282
283 $i = 0;
284
285 forEach ( $meta[$layout] as $selector => $array ) {
286 $type = '';
287
288 if ( $i == 0 ) {
289 $type = 'form';
290 } else if ( strpos($selector, 'headline') !== false ) {
291 $type = 'headline';
292 } else if ( strpos($selector, 'description') !== false ) {
293 $type = 'description';
294 } else if ( strpos($selector, 'name') !== false ) {
295 $type = 'name';
296 } else if ( strpos($selector, 'email') !== false ) {
297 $type = 'email';
298 } else if ( strpos($selector, 'submit_button_wrapper input:hover') !== false ) {
299 $type = 'hover';
300 } else if ( strpos($selector, 'submit_button_wrapper input') !== false && strpos($selector, 'hover') === false ) {
301 $type = 'button';
302 } else if ( strpos($selector, 'privacy') !== false ) {
303 $type = 'privacy';
304 } else if ( strpos($selector, 'fatcatapps') !== false ) {
305 $type = 'branding';
306 }
307
308 forEach ($array as $css_property => $value ) {
309 if ( !empty ( $type ) ) {
310
311 if ( $type == 'hover' ) {
312
313 $new_meta['button_wrapper_background_color_selector'] = '.fca_eoi_layout_submit_button_wrapper';
314 $new_meta['button_wrapper_background_color'] = $value;
315
316 } else {
317
318 $new_key = $type . '_' . str_replace ('-', '_', $css_property) . '_selector';
319 if ( strpos( $new_key, 'color' ) !== false && strpos( $new_key, 'border' ) === false && strpos( $new_key, 'background' ) === false ) {
320 $new_key = str_replace ('_color', '_font_color', $new_key);
321 }
322 $new_meta[trim($new_key)] = $selector;
323
324 $new_value_key = $type . '_' . str_replace ('-', '_', $css_property);
325
326 if ( strpos( $new_value_key, 'color' ) !== false && strpos( $new_value_key, 'border' ) === false && strpos( $new_value_key, 'background' ) === false ) {
327 $new_value_key = str_replace ('_color', '_font_color', $new_value_key);
328 }
329
330 $new_meta[trim($new_value_key)] = $value;
331 }
332 }
333 }
334
335 $i++;
336 }
337
338 //SOME SPECIAL CASES
339 if ( empty ( $new_meta['email_font_size'] ) ) {
340 $new_meta['email_font_size_selector'] = 'div.fca_eoi_layout_email_field_wrapper';
341 $new_meta['email_font_size'] = '13px';
342 }
343 if ( empty ( $new_meta['name_font_size'] ) ) {
344 $new_meta['name_font_size_selector'] = 'div.fca_eoi_layout_name_field_wrapper';
345 $new_meta['name_font_size'] = '13px';
346 }
347
348 //POSSIBLE FIX FOR PUBLICATION MODE
349 if ( stripos ( $new_meta[ 'layout' ], 'lightbox') === FALSE && array_key_exists( 'publish_lightbox_mode', $new_meta )) {
350 unset ( $new_meta['publish_lightbox_mode'] );
351 }
352
353 //COMPILE CSS AND SAVE INTO 'HEAD' META
354
355 // General CSS for all forms
356 $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; }";
357
358 // CACHE (ALMSOT) ALL THE OUTPUT HERE
359 $layout_helper = new EasyOptInsLayout( $new_meta[ 'layout' ] );
360 $scss_path = $layout_helper->path_to_resource( 'layout', 'scss' );
361
362 if ( file_exists( $scss_path ) ) {
363 $css_path = str_replace ( '.scss' , '_min.css', $scss_path );
364 $css_file = file_get_contents( $css_path );
365 }
366
367 $show_name = !empty( $new_meta['show_name_field'] ) ? $new_meta['show_name_field'] : false;
368
369 if ( !$show_name ) {
370 $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_email_field_wrapper {width: 100% !important;}";
371 $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_name_field_wrapper {display: none !important;}";
372 }
373
374 //ADD CSS FROM FILE
375 $css .= $css_file;
376
377 //ADD CUSTOM CSS FROM SAVE
378 $added_widget_3_css_rule = false;
379
380 foreach ( $settings as $key => $property ) {
381 $input = str_replace ( '_selector', '', $key);
382
383 $selector = empty ( $new_meta[$key] ) ? '' : $new_meta[$key];
384
385 if ( !empty ( $selector ) ) {
386
387
388 //SPECIAL CASE FOR WIDGET 3
389 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' ) {
390 $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; }";
391 $added_widget_3_css_rule = true;
392 }
393
394 $css .= "#fca_eoi_form_$form_id $selector { $property: $new_meta[$input] !important; }";
395 }
396 }
397
398 $head = $css . '</style>';
399
400 $html = fca_eoi_get_html ( $form_id, $new_meta );
401
402 $head = $head . $html;
403
404 update_post_meta( $post->ID, 'fca_eoi', $new_meta );
405 update_post_meta( $post->ID, 'fca_eoi_meta_format', '2.0' );
406 update_post_meta( $post->ID, 'fca_eoi_head', $head );
407
408 }
409 }
410 }
411
412 function fca_eoi_convert_option_save() {
413
414 $old_options = get_option('paf');
415 $license = get_option('fca_eoi_license_key');
416
417 $new_options = array(
418 'license_key' => $license,
419 );
420
421 $options = array (
422
423 'eoi_powerup_custom_css' => 'custom_css',
424 'eoi_powerup_optin_bait' => 'optin_bait',
425 'eoi_powerup_animation' => 'animation',
426 'eoi_powerup_mp_groups' => 'mailchimp_groups',
427
428 );
429
430 if ( !empty( $old_options ) ) {
431 forEach ( $options as $key => $value ) {
432 if ( !empty ( $old_options[$key] ) && $old_options[$key][0] == 'on' ) {
433 $new_options[$value] = 1;
434 }
435 }
436
437 update_option( 'fca_eoi_settings', $new_options );
438 delete_option ( 'paf' );
439 delete_option ( 'fca_eoi_license_key' );
440
441 }
442
443 }