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

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