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

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