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

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

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