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

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