PluginProbe
GetResponse Forms by Optin Cat / 1.7.2
GetResponse Forms by Optin Cat v1.7.2
1.3.4 1.3.5 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 2.0.0 All 36 releases
getresponse / includes / eoi-post-types.php

eoi-post-types.php in GetResponse Forms by Optin Cat 1.7.2, at includes/eoi-post-types.php

2,677 lines 86.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class EasyOptInsPostTypes {
4
5 public $settings;
6
7 private $activity_day_interval = array(
8 'form_list' => null,
9 'dashboard_widget' => 30
10 );
11
12 private $targeting_cat_path = 'assets/vendor/targeting-cat/TargetingCat-OptinCat-1.2.min.js';
13
14 private $two_step_ids_on_page = array();
15
16 public function __construct( $settings ) {
17
18 $this->settings = $settings;
19
20 $providers_available = array_keys( $this->settings[ 'providers' ] );
21
22 // Register custom post type
23 add_action( 'init', array( $this, 'register_custom_post_type' ) );
24 add_filter( 'manage_easy-opt-ins_posts_columns', array( $this, 'add_new_columns' ) );
25 add_action( 'manage_easy-opt-ins_posts_custom_column', array( $this, 'set_column_data' ), 10, 2 );
26 add_filter( 'post_row_actions', array( $this, 'post_row_actions' ), 10, 2 );
27
28 // Reset action
29 add_action( 'admin_post_fca_eoi_reset_stats', array( $this, 'reset_stats' ) );
30
31 // Dashboard widget
32 add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) );
33
34 // Save
35 add_action( 'save_post', array( $this, 'save_meta_box_content' ), 1, 2 );
36
37 // Live preview
38 add_filter( 'the_content', array( $this, 'live_preview' ) );
39
40 // Scripts and styles
41 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) );
42
43 add_action( 'admin_head', array( $this, 'hide_minor_publishing' ) );
44
45 add_filter( 'admin_body_class', array( $this, 'add_body_class' ) );
46
47 add_filter( 'wp_insert_post_data', array( $this, 'force_published' ) );
48
49 add_action( 'wp_ajax_fca_eoi_subscribe', array( $this, 'ajax_subscribe' ) );
50 add_action( 'wp_ajax_nopriv_fca_eoi_subscribe', array( $this, 'ajax_subscribe' ) );
51
52 add_filter( 'get_user_option_screen_layout_easy-opt-ins', array( $this, 'force_one_column' ) );
53
54 add_filter( 'get_user_option_meta-box-order_easy-opt-ins', array( $this, 'order_columns' ) );
55
56 add_filter( 'post_updated_messages', array( $this, 'override_text' ) );
57
58 add_filter( 'bulk_actions-edit-easy-opt-ins', array( $this, 'disable_bulk_edit' ) );
59
60 add_filter( 'post_row_actions', array( $this, 'remove_quick_edit' ) );
61
62 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
63
64 add_filter( 'enter_title_here', array( $this, 'change_default_title' ) );
65
66 add_filter( 'init', array( $this, 'bind_content_filter' ), 10 );
67
68 add_filter( 'template_redirect', array( $this, 'parse_tc_condition_request' ), 1 );
69
70 //ADD ACTIONS TO GET THE ENTIRE PAGE OUTPUT IN BUFFER
71
72 if ( wp_get_theme() == 'Customizr' ) {
73 add_filter( 'the_content', array( $this, 'scan_for_shortcodes' ) );
74 } else {
75 add_action('wp_head', array( $this, 'fca_eoi_buffer_start' ));
76 add_action('wp_footer', array( $this, 'fca_eoi_buffer_end' ));
77 }
78
79 add_filter( 'init', array( $this, 'request_prepare_lightbox' ) );
80
81 add_filter( 'wp_footer', array( $this, 'show_lightbox' ) );
82
83 foreach ( $providers_available as $provider ) {
84 add_action( 'wp_ajax_fca_eoi_' . $provider . '_get_lists', $provider . '_ajax_get_lists' );
85 }
86
87 // Hook provder callback functions
88 foreach ( $providers_available as $provider ) {
89 add_filter( 'fca_eoi_alter_admin_notices', $provider . '_admin_notices', 10, 1 );
90 }
91
92 // Handle licensing
93 if( count( $providers_available ) > 1 ) {
94 require_once FCA_EOI_PLUGIN_DIR . 'includes/licensing.php';
95 new EasyOptInsLicense( $this->settings );
96 }
97 }
98
99 function fca_eoi_buffer_start() { ob_start(array( $this, 'scan_for_shortcodes' )); }
100 function fca_eoi_buffer_end() { ob_end_flush(); }
101
102 public function register_custom_post_type() {
103
104 $labels = array(
105 'name' => __('Optin Forms') ,
106 'singular_name' => __('Optin Form') ,
107 'add_new' => __('Add New') ,
108 'add_new_item' => __('Add New Optin Form') ,
109 'edit_item' => __('Edit Optin Form') ,
110 'new_item' => __('New Optin Form') ,
111 'all_items' => __('All Optin Forms') ,
112 'view_item' => __('View Optin Form') ,
113 'search_items' => __('Search Optin Form') ,
114 'not_found' => __('No Optin Form Found') ,
115 'not_found_in_trash' => __('No Optin Form Found in Trash') ,
116 'parent_item_colon' => '',
117 'menu_name' => __('Optin Cat')
118 );
119 $args = array(
120 'menu_icon' => FCA_EOI_PLUGIN_URL . '/icon.png',
121 'labels' => $labels,
122 'public' => false,
123 'exclude_from_search' => true,
124 'publicly_queryable' => false,
125 'show_ui' => true,
126 'show_in_menu' => true,
127 'query_var' => true,
128 'rewrite' => array(
129 'slug' => 'easy-opt-ins',
130 ) ,
131 'capability_type' => 'page',
132 'has_archive' => false,
133 'hierarchical' => false,
134 'menu_position' => 105,
135 'supports' => array(
136 'title',
137 ) ,
138 'register_meta_box_cb' => array(
139 $this,
140 'add_meta_boxes'
141 )
142 );
143 register_post_type('easy-opt-ins', $args);
144 }
145
146 private function enqueue_activity_style() {
147 wp_enqueue_style( 'admin-cpt-easy-opt-ins-activity', FCA_EOI_PLUGIN_URL . '/assets/admin/cpt-easy-opt-ins-activity.css', array(), FCA_EOI_VER );
148 }
149
150 public function add_new_columns( $columns ) {
151 $new_columns = array();
152
153 if ( ! empty( $columns['cb'] ) ) {
154 $new_columns['cb'] = $columns['cb'];
155 }
156
157 if ( ! empty( $columns['title'] ) ) {
158 $new_columns['title'] = $columns['title'];
159 }
160
161 $this->enqueue_activity_style();
162 $activity = EasyOptInsActivity::get_instance();
163
164 $period =
165 '<span class="fca_eoi_activity_period">(' .
166 $activity->get_text( 'period', null, array( $this->activity_day_interval['form_list'] ) ) .
167 ')</span>';
168
169 foreach ( array( 'impressions', 'conversions', 'conversion_rate' ) as $activity_type ) {
170 $new_columns[ $activity_type ] = esc_html( $activity->get_text( $activity_type, 'form' ) ) . '<br>' . $period;
171 }
172
173 return $new_columns;
174 }
175
176 public function set_column_data( $column_name, $form_id ) {
177 $activity = EasyOptInsActivity::get_instance();
178
179 $stats = $activity->get_form_stats( $this->activity_day_interval['form_list'] );
180 $value = 0;
181
182 if ( ! empty( $stats[ $column_name ][ $form_id ] ) ) {
183 $value = $stats[ $column_name ][ $form_id ];
184 }
185
186 echo $activity->format_column_text( $column_name, $value );
187 }
188
189 public function post_row_actions( $actions, $post ) {
190 if ( $post->post_type == 'easy-opt-ins' ) {
191 $action = 'fca_eoi_reset_stats';
192 $title = __( 'Reset stats for this item' );
193 $label = __( 'Reset Stats' );
194
195 $url = add_query_arg( 'action', $action, admin_url( 'admin-post.php?post=' . $post->ID ) );
196 $url = wp_nonce_url( $url );
197
198 $actions[$action] = $this->confirm_tag(
199 '<a href="' . $url . '" title="' . $title . '">' . $label . '</a>',
200 __( 'Are you sure?' ),
201 __( 'Do you really want to reset this Optin Form\'s stats? This action cannot be undone.' )
202 );
203 }
204 return $actions;
205 }
206
207 public function reset_stats() {
208 if ( wp_verify_nonce( $_REQUEST['_wpnonce'] ) ) {
209 EasyOptInsActivity::get_instance()->reset_stats( (int) $_REQUEST['post'] );
210 wp_redirect( wp_get_referer() );
211 }
212 }
213
214 private function confirm_tag( $tag, $title, $message ) {
215 return preg_replace(
216 '/>/',
217 ' onclick="return confirm(' .
218 esc_html( '"' . $title . '\n\n' . $message . '"' ) .
219 ')">',
220 $tag, 1 );
221 }
222
223 public function dashboard_setup() {
224
225 if ( defined ( 'FCA_EOI_DISABLE_STATS_TRACKING' )) {
226 $title = 'Optin Cat Summary (TRACKING DISABLED)';
227 } else {
228 $title = 'Optin Cat Summary';
229 }
230 add_meta_box(
231 'fca_eoi_dashboard_widget',
232 $title,
233 array( $this, 'add_dashboard_widget' ),
234 'dashboard',
235 'normal',
236 'high'
237 );
238 }
239
240 public function add_dashboard_widget() {
241 wp_enqueue_script( 'd3_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/d3.min.js', array(), FCA_EOI_VER, true );
242 wp_enqueue_script( 'nvd3_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/nv.d3.min.js', array(), FCA_EOI_VER, true );
243 wp_enqueue_style( 'nvd3_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/nv.d3.min.css', array(), FCA_EOI_VER );
244 $this->enqueue_activity_style();
245
246 $day_interval = $this->activity_day_interval['dashboard_widget'];
247 $activity = EasyOptInsActivity::get_instance();
248 $stats = $activity->get_daily_stats( $day_interval );
249
250 $date_labels = array();
251 foreach ( array_keys( $stats['impressions'] ) as $date ) {
252 $date_labels[] = strftime( '%e %b', strtotime( $date ) );
253 }
254
255 $colors = array(
256 'impressions' => '#5b90bf',
257 'conversions' => '#bf616a'
258 );
259
260 ?>
261 <div class="fca_eoi_activity_chart_title_container">
262 <div class="fca_eoi_activity_chart_legend">
263 <?php foreach ( array( 'impressions', 'conversions' ) as $activity_type ): ?>
264 <div class="fca_eoi_activity_chart_legend_item">
265 <div class="fca_eoi_activity_chart_legend_sample" style="background-color: <?php echo $colors[ $activity_type ] ?>;"></div>
266 <div class="fca_eoi_activity_chart_legend_text">
267 <?php echo esc_html( $activity->get_text( $activity_type, 'total' ) ) ?>
268 </div>
269 </div>
270 <?php endforeach ?>
271 </div>
272 <div class="fca_eoi_activity_chart_period">
273 <?php echo esc_html( $activity->get_text( 'period', null, array( $day_interval ) ) ) ?>
274 -
275 <a href="<?php echo admin_url( 'edit.php?post_type=easy-opt-ins' ) ?>"><?php echo __( 'View All Data' ) ?></a>
276 </div>
277 </div>
278 <div class="fca_eoi_activity_chart" id="fca_eoi_activity_chart"></div>
279 <div class="fca_eoi_activity_chart_stat">
280 <?php foreach ( array( 'impressions', 'conversions', 'conversion_rate' ) as $activity_type ): ?>
281 <div class="fca_eoi_activity_chart_stat_item">
282 <div class="fca_eoi_activity_chart_stat_value">
283 <?php echo $activity->format_column_text( $activity_type, $stats['totals'][ $activity_type ] ) ?>
284 </div>
285 <div class="fca_eoi_activity_chart_stat_title">
286 <?php echo esc_html( $activity->get_text( $activity_type, 'total' ) ) ?>
287 </div>
288 </div>
289 <?php endforeach ?>
290 </div>
291 <script>
292 jQuery( function() {
293 var impressions = <?php echo json_encode( array_values( $stats['impressions'] ) ) ?>;
294 var conversions = <?php echo json_encode( array_values( $stats['conversions'] ) ) ?>;
295 var dates = <?php echo json_encode( $date_labels ) ?>;
296
297 var chart = nv.models.lineChart().options({
298 duration: 0,
299 transitionDuration: 0,
300 useInteractiveGuideline: true,
301 isArea: true,
302 showLegend: false,
303 margin: { top: 10, right: 20, bottom: 30, left: 40 }
304 } );
305
306 chart.xAxis.tickFormat( function( index ) { return dates[ index ]; } );
307 chart.yAxis.tickFormat( d3.format( 'd' ) );
308 chart.forceY( [ 0, d3.max(impressions) || 1 ] );
309
310 var valuesToPoint = function( value, index ) {
311 return { x: index, y: value };
312 };
313
314 d3.select( '#fca_eoi_activity_chart' ).append( 'svg' ).datum( [
315 { color: '<?php echo $colors['impressions'] ?>', key: 'Impressions', values: impressions.map(valuesToPoint) },
316 { color: '<?php echo $colors['conversions'] ?>', key: 'Conversions', values: conversions.map(valuesToPoint) }
317 ] ).call( chart );
318
319 nv.utils.windowResize( chart.update );
320 } );
321 </script>
322 <?php
323 }
324
325 public function add_meta_boxes() {
326
327 add_meta_box(
328 'fca_eoi_meta_box_setup',
329 __( 'Setup' ),
330 array( &$this, 'meta_box_content_setup' ),
331 'easy-opt-ins',
332 'side',
333 'high'
334 );
335 add_meta_box(
336 'fca_eoi_meta_box_build',
337 __( 'Form Builder' ),
338 array( &$this, 'meta_box_content_build' ),
339 'easy-opt-ins',
340 'side',
341 'high'
342 );
343
344 add_meta_box(
345 'fca_eoi_meta_box_provider',
346 __( 'Email Marketing Provider Integration' ),
347 array( &$this, 'meta_box_content_provider' ),
348 'easy-opt-ins',
349 'side',
350 'high'
351 );
352 add_meta_box(
353 'fca_eoi_meta_box_publish',
354 __( 'Publication' ),
355 array( &$this, 'meta_box_content_publish' ),
356 'easy-opt-ins',
357 'side',
358 'high'
359 );
360 add_meta_box(
361 'fca_eoi_meta_box_thanks',
362 __( 'Thank You Message' ),
363 array( &$this, 'meta_box_content_thanks' ),
364 'easy-opt-ins',
365 'side',
366 'high'
367 );
368 if ( has_action( 'fca_eoi_powerups' ) ) {
369 add_meta_box(
370 'fca_eoi_meta_box_powerups',
371 __( 'Power Ups' ),
372 array( &$this, 'meta_box_content_powerups' ),
373 'easy-opt-ins',
374 'side',
375 'high'
376 );
377 }
378 }
379
380 public function meta_box_content_setup() {
381
382 $layouts_types_labels = array(
383 'lightbox' => 'Popups',
384 'postbox' => 'Post Boxes',
385 'widget' => 'Sidebar Widgets',
386 );
387
388 // Build the layouts array
389 $layouts = $layouts_types = $layouts_types_found = array();
390 foreach ( glob( FCA_EOI_PLUGIN_DIR . 'layouts/*', GLOB_ONLYDIR ) as $v) {
391 $layouts_types_found[] = basename( $v );
392 }
393
394 $layouts_types_accepted = array_keys( $layouts_types_labels );
395 foreach ( $layouts_types_accepted as $layout_type ) {
396 if ( in_array( $layout_type, $layouts_types_found ) ) {
397 $layouts_types[] = $layout_type;
398 }
399 }
400 // Layouts types mini-tabs
401
402 echo '<ul class="category-tabs" id="layouts_types_tabs">';
403 foreach ( $layouts_types as $layout_type ) {
404 K::wrap(
405 $layouts_types_labels[ $layout_type ]
406 , array(
407 'href' => '#'. 'layouts_type_' . $layout_type,
408 )
409 , array(
410 'html_before' => '<li' . ( 'widget' === $layout_type ? ' class="tabs"' : '' ) . ' >',
411 'html_after' => '</li> ',
412 'in' => 'a',
413 )
414 );
415 }
416 echo '</ul>';
417
418 //GENERATE SCREENSHOTS / OPTIN THEME PICKER
419 //RN NOTE: COULD CACHE THIS (?)
420 $output = '';
421 foreach ( $layouts_types as $layout_type ) {
422
423 $output .= "<div class='fca_eoi_accordion_tab' id='layouts_type_$layout_type'>";
424 $layout_counter = 1;
425 foreach ( glob( FCA_EOI_PLUGIN_DIR . "layouts/$layout_type/*", GLOB_ONLYDIR ) as $layout_path ) {
426 $layout_id = basename( $layout_path );
427
428 $layout_helper = new EasyOptInsLayout( $layout_id );
429 $layout_type = ucfirst ( $layout_helper->layout_type );
430
431 $screenshot_path = $layout_helper->path_to_resource( 'screenshot', 'png' );
432 $screenshot_url = $layout_helper->url_to_resource( 'screenshot', 'png' );
433 $screenshot = file_exists( $screenshot_path ) ? $screenshot_url : FCA_EOI_PLUGIN_URL . '/layouts/no-image.jpg';
434
435 $layout_name = ucfirst ( str_replace( 'layout', 'widget', str_replace('_', ' ', $layout_id) ) );
436 $layout_name = str_replace( array('Postbox 0', 'Widget 0'), 'No CSS', $layout_name );
437 $output .= "<div class='fca_eoi_layout has-tip fca_eoi_layout_preview' data-layout-id='$layout_id' data-layout-type='$layout_type'>";
438 $output .= "<img src='$screenshot'>";
439 $output .= "<div class='fca_eoi_layout_info'>";
440 $output .= "<h3>$layout_name</h3>";
441 $output .= "</div>";
442 $output .= "</div>";
443
444 $layout_counter = $layout_counter + 1;
445 }
446 $output .= "</div>";
447
448 }
449 $output .= '<br clear="all">';
450 echo $output;
451 }
452
453 public function meta_box_content_provider() {
454
455 global $post;
456 $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true );
457
458 //DISABLE CUSTOM FORM
459 $allow_customform = get_option ( 'fca_eoi_allow_customform', 'false' );
460 if ( $allow_customform == 'false' ) {
461 $providers = $this->settings[ 'providers' ];
462 unset ( $providers['customform'] );
463 $providers_available = array_keys( $providers );
464 } else {
465 $providers_available = array_keys( $this->settings[ 'providers' ] );
466 }
467
468 $providers_options = array();
469
470 // Prepare providers options
471 foreach ( $this->settings[ 'providers' ] as $provider_id => $provider ) {
472 $providers_options[ $provider_id ] = $provider[ 'info' ][ 'name' ];
473 }
474
475 if ( $allow_customform == 'false') {
476 unset ( $providers_options['customform'] );
477 }
478
479 // Provider choice if there are many providers
480 if ( 1 < count( $providers_available) ) {
481
482 $provider = get_option( 'fca_eoi_last_provider', '' );
483 $provider = empty($provider) ? 'mailchimp' : $provider; // use mailchimp by default
484
485 K::select( 'fca_eoi[provider]'
486 , array(
487 'class' => 'select2',
488 'style' => 'width: 27em;',
489 )
490 , array(
491 'format' => '<p><label>:select</label></p>',
492 'options' => array( '' => 'Not set' ) + $providers_options,
493 'selected' => K::get_var( 'provider', $fca_eoi, $provider ),
494 )
495 );
496 }
497
498 foreach ( $providers_available as $provider ) {
499 call_user_func( $provider . '_integration', $this->settings );
500 }
501 }
502
503 public function meta_box_content_publish() {
504
505 global $post;
506 $screen = get_current_screen();
507
508 $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true );
509
510 // Widgets
511 K::wrap(
512 sprintf(
513 __( 'You can publish this optin box by going to <a href="%s" target="_blank">Appearance › Widgets</a>')
514 , admin_url( 'widgets.php')
515 )
516 , array( 'id' => 'fca_eoi_publish_widget' )
517 , array( 'in' => 'p' )
518 );
519
520 // Post boxes
521 echo '<div id ="fca_eoi_publish_postbox">';
522 K::wrap( __( 'Shortcode')
523 , array( 'style' => 'padding-left: 0px; padding-right: 0px; ' )
524 , array( 'in' => 'h3' )
525 );
526 K::wrap( __( "Copy and paste beneath shortcode anywhere on your site where you'd like this opt-in form to appear." )
527 , null
528 , array( 'in' => 'p' )
529 );
530 K::input( ''
531 , array(
532 'class' => 'regular-text autoselect',
533 'readonly' => 'readonly',
534 'value' => sprintf( '[%s id=%d]', $this->settings[ 'shortcode' ], $post->ID ),
535 )
536 , array( 'format' => '<p>:input</p>', )
537 );
538 K::wrap( __( 'Append to post or page')
539 , array( 'style' => 'padding-left: 0px; padding-right: 0px; ' )
540 , array( 'in' => 'h3' )
541 );
542 K::wrap( __( 'Automatically append this optin to the following posts, categories and/or pages.' )
543 , null
544 , array( 'in' => 'p' )
545 );
546 k_selector( 'fca_eoi[publish_postbox]', K::get_var( 'publish_postbox', $fca_eoi, array() ) );
547 echo '</div>';
548
549 // Lightboxes
550
551 switch ( $this->settings['distribution'] ) {
552 case 'free':
553 $conditions_options = array(
554 'time_on_page' => 'Time on page is at least (second)',
555 );
556 break;
557 case 'premium':
558 $conditions_options = array(
559 'pageviews' => 'Number of pageviews during this visit at least',
560 'scrolled_percent' => 'Scrolled down on current page at least (%)',
561 'time_on_page' => 'Time on page is at least (second)',
562 'include' => 'Only show popup on the following posts/pages',
563 'exclude' => 'Never show popup on the following posts/pages',
564 'exit_intervention' => 'User is about to close the page (Exit Intervention)'
565 );
566 break;
567 }
568
569 $fca_eoi[ 'publish_lightbox' ] = K::get_var( 'publish_lightbox', $fca_eoi, array() );
570 echo "<div id ='fca_eoi_publish_lightbox'>";
571
572 if ( 'premium' === $this->settings[ 'distribution' ] ) {
573 K::input( 'fca_eoi[publish_lightbox_mode]'
574 , array(
575 'type' => 'radio',
576 'value' => 'two_step_optin',
577 'checked' => 'two_step_optin' === K::get_var( 'publish_lightbox_mode', $fca_eoi ),
578 )
579 , array(
580 'format' => '<p><label>:input Two-Step Optin (Trigger popup only when the visitor clicks on a call to action link)</label></p>',
581 )
582 );
583 }
584
585 K::input( 'fca_eoi[publish_lightbox_mode]'
586 , array(
587 'type' => 'radio',
588 'value' => 'traditional_popup',
589 'checked' => 'traditional_popup' === K::get_var( 'publish_lightbox_mode', $fca_eoi ),
590 )
591 , array(
592 'format' => '<p><label>:input Traditional Popup (Trigger popup when the visitor is browsing your site)</label></p>',
593 )
594 );
595 ?>
596
597 <hr />
598
599 <?php // Condition always present ?>
600 <div id="fca_eoi_publish_lightbox_mode_traditional_popup" class="hidden">
601 <fieldset class="fca_lightbox_condition fca_lightbox_condition_permanent">
602 <span class="fca_lightbox_condition_text"><?php _e('Show popup'); ?></span><?php
603 K::select(
604 'fca_eoi[publish_lightbox][show_every]'
605 , array()
606 , array(
607 'options' => array(
608 'never' => __( 'Never' ),
609 'always' => __( 'On every pageview' ),
610 'session' => __( 'Once per visit' ),
611 'day' => __( 'Once per day' ),
612 'month' => __( 'Once per month' ),
613 'once' => __( 'Only once' ),
614 ),
615 'selected' => K::get_var( 'show_every', $fca_eoi[ 'publish_lightbox' ] ),
616 )
617 );
618 ?>
619 <p class="fca_eoi_help"><?php _e( 'Set how frequently to show the popup. (Never means the popup is deactivated.)' ); ?></p>
620 </fieldset>
621 <?php
622 // Saved conditions
623 $saved_conditions = array();
624 $saved_conditions = K::get_var( 'conditions', $fca_eoi[ 'publish_lightbox' ], array() );
625
626 // Add default if creating a new form
627 if ( 'add' === $screen->action ) {
628 $saved_conditions = array(
629 '_'.time().'001' => array(
630 'parameter' => 'pageviews',
631 'value' => '2',
632 ),
633 '_'.time().'002' => array(
634 'parameter' => 'scrolled_percent',
635 'value' => '30',
636 ),
637 '_'.time().'003' => array(
638 'parameter' => 'time_on_page',
639 'value' => '30',
640 ),
641 );
642 }
643
644 foreach ( $saved_conditions as $condition_id => $condition ) {
645 // Skip conditions that are not available in version
646 if ( ! array_key_exists( $condition[ 'parameter' ], $conditions_options ) ) {
647 continue;
648 }
649
650 $select = K::select( "fca_eoi[publish_lightbox][conditions][$condition_id][parameter]"
651 , array()
652 , array(
653 'selected' => $condition['parameter'],
654 'options' => $conditions_options,
655 'return' => 'true',
656 )
657 );
658
659 if ( in_array( $condition['parameter'], array( 'include', 'exclude' ) ) ) {
660 $input = k_selector( "fca_eoi[publish_lightbox][conditions][$condition_id][value]"
661 , K::get_var( 'value', $condition, array() )
662 , true
663 );
664 } else if ( $condition['parameter'] == 'exit_intervention' ) {
665 $input = K::input( "fca_eoi[publish_lightbox][conditions][$condition_id][value]"
666 , array(
667 'type' => 'hidden',
668 'value' => ''
669 )
670 , array(
671 'return' => true
672 )
673 );
674 } else {
675 $input = K::input( "fca_eoi[publish_lightbox][conditions][$condition_id][value]"
676 , array(
677 'class' => 'medium-text',
678 'type' => 'text',
679 'value' => $condition['value'],
680 )
681 , array(
682 'return' => true,
683 )
684 );
685 }
686
687 $condition_HTML_inner = ''
688 . $select
689 . $input
690 . ' '
691 . '<span class="button fca_remove_lightbox_condition"><span style="vertical-align:text-top" class="dashicons dashicons-no"></span> Remove Rule</span>'
692 . '<p class="fca_eoi_help"></p>'
693 ;
694 echo '<div class="fca_eoi_and">- And -</div>';
695 K::wrap( $condition_HTML_inner
696 , array(
697 'id' => 'fca_lightbox_condition' . $condition_id,
698 'class' => 'fca_lightbox_condition',
699 'style' => '
700 padding: .5%;
701 margin:.5% 0;
702 box-shadow: 0 0 1px rgba(0, 0, 0, .2);
703 width: 97%;
704 background:#F7F7F7;
705 ',
706 )
707 , array(
708 'in' => 'fieldset',
709 )
710 );
711 }
712 ?>
713
714 <?php /* Button to add conditions */ ?>
715 <p><span class="button" id="fca_add_lightbox_condition"><span style="vertical-align:text-top" class="dashicons dashicons-plus"></span> Add Rule</span></p>
716 </div>
717
718 <?php if ( 'premium' === $this->settings[ 'distribution' ] ) { ?>
719 <div id="fca_eoi_publish_lightbox_mode_two_step_optin" class="hidden">
720 <?php
721 K::input( 'fca_eoi[lightbox_cta_text]'
722 , array(
723 'value' => K::get_var( 'lightbox_cta_text', $fca_eoi )
724 ? K::get_var( 'lightbox_cta_text', $fca_eoi )
725 : __( 'Free Download' )
726 ,
727 'class' => 'regular-text',
728 )
729 , array(
730 'format' => '<p><label>Call to action text :input</label></p>',
731 )
732 );
733 K::input( 'fca_eoi[lightbox_cta_link]'
734 , array(
735 'readonly' => 'readonly',
736 'value' => htmlspecialchars( sprintf( '<button data-optin-cat="%d">%s</button>'
737 , $post->ID
738 , __( 'Free Download' )
739 ) ),
740 'class' => 'regular-text autoselect',
741 )
742 , array(
743 'format' => '<p><label>Call to action link :input</label></p>',
744 )
745 );
746
747 K::wrap( __( 'Post above link into the text editor window of your post/page/widget.' )
748 , array( 'class' => 'description' )
749 , array( 'in' => 'p' )
750 );
751
752 ?>
753 </div>
754 <?php } ?>
755
756 <script>
757 jQuery( document ).ready( function( $ ) {
758
759 <?php
760 $lightbox_help = array(
761 '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.)' ),
762 '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.' ),
763 '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.' ),
764 '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.' ),
765 'exit_intervention' => __( 'Only show this popup to visitors who are about to close the current page.' ),
766 '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.' ),
767 );
768 ?>
769
770 var lightbox_help = <?php echo json_encode( $lightbox_help ) ?>;
771
772 // Condition template
773 <?php if ( 'free' === $this->settings[ 'distribution' ] ) { ?>
774 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>' );
775 <?php } else if ( 'premium' === $this->settings[ 'distribution' ] ) { ?>
776 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>' );
777 <?php } ?>
778
779 <?php
780 $s = str_replace( array( "\n", '"' )
781 , array( '', '\"' )
782 , k_selector( 'fca_eoi[publish_lightbox][conditions][_x_][value]', array(), true )
783 );
784 ?>
785
786 var s = "<?php echo $s; ?>";
787
788 var t = '<input class="medium-text" type="text" name="fca_eoi[publish_lightbox][conditions][_x_][value]"/>';
789
790 // Disables all but last condition, and use the right input field
791 $( document )
792 .on( 'change'
793 , "select[name^='fca_eoi[publish_lightbox][conditions]['][name$='][parameter]']"
794 , function() {
795 fix_conditions();
796 }
797 )
798 ;
799 $("select[name^='fca_eoi[publish_lightbox][conditions]['][name$='][parameter]']:first").change()
800 ;
801 function fix_conditions() {
802 var $button = $( '#fca_add_lightbox_condition' );
803 var $conditions;
804
805 $conditions = $( 'select' )
806 .filter( "[name^='fca_eoi[publish_lightbox][conditions][']" )
807 .filter( "[name$='][parameter]']" )
808 ;
809 // Prevent changing other conditions
810 $conditions
811 .not(':last')
812 .prop( 'disabled', true )
813 ;
814 // Allow changing last
815 $conditions
816 .last()
817 .prop( 'disabled', false )
818 ;
819 // Show hide plus button
820 if ( $conditions.length == $(f).find('select:first option').length ) {
821 $button.hide();
822 } else {
823 $button.show();
824 }
825
826 // Update conditions variable
827 $conditions = $( 'select' )
828 .filter( "[name^='fca_eoi[publish_lightbox][conditions][']" )
829 .filter( "[name$='][parameter]']" )
830 ;
831
832 /**
833 * Show posts selector VS input depending on option.
834 * Remove previously selected options.
835 * Update help text
836 * Use default when applicable (i.e when data-default is here)
837 * Remove overflow (condition fieldsets without possible options)
838 */
839 $conditions.each( function( i ) {
840 var $this = $( this );
841 var $fieldset = $this.parent();
842 var $parameter = $( '[name$="[parameter]"]', $fieldset );
843 var $value = $( '[name$="[value]"],[name$="[value][]"]', $fieldset );
844 var $input = $value;
845 var name = $value.attr( 'name' ).replace(/\[\]/g, '');
846 var is_textfield = $value.is( 'input' );
847 var is_hidden = ( 'exit_intervention' === $parameter.val() );
848 var use_textfield = ( 'include' !== $parameter.val() && 'exclude' !== $parameter.val() );
849 var cpt, condition, _default;
850
851 // Decide what element to use : input VS select
852 if ( use_textfield && ! is_textfield ) {
853 $( '.select2', $fieldset ).remove();
854 $input = $( t ).attr( 'name', name );
855 $parameter.after( $input );
856 } else if ( ! use_textfield && is_textfield ) {
857 $input = $( s ).attr( 'name', name + '[]' );
858 $value.replaceWith( $input );
859 }
860
861 // Hide or show the input
862 $input.attr( 'type', is_hidden ? 'hidden' : 'text' );
863
864 // Remove previously selected condition parameters
865 $conditions.not($this).find('option[value='+$this.val()+']').remove();
866
867 // Update help text
868 $( '.fca_eoi_help', $fieldset ).text( lightbox_help[ $parameter.val() ] );
869
870 // Use default
871 if ( _default = $( ':selected', $parameter).data( 'default' ) ) {
872 $value.val( _default );
873 $( 'option', $parameter ).data( 'default', '' );
874 }
875
876 // Remove overflow
877 if ( ! $( 'option', $parameter ).length ) {
878 $( '.fca_remove_lightbox_condition', $fieldset ).click();
879 }
880 } );
881 $('select.select2').select2();
882 }
883
884 $( document ).on( 'click', '.fca_remove_lightbox_condition', function( i ) {
885
886 var $this = $( this );
887 var $opt = $( 'select:first option:selected', $this.parent() )
888 .clone()
889 .removeAttr( 'selected' )
890 ;
891
892 $this.parent().remove(); // remove condition row
893
894 $('.fca_eoi_and').remove(); // removes "AND"
895 $('.fca_lightbox_condition:gt(0)').before( '<div class="fca_eoi_and">- And -</div>' );
896
897 $('select')
898 .filter( "[name^='fca_eoi[publish_lightbox][conditions][']" )
899 .filter( "[name$='][parameter]']" )
900 .append( $opt )
901 ;
902
903 fix_conditions();
904 } );
905
906
907 $( document ).on( 'click', '#fca_add_lightbox_condition', function() {
908
909 var $this = $( this );
910 var ts = Date.now();
911 var $condition = $( f.replace( /_x_/g, '_' + ts ) );
912
913 // Remove already used conditions
914 $( 'option', $condition ).each( function() {
915 var $this = $( this );
916 var val = $this.val();
917 var remove = $('select')
918 .filter("[name^='fca_eoi[publish_lightbox][conditions][']")
919 .filter("[name$='][parameter]']")
920 .find('option:selected[value=' + val + ']')
921 .length
922 ;
923
924 if ( remove ) {
925 $( this ).remove();
926 }
927 } );
928
929 $this.parent().before( '<div class="fca_eoi_and">- And -</div>' );
930 $this.parent().before( $condition );
931
932 // Bind removing to minus sign
933 $( '.fca_remove_lightbox_condition', '#fca_lightbox_condition_' + ts ).click( function() {
934 $( this ).parent().remove();
935 } );
936
937 // Prevent changing previous conditions
938 fix_conditions();
939 } );
940
941 // Enable disabled conditions fields to allow passing their value to the form action
942 $( document ).on( 'submit', '#post', function() {
943 $( 'select' )
944 .filter( "[name^='fca_eoi[publish_lightbox][conditions][']" )
945 .filter( "[name$='][parameter]']" )
946 .prop( 'disabled', false )
947 ;
948 } );
949 } );
950
951 </script>
952 <?php
953
954 echo '</div>'; // #fca_eoi_publish_lightbox
955 }
956
957 private function meta_box_field( $id, $title, $controls = array() ) {
958 $content = '';
959
960 foreach ( $controls as $control ) {
961 $control[2] = empty( $control[2] ) ? array() : $control[2];
962 $control[3] = empty( $control[3] ) ? array() : $control[3];
963
964 $control[3][ 'return' ] = true;
965
966 $content .= call_user_func_array( 'K::' . $control[0], array_slice( $control, 1 ) );
967 }
968
969 $content = trim( $content );
970 $class_name = 'accordion-section-primary-' . ( empty( $content ) ? 'empty' : 'full' );
971 $content = '<div class="' . $class_name . '">' . $content . '</div>';
972
973 K::wrap(
974 K::wrap(
975 $title,
976 array( 'class' => 'accordion-section-title' ),
977 array( 'return' => true )
978 ) .
979 K::wrap(
980 $content,
981 array( 'class' => 'accordion-section-content' ),
982 array( 'return' => true )
983 ),
984 array(
985 'class' => 'accordion-section',
986 'id' => $id
987 )
988 );
989 }
990
991 public function meta_box_content_build() {
992
993 global $post;
994 $post_meta = get_post_meta( $post->ID, 'fca_eoi', true );
995 $layout = get_post_meta( $post->ID, 'fca_eoi_layout', true );
996
997 $selected_layout = empty( $layout ) ? 'lightbox_not_set' : $layout;
998 $class = empty( $layout ) ? 'fca-new-layout' : '';
999 echo "<input id='fca_eoi_layout_select' name='fca_eoi[layout]' value='$selected_layout' hidden readonly class='$class'>";
1000
1001 //OUTPUT SELECTED OR DEFAULT TEMPLATE
1002
1003 echo "<div id='fca_eoi_form_preview'>";
1004
1005 $output = '<div id="fca_eoi_preview">';
1006 $output .= '<button class="button button-secondary" type="button" href="#" id="fca_eoi_show_setup">Change Layout</button>';
1007
1008 //JS WILL LOAD THE TEMPLATE
1009 //$output .= fca_eoi_get_layout_html( $selected_layout );
1010
1011 $output .= '</div>';
1012 echo $output;
1013 /* END FORM HTML GENERATION */
1014
1015 $providers_available = array_keys( $this->settings[ 'providers' ] );
1016 $providers_options = array();
1017 $screen = get_current_screen();
1018
1019 // Prepare providers options
1020 foreach ($this->settings[ 'providers' ] as $provider_id => $provider ) {
1021 $providers_options[ $provider_id ] = $provider[ 'info' ][ 'name' ];
1022 }
1023
1024 echo '<div id="fca_eoi_settings" class="accordion-container">';
1025
1026 $this->meta_box_field( 'fca_eoi_fieldset_form', 'Form', array(
1027 $this->generate_hidden_css_select_input('form_background_color_selector'),
1028 $this->generate_color_picker('form_background_color','Form Background Color'),
1029 $this->generate_hidden_css_select_input('form_border_color_selector'),
1030 $this->generate_color_picker('form_border_color','Border Color'),
1031 ) );
1032
1033 $this->meta_box_field( 'fca_eoi_fieldset_headline', 'Headline', array(
1034 array( 'input', 'fca_eoi[headline_copy]',
1035 array( 'value' => K::get_var( 'headline_copy', $post_meta ) ),
1036 array( 'format' => '<p><label><span class="control-title">Headline Copy</span><br />:input</label></p>' )
1037 ),
1038 $this->generate_hidden_css_select_input('headline_font_size_selector'),
1039 $this->generate_font_size_picker ('headline_font_size', 'Font Size'),
1040 $this->generate_hidden_css_select_input('headline_font_color_selector'),
1041 $this->generate_color_picker('headline_font_color','Font Color'),
1042 $this->generate_hidden_css_select_input('headline_background_color_selector'),
1043 $this->generate_color_picker('headline_background_color','Background Color'),
1044
1045 ) );
1046
1047 $this->meta_box_field( 'fca_eoi_fieldset_description', 'Description', array(
1048 array( 'textarea', 'fca_eoi[description_copy]', array(), array(
1049 'format' => ':textarea',
1050 'editor' => true,
1051 'value' => K::get_var( 'description_copy', $post_meta ),
1052 ) ),
1053 $this->generate_hidden_css_select_input('description_font_size_selector'),
1054 $this->generate_font_size_picker ('description_font_size', 'Font Size'),
1055 $this->generate_hidden_css_select_input('description_font_color_selector'),
1056 $this->generate_color_picker('description_font_color','Font Color'),
1057 ) );
1058
1059 $this->meta_box_field( 'fca_eoi_fieldset_name_field', 'Name Field', array(
1060 array( 'input', 'fca_eoi[show_name_field]',
1061 array(
1062 'type' => 'checkbox',
1063 'checked' => K::get_var( 'show_name_field', $post_meta ),
1064 'class' => 'switch-input'
1065 ),
1066 array(
1067 '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>'
1068 ),
1069 ),
1070 array( 'input', 'fca_eoi[name_placeholder]',
1071 array( 'value' => K::get_var( 'name_placeholder', $post_meta, 'First Name' ) ),
1072 array( 'format' => '<p><label><span class="control-title">Placeholder Text</span><br />:input</label></p>' )
1073 ),
1074 $this->generate_hidden_css_select_input('name_font_size_selector'),
1075 $this->generate_font_size_picker ('name_font_size', 'Font Size'),
1076 $this->generate_hidden_css_select_input('name_font_color_selector'),
1077 $this->generate_color_picker('name_font_color','Font Color'),
1078 $this->generate_hidden_css_select_input('name_background_color_selector'),
1079 $this->generate_color_picker('name_background_color','Background Color'),
1080 $this->generate_hidden_css_select_input('name_border_color_selector'),
1081 $this->generate_color_picker('name_border_color','Border Color'),
1082 ) );
1083
1084 $this->meta_box_field( 'fca_eoi_fieldset_email_field', 'Email Field', array(
1085 array( 'input', 'fca_eoi[email_placeholder]',
1086 array( 'value' => K::get_var( 'email_placeholder', $post_meta, 'Your Email' ) ),
1087 array( 'format' => '<p><label><span class="control-title">Placeholder Text</span><br />:input</label></p>' )
1088 ),
1089 $this->generate_hidden_css_select_input('email_font_size_selector'),
1090 $this->generate_font_size_picker ('email_font_size', 'Font Size'),
1091 $this->generate_hidden_css_select_input('email_font_color_selector'),
1092 $this->generate_color_picker('email_font_color','Font Color'),
1093 $this->generate_hidden_css_select_input('email_background_color_selector'),
1094 $this->generate_color_picker('email_background_color','Background Color'),
1095 $this->generate_hidden_css_select_input('email_border_color_selector'),
1096 $this->generate_color_picker('email_border_color','Border Color'),
1097 ) );
1098
1099 $this->meta_box_field( 'fca_eoi_fieldset_button', 'Button', array(
1100 array( 'input', 'fca_eoi[button_copy]',
1101 array( 'value' => K::get_var( 'button_copy', $post_meta, 'Subscribe Now' ) ),
1102 array( 'format' => '<p><label><span class="control-title">Button Copy</span><br />:input</label></p>' )
1103 ),
1104 $this->generate_hidden_css_select_input('button_font_size_selector'),
1105 $this->generate_font_size_picker ('button_font_size', 'Font Size'),
1106 $this->generate_hidden_css_select_input('button_font_color_selector'),
1107 $this->generate_color_picker('button_font_color','Font Color'),
1108 $this->generate_hidden_css_select_input('button_background_color_selector'),
1109 $this->generate_color_picker('button_background_color','Background Color'),
1110 array( 'input', "fca_eoi[button_wrapper_background_color_selector]",
1111 array ( 'class' => 'fca-hidden-input hidden',
1112 'value' => '.fca_eoi_layout_submit_button_wrapper'
1113 )
1114 ),
1115 $this->generate_hidden_css_select_input('button_wrapper_background_color'),
1116 ) );
1117
1118 $this->meta_box_field( 'fca_eoi_fieldset_privacy', 'Privacy Policy', array(
1119 array( 'textarea', 'fca_eoi[privacy_copy]',
1120 array(
1121 'class' => 'large-text',
1122 ),
1123 array(
1124 'format' => '<p><label><span class="control-title">Privacy Policy Copy</span><br />:textarea</label></p>',
1125 'value' => K::get_var( 'privacy_copy', $post_meta ),
1126 )
1127 ),
1128 $this->generate_hidden_css_select_input('privacy_font_size_selector'),
1129 $this->generate_font_size_picker ('privacy_font_size', 'Font Size'),
1130 $this->generate_hidden_css_select_input('privacy_font_color_selector'),
1131 $this->generate_color_picker('privacy_font_color','Font Color'),
1132 ) );
1133
1134 $this->meta_box_field( 'fca_eoi_fieldset_fatcatapps', 'Branding', array(
1135 array( 'input', 'fca_eoi[show_fatcatapps_link]',
1136 array(
1137 'type' => 'checkbox',
1138 'checked' => K::get_var( 'show_fatcatapps_link', $post_meta ),
1139 'class' => 'switch-input'
1140 ),
1141 array(
1142 '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>'
1143 ),
1144 ),
1145
1146 $this->generate_hidden_css_select_input('branding_font_color_selector'),
1147 $this->generate_color_picker ('branding_font_color', 'Font Color'),
1148 ) );
1149
1150 $this->meta_box_field( 'fca_eoi_fieldset_error_text', 'Error Text', array(
1151 array( 'textarea', 'fca_eoi[error_text_field_required]',
1152 array(
1153 'class' => 'large-text'
1154 ),
1155 array(
1156 'format' => '<p><label><span class="control-title">Field Required</span><br />:textarea</label></p>',
1157 'value' => K::get_var( 'error_text_field_required', $post_meta, '' )
1158 )
1159 ),
1160 array( 'textarea', 'fca_eoi[error_text_invalid_email]',
1161 array(
1162 'class' => 'large-text'
1163 ),
1164 array(
1165 'format' => '<p><label><span class="control-title">Invalid Email</span><br />:textarea</label></p>',
1166 'value' => K::get_var( 'error_text_invalid_email', $post_meta, '' )
1167 )
1168 )
1169 ) );
1170 echo '</div>';
1171 echo '</div>';
1172 echo '<br clear="all"/>';
1173
1174
1175 }
1176
1177 public function generate_hidden_css_select_input ($id) {
1178 return array( 'input', "fca_eoi[$id]",
1179 array ( 'class' => 'fca-hidden-input hidden',
1180 'value' => ''
1181 )
1182 );
1183 }
1184
1185 public function generate_color_picker ($id, $name) {
1186 global $post;
1187 $post_meta = get_post_meta( $post->ID, 'fca_eoi', true );
1188 return array( 'input', "fca_eoi[$id]",
1189 array ( 'class' => 'fca-color-picker',
1190 'value' => K::get_var( "$id", $post_meta )
1191 ),
1192 array(
1193 'format' => '<p><label><span class="control-title">'. $name . '</span><br />:input</label></p>',
1194 ),
1195 );
1196 }
1197
1198 public function generate_font_size_picker ($id, $name) {
1199 global $post;
1200 $post_meta = get_post_meta( $post->ID, 'fca_eoi', true );
1201 return array( 'select', "fca_eoi[$id]",
1202
1203 array (
1204 'data-selected' => K::get_var( "$id", $post_meta ),
1205 'class' => 'fca-font-size-picker ',
1206 ),
1207 array(
1208 'format' => '<p class="clear"><label><span class="control-title">'. $name . '</span><br />:select</label></p>',
1209 'options' => array(
1210 'none' => '',
1211 '7px' => '7px',
1212 '8px' => '8px',
1213 '9px' => '9px',
1214 '10px' => '10px',
1215 '11px' => '11px',
1216 '12px' => '12px',
1217 '13px' => '13px',
1218 '14px' => '14px',
1219 '15px' => '15px',
1220 '16px' => '16px',
1221 '17px' => '17px',
1222 '18px' => '18px',
1223 '19px' => '19px',
1224 '20px' => '20px',
1225 '21px' => '21px',
1226 '22px' => '22px',
1227 '23px' => '23px',
1228 '24px' => '24px',
1229 '25px' => '25px',
1230 '26px' => '26px',
1231 '27px' => '27px',
1232 '28px' => '28px',
1233 '29px' => '29px',
1234 '30px' => '30px',
1235 '31px' => '31px',
1236 '32px' => '32px',
1237 '33px' => '33px',
1238 '34px' => '34px',
1239 '35px' => '35px',
1240 '36px' => '36px',
1241 ),
1242 'selected' => K::get_var( "$id", $post_meta ),
1243 'return' => true,
1244 ),
1245 );
1246 }
1247
1248 public function meta_box_content_thanks() {
1249 global $post;
1250 $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true );
1251 $screen = get_current_screen();
1252
1253 // Get the previous thank you page if this is a new post
1254 $last_form_meta = get_option( 'fca_eoi_last_form_meta', '' );
1255 $thank_you_page_suggestion = empty ($last_form_meta['thank_you_page']) ? '~' : $last_form_meta['thank_you_page'];
1256 $thank_you_mode_suggestion = empty ($last_form_meta['thankyou_page_mode']) ? 'ajax' : $last_form_meta['thankyou_page_mode'];
1257 $thank_you_text_suggestion = empty ($last_form_meta['thankyou_ajax']) ? 'Thank you! Please check your inbox for your confirmation email.' : $last_form_meta['thankyou_ajax'];
1258
1259 // Prepare options
1260 $pages = array( '~' => __( 'Front page' ) );
1261 $pages_objects = get_pages();
1262 foreach ( $pages_objects as $page_obj ) {
1263 $pages[ $page_obj->ID ] = $page_obj->post_title;
1264 }
1265 K::input( 'fca_eoi[thankyou_page_mode]'
1266 , array(
1267 'type' => 'radio',
1268 'value' => 'redirect',
1269 'checked' => 'redirect' === K::get_var( 'thankyou_page_mode', $fca_eoi ),
1270 )
1271 , array(
1272 'format' => '<p><label>:input Redirect to "Thank You" page</label></p>',
1273 )
1274 );
1275
1276 if ( $this->settings['distribution'] === 'premium' ) {
1277
1278 K::input( 'fca_eoi[thankyou_page_mode]'
1279 , array(
1280 'type' => 'radio',
1281 'value' => 'ajax',
1282 'checked' => 'ajax' === K::get_var( 'thankyou_page_mode', $fca_eoi, $thank_you_mode_suggestion ),
1283 )
1284 , array(
1285 'format' => '<p><label>:input Display "Thank You" message using AJAX (Immediately after form submission. No page reload or redirect).</label></p>',
1286 )
1287 );
1288
1289 }
1290
1291 echo "<hr>";
1292
1293 echo "<div id='fca_eoi_thankyou_redirect'>";
1294
1295 K::wrap( 'Redirect user to the following page after submitting the form:'
1296 , null
1297 , array( 'in' => 'p' )
1298 );
1299 K::select( 'fca_eoi[thank_you_page]'
1300 , array(
1301 'class' => 'select2',
1302 'style' => 'width: 27em;',
1303 )
1304 , array(
1305 'format' => '<p><label>:select</label></p>',
1306 'options' => $pages,
1307 'selected' => 'add' === $screen->action
1308 ? $thank_you_page_suggestion
1309 : K::get_var( 'thank_you_page', $fca_eoi, '~' )
1310 ,
1311 )
1312 );
1313 K::wrap( __( 'Create a new "Thank You Page" &rsaquo;' )
1314 , array(
1315 'href' => admin_url( 'post-new.php?post_type=page' ),
1316 'target' => '_blank',
1317 )
1318 , array(
1319 'in' => 'a',
1320 'html_before' => '<p>',
1321 'html_after' => '</p>',
1322 )
1323 );
1324
1325 echo "</div>";
1326
1327 echo "<div id='fca_eoi_thankyou_ajax_msg'>";
1328 K::textarea( 'fca_eoi[thankyou_ajax]'
1329 , array(
1330 'class' => 'fca-eoi-thank-you-ajax',
1331 )
1332 , array(
1333 'value' => K::get_var( 'thankyou_ajax', $fca_eoi, $thank_you_text_suggestion ),
1334 'format' => '<label> Display this message after submitting the form:</label><br><br />:textarea',
1335 )
1336 );
1337 echo "</div>";
1338 }
1339
1340 public function meta_box_content_powerups() {
1341
1342 global $post;
1343 $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true );
1344 do_action('fca_eoi_powerups', $fca_eoi );
1345 }
1346
1347 /**
1348 * Save the Metabox Data
1349 */
1350 public function save_meta_box_content( $post_id, $post ) {
1351
1352 if ( isset ($_POST['fca_eoi'])) {
1353 $form_id = $post_id;
1354 $meta = $_POST['fca_eoi'];
1355
1356 $settings = array (
1357 'form_background_color_selector' => 'background-color',
1358 'form_border_color_selector' => 'border-color',
1359 'headline_font_size_selector' => 'font-size',
1360 'headline_font_color_selector' => 'color',
1361 'headline_background_color_selector' => 'background-color',
1362 'description_font_size_selector' => 'font-size',
1363 'description_font_color_selector' => 'color',
1364 'name_font_size_selector' => 'font-size',
1365 'name_font_color_selector' => 'color',
1366 'name_background_color_selector' => 'background-color',
1367 'name_border_color_selector' => 'border-color',
1368 'email_font_size_selector' => 'font-size',
1369 'email_font_color_selector' => 'color',
1370 'email_background_color_selector' => 'background-color',
1371 'email_border_color_selector' => 'border-color',
1372 'button_font_size_selector' => 'font-size',
1373 'button_font_color_selector' => 'color',
1374 'button_background_color_selector' => 'background-color',
1375 'button_wrapper_background_color_selector' => 'background-color',
1376 'privacy_font_size_selector' => 'font-size',
1377 'privacy_font_color_selector' => 'color',
1378 'branding_font_color_selector' => 'color',
1379 );
1380
1381 $animation = isset($_POST['fca_eoi_animations']) ? $_POST['fca_eoi_animations'] : '';
1382 $animationValue = isset($_POST['fca_eoi_show_animation_checkbox']) ? $_POST['fca_eoi_show_animation_checkbox'] : '';
1383 if ($animationValue != 'on') {
1384 $animation = '';
1385 }
1386
1387 // Add provider if missing (happens on free distros where there is only one provider)
1388 if( ! K::get_var( 'provider', $meta ) ) {
1389 $meta[ 'provider' ] = $this->settings[ 'provider' ];
1390 }
1391
1392 // Keep only the current providers settings, Remove all [provider]_[setting] not belonging to the current provider
1393 $provider = K::get_var( 'provider', $meta );
1394 if( $provider ) {
1395 $providers = array_keys( $this->settings[ 'providers' ] );
1396 $other_providers = array_values( array_diff( $providers, array( $provider ) ) );
1397 foreach ( $meta as $k => $v ) {
1398 $p = explode( '_', $k );
1399 $k_1 = array_shift( $p );
1400 if( in_array( $k_1, $other_providers ) ) {
1401 unset( $meta[ $k ] );
1402 }
1403 }
1404
1405 foreach ( $_POST as $k => $v ) {
1406 if ( strpos( $k, 'fca_eoi_' . $provider . '_' ) === 0 ) {
1407 delete_post_meta( $post->ID, $k );
1408 add_post_meta( $post->ID, $k, $v );
1409 $meta[ substr($k, 8) ] = $v;
1410 }
1411 }
1412 }
1413
1414 // Make sure empty value for publish_postbox or publish_lightbox are saved as array(-1)
1415 if( ! K::get_var( 'publish_postbox' , $meta, array() ) ) {
1416 $meta[ 'publish_postbox' ] = array(-1);
1417 }
1418 if( ! K::get_var( 'publish_lightbox' , $meta, array() ) ) {
1419 $meta[ 'publish_lightbox' ] = array(-1);
1420 }
1421
1422 //sanitize thank you ajax message
1423 if ( !empty ( $meta[ 'thankyou_ajax' ] ) ) {
1424 $meta[ 'thankyou_ajax' ] = htmlentities($meta[ 'thankyou_ajax' ], ENT_QUOTES, "UTF-8");
1425 }
1426
1427 //RN NOTE: THIS DO ANYTHING? -> ONLY FOR CUSTOM HTML FORMS SEEMS LIKE
1428 $on_save_function = $provider . '_on_save';
1429 if ( function_exists( $on_save_function ) ) {
1430 $meta = $on_save_function( $meta );
1431 }
1432
1433 //COMPILE CSS AND SAVE INTO 'HEAD' META
1434 $layout_id = $meta[ 'layout' ];
1435
1436 // General CSS for all forms
1437 $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; }";
1438
1439 if ( !empty( $layout_id ) ) {
1440
1441 // CACHE (ALMSOT) ALL THE OUTPUT HERE
1442 $layout = new EasyOptInsLayout( $layout_id );
1443 $scss_path = $layout->path_to_resource( 'layout', 'scss' );
1444
1445 if ( file_exists( $scss_path ) ) {
1446 $css_path = str_replace ( '.scss' , '_min.css', $scss_path );
1447 $css_file = file_get_contents( $css_path );
1448 }
1449
1450 $show_name = K::get_var( 'show_name_field', $meta, false );
1451 if ( !$show_name ) {
1452 $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_email_field_wrapper {width: 100% !important;}";
1453 $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_name_field_wrapper {display: none !important;}";
1454 }
1455
1456 //ADD CSS FROM FILE
1457 $css .= $css_file;
1458
1459 //ADD CUSTOM CSS FROM SAVE
1460 $added_inherent_css_rule = false;
1461 $added_widget_3_css_rule = false;
1462
1463 foreach ( $settings as $key => $property ) {
1464 $selector = $meta[$key];
1465 $input = str_replace ( '_selector', '', $key);
1466
1467 if ( !empty ( $selector ) ) {
1468 //BUTTON HOVER HACK
1469 if ( strpos ( $selector, '.fca_eoi_layout_submit_button_wrapper input' ) !== false && !$added_inherent_css_rule ) {
1470 $css .= "#fca_eoi_form_$form_id $selector:hover { background-color: inherit !important; }";
1471 $added_inherent_css_rule = true;
1472 }
1473 //SPECIAL CASE FOR WIDGET 3
1474 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' ) {
1475 $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; }";
1476 $added_widget_3_css_rule = true;
1477 }
1478
1479 $css .= "#fca_eoi_form_$form_id $selector { $property: $meta[$input] !important; }";
1480 }
1481 }
1482
1483 $head = $css . '</style>';
1484
1485 $html = fca_eoi_get_html ( $form_id, $meta );
1486
1487 $head = $head . $html;
1488 $meta[ 'post_id' ] = $post_id;
1489 update_option( 'fca_eoi_last_provider', $meta[ 'provider' ] );
1490 update_option( 'fca_eoi_last_form_meta', $meta );
1491 update_post_meta( $post->ID, 'fca_eoi_meta_format', '2.0' );
1492 update_post_meta( $post->ID, 'fca_eoi', $meta );
1493 update_post_meta( $post->ID, 'fca_eoi_layout', $meta[ 'layout' ] );
1494 update_post_meta( $post->ID, 'fca_eoi_provider', $meta[ 'provider' ] );
1495 update_post_meta( $post->ID, 'fca_eoi_animation', $animation );
1496 update_post_meta( $post->ID, 'fca_eoi_head', $head );
1497
1498 }
1499 }
1500 }
1501
1502 public function live_preview( $content ) {
1503 global $post;
1504 if (get_post_type() == 'easy-opt-ins' && is_main_query()) {
1505 $shortcode = sprintf( '[%s id=%d]', $this->settings[ 'shortcode' ], $post->ID );
1506 return do_shortcode($shortcode);
1507 } else {
1508 return $content;
1509 }
1510 }
1511
1512 public function admin_enqueue() {
1513
1514 $provider = $this->settings[ 'provider' ];
1515 $providers_available = array_keys( $this->settings[ 'providers' ] );
1516
1517 /**
1518 * Disable autosaving optin forms since it causes data loss
1519 */
1520 if ( 'easy-opt-ins' == get_post_type() ) {
1521 wp_dequeue_script( 'autosave' );
1522 }
1523
1524 $screen = get_current_screen();
1525 if( 'easy-opt-ins' === $screen->id ){
1526 global $post;
1527 $meta = get_post_meta($post->ID, 'fca_eoi', true );
1528 $options = get_option( 'fca_eoi_settings' );
1529 //LOAD DEPENDENCIES
1530 wp_enqueue_script( 'fca_eoi_tooltipster', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.js', array(), FCA_EOI_VER, true );
1531 wp_enqueue_style( 'fca_eoi_tooltipster_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.css', array(), FCA_EOI_VER );
1532 wp_enqueue_style( 'fca_eoi_tooltipster_theme_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster-borderless.min.css', array(), FCA_EOI_VER );
1533
1534 wp_enqueue_style( 'wp-color-picker' );
1535 wp_enqueue_script( 'wp-color-picker' );
1536 wp_enqueue_script( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js', array(), FCA_EOI_VER, true );
1537 wp_enqueue_style( 'font-awesome', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css', array(), FCA_EOI_VER );
1538 wp_enqueue_style( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css', array(), FCA_EOI_VER );
1539 wp_enqueue_script( 'accordion' );
1540
1541 if ( !empty( $options['animation'] ) ) {
1542 wp_enqueue_style( 'fca_eoi_powerups_animate', FCA_EOI_PLUGIN_URL . '/assets/vendor/animate/animate.css', array(), FCA_EOI_VER );
1543 }
1544
1545 //LOAD CUSTOM AJAX SPINNER CODE/CSS
1546 wp_enqueue_script( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.js', array(), FCA_EOI_VER, true );
1547 wp_enqueue_style( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.css', array(), FCA_EOI_VER );
1548
1549 //LOAD COMMON CSS
1550 wp_enqueue_style( 'fca_eoi', FCA_EOI_PLUGIN_URL .'/assets/style-new.css', array(), FCA_EOI_VER );
1551
1552 //LOAD EDITOR JS
1553 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 );
1554
1555 //LOAD PROVIDER JS AND CSS
1556 foreach ( $providers_available as $provider ) {
1557 wp_enqueue_script( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . '/providers/' . $provider . '/cpt-easy-opt-ins.js', array(), FCA_EOI_VER, true );
1558
1559 $css_path = '/providers/' . $provider . '/cpt-easy-opt-ins.css';
1560 if ( is_readable( FCA_EOI_PLUGIN_DIR . $css_path ) ) {
1561 wp_enqueue_style( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . $css_path, array(), FCA_EOI_VER );
1562 }
1563 }
1564 //SEND VARIABLES TO JS
1565 $useGroups = empty ( $options['mailchimp_groups'] ) ? array('off') : array('on') ;
1566 wp_localize_script( 'admin-cpt-easy-opt-ins-mailchimp', 'useGroups', $useGroups );
1567
1568 $tags = empty($meta['aweber_tags']) ? '' : $meta['aweber_tags'];
1569 $aweberSettings = array(
1570 'tags' => $tags,
1571 );
1572 wp_localize_script( 'admin-cpt-easy-opt-ins-aweber', 'aweberSettings', $aweberSettings );
1573
1574
1575 $file = plugin_dir_path( __FILE__ ) . "layout-cache";
1576 $layout_data = unserialize (file_get_contents($file));
1577
1578 wp_localize_script( 'fca-eoi-editor', 'layouts', $layout_data );
1579
1580 //EDITOR CSS
1581 wp_enqueue_style( 'admin-cpt-easy-opt-ins', FCA_EOI_PLUGIN_URL . '/assets/admin/cpt-easy-opt-ins.css', array(), FCA_EOI_VER );
1582
1583 if ( has_action( 'fca_eoi_powerups' ) ) {
1584 wp_enqueue_script('fca_eoi_powerups', FCA_EOI_PLUGIN_URL . '/assets/powerups/fca_eoi_powerups.js', array(), FCA_EOI_VER, true);
1585 }
1586 }
1587 if( 'widgets' === $screen->id ){
1588 wp_enqueue_script( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js', array(), FCA_EOI_VER, true );
1589 wp_enqueue_style( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css', array(), FCA_EOI_VER );
1590 }
1591 }
1592
1593 /**
1594 * Hides minor publising form items (status, visibility and publication date)
1595 *
1596 * This function shoud be used along with force_published to prevent
1597 * saving posts as drafts
1598 */
1599 public function hide_minor_publishing() {
1600 $screen = get_current_screen();
1601 if( in_array( $screen->id, array( 'easy-opt-ins' ) ) ) {
1602 echo '<style>#minor-publishing { display: none; }</style>';
1603 }
1604 }
1605
1606 /**
1607 * Forces one column
1608 */
1609 public function force_one_column() {
1610
1611 return 1;
1612 }
1613
1614 /**
1615 * Sort metaboxes
1616 */
1617 public function order_columns( $order ) {
1618 return array(
1619 'normal' => join( ",", array(
1620 'submitdiv',
1621 'fca_eoi_meta_box_nav',
1622 'fca_eoi_meta_box_setup',
1623 'fca_eoi_meta_box_build',
1624 'fca_eoi_meta_box_provider',
1625 'fca_eoi_meta_box_thanks',
1626 'fca_eoi_meta_box_publish',
1627 'fca_eoi_meta_box_powerups',
1628 'fca_eoi_meta_box_debug',
1629 ) ),
1630 'side' => '',
1631 'advanced' => '',
1632 );
1633 }
1634
1635 /**
1636 * replacing the default "Enter title here" placeholder text in the title input box to
1637 *
1638 */
1639 public function change_default_title($title) {
1640
1641 $screen = get_current_screen();
1642
1643 if ( 'easy-opt-ins' == $screen->post_type ) {
1644 $title = 'Enter name here';
1645 }
1646
1647 return $title;
1648 }
1649
1650 /**
1651 * Override some strings to match our likings
1652 */
1653 public function override_text( $messages ) {
1654
1655 global $post;
1656
1657 $post_ID = $post->ID;
1658 $post_type = get_post_type( $post_ID );
1659
1660 $obj = get_post_type_object( $post_type );
1661 $singular = $obj->labels->singular_name;
1662
1663 if ( 'easy-opt-ins' === $post->post_type ) {
1664
1665 $messages[$post_type] = array(
1666 0 => '', // Unused. Messages start at index 1.
1667 1 => __( 'Opt-In Form updated.' ),
1668 2 => __( 'Opt-In Form updated.' ),
1669 3 => __( 'Opt-In Form deleted.' ),
1670 4 => __( 'Opt-In Form updated.' ),
1671 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,
1672 6 => __( 'Opt-In Form saved.' ),
1673 7 => sprintf( __( '%s saved.' ), esc_attr( $singular ) ),
1674 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 ) ),
1675 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 ) ),
1676 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 ) )
1677 );
1678
1679 }
1680
1681 return $messages;
1682
1683 }
1684
1685 public function force_published( $post ) {
1686
1687 if( ! in_array( $post[ 'post_status' ], array( 'auto-draft', 'trash') ) ) {
1688 if( in_array( $post[ 'post_type' ], array( 'easy-opt-ins' ) ) ) {
1689 $post['post_status'] = 'publish';
1690 }
1691 }
1692 return $post;
1693 }
1694
1695 /**
1696 * Disables bulk editing
1697 */
1698 public function disable_bulk_edit( $actions ){
1699 unset( $actions[ 'edit' ] );
1700 return $actions;
1701 }
1702
1703 /**
1704 * Removes quick edit
1705 */
1706 public function remove_quick_edit( $actions ) {
1707 global $post;
1708 if( 'easy-opt-ins' === $post->post_type ) {
1709 unset($actions['inline hide-if-no-js']);
1710 }
1711 return $actions;
1712 }
1713
1714 /**
1715 * Add the desired body classes (backend)
1716 */
1717 public function add_body_class( $classes ) {
1718 return "$classes fca_eoi";
1719 }
1720
1721 /**
1722 * Handle Adding a subscriber with Ajax
1723 */
1724 public function ajax_subscribe() {
1725
1726 $error = '';
1727 // Get meta
1728 $id = $_REQUEST['form_id'];
1729
1730 if (empty ($id)){
1731 $error .= "Couldn't find form ID";
1732 }
1733
1734 $fca_eoi = get_post_meta( $id, 'fca_eoi', true );
1735
1736 if (empty ($fca_eoi)){
1737 $error .= "Couldn't find post meta";
1738 }
1739
1740 $provider = K::get_var( 'provider' , $fca_eoi );
1741
1742 // Check a list_id is provided
1743 $list_id = K::get_var( $provider . '_list_id' , $fca_eoi );
1744 if ( empty( $list_id ) ) {
1745 $error .= "List not set";
1746 }
1747
1748 $nonce = $_REQUEST['nonce'];
1749 $nonceVerified = wp_verify_nonce( $nonce, 'fca_eoi_submit_form' );
1750 if ($nonceVerified === FALSE) {
1751 $error .= "Couldn't verify form submission";
1752 }
1753
1754 // Subscribe user
1755 $status = false;
1756
1757 if( $list_id && $nonceVerified !== FALSE ) {
1758 $str = $provider . '_add_user';
1759
1760 $status = call_user_func( $provider . '_add_user' , $this->settings , $_POST , $list_id );
1761
1762 do_action('fca_eoi_after_submission', $fca_eoi, $_POST );
1763
1764 if ($status !== TRUE) {
1765 $error .= " Can't add user";
1766 }
1767 }
1768
1769 if ( $status !== FALSE && $error === '' ) {
1770 echo '';
1771 EasyOptInsActivity::get_instance()->add_conversion( $id );
1772 } else {
1773 echo '' . " Error: " . $error;
1774 }
1775
1776 exit;
1777 }
1778
1779 public function admin_notices() {
1780
1781 //RN NOTE: MAYBE REWRITE
1782 $current_screen = get_current_screen();
1783
1784 // Exit function if we are not on the opt-in editing page
1785 if ( ! (
1786 'easy-opt-ins' === $current_screen->id
1787 && 'post' === $current_screen->base
1788 && 'edit' === $current_screen->parent_base
1789 && '' === $current_screen->action
1790 ) ) {
1791 return;
1792 }
1793
1794 global $post;
1795 $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true );
1796 $provider = K::get_var( 'provider', $fca_eoi);
1797 $errors = array();
1798
1799 // Add error for missing thank you page
1800 $confirmation_page_set = ( bool ) K::get_var( 'thank_you_page', $fca_eoi);
1801 if( ! $confirmation_page_set ) {
1802 $errors[] = __( 'No "Thank you" page selected. You will not be able to use this form.' );
1803 }
1804
1805 // Add error for missing list setting for the current provider
1806 $list_set = ( bool ) K::get_var( $provider . '_list_id', $fca_eoi);
1807
1808 // @todo: remove
1809 // Hack for mailchimp upgrade
1810 if( empty( $fca_eoi[ 'provider' ] ) ) {
1811 $fca_eoi[ 'mailchimp_list_id' ] = K::get_var(
1812 'mailchimp_list_id'
1813 , $fca_eoi
1814 , K::get_var( 'list_id' , $fca_eoi )
1815 );
1816 $list_set = ( bool ) K::get_var( 'mailchimp_list_id', $fca_eoi);
1817 }
1818 // End of Hack
1819
1820
1821 if( ! $list_set ) {
1822 $errors[] = __( 'No List selected. You will not be able to use this form.' );
1823 }
1824
1825 $errors = apply_filters( 'fca_eoi_alter_admin_notices', $errors );
1826
1827 foreach ( $errors as $error ) {
1828 echo '<div class="error"><p>' . $error . '</p></div>';
1829 }
1830 }
1831
1832 public function bind_content_filter() {
1833
1834 // Do nothing in backend
1835 if ( is_admin() ) {
1836 return;
1837 }
1838
1839 add_action( 'wp', array( $this, 'content' ), 10 );
1840 }
1841
1842 public function content() {
1843 //RN NOTE WAT
1844 global $post;
1845
1846 if ( empty( $post ) ) {
1847 return;
1848 }
1849
1850 // Do nothing if viewing an opt-in
1851 if ( 'easy-opt-ins' === $post->post_type ) {
1852 return;
1853 }
1854
1855 // Work only when viewing a post of any type
1856 if ( empty( $post ) ) {
1857 return;
1858 }
1859
1860 $priorities = array();
1861
1862 // Post details
1863 $post_ID = $post->ID;
1864 $post_type = get_post_type( $post_ID );
1865
1866 // Build the array for testing
1867 $post_cond = array(
1868 '*',
1869 $post_type,
1870 '#' . $post_ID,
1871 );
1872 if ( is_front_page() ) {
1873 $post_cond[] = '~';
1874 }
1875
1876 $priorities[] = '#' . $post_ID;
1877
1878 $taxonomies = get_taxonomies('','names');
1879 $post_taxonomies = wp_get_object_terms( $post->ID,$taxonomies);
1880 foreach ( $post_taxonomies as $t ) {
1881 $condition = $post_type . ':' . $t->term_id;
1882
1883 $post_cond[] = $condition;
1884 $priorities[] = $condition;
1885 }
1886
1887 $priorities[] = $post_type;
1888 $priorities[] = '*';
1889
1890 $fca_eoi_last_99_forms = array();
1891 foreach (get_posts( 'posts_per_page=99&post_type=easy-opt-ins' ) as $i => $f ) {
1892 $fca_eoi_last_99_forms[ $i ][ 'post' ] = $f;
1893 $fca_eoi_last_99_forms[ $i ][ 'fca_eoi' ] = get_post_meta( $f->ID, 'fca_eoi', true );
1894 }
1895 // wp_reset_query();
1896
1897 $postboxes = array();
1898
1899 // Append postcode shortcode when the conditions match
1900 foreach( $fca_eoi_last_99_forms as $f) {
1901
1902 // Exclude other layout types
1903 if ( empty ( $f[ 'fca_eoi' ][ 'layout' ] ) ) {
1904 continue;
1905 }
1906 if ( strpos( $f[ 'fca_eoi' ][ 'layout' ], 'postbox_' ) !== 0 ) {
1907 continue;
1908 }
1909
1910 // Get conditions
1911 $eoi_form_cond = K::get_var( 'publish_postbox', $f[ 'fca_eoi' ], array() );
1912
1913 // Append
1914 if ( array_intersect( $eoi_form_cond, $post_cond ) ) {
1915 foreach ( $eoi_form_cond as $cond ) {
1916 if ( empty( $postboxes[ $cond ] ) ) {
1917 $postboxes[ $cond ] = sprintf( '[%s id=%d]', $this->settings['shortcode'], $f['post']->ID );
1918 }
1919 }
1920 }
1921 }
1922
1923 if ( ! empty( $postboxes ) ) {
1924 foreach ( $priorities as $cond ) {
1925 if ( ! empty( $postboxes[ $cond ] ) ) {
1926 $post->post_content .= $postboxes[ $cond ];
1927 return;
1928 }
1929 }
1930
1931 $post->post_content .= reset( $postboxes );
1932 return;
1933 }
1934 }
1935
1936 private function get_tc_token( $form_id ) {
1937 return "$form_id";
1938 }
1939
1940 private function to_call_tc_condition( $name, $arguments ) {
1941 return array_merge( array( $name ), $arguments );
1942 }
1943
1944 private function to_value_tc_condition( $form_id, $name, $eoi_condition ) {
1945 $value = intval( $eoi_condition['value'] );
1946 $params = array( $value );
1947
1948 if ( $name === 'page_views' ) {
1949 $params[] = $this->get_tc_token( $form_id );
1950 } else if ( $name === 'time_on_page' ) {
1951 $params[0] *= 1000;
1952 }
1953
1954 return $this->to_call_tc_condition( $name, $params );
1955 }
1956
1957 private function to_server_pass_tc_condition( $post_id, $parameter, $eoi_condition ) {
1958 $url = add_query_arg( array(
1959 'fca_eoi_tc_condition_pass' => urlencode( $parameter ),
1960 'fca_eoi_tc_condition_value' => urlencode( implode( ',', $eoi_condition['value'] ) ),
1961 'fca_eoi_tc_condition_post_id' => $post_id
1962 ) );
1963
1964 return $this->to_call_tc_condition( 'server_pass', array( $url, 'true' ) );
1965 }
1966
1967 private function to_tc_condition( $form_id, $post_id, $eoi_condition ) {
1968 $eoi_to_tc_value_map = array(
1969 'pageviews' => 'page_views',
1970 'scrolled_percent' => 'scroll_percent',
1971 'time_on_page' => 'time_on_page'
1972 );
1973
1974 $eoi_server_pass_conditions = array( 'include', 'exclude' );
1975
1976 $parameter = $eoi_condition['parameter'];
1977 if ( array_key_exists( $parameter, $eoi_to_tc_value_map ) ) {
1978 return $this->to_value_tc_condition( $form_id, $eoi_to_tc_value_map[ $parameter ], $eoi_condition );
1979 } else if ( in_array( $parameter, $eoi_server_pass_conditions ) ) {
1980 return $this->to_server_pass_tc_condition( $post_id, $parameter, $eoi_condition );
1981 }
1982
1983 return null;
1984 }
1985
1986 private function to_show_every_tc_condition( $form_id, $condition ) {
1987 if ( in_array( $condition, array( 'day', 'month', 'once', 'session' ) ) ) {
1988 return array( $condition, $this->get_tc_token( $form_id ) );
1989 } elseif ( $condition === 'always' ) {
1990 return 'true';
1991 } elseif ( $condition === 'never' ) {
1992 return 'false';
1993 }
1994
1995 return $condition;
1996 }
1997
1998 private function get_tc_conditions( $form_id, $post_id, $conditions ) {
1999 $tc_conditions = array();
2000 $sequence_conditions = array();
2001
2002 if ( ! empty( $conditions['show_every'] ) ) {
2003 $condition = $this->to_show_every_tc_condition( $form_id, $conditions['show_every'] );
2004
2005 if ( $condition === 'false' ) {
2006 return array( 'false' );
2007 } else {
2008 $sequence_conditions[] = $condition;
2009 }
2010 }
2011
2012 if ( ! empty( $conditions['conditions'] ) ) {
2013 foreach ( $conditions['conditions'] as $condition ) {
2014 if ( $condition['parameter'] === 'exit_intervention' ) {
2015 $sequence_conditions[] = 'exit';
2016 continue;
2017 }
2018
2019 $tc_condition = $this->to_tc_condition( $form_id, $post_id, $condition );
2020 if ( ! empty( $tc_condition ) ) {
2021 $tc_conditions[] = $tc_condition;
2022 }
2023 }
2024 }
2025
2026 $has_conditions = ! empty ( $tc_conditions );
2027 if ( $has_conditions ) {
2028 $tc_conditions = array( 'and' => $tc_conditions );
2029 }
2030
2031 if ( $sequence_conditions ) {
2032 if ( $has_conditions ) {
2033 $tc_conditions = array( 'sequence' => array( $tc_conditions ) );
2034 } else {
2035 $tc_conditions = array( 'sequence' => array() );
2036 }
2037 foreach ( $sequence_conditions as $condition ) {
2038 $tc_conditions['sequence'][] = $condition;
2039 }
2040 }
2041
2042 return $tc_conditions;
2043 }
2044
2045 private function echo_tc_conditions_for_form( $form_id, $post_id ) {
2046 $fca_eoi = get_post_meta( $form_id , 'fca_eoi', true );
2047 $publish_lightbox = K::get_var( 'publish_lightbox', $fca_eoi, array() );
2048
2049 header( 'Content-Type: application/json' );
2050 exit( json_encode( $this->get_tc_conditions( $form_id, $post_id, $publish_lightbox ) ) );
2051 }
2052
2053 private function echo_tc_condition_pass( $post_id, $type, $values ) {
2054 $post_cond = array( '*' );
2055
2056 if ( is_front_page() ) {
2057 $post_cond[] = '~';
2058 }
2059
2060 if ( $post_id ) {
2061 $post_type = get_post_type( $post_id );
2062
2063 $post_cond[] = $post_type;
2064 $post_cond[] = '#' . $post_id;
2065
2066 $taxonomies = get_taxonomies( '', 'names' );
2067 $post_taxonomies = wp_get_object_terms( $post_id, $taxonomies );
2068
2069 foreach ( $post_taxonomies as $t ) {
2070 $post_cond[] = $post_type . ':' . $t->term_id;
2071 }
2072 } else {
2073 //FIX FOR NOT DISPLAYING ON BLOG PAGE
2074
2075 if ( is_home() ) {
2076 $post_cond[] = '#' . get_option('page_for_posts');
2077 }
2078
2079 }
2080
2081 $intersect = array_intersect( $values, $post_cond );
2082
2083 if ( $type === 'include' ) {
2084 echo $intersect ? 'true' : 'false';
2085 } else if ( $type === 'exclude' ) {
2086 echo $intersect ? 'false' : 'true';
2087 }
2088
2089 exit;
2090 }
2091
2092 public function parse_tc_condition_request() {
2093 $post_id = empty( $_REQUEST['fca_eoi_tc_condition_post_id'] ) ? 0 : (int) $_REQUEST['fca_eoi_tc_condition_post_id'];
2094
2095 if ( ! empty( $_REQUEST['fca_eoi_tc_conditions_for'] ) ) {
2096 $form_id = (int) $_REQUEST['fca_eoi_tc_conditions_for'];
2097 $this->echo_tc_conditions_for_form( $form_id, $post_id );
2098 }
2099
2100 if ( ! empty( $_REQUEST['fca_eoi_tc_condition_pass'] ) ) {
2101 $this->echo_tc_condition_pass(
2102 $post_id,
2103 $_REQUEST['fca_eoi_tc_condition_pass'],
2104 explode( ',', $_REQUEST['fca_eoi_tc_condition_value'] )
2105 );
2106 }
2107 }
2108
2109 private function get_cookie_configuration() {
2110 $cookie_configuration = array();
2111
2112 if ( defined( 'COOKIEPATH' ) ) {
2113 $path = COOKIEPATH;
2114 if ( ! empty( $path ) ) {
2115 $cookie_configuration['path'] = $path;
2116 }
2117 }
2118
2119 if ( defined( 'COOKIE_DOMAIN' ) ) {
2120 $domain = COOKIE_DOMAIN;
2121 if ( ! empty( $domain ) ) {
2122 $cookie_configuration['domain'] = $domain;
2123 }
2124 }
2125
2126 return $cookie_configuration;
2127 }
2128
2129 public function scan_for_shortcodes( $content ) {
2130 if ( preg_match_all( '/data-optin-cat\s*=\s*["\']?\s*(\d+)/', $content, $matches ) ) {
2131 $this->two_step_ids_on_page = array_map( 'intval', $matches[1] );
2132 }
2133
2134 return $content;
2135 }
2136
2137 public function show_lightbox() {
2138
2139 // Do not show lightbox on mobile if this is the free distribution
2140 if ( $this->settings[ 'distribution' ] === 'free' ) {
2141 $mobile_detect = new Mobile_Detect;
2142 if ( $mobile_detect->isMobile() ) {
2143 return;
2144 }
2145 }
2146
2147 // Get lightboxes
2148 $lightboxes = get_posts( array(
2149 'post_type' => 'easy-opt-ins',
2150 'posts_per_page' => -1,
2151 'orderby' => 'ID',
2152 'meta_key' => 'fca_eoi_layout',
2153 'meta_value' => 'lightbox_',
2154 'meta_compare' => 'like',
2155 ) );
2156
2157 // Exit function if no lightbox found
2158 if( ! $lightboxes ) {
2159 return;
2160 }
2161
2162 $two_step_ids = array();
2163 $traditional_ids = array();
2164
2165 foreach ( $lightboxes as $lightbox ) {
2166
2167 // Get conditions
2168 $lightbox->fca_eoi = get_post_meta( $lightbox->ID , 'fca_eoi', true );
2169 $publish_lightbox_mode = K::get_var( 'publish_lightbox_mode', $lightbox->fca_eoi, array() );
2170
2171 // If on a free distribution, force traditional popup mode
2172 if ( 'free' === $this->settings['distribution'] ) {
2173 $publish_lightbox_mode = 'traditional_popup';
2174 }
2175
2176 if ( 'two_step_optin' === $publish_lightbox_mode ) {
2177 $two_step_ids[] = $lightbox->ID;
2178 } else {
2179 $traditional_ids[] = $lightbox->ID;
2180 }
2181 }
2182
2183 $this->display_traditional_popups($traditional_ids, $this->display_two_step_popups($two_step_ids));
2184 }
2185
2186 private function display_two_step_popups($lightbox_ids) {
2187 $lightbox_ids = array_intersect( $lightbox_ids, $this->two_step_ids_on_page );
2188
2189 if ( empty( $lightbox_ids ) ) {
2190 return false;
2191 }
2192 do_action( 'fca_eoi_display_lightbox' );
2193
2194 foreach ( $lightbox_ids as $lightbox_id ) {
2195 $this->prepare_lightbox( $lightbox_id );
2196 }
2197
2198 ?>
2199 <script>
2200 jQuery( function() {
2201 jQuery( document ).on( 'click', '[data-optin-cat]', function( e ) {
2202 var lightbox_id = jQuery( this ).data( 'optin-cat' );
2203 <?php echo EasyOptInsActivity::get_instance()->get_tracking_code( 'lightbox_id', false ) ?>
2204 jQuery.featherlight( jQuery( '#fca_eoi_lightbox_' + lightbox_id ), <?php echo $this->get_featherlight_options() ?> );
2205 e.preventDefault();
2206 } );
2207 } );
2208 </script>
2209 <?php
2210
2211 return true;
2212 }
2213
2214 private function display_traditional_popups( $lightbox_ids, $prerequisites_loaded = false ) {
2215 if ( empty( $lightbox_ids ) ) {
2216 return false;
2217 }
2218
2219 wp_enqueue_script( 'fca_eoi_script_js', FCA_EOI_PLUGIN_URL.'/assets/script.js', array(), FCA_EOI_VER, true );
2220 //PASS VARIABLES TO JAVASCRIPT
2221 $data = array (
2222 'ajax_url' => admin_url( 'admin-ajax.php' ),
2223 'nonce' => wp_create_nonce( 'fca_eoi_submit_form' ),
2224 );
2225
2226 wp_localize_script( 'fca_eoi_script_js', 'fca_eoi', $data );
2227 wp_enqueue_script( 'fca_eoi_featherlight_js', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.js', array(), FCA_EOI_VER, true );
2228 wp_enqueue_style( 'fca_eoi_featherlight_css', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.css', array(), FCA_EOI_VER );
2229
2230 ?>
2231 <script type="text/javascript" src="<?php echo FCA_EOI_PLUGIN_URL . '/' . $this->targeting_cat_path ?>"></script>
2232 <script>
2233 (function() {
2234 if ( typeof fca_eoi === "undefined" ) {
2235 fca_eoi = {};
2236 }
2237
2238 fca_eoi.ajax_url = <?php echo json_encode( admin_url( 'admin-ajax.php' ) ) ?>;
2239 })();
2240
2241 <?php $v = array(
2242 'prerequisites_loaded' => 'p',
2243 'load_prerequisites' => 'l',
2244 'head' => 'h',
2245 'load_script' => 'c',
2246 'load_style' => 'y',
2247 'callback' => 'k',
2248 'vendor_url' => 'v',
2249 'done' => 'n',
2250 'document' => 'd',
2251 'window.location.href' => 'w',
2252 'display_popup' => 's',
2253 'false' => '!1',
2254 'true' => '1',
2255 'evaluable' => 'e',
2256 'descriptors' => 'r',
2257 'form_id' => 'm',
2258 'TargetingCat_OptinCat' => 'g',
2259 'url' => 'u'
2260 ); ?>
2261
2262 <?php ob_start(); ?>
2263
2264 jQuery( function( $ ) {
2265 var
2266 <?php echo $v['document'] ?> = document,
2267 <?php echo $v['window.location.href'] ?> = window.location.href,
2268 <?php echo $v['TargetingCat_OptinCat'] ?> = TargetingCat_OptinCat;
2269
2270 <?php if ( ! $prerequisites_loaded ) { ?>
2271
2272 var
2273 <?php echo $v['prerequisites_loaded'] ?> = <?php echo $v['false'] ?>,
2274 <?php echo $v['head'] ?> = <?php echo $v['document'] ?>.head;
2275
2276 function <?php echo $v['load_script'] ?>( <?php echo $v['url'] ?>, <?php echo $v['callback'] ?> ) {
2277 var e = <?php echo $v['document'] ?>.createElement( 'script' );
2278
2279 e.type = 'text/javascript';
2280 e.src = <?php echo $v['url'] ?>;
2281 e.onload = <?php echo $v['callback'] ?>;
2282
2283 <?php echo $v['head'] ?>.appendChild( e );
2284 }
2285
2286 function <?php echo $v['load_style'] ?>( <?php echo $v['url'] ?>, <?php echo $v['callback'] ?> ) {
2287 var e = <?php echo $v['document'] ?>.createElement( 'link' );
2288
2289 e.rel = 'stylesheet';
2290 e.type = 'text/css';
2291 e.href = <?php echo $v['url'] ?>;
2292 e.onload = <?php echo $v['callback'] ?>;
2293
2294 <?php echo $v['head'] ?>.appendChild( e );
2295 }
2296
2297 function <?php echo $v['load_prerequisites'] ?>( <?php echo $v['callback'] ?> ) {
2298 if ( <?php echo $v['prerequisites_loaded'] ?> ) {
2299 <?php echo $v['callback'] ?>();
2300 return;
2301 }
2302
2303 var t = 4,
2304 <?php echo $v['url'] ?> = <?php echo json_encode( FCA_EOI_PLUGIN_URL . '/assets/' ) ?>,
2305 <?php echo $v['vendor_url'] ?> = <?php echo $v['url'] ?> + 'vendor/',
2306 <?php echo $v['done'] ?> = function() {
2307 if ( ! --t ) {
2308 <?php echo $v['prerequisites_loaded'] ?> = <?php echo $v['true'] ?>;
2309 <?php echo $v['callback'] ?>();
2310 }
2311 };
2312
2313 <?php echo $v['load_style'] ?>( '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css', <?php echo $v['done'] ?> );
2314
2315
2316 <?php echo $v['load_style'] ?>( <?php echo $v['url'] ?> + 'style-new.css', <?php echo $v['done'] ?> );
2317
2318 <?php echo $v['load_script'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/tooltipster.bundle.min.js', <?php echo $v['done'] ?> );
2319 <?php echo $v['load_style'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/tooltipster.bundle.min.css', <?php echo $v['done'] ?> );
2320 <?php echo $v['load_style'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/tooltipster-borderless.min.css', <?php echo $v['done'] ?> );
2321
2322 <?php
2323
2324 $loadAnim = false;
2325 forEach ($lightbox_ids as $id) {
2326 $animation = get_post_meta( $id, 'fca_eoi_animation', true );
2327 if ($animation != '') {
2328 $loadAnim = true;
2329 break;
2330 }
2331 }
2332
2333 if ( $loadAnim ) {
2334
2335 echo $v['load_style'] . "(" . $v['vendor_url'] . "+ 'animate/animate.css'," . $v['done'] . ');'; } ?>
2336 }
2337
2338 <?php } ?>
2339
2340 function <?php echo $v['display_popup'] ?>( <?php echo $v['form_id'] ?> ) {
2341 var t = <?php echo $prerequisites_loaded ? 1 : 2 ?>,
2342 <?php echo $v['done'] ?> = function() {
2343 if ( ! --t ) {
2344 $.featherlight(
2345 $( '#fca_eoi_lightbox_' + <?php echo $v['form_id'] ?> ),
2346 <?php echo $this->get_featherlight_options() ?>
2347 );
2348
2349 <?php echo EasyOptInsActivity::get_instance()->get_tracking_code( $v['form_id'], false ) ?>
2350 }
2351 };
2352
2353 $.post( <?php echo $v['window.location.href'] ?>, {
2354 fca_eoi_prepare_lightbox: <?php echo $v['form_id'] ?>
2355 }, function( html ) {
2356 $( 'body' ).append( html );
2357 <?php echo $v['done'] ?>();
2358 } );
2359
2360 <?php if ( ! $prerequisites_loaded ) { ?>
2361 <?php echo $v['load_prerequisites'] ?>( <?php echo $v['done'] ?> );
2362 <?php } ?>
2363 }
2364
2365 <?php echo $v['TargetingCat_OptinCat'] ?>.StorageManagerSessionPermanent.get_instance().default_configuration = <?php echo json_encode( $this->get_cookie_configuration() ) ?>;
2366
2367 <?php echo json_encode( $lightbox_ids ) ?>.forEach( function( <?php echo $v['form_id'] ?> ) {
2368 $.post( <?php echo $v['window.location.href'] ?>, {
2369 <?php if ( is_single() || is_page() ) { ?>
2370 'fca_eoi_tc_condition_post_id': <?php echo get_the_ID() ?>,
2371 <?php } ?>
2372 'fca_eoi_tc_conditions_for': <?php echo $v['form_id'] ?>
2373 }, function( <?php echo $v['descriptors'] ?> ) {
2374 var <?php echo $v['evaluable'] ?> = <?php echo $v['TargetingCat_OptinCat'] ?>.ConditionManager.get_instance().parse_descriptors(
2375 typeof <?php echo $v['descriptors'] ?> === 'string'
2376 ? JSON.parse( <?php echo $v['descriptors'] ?> )
2377 : <?php echo $v['descriptors'] ?>
2378 );
2379 if ( <?php echo $v['evaluable'] ?> ) {
2380 <?php echo $v['evaluable'] ?>.set_pass_callback( function() {
2381 <?php echo $v['display_popup'] ?>( <?php echo $v['form_id'] ?> );
2382 } );
2383 <?php echo $v['evaluable'] ?>.evaluate();
2384 }
2385 } );
2386 } );
2387
2388 var lightbox_ids_Count = <?php echo count ($lightbox_ids) ?>;
2389 var currentLightBoxCount = 0;
2390 var totalAddedLightboxes = 0;
2391
2392 function waitUntilPopupsAreMade() {
2393
2394 if( totalAddedLightboxes < lightbox_ids_Count ) {
2395
2396 if (document.getElementsByClassName("fca_eoi_featherlight").length > currentLightBoxCount) {
2397
2398 totalAddedLightboxes++;
2399 currentLightBoxCount = document.getElementsByClassName("fca_eoi_featherlight").length;
2400 attachDeleteButtons();
2401 window.setTimeout(waitUntilPopupsAreMade, 200);
2402 }else {
2403
2404 currentLightBoxCount = document.getElementsByClassName("fca_eoi_featherlight").length;
2405 window.setTimeout(waitUntilPopupsAreMade, 200);
2406 }
2407
2408 } else {
2409
2410 attachDeleteButtons();
2411 }
2412 }
2413 if (lightbox_ids_Count > 1) {
2414 waitUntilPopupsAreMade();
2415 }
2416
2417 function attachDeleteButtons() {
2418 myNodes = document.getElementsByClassName("fca_eoi_layout_popup_close");
2419
2420 for (var i=0; i<myNodes.length; i++) {
2421 myNodes[i].onclick = function(e) {
2422 $(this).parents(".fca_eoi_featherlight").hide();
2423 };
2424
2425 }
2426 }
2427
2428
2429 } );
2430
2431 <?php
2432
2433 echo preg_replace(
2434 array( '/\s+/', '/([-+|\(\){}&=;,:?])\s+/', '/\s+([-+|\(\){}&=?])/', '/;}/' ),
2435 array( ' ', '$1', '$1', '}' ),
2436 trim( ob_get_clean() )
2437 );
2438
2439 ?>
2440 </script>
2441 <?php
2442
2443 return true;
2444 }
2445
2446 public function request_prepare_lightbox() {
2447 if (array_key_exists('fca_eoi_prepare_lightbox', $_POST)) {
2448 $lightbox_id = (int) $_POST['fca_eoi_prepare_lightbox'];
2449 if ( $lightbox_id > 0 ) {
2450 $this->prepare_lightbox( $lightbox_id );
2451 exit;
2452 }
2453 }
2454 }
2455
2456 public function prepare_lightbox( $id ) {
2457 $id = (int) $id;
2458
2459 global $post;
2460
2461 $animation = get_post_meta( $id, 'fca_eoi_animation', true );
2462 $animation_html_class = "animated $animation";
2463
2464 if ( empty ( $animation ) || $animation == 'None' ) {
2465 $animation_html_class = '';
2466 }
2467
2468
2469 $featherlight_class = 'fca_eoi_featherlight';
2470 $content = do_shortcode( "[easy-opt-in id=$id]" );
2471
2472 ?>
2473 <div style="display:none">
2474 <style>.<?php echo $featherlight_class ?>-content { background: transparent !important; }</style>
2475 <div class="<?php echo $animation_html_class ?>" id="fca_eoi_lightbox_<?php echo $id ?>"><?php echo $content ?></div>
2476 </div>
2477 <?php
2478 }
2479
2480 private function get_featherlight_options() {
2481
2482 $is_iphone = preg_match('/(?:iPhone|iPod);/i', $_SERVER['HTTP_USER_AGENT']);
2483 $is_ios = preg_match( '/(?:iPhone|iPad|iPod).* OS ([\d])_.* Safari/', $_SERVER['HTTP_USER_AGENT'], $matches );
2484
2485 if ( $is_ios ) {
2486 $ios_specific_options = ',
2487 beforeOpen: function() {
2488 var viewport = jQuery( "meta[name=viewport]" );
2489 if ( viewport.length == 0 ) {
2490 viewport = jQuery( "<meta name=\"viewport\" content=\"\"/>" );
2491 jQuery( "head" ).append( viewport );
2492 }
2493
2494 var viewport_content = viewport.attr( "content" );
2495 this.fca_eoi_viewport_content = viewport_content;
2496 viewport.attr( "content", "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" );
2497
2498 this.fca_eoi_orientation_change_listener = function() {
2499 window.scrollTo( 0, 0 );
2500 jQuery( ".fca_eoi_form input" ).each( function() {
2501 this.blur();
2502 } );
2503 };
2504 window.addEventListener( "orientationchange", this.fca_eoi_orientation_change_listener, false );
2505
2506 this.fca_eoi_touch_move_listener = function( event ) {
2507 event.preventDefault();
2508 };
2509 window.addEventListener( "touchmove", this.fca_eoi_touch_move_listener, false );
2510 },
2511 afterOpen: function() {
2512 this.$instance.find(".fca_eoi_form_input_element").first().focus();
2513 jQuery( "body" ).append( "<div class=\"fca_eoi_featherlight_pad\" style=\"display: block; height: 1000px;\"/>" );
2514 },
2515 beforeClose: function() {
2516 jQuery( ".fca_eoi_featherlight_pad" ).remove();
2517 },
2518 afterClose: function() {
2519 if ( this.hasOwnProperty( "fca_eoi_viewport_content" ) ) {
2520 jQuery( "meta[name=viewport]" ).attr( "content", this.fca_eoi_viewport_content );
2521 }
2522
2523 if ( this.hasOwnProperty( "fca_eoi_orientation_change_listener" ) ) {
2524 window.removeEventListener( "orientationchange", this.fca_eoi_orientation_change_listener );
2525 }
2526
2527 if ( this.hasOwnProperty( "fca_eoi_touch_move_listener" ) ) {
2528 window.removeEventListener( "touchmove", this.fca_eoi_touch_move_listener );
2529 }
2530 }';
2531 } else {
2532 $ios_specific_options = ',
2533 afterOpen: function() {
2534 this.$instance.find(".fca_eoi_form_input_element").first().focus();
2535 }';
2536 }
2537
2538 return '{
2539 namespace: "fca_eoi_featherlight",
2540 otherClose: ".fca_eoi_layout_popup_close"' . $ios_specific_options . ',
2541 variant: ' . ( $is_iphone ? '"fca_eoi_device_iphone"' : 'null' ) . '
2542 }';
2543 }
2544 }
2545
2546 function k_selector( $name, $selected_options = array(), $return = false ) {
2547
2548 global $post;
2549 // Dirty fix to restore the global $post
2550 $post_bak = $post;
2551
2552 // Get all post types except media
2553 $post_types = get_post_types( array( 'public' => true ) );
2554 unset( $post_types[ 'attachment' ] );
2555
2556 $ret = ob_start();
2557
2558 // Start ouput
2559 echo '<select data-placeholder="' . __( 'Type to search for posts, categories or pages.' ) . '" name = "' . $name . '[]" class="select2" multiple="multiple" style="width: 27em;">';
2560
2561 // Front page
2562 K::wrap( __( 'Front page' )
2563 , array(
2564 'value' => '~',
2565 'selected' => in_array( '~', $selected_options ),
2566 )
2567 , array( 'in' => 'option' )
2568 );
2569
2570 // All posts
2571 // K::wrap( __( 'All' )
2572 // , array(
2573 // 'value' => '*',
2574 // 'selected' => in_array( '*', $selected_options ),
2575 // )
2576 // , array( 'in' => 'option' )
2577 // );
2578
2579 foreach ($post_types as $post_type => $post_type_args ) {
2580
2581 $post_type_obj = get_post_type_object( $post_type );
2582 $post_type_name = $post_type_obj->labels->singular_name;
2583
2584 $options = array();
2585
2586 // Add taxonomy/terms options
2587 $taxonomies = get_object_taxonomies( $post_type );
2588 foreach ( $taxonomies as $taxonomy ) {
2589 $taxonomy_obj = get_taxonomy( $taxonomy );
2590 $taxonomy_name = $taxonomy_obj->labels->singular_name;
2591 $terms = get_categories("taxonomy=$taxonomy&type=$post_type");
2592 foreach ($terms as $term) {
2593 $options[ 'taxonomies' ][ "$post_type:$term->term_id" ] =
2594 $post_type_name
2595 . "$taxonomy_name"
2596 . "$term->name"
2597 ;
2598 }
2599 }
2600
2601 // Add posts options
2602 $the_query = new WP_Query( "post_type=$post_type&posts_per_page=-1" );
2603 if ( $the_query->have_posts() ) {
2604
2605 while ( $the_query->have_posts() ) {
2606 $the_query->the_post();
2607 $options[ 'posts' ][ '#' . get_the_ID() ] = $post_type_name
2608 . ' ' . __( '' ) . ' '
2609 . '#' . get_the_ID() . ' &ndash; '
2610 . ( get_the_title() ? get_the_title() : __('[Untitled]') )
2611 ;
2612 }
2613 }
2614
2615 // Dirty fix to restore the global $post
2616 $post = $post_bak;
2617
2618 // Posts > All
2619 echo '<optgroup label="' . $post_type_name . '">';
2620 printf(
2621 '<option value="%s" %s >%s</option>'
2622 , $post_type
2623 , ( in_array( $post_type, $selected_options ) ? 'selected' : '' )
2624 , $post_type_name . ' ' . ( '' ) . ' ' . __( 'All' )
2625 );
2626 echo '</optgroup>';
2627
2628 // Posts > Taoxonomies
2629 if ( ! empty( $options[ 'taxonomies' ] ) ) {
2630 printf(
2631 '<optgroup label="%s">'
2632 , $post_type_name . ' ' . __( '' ) . ' ' . __( 'Taxonomies' )
2633 );
2634 foreach ( $options[ 'taxonomies' ] as $k => $v ) {
2635 $selected = ( in_array( $k, $selected_options ) ) ? 'selected="selected"' : '';
2636 printf( '<option value="%s" %s >%s</option>', $k, $selected, $v );
2637 }
2638 echo '</optgroup>';
2639 }
2640
2641 // Posts > content
2642 if ( ! empty( $options[ 'posts' ] ) ) {
2643 printf( '<optgroup label="%s">'
2644 , $post_type_name . ' ' . __( '' ) . ' ' . __( 'Content' )
2645 );
2646 foreach ( $options[ 'posts' ] as $k => $v ) {
2647 $selected = ( in_array( $k, $selected_options ) ) ? 'selected="selected"' : '';
2648 printf( '<option value="%s" %s >%s</option>'
2649 , $k
2650 , $selected
2651 , $v
2652 );
2653 }
2654 echo '</optgroup>';
2655 }
2656 }
2657 echo '</select>';
2658
2659 $ret = ob_get_clean();
2660
2661 if ( $return ) {
2662 return $ret;
2663 } else {
2664 echo $ret;
2665 }
2666 }
2667
2668 function fca_eoi_comp( $a, $b, $op, $negate = false ) {
2669 switch ( $op ) {
2670 case 'eq': return $negate ? ( ! ( $a == $b ) ) : ( $a == $b );
2671 case 'gt': return $negate ? ( ! ( $a > $b ) ) : ( $a > $b );
2672 case 'gte': return $negate ? ( ! ( $a >= $b ) ) : ( $a >= $b );
2673 case 'lt': return $negate ? ( ! ( $a < $b ) ) : ( $a < $b );
2674 case 'lte': return $negate ? ( ! ( $a <= $b ) ) : ( $a <= $b );
2675 }
2676 }
2677