PluginProbe
GetResponse Forms by Optin Cat / 1.6.3
GetResponse Forms by Optin Cat v1.6.3
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.6.3, at includes/eoi-post-types.php

2,735 lines 87.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' );
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' );
242 wp_enqueue_script( 'nvd3_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/nv.d3.min.js' );
243 wp_enqueue_style( 'nvd3_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/nv.d3.min.css' );
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-bottom" 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-bottom" 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 $protocol = is_ssl() ? 'https' : 'http';
1515 $provider = $this->settings[ 'provider' ];
1516 $providers_available = array_keys( $this->settings[ 'providers' ] );
1517
1518 /**
1519 * Disable autosaving optin forms since it causes data loss
1520 */
1521 if ( 'easy-opt-ins' == get_post_type() ) {
1522 wp_dequeue_script( 'autosave' );
1523 }
1524
1525 if ( ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'eoi_powerups' ) || has_action( 'fca_eoi_powerups' ) ) {
1526 wp_enqueue_style( 'fca_eoi_powerups', FCA_EOI_PLUGIN_URL . '/assets/powerups/fca_eoi_powerups.css' );
1527 }
1528
1529 if ( ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'eoi_powerups' ) ) {
1530 wp_enqueue_script('fca_eoi_powerups_javascript', FCA_EOI_PLUGIN_URL . '/assets/powerups/fca_eoi_powerup.js');
1531 }
1532
1533
1534 $screen = get_current_screen();
1535 if( 'easy-opt-ins' === $screen->id ){
1536
1537 //LOAD DEPENDENCIES
1538 wp_enqueue_script( 'fca_eoi_tooltipster', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.js' );
1539 wp_enqueue_style( 'fca_eoi_tooltipster_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.css' );
1540 wp_enqueue_style( 'fca_eoi_tooltipster_theme_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster-borderless.min.css' );
1541
1542
1543 wp_enqueue_script( 'select2', $protocol . '://cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js' );
1544 wp_enqueue_style( 'font-awesome', $protocol . '://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css' );
1545 wp_enqueue_style( 'select2', $protocol . '://cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css' );
1546 wp_enqueue_script( 'accordion' );
1547
1548 if ( paf( 'eoi_powerup_animation' ) ) {
1549 wp_enqueue_style( 'fca_eoi_powerups_animate', FCA_EOI_PLUGIN_URL . '/assets/vendor/animate/animate.css' );
1550 }
1551
1552 //LOAD CUSTOM AJAX SPINNER CODE/CSS
1553 wp_enqueue_script( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.js' );
1554 wp_enqueue_style( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.css' );
1555
1556 //LOAD COMMON CSS
1557 wp_enqueue_style( 'fca_eoi', FCA_EOI_PLUGIN_URL .'/assets/style-new.css' );
1558
1559 //LOAD EDITOR JS
1560 wp_enqueue_script( 'fca-eoi-editor', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-editor.js' );
1561
1562 //LOAD PROVIDER JS AND CSS
1563 foreach ( $providers_available as $provider ) {
1564 wp_enqueue_script( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . '/providers/' . $provider . '/cpt-easy-opt-ins.js' );
1565
1566 $css_path = '/providers/' . $provider . '/cpt-easy-opt-ins.css';
1567 if ( is_readable( FCA_EOI_PLUGIN_URL . $css_path ) ) {
1568 wp_enqueue_style( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . $css_path );
1569 }
1570 }
1571 //SEND VARIABLES TO JS
1572 wp_localize_script( 'admin-cpt-easy-opt-ins-mailchimp', 'useGroups', paf( 'eoi_powerup_mp_groups' ) );
1573
1574 $file = plugin_dir_path( __FILE__ ) . "layout-cache";
1575 $layout_data = unserialize (file_get_contents($file));
1576
1577 wp_localize_script( 'fca-eoi-editor', 'layouts', $layout_data );
1578
1579 //EDITOR CSS
1580 wp_enqueue_style( 'admin-cpt-easy-opt-ins', FCA_EOI_PLUGIN_URL . '/assets/admin/cpt-easy-opt-ins.css' );
1581
1582 if ( has_action( 'fca_eoi_powerups' ) ) {
1583 wp_enqueue_script('fca_eoi_powerups', FCA_EOI_PLUGIN_URL . '/assets/powerups/fca_eoi_powerups.js');
1584 }
1585 }
1586 if( 'widgets' === $screen->id ){
1587 wp_enqueue_script( 'select2', $protocol . '://cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js' );
1588 wp_enqueue_style( 'select2', $protocol . '://cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css' );
1589 }
1590 }
1591
1592 /**
1593 * Hides minor publising form items (status, visibility and publication date)
1594 *
1595 * This function shoud be used along with force_published to prevent
1596 * saving posts as drafts
1597 */
1598 public function hide_minor_publishing() {
1599 $screen = get_current_screen();
1600 if( in_array( $screen->id, array( 'easy-opt-ins' ) ) ) {
1601 echo '<style>#minor-publishing { display: none; }</style>';
1602 }
1603 }
1604
1605 /**
1606 * Forces one column
1607 */
1608 public function force_one_column() {
1609
1610 return 1;
1611 }
1612
1613 /**
1614 * Sort metaboxes
1615 */
1616 public function order_columns( $order ) {
1617 return array(
1618 'normal' => join( ",", array(
1619 'submitdiv',
1620 'fca_eoi_meta_box_nav',
1621 'fca_eoi_meta_box_setup',
1622 'fca_eoi_meta_box_build',
1623 'fca_eoi_meta_box_provider',
1624 'fca_eoi_meta_box_thanks',
1625 'fca_eoi_meta_box_publish',
1626 'fca_eoi_meta_box_powerups',
1627 'fca_eoi_meta_box_debug',
1628 ) ),
1629 'side' => '',
1630 'advanced' => '',
1631 );
1632 }
1633
1634 /**
1635 * replacing the default "Enter title here" placeholder text in the title input box to
1636 *
1637 */
1638 public function change_default_title($title) {
1639
1640 $screen = get_current_screen();
1641
1642 if ( 'easy-opt-ins' == $screen->post_type ) {
1643 $title = 'Enter name here';
1644 }
1645
1646 return $title;
1647 }
1648
1649 /**
1650 * Override some strings to match our likings
1651 */
1652 public function override_text( $messages ) {
1653
1654 global $post;
1655
1656 $post_ID = $post->ID;
1657 $post_type = get_post_type( $post_ID );
1658
1659 $obj = get_post_type_object( $post_type );
1660 $singular = $obj->labels->singular_name;
1661
1662 if ( 'easy-opt-ins' === $post->post_type ) {
1663
1664 $messages[$post_type] = array(
1665 0 => '', // Unused. Messages start at index 1.
1666 1 => __( 'Opt-In Form updated.' ),
1667 2 => __( 'Opt-In Form updated.' ),
1668 3 => __( 'Opt-In Form deleted.' ),
1669 4 => __( 'Opt-In Form updated.' ),
1670 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,
1671 6 => __( 'Opt-In Form saved.' ),
1672 7 => sprintf( __( '%s saved.' ), esc_attr( $singular ) ),
1673 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 ) ),
1674 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 ) ),
1675 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 ) )
1676 );
1677
1678 }
1679
1680 return $messages;
1681
1682 }
1683
1684 public function force_published( $post ) {
1685
1686 if( ! in_array( $post[ 'post_status' ], array( 'auto-draft', 'trash') ) ) {
1687 if( in_array( $post[ 'post_type' ], array( 'easy-opt-ins' ) ) ) {
1688 $post['post_status'] = 'publish';
1689 }
1690 }
1691 return $post;
1692 }
1693
1694 /**
1695 * Disables bulk editing
1696 */
1697 public function disable_bulk_edit( $actions ){
1698 unset( $actions[ 'edit' ] );
1699 return $actions;
1700 }
1701
1702 /**
1703 * Removes quick edit
1704 */
1705 public function remove_quick_edit( $actions ) {
1706 global $post;
1707 if( 'easy-opt-ins' === $post->post_type ) {
1708 unset($actions['inline hide-if-no-js']);
1709 }
1710 return $actions;
1711 }
1712
1713 /**
1714 * Add the desired body classes (backend)
1715 */
1716 public function add_body_class( $classes ) {
1717 return "$classes fca_eoi";
1718 }
1719
1720 /**
1721 * Handle Adding a subscriber with Ajax
1722 */
1723 public function ajax_subscribe() {
1724
1725 $error = '';
1726 // Get meta
1727 $id = $_REQUEST['form_id'];
1728
1729 if (empty ($id)){
1730 $error .= "Couldn't find form ID";
1731 }
1732
1733 $fca_eoi = get_post_meta( $id, 'fca_eoi', true );
1734
1735 if (empty ($fca_eoi)){
1736 $error .= "Couldn't find post meta";
1737 }
1738
1739 $provider = K::get_var( 'provider' , $fca_eoi );
1740
1741 // Check a list_id is provided
1742 $list_id = K::get_var( $provider . '_list_id' , $fca_eoi );
1743 if ( empty( $list_id ) ) {
1744 $error .= "List not set";
1745 }
1746
1747 // @todo: remove
1748 // Hack for mailchimp upgrade
1749 if( empty( $fca_eoi[ 'provider' ] ) ) {
1750 $list_id = K::get_var(
1751 'mailchimp_list_id'
1752 , $fca_eoi
1753 , K::get_var( 'list_id' , $fca_eoi )
1754 );
1755 $provider = 'mailchimp';
1756 }
1757 // End of Hack
1758
1759 // Hack for campaignmonitor upgrade
1760 if( strlen( K::get_var( 'list_id' , $fca_eoi ) ) == 32){
1761 $list_id = K::get_var(
1762 'campaignmonitor_list_id'
1763 , $fca_eoi
1764 , K::get_var( 'list_id' , $fca_eoi )
1765 );
1766 $provider = 'campaignmonitor';
1767 }
1768 // End of Hack
1769
1770 // Hack for drip
1771 if ( $provider == 'drip' ) {
1772 $_POST['drip_api_token'] = $fca_eoi['drip_api_token'];
1773 $_POST['drip_account_id'] = $fca_eoi['drip_account_id'];
1774 $_POST['drip_action'] = $fca_eoi['drip_action'];
1775 $_POST['drip_list_id'] = $fca_eoi['drip_list_id'];
1776 }
1777
1778 // Hack for mailchimp upgrade
1779 if( empty( $fca_eoi[ 'provider' ] ) ) {
1780 $list_id = K::get_var(
1781 'getresponse_list_id'
1782 , $fca_eoi
1783 , K::get_var( 'list_id' , $fca_eoi )
1784 );
1785 $provider = 'getresponse';
1786 }
1787 // End of Hack
1788
1789 // Hack for custom form upgrade
1790 if( empty( $fca_eoi[ 'provider' ] ) ) {
1791 $list_id = K::get_var(
1792 'customform_list_id'
1793 , $fca_eoi
1794 , K::get_var( 'list_id' , $fca_eoi )
1795 );
1796 $provider = 'customform';
1797 }
1798 if ( $provider == 'customform' ) {
1799 $_POST['customform_request'] = $fca_eoi['customform_request'];
1800 }
1801
1802 // End of Hack
1803
1804 $nonce = $_REQUEST['nonce'];
1805 $nonceVerified = wp_verify_nonce( $nonce, 'fca_eoi_submit_form' );
1806 if ($nonceVerified === FALSE) {
1807 $error .= "Couldn't verify form submission";
1808 }
1809
1810 // Subscribe user
1811 $status = false;
1812
1813 if( $list_id && $nonceVerified !== FALSE ) {
1814 $status = call_user_func( $provider . '_add_user' , $this->settings , $_POST , $list_id );
1815
1816 do_action('fca_eoi_after_submission', $fca_eoi, $_POST );
1817
1818 if ($status !== TRUE) {
1819 $error .= " Can't add user";
1820 }
1821 }
1822
1823 if ( $status !== FALSE && $error === '' ) {
1824 echo '';
1825 EasyOptInsActivity::get_instance()->add_conversion( $id );
1826 } else {
1827 echo '' . " Error: " . $error;
1828 }
1829
1830 exit;
1831 }
1832
1833 public function admin_notices() {
1834
1835 //RN NOTE: MAYBE REWRITE
1836 $current_screen = get_current_screen();
1837
1838 // Exit function if we are not on the opt-in editing page
1839 if ( ! (
1840 'easy-opt-ins' === $current_screen->id
1841 && 'post' === $current_screen->base
1842 && 'edit' === $current_screen->parent_base
1843 && '' === $current_screen->action
1844 ) ) {
1845 return;
1846 }
1847
1848 global $post;
1849 $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true );
1850 $provider = K::get_var( 'provider', $fca_eoi);
1851 $errors = array();
1852
1853 // Add error for missing thank you page
1854 $confirmation_page_set = ( bool ) K::get_var( 'thank_you_page', $fca_eoi);
1855 if( ! $confirmation_page_set ) {
1856 $errors[] = __( 'No "Thank you" page selected. You will not be able to use this form.' );
1857 }
1858
1859 // Add error for missing list setting for the current provider
1860 $list_set = ( bool ) K::get_var( $provider . '_list_id', $fca_eoi);
1861
1862 // @todo: remove
1863 // Hack for mailchimp upgrade
1864 if( empty( $fca_eoi[ 'provider' ] ) ) {
1865 $fca_eoi[ 'mailchimp_list_id' ] = K::get_var(
1866 'mailchimp_list_id'
1867 , $fca_eoi
1868 , K::get_var( 'list_id' , $fca_eoi )
1869 );
1870 $list_set = ( bool ) K::get_var( 'mailchimp_list_id', $fca_eoi);
1871 }
1872 // End of Hack
1873
1874
1875 if( ! $list_set ) {
1876 $errors[] = __( 'No List selected. You will not be able to use this form.' );
1877 }
1878
1879 $errors = apply_filters( 'fca_eoi_alter_admin_notices', $errors );
1880
1881 foreach ( $errors as $error ) {
1882 echo '<div class="error"><p>' . $error . '</p></div>';
1883 }
1884 }
1885
1886 public function bind_content_filter() {
1887
1888 // Do nothing in backend
1889 if ( is_admin() ) {
1890 return;
1891 }
1892
1893 add_action( 'wp', array( $this, 'content' ), 10 );
1894 }
1895
1896 public function content() {
1897 //RN NOTE WAT
1898 global $post;
1899
1900 if ( empty( $post ) ) {
1901 return;
1902 }
1903
1904 // Do nothing if viewing an opt-in
1905 if ( 'easy-opt-ins' === $post->post_type ) {
1906 return;
1907 }
1908
1909 // Work only when viewing a post of any type
1910 if ( empty( $post ) ) {
1911 return;
1912 }
1913
1914 $priorities = array();
1915
1916 // Post details
1917 $post_ID = $post->ID;
1918 $post_type = get_post_type( $post_ID );
1919
1920 // Build the array for testing
1921 $post_cond = array(
1922 '*',
1923 $post_type,
1924 '#' . $post_ID,
1925 );
1926 if ( is_front_page() ) {
1927 $post_cond[] = '~';
1928 }
1929
1930 $priorities[] = '#' . $post_ID;
1931
1932 $taxonomies = get_taxonomies('','names');
1933 $post_taxonomies = wp_get_object_terms( $post->ID,$taxonomies);
1934 foreach ( $post_taxonomies as $t ) {
1935 $condition = $post_type . ':' . $t->term_id;
1936
1937 $post_cond[] = $condition;
1938 $priorities[] = $condition;
1939 }
1940
1941 $priorities[] = $post_type;
1942 $priorities[] = '*';
1943
1944 $fca_eoi_last_99_forms = array();
1945 foreach (get_posts( 'posts_per_page=99&post_type=easy-opt-ins' ) as $i => $f ) {
1946 $fca_eoi_last_99_forms[ $i ][ 'post' ] = $f;
1947 $fca_eoi_last_99_forms[ $i ][ 'fca_eoi' ] = get_post_meta( $f->ID, 'fca_eoi', true );
1948 }
1949 // wp_reset_query();
1950
1951 $postboxes = array();
1952
1953 // Append postcode shortcode when the conditions match
1954 foreach( $fca_eoi_last_99_forms as $f) {
1955
1956 // Exclude other layout types
1957 if ( empty ( $f[ 'fca_eoi' ][ 'layout' ] ) ) {
1958 continue;
1959 }
1960 if ( strpos( $f[ 'fca_eoi' ][ 'layout' ], 'postbox_' ) !== 0 ) {
1961 continue;
1962 }
1963
1964 // Get conditions
1965 $eoi_form_cond = K::get_var( 'publish_postbox', $f[ 'fca_eoi' ], array() );
1966
1967 // Append
1968 if ( array_intersect( $eoi_form_cond, $post_cond ) ) {
1969 foreach ( $eoi_form_cond as $cond ) {
1970 if ( empty( $postboxes[ $cond ] ) ) {
1971 $postboxes[ $cond ] = sprintf( '[%s id=%d]', $this->settings['shortcode'], $f['post']->ID );
1972 }
1973 }
1974 }
1975 }
1976
1977 if ( ! empty( $postboxes ) ) {
1978 foreach ( $priorities as $cond ) {
1979 if ( ! empty( $postboxes[ $cond ] ) ) {
1980 $post->post_content .= $postboxes[ $cond ];
1981 return;
1982 }
1983 }
1984
1985 $post->post_content .= reset( $postboxes );
1986 return;
1987 }
1988 }
1989
1990 private function get_tc_token( $form_id ) {
1991 return "$form_id";
1992 }
1993
1994 private function to_call_tc_condition( $name, $arguments ) {
1995 return array_merge( array( $name ), $arguments );
1996 }
1997
1998 private function to_value_tc_condition( $form_id, $name, $eoi_condition ) {
1999 $value = intval( $eoi_condition['value'] );
2000 $params = array( $value );
2001
2002 if ( $name === 'page_views' ) {
2003 $params[] = $this->get_tc_token( $form_id );
2004 } else if ( $name === 'time_on_page' ) {
2005 $params[0] *= 1000;
2006 }
2007
2008 return $this->to_call_tc_condition( $name, $params );
2009 }
2010
2011 private function to_server_pass_tc_condition( $post_id, $parameter, $eoi_condition ) {
2012 $url = add_query_arg( array(
2013 'fca_eoi_tc_condition_pass' => urlencode( $parameter ),
2014 'fca_eoi_tc_condition_value' => urlencode( implode( ',', $eoi_condition['value'] ) ),
2015 'fca_eoi_tc_condition_post_id' => $post_id
2016 ) );
2017
2018 return $this->to_call_tc_condition( 'server_pass', array( $url, 'true' ) );
2019 }
2020
2021 private function to_tc_condition( $form_id, $post_id, $eoi_condition ) {
2022 $eoi_to_tc_value_map = array(
2023 'pageviews' => 'page_views',
2024 'scrolled_percent' => 'scroll_percent',
2025 'time_on_page' => 'time_on_page'
2026 );
2027
2028 $eoi_server_pass_conditions = array( 'include', 'exclude' );
2029
2030 $parameter = $eoi_condition['parameter'];
2031 if ( array_key_exists( $parameter, $eoi_to_tc_value_map ) ) {
2032 return $this->to_value_tc_condition( $form_id, $eoi_to_tc_value_map[ $parameter ], $eoi_condition );
2033 } else if ( in_array( $parameter, $eoi_server_pass_conditions ) ) {
2034 return $this->to_server_pass_tc_condition( $post_id, $parameter, $eoi_condition );
2035 }
2036
2037 return null;
2038 }
2039
2040 private function to_show_every_tc_condition( $form_id, $condition ) {
2041 if ( in_array( $condition, array( 'day', 'month', 'once', 'session' ) ) ) {
2042 return array( $condition, $this->get_tc_token( $form_id ) );
2043 } elseif ( $condition === 'always' ) {
2044 return 'true';
2045 } elseif ( $condition === 'never' ) {
2046 return 'false';
2047 }
2048
2049 return $condition;
2050 }
2051
2052 private function get_tc_conditions( $form_id, $post_id, $conditions ) {
2053 $tc_conditions = array();
2054 $sequence_conditions = array();
2055
2056 if ( ! empty( $conditions['show_every'] ) ) {
2057 $condition = $this->to_show_every_tc_condition( $form_id, $conditions['show_every'] );
2058
2059 if ( $condition === 'false' ) {
2060 return array( 'false' );
2061 } else {
2062 $sequence_conditions[] = $condition;
2063 }
2064 }
2065
2066 if ( ! empty( $conditions['conditions'] ) ) {
2067 foreach ( $conditions['conditions'] as $condition ) {
2068 if ( $condition['parameter'] === 'exit_intervention' ) {
2069 $sequence_conditions[] = 'exit';
2070 continue;
2071 }
2072
2073 $tc_condition = $this->to_tc_condition( $form_id, $post_id, $condition );
2074 if ( ! empty( $tc_condition ) ) {
2075 $tc_conditions[] = $tc_condition;
2076 }
2077 }
2078 }
2079
2080 $has_conditions = ! empty ( $tc_conditions );
2081 if ( $has_conditions ) {
2082 $tc_conditions = array( 'and' => $tc_conditions );
2083 }
2084
2085 if ( $sequence_conditions ) {
2086 if ( $has_conditions ) {
2087 $tc_conditions = array( 'sequence' => array( $tc_conditions ) );
2088 } else {
2089 $tc_conditions = array( 'sequence' => array() );
2090 }
2091 foreach ( $sequence_conditions as $condition ) {
2092 $tc_conditions['sequence'][] = $condition;
2093 }
2094 }
2095
2096 return $tc_conditions;
2097 }
2098
2099 private function echo_tc_conditions_for_form( $form_id, $post_id ) {
2100 $fca_eoi = get_post_meta( $form_id , 'fca_eoi', true );
2101 $publish_lightbox = K::get_var( 'publish_lightbox', $fca_eoi, array() );
2102
2103 header( 'Content-Type: application/json' );
2104 exit( json_encode( $this->get_tc_conditions( $form_id, $post_id, $publish_lightbox ) ) );
2105 }
2106
2107 private function echo_tc_condition_pass( $post_id, $type, $values ) {
2108 $post_cond = array( '*' );
2109
2110 if ( is_front_page() ) {
2111 $post_cond[] = '~';
2112 }
2113
2114 if ( $post_id ) {
2115 $post_type = get_post_type( $post_id );
2116
2117 $post_cond[] = $post_type;
2118 $post_cond[] = '#' . $post_id;
2119
2120 $taxonomies = get_taxonomies( '', 'names' );
2121 $post_taxonomies = wp_get_object_terms( $post_id, $taxonomies );
2122
2123 foreach ( $post_taxonomies as $t ) {
2124 $post_cond[] = $post_type . ':' . $t->term_id;
2125 }
2126 } else {
2127 //FIX FOR NOT DISPLAYING ON BLOG PAGE
2128
2129 if ( is_home() ) {
2130 $post_cond[] = '#' . get_option('page_for_posts');
2131 }
2132
2133 }
2134
2135 $intersect = array_intersect( $values, $post_cond );
2136
2137 if ( $type === 'include' ) {
2138 echo $intersect ? 'true' : 'false';
2139 } else if ( $type === 'exclude' ) {
2140 echo $intersect ? 'false' : 'true';
2141 }
2142
2143 exit;
2144 }
2145
2146 public function parse_tc_condition_request() {
2147 $post_id = empty( $_REQUEST['fca_eoi_tc_condition_post_id'] ) ? 0 : (int) $_REQUEST['fca_eoi_tc_condition_post_id'];
2148
2149 if ( ! empty( $_REQUEST['fca_eoi_tc_conditions_for'] ) ) {
2150 $form_id = (int) $_REQUEST['fca_eoi_tc_conditions_for'];
2151 $this->echo_tc_conditions_for_form( $form_id, $post_id );
2152 }
2153
2154 if ( ! empty( $_REQUEST['fca_eoi_tc_condition_pass'] ) ) {
2155 $this->echo_tc_condition_pass(
2156 $post_id,
2157 $_REQUEST['fca_eoi_tc_condition_pass'],
2158 explode( ',', $_REQUEST['fca_eoi_tc_condition_value'] )
2159 );
2160 }
2161 }
2162
2163 private function get_cookie_configuration() {
2164 $cookie_configuration = array();
2165
2166 if ( defined( 'COOKIEPATH' ) ) {
2167 $path = COOKIEPATH;
2168 if ( ! empty( $path ) ) {
2169 $cookie_configuration['path'] = $path;
2170 }
2171 }
2172
2173 if ( defined( 'COOKIE_DOMAIN' ) ) {
2174 $domain = COOKIE_DOMAIN;
2175 if ( ! empty( $domain ) ) {
2176 $cookie_configuration['domain'] = $domain;
2177 }
2178 }
2179
2180 return $cookie_configuration;
2181 }
2182
2183 public function scan_for_shortcodes( $content ) {
2184 if ( preg_match_all( '/data-optin-cat\s*=\s*["\']?\s*(\d+)/', $content, $matches ) ) {
2185 $this->two_step_ids_on_page = array_map( 'intval', $matches[1] );
2186 }
2187
2188 return $content;
2189 }
2190
2191 public function show_lightbox() {
2192
2193 // Do not show lightbox on mobile if this is the free distribution
2194 if ( $this->settings[ 'distribution' ] === 'free' ) {
2195 $mobile_detect = new Mobile_Detect;
2196 if ( $mobile_detect->isMobile() ) {
2197 return;
2198 }
2199 }
2200
2201 // Get lightboxes
2202 $lightboxes = get_posts( array(
2203 'post_type' => 'easy-opt-ins',
2204 'posts_per_page' => -1,
2205 'orderby' => 'ID',
2206 'meta_key' => 'fca_eoi_layout',
2207 'meta_value' => 'lightbox_',
2208 'meta_compare' => 'like',
2209 ) );
2210
2211 // Exit function if no lightbox found
2212 if( ! $lightboxes ) {
2213 return;
2214 }
2215
2216 $two_step_ids = array();
2217 $traditional_ids = array();
2218
2219 foreach ( $lightboxes as $lightbox ) {
2220
2221 // Get conditions
2222 $lightbox->fca_eoi = get_post_meta( $lightbox->ID , 'fca_eoi', true );
2223 $publish_lightbox_mode = K::get_var( 'publish_lightbox_mode', $lightbox->fca_eoi, array() );
2224
2225 // If on a free distribution, force traditional popup mode
2226 if ( 'free' === $this->settings['distribution'] ) {
2227 $publish_lightbox_mode = 'traditional_popup';
2228 }
2229
2230 if ( 'two_step_optin' === $publish_lightbox_mode ) {
2231 $two_step_ids[] = $lightbox->ID;
2232 } else {
2233 $traditional_ids[] = $lightbox->ID;
2234 }
2235 }
2236
2237 $this->display_traditional_popups($traditional_ids, $this->display_two_step_popups($two_step_ids));
2238 }
2239
2240 private function display_two_step_popups($lightbox_ids) {
2241 $lightbox_ids = array_intersect( $lightbox_ids, $this->two_step_ids_on_page );
2242
2243 if ( empty( $lightbox_ids ) ) {
2244 return false;
2245 }
2246 do_action( 'fca_eoi_display_lightbox' );
2247
2248 foreach ( $lightbox_ids as $lightbox_id ) {
2249 $this->prepare_lightbox( $lightbox_id );
2250 }
2251
2252 ?>
2253 <script>
2254 jQuery( function() {
2255 jQuery( document ).on( 'click', '[data-optin-cat]', function( e ) {
2256 var lightbox_id = jQuery( this ).data( 'optin-cat' );
2257 <?php echo EasyOptInsActivity::get_instance()->get_tracking_code( 'lightbox_id', false ) ?>
2258 jQuery.featherlight( jQuery( '#fca_eoi_lightbox_' + lightbox_id ), <?php echo $this->get_featherlight_options() ?> );
2259 e.preventDefault();
2260 } );
2261 } );
2262 </script>
2263 <?php
2264
2265 return true;
2266 }
2267
2268 private function display_traditional_popups( $lightbox_ids, $prerequisites_loaded = false ) {
2269 if ( empty( $lightbox_ids ) ) {
2270 return false;
2271 }
2272
2273 wp_enqueue_script( 'fca_eoi_script_js', FCA_EOI_PLUGIN_URL.'/assets/script.js' );
2274 //PASS VARIABLES TO JAVASCRIPT
2275 $data = array (
2276 'ajax_url' => admin_url( 'admin-ajax.php' ),
2277 'nonce' => wp_create_nonce( 'fca_eoi_submit_form' ),
2278 );
2279
2280 wp_localize_script( 'fca_eoi_script_js', 'fca_eoi', $data );
2281 wp_enqueue_script( 'fca_eoi_featherlight_js', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.js' );
2282 wp_enqueue_style( 'fca_eoi_featherlight_css', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.css' );
2283
2284 ?>
2285 <script type="text/javascript" src="<?php echo FCA_EOI_PLUGIN_URL . '/' . $this->targeting_cat_path ?>"></script>
2286 <script>
2287 (function() {
2288 if ( typeof fca_eoi === "undefined" ) {
2289 fca_eoi = {};
2290 }
2291
2292 fca_eoi.ajax_url = <?php echo json_encode( admin_url( 'admin-ajax.php' ) ) ?>;
2293 })();
2294
2295 <?php $v = array(
2296 'prerequisites_loaded' => 'p',
2297 'load_prerequisites' => 'l',
2298 'head' => 'h',
2299 'load_script' => 'c',
2300 'load_style' => 'y',
2301 'callback' => 'k',
2302 'vendor_url' => 'v',
2303 'done' => 'n',
2304 'document' => 'd',
2305 'window.location.href' => 'w',
2306 'display_popup' => 's',
2307 'false' => '!1',
2308 'true' => '1',
2309 'evaluable' => 'e',
2310 'descriptors' => 'r',
2311 'form_id' => 'm',
2312 'TargetingCat_OptinCat' => 'g',
2313 'url' => 'u'
2314 ); ?>
2315
2316 <?php ob_start(); ?>
2317
2318 jQuery( function( $ ) {
2319 var
2320 <?php echo $v['document'] ?> = document,
2321 <?php echo $v['window.location.href'] ?> = window.location.href,
2322 <?php echo $v['TargetingCat_OptinCat'] ?> = TargetingCat_OptinCat;
2323
2324 <?php if ( ! $prerequisites_loaded ) { ?>
2325
2326 var
2327 <?php echo $v['prerequisites_loaded'] ?> = <?php echo $v['false'] ?>,
2328 <?php echo $v['head'] ?> = <?php echo $v['document'] ?>.head;
2329
2330 function <?php echo $v['load_script'] ?>( <?php echo $v['url'] ?>, <?php echo $v['callback'] ?> ) {
2331 var e = <?php echo $v['document'] ?>.createElement( 'script' );
2332
2333 e.type = 'text/javascript';
2334 e.src = <?php echo $v['url'] ?>;
2335 e.onload = <?php echo $v['callback'] ?>;
2336
2337 <?php echo $v['head'] ?>.appendChild( e );
2338 }
2339
2340 function <?php echo $v['load_style'] ?>( <?php echo $v['url'] ?>, <?php echo $v['callback'] ?> ) {
2341 var e = <?php echo $v['document'] ?>.createElement( 'link' );
2342
2343 e.rel = 'stylesheet';
2344 e.type = 'text/css';
2345 e.href = <?php echo $v['url'] ?>;
2346 e.onload = <?php echo $v['callback'] ?>;
2347
2348 <?php echo $v['head'] ?>.appendChild( e );
2349 }
2350
2351 function <?php echo $v['load_prerequisites'] ?>( <?php echo $v['callback'] ?> ) {
2352 if ( <?php echo $v['prerequisites_loaded'] ?> ) {
2353 <?php echo $v['callback'] ?>();
2354 return;
2355 }
2356
2357 var t = 4,
2358 <?php echo $v['url'] ?> = <?php echo json_encode( FCA_EOI_PLUGIN_URL . '/assets/' ) ?>,
2359 <?php echo $v['vendor_url'] ?> = <?php echo $v['url'] ?> + 'vendor/',
2360 <?php echo $v['done'] ?> = function() {
2361 if ( ! --t ) {
2362 <?php echo $v['prerequisites_loaded'] ?> = <?php echo $v['true'] ?>;
2363 <?php echo $v['callback'] ?>();
2364 }
2365 };
2366
2367 <?php echo $v['load_style'] ?>( '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css', <?php echo $v['done'] ?> );
2368
2369
2370 <?php echo $v['load_style'] ?>( <?php echo $v['url'] ?> + 'style-new.css', <?php echo $v['done'] ?> );
2371
2372 <?php echo $v['load_script'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/tooltipster.bundle.min.js', <?php echo $v['done'] ?> );
2373 <?php echo $v['load_style'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/tooltipster.bundle.min.css', <?php echo $v['done'] ?> );
2374 <?php echo $v['load_style'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/tooltipster-borderless.min.css', <?php echo $v['done'] ?> );
2375
2376 <?php
2377
2378 $loadAnim = false;
2379 forEach ($lightbox_ids as $id) {
2380 $animation = get_post_meta( $id, 'fca_eoi_animation', true );
2381 if ($animation != '') {
2382 $loadAnim = true;
2383 break;
2384 }
2385 }
2386 global $fca_eoi_animation_enabled;
2387 if (!$fca_eoi_animation_enabled) {
2388 $loadAnim = false;
2389 }
2390
2391 if ( $loadAnim ) {
2392
2393 echo $v['load_style'] . "(" . $v['vendor_url'] . "+ 'animate/animate.css'," . $v['done'] . ');'; } ?>
2394 }
2395
2396 <?php } ?>
2397
2398 function <?php echo $v['display_popup'] ?>( <?php echo $v['form_id'] ?> ) {
2399 var t = <?php echo $prerequisites_loaded ? 1 : 2 ?>,
2400 <?php echo $v['done'] ?> = function() {
2401 if ( ! --t ) {
2402 $.featherlight(
2403 $( '#fca_eoi_lightbox_' + <?php echo $v['form_id'] ?> ),
2404 <?php echo $this->get_featherlight_options() ?>
2405 );
2406
2407 <?php echo EasyOptInsActivity::get_instance()->get_tracking_code( $v['form_id'], false ) ?>
2408 }
2409 };
2410
2411 $.post( <?php echo $v['window.location.href'] ?>, {
2412 fca_eoi_prepare_lightbox: <?php echo $v['form_id'] ?>
2413 }, function( html ) {
2414 $( 'body' ).append( html );
2415 <?php echo $v['done'] ?>();
2416 } );
2417
2418 <?php if ( ! $prerequisites_loaded ) { ?>
2419 <?php echo $v['load_prerequisites'] ?>( <?php echo $v['done'] ?> );
2420 <?php } ?>
2421 }
2422
2423 <?php echo $v['TargetingCat_OptinCat'] ?>.StorageManagerSessionPermanent.get_instance().default_configuration = <?php echo json_encode( $this->get_cookie_configuration() ) ?>;
2424
2425 <?php echo json_encode( $lightbox_ids ) ?>.forEach( function( <?php echo $v['form_id'] ?> ) {
2426 $.post( <?php echo $v['window.location.href'] ?>, {
2427 <?php if ( is_single() || is_page() ) { ?>
2428 'fca_eoi_tc_condition_post_id': <?php echo get_the_ID() ?>,
2429 <?php } ?>
2430 'fca_eoi_tc_conditions_for': <?php echo $v['form_id'] ?>
2431 }, function( <?php echo $v['descriptors'] ?> ) {
2432 var <?php echo $v['evaluable'] ?> = <?php echo $v['TargetingCat_OptinCat'] ?>.ConditionManager.get_instance().parse_descriptors(
2433 typeof <?php echo $v['descriptors'] ?> === 'string'
2434 ? JSON.parse( <?php echo $v['descriptors'] ?> )
2435 : <?php echo $v['descriptors'] ?>
2436 );
2437 if ( <?php echo $v['evaluable'] ?> ) {
2438 <?php echo $v['evaluable'] ?>.set_pass_callback( function() {
2439 <?php echo $v['display_popup'] ?>( <?php echo $v['form_id'] ?> );
2440 } );
2441 <?php echo $v['evaluable'] ?>.evaluate();
2442 }
2443 } );
2444 } );
2445
2446 var lightbox_ids_Count = <?php echo count ($lightbox_ids) ?>;
2447 var currentLightBoxCount = 0;
2448 var totalAddedLightboxes = 0;
2449
2450 function waitUntilPopupsAreMade() {
2451
2452 if( totalAddedLightboxes < lightbox_ids_Count ) {
2453
2454 if (document.getElementsByClassName("fca_eoi_featherlight").length > currentLightBoxCount) {
2455
2456 totalAddedLightboxes++;
2457 currentLightBoxCount = document.getElementsByClassName("fca_eoi_featherlight").length;
2458 attachDeleteButtons();
2459 window.setTimeout(waitUntilPopupsAreMade, 200);
2460 }else {
2461
2462 currentLightBoxCount = document.getElementsByClassName("fca_eoi_featherlight").length;
2463 window.setTimeout(waitUntilPopupsAreMade, 200);
2464 }
2465
2466 } else {
2467
2468 attachDeleteButtons();
2469 }
2470 }
2471 if (lightbox_ids_Count > 1) {
2472 waitUntilPopupsAreMade();
2473 }
2474
2475 function attachDeleteButtons() {
2476 myNodes = document.getElementsByClassName("fca_eoi_layout_popup_close");
2477
2478 for (var i=0; i<myNodes.length; i++) {
2479 myNodes[i].onclick = function(e) {
2480 $(this).parents(".fca_eoi_featherlight").hide();
2481 };
2482
2483 }
2484 }
2485
2486
2487 } );
2488
2489 <?php
2490
2491 echo preg_replace(
2492 array( '/\s+/', '/([-+|\(\){}&=;,:?])\s+/', '/\s+([-+|\(\){}&=?])/', '/;}/' ),
2493 array( ' ', '$1', '$1', '}' ),
2494 trim( ob_get_clean() )
2495 );
2496
2497 ?>
2498 </script>
2499 <?php
2500
2501 return true;
2502 }
2503
2504 public function request_prepare_lightbox() {
2505 if (array_key_exists('fca_eoi_prepare_lightbox', $_POST)) {
2506 $lightbox_id = (int) $_POST['fca_eoi_prepare_lightbox'];
2507 if ( $lightbox_id > 0 ) {
2508 $this->prepare_lightbox( $lightbox_id );
2509 exit;
2510 }
2511 }
2512 }
2513
2514 public function prepare_lightbox( $id ) {
2515 $id = (int) $id;
2516
2517 global $post;
2518
2519 $animation = get_post_meta( $id, 'fca_eoi_animation', true );
2520 $animation_html_class = "animated $animation";
2521
2522 if ( empty ( $animation ) || $animation == 'None' ) {
2523 $animation_html_class = '';
2524 }
2525
2526
2527 $featherlight_class = 'fca_eoi_featherlight';
2528 $content = do_shortcode( "[easy-opt-in id=$id]" );
2529
2530 ?>
2531 <div style="display:none">
2532 <style>.<?php echo $featherlight_class ?>-content { background: transparent !important; }</style>
2533 <div class="<?php echo $animation_html_class ?>" id="fca_eoi_lightbox_<?php echo $id ?>"><?php echo $content ?></div>
2534 </div>
2535 <?php
2536 }
2537
2538 private function get_featherlight_options() {
2539
2540 $is_iphone = preg_match('/(?:iPhone|iPod);/i', $_SERVER['HTTP_USER_AGENT']);
2541 $is_ios = preg_match( '/(?:iPhone|iPad|iPod).* OS ([\d])_.* Safari/', $_SERVER['HTTP_USER_AGENT'], $matches );
2542
2543 if ( $is_ios ) {
2544 $ios_specific_options = ',
2545 beforeOpen: function() {
2546 var viewport = jQuery( "meta[name=viewport]" );
2547 if ( viewport.length == 0 ) {
2548 viewport = jQuery( "<meta name=\"viewport\" content=\"\"/>" );
2549 jQuery( "head" ).append( viewport );
2550 }
2551
2552 var viewport_content = viewport.attr( "content" );
2553 this.fca_eoi_viewport_content = viewport_content;
2554 viewport.attr( "content", "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" );
2555
2556 this.fca_eoi_orientation_change_listener = function() {
2557 window.scrollTo( 0, 0 );
2558 jQuery( ".fca_eoi_form input" ).each( function() {
2559 this.blur();
2560 } );
2561 };
2562 window.addEventListener( "orientationchange", this.fca_eoi_orientation_change_listener, false );
2563
2564 this.fca_eoi_touch_move_listener = function( event ) {
2565 event.preventDefault();
2566 };
2567 window.addEventListener( "touchmove", this.fca_eoi_touch_move_listener, false );
2568 },
2569 afterOpen: function() {
2570 this.$instance.find(".fca_eoi_form_input_element").first().focus();
2571 jQuery( "body" ).append( "<div class=\"fca_eoi_featherlight_pad\" style=\"display: block; height: 1000px;\"/>" );
2572 },
2573 beforeClose: function() {
2574 jQuery( ".fca_eoi_featherlight_pad" ).remove();
2575 },
2576 afterClose: function() {
2577 if ( this.hasOwnProperty( "fca_eoi_viewport_content" ) ) {
2578 jQuery( "meta[name=viewport]" ).attr( "content", this.fca_eoi_viewport_content );
2579 }
2580
2581 if ( this.hasOwnProperty( "fca_eoi_orientation_change_listener" ) ) {
2582 window.removeEventListener( "orientationchange", this.fca_eoi_orientation_change_listener );
2583 }
2584
2585 if ( this.hasOwnProperty( "fca_eoi_touch_move_listener" ) ) {
2586 window.removeEventListener( "touchmove", this.fca_eoi_touch_move_listener );
2587 }
2588 }';
2589 } else {
2590 $ios_specific_options = ',
2591 afterOpen: function() {
2592 this.$instance.find(".fca_eoi_form_input_element").first().focus();
2593 }';
2594 }
2595
2596 return '{
2597 namespace: "fca_eoi_featherlight",
2598 otherClose: ".fca_eoi_layout_popup_close"' . $ios_specific_options . ',
2599 variant: ' . ( $is_iphone ? '"fca_eoi_device_iphone"' : 'null' ) . '
2600 }';
2601 }
2602 }
2603
2604 function k_selector( $name, $selected_options = array(), $return = false ) {
2605
2606 global $post;
2607 // Dirty fix to restore the global $post
2608 $post_bak = $post;
2609
2610 // Get all post types except media
2611 $post_types = get_post_types( array( 'public' => true ) );
2612 unset( $post_types[ 'attachment' ] );
2613
2614 $ret = ob_start();
2615
2616 // Start ouput
2617 echo '<select data-placeholder="' . __( 'Type to search for posts, categories or pages.' ) . '" name = "' . $name . '[]" class="select2" multiple="multiple" style="width: 27em;">';
2618
2619 // Front page
2620 K::wrap( __( 'Front page' )
2621 , array(
2622 'value' => '~',
2623 'selected' => in_array( '~', $selected_options ),
2624 )
2625 , array( 'in' => 'option' )
2626 );
2627
2628 // All posts
2629 // K::wrap( __( 'All' )
2630 // , array(
2631 // 'value' => '*',
2632 // 'selected' => in_array( '*', $selected_options ),
2633 // )
2634 // , array( 'in' => 'option' )
2635 // );
2636
2637 foreach ($post_types as $post_type => $post_type_args ) {
2638
2639 $post_type_obj = get_post_type_object( $post_type );
2640 $post_type_name = $post_type_obj->labels->singular_name;
2641
2642 $options = array();
2643
2644 // Add taxonomy/terms options
2645 $taxonomies = get_object_taxonomies( $post_type );
2646 foreach ( $taxonomies as $taxonomy ) {
2647 $taxonomy_obj = get_taxonomy( $taxonomy );
2648 $taxonomy_name = $taxonomy_obj->labels->singular_name;
2649 $terms = get_categories("taxonomy=$taxonomy&type=$post_type");
2650 foreach ($terms as $term) {
2651 $options[ 'taxonomies' ][ "$post_type:$term->term_id" ] =
2652 $post_type_name
2653 . "$taxonomy_name"
2654 . "$term->name"
2655 ;
2656 }
2657 }
2658
2659 // Add posts options
2660 $the_query = new WP_Query( "post_type=$post_type&posts_per_page=-1" );
2661 if ( $the_query->have_posts() ) {
2662
2663 while ( $the_query->have_posts() ) {
2664 $the_query->the_post();
2665 $options[ 'posts' ][ '#' . get_the_ID() ] = $post_type_name
2666 . ' ' . __( '' ) . ' '
2667 . '#' . get_the_ID() . ' &ndash; '
2668 . ( get_the_title() ? get_the_title() : __('[Untitled]') )
2669 ;
2670 }
2671 }
2672
2673 // Dirty fix to restore the global $post
2674 $post = $post_bak;
2675
2676 // Posts > All
2677 echo '<optgroup label="' . $post_type_name . '">';
2678 printf(
2679 '<option value="%s" %s >%s</option>'
2680 , $post_type
2681 , ( in_array( $post_type, $selected_options ) ? 'selected' : '' )
2682 , $post_type_name . ' ' . ( '' ) . ' ' . __( 'All' )
2683 );
2684 echo '</optgroup>';
2685
2686 // Posts > Taoxonomies
2687 if ( ! empty( $options[ 'taxonomies' ] ) ) {
2688 printf(
2689 '<optgroup label="%s">'
2690 , $post_type_name . ' ' . __( '' ) . ' ' . __( 'Taxonomies' )
2691 );
2692 foreach ( $options[ 'taxonomies' ] as $k => $v ) {
2693 $selected = ( in_array( $k, $selected_options ) ) ? 'selected="selected"' : '';
2694 printf( '<option value="%s" %s >%s</option>', $k, $selected, $v );
2695 }
2696 echo '</optgroup>';
2697 }
2698
2699 // Posts > content
2700 if ( ! empty( $options[ 'posts' ] ) ) {
2701 printf( '<optgroup label="%s">'
2702 , $post_type_name . ' ' . __( '' ) . ' ' . __( 'Content' )
2703 );
2704 foreach ( $options[ 'posts' ] as $k => $v ) {
2705 $selected = ( in_array( $k, $selected_options ) ) ? 'selected="selected"' : '';
2706 printf( '<option value="%s" %s >%s</option>'
2707 , $k
2708 , $selected
2709 , $v
2710 );
2711 }
2712 echo '</optgroup>';
2713 }
2714 }
2715 echo '</select>';
2716
2717 $ret = ob_get_clean();
2718
2719 if ( $return ) {
2720 return $ret;
2721 } else {
2722 echo $ret;
2723 }
2724 }
2725
2726 function fca_eoi_comp( $a, $b, $op, $negate = false ) {
2727 switch ( $op ) {
2728 case 'eq': return $negate ? ( ! ( $a == $b ) ) : ( $a == $b );
2729 case 'gt': return $negate ? ( ! ( $a > $b ) ) : ( $a > $b );
2730 case 'gte': return $negate ? ( ! ( $a >= $b ) ) : ( $a >= $b );
2731 case 'lt': return $negate ? ( ! ( $a < $b ) ) : ( $a < $b );
2732 case 'lte': return $negate ? ( ! ( $a <= $b ) ) : ( $a <= $b );
2733 }
2734 }
2735