PluginProbe
GetResponse Forms by Optin Cat / 2.0.2
GetResponse Forms by Optin Cat v2.0.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
← All changes | includes/eoi-post-types.php +1421 -1902 1.5.12.0.2 View file →
@@ -1,6 +1,6 @@
1 1 <?php
2 -
2 +
3 3 class EasyOptInsPostTypes {
4 4
5 5 public $settings;
6 6
@@ -8,10 +8,8 @@
8 8 'form_list' => null,
9 9 'dashboard_widget' => 30
10 10 );
11 11
12 - private $targeting_cat_path = 'assets/vendor/targeting-cat/TargetingCat-OptinCat-1.2.min.js';
13 -
14 12 private $two_step_ids_on_page = array();
15 13
16 14 public function __construct( $settings ) {
17 15
@@ -29,17 +27,10 @@
29 27 add_action( 'admin_post_fca_eoi_reset_stats', array( $this, 'reset_stats' ) );
30 28
31 29 // Dashboard widget
32 30 add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) );
33 -
34 31
35 - // Add provider object and post settings to settings
36 - add_action( 'init', array( $this, 'more_settings' ) );
37 -
38 - // Handle AJAX submission (unused)
39 - //add_action( 'init', array( $this, 'handle_submission' ) );
40 -
41 - // Initiate action hooks
32 + // Save
42 33 add_action( 'save_post', array( $this, 'save_meta_box_content' ), 1, 2 );
43 34
44 35 // Live preview
45 36 add_filter( 'the_content', array( $this, 'live_preview' ) );
@@ -44,22 +35,30 @@
44 35 // Live preview
45 36 add_filter( 'the_content', array( $this, 'live_preview' ) );
46 37
47 38 // Scripts and styles
48 - add_filter( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) );
49 - add_filter( 'admin_enqueue_scripts', array( $this, 'disable_autosave' ) );
39 + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) );
50 40
51 41 add_action( 'admin_head', array( $this, 'hide_minor_publishing' ) );
52 -
42 +
43 + add_action( 'admin_notices', array( $this, 'onboard_help' ), 1 );
44 +
45 + if ( $this->settings['distribution'] === 'free' ) {
46 + add_action( 'admin_notices', array( $this, 'review_notice' ) );
47 + }
48 +
49 + //V 2.0 BLOG POST NOTICE
50 + add_action( 'admin_notices', array( $this, 'google_changes_notice' ) );
51 +
53 52 add_filter( 'admin_body_class', array( $this, 'add_body_class' ) );
54 53
55 54 add_filter( 'wp_insert_post_data', array( $this, 'force_published' ) );
56 55
57 - // add_action( 'admin_footer', array( $this, 'disable_metabox_toggle' ) );
58 -
59 56 add_action( 'wp_ajax_fca_eoi_subscribe', array( $this, 'ajax_subscribe' ) );
60 57 add_action( 'wp_ajax_nopriv_fca_eoi_subscribe', array( $this, 'ajax_subscribe' ) );
61 58
59 + add_action( 'wp_ajax_fca_eoi_dismiss', array( $this, 'ajax_dismiss_notice' ) );
60 +
62 61 add_filter( 'get_user_option_screen_layout_easy-opt-ins', array( $this, 'force_one_column' ) );
63 62
64 63 add_filter( 'get_user_option_meta-box-order_easy-opt-ins', array( $this, 'order_columns' ) );
65 64
@@ -74,10 +73,10 @@
74 73 add_filter( 'enter_title_here', array( $this, 'change_default_title' ) );
75 74
76 75 add_filter( 'init', array( $this, 'bind_content_filter' ), 10 );
77 76
78 - add_filter( 'template_redirect', array( $this, 'parse_tc_condition_request' ), 1 );
79 -
77 + add_filter( 'plugin_action_links_' . FCA_EOI_PLUGIN_BASENAME, array( $this, 'add_plugin_action_links' ) );
78 +
80 79 //ADD ACTIONS TO GET THE ENTIRE PAGE OUTPUT IN BUFFER
81 80
82 81 if ( wp_get_theme() == 'Customizr' ) {
83 82 add_filter( 'the_content', array( $this, 'scan_for_shortcodes' ) );
@@ -84,15 +83,11 @@
84 83 } else {
85 84 add_action('wp_head', array( $this, 'fca_eoi_buffer_start' ));
86 85 add_action('wp_footer', array( $this, 'fca_eoi_buffer_end' ));
87 86 }
88 -
89 - add_filter( 'init', array( $this, 'request_prepare_lightbox' ) );
90 87
91 - add_filter( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
88 + add_filter( 'wp_footer', array( $this, 'maybe_show_lightbox' ) );
92 89
93 - add_filter( 'wp_footer', array( $this, 'show_lightbox' ) );
94 -
95 90 foreach ( $providers_available as $provider ) {
96 91 add_action( 'wp_ajax_fca_eoi_' . $provider . '_get_lists', $provider . '_ajax_get_lists' );
97 92 }
98 93
@@ -102,51 +97,29 @@
102 97 }
103 98
104 99 // Handle licensing
105 100 if( count( $providers_available ) > 1 ) {
106 - require_once $this->settings[ 'plugin_dir' ] . 'includes/licensing.php';
101 + require_once FCA_EOI_PLUGIN_DIR . 'includes/licensing.php';
107 102 new EasyOptInsLicense( $this->settings );
108 103 }
109 104 }
110 105
106 + public function add_plugin_action_links( $links ) {
107 + $url = admin_url('post-new.php?post_type=easy-opt-ins');
108 +
109 + $new_links = array(
110 + 'addnew' => "<a href='$url' >" . __('Add New Optin Form', 'easy-opt-ins' ) . '</a>'
111 + );
112 +
113 + $links = array_merge( $new_links, $links );
114 +
115 + return $links;
116 +
117 + }
118 +
111 119 function fca_eoi_buffer_start() { ob_start(array( $this, 'scan_for_shortcodes' )); }
112 120 function fca_eoi_buffer_end() { ob_end_flush(); }
113 121
114 -
115 - public function enqueue_scripts() {
116 - wp_enqueue_script( 'jquery' );
117 - }
118 -
119 - public function more_settings() {
120 -
121 - $providers_available = array_keys( $this->settings[ 'providers' ] );
122 -
123 - // Get the post id
124 - if( is_admin() ) {
125 - $form_id = K::get_var( 'post', $_GET );
126 - } else {
127 - $protocol = is_ssl() ? 'https' : 'http';
128 - $form_id = K::get_var( 'fca_eoi_form_id', $_POST );
129 - }
130 -
131 - // Save form meta into object settings
132 - $this->settings[ 'eoi_form_meta' ] = empty ( $form_id )
133 - ? false
134 - : get_post_meta( $form_id, 'fca_eoi', true )
135 - ;
136 -
137 - // Add last 3 posts and there meta
138 - // We need to prepare the previous posts
139 - $fca_eoi_last_3_forms = array();
140 - foreach (query_posts( 'posts_per_page=3&post_type=easy-opt-ins' ) as $i => $f ) {
141 - $fca_eoi_last_3_forms[ $i ][ 'post' ] = $f;
142 - $fca_eoi_last_3_forms[ $i ][ 'fca_eoi' ] = get_post_meta( $f->ID, 'fca_eoi', true );
143 - }
144 - // reset query after the loop
145 - wp_reset_query();
146 - $this->settings[ 'fca_eoi_last_3_forms' ] = $fca_eoi_last_3_forms;
147 - }
148 -
149 122 public function register_custom_post_type() {
150 123
151 124 $labels = array(
152 125 'name' => __('Optin Forms') ,
@@ -160,16 +133,16 @@
160 133 'search_items' => __('Search Optin Form') ,
161 134 'not_found' => __('No Optin Form Found') ,
162 135 'not_found_in_trash' => __('No Optin Form Found in Trash') ,
163 136 'parent_item_colon' => '',
164 - 'menu_name' => __('Optin Cat')
137 + 'menu_name' => __('Optin Forms')
165 138 );
166 139 $args = array(
167 - 'menu_icon' => "{$this->settings['plugin_url']}/icon.png",
140 + 'menu_icon' => FCA_EOI_PLUGIN_URL . '/icon.png',
168 141 'labels' => $labels,
169 142 'public' => false,
170 143 'exclude_from_search' => true,
171 - 'publicly_queryable' => true,
144 + 'publicly_queryable' => false,
172 145 'show_ui' => true,
173 146 'show_in_menu' => true,
174 147 'query_var' => true,
175 148 'rewrite' => array(
@@ -190,9 +163,9 @@
190 163 register_post_type('easy-opt-ins', $args);
191 164 }
192 165
193 166 private function enqueue_activity_style() {
194 - wp_enqueue_style( 'admin-cpt-easy-opt-ins-activity', $this->settings['plugin_url'] . '/assets/admin/cpt-easy-opt-ins-activity.css' );
167 + wp_enqueue_style( 'admin-cpt-easy-opt-ins-activity', FCA_EOI_PLUGIN_URL . '/assets/admin/cpt-easy-opt-ins-activity.min.css', array(), FCA_EOI_VER );
195 168 }
196 169
197 170 public function add_new_columns( $columns ) {
198 171 $new_columns = array();
@@ -284,11 +257,11 @@
284 257 );
285 258 }
286 259
287 260 public function add_dashboard_widget() {
288 - wp_enqueue_script( 'd3_js', $this->settings['plugin_url'] . '/assets/vendor/nvd3/d3.min.js' );
289 - wp_enqueue_script( 'nvd3_js', $this->settings['plugin_url'] . '/assets/vendor/nvd3/nv.d3.min.js' );
290 - wp_enqueue_style( 'nvd3_css', $this->settings['plugin_url'] . '/assets/vendor/nvd3/nv.d3.min.css' );
261 + wp_enqueue_script( 'd3_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/d3.min.js', array(), FCA_EOI_VER, true );
262 + wp_enqueue_script( 'nvd3_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/nv.d3.min.js', array(), FCA_EOI_VER, true );
263 + wp_enqueue_style( 'nvd3_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/nv.d3.min.css', array(), FCA_EOI_VER );
291 264 $this->enqueue_activity_style();
292 265
293 266 $day_interval = $this->activity_day_interval['dashboard_widget'];
294 267 $activity = EasyOptInsActivity::get_instance();
@@ -369,17 +342,10 @@
369 342 <?php
370 343 }
371 344
372 345 public function add_meta_boxes() {
346 +
373 347 add_meta_box(
374 - 'fca_eoi_meta_box_nav',
375 - __( 'Navigation' ),
376 - array( &$this, 'meta_box_content_nav' ),
377 - 'easy-opt-ins',
378 - 'side',
379 - 'high'
380 - );
381 - add_meta_box(
382 348 'fca_eoi_meta_box_setup',
383 349 __( 'Setup' ),
384 350 array( &$this, 'meta_box_content_setup' ),
385 351 'easy-opt-ins',
@@ -393,8 +359,9 @@
393 359 'easy-opt-ins',
394 360 'side',
395 361 'high'
396 362 );
363 +
397 364 add_meta_box(
398 365 'fca_eoi_meta_box_provider',
399 366 __( 'Email Marketing Provider Integration' ),
400 367 array( &$this, 'meta_box_content_provider' ),
@@ -402,9 +369,9 @@
402 369 'side',
403 370 'high'
404 371 );
405 372 add_meta_box(
406 - 'fca_eoi_meta_box_publish',
373 + 'fca_eoi_meta_box_publish',
407 374 __( 'Publication' ),
408 375 array( &$this, 'meta_box_content_publish' ),
409 376 'easy-opt-ins',
410 377 'side',
@@ -411,10 +378,10 @@
411 378 'high'
412 379 );
413 380 add_meta_box(
414 381 'fca_eoi_meta_box_thanks',
415 - __( 'Thank You Message' ),
416 - array( &$this, 'meta_box_content_thanks' ),
382 + __( 'Messages' ),
383 + array( &$this, 'meta_box_content_messages' ),
417 384 'easy-opt-ins',
418 385 'side',
419 386 'high'
420 387 );
@@ -427,49 +394,31 @@
427 394 'side',
428 395 'high'
429 396 );
430 397 }
431 - if ( FCA_EOI_DEBUG ) {
432 - add_meta_box(
433 - 'fca_eoi_meta_box_debug',
434 - 'Debug',
435 - array( &$this, 'meta_box_content_debug' ),
436 - 'easy-opt-ins',
437 - 'side',
438 - 'high'
439 - );
440 - }
441 398 }
442 399
443 - public function meta_box_content_nav() {
444 - ?>
445 - <h2 class="nav-tab-wrapper" style="padding: 0 10px">
446 - <a href="#fca_eoi_meta_box_setup" class="nav-tab nav-tab-active">Choose</a>
447 - <a href="#fca_eoi_meta_box_build" class="nav-tab ">Build</a>
448 - <?php if( FCA_EOI_DEBUG ) : ?>
449 - <a href="#fca_eoi_meta_box_debug" class="nav-tab ">Debug</a>
450 - <?php endif; ?>
451 - </h2>
452 - <?php
453 - }
454 -
455 400 public function meta_box_content_setup() {
456 401
457 - global $post;
458 -
459 402 $layouts_types_labels = array(
460 403 'lightbox' => 'Popups',
461 404 'postbox' => 'Post Boxes',
462 405 'widget' => 'Sidebar Widgets',
406 + 'banner' => 'Optin Bars',
407 + 'overlay' => 'Slide Ins',
463 408 );
409 +
410 + $layout_names = array(
411 + 'banner_10' => __( 'Optin Bar 1', 'easy-opt-ins'),
412 + 'banner_11' => __( 'Optin Bar 2', 'easy-opt-ins'),
413 + 'banner_12' => __( 'Optin Bar 3', 'easy-opt-ins'),
414 + 'overlay_13' => __( 'Slide In Light', 'easy-opt-ins'),
415 + 'overlay_14' => __( 'Slide In Dark', 'easy-opt-ins'),
416 + );
464 417
465 - $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true );
466 -
467 - echo '<script id="fca_eoi_texts" type="application/json">{ "headline_copy": "Headline Copy", "description_copy": "Description Copy", "name_placeholder": "Name Placeholder", "email_placeholder": "Email Placeholder", "button_copy": "Button Copy", "privacy_copy": "Privacy Copy" }</script>';
468 -
469 418 // Build the layouts array
470 419 $layouts = $layouts_types = $layouts_types_found = array();
471 - foreach ( glob( $this->settings[ 'plugin_dir' ] . 'layouts/*', GLOB_ONLYDIR ) as $v) {
420 + foreach ( glob( FCA_EOI_PLUGIN_DIR . 'layouts/*', GLOB_ONLYDIR ) as $v) {
472 421 $layouts_types_found[] = basename( $v );
473 422 }
474 423
475 424 $layouts_types_accepted = array_keys( $layouts_types_labels );
@@ -477,9 +426,9 @@
477 426 if ( in_array( $layout_type, $layouts_types_found ) ) {
478 427 $layouts_types[] = $layout_type;
479 428 }
480 429 }
481 -
430 +
482 431 // Layouts types mini-tabs
483 432 echo '<ul class="category-tabs" id="layouts_types_tabs">';
484 433 foreach ( $layouts_types as $layout_type ) {
485 434 K::wrap(
@@ -493,375 +442,86 @@
493 442 'in' => 'a',
494 443 )
495 444 );
496 445 }
446 + echo '<button type="button" class="button button-primary" id="fca_eoi_layout_revert_button" style="display: none">' . __('Back', 'easy-opt-in') . '</button>';
447 +
497 448 echo '</ul>';
498 -
499 - $file = plugin_dir_path( __FILE__ ) . "cache";
500 - $fca_eoi_global_scss_array = unserialize (file_get_contents($file));
501 -
502 - // Layout types
449 +
450 + //GENERATE SCREENSHOTS / OPTIN THEME PICKER
451 + //RN NOTE: MAYBE CACHE THIS
452 + $output = '';
503 453 foreach ( $layouts_types as $layout_type ) {
504 454
505 - echo '<div class="fca_eoi_accordion_tab" id="layouts_type_' . $layout_type . '">';
506 -
507 -
508 -
509 - foreach ( glob( $this->settings[ 'plugin_dir' ] . "layouts/$layout_type/*", GLOB_ONLYDIR ) as $layout_path ) {
510 - // Grab layout details
455 + $output .= "<div class='fca_eoi_accordion_tab' id='layouts_type_$layout_type'>";
456 + $layout_counter = 1;
457 + foreach ( glob( FCA_EOI_PLUGIN_DIR . "layouts/$layout_type/*", GLOB_ONLYDIR ) as $layout_path ) {
511 458 $layout_id = basename( $layout_path );
459 +
460 +
461 +
462 + $layout_helper = new EasyOptInsLayout( $layout_id );
463 + $layout_type = ucfirst ( $layout_helper->layout_type );
512 464
513 - $layout_helper = new EasyOptInsLayout( $layout_id );
514 - $layout_type = $layout_helper->layout_type;
515 - $php_path = $layout_helper->path_to_resource( 'layout', 'php' );
516 - $html_path = $layout_helper->path_to_resource( 'layout', 'html' );
517 - $html_wrap_path = $layout_helper->path_to_html_wrapper();
518 - $scss_path = $layout_helper->path_to_resource( 'layout', 'scss' );
519 465 $screenshot_path = $layout_helper->path_to_resource( 'screenshot', 'png' );
520 466 $screenshot_url = $layout_helper->url_to_resource( 'screenshot', 'png' );
521 -
522 - include $php_path;
467 + $screenshot = file_exists( $screenshot_path ) ? $screenshot_url : FCA_EOI_PLUGIN_URL . '/layouts/no-image.jpg';
523 468
524 - if ( EasyOptInsLayout::uses_new_css() ) {
525 - $layout[ 'css' ] = file_exists( $scss_path )
526 - ? '#fca_eoi_preview_form_container {' .
527 - file_get_contents( $scss_path ) .
528 - '.fca_eoi_layout_popup_close {' .
529 - 'display: none;' .
530 - '}' .
531 - '}'
532 - : ''
533 - ;
469 + if ( array_key_exists ( $layout_id, $layout_names ) ) {
470 + $layout_name = $layout_names[$layout_id];
534 471 } else {
535 - $layout[ 'css' ] = file_exists( $scss_path )
536 - ? file_get_contents( $scss_path)
537 - : ''
538 - ;
472 + $layout_name = ucfirst ( str_replace( 'layout', 'widget', str_replace('_', ' ', $layout_id) ) );
473 + $layout_name = str_replace( array('Postbox 0', 'Widget 0'), 'No CSS', $layout_name );
539 474 }
540 -
541 - // Add $ltr SASS variable
542 - $layout[ 'css' ] = sprintf( '$ltr: %s;', is_rtl() ? 'false' : 'true' )
543 - . $layout[ 'css' ]
544 - ;
545 475
546 - //$scss = $layout_helper->new_scss_compiler(); //fix these two lines
547 - //$layout[ 'css' ] = $scss->compile( $layout[ 'css' ] ); //fix these two lines
548 - $name = $layout[ 'css' ];
549 - $layout[ 'css' ] = $fca_eoi_global_scss_array[$name];
476 + $output .= "<div class='fca_eoi_layout has-tip fca_eoi_layout_preview' data-layout-id='$layout_id' data-layout-type='$layout_type'>";
477 + $output .= "<img src='$screenshot'>";
478 + $output .= "<div class='fca_eoi_layout_info'>";
479 + $output .= "<h3>$layout_name</h3>";
480 + $output .= "</div>";
481 + $output .= "</div>";
550 482
551 -
552 -
553 - if ( EasyOptInsLayout::uses_new_css() ) {
554 - $layout[ 'template' ] = str_replace(
555 - '{{{layout}}}',
556 - file_get_contents( $html_path ),
557 - file_get_contents( $html_wrap_path )
558 - );
559 - } else {
560 - $layout[ 'template' ] = file_get_contents( $html_path );
561 - }
562 - $layout[ 'template' ] = str_replace(
563 - array(
564 - '<form',
565 - '/form',
566 - '{{{description_copy}}}',
567 - '{{{headline_copy}}}',
568 - '{{{name_field}}}',
569 - '{{{email_field}}}',
570 - '{{{submit_button}}}',
571 - '{{{privacy_copy}}}',
572 - '{{{fatcatapps_link}}}'
573 - )
574 - , array(
575 - EasyOptInsLayout::uses_new_css()
576 - ? '<div id="fca_eoi_preview_form_container">' .
577 - '<div id="fca_eoi_preview_form_wrapper">' .
578 - '<div id="fca_eoi_preview_form" class="' .
579 - 'fca_eoi_layout_' . $layout_helper->layout_number . ' ' .
580 - $layout_helper->layout_class .
581 - '"'
582 - : '<div id="fca_eoi_preview_form" class="fca_eoi_' . $layout_id . '"',
583 - EasyOptInsLayout::uses_new_css()
584 - ? '/div></div></div'
585 - : '/div',
586 - '<div data-fca-eoi-fieldset-id ="description">{{{description_copy}}}</div>',
587 - EasyOptInsLayout::uses_new_css()
588 - ? '<div data-fca-eoi-fieldset-id ="headline" id="fca_eoi_preview_headline_copy">{{{headline_copy}}}</div>'
589 - : '<span data-fca-eoi-fieldset-id ="headline" id="fca_eoi_preview_headline_copy">{{{headline_copy}}}</span>',
590 - EasyOptInsLayout::uses_new_css()
591 - ? '<input class="fca_eoi_form_input_element" type="text" placeholder="{{{name_placeholder}}}">'
592 - : '<input data-fca-eoi-fieldset-id ="name_field" type="text" placeholder="{{{name_placeholder}}}" />',
593 - EasyOptInsLayout::uses_new_css()
594 - ? '<input class="fca_eoi_form_input_element" type="email" placeholder="{{{email_placeholder}}}">'
595 - : '<input data-fca-eoi-fieldset-id ="email_field" type="email" placeholder="{{{email_placeholder}}}" />',
596 - EasyOptInsLayout::uses_new_css()
597 - ? '<input class="fca_eoi_form_button_element" data-fca-eoi-fieldset-id ="button" type="submit" value="{{{button_copy}}}">'
598 - : '<input data-fca-eoi-fieldset-id ="button" type="submit" value="{{{button_copy}}}" />',
599 - EasyOptInsLayout::uses_new_css()
600 - ? '<div data-fca-eoi-fieldset-id="privacy">{{{privacy_copy}}}</div>'
601 - : '<span data-fca-eoi-fieldset-id ="privacy">{{{privacy_copy}}}</span>',
602 - EasyOptInsLayout::uses_new_css()
603 - ? '{{#show_fatcatapps_link}}<div class="fca_eoi_layout_fatcatapps_link_wrapper fca_eoi_form_text_element"><span data-fca-eoi-fieldset-id ="fatcatapps"><a href="#" onclick="javascript:return false">Powered by Optin Cat</a></span></div>{{/show_fatcatapps_link}}'
604 - : '{{#show_fatcatapps_link}}<p class="fca_eoi_' . $layout_id . '_fatcatapps_link_wrapper"><span data-fca-eoi-fieldset-id ="fatcatapps"><a href="#" onclick="javascript:return false">Powered by Optin Cat</a></span></p>{{/show_fatcatapps_link}}',
605 - )
606 - , $layout[ 'template' ]
607 - );
608 - $layout[ 'template' ] .= sprintf( '<style>%s</style>', $layout[ 'css' ] );
609 - $layouts[ $layout_id ] = $layout;
610 - // Output the layout image and hidden template
611 - $layout_output_tpl = '
612 - <div class="fca_eoi_layout has-tip" data-layout-id=":id" data-layout-type=":type">
613 - <img src=":src" />
614 - <div class="fca_eoi_layout_info">
615 - <h3>:name</h3>
616 - </div>
617 - <script id="fca_eoi_tpl_:id" type="x-tmpl-mustache">:template</script>
618 - <script id="fca_eoi_editables_:id" type="application/json">:editables</script>
619 - <script id="fca_eoi_texts_:id" type="application/json">:texts</script>
620 - </div>
621 - ';
622 - $layout_output = str_replace(
623 - array(
624 - ':id',
625 - ':type',
626 - ':name',
627 - ':src',
628 - ':template',
629 - ':editables',
630 - ':texts',
631 - ),
632 - array(
633 - $layout_id,
634 - $layout_type,
635 - $layout[ 'name' ],
636 - file_exists( $screenshot_path )
637 - ? $screenshot_url
638 - : $this->settings[ 'plugin_url' ] . '/layouts/no-image.jpg'
639 - ,
640 - $layout[ 'template' ],
641 - ! empty( $layout[ 'editables' ] )
642 - ? json_encode( $layout[ 'editables' ] )
643 - : 'null'
644 - ,
645 - ! empty( $layout[ 'texts' ] )
646 - ? json_encode( $layout[ 'texts' ] )
647 - : 'null'
648 - ,
649 - ),
650 - $layout_output_tpl
651 - );
652 -
653 - // Add autocolors
654 - if( ! empty( $layout[ 'autocolors' ] ) ) {
655 - foreach ($layout[ 'autocolors' ] as $autocolor ) {
656 - $layout_output .= '
657 - <script>
658 - jQuery( document ).ready( function( $ ) {
659 -
660 - var source = "[name*=\'' . $autocolor[ 'source' ] . '\']";
661 - var destination = "[name*=\'' . $autocolor[ 'destination' ] . '\']";
662 -
663 - $( destination ).closest( "p" ).hide();
664 -
665 - $( document ).on( "change", source, function() {
666 - var v = $(this).val();
667 - if( ! v ) {
668 - $( destination ).val( "" );
669 - return ;
670 - }
671 -
672 - var c = tinycolor( v );'
673 - ;
674 - foreach ( $autocolor[ 'operations'] as $op => $val ) {
675 - $layout_output .= '
676 - c = c.' . $op. '( ' . 1*$val . ' );
677 - ';
678 - }
679 - $layout_output .= '
680 - $( destination ).val( c.toString() );
681 - $( destination ).blur();
682 - } );
683 - } );
684 - </script>'
685 - ;
686 - }
687 - }
688 -
689 - echo $layout_output;
690 -
483 + $layout_counter = $layout_counter + 1;
691 484 }
692 - echo '</div>';
485 + $output .= "</div>";
486 +
693 487 }
694 - echo '<br clear="all"/>';
695 -
696 - // Prepare layouts array (id->name) for K
697 - $layouts_array = array();
698 - foreach ( $layouts as $layout_id => $layout ) {
699 - $layouts_array[ $layout_id ] = $layout[ 'name' ];
700 - }
701 -
702 - // Print hidden select box, it will be controlled by images (UI)
703 - K::select(
704 - 'fca_eoi[layout]',
705 - array(
706 - 'class' => 'hidden',
707 - 'id' => 'fca_eoi_layout_select',
708 - ),
709 - array(
710 - 'options' => $layouts_array,
711 - 'selected' => K::get_var( 'layout', $fca_eoi ),
712 - )
713 - );
714 -
715 - // Prepare the properties fields templates
716 - $property_templates[ 'color' ] = K::input( '{{property_name}}',
717 - array(
718 - 'class' => sprintf(
719 - "color { hash: true, caps: false, required: false, pickerPosition: '%s' }"
720 - , is_rtl() ? 'right' : 'left'
721 - ),
722 - 'value' => '{{property_value}}',
723 - ),
724 - array(
725 - 'format' => '<p class="clear"><label><span class="control-title">{{property_label}}</span><br />:input <a href="#transparent">None</a></label></p>',
726 - 'nocolorpicker' => true,
727 - 'return' => true,
728 - )
729 - );
730 - $property_templates[ 'icon' ] = K::input( '{{property_name}}',
731 - array(
732 - 'data-value-unchecked' => '{{property_value_unchecked}}',
733 - 'data-is-checked' => '{{property_is_checked}}',
734 - 'type' => 'checkbox',
735 - 'value' => '{{property_value}}',
736 - ),
737 - array(
738 - 'format' => '<p class="control-property-icon"><label class="fca_eoi_toggle">{{{icon}}} :input</label></p>',
739 - 'return' => true,
740 - )
741 - );
742 - $property_templates[ 'font-size' ] = K::select( '{{property_name}}',
743 - array(
744 - 'data-selected' => '{{selected}}',
745 - ),
746 - array(
747 - 'format' => '<p class="clear"><label><span class="control-title">{{property_label}}</span><br />:select</label></p>',
748 - 'options' => array(
749 - 'none' => '',
750 - '7px' => '7px',
751 - '8px' => '8px',
752 - '9px' => '9px',
753 - '10px' => '10px',
754 - '11px' => '11px',
755 - '12px' => '12px',
756 - '13px' => '13px',
757 - '14px' => '14px',
758 - '15px' => '15px',
759 - '16px' => '16px',
760 - '17px' => '17px',
761 - '18px' => '18px',
762 - '19px' => '19px',
763 - '20px' => '20px',
764 - '21px' => '21px',
765 - '22px' => '22px',
766 - '23px' => '23px',
767 - '24px' => '24px',
768 - '25px' => '25px',
769 - '26px' => '26px',
770 - '27px' => '27px',
771 - '28px' => '28px',
772 - '29px' => '29px',
773 - '30px' => '30px',
774 - '31px' => '31px',
775 - '32px' => '32px',
776 - '33px' => '33px',
777 - '34px' => '34px',
778 - '35px' => '35px',
779 - '36px' => '36px',
780 - ),
781 - 'selected' => 'none',
782 - 'return' => true,
783 - )
784 - );
785 -
786 - // Print the proprties fields templates
787 - foreach ( $property_templates as $prop => $property_template) {
788 - echo '<script id="fca_eoi_property_' . $prop . '" type="x-tmpl-mustache">' . $property_template . '</script>';
789 - }
790 -
791 - // Print a copy of the current settings
792 - echo
793 - '<script id="fca_eoi_post_meta" type="application/json">'
794 - . ( $fca_eoi ? json_encode( $fca_eoi ) : '{}' )
795 - . '</script>'
796 - ;
488 + $output .= '<br clear="all">';
489 + echo $output;
797 490 }
798 491
799 492 public function meta_box_content_provider() {
800 -
493 +
801 494 global $post;
802 495 $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true );
803 - $providers_available = array_keys( $this->settings[ 'providers' ] );
496 +
497 + //DISABLE CUSTOM FORM
498 + $allow_customform = get_option ( 'fca_eoi_allow_customform', 'false' );
499 + if ( $allow_customform == 'false' ) {
500 + $providers = $this->settings[ 'providers' ];
501 + unset ( $providers['customform'] );
502 + $providers_available = array_keys( $providers );
503 + } else {
504 + $providers_available = array_keys( $this->settings[ 'providers' ] );
505 + }
506 +
804 507 $providers_options = array();
805 - $screen = get_current_screen();
806 - $fca_eoi_last_3_forms = $this->settings[ 'fca_eoi_last_3_forms' ];
807 508
808 - // @todo: remove
809 - // Hack for mailchimp upgrade
810 - $fca_eoi[ 'mailchimp_list_id' ] = K::get_var(
811 - 'mailchimp_list_id'
812 - , $fca_eoi
813 - , K::get_var( 'list_id' , $fca_eoi )
814 - );
815 - if( K::get_var( 'list_id' , $fca_eoi ) ) {
816 - $fca_eoi[ 'provider' ] = 'mailchimp';
817 - }
818 - // End of hack
819 - // Hack for campaignmonitor upgrade
820 - $fca_eoi[ 'campaignmonitor_list_id' ] = K::get_var(
821 - 'campaignmonitor_list_id'
822 - , $fca_eoi
823 - , K::get_var( 'list_id' , $fca_eoi )
824 - );
825 - if( strlen( K::get_var( 'campaignmonitor_list_id' , $fca_eoi ) ) == 32){
826 - $fca_eoi[ 'provider' ] = 'campaignmonitor';
827 - }
828 - // End of hack
829 - // Hack for getresponse upgrade
830 - $fca_eoi[ 'getresponse_list_id' ] = K::get_var(
831 - 'getresponse_list_id'
832 - , $fca_eoi
833 - , K::get_var( 'list_id' , $fca_eoi )
834 - );
835 - if( K::get_var( 'list_id' , $fca_eoi ) ) {
836 - $fca_eoi[ 'provider' ] = 'getresponse';
837 - }
838 - // End of hack
839 -
840 509 // Prepare providers options
841 - foreach ($this->settings[ 'providers' ] as $provider_id => $provider ) {
510 + foreach ( $this->settings[ 'providers' ] as $provider_id => $provider ) {
842 511 $providers_options[ $provider_id ] = $provider[ 'info' ][ 'name' ];
843 512 }
844 513
514 + if ( $allow_customform == 'false') {
515 + unset ( $providers_options['customform'] );
516 + }
517 +
845 518 // Provider choice if there are many providers
846 519 if ( 1 < count( $providers_available) ) {
847 520
848 - $last_date = 0;
849 - $provider = 'mailchimp'; // use mailchimp by default
850 - foreach ( $fca_eoi_last_3_forms as $form ) {
851 - if ( ! empty( $form['fca_eoi'] ) ) {
852 - $post_date = strtotime( $form['post']->post_date );
853 -
854 - foreach ( array_keys( $form['fca_eoi'] ) as $key ) {
855 - $pos = strpos( $key, '_list_id' );
856 - if ( $pos !== false && $post_date > $last_date ) {
857 - $provider = substr( $key, 0, $pos );
858 - $last_date = $post_date;
859 - }
860 - }
861 - }
862 - }
863 -
521 + $provider = get_option( 'fca_eoi_last_provider', '' );
522 + $provider = empty($provider) ? 'mailchimp' : $provider; // use mailchimp by default
523 +
864 524 K::select( 'fca_eoi[provider]'
865 525 , array(
866 526 'class' => 'select2',
867 527 'style' => 'width: 27em;',
@@ -873,466 +533,347 @@
873 533 )
874 534 );
875 535 }
876 536
877 - $providers_available = array_keys( $this->settings[ 'providers' ] );
878 537 foreach ( $providers_available as $provider ) {
879 538 call_user_func( $provider . '_integration', $this->settings );
880 539 }
881 540 }
541 +
542 + //SEND JS TEMPLATE DATA FOR RULE CREATION
543 + public function prepare_publish_rules_html( $rules = array() ) {
544 +
545 + switch ( $this->settings['distribution'] ) {
546 + case 'free':
547 + $conditions_options = array(
548 + '' => __( 'Choose a rule...' ),
549 + 'time_on_page' => __( 'Time on page' ),
550 + );
551 + ob_start();
552 + ?>
553 + <tr>
554 + <th><select class="fca_eoi_condition_select">
555 + <option selected="selected">
556 + Choose a rule...
557 + </option>
882 558
883 - public function meta_box_content_publish() {
559 + <option value="scrolled_percent">
560 + Scrolled down
561 + </option>
562 + <optgroup label="Premium Only">
563 +
564 + <option value="pageviews" disabled>
565 + Number of Pageviews
566 + </option>
884 567
885 - global $post;
886 - $screen = get_current_screen();
568 + <option value="time_on_page" disabled>
569 + Time on page
570 + </option>
887 571
572 + <option value="include" disabled>
573 + Only display on these pages
574 + </option>
575 +
576 + <option value="exclude" disabled>
577 + Never display on these pages
578 + </option>
579 +
580 + <option value="exit_intervention" disabled>
581 + Exit Intervention
582 + </option>
583 + </optgroup>
584 + </select><span class='fca_eoi_at_least' style=
585 + 'display:none'>at&nbsp;least</span></th>
586 +
587 + <td></td>
588 +
589 + <td class='fca_eoi_delete_condition' title='Click to remove'><span class='fca_eoi_close_icon dashicons dashicons-no'></span></td>
590 + </tr>
591 +
592 + <?php
593 +
594 + $rowNew = ob_get_clean();
595 + break;
596 +
597 + case 'premium':
598 +
599 + $conditions_options = array(
600 + '' => __( 'Choose a rule...' ),
601 + 'scrolled_percent' => __( 'Scrolled down' ),
602 + 'pageviews' => __( 'Number of Pageviews' ),
603 + 'time_on_page' => __( 'Time on page' ),
604 + 'include' => __( 'Only display on these pages' ),
605 + 'exclude' => __( 'Never display on these pages' ),
606 + 'exit_intervention' => __( 'Exit Intervention' ),
607 + );
608 +
609 + $rowNew = "<tr><th>" .
610 + K::select(
611 + '',
612 + array(
613 + 'class' => 'fca_eoi_condition_select',
614 + ),
615 + array(
616 + 'options' => $conditions_options,
617 + 'return' => true,
618 + )
619 + ) . "<span class='fca_eoi_at_least' style='display:none' >at&nbsp;least</span></th><td></td><td class='fca_eoi_delete_condition' title='Click to remove'><span class='fca_eoi_close_icon dashicons dashicons-no'></span></td></tr>";
620 +
621 + break;
622 + }
623 +
624 + $ruleTableHtml = array (
625 + 'rowNew' => $rowNew,
626 +
627 + 'dataScroll' => K::input(
628 + 'fca_eoi[publish_lightbox][conditions][scrolled_percent]',
629 + array(
630 + 'type' => 'number',
631 + 'min' => '0',
632 + 'max' => '100',
633 + 'value' => '30',
634 + 'class' => '',
635 + ),
636 + array(
637 + 'return' => true,
638 + )
639 + ) . '&nbsp;%',
640 +
641 + 'dataPageviews' => K::input(
642 + 'fca_eoi[publish_lightbox][conditions][pageviews]',
643 + array(
644 + 'type' => 'number',
645 + 'min' => '0',
646 + 'value' => '2',
647 + 'class' => '',
648 + ),
649 + array(
650 + 'return' => true,
651 + )
652 + ) . '&nbsp;pageviews',
653 +
654 + 'dataTime' => K::input(
655 + 'fca_eoi[publish_lightbox][conditions][time_on_page]',
656 + array(
657 + 'type' => 'number',
658 + 'min' => '0',
659 + 'value' => '30',
660 + 'class' => '',
661 + ),
662 + array(
663 + 'return' => true,
664 + )
665 + ) . '&nbsp;seconds',
666 +
667 + 'dataExit' => K::input( 'fca_eoi[publish_lightbox][conditions][exit_intervention]',
668 + array(
669 + 'type' => 'checkbox',
670 + 'class' => 'switch-input'
671 + ),
672 + array(
673 + 'format' => '<label class="switch">:input<span class="switch-label" data-on="On" data-off="Off"></span><span class="switch-handle"></span></label>',
674 + 'return' => true,
675 + )
676 + ),
677 +
678 + 'dataInclude' => k_selector( 'fca_eoi[publish_lightbox][conditions][include]', array(), true ),
679 + 'dataExclude' => k_selector( 'fca_eoi[publish_lightbox][conditions][exclude]', array(), true ),
680 + );
681 +
682 + wp_localize_script( 'fca-eoi-rules', 'fcaEoiRuleTableHtml', $ruleTableHtml );
683 + wp_localize_script( 'fca-eoi-rules', 'fcaEoiRules', $rules );
684 + wp_localize_script( 'fca-eoi-rules', 'fcaEoiDistro', $this->settings['distribution'] );
685 + }
686 +
687 + public function meta_box_content_publish( $post ) {
688 +
888 689 $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true );
889 -
890 - // Widgets
690 +
691 + $conditions = empty( $fca_eoi['publish_lightbox']['conditions'] ) ? array() : $fca_eoi['publish_lightbox']['conditions'];
692 + $this->prepare_publish_rules_html( $conditions );
693 +
891 694 K::wrap(
892 695 sprintf(
893 - __( 'You can publish this optin box by going to <a href="%s" target="_blank">Appearance › Widgets</a>')
894 - , admin_url( 'widgets.php')
895 - )
896 - , array( 'id' => 'fca_eoi_publish_widget' )
897 - , array( 'in' => 'p' )
696 + __( 'You can publish this optin box by going to <a href="%s" target="_blank">Appearance › Widgets</a>'),
697 + admin_url( 'widgets.php')
698 + ),
699 + array( 'id' => 'fca_eoi_publish_widget' ),
700 + array( 'in' => 'p' )
898 701 );
899 702
900 703 // Post boxes
901 704 echo '<div id ="fca_eoi_publish_postbox">';
902 - K::wrap( __( 'Shortcode')
903 - , array( 'style' => 'padding-left: 0px; padding-right: 0px; ' )
904 - , array( 'in' => 'h3' )
905 - );
906 - K::wrap( __( "Copy and paste beneath shortcode anywhere on your site where you'd like this opt-in form to appear." )
907 - , null
908 - , array( 'in' => 'p' )
909 - );
910 - K::input( ''
911 - , array(
912 - 'class' => 'regular-text autoselect',
913 - 'readonly' => 'readonly',
914 - 'value' => sprintf( '[%s id=%d]', $this->settings[ 'shortcode' ], $post->ID ),
915 - )
916 - , array( 'format' => '<p>:input</p>', )
917 - );
918 - K::wrap( __( 'Append to post or page')
919 - , array( 'style' => 'padding-left: 0px; padding-right: 0px; ' )
920 - , array( 'in' => 'h3' )
921 - );
922 - K::wrap( __( 'Automatically append this optin to the following posts, categories and/or pages.' )
923 - , null
924 - , array( 'in' => 'p' )
925 - );
926 - k_selector( 'fca_eoi[publish_postbox]', K::get_var( 'publish_postbox', $fca_eoi, array() ) );
705 + K::wrap( __( 'Shortcode'),
706 + array( 'style' => 'padding-left: 0px; padding-right: 0px; ' ),
707 + array( 'in' => 'h3' )
708 + );
709 + K::wrap( __( "Copy and paste beneath shortcode anywhere on your site where you'd like this opt-in form to appear." ),
710 + null,
711 + array( 'in' => 'p' )
712 + );
713 + K::input( '',
714 + array(
715 + 'class' => 'regular-text autoselect',
716 + 'readonly' => 'readonly',
717 + 'value' => sprintf( '[%s id=%d]', $this->settings[ 'shortcode' ], $post->ID ),
718 + ),
719 + array( 'format' => '<p>:input</p>', )
720 + );
721 + K::wrap( __( 'Append to post or page'),
722 + array( 'style' => 'padding-left: 0px; padding-right: 0px; ' ),
723 + array( 'in' => 'h3' )
724 + );
725 + K::wrap( __( 'Automatically append this optin to the following posts, categories and/or pages.' ),
726 + null,
727 + array( 'in' => 'p' )
728 + );
729 + k_selector( 'fca_eoi[publish_postbox]', K::get_var( 'publish_postbox', $fca_eoi, array() ) );
927 730 echo '</div>';
928 731
929 732 // Lightboxes
930 733
931 - switch ( $this->settings['distribution'] ) {
932 - case 'free':
933 - $conditions_options = array(
934 - 'time_on_page' => 'Time on page is at least (second)',
935 - );
936 - break;
937 - case 'premium':
938 - $conditions_options = array(
939 - 'pageviews' => 'Number of pageviews during this visit at least',
940 - 'scrolled_percent' => 'Scrolled down on current page at least (%)',
941 - 'time_on_page' => 'Time on page is at least (second)',
942 - 'include' => 'Only show popup on the following posts/pages',
943 - 'exclude' => 'Never show popup on the following posts/pages',
944 - 'exit_intervention' => 'User is about to close the page (Exit Intervention)'
945 - );
946 - break;
947 - }
948 -
734 +
949 735 $fca_eoi[ 'publish_lightbox' ] = K::get_var( 'publish_lightbox', $fca_eoi, array() );
950 - echo "<div id ='fca_eoi_publish_lightbox'>";
951 736
952 - if ( 'premium' === $this->settings[ 'distribution' ] ) {
953 - K::input( 'fca_eoi[publish_lightbox_mode]'
954 - , array(
955 - 'type' => 'radio',
956 - 'value' => 'two_step_optin',
957 - 'checked' => 'two_step_optin' === K::get_var( 'publish_lightbox_mode', $fca_eoi ),
958 - )
959 - , array(
960 - 'format' => '<p><label>:input Two-Step Optin (Trigger popup only when the visitor clicks on a call to action link)</label></p>',
961 - )
962 - );
963 - }
964 -
965 - K::input( 'fca_eoi[publish_lightbox_mode]'
966 - , array(
967 - 'type' => 'radio',
968 - 'value' => 'traditional_popup',
969 - 'checked' => 'traditional_popup' === K::get_var( 'publish_lightbox_mode', $fca_eoi ),
970 - )
971 - , array(
972 - 'format' => '<p><label>:input Traditional Popup (Trigger popup when the visitor is browsing your site)</label></p>',
973 - )
974 - );
975 - ?>
976 -
977 - <hr />
978 -
979 - <?php // Condition always present ?>
980 - <div id="fca_eoi_publish_lightbox_mode_traditional_popup" class="hidden">
981 - <fieldset class="fca_lightbox_condition fca_lightbox_condition_permanent">
982 - <span class="fca_lightbox_condition_text"><?php _e('Show popup'); ?></span><?php
983 - K::select(
984 - 'fca_eoi[publish_lightbox][show_every]'
985 - , array()
986 - , array(
987 - 'options' => array(
988 - 'never' => __( 'Never' ),
989 - 'always' => __( 'On every pageview' ),
990 - 'session' => __( 'Once per visit' ),
991 - 'day' => __( 'Once per day' ),
992 - 'month' => __( 'Once per month' ),
993 - 'once' => __( 'Only once' ),
737 +
738 + echo "<div id='fca_eoi_publish_lightbox'>";
739 +
740 + echo '<div id="publish_lightbox_mode_selector_div">';
741 + if ( 'premium' === $this->settings[ 'distribution' ] ) {
742 +
743 + K::input( 'fca_eoi[publish_lightbox_mode]',
744 + array(
745 + 'type' => 'radio',
746 + 'value' => 'two_step_optin',
747 + 'checked' => 'two_step_optin' === K::get_var( 'publish_lightbox_mode', $fca_eoi ),
994 748 ),
995 - 'selected' => K::get_var( 'show_every', $fca_eoi[ 'publish_lightbox' ] ),
996 - )
997 - );
998 - ?>
999 - <p class="fca_eoi_help"><?php _e( 'Set how frequently to show the popup. (Never means the popup is deactivated.)' ); ?></p>
1000 - </fieldset>
1001 - <?php
1002 - // Saved conditions
1003 - $saved_conditions = array();
1004 - $saved_conditions = K::get_var( 'conditions', $fca_eoi[ 'publish_lightbox' ], array() );
749 + array(
750 + 'format' => '<p><label>:input Two-Step Optin (Trigger popup only when the visitor clicks on a call to action link)</label></p>',
751 + )
752 + );
753 + }
1005 754
1006 - // Add default if creating a new form
1007 - if ( 'add' === $screen->action ) {
1008 - $saved_conditions = array(
1009 - '_'.time().'001' => array(
1010 - 'parameter' => 'pageviews',
1011 - 'value' => '2',
755 + K::input( 'fca_eoi[publish_lightbox_mode]',
756 + array(
757 + 'type' => 'radio',
758 + 'value' => 'traditional_popup',
759 + 'checked' => 'traditional_popup' === K::get_var( 'publish_lightbox_mode', $fca_eoi ),
1012 760 ),
1013 - '_'.time().'002' => array(
1014 - 'parameter' => 'scrolled_percent',
1015 - 'value' => '30',
1016 - ),
1017 - '_'.time().'003' => array(
1018 - 'parameter' => 'time_on_page',
1019 - 'value' => '30',
1020 - ),
1021 - );
1022 - }
1023 -
1024 - foreach ( $saved_conditions as $condition_id => $condition ) {
1025 - // Skip conditions that are not available in version
1026 - if ( ! array_key_exists( $condition[ 'parameter' ], $conditions_options ) ) {
1027 - continue;
1028 - }
1029 -
1030 - $select = K::select( "fca_eoi[publish_lightbox][conditions][$condition_id][parameter]"
1031 - , array()
1032 - , array(
1033 - 'selected' => $condition['parameter'],
1034 - 'options' => $conditions_options,
1035 - 'return' => 'true',
761 + array(
762 + 'format' => '<p><label>:input Traditional Popup (Trigger popup when the visitor is browsing your site)</label></p>',
1036 763 )
1037 764 );
765 + echo '</div>';
1038 766
1039 - if ( in_array( $condition['parameter'], array( 'include', 'exclude' ) ) ) {
1040 - $input = k_selector( "fca_eoi[publish_lightbox][conditions][$condition_id][value]"
1041 - , K::get_var( 'value', $condition, array() )
1042 - , true
1043 - );
1044 - } else if ( $condition['parameter'] == 'exit_intervention' ) {
1045 - $input = K::input( "fca_eoi[publish_lightbox][conditions][$condition_id][value]"
1046 - , array(
1047 - 'type' => 'hidden',
1048 - 'value' => ''
1049 - )
1050 - , array(
1051 - 'return' => true
1052 - )
1053 - );
1054 - } else {
1055 - $input = K::input( "fca_eoi[publish_lightbox][conditions][$condition_id][value]"
1056 - , array(
1057 - 'class' => 'medium-text',
1058 - 'type' => 'text',
1059 - 'value' => $condition['value'],
1060 - )
1061 - , array(
1062 - 'return' => true,
1063 - )
1064 - );
1065 - }
767 + echo '<div id="fca_eoi_publish_lightbox_mode_traditional_popup">';
768 + echo "<h3>Rules</h3>";
769 +
770 + echo "<table class='fca_eoi_display_rules_table'>";
771 + echo "<tr><th>Display Frequency" . fca_eoi_tooltip ( __('Set the minimum time between visits your optin will display to each user', 'easy-opt-ins') ) . "</th><td>";
772 + K::select(
773 + 'fca_eoi[publish_lightbox][show_every]',
774 + array(),
775 + array(
776 + 'options' => array(
777 + 'always' => __( 'On every pageview' ),
778 + 'session' => __( 'Once per visit' ),
779 + 'day' => __( 'Once per day' ),
780 + 'month' => __( 'Once per month' ),
781 + 'once' => __( 'Only once' ),
782 + ),
783 + 'selected' => K::get_var( 'show_every', $fca_eoi[ 'publish_lightbox' ], 'month' ),
784 + )
785 + );
786 + echo "</td></tr>";
787 +
788 + echo "<tr><th>Devices to Display on</th><td>";
789 + K::select(
790 + 'fca_eoi[publish_lightbox][devices]',
791 + array(),
792 + array(
793 + 'options' => array(
794 + 'desktop' => __( 'Desktop Only' ),
795 + 'mobile' => __( 'Mobile Only' ),
796 + 'all' => __( 'Desktop & Mobile' ),
797 + ),
798 + 'selected' => K::get_var( 'devices', $fca_eoi[ 'publish_lightbox' ], 'all' ),
799 + )
800 + );
801 + echo "</td></tr>";
802 +
803 + echo "<tr><th>Success Cookie Duration" . fca_eoi_tooltip ( __('The number of days before the optin will display again once the user successfully opts in to your campaign.', 'easy-opt-ins') ) . "</th><td>";
804 + K::input( 'fca_eoi[publish_lightbox][success_duration]',
805 + array(
806 + 'type' => 'number',
807 + 'class' => 'regular-text',
808 + 'min' => 0,
809 + 'value' => K::get_var( 'success_duration', $fca_eoi[ 'publish_lightbox' ], 365 ),
810 + )
811 + );
812 +
813 + echo " days</td></tr>";
814 +
1066 815
1067 - $condition_HTML_inner = ''
1068 - . $select
1069 - . $input
1070 - . ' '
1071 - . '<span class="button fca_remove_lightbox_condition"><span style="vertical-align:text-bottom" class="dashicons dashicons-no"></span> Remove Rule</span>'
1072 - . '<p class="fca_eoi_help"></p>'
1073 - ;
1074 - echo '<div class="fca_eoi_and">- And -</div>';
1075 - K::wrap( $condition_HTML_inner
1076 - , array(
1077 - 'id' => 'fca_lightbox_condition' . $condition_id,
1078 - 'class' => 'fca_lightbox_condition',
1079 - 'style' => '
1080 - padding: .5%;
1081 - margin:.5% 0;
1082 - box-shadow: 0 0 1px rgba(0, 0, 0, .2);
1083 - width: 97%;
1084 - background:#F7F7F7;
1085 - ',
1086 - )
1087 - , array(
1088 - 'in' => 'fieldset',
1089 - )
1090 - );
1091 - }
1092 - ?>
816 + echo "</table>";
817 +
818 + echo "<table class='fca_eoi_display_rules_table' id='fca_eoi_primary_rules_table' >";
819 + //to be filled dynamically?
820 + echo "</table>";
821 +
822 + echo "<a href='#' id='fca_eoi_add_rule'>+ Add a rule</a>";
823 +
824 + echo "<h3>Go Live</h3>";
825 + echo "<table class='fca_eoi_display_rules_table' >";
826 + echo "<tr><th>Deployed (makes this optin go live)</th><td>";
827 + K::input( 'fca_eoi[publish_lightbox][live]',
828 + array(
829 + 'type' => 'checkbox',
830 + 'checked' => K::get_var( 'live', $fca_eoi[ 'publish_lightbox' ], '' ),
831 + 'class' => 'switch-input'
832 + ),
833 + array(
834 + 'format' => '<label class="switch">:input<span class="switch-label" data-on="On" data-off="Off"></span><span class="switch-handle"></span></label>'
835 + )
836 + );
837 + echo "</td></tr>";
838 + echo "</table>";
839 + echo "</div>";
840 +
1093 841
1094 - <?php /* Button to add conditions */ ?>
1095 - <p><span class="button" id="fca_add_lightbox_condition"><span style="vertical-align:text-bottom" class="dashicons dashicons-plus"></span> Add Rule</span></p>
1096 - </div>
1097 -
1098 - <?php if ( 'premium' === $this->settings[ 'distribution' ] ) { ?>
1099 - <div id="fca_eoi_publish_lightbox_mode_two_step_optin" class="hidden">
1100 - <?php
1101 - K::input( 'fca_eoi[lightbox_cta_text]'
1102 - , array(
1103 - 'value' => K::get_var( 'lightbox_cta_text', $fca_eoi )
1104 - ? K::get_var( 'lightbox_cta_text', $fca_eoi )
1105 - : __( 'Free Download' )
1106 - ,
842 +
843 + if ( 'premium' === $this->settings[ 'distribution' ] ) {
844 +
845 + echo '<div id="fca_eoi_publish_lightbox_mode_two_step_optin">';
846 + echo "<h3>Two-Step</h3>";
847 + K::input( 'fca_eoi[lightbox_cta_text]',
848 + array(
849 + 'value' => K::get_var( 'lightbox_cta_text', $fca_eoi ) ? K::get_var( 'lightbox_cta_text', $fca_eoi ) : __( 'Free Download' ),
1107 850 'class' => 'regular-text',
1108 - )
1109 - , array(
851 + ),
852 + array(
1110 853 'format' => '<p><label>Call to action text :input</label></p>',
1111 854 )
1112 855 );
1113 - K::input( 'fca_eoi[lightbox_cta_link]'
1114 - , array(
856 + K::input( 'fca_eoi[lightbox_cta_link]',
857 + array(
1115 858 'readonly' => 'readonly',
1116 - 'value' => htmlspecialchars( sprintf( '<a href="#" data-optin-cat="%d">%s</a>'
1117 - , $post->ID
1118 - , __( 'Free Download' )
1119 - ) ),
859 + 'value' => htmlspecialchars( sprintf( '<button data-optin-cat="%d">%s</button>',
860 + $post->ID,
861 + __( 'Free Download' ) ) ),
1120 862 'class' => 'regular-text autoselect',
1121 - )
1122 - , array(
863 + ),
864 + array(
1123 865 'format' => '<p><label>Call to action link :input</label></p>',
1124 866 )
1125 867 );
1126 868
1127 - K::wrap( __( 'Post above link into the text editor window of your post/page/widget.' )
1128 - , array( 'class' => 'description' )
1129 - , array( 'in' => 'p' )
869 + K::wrap( __( 'Post above link into the text editor window of your post/page/widget.' ),
870 + array( 'class' => 'description' ),
871 + array( 'in' => 'p' )
1130 872 );
1131 -
1132 - ?>
1133 - </div>
1134 - <?php } ?>
1135 -
1136 - <script>
1137 - jQuery( document ).ready( function( $ ) {
1138 -
1139 - <?php
1140 - $lightbox_help = array(
1141 - 'scrolled_percent' => __( 'Only show this popup to visitors who have scrolled down at least X% on the current page. Someone who scrolls down is engaging with your content and therefore more likely to convert. (Keep in mind that the entire page length, including comments, is included in this calculation.)' ),
1142 - 'pageviews' => __( 'Only show this popup to visitors have viewed at least X pages in this visit. Someone who views multiple pages during a visit is very engaged and therefore more likely to convert.' ),
1143 - 'include' => __( 'Makes sure your popup will only be shown on the posts, pages or categories you select. This is great if you want to set up offers for specific categories or blog posts.' ),
1144 - 'exclude' => __( 'Makes sure your popup will never be shown on the posts, pages or categories you select. This is great if you want to avoid showing your popups on landing pages, checkout pages, order confirmation pages, etc.' ),
1145 - 'exit_intervention' => __( 'Only show this popup to visitors who are about to close the current page.' ),
1146 - 'time_on_page' => __( 'Only show this popup to visitors who have spent at least X seconds on the current page. The longer someone spends on your page, the more engaged he is.' ),
1147 - );
1148 - ?>
1149 -
1150 - var lightbox_help = <?php echo json_encode( $lightbox_help ) ?>;
1151 -
1152 - // Condition template
1153 - <?php if ( 'free' === $this->settings[ 'distribution' ] ) { ?>
1154 - var f = ( '<fieldset id="fca_lightbox_condition_x_" class="fca_lightbox_condition"><select name="fca_eoi[publish_lightbox][conditions][_x_][parameter]"><option value="time_on_page" data-default="30">Time on page is at least (second)</option></select><input class="medium-text" type="text" value="" name="fca_eoi[publish_lightbox][conditions][_x_][value]"/> <span class="button fca_remove_lightbox_condition"><span class="dashicons dashicons-no"></span> Remove Rule</span><p class="fca_eoi_help"></p></fieldset>' );
1155 - <?php } else if ( 'premium' === $this->settings[ 'distribution' ] ) { ?>
1156 - var f = ( '<fieldset id="fca_lightbox_condition_x_" class="fca_lightbox_condition"><select name="fca_eoi[publish_lightbox][conditions][_x_][parameter]"><option value="pageviews" data-default="2">Number of pageviews during this visit at least</option><option value="scrolled_percent" data-default="30">Scrolled down on current page at least (%)</option><option value="time_on_page" data-default="30">Time on page is at least (second)</option><option value="include">Only show popup on the following posts/pages</option><option value="exclude">Never show popup on the following posts/pages</option><option value="exit_intervention">User is about to close the page (Exit Intervention)</option></select><input class="medium-text" type="text" value="" name="fca_eoi[publish_lightbox][conditions][_x_][value]"/> <span class="button fca_remove_lightbox_condition"><span class="dashicons dashicons-no"></span> Remove Rule</span><p class="fca_eoi_help"></p></fieldset>' );
1157 - <?php } ?>
1158 -
1159 - <?php
1160 - $s = str_replace( array( "\n", '"' )
1161 - , array( '', '\"' )
1162 - , k_selector( 'fca_eoi[publish_lightbox][conditions][_x_][value]', array(), true )
1163 - );
1164 - ?>
1165 -
1166 - var s = "<?php echo $s; ?>";
1167 -
1168 - var t = '<input class="medium-text" type="text" name="fca_eoi[publish_lightbox][conditions][_x_][value]"/>';
1169 -
1170 - // Disables all but last condition, and use the right input field
1171 - $( document )
1172 - .on( 'change'
1173 - , "select[name^='fca_eoi[publish_lightbox][conditions]['][name$='][parameter]']"
1174 - , function() {
1175 - fix_conditions();
1176 - }
1177 - )
1178 - ;
1179 - $("select[name^='fca_eoi[publish_lightbox][conditions]['][name$='][parameter]']:first").change()
1180 - ;
1181 - function fix_conditions() {
1182 - var $button = $( '#fca_add_lightbox_condition' );
1183 - var $conditions;
1184 -
1185 - $conditions = $( 'select' )
1186 - .filter( "[name^='fca_eoi[publish_lightbox][conditions][']" )
1187 - .filter( "[name$='][parameter]']" )
1188 - ;
1189 - // Prevent changing other conditions
1190 - $conditions
1191 - .not(':last')
1192 - .prop( 'disabled', true )
1193 - ;
1194 - // Allow changing last
1195 - $conditions
1196 - .last()
1197 - .prop( 'disabled', false )
1198 - ;
1199 - // Show hide plus button
1200 - if ( $conditions.length == $(f).find('select:first option').length ) {
1201 - $button.hide();
1202 - } else {
1203 - $button.show();
1204 - }
1205 -
1206 - // Update conditions variable
1207 - $conditions = $( 'select' )
1208 - .filter( "[name^='fca_eoi[publish_lightbox][conditions][']" )
1209 - .filter( "[name$='][parameter]']" )
1210 - ;
1211 -
1212 - /**
1213 - * Show posts selector VS input depending on option.
1214 - * Remove previously selected options.
1215 - * Update help text
1216 - * Use default when applicable (i.e when data-default is here)
1217 - * Remove overflow (condition fieldsets without possible options)
1218 - */
1219 - $conditions.each( function( i ) {
1220 - var $this = $( this );
1221 - var $fieldset = $this.parent();
1222 - var $parameter = $( '[name$="[parameter]"]', $fieldset );
1223 - var $value = $( '[name$="[value]"],[name$="[value][]"]', $fieldset );
1224 - var $input = $value;
1225 - var name = $value.attr( 'name' ).replace(/\[\]/g, '');
1226 - var is_textfield = $value.is( 'input' );
1227 - var is_hidden = ( 'exit_intervention' === $parameter.val() );
1228 - var use_textfield = ( 'include' !== $parameter.val() && 'exclude' !== $parameter.val() );
1229 - var cpt, condition, _default;
1230 -
1231 - // Decide what element to use : input VS select
1232 - if ( use_textfield && ! is_textfield ) {
1233 - $( '.select2', $fieldset ).remove();
1234 - $input = $( t ).attr( 'name', name );
1235 - $parameter.after( $input );
1236 - } else if ( ! use_textfield && is_textfield ) {
1237 - $input = $( s ).attr( 'name', name + '[]' );
1238 - $value.replaceWith( $input );
1239 - }
1240 -
1241 - // Hide or show the input
1242 - $input.attr( 'type', is_hidden ? 'hidden' : 'text' );
1243 -
1244 - // Remove previously selected condition parameters
1245 - $conditions.not($this).find('option[value='+$this.val()+']').remove();
1246 -
1247 - // Update help text
1248 - $( '.fca_eoi_help', $fieldset ).text( lightbox_help[ $parameter.val() ] );
1249 -
1250 - // Use default
1251 - if ( _default = $( ':selected', $parameter).data( 'default' ) ) {
1252 - $value.val( _default );
1253 - $( 'option', $parameter ).data( 'default', '' );
1254 - }
1255 -
1256 - // Remove overflow
1257 - if ( ! $( 'option', $parameter ).length ) {
1258 - $( '.fca_remove_lightbox_condition', $fieldset ).click();
1259 - }
1260 - } );
1261 - $('select.select2').select2();
873 + echo "</div>";
1262 874 }
1263 -
1264 - $( document ).on( 'click', '.fca_remove_lightbox_condition', function( i ) {
1265 -
1266 - var $this = $( this );
1267 - var $opt = $( 'select:first option:selected', $this.parent() )
1268 - .clone()
1269 - .removeAttr( 'selected' )
1270 - ;
1271 -
1272 - $this.parent().remove(); // remove condition row
1273 -
1274 - $('.fca_eoi_and').remove(); // removes "AND"
1275 - $('.fca_lightbox_condition:gt(0)').before( '<div class="fca_eoi_and">- And -</div>' );
1276 -
1277 - $('select')
1278 - .filter( "[name^='fca_eoi[publish_lightbox][conditions][']" )
1279 - .filter( "[name$='][parameter]']" )
1280 - .append( $opt )
1281 - ;
1282 -
1283 - fix_conditions();
1284 - } );
1285 -
1286 -
1287 - $( document ).on( 'click', '#fca_add_lightbox_condition', function() {
1288 -
1289 - var $this = $( this );
1290 - var ts = Date.now();
1291 - var $condition = $( f.replace( /_x_/g, '_' + ts ) );
1292 -
1293 - // Remove already used conditions
1294 - $( 'option', $condition ).each( function() {
1295 - var $this = $( this );
1296 - var val = $this.val();
1297 - var remove = $('select')
1298 - .filter("[name^='fca_eoi[publish_lightbox][conditions][']")
1299 - .filter("[name$='][parameter]']")
1300 - .find('option:selected[value=' + val + ']')
1301 - .length
1302 - ;
1303 -
1304 - if ( remove ) {
1305 - $( this ).remove();
1306 - }
1307 - } );
1308 -
1309 - $this.parent().before( '<div class="fca_eoi_and">- And -</div>' );
1310 - $this.parent().before( $condition );
1311 -
1312 - // Bind removing to minus sign
1313 - $( '.fca_remove_lightbox_condition', '#fca_lightbox_condition_' + ts ).click( function() {
1314 - $( this ).parent().remove();
1315 - } );
1316 -
1317 - // Prevent changing previous conditions
1318 - fix_conditions();
1319 - } );
1320 -
1321 - // Enable disabled conditions fields to allow passing their value to the form action
1322 - $( document ).on( 'submit', '#post', function() {
1323 - $( 'select' )
1324 - .filter( "[name^='fca_eoi[publish_lightbox][conditions][']" )
1325 - .filter( "[name$='][parameter]']" )
1326 - .prop( 'disabled', false )
1327 - ;
1328 - } );
1329 - } );
1330 -
1331 - </script>
1332 - <?php
1333 -
1334 - echo '</div>'; // #fca_eoi_publish_lightbox
875 + echo "</div>";
1335 876 }
1336 877
1337 878 private function meta_box_field( $id, $title, $controls = array() ) {
1338 879 $content = '';
@@ -1348,12 +889,16 @@
1348 889
1349 890 $content = trim( $content );
1350 891 $class_name = 'accordion-section-primary-' . ( empty( $content ) ? 'empty' : 'full' );
1351 892 $content = '<div class="' . $class_name . '">' . $content . '</div>';
1352 -
893 +
894 + $title_id = str_replace ( ' ', '_', $title );
895 + $title_id = strtolower ( $title_id );
896 + $title_id = preg_replace('/[^a-zA-Z0-9_.]/', '', $title_id);
897 +
1353 898 K::wrap(
1354 899 K::wrap(
1355 - $title,
900 + $title . "<span class='accordion-info' id='accordion-info-$title_id'></span>",
1356 901 array( 'class' => 'accordion-section-title' ),
1357 902 array( 'return' => true )
1358 903 ) .
1359 904 K::wrap(
@@ -1366,44 +911,147 @@
1366 911 'id' => $id
1367 912 )
1368 913 );
1369 914 }
1370 -
915 +
1371 916 public function meta_box_content_build() {
917 +
918 + global $post;
919 + $post_meta = get_post_meta( $post->ID, 'fca_eoi', true );
920 + $layout = get_post_meta( $post->ID, 'fca_eoi_layout', true );
921 +
922 + $selected_layout = empty( $layout ) ? 'lightbox_not_set' : $layout;
923 + $class = empty( $layout ) ? 'fca-new-layout' : '';
924 + echo "<input id='fca_eoi_layout_select' name='fca_eoi[layout]' value='$selected_layout' hidden readonly class='$class'>";
925 +
926 + //OUTPUT SELECTED OR DEFAULT TEMPLATE
927 +
928 + echo "<div id='fca_eoi_form_preview'>";
929 +
930 + $output = '<div id="fca_eoi_preview">';
931 + //JS WILL LOAD THE TEMPLATE
932 + //$output .= fca_eoi_get_layout_html( $selected_layout );
1372 933
1373 - wp_enqueue_script( 'accordion' );
1374 -
1375 - global $post;
1376 - $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true );
934 + $output .= '</div>';
935 + echo $output;
936 + /* END FORM HTML GENERATION */
937 +
1377 938 $providers_available = array_keys( $this->settings[ 'providers' ] );
1378 939 $providers_options = array();
1379 940 $screen = get_current_screen();
1380 - $fca_eoi_last_3_forms = $this->settings[ 'fca_eoi_last_3_forms' ];
1381 941
1382 942 // Prepare providers options
1383 943 foreach ($this->settings[ 'providers' ] as $provider_id => $provider ) {
1384 944 $providers_options[ $provider_id ] = $provider[ 'info' ][ 'name' ];
1385 945 }
946 +
947 + echo '<div id="fca_eoi_settings" class="accordion-container">';
948 +
949 + echo '<div id="fca_eoi_fieldset_layout">';
950 + echo '<span id="accordion-info-layout">Layout</span><button title="Change Layout" type="button" id="fca_eoi_layout_select_button" class="button button-secondary"><span style="margin-top: 3px; margin-right: 3px;" class="dashicons dashicons-admin-appearance"></span>Change Layout</button>';
951 + echo '</div>';
952 +
953 + $this->meta_box_field( 'fca_eoi_fieldset_form', 'Form', array(
1386 954
1387 - K::wrap( '', array( 'id' => 'fca_eoi_preview' ) );
955 + array( 'input', 'fca_eoi[toggle_overlay_position]',
956 + array(
957 + 'type' => 'checkbox',
958 + 'checked' => K::get_var( 'toggle_overlay_position', $post_meta, 'off' ) === 'off' ? '' : 'on',
959 + 'class' => 'switch-input'
960 + ),
961 + array(
962 + 'format' => '<p id="fca_eoi_overlay_position_p"><span class="control-title">Placement</span><br><label class="switch">:input<span class="switch-label" data-on="" data-off=""></span><span class="switch-handle"></span></label></p>'
963 + ),
964 + ),
965 + array( 'input', 'fca_eoi[show_close]',
966 + array(
967 + 'type' => 'checkbox',
968 + 'checked' => K::get_var( 'show_close', $post_meta, 'on' ) === 'on' ? 'on' : '',
969 + 'class' => 'switch-input'
970 + ),
971 + array(
972 + 'format' => '<p id="fca_eoi_close_button_p"><span class="control-title">Close Button</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>'
973 + ),
974 + ),
975 +
976 + array( 'input', 'fca_eoi[push_page]',
977 + array(
978 + 'type' => 'checkbox',
979 + 'checked' => K::get_var( 'push_page', $post_meta, 'on' ) === 'on' ? 'on' : '',
980 + 'class' => 'switch-input'
981 + ),
982 + array(
983 + 'format' => '<p id="fca_eoi_push_page_p"><span class="control-title">Push Page Down</span><br><label class="switch">:input<span class="switch-label" data-on="On" data-off="Off"></span><span class="switch-handle"></span></label></p>'
984 + ),
985 + ),
986 +
987 + array( 'input', "fca_eoi[offset]",
988 + array(
989 + 'type' => 'number',
990 + 'min' => '0',
991 + 'value' => K::get_var( 'offset', $post_meta, 0 ),
992 + 'class' => 'fca_eoi_number_input',
993 + ),
994 + array(
995 + 'format' => "<p id='fca_eoi_offset_p'><label><span class='control-title'>Offset</span></label><br />:inputpx</p>",
996 + )
997 + ),
998 +
999 + $this->generate_hidden_css_select_input('form_background_color_selector'),
1000 + $this->generate_color_picker('form_background_color','Form Background Color'),
1001 + $this->generate_hidden_css_select_input('form_border_color_selector'),
1002 + $this->generate_color_picker('form_border_color','Border Color'),
1003 + $this->generate_hidden_css_select_input('form_width_selector'),
1004 + $this->generate_width_select_input('form_width','Width', 100),
1005 + //$this->generate_hidden_css_select_input('form_alignment_selector'),
1006 + //$this->generate_alignment_select_input('form_alignment','Alignment', 'center'),
1388 1007
1389 - echo '<div id="fca_eoi_settings" class="accordion-container">';
1008 + ) );
1390 1009
1391 - $this->meta_box_field( 'fca_eoi_fieldset_form', 'Form' );
1392 -
1393 1010 $this->meta_box_field( 'fca_eoi_fieldset_headline', 'Headline', array(
1011 + array( 'input', 'fca_eoi[show_headline_field]',
1012 + array(
1013 + 'type' => 'checkbox',
1014 + 'checked' => K::get_var( 'show_headline_field', $post_meta, 'on' ) == 'off' ? '' : 'on',
1015 + 'class' => 'switch-input'
1016 + ),
1017 + array(
1018 + 'format' => '<p><span class="control-title">Headline Field</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>'
1019 + ),
1020 + ),
1394 1021 array( 'input', 'fca_eoi[headline_copy]',
1395 - array( 'value' => K::get_var( 'headline_copy', $fca_eoi ) ),
1022 + array( 'class' => 'fca_eoi_text_input', 'value' => K::get_var( 'headline_copy', $post_meta ) ),
1396 1023 array( 'format' => '<p><label><span class="control-title">Headline Copy</span><br />:input</label></p>' )
1397 - )
1024 + ),
1025 + $this->generate_hidden_css_select_input('headline_font_size_selector'),
1026 + $this->generate_font_size_picker ('headline_font_size', 'Font Size'),
1027 + $this->generate_hidden_css_select_input('headline_font_color_selector'),
1028 + $this->generate_color_picker('headline_font_color','Font Color'),
1029 + $this->generate_hidden_css_select_input('headline_background_color_selector'),
1030 + $this->generate_color_picker('headline_background_color','Background Color'),
1031 +
1398 1032 ) );
1399 -
1033 +
1400 1034 $this->meta_box_field( 'fca_eoi_fieldset_description', 'Description', array(
1035 + array( 'input', 'fca_eoi[show_description_field]',
1036 + array(
1037 + 'type' => 'checkbox',
1038 + 'checked' => K::get_var( 'show_description_field', $post_meta, 'on' ) == 'off' ? '' : 'on',
1039 + 'class' => 'switch-input'
1040 + ),
1041 + array(
1042 + 'format' => '<p><span class="control-title">Description Field</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>'
1043 + ),
1044 + ),
1401 1045 array( 'textarea', 'fca_eoi[description_copy]', array(), array(
1402 1046 'format' => ':textarea',
1403 1047 'editor' => true,
1404 - 'value' => K::get_var( 'description_copy', $fca_eoi ),
1405 - ) )
1048 + 'value' => K::get_var( 'description_copy', $post_meta ),
1049 + ) ),
1050 + $this->generate_hidden_css_select_input('description_font_size_selector'),
1051 + $this->generate_font_size_picker ('description_font_size', 'Font Size'),
1052 + $this->generate_hidden_css_select_input('description_font_color_selector'),
1053 + $this->generate_color_picker('description_font_color','Font Color'),
1406 1054 ) );
1407 1055
1408 1056 $this->meta_box_field( 'fca_eoi_fieldset_name_field', 'Name Field', array(
1409 1057 array( 'input', 'fca_eoi[show_name_field]',
@@ -1408,183 +1056,385 @@
1408 1056 $this->meta_box_field( 'fca_eoi_fieldset_name_field', 'Name Field', array(
1409 1057 array( 'input', 'fca_eoi[show_name_field]',
1410 1058 array(
1411 1059 'type' => 'checkbox',
1412 - 'checked' => K::get_var( 'show_name_field', $fca_eoi ),
1060 + 'checked' => K::get_var( 'show_name_field', $post_meta, 'off' ) == 'off' ? '' : 'on',
1061 + 'class' => 'switch-input'
1413 1062 ),
1414 1063 array(
1415 - 'format' => '<p><label>:input Show Name Field</label></p>'
1064 + 'format' => '<p><span class="control-title">Name Field</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>'
1416 1065 ),
1417 1066 ),
1418 1067 array( 'input', 'fca_eoi[name_placeholder]',
1419 - array( 'value' => K::get_var( 'name_placeholder', $fca_eoi, 'Your Name' ) ),
1068 + array( 'class' => 'fca_eoi_text_input', 'value' => K::get_var( 'name_placeholder', $post_meta, 'First Name' ) ),
1420 1069 array( 'format' => '<p><label><span class="control-title">Placeholder Text</span><br />:input</label></p>' )
1421 - )
1070 + ),
1071 + $this->generate_hidden_css_select_input('name_font_size_selector'),
1072 + $this->generate_font_size_picker ('name_font_size', 'Font Size'),
1073 + $this->generate_hidden_css_select_input('name_font_color_selector'),
1074 + $this->generate_color_picker('name_font_color','Font Color'),
1075 + $this->generate_hidden_css_select_input('name_background_color_selector'),
1076 + $this->generate_color_picker('name_background_color','Background Color'),
1077 + $this->generate_hidden_css_select_input('name_border_color_selector'),
1078 + $this->generate_color_picker('name_border_color','Border Color'),
1079 + $this->generate_hidden_css_select_input('name_width_selector'),
1080 + $this->generate_width_select_input('name_width','Width', 100),
1081 + //$this->generate_hidden_css_select_input('name_alignment_selector'),
1082 + //$this->generate_alignment_select_input('name_alignment','Alignment', 'left'),
1422 1083 ) );
1423 1084
1424 1085 $this->meta_box_field( 'fca_eoi_fieldset_email_field', 'Email Field', array(
1425 1086 array( 'input', 'fca_eoi[email_placeholder]',
1426 - array( 'value' => K::get_var( 'email_placeholder', $fca_eoi, 'Your Email' ) ),
1087 + array( 'class' => 'fca_eoi_text_input', 'value' => K::get_var( 'email_placeholder', $post_meta, 'Your Email' ) ),
1427 1088 array( 'format' => '<p><label><span class="control-title">Placeholder Text</span><br />:input</label></p>' )
1428 - )
1089 + ),
1090 + $this->generate_hidden_css_select_input('email_font_size_selector'),
1091 + $this->generate_font_size_picker ('email_font_size', 'Font Size'),
1092 + $this->generate_hidden_css_select_input('email_font_color_selector'),
1093 + $this->generate_color_picker('email_font_color','Font Color'),
1094 + $this->generate_hidden_css_select_input('email_background_color_selector'),
1095 + $this->generate_color_picker('email_background_color','Background Color'),
1096 + $this->generate_hidden_css_select_input('email_border_color_selector'),
1097 + $this->generate_color_picker('email_border_color','Border Color'),
1098 + $this->generate_hidden_css_select_input('email_width_selector'),
1099 + $this->generate_width_select_input('email_width','Width', 100),
1100 + //$this->generate_hidden_css_select_input('email_alignment_selector'),
1101 + //$this->generate_alignment_select_input('email_alignment','Alignment', 'left'),
1429 1102 ) );
1430 1103
1431 1104 $this->meta_box_field( 'fca_eoi_fieldset_button', 'Button', array(
1432 1105 array( 'input', 'fca_eoi[button_copy]',
1433 - array( 'value' => K::get_var( 'button_copy', $fca_eoi, 'Subscribe Now' ) ),
1106 + array( 'class' => 'fca_eoi_text_input', 'value' => K::get_var( 'button_copy', $post_meta, 'Subscribe Now' ) ),
1434 1107 array( 'format' => '<p><label><span class="control-title">Button Copy</span><br />:input</label></p>' )
1435 - )
1108 + ),
1109 + $this->generate_hidden_css_select_input('button_font_size_selector'),
1110 + $this->generate_font_size_picker ('button_font_size', 'Font Size'),
1111 + $this->generate_hidden_css_select_input('button_font_color_selector'),
1112 + $this->generate_color_picker('button_font_color','Font Color'),
1113 +
1114 + $this->generate_hidden_css_select_input('button_background_color_selector'),
1115 + $this->generate_color_picker('button_background_color','Background Color'),
1116 + $this->generate_hidden_css_select_input('button_wrapper_background_color_selector'),
1117 + $this->generate_color_picker('button_wrapper_background_color','Bottom Border Color'),
1118 + $this->generate_hidden_css_select_input('button_border_color_selector'),
1119 + $this->generate_color_picker('button_border_color','Border Color'),
1120 +
1121 + $this->generate_hidden_css_select_input('button_hover_color_selector'),
1122 + $this->generate_color_picker('button_hover_color','Hover Color'),
1123 +
1124 + $this->generate_hidden_css_select_input('button_width_selector'),
1125 + $this->generate_width_select_input('button_width','Width', 100),
1126 + //$this->generate_hidden_css_select_input('button_alignment_selector'),
1127 + //$this->generate_alignment_select_input('button_alignment','Alignment', 'center'),
1128 +
1436 1129 ) );
1437 1130
1438 - $this->meta_box_field( 'fca_eoi_fieldset_privacy', 'Privacy Policy', array(
1439 - array( 'textarea', 'fca_eoi[privacy_copy]',
1131 + $this->meta_box_field( 'fca_eoi_fieldset_privacy', 'After Button Area', array(
1132 + array( 'input', 'fca_eoi[show_privacy_field]',
1440 1133 array(
1441 - 'class' => 'large-text',
1442 - ),
1443 - array(
1444 - 'format' => '<p><label><span class="control-title">Privacy Policy Copy</span><br />:textarea</label></p>',
1445 - 'value' => K::get_var( 'privacy_copy', $fca_eoi ),
1446 - )
1447 - )
1448 - ) );
1449 -
1450 - $this->meta_box_field( 'fca_eoi_fieldset_fatcatapps', 'Branding', array(
1451 - array( 'input', 'fca_eoi[show_fatcatapps_link]',
1452 - array(
1453 1134 'type' => 'checkbox',
1454 - 'checked' => K::get_var( 'show_fatcatapps_link', $fca_eoi ),
1135 + 'checked' => K::get_var( 'show_privacy_field', $post_meta, 'on' ) == 'off' ? '' : 'on',
1136 + 'class' => 'switch-input'
1455 1137 ),
1456 1138 array(
1457 - 'format' => '<p><label>:input Show <a href="http://fatcatapps.com/" target="_blank">Optin Cat</a> Branding</label></p>'
1458 - )
1459 - )
1460 - ) );
1461 -
1462 - $this->meta_box_field( 'fca_eoi_fieldset_error_text', 'Error Text', array(
1463 - array( 'textarea', 'fca_eoi[error_text_field_required]',
1464 - array(
1465 - 'class' => 'large-text'
1139 + 'format' => '<p><span class="control-title">After Button Area</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>'
1466 1140 ),
1467 - array(
1468 - 'format' => '<p><label><span class="control-title">Field Required</span><br />:textarea</label></p>',
1469 - 'value' => K::get_var( 'error_text_field_required', $fca_eoi, '' )
1470 - )
1471 1141 ),
1472 - array( 'textarea', 'fca_eoi[error_text_invalid_email]',
1142 + array( 'textarea', 'fca_eoi[privacy_copy]',
1473 1143 array(
1474 - 'class' => 'large-text'
1144 + 'class' => 'large-text fca_eoi_text_input',
1475 1145 ),
1476 1146 array(
1477 - 'format' => '<p><label><span class="control-title">Invalid Email</span><br />:textarea</label></p>',
1478 - 'value' => K::get_var( 'error_text_invalid_email', $fca_eoi, '' )
1147 + 'format' => '<p><label><span class="control-title">After Button Area Copy</span><br />:textarea</label></p>',
1148 + 'value' => K::get_var( 'privacy_copy', $post_meta ),
1479 1149 )
1480 - )
1150 + ),
1151 + $this->generate_hidden_css_select_input('privacy_font_size_selector'),
1152 + $this->generate_font_size_picker ('privacy_font_size', 'Font Size'),
1153 + $this->generate_hidden_css_select_input('privacy_font_color_selector'),
1154 + $this->generate_color_picker('privacy_font_color','Font Color'),
1481 1155 ) );
1156 + if ( $this->settings['distribution'] === 'free' ) {
1157 + $this->meta_box_field( 'fca_eoi_fieldset_fatcatapps', 'Branding', array(
1158 + array( 'input', 'fca_eoi[show_fatcatapps_link]',
1159 + array(
1160 + 'type' => 'checkbox',
1161 + 'checked' => K::get_var( 'show_fatcatapps_link', $post_meta ),
1162 + 'class' => 'switch-input'
1163 + ),
1164 + array(
1165 + 'format' => '<p><span class="control-title"><a href="http://fatcatapps.com/" target="_blank">Optin Cat</a> Branding</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>'
1166 + ),
1167 + ),
1168 +
1169 + $this->generate_hidden_css_select_input('branding_font_color_selector'),
1170 + $this->generate_color_picker ('branding_font_color', 'Font Color'),
1171 + ) );
1172 + }
1482 1173
1483 1174 echo '</div>';
1175 + echo '</div>';
1176 + echo '<br clear="all"/>';
1177 +
1178 +
1484 1179 }
1180 + public function generate_width_select_input( $id, $name, $default = 100 ) {
1181 + global $post;
1182 + $post_meta = get_post_meta( $post->ID, 'fca_eoi', true );
1183 + $value = K::get_var( "$id", $post_meta, $default );
1184 + $units = K::get_var( "$id" . "-units", $post_meta, '%' );
1185 +
1186 + $px_selected = $units == 'px' ? 'selected' : '';
1187 + $pct_selected = $units == '%' ? 'selected' : '';
1188 +
1189 + return array( 'input', "fca_eoi[$id]",
1190 + array(
1191 + 'type' => 'number',
1192 + 'min' => '0',
1193 + 'value' => $value,
1194 + 'class' => 'fca_eoi_width_input',
1195 + ),
1196 + array(
1197 + 'format' => "<p><label><span class='control-title'>$name</span></label><br />:input <select class='fca_eoi_width_units_select' name='fca_eoi[$id-units]'><option value='%' $pct_selected>%</option><option value='px' $px_selected>px</option></select></p>",
1198 +
1199 + )
1200 + );
1201 + }
1202 +
1203 + public function generate_alignment_select_input( $id, $name, $default ) {
1204 + global $post;
1205 + $post_meta = get_post_meta( $post->ID, 'fca_eoi', true );
1206 + $value = K::get_var( "$id", $post_meta, $default );
1485 1207
1486 - public function meta_box_content_thanks() {
1208 + return array( 'input', "fca_eoi[$id]",
1209 + array(
1210 + 'type' => 'hidden',
1211 + 'value' => $value,
1212 + 'class' => 'fca_eoi_alignment_input',
1213 + ),
1214 + array(
1215 + 'format' => "<p><label><span class='control-title'>$name</span></label><br><span data-value='left' class='dashicons dashicons-editor-alignleft fca-eoi-align-button fca-eoi-align-left-btn'></span><span data-value='center' class='dashicons dashicons-editor-aligncenter fca-eoi-align-button fca-eoi-align-center-btn'></span><span data-value='right' class='dashicons dashicons-editor-alignright fca-eoi-align-button fca-eoi-align-right-btn'></span>:input</p>",
1216 + ),
1217 + );
1218 + }
1219 +
1220 + public function generate_hidden_css_select_input ($id) {
1221 + return array( 'input', "fca_eoi[$id]",
1222 + array ( 'class' => 'fca-hidden-input hidden',
1223 + 'value' => ''
1224 + )
1225 + );
1226 + }
1227 +
1228 + public function generate_color_picker ($id, $name) {
1487 1229 global $post;
1230 + $post_meta = get_post_meta( $post->ID, 'fca_eoi', true );
1231 + return array( 'input', "fca_eoi[$id]",
1232 + array ( 'class' => 'fca-color-picker',
1233 + 'value' => K::get_var( "$id", $post_meta )
1234 + ),
1235 + array(
1236 + 'format' => '<p><label><span class="control-title">'. $name . '</span><br />:input</label></p>',
1237 + ),
1238 + );
1239 + }
1240 +
1241 + public function generate_font_size_picker ($id, $name) {
1242 + global $post;
1243 + $post_meta = get_post_meta( $post->ID, 'fca_eoi', true );
1244 + return array( 'select', "fca_eoi[$id]",
1245 +
1246 + array (
1247 + 'data-selected' => K::get_var( "$id", $post_meta ),
1248 + 'class' => 'fca-font-size-picker ',
1249 + ),
1250 + array(
1251 + 'format' => '<p class="clear"><label><span class="control-title">'. $name . '</span><br />:select</label></p>',
1252 + 'options' => array(
1253 + 'none' => '',
1254 + '7px' => '7px',
1255 + '8px' => '8px',
1256 + '9px' => '9px',
1257 + '10px' => '10px',
1258 + '11px' => '11px',
1259 + '12px' => '12px',
1260 + '13px' => '13px',
1261 + '14px' => '14px',
1262 + '15px' => '15px',
1263 + '16px' => '16px',
1264 + '17px' => '17px',
1265 + '18px' => '18px',
1266 + '19px' => '19px',
1267 + '20px' => '20px',
1268 + '21px' => '21px',
1269 + '22px' => '22px',
1270 + '23px' => '23px',
1271 + '24px' => '24px',
1272 + '25px' => '25px',
1273 + '26px' => '26px',
1274 + '27px' => '27px',
1275 + '28px' => '28px',
1276 + '29px' => '29px',
1277 + '30px' => '30px',
1278 + '31px' => '31px',
1279 + '32px' => '32px',
1280 + '33px' => '33px',
1281 + '34px' => '34px',
1282 + '35px' => '35px',
1283 + '36px' => '36px',
1284 + ),
1285 + 'selected' => K::get_var( "$id", $post_meta ),
1286 + 'return' => true,
1287 + ),
1288 + );
1289 + }
1290 +
1291 + public function meta_box_content_messages( $post ) {
1292 +
1488 1293 $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true );
1489 1294 $screen = get_current_screen();
1490 - $fca_eoi_last_3_forms = $this->settings[ 'fca_eoi_last_3_forms' ];
1491 -
1295 +
1492 1296 // Get the previous thank you page if this is a new post
1493 - $thank_you_page_suggestion = false;
1494 - if ( 'add' === $screen->action ) {
1495 - foreach ( $fca_eoi_last_3_forms as $fca_eoi_previous_form ) {
1496 - try {
1497 - if(
1498 - K::get_var( 'fca_eoi', $fca_eoi_previous_form )
1499 - && K::get_var( 'thank_you_page', $fca_eoi_previous_form[ 'fca_eoi' ] )
1500 - ) {
1501 - $thank_you_page_suggestion = $fca_eoi_previous_form[ 'fca_eoi' ][ 'thank_you_page' ];
1502 - break;
1503 - }
1504 - } catch ( Exception $e ) {}
1505 - }
1506 - }
1297 + $last_form_meta = get_option( 'fca_eoi_last_form_meta', '' );
1298 + $thank_you_page_suggestion = empty ($last_form_meta['thank_you_page']) ? '~' : $last_form_meta['thank_you_page'];
1299 + $thank_you_mode_suggestion = empty ($last_form_meta['thankyou_page_mode']) ? 'ajax' : $last_form_meta['thankyou_page_mode'];
1300 + $thank_you_text_suggestion = empty ($last_form_meta['thankyou_ajax']) ? __('Thank you! Please check your inbox for your confirmation email.', 'easy-opt-ins') : stripslashes( $last_form_meta['thankyou_ajax'] );
1301 + $subscribing_suggestion = empty ($last_form_meta['subscribing_message']) ? __('Subscribing...', 'easy-opt-ins') : stripslashes( $last_form_meta['subscribing_message'] );
1302 + $text_error_suggestion = empty ($last_form_meta['error_text_field_required']) ? __('Please fill out this field to continue', 'easy-opt-ins') : stripslashes( $last_form_meta['error_text_field_required'] );
1303 + $email_error_suggestion = empty ($last_form_meta['error_text_invalid_email']) ? __('Please enter a valid email address. For example "example@example.com".', 'easy-opt-ins') : stripslashes( $last_form_meta['error_text_invalid_email'] );
1304 +
1305 + echo '<h3>' . __('Subscribing Message', 'easy-opt-ins') . fca_eoi_tooltip ( __('This message will be displayed after your visitors submit your form.', 'easy-opt-ins') ) . '</h3>';
1306 + echo '<table class="fca_eoi_text_messages_table">';
1307 + echo '<tr><th>Message</th><td>';
1308 + K::input( 'fca_eoi[subscribing_message]',
1309 + array(
1310 + 'class' => 'regular-text',
1311 + 'value' => K::get_var( 'subscribing_message', $fca_eoi, $subscribing_suggestion ),
1312 + ),
1313 + array()
1314 + );
1507 1315
1508 - // Prepare options
1509 - $pages = array( '~' => __( 'Front page' ) );
1510 - $pages_objects = get_pages();
1511 - foreach ( $pages_objects as $page_obj ) {
1512 - $pages[ $page_obj->ID ] = $page_obj->post_title;
1513 - }
1514 - K::input( 'fca_eoi[thankyou_page_mode]'
1515 - , array(
1516 - 'type' => 'radio',
1316 + echo '</td></tr></table>';
1317 +
1318 + echo '<h3>' . __('Thank You Message', 'easy-opt-ins') . fca_eoi_tooltip( __('This message will be displayed after someone has successfully subscribed.', 'easy-opt-ins') ) . '</h3>';
1319 + echo '<table class="fca_eoi_text_messages_table">';
1320 + echo '<tr><th>Behavior</th><td>';
1321 + _e('Display immediately', 'easy-opt-ins');
1322 + $checked = K::get_var( 'thankyou_page_mode', $fca_eoi, $thank_you_mode_suggestion );
1323 +
1324 + K::input( 'fca_eoi[thankyou_page_mode]',
1325 + array(
1326 + 'type' => 'checkbox',
1517 1327 'value' => 'redirect',
1518 - 'checked' => 'redirect' === K::get_var( 'thankyou_page_mode', $fca_eoi ),
1328 + 'checked' => 'redirect' === $checked,
1329 + 'class' => 'switch-input fca-eoi-redirect-mode-toggle'
1330 + ),
1331 + array(
1332 + 'format' => '<label class="switch" id="fca-eoi-redirect-mode-toggle-label" >:input<span class="switch-label" data-on="" data-off=""></span><span class="switch-handle"></span></label>'
1519 1333 )
1520 - , array(
1521 - 'format' => '<p><label>:input Redirect to "Thank You" page</label></p>',
1334 + );
1335 + _e('Redirect', 'easy-opt-ins');
1336 +
1337 + echo '</td></tr>';
1338 +
1339 + echo '<tr id="fca_eoi_thankyou_ajax_msg"><th>Thank You Message</th><td>';
1340 +
1341 + K::textarea( 'fca_eoi[thankyou_ajax]', array(
1342 + 'class' => 'large-text fca_eoi_text_input',
1343 + ),
1344 + array(
1345 + 'value' => K::get_var( 'thankyou_ajax', $fca_eoi, $thank_you_text_suggestion ),
1522 1346 )
1523 - );
1347 + );
1348 +
1349 + echo '</td></tr>';
1524 1350
1525 - if ( $this->settings['distribution'] === 'premium' ) {
1526 1351
1527 - K::input( 'fca_eoi[thankyou_page_mode]'
1528 - , array(
1529 - 'type' => 'radio',
1530 - 'value' => 'ajax',
1531 - 'checked' => 'ajax' === K::get_var( 'thankyou_page_mode', $fca_eoi ),
1352 + echo '<tr id="fca_eoi_thankyou_redirect"><th>Redirect to';
1353 +
1354 + K::select(
1355 + 'fca_eoi[redirect_page_mode]',
1356 + array(
1357 + 'class' => 'fca-eoi-redirect-page-toggle',
1358 + ),
1359 + array(
1360 + 'options' => array(
1361 + 'page' => __( 'Page' ),
1362 + 'url' => __( 'URL' ),
1363 +
1364 + ),
1365 + 'selected' => K::get_var( 'redirect_page_mode', $fca_eoi, 'page' ),
1532 1366 )
1533 - , array(
1534 - 'format' => '<p><label>:input Display "Thank You" message using AJAX (Immediately after form submission. No page reload or redirect).</label></p>',
1535 - )
1367 + );
1368 +
1369 +
1370 + echo '</th><td>';
1371 +
1372 + echo '<span id="fca_eoi_redirect_page_span">';
1373 + $pages = array( '~' => __( 'Front page' ) );
1374 + $pages_objects = get_pages();
1375 + foreach ( $pages_objects as $page_obj ) {
1376 + $pages[ $page_obj->ID ] = $page_obj->post_title;
1377 + }
1378 + K::select( 'fca_eoi[thank_you_page]',
1379 + array(
1380 + 'class' => 'select2',
1381 + 'style' => 'width: 27em;',
1382 + ),
1383 + array(
1384 + 'format' => '<p><label>:select</label></p>',
1385 + 'options' => $pages,
1386 + 'selected' => 'add' === $screen->action
1387 + ? $thank_you_page_suggestion
1388 + : K::get_var( 'thank_you_page', $fca_eoi, '~' ),
1389 + )
1536 1390 );
1391 + echo '</span>';
1392 + echo '<span id="fca_eoi_redirect_url_span">';
1393 + K::input( 'fca_eoi[thank_you_url]',
1394 + array(
1395 + 'class' => 'regular-text',
1396 + 'value' => K::get_var( 'thank_you_url', $fca_eoi ),
1397 + 'placeholder' => 'enter URL here',
1398 + ),
1399 + array()
1400 + );
1401 + echo '</span>';
1402 + echo '</td></tr>';
1537 1403
1538 - }
1539 1404
1540 - echo "<hr>";
1405 + echo '</table>';
1541 1406
1542 - echo "<div id='fca_eoi_thankyou_redirect'>";
1407 + echo '<h3>' . __('Error Messages', 'easy-opt-ins') . fca_eoi_tooltip( __("These messages will be dispalyed if someone fills out the form incorrectly.", 'easy-opt-ins') ) . '</h3>';
1408 + echo '<table class="fca_eoi_text_messages_table">';
1409 + echo '<tr><th>Field Required</th><td>';
1410 +
1411 + K::textarea( 'fca_eoi[error_text_field_required]',
1412 + array(
1413 + 'class' => 'large-text fca_eoi_text_input',
1414 + ),
1415 + array(
1416 + 'value' => K::get_var( 'error_text_field_required', $fca_eoi, $text_error_suggestion ),
1417 + )
1418 + );
1419 +
1420 + echo '</td></tr>';
1543 1421
1544 - K::wrap( 'Redirect user to the following page after submitting the form:'
1545 - , null
1546 - , array( 'in' => 'p' )
1547 - );
1548 - K::select( 'fca_eoi[thank_you_page]'
1549 - , array(
1550 - 'class' => 'select2',
1551 - 'style' => 'width: 27em;',
1552 - )
1553 - , array(
1554 - 'format' => '<p><label>:select</label></p>',
1555 - 'options' => $pages,
1556 - 'selected' => 'add' === $screen->action
1557 - ? $thank_you_page_suggestion
1558 - : K::get_var( 'thank_you_page', $fca_eoi, '~' )
1559 - ,
1560 - )
1561 - );
1562 - K::wrap( __( 'Create a new "Thank You Page" &rsaquo;' )
1563 - , array(
1564 - 'href' => admin_url( 'post-new.php?post_type=page' ),
1565 - 'target' => '_blank',
1566 - )
1567 - , array(
1568 - 'in' => 'a',
1569 - 'html_before' => '<p>',
1570 - 'html_after' => '</p>',
1571 - )
1572 - );
1422 + echo '<tr><th>Invalid Email</th><td>';
1423 +
1424 + K::textarea( 'fca_eoi[error_text_invalid_email]',
1425 + array(
1426 + 'class' => 'large-text fca_eoi_text_input',
1427 + ),
1428 + array(
1429 + 'value' => K::get_var( 'error_text_invalid_email', $fca_eoi, $email_error_suggestion )
1430 + )
1431 + );
1432 +
1433 + echo '</td></tr>';
1573 1434
1574 - echo "</div>";
1575 1435
1576 - echo "<div id='fca_eoi_thankyou_ajax_msg'>";
1577 - K::textarea( 'fca_eoi[thankyou_ajax]'
1578 - , array(
1579 - 'class' => 'fca-eoi-thank-you-ajax',
1580 - )
1581 - , array(
1582 - 'value' => htmlentities ( K::get_var( 'thankyou_ajax', $fca_eoi, 'Thank you! Please check your inbox for your confirmation email.' )),
1583 - 'format' => '<label> Display this message after submitting the form:</label><br><br />:textarea',
1584 - )
1585 - );
1586 - echo "</div>";
1436 + echo '</table>';
1587 1437 }
1588 1438
1589 1439 public function meta_box_content_powerups() {
1590 1440
@@ -1589,36 +1439,61 @@
1589 1439 public function meta_box_content_powerups() {
1590 1440
1591 1441 global $post;
1592 1442 $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true );
1593 -
1594 1443 do_action('fca_eoi_powerups', $fca_eoi );
1595 1444 }
1596 1445
1597 - public function meta_box_content_debug() {
1598 -
1599 - global $post;
1600 -
1601 - $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true );
1602 -
1603 - !d( $fca_eoi );
1604 - }
1605 -
1606 1446 /**
1607 1447 * Save the Metabox Data
1608 1448 */
1609 1449 public function save_meta_box_content( $post_id, $post ) {
1610 -
1611 - // Save meta data
1612 - delete_post_meta( $post->ID, 'fca_eoi' );
1613 -
1614 - $animation = isset($_POST['fca_eoi_animations']) ? $_POST['fca_eoi_animations'] : '';
1615 - $animationValue = isset($_POST['fca_eoi_show_animation_checkbox']) ? $_POST['fca_eoi_show_animation_checkbox'] : '';
1616 - if ($animationValue != 'on') {
1617 - $animation = '';
1618 - }
1619 1450
1620 - if( $meta = K::get_var( 'fca_eoi', $_POST ) ) {
1451 + if ( isset ($_POST['fca_eoi'])) {
1452 + $form_id = $post_id;
1453 + $meta = $_POST['fca_eoi'];
1454 +
1455 + //SET SHOW/HIDE SETTINGS
1456 + $toggles = array (
1457 + 'show_headline_field',
1458 + 'show_description_field',
1459 + 'show_name_field',
1460 + 'show_close',
1461 + 'show_privacy_field',
1462 + 'push_page',
1463 + );
1464 +
1465 + forEach ( $toggles as $field ) {
1466 + $meta[$field] = empty ( $meta[$field] ) ? 'off' : 'on';
1467 + }
1468 +
1469 + $settings = array (
1470 + 'form_background_color_selector' => 'background-color',
1471 + 'form_border_color_selector' => 'border-color',
1472 + 'headline_font_size_selector' => 'font-size',
1473 + 'headline_font_color_selector' => 'color',
1474 + 'headline_background_color_selector' => 'background-color',
1475 + 'description_font_size_selector' => 'font-size',
1476 + 'description_font_color_selector' => 'color',
1477 + 'name_font_size_selector' => 'font-size',
1478 + 'name_font_color_selector' => 'color',
1479 + 'name_background_color_selector' => 'background-color',
1480 + 'name_border_color_selector' => 'border-color',
1481 + 'email_font_size_selector' => 'font-size',
1482 + 'email_font_color_selector' => 'color',
1483 + 'email_background_color_selector' => 'background-color',
1484 + 'email_border_color_selector' => 'border-color',
1485 + 'button_font_size_selector' => 'font-size',
1486 + 'button_font_color_selector' => 'color',
1487 + 'button_background_color_selector' => 'background-color',
1488 + 'button_border_color_selector' => 'border-color',
1489 + // 'button_hover_color_selector' => 'background-color', special case
1490 + 'button_wrapper_background_color_selector' => 'background-color',
1491 + 'privacy_font_size_selector' => 'font-size',
1492 + 'privacy_font_color_selector' => 'color',
1493 + 'branding_font_color_selector' => 'color',
1494 + );
1495 +
1621 1496 // Add provider if missing (happens on free distros where there is only one provider)
1622 1497 if( ! K::get_var( 'provider', $meta ) ) {
1623 1498 $meta[ 'provider' ] = $this->settings[ 'provider' ];
1624 1499 }
@@ -1644,15 +1519,8 @@
1644 1519 }
1645 1520 }
1646 1521 }
1647 1522
1648 - // Keep only the current layout inforamtion
1649 - foreach ( $meta as $k => $v ) {
1650 - if( preg_match( '|^[a-z]+_[0-9]+$|', $k ) && $k !== $meta[ 'layout' ] ) {
1651 - unset( $meta[ $k ] );
1652 - }
1653 - }
1654 -
1655 1523 // Make sure empty value for publish_postbox or publish_lightbox are saved as array(-1)
1656 1524 if( ! K::get_var( 'publish_postbox' , $meta, array() ) ) {
1657 1525 $meta[ 'publish_postbox' ] = array(-1);
1658 1526 }
@@ -1658,28 +1526,166 @@
1658 1526 }
1659 1527 if( ! K::get_var( 'publish_lightbox' , $meta, array() ) ) {
1660 1528 $meta[ 'publish_lightbox' ] = array(-1);
1661 1529 }
1662 -
1663 -
1664 - delete_post_meta( $post->ID, 'fca_eoi_layout' );
1665 - delete_post_meta( $post->ID, 'fca_eoi_provider' );
1666 -
1530 +
1531 + //sanitize thank you ajax message
1532 + if ( !empty ( $meta[ 'thankyou_ajax' ] ) ) {
1533 + $meta[ 'thankyou_ajax' ] = htmlentities($meta[ 'thankyou_ajax' ], ENT_QUOTES, "UTF-8");
1534 + }
1535 +
1536 + //RN NOTE: THIS DO ANYTHING? -> ONLY FOR CUSTOM HTML FORMS SEEMS LIKE
1667 1537 $on_save_function = $provider . '_on_save';
1668 1538 if ( function_exists( $on_save_function ) ) {
1669 1539 $meta = $on_save_function( $meta );
1670 1540 }
1671 1541
1672 -
1542 + //COMPILE CSS AND SAVE INTO 'HEAD' META
1543 + $layout_id = $meta[ 'layout' ];
1544 +
1545 + // General CSS for all forms
1546 + $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; }";
1673 1547
1674 - add_post_meta( $post->ID, 'fca_eoi', $meta );
1675 - add_post_meta( $post->ID, 'fca_eoi_layout', $meta[ 'layout' ] );
1676 - add_post_meta( $post->ID, 'fca_eoi_provider', $meta[ 'provider' ] );
1677 -
1678 - delete_post_meta( $post->ID, 'fca_eoi_animation' );
1679 - add_post_meta( $post->ID, 'fca_eoi_animation', $animation );
1680 -
1681 -
1548 + if ( !empty( $layout_id ) ) {
1549 +
1550 + // CACHE (ALMOST) ALL THE OUTPUT HERE
1551 + $layout = new EasyOptInsLayout( $layout_id );
1552 + $scss_path = $layout->path_to_resource( 'layout', 'scss' );
1553 +
1554 + if ( file_exists( $scss_path ) ) {
1555 + $css_path = str_replace ( '.scss' , '_min.css', $scss_path );
1556 + $css_file = file_get_contents( $css_path );
1557 + }
1558 +
1559 + $show_name = K::get_var( 'show_name_field', $meta, 'off' );
1560 + if ( $show_name === 'off' ) {
1561 + $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_name_field_wrapper {display: none !important;}";
1562 + $selector = K::get_var( 'email_width_selector', $meta, '' );
1563 + $css .= "#fca_eoi_form_$form_id $selector {float:none;margin-left:auto;margin-right:auto;}";
1564 +
1565 + }
1566 + $show_headline_field = K::get_var( 'show_headline_field', $meta, 'on' );
1567 + if ( $show_headline_field === 'off' ) {
1568 + $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_headline_copy_wrapper {display: none !important;}";
1569 + }
1570 +
1571 + $show_description_field = K::get_var( 'show_description_field', $meta, 'on' );
1572 + if ( $show_description_field === 'off' ) {
1573 + $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_description_copy_wrapper {display: none !important;}";
1574 + }
1575 +
1576 + $show_close = K::get_var( 'show_close', $meta, 'on' );
1577 + if ( $show_close === 'off' ) {
1578 + $css .= "#fca_eoi_form_$form_id .fca_eoi_banner_close_btn {display: none !important;}";
1579 + }
1580 +
1581 + $toggle_position = K::get_var( 'toggle_overlay_position', $meta, 'off' );
1582 + $offset = K::get_var( 'offset', $meta, 0 ) . 'px';
1583 +
1584 + if ( $toggle_position === 'on' && strrpos( $layout_id, 'overlay' ) !== false ) {
1585 + $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_overlay { left: $offset !important; right: initial !important; }";
1586 + } else if ( strrpos( $layout_id, 'overlay' ) !== false ) {
1587 + $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_overlay { right: $offset !important; }";
1588 + }
1589 + if ( $toggle_position === 'on' && strrpos( $layout_id, 'banner' ) !== false ) {
1590 + $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_banner { bottom: $offset !important; top: initial !important; }";
1591 + } else if ( strrpos( $layout_id, 'banner' ) !== false ) {
1592 + $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_banner { top: $offset !important; }";
1593 + }
1594 +
1595 + //VENDOR PREFIXED PLACEHOLDER COLORS
1596 + $placeholder_color = K::get_var( 'email_font_color', $meta, '#000000' );
1597 + $css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element::-webkit-input-placeholder {opacity:0.6;color:$placeholder_color;}";
1598 + $css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element::-moz-placeholder {opacity:0.6;color:$placeholder_color;}";
1599 + $css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element:-ms-input-placeholder {opacity:0.6;color:$placeholder_color;}";
1600 + $css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element:-moz-placeholder {opacity:0.6;color:$placeholder_color;}";
1601 +
1602 + //HOVER
1603 + $hover_color = K::get_var( 'button_hover_color', $meta, 'initial' );
1604 + $selector = K::get_var( 'button_hover_color_selector', $meta, '' );
1605 +
1606 + $s1 = str_replace ( ' input', ':hover', $selector );
1607 + $s2 = str_replace ( ' input', ' input:hover', $selector );
1608 +
1609 + $css .= "#fca_eoi_form_$form_id $s1, #fca_eoi_form_$form_id $s2 {background-color:$hover_color !important;}";
1610 +
1611 + //WIDTHS
1612 + $width_selects = array(
1613 + 'form_width',
1614 + 'name_width',
1615 + 'email_width',
1616 + 'button_width',
1617 + );
1618 +
1619 + forEach ( $width_selects as $w ) {
1620 + $width = K::get_var( $w, $meta, '100' );
1621 + $units = K::get_var( "$w-units", $meta, '%' );
1622 + $selector = K::get_var( $w . "_selector", $meta, '' );
1623 + $css .= "#fca_eoi_form_$form_id $selector {width:$width$units;}";
1624 +
1625 + }
1626 +
1627 + //ADD CSS FROM FILE
1628 + $css .= $css_file;
1629 +
1630 + //ADD CUSTOM CSS FROM SAVE
1631 +
1632 + $added_widget_3_css_rule = false;
1633 +
1634 + foreach ( $settings as $key => $property ) {
1635 + $selector = empty ( $meta[$key] ) ? '' : $meta[$key];
1636 + $input = str_replace ( '_selector', '', $key);
1637 +
1638 + if ( !empty ( $selector ) ) {
1639 + //SPECIAL CASE FOR BUTTON BORDER
1640 + if ( $key === 'button_wrapper_background_color_selector' ) {
1641 + $selector = str_replace ( 'input', '', $selector );
1642 + }
1643 + //SPECIAL CASE FOR WIDGET 3
1644 + 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' ) {
1645 + $css .= "#fca_eoi_form_$form_id form.fca_eoi_layout_3.fca_eoi_layout_widget svg.fca_eoi_layout_headline_copy_triangle { fill: $meta[$input] !important; }";
1646 + $added_widget_3_css_rule = true;
1647 + }
1648 +
1649 + $css .= "#fca_eoi_form_$form_id $selector { $property: $meta[$input] !important; }";
1650 +
1651 + }
1652 + }
1653 +
1654 + $animation = isset( $_POST['fca_eoi_animations'] ) && isset( $_POST['fca_eoi_show_animation_checkbox'] ) ? $_POST['fca_eoi_animations'] : '';
1655 + update_post_meta( $post->ID, 'fca_eoi_animation', $animation );
1656 +
1657 + $head = $css . '</style>';
1658 +
1659 + $html = fca_eoi_get_html ( $form_id, $meta );
1660 +
1661 + $head = $head . $html;
1662 + $meta[ 'post_id' ] = $post_id;
1663 +
1664 + //format conditions
1665 + $new_conditions = array();
1666 + $conditions = empty ( $meta['publish_lightbox']['conditions'] ) ? array() : $meta['publish_lightbox']['conditions'];
1667 +
1668 + forEach ( $conditions as $key => $value ) {
1669 + $new_conditions[] = array (
1670 + 'parameter' => $key,
1671 + 'value' => $value,
1672 + );
1673 + }
1674 + $meta['publish_lightbox']['conditions'] = $new_conditions;
1675 +
1676 + //SET THE LIVE TO 'FALSE' FOR BACKWARD COMPATIBILITY
1677 + $meta['publish_lightbox']['live'] = empty ( $meta['publish_lightbox']['live'] ) ? false : true;
1678 +
1679 + update_option( 'fca_eoi_last_provider', $meta[ 'provider' ] );
1680 + update_option( 'fca_eoi_last_form_meta', $meta );
1681 + update_post_meta( $post->ID, 'fca_eoi_meta_format', '2.0' );
1682 + update_post_meta( $post->ID, 'fca_eoi', $meta );
1683 + update_post_meta( $post->ID, 'fca_eoi_layout', $meta[ 'layout' ] );
1684 + update_post_meta( $post->ID, 'fca_eoi_provider', $meta[ 'provider' ] );
1685 + update_post_meta( $post->ID, 'fca_eoi_head', $head );
1686 +
1687 + }
1682 1688 }
1683 1689 }
1684 1690
1685 1691 public function live_preview( $content ) {
@@ -1693,76 +1699,88 @@
1693 1699 }
1694 1700
1695 1701 public function admin_enqueue() {
1696 1702
1697 - $protocol = is_ssl() ? 'https' : 'http';
1698 1703 $provider = $this->settings[ 'provider' ];
1699 1704 $providers_available = array_keys( $this->settings[ 'providers' ] );
1700 1705
1701 -
1702 -
1703 - if ( ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'eoi_powerups' ) || has_action( 'fca_eoi_powerups' ) ) {
1704 - wp_enqueue_style( 'fca_eoi_powerups', $this->settings['plugin_url'] . '/assets/powerups/fca_eoi_powerups.css' );
1705 -
1706 + /**
1707 + * Disable autosaving optin forms since it causes data loss
1708 + */
1709 + if ( 'easy-opt-ins' == get_post_type() ) {
1710 + wp_dequeue_script( 'autosave' );
1706 1711 }
1707 -
1708 - if ( ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'eoi_powerups' ) ) {
1709 - wp_enqueue_script('fca_eoi_powerups_javascript', $this->settings['plugin_url'] . '/assets/powerups/fca_eoi_powerup.js');
1710 -
1711 - }
1712 -
1713 1712
1714 1713 $screen = get_current_screen();
1715 1714 if( 'easy-opt-ins' === $screen->id ){
1716 - wp_enqueue_script( 'tooltipster', $this->settings[ 'plugin_url' ] . '/assets/vendor/tooltipster/jquery.tooltipster.min.js' );
1717 - wp_enqueue_style( 'tooltipster', $this->settings[ 'plugin_url' ] . '/assets/vendor/tooltipster/tooltipster.css' );
1718 - wp_enqueue_script( 'mustache', $protocol . '://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js' );
1719 - wp_enqueue_script( 'select2', $protocol . '://cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js' );
1720 - wp_enqueue_script( 'tinycolor', $protocol . '://cdnjs.cloudflare.com/ajax/libs/tinycolor/1.0.0/tinycolor.min.js' );
1721 - wp_enqueue_script( 'jscolor', $this->settings['plugin_url'] . '/assets/vendor/jscolor/jscolor.js' );
1722 - wp_enqueue_script( 'admin-cpt-easy-opt-ins-providers', $this->settings['plugin_url'] . '/assets/admin/eoi-providers.js' );
1723 - wp_enqueue_style( 'admin-cpt-easy-opt-ins-providers', $this->settings['plugin_url'] . '/assets/admin/eoi-providers.css' );
1724 - wp_enqueue_script( 'admin-cpt-easy-opt-ins', $this->settings['plugin_url'] . '/assets/admin/cpt-easy-opt-ins.js' );
1725 - wp_enqueue_style( 'fca_eoi', $this->settings[ 'plugin_url' ].'/assets/style' . ( EasyOptInsLayout::uses_new_css() ? '-new' : '' ) . '.css' );
1715 + global $post;
1716 + $meta = get_post_meta($post->ID, 'fca_eoi', true );
1717 + $options = get_option( 'fca_eoi_settings' );
1718 + //LOAD DEPENDENCIES
1719 + wp_enqueue_script( 'fca_eoi_tooltipster', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.js', array(), FCA_EOI_VER, true );
1720 + wp_enqueue_style( 'fca_eoi_tooltipster_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.css', array(), FCA_EOI_VER );
1721 + wp_enqueue_style( 'fca_eoi_tooltipster_theme_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster-borderless.min.css', array(), FCA_EOI_VER );
1722 +
1723 + wp_enqueue_style( 'wp-color-picker' );
1724 + wp_enqueue_script( 'wp-color-picker' );
1725 + wp_enqueue_script( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js', array(), FCA_EOI_VER, true );
1726 + wp_enqueue_style( 'font-awesome', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css', array(), FCA_EOI_VER );
1727 + wp_enqueue_style( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css', array(), FCA_EOI_VER );
1728 + wp_enqueue_script( 'accordion' );
1729 +
1730 + if ( !empty( $options['animation'] ) ) {
1731 + wp_enqueue_style( 'fca_eoi_powerups_animate', FCA_EOI_PLUGIN_URL . '/assets/vendor/animate/animate.min.css', array(), FCA_EOI_VER );
1732 + }
1733 +
1734 + //LOAD CUSTOM AJAX SPINNER CODE/CSS
1735 + wp_enqueue_script( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.min.js', array(), FCA_EOI_VER, true );
1736 + wp_enqueue_style( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.min.css', array(), FCA_EOI_VER );
1737 +
1738 + //LOAD COMMON CSS
1739 + wp_enqueue_style( 'fca-eoi-common-css', FCA_EOI_PLUGIN_URL .'/assets/style-new.min.css', array(), FCA_EOI_VER );
1740 +
1741 + //LOAD EDITOR JS
1742 + wp_enqueue_script( 'fca-eoi-editor', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-editor.min.js', array('jquery', 'fca_eoi_tooltipster', 'wp-color-picker', 'select2', 'accordion' ), FCA_EOI_VER, true );
1743 + wp_enqueue_script( 'fca-eoi-rules', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-rules.min.js', array('jquery' ), FCA_EOI_VER, true );
1744 +
1745 + //LOAD PROVIDER JS AND CSS
1726 1746 foreach ( $providers_available as $provider ) {
1727 - wp_enqueue_script( 'admin-cpt-easy-opt-ins-' . $provider, $this->settings['plugin_url'] . '/providers/' . $provider . '/cpt-easy-opt-ins.js' );
1747 + wp_enqueue_script( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . '/providers/' . $provider . '/cpt-easy-opt-ins.min.js', array(), FCA_EOI_VER, true );
1728 1748
1729 - $css_path = '/providers/' . $provider . '/cpt-easy-opt-ins.css';
1730 - if ( is_readable( $this->settings['plugin_dir'] . $css_path ) ) {
1731 - wp_enqueue_style( 'admin-cpt-easy-opt-ins-' . $provider, $this->settings['plugin_url'] . $css_path );
1749 + $css_path = '/providers/' . $provider . '/cpt-easy-opt-ins.min.css';
1750 + if ( is_readable( FCA_EOI_PLUGIN_DIR . $css_path ) ) {
1751 + wp_enqueue_style( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . $css_path, array(), FCA_EOI_VER );
1732 1752 }
1733 1753 }
1734 - wp_enqueue_style( 'admin-cpt-easy-opt-ins', $this->settings['plugin_url'] . '/assets/admin/cpt-easy-opt-ins.css' );
1735 - if ( EasyOptInsLayout::uses_new_css() ) {
1736 - wp_enqueue_style( 'admin-cpt-easy-opt-ins-new', $this->settings['plugin_url'] . '/assets/admin/cpt-easy-opt-ins-new.css' );
1737 - } else {
1738 - wp_enqueue_style( 'admin-cpt-easy-opt-ins-old', $this->settings['plugin_url'] . '/assets/admin/cpt-easy-opt-ins-old.css' );
1739 - }
1740 - wp_enqueue_style( 'font-awesome', $protocol . '://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css' );
1741 - wp_enqueue_style( 'select2', $protocol . '://cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css' );
1742 - wp_enqueue_script('bootstrap-js', $protocol . '://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/js/bootstrap.min.js');
1754 + //SEND VARIABLES TO JS
1755 + $useGroups = empty ( $options['mailchimp_groups'] ) ? array('off') : array('on') ;
1756 + wp_localize_script( 'admin-cpt-easy-opt-ins-mailchimp', 'fcaEoiUseGroups', $useGroups );
1757 +
1758 + $tags = empty($meta['aweber_tags']) ? '' : $meta['aweber_tags'];
1759 + $aweberSettings = array(
1760 + 'tags' => $tags,
1761 + );
1762 + wp_localize_script( 'admin-cpt-easy-opt-ins-aweber', 'fcaEoiAweberSettings', $aweberSettings );
1743 1763
1764 + $file = plugin_dir_path( __FILE__ ) . "layout-cache";
1765 + $layout_data = unserialize (file_get_contents($file));
1744 1766
1767 + wp_localize_script( 'fca-eoi-editor', 'fcaEoiLayouts', $layout_data );
1768 +
1769 + //EDITOR CSS
1770 + wp_enqueue_style( 'fca-eoi-editor-css', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-editor.min.css', array(), FCA_EOI_VER );
1771 +
1745 1772 if ( has_action( 'fca_eoi_powerups' ) ) {
1746 - wp_enqueue_script('fca_eoi_powerups', $this->settings['plugin_url'] . '/assets/powerups/fca_eoi_powerups.js');
1773 + wp_enqueue_script('fca_eoi_powerups', FCA_EOI_PLUGIN_URL . '/assets/powerups/fca_eoi_powerups.min.js', array(), FCA_EOI_VER, true);
1747 1774 }
1748 1775 }
1749 1776 if( 'widgets' === $screen->id ){
1750 - wp_enqueue_script( 'select2', $protocol . '://cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js' );
1751 - wp_enqueue_style( 'select2', $protocol . '://cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css' );
1777 + wp_enqueue_script( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js', array(), FCA_EOI_VER, true );
1778 + wp_enqueue_style( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css', array(), FCA_EOI_VER );
1752 1779 }
1753 1780 }
1754 1781
1755 1782 /**
1756 - * Disable autosaving optin forms since it causes data loss
1757 - */
1758 - function disable_autosave() {
1759 - if ( 'easy-opt-ins' == get_post_type() ) {
1760 - wp_dequeue_script( 'autosave' );
1761 - }
1762 - }
1763 -
1764 - /**
1765 1783 * Hides minor publising form items (status, visibility and publication date)
1766 1784 *
1767 1785 * This function shoud be used along with force_published to prevent
1768 1786 * saving posts as drafts
@@ -1772,36 +1790,97 @@
1772 1790 if( in_array( $screen->id, array( 'easy-opt-ins' ) ) ) {
1773 1791 echo '<style>#minor-publishing { display: none; }</style>';
1774 1792 }
1775 1793 }
1794 +
1795 + public function onboard_help() {
1776 1796
1777 - /**
1778 - * Disables meta box toggling (collapse/expand) for specified post types
1779 - */
1780 - public function disable_metabox_toggle() {
1797 + $current_screen = get_current_screen();
1798 +
1799 + // Exit function if we are not on the opt-in list
1800 + if ( $current_screen->id === 'edit-easy-opt-ins' ) {
1801 + $posts = get_posts( 'posts_per_page=-1&post_type=easy-opt-ins' );
1802 +
1803 + if ( empty ( $posts ) ) {
1804 +
1805 + wp_enqueue_style( 'fca_eoi_onboard_stylesheet', FCA_EOI_PLUGIN_URL . '/assets/admin/onboard.min.css', array(), FCA_EOI_VER );
1806 +
1807 + echo '<div class="error fca_eoi_onboard_div">';
1808 +
1809 + echo '<img id="fca_eoi_onboard_text" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/onboarding-text.png' . '">';
1810 + echo '<img id="fca_eoi_onboard_arrow" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/onboarding-arrow.png' . '">';
1811 + echo '</div>';
1812 + }
1813 + }
1814 + }
1815 +
1816 + public function google_changes_notice() {
1781 1817
1782 - $current_screen = get_current_screen();
1818 + $dismissed = get_option ( 'fca_eoi_dismiss_google_changes' );
1819 +
1820 + if ( $dismissed !== 'true' ) {
1821 +
1822 + wp_enqueue_script( 'fca_eoi_dismiss_review_js', FCA_EOI_PLUGIN_URL . '/assets/admin/dismiss.min.js', array(), FCA_EOI_VER );
1823 + wp_localize_script( 'fca_eoi_dismiss_review_js', 'fcaEoiDismiss', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'fca_eoi_dismiss' ) ) );
1824 + $blog_link = 'https://fatcatapps.com/interstitials-update/';
1825 +
1826 + echo '<div class="notice notice-info fca_eoi_review_div" style="padding-bottom: 8px;">';
1827 + echo '<img style="float:left" width="120" height="120" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/optincat.png' . '">';
1828 + echo '<p><strong>' . __( "Optin Cat: New Google algorithm update may affect your rankings", 'easy-opt-ins' ) . '</strong></p>';
1829 +
1830 + echo '<p>' . __( "Google has recently made changes to its mobile search results. These changes may negatively impact sites that use popups on mobile devices if no action is taken.", 'easy-opt-ins') . '</p>';
1831 + echo '<br>';
1832 +
1833 + echo "<a target='_blank' href='$blog_link' class='button button-primary'>" . __( 'Learn More & Fix This', 'easy-opt-ins') . "</a> ";
1834 + echo "<button type='button' class='button button-secondary' data-option='fca_eoi_dismiss_google_changes' id='fca-eoi-dismiss-review-btn'>" . __( 'Dismiss', 'easy-opt-ins') . "</button>";
1835 + echo '<br style="clear:both">';
1836 + echo '</div>';
1837 + }
1838 + }
1839 +
1840 + public function review_notice() {
1841 +
1842 + $dismissed = get_option ( 'fca_eoi_dismiss_review' );
1843 +
1844 + if ( $dismissed !== 'true' ) {
1845 + $activity = EasyOptInsActivity::get_instance();
1846 + $stats = $activity->get_form_stats( $this->activity_day_interval['form_list'] );
1847 + $conversions = empty ( $stats['conversions'] ) ? array() : $stats['conversions'];
1848 + $conversions = array_sum ( $conversions );
1849 +
1850 + if ( $conversions >= 25 ) {
1851 + $review_link = 'https://wordpress.org/support/plugin/' . FCA_EOI_PLUGIN_SLUG . '/reviews/?rate=5#new-post';
1783 1852
1784 - // Array of post types where we want to remove metabox toggling
1785 - $post_types = array(
1786 - 'easy-opt-ins',
1787 - );
1853 + wp_enqueue_script( 'fca_eoi_dismiss_review_js', FCA_EOI_PLUGIN_URL . '/assets/admin/dismiss.min.js', array(), FCA_EOI_VER );
1854 + wp_localize_script( 'fca_eoi_dismiss_review_js', 'fcaEoiDismiss', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'fca_eoi_dismiss' ) ) );
1855 +
1856 + echo '<div class="notice notice-success fca_eoi_review_div">';
1857 + echo '<img style="float:left" width="120" height="120" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/optincat.png' . '">';
1858 + echo '<p><strong>' . __( "Great work! You've gotten more than 25 email subscribers using Optin Cat.", 'easy-opt-ins' ) . '</strong></p>';
1859 +
1860 + echo '<p>' . sprintf( __( "If you love Optin Cat, why not leave us a nice review on %sWordPress.org%s? Reviews keeps us motivated - we'd really appreciate it.", 'easy-opt-ins' ), "<a target='_blank' href='$review_link'>", '</a>') . '</p>';
1861 + echo '<br>';
1862 +
1863 + echo "<a target='_blank' href='$review_link' class='button button-primary'>" . __( 'Leave a Review', 'easy-opt-ins') . "</a> ";
1864 + echo "<button type='button' class='button button-secondary' data-option='fca_eoi_dismiss_review' id='fca-eoi-dismiss-review-btn'>" . __( 'Dismiss', 'easy-opt-ins') . "</button>";
1865 + echo '<br style="clear:both">';
1866 + echo '</div>';
1867 +
1868 + }
1869 + }
1870 + }
1871 +
1872 + public function ajax_dismiss_notice() {
1873 +
1874 + $nonce = empty ( $_REQUEST['nonce'] ) ? '' : $_REQUEST['nonce'];
1875 + $option = empty ( $_REQUEST['option'] ) ? 'fca_eoi_dismiss_review' : $_REQUEST['option'];
1788 1876
1789 - if( in_array( $current_screen->id, $post_types ) ) {
1790 - ?>
1791 - <script type="text/javascript">
1792 - jQuery( document ).ready( function($) {
1793 - $( '.postbox' ).removeClass( 'closed' );
1794 - $( '.postbox .hndle' ).css( 'cursor', 'default' );
1795 - $( document ).delegate( '.postbox h3, .postbox .handlediv', 'click', function() {
1796 - $( this )
1797 - .unbind( 'click.postboxes' )
1798 - .parent().removeClass( 'closed' );
1799 - } );
1800 - } );
1801 - </script>
1802 - <?php
1877 + if ( wp_verify_nonce ( $nonce, 'fca_eoi_dismiss') == 1 ) {
1878 + if ( update_option( $option, 'true' ) ) {
1879 + wp_send_json_success( $option );
1880 + }
1803 1881 }
1882 + wp_send_json_error();
1804 1883 }
1805 1884
1806 1885 /**
1807 1886 * Forces one column
@@ -1914,16 +1993,17 @@
1914 1993 /**
1915 1994 * Add the desired body classes (backend)
1916 1995 */
1917 1996 public function add_body_class( $classes ) {
1918 -
1919 1997 return "$classes fca_eoi";
1920 1998 }
1921 -
1999 +
2000 +
1922 2001 /**
1923 2002 * Handle Adding a subscriber with Ajax
1924 2003 */
1925 2004 public function ajax_subscribe() {
2005 +
1926 2006 $error = '';
1927 2007 // Get meta
1928 2008 $id = $_REQUEST['form_id'];
1929 2009
@@ -1929,123 +2009,57 @@
1929 2009
1930 2010 if (empty ($id)){
1931 2011 $error .= "Couldn't find form ID";
1932 2012 }
1933 -
1934 - $nonce = $_REQUEST['nonce'];
1935 - $nonceVerified = wp_verify_nonce( $nonce, 'fca_eoi_submit_form' );
1936 - if ($nonceVerified === FALSE) {
1937 - $error .= " Couldn't verify form submission";
1938 - }
1939 -
2013 +
1940 2014 $fca_eoi = get_post_meta( $id, 'fca_eoi', true );
1941 2015
1942 2016 if (empty ($fca_eoi)){
1943 - $error .= " Couldn't find post meta";
2017 + $error .= "Couldn't find post meta";
1944 2018 }
1945 2019
1946 2020 $provider = K::get_var( 'provider' , $fca_eoi );
1947 2021
1948 -
1949 2022 // Check a list_id is provided
1950 2023 $list_id = K::get_var( $provider . '_list_id' , $fca_eoi );
1951 -
1952 - // @todo: remove
1953 - // Hack for mailchimp upgrade
1954 - if( empty( $fca_eoi[ 'provider' ] ) ) {
1955 - $list_id = K::get_var(
1956 - 'mailchimp_list_id'
1957 - , $fca_eoi
1958 - , K::get_var( 'list_id' , $fca_eoi )
1959 - );
1960 - $provider = 'mailchimp';
2024 + if ( empty( $list_id ) ) {
2025 + $error .= "List not set";
1961 2026 }
1962 - // End of Hack
1963 -
1964 - // Hack for campaignmonitor upgrade
1965 - if( strlen( K::get_var( 'list_id' , $fca_eoi ) ) == 32){
1966 - $list_id = K::get_var(
1967 - 'campaignmonitor_list_id'
1968 - , $fca_eoi
1969 - , K::get_var( 'list_id' , $fca_eoi )
1970 - );
1971 - $provider = 'campaignmonitor';
2027 +
2028 + $nonce = $_REQUEST['nonce'];
2029 + $nonceVerified = wp_verify_nonce( $nonce, 'fca_eoi_submit_form' );
2030 + if ($nonceVerified === FALSE) {
2031 + $error .= "Couldn't verify form submission";
1972 2032 }
1973 - if ( $provider == 'campaignmonitor' ) {
1974 - $_POST['campaignmonitor_api_key'] = $fca_eoi['campaignmonitor_api_key'];
1975 - }
1976 - // End of Hack
1977 2033
2034 + // Subscribe user
2035 + $status = false;
2036 +
2037 + if( $list_id && $nonceVerified !== FALSE ) {
2038 + $str = $provider . '_add_user';
2039 +
2040 + $status = call_user_func( $provider . '_add_user' , $this->settings , $_POST , $list_id );
2041 +
2042 + do_action('fca_eoi_after_submission', $fca_eoi, $_POST );
1978 2043
1979 - // Hack for drip
1980 - if ( $provider == 'drip' ) {
1981 - $_POST['drip_api_token'] = $fca_eoi['drip_api_token'];
1982 - $_POST['drip_account_id'] = $fca_eoi['drip_account_id'];
1983 - $_POST['drip_action'] = $fca_eoi['drip_action'];
1984 - $_POST['drip_list_id'] = $fca_eoi['drip_list_id'];
2044 + if ($status !== TRUE) {
2045 + $error .= " Can't add user";
2046 + }
1985 2047 }
1986 -
1987 - // Hack for mailchimp upgrade
1988 - if( empty( $fca_eoi[ 'provider' ] ) ) {
1989 - $list_id = K::get_var(
1990 - 'getresponse_list_id'
1991 - , $fca_eoi
1992 - , K::get_var( 'list_id' , $fca_eoi )
1993 - );
1994 - $provider = 'getresponse';
1995 - }
1996 - // End of Hack
1997 -
1998 - // Hack for custom form upgrade
1999 - if( empty( $fca_eoi[ 'provider' ] ) ) {
2000 - $list_id = K::get_var(
2001 - 'customform_list_id'
2002 - , $fca_eoi
2003 - , K::get_var( 'list_id' , $fca_eoi )
2004 - );
2005 - $provider = 'customform';
2006 - }
2007 - if ( $provider == 'customform' ) {
2008 - $_POST['customform_request'] = $fca_eoi['customform_request'];
2009 - }
2010 2048
2011 - // End of Hack
2012 -
2013 -
2014 - if (empty ($provider)){
2015 - $error .= " Couldn't find provider";
2016 - }
2017 -
2018 - if (empty ($list_id)){
2019 - $error .= " Couldn't find list ID";
2020 - }
2021 -
2022 - // Subscribe user
2023 - if( $list_id ) {
2024 - $status = call_user_func( $provider . '_add_user' , $this->settings , $_POST , $list_id );
2025 - $double_opt_in = K::get_var( 'mailchimp_double_opt_in', $fca_eoi, '' );
2026 - do_action('fca_eoi_after_submission'
2027 - , $fca_eoi
2028 - , $_POST
2029 - );
2030 - }
2031 -
2032 - if ($status !== TRUE) {
2033 - $error .= " Error: $status";
2034 - }
2035 -
2036 -
2037 2049 if ( $status !== FALSE && $error === '' ) {
2038 2050 echo '✓';
2039 2051 EasyOptInsActivity::get_instance()->add_conversion( $id );
2040 2052 } else {
2041 - echo '✗' . $error;
2042 - }
2053 + echo '✗' . " Error: " . $error;
2054 + }
2055 +
2043 2056 exit;
2044 2057 }
2045 2058
2046 2059 public function admin_notices() {
2047 2060
2061 + //RN NOTE: MAYBE REWRITE
2048 2062 $current_screen = get_current_screen();
2049 2063
2050 2064 // Exit function if we are not on the opt-in editing page
2051 2065 if ( ! (
@@ -2103,27 +2117,22 @@
2103 2117 }
2104 2118
2105 2119 add_action( 'wp', array( $this, 'content' ), 10 );
2106 2120 }
2107 -
2121 +
2122 + //SEARCH THE CONTENT AND APPEND ANY RELEVANT POST BOXES
2108 2123 public function content() {
2109 -
2124 +
2110 2125 global $post;
2111 -
2112 - if ( empty( $post ) ) {
2126 +
2127 + // Work only when viewing a post of any type & not viewing an opt-in editor
2128 + if ( empty( $post ) OR $post->post_type === 'easy-opt-ins' ) {
2113 2129 return;
2114 2130 }
2131 +
2132 + //ADD SESSION COOKIE TRACKING SCRIPT
2133 + wp_enqueue_script( 'fca_eoi_pagecount_js', FCA_EOI_PLUGIN_URL.'/assets/pagecount.min.js', array(), FCA_EOI_VER, true );
2115 2134
2116 - // Do nothing if viewing an opt-in
2117 - if ( 'easy-opt-ins' === $post->post_type ) {
2118 - return;
2119 - }
2120 -
2121 - // Work only when viewing a post of any type
2122 - if ( empty( $post ) ) {
2123 - return;
2124 - }
2125 -
2126 2135 $priorities = array();
2127 2136
2128 2137 // Post details
2129 2138 $post_ID = $post->ID;
@@ -2140,10 +2149,10 @@
2140 2149 }
2141 2150
2142 2151 $priorities[] = '#' . $post_ID;
2143 2152
2144 - $taxonomies = get_taxonomies('','names');
2145 - $post_taxonomies = wp_get_object_terms( $post->ID,$taxonomies);
2153 + $taxonomies = get_taxonomies('', 'names');
2154 + $post_taxonomies = wp_get_object_terms( $post->ID, $taxonomies);
2146 2155 foreach ( $post_taxonomies as $t ) {
2147 2156 $condition = $post_type . ':' . $t->term_id;
2148 2157
2149 2158 $post_cond[] = $condition;
@@ -2152,28 +2161,22 @@
2152 2161
2153 2162 $priorities[] = $post_type;
2154 2163 $priorities[] = '*';
2155 2164
2156 - $fca_eoi_last_99_forms = array();
2157 - foreach (get_posts( 'posts_per_page=99&post_type=easy-opt-ins' ) as $i => $f ) {
2158 - $fca_eoi_last_99_forms[ $i ][ 'post' ] = $f;
2159 - $fca_eoi_last_99_forms[ $i ][ 'fca_eoi' ] = get_post_meta( $f->ID, 'fca_eoi', true );
2165 + $optins = get_posts( 'posts_per_page=99&post_type=easy-opt-ins' );
2166 +
2167 + $fca_eoi_postboxes = array();
2168 +
2169 + foreach ( $optins as $i => $p ) {
2170 + $fca_eoi_postboxes[ $i ][ 'post' ] = $p;
2171 + $fca_eoi_postboxes[ $i ][ 'fca_eoi' ] = get_post_meta( $p->ID, 'fca_eoi', true );
2160 2172 }
2161 - // wp_reset_query();
2162 2173
2163 2174 $postboxes = array();
2164 2175
2165 2176 // Append postcode shortcode when the conditions match
2166 - foreach( $fca_eoi_last_99_forms as $f) {
2177 + foreach( $fca_eoi_postboxes as $f ) {
2167 2178
2168 - // Exclude other layout types
2169 - if ( empty ( $f[ 'fca_eoi' ][ 'layout' ] ) ) {
2170 - continue;
2171 - }
2172 - if ( strpos( $f[ 'fca_eoi' ][ 'layout' ], 'postbox_' ) !== 0 ) {
2173 - continue;
2174 - }
2175 -
2176 2179 // Get conditions
2177 2180 $eoi_form_cond = K::get_var( 'publish_postbox', $f[ 'fca_eoi' ], array() );
2178 2181
2179 2182 // Append
@@ -2187,9 +2190,9 @@
2187 2190 }
2188 2191
2189 2192 if ( ! empty( $postboxes ) ) {
2190 2193 foreach ( $priorities as $cond ) {
2191 - if ( ! empty( $postboxes[ $cond ] ) ) {
2194 + if ( !empty( $postboxes[ $cond ] ) ) {
2192 2195 $post->post_content .= $postboxes[ $cond ];
2193 2196 return;
2194 2197 }
2195 2198 }
@@ -2198,735 +2201,251 @@
2198 2201 return;
2199 2202 }
2200 2203 }
2201 2204
2202 - private function get_tc_token( $form_id ) {
2203 - return "$form_id";
2204 - }
2205 -
2206 - private function to_call_tc_condition( $name, $arguments ) {
2207 - return array_merge( array( $name ), $arguments );
2208 - }
2209 -
2210 - private function to_value_tc_condition( $form_id, $name, $eoi_condition ) {
2211 - $value = intval( $eoi_condition['value'] );
2212 - $params = array( $value );
2213 -
2214 - if ( $name === 'page_views' ) {
2215 - $params[] = $this->get_tc_token( $form_id );
2216 - } else if ( $name === 'time_on_page' ) {
2217 - $params[0] *= 1000;
2205 + public function scan_for_shortcodes( $content ) {
2206 + if ( preg_match_all( '/data-optin-cat\s*=\s*["\']?\s*(\d+)/', $content, $matches ) ) {
2207 + $this->two_step_ids_on_page = array_map( 'intval', $matches[1] );
2218 2208 }
2219 2209
2220 - return $this->to_call_tc_condition( $name, $params );
2210 + return $content;
2221 2211 }
2222 2212
2223 - private function to_server_pass_tc_condition( $post_id, $parameter, $eoi_condition ) {
2224 - $url = add_query_arg( array(
2225 - 'fca_eoi_tc_condition_pass' => urlencode( $parameter ),
2226 - 'fca_eoi_tc_condition_value' => urlencode( implode( ',', $eoi_condition['value'] ) ),
2227 - 'fca_eoi_tc_condition_post_id' => $post_id
2213 + public function maybe_show_lightbox() {
2214 +
2215 + // Get lightboxes
2216 + $lightboxes = get_posts( array(
2217 + 'post_type' => 'easy-opt-ins',
2218 + 'posts_per_page' => -1,
2219 + 'orderby' => 'ID',
2220 + 'meta_key' => 'fca_eoi_layout',
2221 + 'meta_value' => 'lightbox_',
2222 + 'meta_compare' => 'like',
2228 2223 ) );
2224 +
2225 + // BANNERS
2226 + $banners = get_posts( array(
2227 + 'post_type' => 'easy-opt-ins',
2228 + 'posts_per_page' => -1,
2229 + 'orderby' => 'ID',
2230 + 'meta_key' => 'fca_eoi_layout',
2231 + 'meta_value' => 'banner_',
2232 + 'meta_compare' => 'like',
2233 + ) );
2234 +
2235 + //OVERLAY AND BANNERS WORK FUNCTIONALLY THE SAME
2236 + $banners = array_merge ( $banners, get_posts( array(
2237 + 'post_type' => 'easy-opt-ins',
2238 + 'posts_per_page' => -1,
2239 + 'orderby' => 'ID',
2240 + 'meta_key' => 'fca_eoi_layout',
2241 + 'meta_value' => 'overlay_',
2242 + 'meta_compare' => 'like',
2243 + ) ) );
2229 2244
2230 - return $this->to_call_tc_condition( 'server_pass', array( $url, 'true' ) );
2231 - }
2232 -
2233 - private function to_tc_condition( $form_id, $post_id, $eoi_condition ) {
2234 - $eoi_to_tc_value_map = array(
2235 - 'pageviews' => 'page_views',
2236 - 'scrolled_percent' => 'scroll_percent',
2237 - 'time_on_page' => 'time_on_page'
2238 - );
2239 -
2240 - $eoi_server_pass_conditions = array( 'include', 'exclude' );
2241 -
2242 - $parameter = $eoi_condition['parameter'];
2243 - if ( array_key_exists( $parameter, $eoi_to_tc_value_map ) ) {
2244 - return $this->to_value_tc_condition( $form_id, $eoi_to_tc_value_map[ $parameter ], $eoi_condition );
2245 - } else if ( in_array( $parameter, $eoi_server_pass_conditions ) ) {
2246 - return $this->to_server_pass_tc_condition( $post_id, $parameter, $eoi_condition );
2245 + if( empty( $lightboxes ) && empty ( $banners ) ) {
2246 + return false;
2247 2247 }
2248 2248
2249 - return null;
2250 - }
2251 -
2252 - private function to_show_every_tc_condition( $form_id, $condition ) {
2253 - if ( in_array( $condition, array( 'day', 'month', 'once', 'session' ) ) ) {
2254 - return array( $condition, $this->get_tc_token( $form_id ) );
2255 - } elseif ( $condition === 'always' ) {
2256 - return 'true';
2257 - } elseif ( $condition === 'never' ) {
2258 - return 'false';
2249 + $two_step_popups = array();
2250 + $traditional_popups = array();
2251 + $banners_to_show = array();
2252 +
2253 + foreach ( $banners as $banner ) {
2254 + $m = get_post_meta( $banner->ID , 'fca_eoi', true );
2255 + $conditions = K::get_var( 'publish_lightbox', $m, array() );
2256 +
2257 + if ( $this->test_server_conditions( $conditions ) ) {
2258 + $banners_to_show[] = array(
2259 + 'id' => $banner->ID,
2260 + 'meta' => $m,
2261 + 'conditions' => $conditions,
2262 + );
2263 + }
2259 2264 }
2265 +
2266 + foreach ( $lightboxes as $lightbox ) {
2260 2267
2261 - return $condition;
2262 - }
2263 -
2264 - private function get_tc_conditions( $form_id, $post_id, $conditions ) {
2265 - $tc_conditions = array();
2266 - $sequence_conditions = array();
2267 -
2268 - if ( ! empty( $conditions['show_every'] ) ) {
2269 - $condition = $this->to_show_every_tc_condition( $form_id, $conditions['show_every'] );
2270 -
2271 - if ( $condition === 'false' ) {
2272 - return array( 'false' );
2273 - } else {
2274 - $sequence_conditions[] = $condition;
2268 + // Get conditions
2269 + $lightbox->fca_eoi = get_post_meta( $lightbox->ID , 'fca_eoi', true );
2270 + $publish_lightbox_mode = K::get_var( 'publish_lightbox_mode', $lightbox->fca_eoi, array() );
2271 +
2272 + $lightbox_conditions = K::get_var( 'publish_lightbox', $lightbox->fca_eoi, array() );
2273 +
2274 + // If on a free distribution, force traditional popup mode
2275 + if ( $this->settings['distribution'] === 'free' ) {
2276 + $publish_lightbox_mode = 'traditional_popup';
2275 2277 }
2278 +
2279 + if ( 'two_step_optin' === $publish_lightbox_mode ) {
2280 + $two_step_popups[] = $lightbox->ID;
2281 + } else if ( $this->test_server_conditions( $lightbox_conditions ) ) {
2282 + $traditional_popups[] = array(
2283 + 'id' => $lightbox->ID,
2284 + 'meta' => $lightbox->fca_eoi,
2285 + 'conditions' => $lightbox_conditions,
2286 + );
2287 + }
2276 2288 }
2277 -
2278 - if ( ! empty( $conditions['conditions'] ) ) {
2279 - foreach ( $conditions['conditions'] as $condition ) {
2280 - if ( $condition['parameter'] === 'exit_intervention' ) {
2281 - $sequence_conditions[] = 'exit';
2282 - continue;
2283 - }
2284 -
2285 - $tc_condition = $this->to_tc_condition( $form_id, $post_id, $condition );
2286 - if ( ! empty( $tc_condition ) ) {
2287 - $tc_conditions[] = $tc_condition;
2288 - }
2289 - }
2289 +
2290 + $two_step_popups = array_intersect( $two_step_popups, $this->two_step_ids_on_page );
2291 +
2292 + if ( !empty( $traditional_popups ) OR !empty( $two_step_popups ) OR !empty( $banners_to_show ) ) {
2293 + wp_enqueue_script ( 'jquery' );
2294 + wp_enqueue_style( 'fca_eoi_tooltipster_css', FCA_EOI_PLUGIN_URL.'/assets/vendor/tooltipster/tooltipster.bundle.min.css', array(), FCA_EOI_VER );
2295 + wp_enqueue_style( 'fca_eoi_tooltipster_borderless', FCA_EOI_PLUGIN_URL.'/assets/vendor/tooltipster/tooltipster-borderless.min.css', array(), FCA_EOI_VER );
2296 + wp_enqueue_script( 'fca_eoi_tooltipster_js', FCA_EOI_PLUGIN_URL.'/assets/vendor/tooltipster/tooltipster.bundle.min.js', array(), FCA_EOI_VER, true );
2297 +
2298 + wp_enqueue_script( 'fca_eoi_featherlight_js', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.js', array(), FCA_EOI_VER, true );
2299 + wp_enqueue_style( 'fca_eoi_featherlight_css', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.css', array(), FCA_EOI_VER );
2300 +
2301 + wp_enqueue_script( 'fca_eoi_jstz', FCA_EOI_PLUGIN_URL . '/assets/vendor/jstz/jstz.min.js', array(), FCA_EOI_VER, true );
2302 +
2303 + wp_enqueue_script( 'fca_eoi_script_js', FCA_EOI_PLUGIN_URL.'/assets/script.min.js', array( 'fca_eoi_jstz', 'jquery', 'fca_eoi_tooltipster_js', 'fca_eoi_featherlight_js' ), FCA_EOI_VER, true );
2304 +
2305 + $data = array (
2306 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
2307 + 'nonce' => wp_create_nonce( 'fca_eoi_submit_form' ),
2308 + );
2309 + wp_localize_script( 'fca_eoi_script_js', 'fcaEoiScriptData', $data );
2310 +
2311 + empty ( $traditional_popups ) ? '' : $this->display_traditional_popups( $traditional_popups );
2312 + empty ( $two_step_popups ) ? '' : $this->display_two_step_popups( $two_step_popups );
2313 + empty ( $banners_to_show ) ? '' : $this->display_banners( $banners_to_show );
2290 2314 }
2291 2315
2292 - $has_conditions = ! empty ( $tc_conditions );
2293 - if ( $has_conditions ) {
2294 - $tc_conditions = array( 'and' => $tc_conditions );
2316 + }
2317 +
2318 + public function test_server_conditions( $conditions ) {
2319 +
2320 + //CHECK FOR LIVE
2321 + if ( ! K::get_var( 'live', $conditions, true ) ) {
2322 + return false;
2295 2323 }
2296 -
2297 - if ( $sequence_conditions ) {
2298 - if ( $has_conditions ) {
2299 - $tc_conditions = array( 'sequence' => array( $tc_conditions ) );
2300 - } else {
2301 - $tc_conditions = array( 'sequence' => array() );
2324 +
2325 + //CHECK MOBILE
2326 + $mobile_detect = new Mobile_Detect;
2327 + $is_mobile = $mobile_detect->isMobile();
2328 +
2329 + $mobile_mode = K::get_var( 'devices', $conditions, 'all' );
2330 + $fail_mobile = $mobile_mode === 'mobile' && !$is_mobile;
2331 + $fail_desktop = $mobile_mode === 'desktop' && $is_mobile;
2332 + $pass_mobile = !$fail_mobile && !$fail_desktop;
2333 +
2334 + if ( empty( $conditions['conditions'] ) ) {
2335 + return $pass_mobile;
2336 + }
2337 +
2338 + //CHECK INCLUDED AND EXCLUDED PAGES & TAXONOMIES
2339 + global $post;
2340 + $post_id = $post->ID;
2341 +
2342 + $includes = array();
2343 + $excludes = array();
2344 +
2345 + forEach ( $conditions['conditions'] as $condition ) {
2346 + if ( $condition['parameter'] === 'exclude' ) {
2347 + $excludes = $condition['value'];
2348 + } else if ( $condition['parameter'] === 'include' ) {
2349 + $includes = $condition['value'];
2302 2350 }
2303 - foreach ( $sequence_conditions as $condition ) {
2304 - $tc_conditions['sequence'][] = $condition;
2305 - }
2306 2351 }
2307 -
2308 - return $tc_conditions;
2309 - }
2310 -
2311 - private function echo_tc_conditions_for_form( $form_id, $post_id ) {
2312 - $fca_eoi = get_post_meta( $form_id , 'fca_eoi', true );
2313 - $publish_lightbox = K::get_var( 'publish_lightbox', $fca_eoi, array() );
2314 -
2315 - header( 'Content-Type: application/json' );
2316 - exit( json_encode( $this->get_tc_conditions( $form_id, $post_id, $publish_lightbox ) ) );
2317 - }
2318 -
2319 - private function echo_tc_condition_pass( $post_id, $type, $values ) {
2352 +
2320 2353 $post_cond = array( '*' );
2321 -
2354 +
2322 2355 if ( is_front_page() ) {
2323 2356 $post_cond[] = '~';
2324 2357 }
2325 -
2358 +
2326 2359 if ( $post_id ) {
2327 2360 $post_type = get_post_type( $post_id );
2328 -
2329 2361 $post_cond[] = $post_type;
2330 2362 $post_cond[] = '#' . $post_id;
2331 -
2332 2363 $taxonomies = get_taxonomies( '', 'names' );
2333 2364 $post_taxonomies = wp_get_object_terms( $post_id, $taxonomies );
2334 -
2335 2365 foreach ( $post_taxonomies as $t ) {
2336 2366 $post_cond[] = $post_type . ':' . $t->term_id;
2337 2367 }
2338 2368 } else {
2339 2369 //FIX FOR NOT DISPLAYING ON BLOG PAGE
2340 -
2341 2370 if ( is_home() ) {
2342 2371 $post_cond[] = '#' . get_option('page_for_posts');
2343 2372 }
2344 2373
2345 2374 }
2346 -
2347 - $intersect = array_intersect( $values, $post_cond );
2348 -
2349 - if ( $type === 'include' ) {
2350 - echo $intersect ? 'true' : 'false';
2351 - } else if ( $type === 'exclude' ) {
2352 - echo $intersect ? 'false' : 'true';
2353 - }
2354 -
2355 - exit;
2375 +
2376 + $pass_includes = empty( $includes ) ? true : count ( array_intersect( $includes, $post_cond ) ) > 0;
2377 + $pass_excludes = empty( $excludes ) ? true : count ( array_intersect( $excludes, $post_cond ) ) == 0;
2378 +
2379 + return $pass_includes && $pass_excludes && $pass_mobile;
2380 +
2356 2381 }
2357 2382
2358 - public function parse_tc_condition_request() {
2359 - $post_id = empty( $_REQUEST['fca_eoi_tc_condition_post_id'] ) ? 0 : (int) $_REQUEST['fca_eoi_tc_condition_post_id'];
2383 + private function display_two_step_popups( $lightbox_ids ) {
2384 + wp_enqueue_script( 'fca_eoi_twostep_js', FCA_EOI_PLUGIN_URL.'/assets/twostep.min.js', array( 'jquery', 'fca_eoi_tooltipster_js', 'fca_eoi_featherlight_js', 'fca_eoi_script_js' ), FCA_EOI_VER, true );
2360 2385
2361 - if ( ! empty( $_REQUEST['fca_eoi_tc_conditions_for'] ) ) {
2362 - $form_id = (int) $_REQUEST['fca_eoi_tc_conditions_for'];
2363 - $this->echo_tc_conditions_for_form( $form_id, $post_id );
2386 + foreach ( $lightbox_ids as $id ) {
2387 + $this->prepare_lightbox_html( $id );
2364 2388 }
2365 -
2366 - if ( ! empty( $_REQUEST['fca_eoi_tc_condition_pass'] ) ) {
2367 - $this->echo_tc_condition_pass(
2368 - $post_id,
2369 - $_REQUEST['fca_eoi_tc_condition_pass'],
2370 - explode( ',', $_REQUEST['fca_eoi_tc_condition_value'] )
2371 - );
2372 - }
2373 2389 }
2390 +
2391 + private function display_banners( $banners ) {
2392 +
2393 + $target_data = array();
2374 2394
2375 - private function get_cookie_configuration() {
2376 - $cookie_configuration = array();
2395 + forEach ( $banners as $p ) {
2396 + $id = $p['id'];
2397 + $target_data[$id] = empty( $p['conditions'] ) ? array() : $p['conditions'];
2377 2398
2378 - if ( defined( 'COOKIEPATH' ) ) {
2379 - $path = COOKIEPATH;
2380 - if ( ! empty( $path ) ) {
2381 - $cookie_configuration['path'] = $path;
2382 - }
2399 + echo "<div id='fca_eoi_banner_$id' style='display:none;'>";
2400 + echo do_shortcode( "[easy-opt-in id=$id]" );
2401 + echo '</div>';
2383 2402 }
2384 2403
2385 - if ( defined( 'COOKIE_DOMAIN' ) ) {
2386 - $domain = COOKIE_DOMAIN;
2387 - if ( ! empty( $domain ) ) {
2388 - $cookie_configuration['domain'] = $domain;
2389 - }
2390 - }
2391 -
2392 - return $cookie_configuration;
2393 - }
2394 -
2395 - public function scan_for_shortcodes( $content ) {
2396 - if ( preg_match_all( '/data-optin-cat\s*=\s*["\']?\s*(\d+)/', $content, $matches ) ) {
2397 - $this->two_step_ids_on_page = array_map( 'intval', $matches[1] );
2398 - }
2399 -
2400 - return $content;
2401 - }
2402 -
2403 - public function show_lightbox() {
2404 + wp_enqueue_script( 'fca_eoi_targeting_js', FCA_EOI_PLUGIN_URL.'/assets/targeting.min.js', array( 'jquery' ), FCA_EOI_VER, true );
2404 2405
2405 - // Do not show lightbox on mobile if this is the free distribution
2406 - if ( $this->settings[ 'distribution' ] === 'free' ) {
2407 - $mobile_detect = new Mobile_Detect;
2408 - if ( $mobile_detect->isMobile() ) {
2409 - return;
2410 - }
2411 - }
2406 + $targetData = array (
2407 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
2408 + 'nonce' => wp_create_nonce( 'fca_eoi_activity' ),
2409 + 'banners' => $target_data,
2410 + );
2412 2411
2413 - // Get lightboxes
2414 - $lightboxes = get_posts( array(
2415 - 'post_type' => 'easy-opt-ins',
2416 - 'posts_per_page' => -1,
2417 - 'orderby' => 'ID',
2418 - 'meta_key' => 'fca_eoi_layout',
2419 - 'meta_value' => 'lightbox_',
2420 - 'meta_compare' => 'like',
2421 - ) );
2422 -
2423 - // Exit function if no lightbox found
2424 - if( ! $lightboxes ) {
2425 - return;
2426 - }
2427 -
2428 - $two_step_ids = array();
2429 - $traditional_ids = array();
2430 -
2431 - foreach ( $lightboxes as $lightbox ) {
2432 -
2433 - // Get conditions
2434 - $lightbox->fca_eoi = get_post_meta( $lightbox->ID , 'fca_eoi', true );
2435 - $publish_lightbox_mode = K::get_var( 'publish_lightbox_mode', $lightbox->fca_eoi, array() );
2436 -
2437 - // If on a free distribution, force traditional popup mode
2438 - if ( 'free' === $this->settings['distribution'] ) {
2439 - $publish_lightbox_mode = 'traditional_popup';
2440 - }
2441 -
2442 - if ( 'two_step_optin' === $publish_lightbox_mode ) {
2443 - $two_step_ids[] = $lightbox->ID;
2444 - } else {
2445 - $traditional_ids[] = $lightbox->ID;
2446 - }
2447 - }
2412 + wp_localize_script( 'fca_eoi_targeting_js', 'fcaEoiBannerTargetingData', $targetData );
2448 2413
2449 - $this->display_traditional_popups($traditional_ids, $this->display_two_step_popups($two_step_ids));
2414 + return true;
2450 2415 }
2451 2416
2452 - private function display_two_step_popups($lightbox_ids) {
2453 - $lightbox_ids = array_intersect( $lightbox_ids, $this->two_step_ids_on_page );
2417 + private function display_traditional_popups( $popups ) {
2418 +
2419 + $target_data = array();
2454 2420
2455 - if ( empty( $lightbox_ids ) ) {
2456 - return false;
2421 + forEach ( $popups as $p ) {
2422 + $this->prepare_lightbox_html( $p['id'] );
2423 + $target_data[$p['id']] = empty( $p['conditions'] ) ? array() : $p['conditions'];
2457 2424 }
2458 - do_action( 'fca_eoi_display_lightbox' );
2425 +
2426 + wp_enqueue_script( 'fca_eoi_targeting_js', FCA_EOI_PLUGIN_URL.'/assets/targeting.min.js', array( 'jquery' ), FCA_EOI_VER, true );
2459 2427
2460 - foreach ( $lightbox_ids as $lightbox_id ) {
2461 - $this->prepare_lightbox( $lightbox_id );
2462 - }
2463 -
2464 - ?>
2465 - <script>
2466 - jQuery( function() {
2467 - jQuery( document ).on( 'click', '[data-optin-cat]', function( e ) {
2468 - var lightbox_id = jQuery( this ).data( 'optin-cat' );
2469 - <?php echo EasyOptInsActivity::get_instance()->get_tracking_code( 'lightbox_id', false ) ?>
2470 - jQuery.featherlight( jQuery( '#fca_eoi_lightbox_' + lightbox_id ), <?php echo $this->get_featherlight_options() ?> );
2471 - e.preventDefault();
2472 - } );
2473 - } );
2474 - </script>
2475 - <?php
2476 -
2477 - return true;
2478 - }
2479 -
2480 - private function display_traditional_popups( $lightbox_ids, $prerequisites_loaded = false ) {
2481 - if ( empty( $lightbox_ids ) ) {
2482 - return false;
2483 - }
2428 + $targetData = array (
2429 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
2430 + 'nonce' => wp_create_nonce( 'fca_eoi_activity' ),
2431 + 'popups' => $target_data,
2432 + );
2484 2433
2485 - wp_enqueue_script( 'fca_eoi_script_js', $this->settings[ 'plugin_url' ].'/assets/script.js' );
2486 - wp_enqueue_script( 'fca_eoi_featherlight_js', $this->settings[ 'plugin_url' ].'/assets/vendor/featherlight/release/featherlight.min.js' );
2487 - wp_enqueue_style( 'fca_eoi_featherlight_css', $this->settings[ 'plugin_url' ].'/assets/vendor/featherlight/release/featherlight.min.css' );
2434 + wp_localize_script( 'fca_eoi_targeting_js', 'fcaEoiTargetingData', $targetData );
2488 2435
2489 - ?>
2490 - <script type="text/javascript" src="<?php echo $this->settings['plugin_url'] . '/' . $this->targeting_cat_path ?>"></script>
2491 - <script>
2492 - (function() {
2493 - if ( typeof fca_eoi === "undefined" ) {
2494 - fca_eoi = {};
2495 - }
2496 -
2497 - fca_eoi.ajax_url = <?php echo json_encode( admin_url( 'admin-ajax.php' ) ) ?>;
2498 - })();
2499 -
2500 - <?php $v = array(
2501 - 'prerequisites_loaded' => 'p',
2502 - 'load_prerequisites' => 'l',
2503 - 'head' => 'h',
2504 - 'load_script' => 'c',
2505 - 'load_style' => 'y',
2506 - 'callback' => 'k',
2507 - 'vendor_url' => 'v',
2508 - 'done' => 'n',
2509 - 'document' => 'd',
2510 - 'window.location.href' => 'w',
2511 - 'display_popup' => 's',
2512 - 'false' => '!1',
2513 - 'true' => '1',
2514 - 'evaluable' => 'e',
2515 - 'descriptors' => 'r',
2516 - 'form_id' => 'm',
2517 - 'TargetingCat_OptinCat' => 'g',
2518 - 'url' => 'u'
2519 - ); ?>
2520 -
2521 - <?php ob_start(); ?>
2522 -
2523 - jQuery( function( $ ) {
2524 - var
2525 - <?php echo $v['document'] ?> = document,
2526 - <?php echo $v['window.location.href'] ?> = window.location.href,
2527 - <?php echo $v['TargetingCat_OptinCat'] ?> = TargetingCat_OptinCat;
2528 -
2529 - <?php if ( ! $prerequisites_loaded ) { ?>
2530 -
2531 - var
2532 - <?php echo $v['prerequisites_loaded'] ?> = <?php echo $v['false'] ?>,
2533 - <?php echo $v['head'] ?> = <?php echo $v['document'] ?>.head;
2534 -
2535 - function <?php echo $v['load_script'] ?>( <?php echo $v['url'] ?>, <?php echo $v['callback'] ?> ) {
2536 - var e = <?php echo $v['document'] ?>.createElement( 'script' );
2537 -
2538 - e.type = 'text/javascript';
2539 - e.src = <?php echo $v['url'] ?>;
2540 - e.onload = <?php echo $v['callback'] ?>;
2541 -
2542 - <?php echo $v['head'] ?>.appendChild( e );
2543 - }
2544 -
2545 - function <?php echo $v['load_style'] ?>( <?php echo $v['url'] ?>, <?php echo $v['callback'] ?> ) {
2546 - var e = <?php echo $v['document'] ?>.createElement( 'link' );
2547 -
2548 - e.rel = 'stylesheet';
2549 - e.type = 'text/css';
2550 - e.href = <?php echo $v['url'] ?>;
2551 - e.onload = <?php echo $v['callback'] ?>;
2552 -
2553 - <?php echo $v['head'] ?>.appendChild( e );
2554 - }
2555 -
2556 - function <?php echo $v['load_prerequisites'] ?>( <?php echo $v['callback'] ?> ) {
2557 - if ( <?php echo $v['prerequisites_loaded'] ?> ) {
2558 - <?php echo $v['callback'] ?>();
2559 - return;
2560 - }
2561 -
2562 - var t = 4,
2563 - <?php echo $v['url'] ?> = <?php echo json_encode( $this->settings[ 'plugin_url' ] . '/assets/' ) ?>,
2564 - <?php echo $v['vendor_url'] ?> = <?php echo $v['url'] ?> + 'vendor/',
2565 - <?php echo $v['done'] ?> = function() {
2566 - if ( ! --t ) {
2567 - <?php echo $v['prerequisites_loaded'] ?> = <?php echo $v['true'] ?>;
2568 - <?php echo $v['callback'] ?>();
2569 - }
2570 - };
2571 -
2572 - <?php echo $v['load_style'] ?>( '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css', <?php echo $v['done'] ?> );
2573 -
2574 -
2575 - <?php echo $v['load_style'] ?>( <?php echo $v['url'] ?> + 'style<?php echo EasyOptInsLayout::uses_new_css() ? '-new' : '' ?>.css', <?php echo $v['done'] ?> );
2576 -
2577 - <?php echo $v['load_script'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/jquery.tooltipster.min.js', <?php echo $v['done'] ?> );
2578 - <?php echo $v['load_style'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/tooltipster.min.css', <?php echo $v['done'] ?> );
2579 -
2580 -
2581 - <?php
2582 -
2583 - $loadAnim = false;
2584 - forEach ($lightbox_ids as $id) {
2585 - $animation = get_post_meta( $id, 'fca_eoi_animation', true );
2586 - if ($animation != '') {
2587 - $loadAnim = true;
2588 - break;
2589 - }
2590 - }
2591 - global $fca_eoi_animation_enabled;
2592 - if (!$fca_eoi_animation_enabled) {
2593 - $loadAnim = false;
2594 - }
2595 -
2596 - if ( $loadAnim ) {
2597 -
2598 - echo $v['load_style'] . "(" . $v['vendor_url'] . "+ 'animate/animate.css'," . $v['done'] . ');'; } ?>
2599 - }
2600 -
2601 - <?php } ?>
2602 -
2603 - function <?php echo $v['display_popup'] ?>( <?php echo $v['form_id'] ?> ) {
2604 - var t = <?php echo $prerequisites_loaded ? 1 : 2 ?>,
2605 - <?php echo $v['done'] ?> = function() {
2606 - if ( ! --t ) {
2607 - $.featherlight(
2608 - $( '#fca_eoi_lightbox_' + <?php echo $v['form_id'] ?> ),
2609 - <?php echo $this->get_featherlight_options() ?>
2610 - );
2611 - <?php echo EasyOptInsActivity::get_instance()->get_tracking_code( $v['form_id'], false ) ?>
2612 - }
2613 - };
2614 -
2615 - $.post( <?php echo $v['window.location.href'] ?>, {
2616 - fca_eoi_prepare_lightbox: <?php echo $v['form_id'] ?>
2617 - }, function( html ) {
2618 - $( 'body' ).append( html );
2619 - <?php echo $v['done'] ?>();
2620 - } );
2621 -
2622 - <?php if ( ! $prerequisites_loaded ) { ?>
2623 - <?php echo $v['load_prerequisites'] ?>( <?php echo $v['done'] ?> );
2624 - <?php } ?>
2625 - }
2626 -
2627 - <?php echo $v['TargetingCat_OptinCat'] ?>.StorageManagerSessionPermanent.get_instance().default_configuration = <?php echo json_encode( $this->get_cookie_configuration() ) ?>;
2628 -
2629 - <?php echo json_encode( $lightbox_ids ) ?>.forEach( function( <?php echo $v['form_id'] ?> ) {
2630 - $.post( <?php echo $v['window.location.href'] ?>, {
2631 - <?php if ( is_single() || is_page() ) { ?>
2632 - 'fca_eoi_tc_condition_post_id': <?php echo get_the_ID() ?>,
2633 - <?php } ?>
2634 - 'fca_eoi_tc_conditions_for': <?php echo $v['form_id'] ?>
2635 - }, function( <?php echo $v['descriptors'] ?> ) {
2636 - var <?php echo $v['evaluable'] ?> = <?php echo $v['TargetingCat_OptinCat'] ?>.ConditionManager.get_instance().parse_descriptors(
2637 - typeof <?php echo $v['descriptors'] ?> === 'string'
2638 - ? JSON.parse( <?php echo $v['descriptors'] ?> )
2639 - : <?php echo $v['descriptors'] ?>
2640 - );
2641 - if ( <?php echo $v['evaluable'] ?> ) {
2642 - <?php echo $v['evaluable'] ?>.set_pass_callback( function() {
2643 - <?php echo $v['display_popup'] ?>( <?php echo $v['form_id'] ?> );
2644 - } );
2645 - <?php echo $v['evaluable'] ?>.evaluate();
2646 - }
2647 - } );
2648 - } );
2649 -
2650 - var lightbox_ids_Count = <?php echo count ($lightbox_ids) ?>;
2651 - var currentLightBoxCount = 0;
2652 - var totalAddedLightboxes = 0;
2653 -
2654 - function waitUntilPopupsAreMade() {
2655 -
2656 - if( totalAddedLightboxes < lightbox_ids_Count ) {
2657 -
2658 - if (document.getElementsByClassName("fca_eoi_featherlight").length > currentLightBoxCount) {
2659 -
2660 - totalAddedLightboxes++;
2661 - currentLightBoxCount = document.getElementsByClassName("fca_eoi_featherlight").length;
2662 - attachDeleteButtons();
2663 - window.setTimeout(waitUntilPopupsAreMade, 200);
2664 - }else {
2665 -
2666 - currentLightBoxCount = document.getElementsByClassName("fca_eoi_featherlight").length;
2667 - window.setTimeout(waitUntilPopupsAreMade, 200);
2668 - }
2669 -
2670 - } else {
2671 -
2672 - attachDeleteButtons();
2673 - }
2674 - }
2675 - if (lightbox_ids_Count > 1) {
2676 - waitUntilPopupsAreMade();
2677 - }
2678 -
2679 - function attachDeleteButtons() {
2680 - myNodes = document.getElementsByClassName("fca_eoi_layout_popup_close");
2681 -
2682 - for (var i=0; i<myNodes.length; i++) {
2683 - myNodes[i].onclick = function(e) {
2684 - $(this).parents(".fca_eoi_featherlight").hide();
2685 - };
2686 -
2687 - }
2688 - }
2689 -
2690 -
2691 - } );
2692 -
2693 - <?php
2694 -
2695 - echo preg_replace(
2696 - array( '/\s+/', '/([-+|\(\){}&=;,:?])\s+/', '/\s+([-+|\(\){}&=?])/', '/;}/' ),
2697 - array( ' ', '$1', '$1', '}' ),
2698 - trim( ob_get_clean() )
2699 - );
2700 -
2701 - ?>
2702 - </script>
2703 - <?php
2704 -
2705 2436 return true;
2706 2437 }
2707 2438
2708 - public function request_prepare_lightbox() {
2709 - if (array_key_exists('fca_eoi_prepare_lightbox', $_POST)) {
2710 - $lightbox_id = (int) $_POST['fca_eoi_prepare_lightbox'];
2711 - if ( $lightbox_id > 0 ) {
2712 - $this->prepare_lightbox( $lightbox_id );
2713 - exit;
2714 - }
2715 - }
2716 - }
2717 -
2718 - public function prepare_lightbox( $id ) {
2439 + public function prepare_lightbox_html( $id ) {
2719 2440 $id = (int) $id;
2720 2441
2721 - global $post;
2442 + $content = do_shortcode( "[easy-opt-in id=$id]" );
2722 2443
2723 - $animation = get_post_meta( $id, 'fca_eoi_animation', true );
2724 -
2725 -
2726 - $featherlight_class = EasyOptInsLayout::uses_new_css() ? 'fca_eoi_featherlight' : 'featherlight';
2727 - $content = do_shortcode( "[easy-opt-in id=$id]" );
2728 -
2729 2444 ?>
2730 2445 <div style="display:none">
2731 - <style scoped>.<?php echo $featherlight_class ?>-content { background: transparent !important; }</style>
2732 - <div class=<?php echo "'animated $animation'" ?> id="fca_eoi_lightbox_<?php echo $id ?>"><?php echo $content ?></div>
2446 + <div id="fca_eoi_lightbox_<?php echo $id ?>"><?php echo $content ?></div>
2733 2447 </div>
2734 2448 <?php
2735 2449 }
2736 2450
2737 - private function get_featherlight_options() {
2738 - if ( EasyOptInsLayout::uses_new_css() ) {
2739 - $is_iphone = preg_match('/(?:iPhone|iPod);/i', $_SERVER['HTTP_USER_AGENT']);
2740 - $is_ios = preg_match( '/(?:iPhone|iPad|iPod).* OS ([\d])_.* Safari/', $_SERVER['HTTP_USER_AGENT'], $matches );
2741 -
2742 - if ( $is_ios ) {
2743 - $ios_specific_options = ',
2744 - beforeOpen: function() {
2745 - var viewport = jQuery( "meta[name=viewport]" );
2746 - if ( viewport.length == 0 ) {
2747 - viewport = jQuery( "<meta name=\"viewport\" content=\"\"/>" );
2748 - jQuery( "head" ).append( viewport );
2749 - }
2750 -
2751 - var viewport_content = viewport.attr( "content" );
2752 - this.fca_eoi_viewport_content = viewport_content;
2753 - viewport.attr( "content", "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" );
2754 -
2755 - this.fca_eoi_orientation_change_listener = function() {
2756 - window.scrollTo( 0, 0 );
2757 - jQuery( ".fca_eoi_form input" ).each( function() {
2758 - this.blur();
2759 - } );
2760 - };
2761 - window.addEventListener( "orientationchange", this.fca_eoi_orientation_change_listener, false );
2762 -
2763 - this.fca_eoi_touch_move_listener = function( event ) {
2764 - event.preventDefault();
2765 - };
2766 - window.addEventListener( "touchmove", this.fca_eoi_touch_move_listener, false );
2767 - },
2768 - afterOpen: function() {
2769 - jQuery( "body" ).append( "<div class=\"fca_eoi_featherlight_pad\" style=\"display: block; height: 1000px;\"/>" );
2770 - },
2771 - beforeClose: function() {
2772 - jQuery( ".fca_eoi_featherlight_pad" ).remove();
2773 - },
2774 - afterClose: function() {
2775 - if ( this.hasOwnProperty( "fca_eoi_viewport_content" ) ) {
2776 - jQuery( "meta[name=viewport]" ).attr( "content", this.fca_eoi_viewport_content );
2777 - }
2778 -
2779 - if ( this.hasOwnProperty( "fca_eoi_orientation_change_listener" ) ) {
2780 - window.removeEventListener( "orientationchange", this.fca_eoi_orientation_change_listener );
2781 - }
2782 -
2783 - if ( this.hasOwnProperty( "fca_eoi_touch_move_listener" ) ) {
2784 - window.removeEventListener( "touchmove", this.fca_eoi_touch_move_listener );
2785 - }
2786 - }';
2787 - } else {
2788 - $ios_specific_options = '';
2789 - }
2790 -
2791 - return '{
2792 - namespace: "fca_eoi_featherlight",
2793 - otherClose: ".fca_eoi_layout_popup_close"' . $ios_specific_options . ',
2794 - variant: ' . ( $is_iphone ? '"fca_eoi_device_iphone"' : 'null' ) . '
2795 - }';
2796 - } else {
2797 - return 'undefined';
2798 - }
2799 - }
2800 -}
2801 -
2802 -function k_selector( $name, $selected_options = array(), $return = false ) {
2803 -
2804 - global $post;
2805 - // Dirty fix to restore the global $post
2806 - $post_bak = $post;
2807 -
2808 - // Get all post types except media
2809 - $post_types = get_post_types( array( 'public' => true ) );
2810 - unset( $post_types[ 'attachment' ] );
2811 -
2812 - $ret = ob_start();
2813 -
2814 - // Start ouput
2815 - echo '<select data-placeholder="' . __( 'Type to search for posts, categories or pages.' ) . '" name = "' . $name . '[]" class="select2" multiple="multiple" style="width: 27em;">';
2816 -
2817 - // Front page
2818 - K::wrap( __( 'Front page' )
2819 - , array(
2820 - 'value' => '~',
2821 - 'selected' => in_array( '~', $selected_options ),
2822 - )
2823 - , array( 'in' => 'option' )
2824 - );
2825 -
2826 - // All posts
2827 - // K::wrap( __( 'All' )
2828 - // , array(
2829 - // 'value' => '*',
2830 - // 'selected' => in_array( '*', $selected_options ),
2831 - // )
2832 - // , array( 'in' => 'option' )
2833 - // );
2834 -
2835 - foreach ($post_types as $post_type => $post_type_args ) {
2836 -
2837 - $post_type_obj = get_post_type_object( $post_type );
2838 - $post_type_name = $post_type_obj->labels->singular_name;
2839 -
2840 - $options = array();
2841 -
2842 - // Add taxonomy/terms options
2843 - $taxonomies = get_object_taxonomies( $post_type );
2844 - foreach ( $taxonomies as $taxonomy ) {
2845 - $taxonomy_obj = get_taxonomy( $taxonomy );
2846 - $taxonomy_name = $taxonomy_obj->labels->singular_name;
2847 - $terms = get_categories("taxonomy=$taxonomy&type=$post_type");
2848 - foreach ($terms as $term) {
2849 - $options[ 'taxonomies' ][ "$post_type:$term->term_id" ] =
2850 - $post_type_name
2851 - . " › $taxonomy_name"
2852 - . " › $term->name"
2853 - ;
2854 - }
2855 - }
2856 -
2857 - // Add posts options
2858 - $the_query = new WP_Query( "post_type=$post_type&posts_per_page=-1" );
2859 - if ( $the_query->have_posts() ) {
2860 -
2861 - while ( $the_query->have_posts() ) {
2862 - $the_query->the_post();
2863 - $options[ 'posts' ][ '#' . get_the_ID() ] = $post_type_name
2864 - . ' ' . __( '›' ) . ' '
2865 - . '#' . get_the_ID() . ' &ndash; '
2866 - . ( get_the_title() ? get_the_title() : __('[Untitled]') )
2867 - ;
2868 - }
2869 - }
2870 -
2871 - // Dirty fix to restore the global $post
2872 - $post = $post_bak;
2873 -
2874 - // Posts > All
2875 - echo '<optgroup label="' . $post_type_name . '">';
2876 - printf(
2877 - '<option value="%s" %s >%s</option>'
2878 - , $post_type
2879 - , ( in_array( $post_type, $selected_options ) ? 'selected' : '' )
2880 - , $post_type_name . ' ' . ( '›' ) . ' ' . __( 'All' )
2881 - );
2882 - echo '</optgroup>';
2883 -
2884 - // Posts > Taoxonomies
2885 - if ( ! empty( $options[ 'taxonomies' ] ) ) {
2886 - printf(
2887 - '<optgroup label="%s">'
2888 - , $post_type_name . ' ' . __( '›' ) . ' ' . __( 'Taxonomies' )
2889 - );
2890 - foreach ( $options[ 'taxonomies' ] as $k => $v ) {
2891 - $selected = ( in_array( $k, $selected_options ) ) ? 'selected="selected"' : '';
2892 - printf( '<option value="%s" %s >%s</option>', $k, $selected, $v );
2893 - }
2894 - echo '</optgroup>';
2895 - }
2896 -
2897 - // Posts > content
2898 - if ( ! empty( $options[ 'posts' ] ) ) {
2899 - printf( '<optgroup label="%s">'
2900 - , $post_type_name . ' ' . __( '›' ) . ' ' . __( 'Content' )
2901 - );
2902 - foreach ( $options[ 'posts' ] as $k => $v ) {
2903 - $selected = ( in_array( $k, $selected_options ) ) ? 'selected="selected"' : '';
2904 - printf( '<option value="%s" %s >%s</option>'
2905 - , $k
2906 - , $selected
2907 - , $v
2908 - );
2909 - }
2910 - echo '</optgroup>';
2911 - }
2912 - }
2913 - echo '</select>';
2914 -
2915 - $ret = ob_get_clean();
2916 -
2917 - if ( $return ) {
2918 - return $ret;
2919 - } else {
2920 - echo $ret;
2921 - }
2922 -}
2923 -
2924 -function fca_eoi_comp( $a, $b, $op, $negate = false ) {
2925 - switch ( $op ) {
2926 - case 'eq': return $negate ? ( ! ( $a == $b ) ) : ( $a == $b );
2927 - case 'gt': return $negate ? ( ! ( $a > $b ) ) : ( $a > $b );
2928 - case 'gte': return $negate ? ( ! ( $a >= $b ) ) : ( $a >= $b );
2929 - case 'lt': return $negate ? ( ! ( $a < $b ) ) : ( $a < $b );
2930 - case 'lte': return $negate ? ( ! ( $a <= $b ) ) : ( $a <= $b );
2931 - }
2932 2451 }