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

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