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