| 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 ( $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 |
function fca_eoi_migrate_css() { |
| 206 |
|
| 207 |
require_once FCA_EOI_PLUGIN_DIR . 'powerups/4_new_css/powerup.php'; |
| 208 |
|
| 209 |
//CHECK CURRENT SETTING |
| 210 |
$isActive = powerup_new_css_is_active(); |
| 211 |
|
| 212 |
if ( !$isActive ) { |
| 213 |
$new_css_obj = new EoiNewCssMigration(); |
| 214 |
$new_css_obj->migrate( 'old', 'new' ); |
| 215 |
powerup_new_css_set_active( TRUE ); |
| 216 |
} |
| 217 |
|
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
//CONVERTS OLD EDITOR SAVE FORMAT TO NEW FORMAT |
| 222 |
function fca_eoi_convert_post_meta() { |
| 223 |
require_once FCA_EOI_PLUGIN_DIR . 'includes/eoi-layout.php'; |
| 224 |
|
| 225 |
$args = array( |
| 226 |
'post_type' => 'easy-opt-ins', |
| 227 |
'post_status' => 'publish', |
| 228 |
'posts_per_page'=> -1, |
| 229 |
); |
| 230 |
|
| 231 |
$posts_array = get_posts( $args ); |
| 232 |
|
| 233 |
$settings = array ( |
| 234 |
'form_background_color_selector' => 'background-color', |
| 235 |
'form_border_color_selector' => 'border-color', |
| 236 |
'headline_font_size_selector' => 'font-size', |
| 237 |
'headline_font_color_selector' => 'color', |
| 238 |
'headline_background_color_selector' => 'background-color', |
| 239 |
'description_font_size_selector' => 'font-size', |
| 240 |
'description_font_color_selector' => 'color', |
| 241 |
'name_font_size_selector' => 'font-size', |
| 242 |
'name_font_color_selector' => 'color', |
| 243 |
'name_background_color_selector' => 'background-color', |
| 244 |
'name_border_color_selector' => 'border-color', |
| 245 |
'email_font_size_selector' => 'font-size', |
| 246 |
'email_font_color_selector' => 'color', |
| 247 |
'email_background_color_selector' => 'background-color', |
| 248 |
'email_border_color_selector' => 'border-color', |
| 249 |
'button_font_size_selector' => 'font-size', |
| 250 |
'button_font_color_selector' => 'color', |
| 251 |
'button_background_color_selector' => 'background-color', |
| 252 |
'button_wrapper_background_color_selector' => 'background-color', |
| 253 |
'privacy_font_size_selector' => 'font-size', |
| 254 |
'privacy_font_color_selector' => 'color', |
| 255 |
'branding_font_color_selector' => 'color', |
| 256 |
|
| 257 |
); |
| 258 |
|
| 259 |
forEach ( $posts_array as $post ) { |
| 260 |
$form_id = $post->ID; |
| 261 |
$version = get_post_meta( $post->ID, 'fca_eoi_meta_format', true ); |
| 262 |
|
| 263 |
//ONLY CONVERT OLD VERSIONS |
| 264 |
if ( $version != '2.0' ) { |
| 265 |
$meta = get_post_meta( $post->ID, 'fca_eoi', true ); |
| 266 |
//FIX FOR EMPTY LAYOUT? SET THE DEFAULT |
| 267 |
$layout = empty ( $meta['layout'] ) ? 'postbox_1' : $meta['layout']; |
| 268 |
$new_meta['layout'] = $layout; |
| 269 |
|
| 270 |
$new_meta = $meta; |
| 271 |
unset ( $new_meta[$layout] ); |
| 272 |
|
| 273 |
$i = 0; |
| 274 |
|
| 275 |
forEach ( $meta[$layout] as $selector => $array ) { |
| 276 |
$type = ''; |
| 277 |
|
| 278 |
if ( $i == 0 ) { |
| 279 |
$type = 'form'; |
| 280 |
} else if ( strpos($selector, 'headline') !== false ) { |
| 281 |
$type = 'headline'; |
| 282 |
} else if ( strpos($selector, 'description') !== false ) { |
| 283 |
$type = 'description'; |
| 284 |
} else if ( strpos($selector, 'name') !== false ) { |
| 285 |
$type = 'name'; |
| 286 |
} else if ( strpos($selector, 'email') !== false ) { |
| 287 |
$type = 'email'; |
| 288 |
} else if ( strpos($selector, 'submit_button_wrapper input:hover') !== false ) { |
| 289 |
$type = 'hover'; |
| 290 |
} else if ( strpos($selector, 'submit_button_wrapper input') !== false && strpos($selector, 'hover') === false ) { |
| 291 |
$type = 'button'; |
| 292 |
} else if ( strpos($selector, 'privacy') !== false ) { |
| 293 |
$type = 'privacy'; |
| 294 |
} else if ( strpos($selector, 'fatcatapps') !== false ) { |
| 295 |
$type = 'branding'; |
| 296 |
} |
| 297 |
|
| 298 |
forEach ($array as $css_property => $value ) { |
| 299 |
if ( !empty ( $type ) ) { |
| 300 |
|
| 301 |
if ( $type == 'hover' ) { |
| 302 |
|
| 303 |
$new_meta['button_wrapper_background_color_selector'] = '.fca_eoi_layout_submit_button_wrapper'; |
| 304 |
$new_meta['button_wrapper_background_color'] = $value; |
| 305 |
|
| 306 |
} else { |
| 307 |
|
| 308 |
$new_key = $type . '_' . str_replace ('-', '_', $css_property) . '_selector'; |
| 309 |
if ( strpos( $new_key, 'color' ) !== false && strpos( $new_key, 'border' ) === false && strpos( $new_key, 'background' ) === false ) { |
| 310 |
$new_key = str_replace ('_color', '_font_color', $new_key); |
| 311 |
} |
| 312 |
$new_meta[trim($new_key)] = $selector; |
| 313 |
|
| 314 |
$new_value_key = $type . '_' . str_replace ('-', '_', $css_property); |
| 315 |
|
| 316 |
if ( strpos( $new_value_key, 'color' ) !== false && strpos( $new_value_key, 'border' ) === false && strpos( $new_value_key, 'background' ) === false ) { |
| 317 |
$new_value_key = str_replace ('_color', '_font_color', $new_value_key); |
| 318 |
} |
| 319 |
|
| 320 |
$new_meta[trim($new_value_key)] = $value; |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
$i++; |
| 326 |
} |
| 327 |
|
| 328 |
//SOME SPECIAL CASES |
| 329 |
if ( empty ( $new_meta['email_font_size'] ) ) { |
| 330 |
$new_meta['email_font_size_selector'] = 'div.fca_eoi_layout_email_field_wrapper'; |
| 331 |
$new_meta['email_font_size'] = '13px'; |
| 332 |
} |
| 333 |
if ( empty ( $new_meta['name_font_size'] ) ) { |
| 334 |
$new_meta['name_font_size_selector'] = 'div.fca_eoi_layout_name_field_wrapper'; |
| 335 |
$new_meta['name_font_size'] = '13px'; |
| 336 |
} |
| 337 |
|
| 338 |
//POSSIBLE FIX FOR PUBLICATION MODE |
| 339 |
if ( stripos ( $new_meta[ 'layout' ], 'lightbox') === FALSE && array_key_exists( 'publish_lightbox_mode', $new_meta )) { |
| 340 |
unset ( $new_meta['publish_lightbox_mode'] ); |
| 341 |
} |
| 342 |
|
| 343 |
//COMPILE CSS AND SAVE INTO 'HEAD' META |
| 344 |
|
| 345 |
// General CSS for all forms |
| 346 |
$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; }"; |
| 347 |
|
| 348 |
// CACHE (ALMSOT) ALL THE OUTPUT HERE |
| 349 |
$layout_helper = new EasyOptInsLayout( $new_meta[ 'layout' ] ); |
| 350 |
$scss_path = $layout_helper->path_to_resource( 'layout', 'scss' ); |
| 351 |
|
| 352 |
if ( file_exists( $scss_path ) ) { |
| 353 |
$css_path = str_replace ( '.scss' , '_min.css', $scss_path ); |
| 354 |
$css_file = file_get_contents( $css_path ); |
| 355 |
} |
| 356 |
|
| 357 |
$show_name = K::get_var( 'show_name_field', $new_meta, false ); |
| 358 |
if ( !$show_name ) { |
| 359 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_layout_email_field_wrapper {width: 100% !important;}"; |
| 360 |
$css .= "#fca_eoi_form_$form_id .fca_eoi_layout_name_field_wrapper {display: none !important;}"; |
| 361 |
} |
| 362 |
|
| 363 |
//ADD CSS FROM FILE |
| 364 |
$css .= $css_file; |
| 365 |
|
| 366 |
//ADD CUSTOM CSS FROM SAVE |
| 367 |
$added_inherent_css_rule = false; |
| 368 |
$added_widget_3_css_rule = false; |
| 369 |
|
| 370 |
foreach ( $settings as $key => $property ) { |
| 371 |
$input = str_replace ( '_selector', '', $key); |
| 372 |
|
| 373 |
$selector = empty ( $new_meta[$key] ) ? '' : $new_meta[$key]; |
| 374 |
|
| 375 |
if ( !empty ( $selector ) ) { |
| 376 |
//BUTTON HOVER HACK |
| 377 |
if ( strpos ( $selector, '.fca_eoi_layout_submit_button_wrapper input' ) !== false && !$added_inherent_css_rule ) { |
| 378 |
$css .= "#fca_eoi_form_$form_id $selector:hover { background-color: inherit !important; }"; |
| 379 |
$added_inherent_css_rule = true; |
| 380 |
} |
| 381 |
//SPECIAL CASE FOR WIDGET 3 |
| 382 |
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' ) { |
| 383 |
$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; }"; |
| 384 |
$added_widget_3_css_rule = true; |
| 385 |
} |
| 386 |
|
| 387 |
$css .= "#fca_eoi_form_$form_id $selector { $property: $new_meta[$input] !important; }"; |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
$head = $css . '</style>'; |
| 392 |
|
| 393 |
$html = fca_eoi_get_html ( $form_id, $new_meta ); |
| 394 |
|
| 395 |
$head = $head . $html; |
| 396 |
|
| 397 |
update_post_meta( $post->ID, 'fca_eoi', $new_meta ); |
| 398 |
update_post_meta( $post->ID, 'fca_eoi_meta_format', '2.0' ); |
| 399 |
update_post_meta( $post->ID, 'fca_eoi_head', $head ); |
| 400 |
|
| 401 |
} |
| 402 |
} |
| 403 |
} |