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

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

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