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

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

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