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

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