null, 'dashboard_widget' => 30 ); private $targeting_cat_path = 'assets/vendor/targeting-cat/TargetingCat-OptinCat-1.2.min.js'; private $two_step_ids_on_page = array(); public function __construct( $settings ) { $this->settings = $settings; $providers_available = array_keys( $this->settings[ 'providers' ] ); // Register custom post type add_action( 'init', array( $this, 'register_custom_post_type' ) ); add_filter( 'manage_easy-opt-ins_posts_columns', array( $this, 'add_new_columns' ) ); add_action( 'manage_easy-opt-ins_posts_custom_column', array( $this, 'set_column_data' ), 10, 2 ); add_filter( 'post_row_actions', array( $this, 'post_row_actions' ), 10, 2 ); // Reset action add_action( 'admin_post_fca_eoi_reset_stats', array( $this, 'reset_stats' ) ); // Dashboard widget add_action( 'wp_dashboard_setup', array( $this, 'dashboard_setup' ) ); // Save add_action( 'save_post', array( $this, 'save_meta_box_content' ), 1, 2 ); // Live preview add_filter( 'the_content', array( $this, 'live_preview' ) ); // Scripts and styles add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) ); add_action( 'admin_head', array( $this, 'hide_minor_publishing' ) ); add_filter( 'admin_body_class', array( $this, 'add_body_class' ) ); add_filter( 'wp_insert_post_data', array( $this, 'force_published' ) ); add_action( 'wp_ajax_fca_eoi_subscribe', array( $this, 'ajax_subscribe' ) ); add_action( 'wp_ajax_nopriv_fca_eoi_subscribe', array( $this, 'ajax_subscribe' ) ); add_filter( 'get_user_option_screen_layout_easy-opt-ins', array( $this, 'force_one_column' ) ); add_filter( 'get_user_option_meta-box-order_easy-opt-ins', array( $this, 'order_columns' ) ); add_filter( 'post_updated_messages', array( $this, 'override_text' ) ); add_filter( 'bulk_actions-edit-easy-opt-ins', array( $this, 'disable_bulk_edit' ) ); add_filter( 'post_row_actions', array( $this, 'remove_quick_edit' ) ); add_action( 'admin_notices', array( $this, 'admin_notices' ) ); add_filter( 'enter_title_here', array( $this, 'change_default_title' ) ); add_filter( 'init', array( $this, 'bind_content_filter' ), 10 ); add_filter( 'template_redirect', array( $this, 'parse_tc_condition_request' ), 1 ); //ADD ACTIONS TO GET THE ENTIRE PAGE OUTPUT IN BUFFER if ( wp_get_theme() == 'Customizr' ) { add_filter( 'the_content', array( $this, 'scan_for_shortcodes' ) ); } else { add_action('wp_head', array( $this, 'fca_eoi_buffer_start' )); add_action('wp_footer', array( $this, 'fca_eoi_buffer_end' )); } add_filter( 'init', array( $this, 'request_prepare_lightbox' ) ); add_filter( 'wp_footer', array( $this, 'show_lightbox' ) ); foreach ( $providers_available as $provider ) { add_action( 'wp_ajax_fca_eoi_' . $provider . '_get_lists', $provider . '_ajax_get_lists' ); } // Hook provder callback functions foreach ( $providers_available as $provider ) { add_filter( 'fca_eoi_alter_admin_notices', $provider . '_admin_notices', 10, 1 ); } // Handle licensing if( count( $providers_available ) > 1 ) { require_once FCA_EOI_PLUGIN_DIR . 'includes/licensing.php'; new EasyOptInsLicense( $this->settings ); } } function fca_eoi_buffer_start() { ob_start(array( $this, 'scan_for_shortcodes' )); } function fca_eoi_buffer_end() { ob_end_flush(); } public function register_custom_post_type() { $labels = array( 'name' => __('Optin Forms') , 'singular_name' => __('Optin Form') , 'add_new' => __('Add New') , 'add_new_item' => __('Add New Optin Form') , 'edit_item' => __('Edit Optin Form') , 'new_item' => __('New Optin Form') , 'all_items' => __('All Optin Forms') , 'view_item' => __('View Optin Form') , 'search_items' => __('Search Optin Form') , 'not_found' => __('No Optin Form Found') , 'not_found_in_trash' => __('No Optin Form Found in Trash') , 'parent_item_colon' => '', 'menu_name' => __('Optin Cat') ); $args = array( 'menu_icon' => FCA_EOI_PLUGIN_URL . '/icon.png', 'labels' => $labels, 'public' => false, 'exclude_from_search' => true, 'publicly_queryable' => false, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'easy-opt-ins', ) , 'capability_type' => 'page', 'has_archive' => false, 'hierarchical' => false, 'menu_position' => 105, 'supports' => array( 'title', ) , 'register_meta_box_cb' => array( $this, 'add_meta_boxes' ) ); register_post_type('easy-opt-ins', $args); } private function enqueue_activity_style() { wp_enqueue_style( 'admin-cpt-easy-opt-ins-activity', FCA_EOI_PLUGIN_URL . '/assets/admin/cpt-easy-opt-ins-activity.css', array(), FCA_EOI_VER ); } public function add_new_columns( $columns ) { $new_columns = array(); if ( ! empty( $columns['cb'] ) ) { $new_columns['cb'] = $columns['cb']; } if ( ! empty( $columns['title'] ) ) { $new_columns['title'] = $columns['title']; } $this->enqueue_activity_style(); $activity = EasyOptInsActivity::get_instance(); $period = '(' . $activity->get_text( 'period', null, array( $this->activity_day_interval['form_list'] ) ) . ')'; foreach ( array( 'impressions', 'conversions', 'conversion_rate' ) as $activity_type ) { $new_columns[ $activity_type ] = esc_html( $activity->get_text( $activity_type, 'form' ) ) . '
' . $period; } return $new_columns; } public function set_column_data( $column_name, $form_id ) { $activity = EasyOptInsActivity::get_instance(); $stats = $activity->get_form_stats( $this->activity_day_interval['form_list'] ); $value = 0; if ( ! empty( $stats[ $column_name ][ $form_id ] ) ) { $value = $stats[ $column_name ][ $form_id ]; } echo $activity->format_column_text( $column_name, $value ); } public function post_row_actions( $actions, $post ) { if ( $post->post_type == 'easy-opt-ins' ) { $action = 'fca_eoi_reset_stats'; $title = __( 'Reset stats for this item' ); $label = __( 'Reset Stats' ); $url = add_query_arg( 'action', $action, admin_url( 'admin-post.php?post=' . $post->ID ) ); $url = wp_nonce_url( $url ); $actions[$action] = $this->confirm_tag( '' . $label . '', __( 'Are you sure?' ), __( 'Do you really want to reset this Optin Form\'s stats? This action cannot be undone.' ) ); } return $actions; } public function reset_stats() { if ( wp_verify_nonce( $_REQUEST['_wpnonce'] ) ) { EasyOptInsActivity::get_instance()->reset_stats( (int) $_REQUEST['post'] ); wp_redirect( wp_get_referer() ); } } private function confirm_tag( $tag, $title, $message ) { return preg_replace( '/>/', ' onclick="return confirm(' . esc_html( '"' . $title . '\n\n' . $message . '"' ) . ')">', $tag, 1 ); } public function dashboard_setup() { if ( defined ( 'FCA_EOI_DISABLE_STATS_TRACKING' )) { $title = 'Optin Cat Summary (TRACKING DISABLED)'; } else { $title = 'Optin Cat Summary'; } add_meta_box( 'fca_eoi_dashboard_widget', $title, array( $this, 'add_dashboard_widget' ), 'dashboard', 'normal', 'high' ); } public function add_dashboard_widget() { wp_enqueue_script( 'd3_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/d3.min.js', array(), FCA_EOI_VER, true ); wp_enqueue_script( 'nvd3_js', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/nv.d3.min.js', array(), FCA_EOI_VER, true ); wp_enqueue_style( 'nvd3_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/nvd3/nv.d3.min.css', array(), FCA_EOI_VER ); $this->enqueue_activity_style(); $day_interval = $this->activity_day_interval['dashboard_widget']; $activity = EasyOptInsActivity::get_instance(); $stats = $activity->get_daily_stats( $day_interval ); $date_labels = array(); foreach ( array_keys( $stats['impressions'] ) as $date ) { $date_labels[] = strftime( '%e %b', strtotime( $date ) ); } $colors = array( 'impressions' => '#5b90bf', 'conversions' => '#bf616a' ); ?>
get_text( $activity_type, 'total' ) ) ?>
get_text( 'period', null, array( $day_interval ) ) ) ?> -
format_column_text( $activity_type, $stats['totals'][ $activity_type ] ) ?>
get_text( $activity_type, 'total' ) ) ?>
'Popups', 'postbox' => 'Post Boxes', 'widget' => 'Sidebar Widgets', ); // Build the layouts array $layouts = $layouts_types = $layouts_types_found = array(); foreach ( glob( FCA_EOI_PLUGIN_DIR . 'layouts/*', GLOB_ONLYDIR ) as $v) { $layouts_types_found[] = basename( $v ); } $layouts_types_accepted = array_keys( $layouts_types_labels ); foreach ( $layouts_types_accepted as $layout_type ) { if ( in_array( $layout_type, $layouts_types_found ) ) { $layouts_types[] = $layout_type; } } // Layouts types mini-tabs echo ''; //GENERATE SCREENSHOTS / OPTIN THEME PICKER //RN NOTE: COULD CACHE THIS (?) $output = ''; foreach ( $layouts_types as $layout_type ) { $output .= "
"; $layout_counter = 1; foreach ( glob( FCA_EOI_PLUGIN_DIR . "layouts/$layout_type/*", GLOB_ONLYDIR ) as $layout_path ) { $layout_id = basename( $layout_path ); $layout_helper = new EasyOptInsLayout( $layout_id ); $layout_type = ucfirst ( $layout_helper->layout_type ); $screenshot_path = $layout_helper->path_to_resource( 'screenshot', 'png' ); $screenshot_url = $layout_helper->url_to_resource( 'screenshot', 'png' ); $screenshot = file_exists( $screenshot_path ) ? $screenshot_url : FCA_EOI_PLUGIN_URL . '/layouts/no-image.jpg'; $layout_name = ucfirst ( str_replace( 'layout', 'widget', str_replace('_', ' ', $layout_id) ) ); $layout_name = str_replace( array('Postbox 0', 'Widget 0'), 'No CSS', $layout_name ); $output .= "
"; $output .= ""; $output .= "
"; $output .= "

$layout_name

"; $output .= "
"; $output .= "
"; $layout_counter = $layout_counter + 1; } $output .= "
"; } $output .= '
'; echo $output; } public function meta_box_content_provider() { global $post; $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); //DISABLE CUSTOM FORM $allow_customform = get_option ( 'fca_eoi_allow_customform', 'false' ); if ( $allow_customform == 'false' ) { $providers = $this->settings[ 'providers' ]; unset ( $providers['customform'] ); $providers_available = array_keys( $providers ); } else { $providers_available = array_keys( $this->settings[ 'providers' ] ); } $providers_options = array(); // Prepare providers options foreach ( $this->settings[ 'providers' ] as $provider_id => $provider ) { $providers_options[ $provider_id ] = $provider[ 'info' ][ 'name' ]; } if ( $allow_customform == 'false') { unset ( $providers_options['customform'] ); } // Provider choice if there are many providers if ( 1 < count( $providers_available) ) { $provider = get_option( 'fca_eoi_last_provider', '' ); $provider = empty($provider) ? 'mailchimp' : $provider; // use mailchimp by default K::select( 'fca_eoi[provider]' , array( 'class' => 'select2', 'style' => 'width: 27em;', ) , array( 'format' => '

', 'options' => array( '' => 'Not set' ) + $providers_options, 'selected' => K::get_var( 'provider', $fca_eoi, $provider ), ) ); } foreach ( $providers_available as $provider ) { call_user_func( $provider . '_integration', $this->settings ); } } public function meta_box_content_publish() { global $post; $screen = get_current_screen(); $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); // Widgets K::wrap( sprintf( __( 'You can publish this optin box by going to Appearance › Widgets') , admin_url( 'widgets.php') ) , array( 'id' => 'fca_eoi_publish_widget' ) , array( 'in' => 'p' ) ); // Post boxes echo '
'; K::wrap( __( 'Shortcode') , array( 'style' => 'padding-left: 0px; padding-right: 0px; ' ) , array( 'in' => 'h3' ) ); K::wrap( __( "Copy and paste beneath shortcode anywhere on your site where you'd like this opt-in form to appear." ) , null , array( 'in' => 'p' ) ); K::input( '' , array( 'class' => 'regular-text autoselect', 'readonly' => 'readonly', 'value' => sprintf( '[%s id=%d]', $this->settings[ 'shortcode' ], $post->ID ), ) , array( 'format' => '

:input

', ) ); K::wrap( __( 'Append to post or page') , array( 'style' => 'padding-left: 0px; padding-right: 0px; ' ) , array( 'in' => 'h3' ) ); K::wrap( __( 'Automatically append this optin to the following posts, categories and/or pages.' ) , null , array( 'in' => 'p' ) ); k_selector( 'fca_eoi[publish_postbox]', K::get_var( 'publish_postbox', $fca_eoi, array() ) ); echo '
'; // Lightboxes switch ( $this->settings['distribution'] ) { case 'free': $conditions_options = array( 'time_on_page' => 'Time on page is at least (second)', ); break; case 'premium': $conditions_options = array( 'pageviews' => 'Number of pageviews during this visit at least', 'scrolled_percent' => 'Scrolled down on current page at least (%)', 'time_on_page' => 'Time on page is at least (second)', 'include' => 'Only show popup on the following posts/pages', 'exclude' => 'Never show popup on the following posts/pages', 'exit_intervention' => 'User is about to close the page (Exit Intervention)' ); break; } $fca_eoi[ 'publish_lightbox' ] = K::get_var( 'publish_lightbox', $fca_eoi, array() ); echo "
"; if ( 'premium' === $this->settings[ 'distribution' ] ) { K::input( 'fca_eoi[publish_lightbox_mode]' , array( 'type' => 'radio', 'value' => 'two_step_optin', 'checked' => 'two_step_optin' === K::get_var( 'publish_lightbox_mode', $fca_eoi ), ) , array( 'format' => '

', ) ); } K::input( 'fca_eoi[publish_lightbox_mode]' , array( 'type' => 'radio', 'value' => 'traditional_popup', 'checked' => 'traditional_popup' === K::get_var( 'publish_lightbox_mode', $fca_eoi ), ) , array( 'format' => '

', ) ); ?>
settings[ 'distribution' ] ) { ?> '; // #fca_eoi_publish_lightbox } private function meta_box_field( $id, $title, $controls = array() ) { $content = ''; foreach ( $controls as $control ) { $control[2] = empty( $control[2] ) ? array() : $control[2]; $control[3] = empty( $control[3] ) ? array() : $control[3]; $control[3][ 'return' ] = true; $content .= call_user_func_array( 'K::' . $control[0], array_slice( $control, 1 ) ); } $content = trim( $content ); $class_name = 'accordion-section-primary-' . ( empty( $content ) ? 'empty' : 'full' ); $content = '
' . $content . '
'; K::wrap( K::wrap( $title, array( 'class' => 'accordion-section-title' ), array( 'return' => true ) ) . K::wrap( $content, array( 'class' => 'accordion-section-content' ), array( 'return' => true ) ), array( 'class' => 'accordion-section', 'id' => $id ) ); } public function meta_box_content_build() { global $post; $post_meta = get_post_meta( $post->ID, 'fca_eoi', true ); $layout = get_post_meta( $post->ID, 'fca_eoi_layout', true ); $selected_layout = empty( $layout ) ? 'lightbox_not_set' : $layout; $class = empty( $layout ) ? 'fca-new-layout' : ''; echo ""; //OUTPUT SELECTED OR DEFAULT TEMPLATE echo "
"; $output = '
'; $output .= ''; //JS WILL LOAD THE TEMPLATE //$output .= fca_eoi_get_layout_html( $selected_layout ); $output .= '
'; echo $output; /* END FORM HTML GENERATION */ $providers_available = array_keys( $this->settings[ 'providers' ] ); $providers_options = array(); $screen = get_current_screen(); // Prepare providers options foreach ($this->settings[ 'providers' ] as $provider_id => $provider ) { $providers_options[ $provider_id ] = $provider[ 'info' ][ 'name' ]; } echo '
'; $this->meta_box_field( 'fca_eoi_fieldset_form', 'Form', array( $this->generate_hidden_css_select_input('form_background_color_selector'), $this->generate_color_picker('form_background_color','Form Background Color'), $this->generate_hidden_css_select_input('form_border_color_selector'), $this->generate_color_picker('form_border_color','Border Color'), ) ); $this->meta_box_field( 'fca_eoi_fieldset_headline', 'Headline', array( array( 'input', 'fca_eoi[headline_copy]', array( 'value' => K::get_var( 'headline_copy', $post_meta ) ), array( 'format' => '

' ) ), $this->generate_hidden_css_select_input('headline_font_size_selector'), $this->generate_font_size_picker ('headline_font_size', 'Font Size'), $this->generate_hidden_css_select_input('headline_font_color_selector'), $this->generate_color_picker('headline_font_color','Font Color'), $this->generate_hidden_css_select_input('headline_background_color_selector'), $this->generate_color_picker('headline_background_color','Background Color'), ) ); $this->meta_box_field( 'fca_eoi_fieldset_description', 'Description', array( array( 'textarea', 'fca_eoi[description_copy]', array(), array( 'format' => ':textarea', 'editor' => true, 'value' => K::get_var( 'description_copy', $post_meta ), ) ), $this->generate_hidden_css_select_input('description_font_size_selector'), $this->generate_font_size_picker ('description_font_size', 'Font Size'), $this->generate_hidden_css_select_input('description_font_color_selector'), $this->generate_color_picker('description_font_color','Font Color'), ) ); $this->meta_box_field( 'fca_eoi_fieldset_name_field', 'Name Field', array( array( 'input', 'fca_eoi[show_name_field]', array( 'type' => 'checkbox', 'checked' => K::get_var( 'show_name_field', $post_meta ), 'class' => 'switch-input' ), array( 'format' => '

Name Field

' ), ), array( 'input', 'fca_eoi[name_placeholder]', array( 'value' => K::get_var( 'name_placeholder', $post_meta, 'First Name' ) ), array( 'format' => '

' ) ), $this->generate_hidden_css_select_input('name_font_size_selector'), $this->generate_font_size_picker ('name_font_size', 'Font Size'), $this->generate_hidden_css_select_input('name_font_color_selector'), $this->generate_color_picker('name_font_color','Font Color'), $this->generate_hidden_css_select_input('name_background_color_selector'), $this->generate_color_picker('name_background_color','Background Color'), $this->generate_hidden_css_select_input('name_border_color_selector'), $this->generate_color_picker('name_border_color','Border Color'), ) ); $this->meta_box_field( 'fca_eoi_fieldset_email_field', 'Email Field', array( array( 'input', 'fca_eoi[email_placeholder]', array( 'value' => K::get_var( 'email_placeholder', $post_meta, 'Your Email' ) ), array( 'format' => '

' ) ), $this->generate_hidden_css_select_input('email_font_size_selector'), $this->generate_font_size_picker ('email_font_size', 'Font Size'), $this->generate_hidden_css_select_input('email_font_color_selector'), $this->generate_color_picker('email_font_color','Font Color'), $this->generate_hidden_css_select_input('email_background_color_selector'), $this->generate_color_picker('email_background_color','Background Color'), $this->generate_hidden_css_select_input('email_border_color_selector'), $this->generate_color_picker('email_border_color','Border Color'), ) ); $this->meta_box_field( 'fca_eoi_fieldset_button', 'Button', array( array( 'input', 'fca_eoi[button_copy]', array( 'value' => K::get_var( 'button_copy', $post_meta, 'Subscribe Now' ) ), array( 'format' => '

' ) ), $this->generate_hidden_css_select_input('button_font_size_selector'), $this->generate_font_size_picker ('button_font_size', 'Font Size'), $this->generate_hidden_css_select_input('button_font_color_selector'), $this->generate_color_picker('button_font_color','Font Color'), $this->generate_hidden_css_select_input('button_background_color_selector'), $this->generate_color_picker('button_background_color','Background Color'), array( 'input', "fca_eoi[button_wrapper_background_color_selector]", array ( 'class' => 'fca-hidden-input hidden', 'value' => '.fca_eoi_layout_submit_button_wrapper' ) ), $this->generate_hidden_css_select_input('button_wrapper_background_color'), ) ); $this->meta_box_field( 'fca_eoi_fieldset_privacy', 'Privacy Policy', array( array( 'textarea', 'fca_eoi[privacy_copy]', array( 'class' => 'large-text', ), array( 'format' => '

', 'value' => K::get_var( 'privacy_copy', $post_meta ), ) ), $this->generate_hidden_css_select_input('privacy_font_size_selector'), $this->generate_font_size_picker ('privacy_font_size', 'Font Size'), $this->generate_hidden_css_select_input('privacy_font_color_selector'), $this->generate_color_picker('privacy_font_color','Font Color'), ) ); $this->meta_box_field( 'fca_eoi_fieldset_fatcatapps', 'Branding', array( array( 'input', 'fca_eoi[show_fatcatapps_link]', array( 'type' => 'checkbox', 'checked' => K::get_var( 'show_fatcatapps_link', $post_meta ), 'class' => 'switch-input' ), array( 'format' => '

Optin Cat Branding

' ), ), $this->generate_hidden_css_select_input('branding_font_color_selector'), $this->generate_color_picker ('branding_font_color', 'Font Color'), ) ); $this->meta_box_field( 'fca_eoi_fieldset_error_text', 'Error Text', array( array( 'textarea', 'fca_eoi[error_text_field_required]', array( 'class' => 'large-text' ), array( 'format' => '

', 'value' => K::get_var( 'error_text_field_required', $post_meta, '' ) ) ), array( 'textarea', 'fca_eoi[error_text_invalid_email]', array( 'class' => 'large-text' ), array( 'format' => '

', 'value' => K::get_var( 'error_text_invalid_email', $post_meta, '' ) ) ) ) ); echo '
'; echo '
'; echo '
'; } public function generate_hidden_css_select_input ($id) { return array( 'input', "fca_eoi[$id]", array ( 'class' => 'fca-hidden-input hidden', 'value' => '' ) ); } public function generate_color_picker ($id, $name) { global $post; $post_meta = get_post_meta( $post->ID, 'fca_eoi', true ); return array( 'input', "fca_eoi[$id]", array ( 'class' => 'fca-color-picker', 'value' => K::get_var( "$id", $post_meta ) ), array( 'format' => '

', ), ); } public function generate_font_size_picker ($id, $name) { global $post; $post_meta = get_post_meta( $post->ID, 'fca_eoi', true ); return array( 'select', "fca_eoi[$id]", array ( 'data-selected' => K::get_var( "$id", $post_meta ), 'class' => 'fca-font-size-picker ', ), array( 'format' => '

', 'options' => array( 'none' => '', '7px' => '7px', '8px' => '8px', '9px' => '9px', '10px' => '10px', '11px' => '11px', '12px' => '12px', '13px' => '13px', '14px' => '14px', '15px' => '15px', '16px' => '16px', '17px' => '17px', '18px' => '18px', '19px' => '19px', '20px' => '20px', '21px' => '21px', '22px' => '22px', '23px' => '23px', '24px' => '24px', '25px' => '25px', '26px' => '26px', '27px' => '27px', '28px' => '28px', '29px' => '29px', '30px' => '30px', '31px' => '31px', '32px' => '32px', '33px' => '33px', '34px' => '34px', '35px' => '35px', '36px' => '36px', ), 'selected' => K::get_var( "$id", $post_meta ), 'return' => true, ), ); } public function meta_box_content_thanks() { global $post; $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); $screen = get_current_screen(); // Get the previous thank you page if this is a new post $last_form_meta = get_option( 'fca_eoi_last_form_meta', '' ); $thank_you_page_suggestion = empty ($last_form_meta['thank_you_page']) ? '~' : $last_form_meta['thank_you_page']; $thank_you_mode_suggestion = empty ($last_form_meta['thankyou_page_mode']) ? 'ajax' : $last_form_meta['thankyou_page_mode']; $thank_you_text_suggestion = empty ($last_form_meta['thankyou_ajax']) ? 'Thank you! Please check your inbox for your confirmation email.' : $last_form_meta['thankyou_ajax']; // Prepare options $pages = array( '~' => __( 'Front page' ) ); $pages_objects = get_pages(); foreach ( $pages_objects as $page_obj ) { $pages[ $page_obj->ID ] = $page_obj->post_title; } K::input( 'fca_eoi[thankyou_page_mode]' , array( 'type' => 'radio', 'value' => 'redirect', 'checked' => 'redirect' === K::get_var( 'thankyou_page_mode', $fca_eoi ), ) , array( 'format' => '

', ) ); if ( $this->settings['distribution'] === 'premium' ) { K::input( 'fca_eoi[thankyou_page_mode]' , array( 'type' => 'radio', 'value' => 'ajax', 'checked' => 'ajax' === K::get_var( 'thankyou_page_mode', $fca_eoi, $thank_you_mode_suggestion ), ) , array( 'format' => '

', ) ); } echo "
"; echo "
"; K::wrap( 'Redirect user to the following page after submitting the form:' , null , array( 'in' => 'p' ) ); K::select( 'fca_eoi[thank_you_page]' , array( 'class' => 'select2', 'style' => 'width: 27em;', ) , array( 'format' => '

', 'options' => $pages, 'selected' => 'add' === $screen->action ? $thank_you_page_suggestion : K::get_var( 'thank_you_page', $fca_eoi, '~' ) , ) ); K::wrap( __( 'Create a new "Thank You Page" ›' ) , array( 'href' => admin_url( 'post-new.php?post_type=page' ), 'target' => '_blank', ) , array( 'in' => 'a', 'html_before' => '

', 'html_after' => '

', ) ); echo "
"; echo "
"; K::textarea( 'fca_eoi[thankyou_ajax]' , array( 'class' => 'fca-eoi-thank-you-ajax', ) , array( 'value' => K::get_var( 'thankyou_ajax', $fca_eoi, $thank_you_text_suggestion ), 'format' => '

:textarea', ) ); echo "
"; } public function meta_box_content_powerups() { global $post; $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); do_action('fca_eoi_powerups', $fca_eoi ); } /** * Save the Metabox Data */ public function save_meta_box_content( $post_id, $post ) { if ( isset ($_POST['fca_eoi'])) { $form_id = $post_id; $meta = $_POST['fca_eoi']; $settings = array ( 'form_background_color_selector' => 'background-color', 'form_border_color_selector' => 'border-color', 'headline_font_size_selector' => 'font-size', 'headline_font_color_selector' => 'color', 'headline_background_color_selector' => 'background-color', 'description_font_size_selector' => 'font-size', 'description_font_color_selector' => 'color', 'name_font_size_selector' => 'font-size', 'name_font_color_selector' => 'color', 'name_background_color_selector' => 'background-color', 'name_border_color_selector' => 'border-color', 'email_font_size_selector' => 'font-size', 'email_font_color_selector' => 'color', 'email_background_color_selector' => 'background-color', 'email_border_color_selector' => 'border-color', 'button_font_size_selector' => 'font-size', 'button_font_color_selector' => 'color', 'button_background_color_selector' => 'background-color', 'button_wrapper_background_color_selector' => 'background-color', 'privacy_font_size_selector' => 'font-size', 'privacy_font_color_selector' => 'color', 'branding_font_color_selector' => 'color', ); $animation = isset($_POST['fca_eoi_animations']) ? $_POST['fca_eoi_animations'] : ''; $animationValue = isset($_POST['fca_eoi_show_animation_checkbox']) ? $_POST['fca_eoi_show_animation_checkbox'] : ''; if ($animationValue != 'on') { $animation = ''; } // Add provider if missing (happens on free distros where there is only one provider) if( ! K::get_var( 'provider', $meta ) ) { $meta[ 'provider' ] = $this->settings[ 'provider' ]; } // Keep only the current providers settings, Remove all [provider]_[setting] not belonging to the current provider $provider = K::get_var( 'provider', $meta ); if( $provider ) { $providers = array_keys( $this->settings[ 'providers' ] ); $other_providers = array_values( array_diff( $providers, array( $provider ) ) ); foreach ( $meta as $k => $v ) { $p = explode( '_', $k ); $k_1 = array_shift( $p ); if( in_array( $k_1, $other_providers ) ) { unset( $meta[ $k ] ); } } foreach ( $_POST as $k => $v ) { if ( strpos( $k, 'fca_eoi_' . $provider . '_' ) === 0 ) { delete_post_meta( $post->ID, $k ); add_post_meta( $post->ID, $k, $v ); $meta[ substr($k, 8) ] = $v; } } } // Make sure empty value for publish_postbox or publish_lightbox are saved as array(-1) if( ! K::get_var( 'publish_postbox' , $meta, array() ) ) { $meta[ 'publish_postbox' ] = array(-1); } if( ! K::get_var( 'publish_lightbox' , $meta, array() ) ) { $meta[ 'publish_lightbox' ] = array(-1); } //sanitize thank you ajax message if ( !empty ( $meta[ 'thankyou_ajax' ] ) ) { $meta[ 'thankyou_ajax' ] = htmlentities($meta[ 'thankyou_ajax' ], ENT_QUOTES, "UTF-8"); } //RN NOTE: THIS DO ANYTHING? -> ONLY FOR CUSTOM HTML FORMS SEEMS LIKE $on_save_function = $provider . '_on_save'; if ( function_exists( $on_save_function ) ) { $meta = $on_save_function( $meta ); } //COMPILE CSS AND SAVE INTO 'HEAD' META $layout_id = $meta[ 'layout' ]; // General CSS for all forms $css = "'; $html = fca_eoi_get_html ( $form_id, $meta ); $head = $head . $html; $meta[ 'post_id' ] = $post_id; update_option( 'fca_eoi_last_provider', $meta[ 'provider' ] ); update_option( 'fca_eoi_last_form_meta', $meta ); update_post_meta( $post->ID, 'fca_eoi_meta_format', '2.0' ); update_post_meta( $post->ID, 'fca_eoi', $meta ); update_post_meta( $post->ID, 'fca_eoi_layout', $meta[ 'layout' ] ); update_post_meta( $post->ID, 'fca_eoi_provider', $meta[ 'provider' ] ); update_post_meta( $post->ID, 'fca_eoi_animation', $animation ); update_post_meta( $post->ID, 'fca_eoi_head', $head ); } } } public function live_preview( $content ) { global $post; if (get_post_type() == 'easy-opt-ins' && is_main_query()) { $shortcode = sprintf( '[%s id=%d]', $this->settings[ 'shortcode' ], $post->ID ); return do_shortcode($shortcode); } else { return $content; } } public function admin_enqueue() { $provider = $this->settings[ 'provider' ]; $providers_available = array_keys( $this->settings[ 'providers' ] ); /** * Disable autosaving optin forms since it causes data loss */ if ( 'easy-opt-ins' == get_post_type() ) { wp_dequeue_script( 'autosave' ); } $screen = get_current_screen(); if( 'easy-opt-ins' === $screen->id ){ global $post; $meta = get_post_meta($post->ID, 'fca_eoi', true ); $options = get_option( 'fca_eoi_settings' ); //LOAD DEPENDENCIES wp_enqueue_script( 'fca_eoi_tooltipster', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.js', array(), FCA_EOI_VER, true ); wp_enqueue_style( 'fca_eoi_tooltipster_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster.bundle.min.css', array(), FCA_EOI_VER ); wp_enqueue_style( 'fca_eoi_tooltipster_theme_css', FCA_EOI_PLUGIN_URL . '/assets/vendor/tooltipster/tooltipster-borderless.min.css', array(), FCA_EOI_VER ); wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_script( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js', array(), FCA_EOI_VER, true ); wp_enqueue_style( 'font-awesome', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css', array(), FCA_EOI_VER ); wp_enqueue_style( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css', array(), FCA_EOI_VER ); wp_enqueue_script( 'accordion' ); if ( !empty( $options['animation'] ) ) { wp_enqueue_style( 'fca_eoi_powerups_animate', FCA_EOI_PLUGIN_URL . '/assets/vendor/animate/animate.css', array(), FCA_EOI_VER ); } //LOAD CUSTOM AJAX SPINNER CODE/CSS wp_enqueue_script( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.js', array(), FCA_EOI_VER, true ); wp_enqueue_style( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.css', array(), FCA_EOI_VER ); //LOAD COMMON CSS wp_enqueue_style( 'fca_eoi', FCA_EOI_PLUGIN_URL .'/assets/style-new.css', array(), FCA_EOI_VER ); //LOAD EDITOR JS wp_enqueue_script( 'fca-eoi-editor', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-editor.js', array('jquery', 'fca_eoi_tooltipster', 'wp-color-picker', 'select2', 'accordion' ), FCA_EOI_VER, true ); //LOAD PROVIDER JS AND CSS foreach ( $providers_available as $provider ) { wp_enqueue_script( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . '/providers/' . $provider . '/cpt-easy-opt-ins.js', array(), FCA_EOI_VER, true ); $css_path = '/providers/' . $provider . '/cpt-easy-opt-ins.css'; if ( is_readable( FCA_EOI_PLUGIN_DIR . $css_path ) ) { wp_enqueue_style( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . $css_path, array(), FCA_EOI_VER ); } } //SEND VARIABLES TO JS $useGroups = empty ( $options['mailchimp_groups'] ) ? array('off') : array('on') ; wp_localize_script( 'admin-cpt-easy-opt-ins-mailchimp', 'useGroups', $useGroups ); $tags = empty($meta['aweber_tags']) ? '' : $meta['aweber_tags']; $aweberSettings = array( 'tags' => $tags, ); wp_localize_script( 'admin-cpt-easy-opt-ins-aweber', 'aweberSettings', $aweberSettings ); $file = plugin_dir_path( __FILE__ ) . "layout-cache"; $layout_data = unserialize (file_get_contents($file)); wp_localize_script( 'fca-eoi-editor', 'layouts', $layout_data ); //EDITOR CSS wp_enqueue_style( 'admin-cpt-easy-opt-ins', FCA_EOI_PLUGIN_URL . '/assets/admin/cpt-easy-opt-ins.css', array(), FCA_EOI_VER ); if ( has_action( 'fca_eoi_powerups' ) ) { wp_enqueue_script('fca_eoi_powerups', FCA_EOI_PLUGIN_URL . '/assets/powerups/fca_eoi_powerups.js', array(), FCA_EOI_VER, true); } } if( 'widgets' === $screen->id ){ wp_enqueue_script( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js', array(), FCA_EOI_VER, true ); wp_enqueue_style( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css', array(), FCA_EOI_VER ); } } /** * Hides minor publising form items (status, visibility and publication date) * * This function shoud be used along with force_published to prevent * saving posts as drafts */ public function hide_minor_publishing() { $screen = get_current_screen(); if( in_array( $screen->id, array( 'easy-opt-ins' ) ) ) { echo ''; } } /** * Forces one column */ public function force_one_column() { return 1; } /** * Sort metaboxes */ public function order_columns( $order ) { return array( 'normal' => join( ",", array( 'submitdiv', 'fca_eoi_meta_box_nav', 'fca_eoi_meta_box_setup', 'fca_eoi_meta_box_build', 'fca_eoi_meta_box_provider', 'fca_eoi_meta_box_thanks', 'fca_eoi_meta_box_publish', 'fca_eoi_meta_box_powerups', 'fca_eoi_meta_box_debug', ) ), 'side' => '', 'advanced' => '', ); } /** * replacing the default "Enter title here" placeholder text in the title input box to * */ public function change_default_title($title) { $screen = get_current_screen(); if ( 'easy-opt-ins' == $screen->post_type ) { $title = 'Enter name here'; } return $title; } /** * Override some strings to match our likings */ public function override_text( $messages ) { global $post; $post_ID = $post->ID; $post_type = get_post_type( $post_ID ); $obj = get_post_type_object( $post_type ); $singular = $obj->labels->singular_name; if ( 'easy-opt-ins' === $post->post_type ) { $messages[$post_type] = array( 0 => '', // Unused. Messages start at index 1. 1 => __( 'Opt-In Form updated.' ), 2 => __( 'Opt-In Form updated.' ), 3 => __( 'Opt-In Form deleted.' ), 4 => __( 'Opt-In Form updated.' ), 5 => isset( $_GET['revision']) ? sprintf( __('%2$s restored to revision from %1$s' ), wp_post_revision_title( (int) $_GET['revision'], false ), esc_attr( $singular ) ) : false, 6 => __( 'Opt-In Form saved.' ), 7 => sprintf( __( '%s saved.' ), esc_attr( $singular ) ), 8 => sprintf( __( '%s submitted. Preview %s'), $singular, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), strtolower( $singular ) ), 9 => sprintf( __( '%s scheduled for: %s. Preview %s' ), $singular, date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ), strtolower( $singular ) ), 10 => sprintf( __( '%s draft updated. Preview %s'), $singular, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), strtolower( $singular ) ) ); } return $messages; } public function force_published( $post ) { if( ! in_array( $post[ 'post_status' ], array( 'auto-draft', 'trash') ) ) { if( in_array( $post[ 'post_type' ], array( 'easy-opt-ins' ) ) ) { $post['post_status'] = 'publish'; } } return $post; } /** * Disables bulk editing */ public function disable_bulk_edit( $actions ){ unset( $actions[ 'edit' ] ); return $actions; } /** * Removes quick edit */ public function remove_quick_edit( $actions ) { global $post; if( 'easy-opt-ins' === $post->post_type ) { unset($actions['inline hide-if-no-js']); } return $actions; } /** * Add the desired body classes (backend) */ public function add_body_class( $classes ) { return "$classes fca_eoi"; } /** * Handle Adding a subscriber with Ajax */ public function ajax_subscribe() { $error = ''; // Get meta $id = $_REQUEST['form_id']; if (empty ($id)){ $error .= "Couldn't find form ID"; } $fca_eoi = get_post_meta( $id, 'fca_eoi', true ); if (empty ($fca_eoi)){ $error .= "Couldn't find post meta"; } $provider = K::get_var( 'provider' , $fca_eoi ); // Check a list_id is provided $list_id = K::get_var( $provider . '_list_id' , $fca_eoi ); if ( empty( $list_id ) ) { $error .= "List not set"; } $nonce = $_REQUEST['nonce']; $nonceVerified = wp_verify_nonce( $nonce, 'fca_eoi_submit_form' ); if ($nonceVerified === FALSE) { $error .= "Couldn't verify form submission"; } // Subscribe user $status = false; if( $list_id && $nonceVerified !== FALSE ) { $str = $provider . '_add_user'; $status = call_user_func( $provider . '_add_user' , $this->settings , $_POST , $list_id ); do_action('fca_eoi_after_submission', $fca_eoi, $_POST ); if ($status !== TRUE) { $error .= " Can't add user"; } } if ( $status !== FALSE && $error === '' ) { echo '✓'; EasyOptInsActivity::get_instance()->add_conversion( $id ); } else { echo '✗' . " Error: " . $error; } exit; } public function admin_notices() { //RN NOTE: MAYBE REWRITE $current_screen = get_current_screen(); // Exit function if we are not on the opt-in editing page if ( ! ( 'easy-opt-ins' === $current_screen->id && 'post' === $current_screen->base && 'edit' === $current_screen->parent_base && '' === $current_screen->action ) ) { return; } global $post; $fca_eoi = get_post_meta( $post->ID, 'fca_eoi', true ); $provider = K::get_var( 'provider', $fca_eoi); $errors = array(); // Add error for missing thank you page $confirmation_page_set = ( bool ) K::get_var( 'thank_you_page', $fca_eoi); if( ! $confirmation_page_set ) { $errors[] = __( 'No "Thank you" page selected. You will not be able to use this form.' ); } // Add error for missing list setting for the current provider $list_set = ( bool ) K::get_var( $provider . '_list_id', $fca_eoi); // @todo: remove // Hack for mailchimp upgrade if( empty( $fca_eoi[ 'provider' ] ) ) { $fca_eoi[ 'mailchimp_list_id' ] = K::get_var( 'mailchimp_list_id' , $fca_eoi , K::get_var( 'list_id' , $fca_eoi ) ); $list_set = ( bool ) K::get_var( 'mailchimp_list_id', $fca_eoi); } // End of Hack if( ! $list_set ) { $errors[] = __( 'No List selected. You will not be able to use this form.' ); } $errors = apply_filters( 'fca_eoi_alter_admin_notices', $errors ); foreach ( $errors as $error ) { echo '

' . $error . '

'; } } public function bind_content_filter() { // Do nothing in backend if ( is_admin() ) { return; } add_action( 'wp', array( $this, 'content' ), 10 ); } public function content() { //RN NOTE WAT global $post; if ( empty( $post ) ) { return; } // Do nothing if viewing an opt-in if ( 'easy-opt-ins' === $post->post_type ) { return; } // Work only when viewing a post of any type if ( empty( $post ) ) { return; } $priorities = array(); // Post details $post_ID = $post->ID; $post_type = get_post_type( $post_ID ); // Build the array for testing $post_cond = array( '*', $post_type, '#' . $post_ID, ); if ( is_front_page() ) { $post_cond[] = '~'; } $priorities[] = '#' . $post_ID; $taxonomies = get_taxonomies('','names'); $post_taxonomies = wp_get_object_terms( $post->ID,$taxonomies); foreach ( $post_taxonomies as $t ) { $condition = $post_type . ':' . $t->term_id; $post_cond[] = $condition; $priorities[] = $condition; } $priorities[] = $post_type; $priorities[] = '*'; $fca_eoi_last_99_forms = array(); foreach (get_posts( 'posts_per_page=99&post_type=easy-opt-ins' ) as $i => $f ) { $fca_eoi_last_99_forms[ $i ][ 'post' ] = $f; $fca_eoi_last_99_forms[ $i ][ 'fca_eoi' ] = get_post_meta( $f->ID, 'fca_eoi', true ); } // wp_reset_query(); $postboxes = array(); // Append postcode shortcode when the conditions match foreach( $fca_eoi_last_99_forms as $f) { // Exclude other layout types if ( empty ( $f[ 'fca_eoi' ][ 'layout' ] ) ) { continue; } if ( strpos( $f[ 'fca_eoi' ][ 'layout' ], 'postbox_' ) !== 0 ) { continue; } // Get conditions $eoi_form_cond = K::get_var( 'publish_postbox', $f[ 'fca_eoi' ], array() ); // Append if ( array_intersect( $eoi_form_cond, $post_cond ) ) { foreach ( $eoi_form_cond as $cond ) { if ( empty( $postboxes[ $cond ] ) ) { $postboxes[ $cond ] = sprintf( '[%s id=%d]', $this->settings['shortcode'], $f['post']->ID ); } } } } if ( ! empty( $postboxes ) ) { foreach ( $priorities as $cond ) { if ( ! empty( $postboxes[ $cond ] ) ) { $post->post_content .= $postboxes[ $cond ]; return; } } $post->post_content .= reset( $postboxes ); return; } } private function get_tc_token( $form_id ) { return "$form_id"; } private function to_call_tc_condition( $name, $arguments ) { return array_merge( array( $name ), $arguments ); } private function to_value_tc_condition( $form_id, $name, $eoi_condition ) { $value = intval( $eoi_condition['value'] ); $params = array( $value ); if ( $name === 'page_views' ) { $params[] = $this->get_tc_token( $form_id ); } else if ( $name === 'time_on_page' ) { $params[0] *= 1000; } return $this->to_call_tc_condition( $name, $params ); } private function to_server_pass_tc_condition( $post_id, $parameter, $eoi_condition ) { $url = add_query_arg( array( 'fca_eoi_tc_condition_pass' => urlencode( $parameter ), 'fca_eoi_tc_condition_value' => urlencode( implode( ',', $eoi_condition['value'] ) ), 'fca_eoi_tc_condition_post_id' => $post_id ) ); return $this->to_call_tc_condition( 'server_pass', array( $url, 'true' ) ); } private function to_tc_condition( $form_id, $post_id, $eoi_condition ) { $eoi_to_tc_value_map = array( 'pageviews' => 'page_views', 'scrolled_percent' => 'scroll_percent', 'time_on_page' => 'time_on_page' ); $eoi_server_pass_conditions = array( 'include', 'exclude' ); $parameter = $eoi_condition['parameter']; if ( array_key_exists( $parameter, $eoi_to_tc_value_map ) ) { return $this->to_value_tc_condition( $form_id, $eoi_to_tc_value_map[ $parameter ], $eoi_condition ); } else if ( in_array( $parameter, $eoi_server_pass_conditions ) ) { return $this->to_server_pass_tc_condition( $post_id, $parameter, $eoi_condition ); } return null; } private function to_show_every_tc_condition( $form_id, $condition ) { if ( in_array( $condition, array( 'day', 'month', 'once', 'session' ) ) ) { return array( $condition, $this->get_tc_token( $form_id ) ); } elseif ( $condition === 'always' ) { return 'true'; } elseif ( $condition === 'never' ) { return 'false'; } return $condition; } private function get_tc_conditions( $form_id, $post_id, $conditions ) { $tc_conditions = array(); $sequence_conditions = array(); if ( ! empty( $conditions['show_every'] ) ) { $condition = $this->to_show_every_tc_condition( $form_id, $conditions['show_every'] ); if ( $condition === 'false' ) { return array( 'false' ); } else { $sequence_conditions[] = $condition; } } if ( ! empty( $conditions['conditions'] ) ) { foreach ( $conditions['conditions'] as $condition ) { if ( $condition['parameter'] === 'exit_intervention' ) { $sequence_conditions[] = 'exit'; continue; } $tc_condition = $this->to_tc_condition( $form_id, $post_id, $condition ); if ( ! empty( $tc_condition ) ) { $tc_conditions[] = $tc_condition; } } } $has_conditions = ! empty ( $tc_conditions ); if ( $has_conditions ) { $tc_conditions = array( 'and' => $tc_conditions ); } if ( $sequence_conditions ) { if ( $has_conditions ) { $tc_conditions = array( 'sequence' => array( $tc_conditions ) ); } else { $tc_conditions = array( 'sequence' => array() ); } foreach ( $sequence_conditions as $condition ) { $tc_conditions['sequence'][] = $condition; } } return $tc_conditions; } private function echo_tc_conditions_for_form( $form_id, $post_id ) { $fca_eoi = get_post_meta( $form_id , 'fca_eoi', true ); $publish_lightbox = K::get_var( 'publish_lightbox', $fca_eoi, array() ); header( 'Content-Type: application/json' ); exit( json_encode( $this->get_tc_conditions( $form_id, $post_id, $publish_lightbox ) ) ); } private function echo_tc_condition_pass( $post_id, $type, $values ) { $post_cond = array( '*' ); if ( is_front_page() ) { $post_cond[] = '~'; } if ( $post_id ) { $post_type = get_post_type( $post_id ); $post_cond[] = $post_type; $post_cond[] = '#' . $post_id; $taxonomies = get_taxonomies( '', 'names' ); $post_taxonomies = wp_get_object_terms( $post_id, $taxonomies ); foreach ( $post_taxonomies as $t ) { $post_cond[] = $post_type . ':' . $t->term_id; } } else { //FIX FOR NOT DISPLAYING ON BLOG PAGE if ( is_home() ) { $post_cond[] = '#' . get_option('page_for_posts'); } } $intersect = array_intersect( $values, $post_cond ); if ( $type === 'include' ) { echo $intersect ? 'true' : 'false'; } else if ( $type === 'exclude' ) { echo $intersect ? 'false' : 'true'; } exit; } public function parse_tc_condition_request() { $post_id = empty( $_REQUEST['fca_eoi_tc_condition_post_id'] ) ? 0 : (int) $_REQUEST['fca_eoi_tc_condition_post_id']; if ( ! empty( $_REQUEST['fca_eoi_tc_conditions_for'] ) ) { $form_id = (int) $_REQUEST['fca_eoi_tc_conditions_for']; $this->echo_tc_conditions_for_form( $form_id, $post_id ); } if ( ! empty( $_REQUEST['fca_eoi_tc_condition_pass'] ) ) { $this->echo_tc_condition_pass( $post_id, $_REQUEST['fca_eoi_tc_condition_pass'], explode( ',', $_REQUEST['fca_eoi_tc_condition_value'] ) ); } } private function get_cookie_configuration() { $cookie_configuration = array(); if ( defined( 'COOKIEPATH' ) ) { $path = COOKIEPATH; if ( ! empty( $path ) ) { $cookie_configuration['path'] = $path; } } if ( defined( 'COOKIE_DOMAIN' ) ) { $domain = COOKIE_DOMAIN; if ( ! empty( $domain ) ) { $cookie_configuration['domain'] = $domain; } } return $cookie_configuration; } public function scan_for_shortcodes( $content ) { if ( preg_match_all( '/data-optin-cat\s*=\s*["\']?\s*(\d+)/', $content, $matches ) ) { $this->two_step_ids_on_page = array_map( 'intval', $matches[1] ); } return $content; } public function show_lightbox() { // Do not show lightbox on mobile if this is the free distribution if ( $this->settings[ 'distribution' ] === 'free' ) { $mobile_detect = new Mobile_Detect; if ( $mobile_detect->isMobile() ) { return; } } // Get lightboxes $lightboxes = get_posts( array( 'post_type' => 'easy-opt-ins', 'posts_per_page' => -1, 'orderby' => 'ID', 'meta_key' => 'fca_eoi_layout', 'meta_value' => 'lightbox_', 'meta_compare' => 'like', ) ); // Exit function if no lightbox found if( ! $lightboxes ) { return; } $two_step_ids = array(); $traditional_ids = array(); foreach ( $lightboxes as $lightbox ) { // Get conditions $lightbox->fca_eoi = get_post_meta( $lightbox->ID , 'fca_eoi', true ); $publish_lightbox_mode = K::get_var( 'publish_lightbox_mode', $lightbox->fca_eoi, array() ); // If on a free distribution, force traditional popup mode if ( 'free' === $this->settings['distribution'] ) { $publish_lightbox_mode = 'traditional_popup'; } if ( 'two_step_optin' === $publish_lightbox_mode ) { $two_step_ids[] = $lightbox->ID; } else { $traditional_ids[] = $lightbox->ID; } } $this->display_traditional_popups($traditional_ids, $this->display_two_step_popups($two_step_ids)); } private function display_two_step_popups($lightbox_ids) { $lightbox_ids = array_intersect( $lightbox_ids, $this->two_step_ids_on_page ); if ( empty( $lightbox_ids ) ) { return false; } do_action( 'fca_eoi_display_lightbox' ); foreach ( $lightbox_ids as $lightbox_id ) { $this->prepare_lightbox( $lightbox_id ); } ?> admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'fca_eoi_submit_form' ), ); wp_localize_script( 'fca_eoi_script_js', 'fca_eoi', $data ); wp_enqueue_script( 'fca_eoi_featherlight_js', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.js', array(), FCA_EOI_VER, true ); wp_enqueue_style( 'fca_eoi_featherlight_css', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.css', array(), FCA_EOI_VER ); ?> 0 ) { $this->prepare_lightbox( $lightbox_id ); exit; } } } public function prepare_lightbox( $id ) { $id = (int) $id; global $post; $animation = get_post_meta( $id, 'fca_eoi_animation', true ); $animation_html_class = "animated $animation"; if ( empty ( $animation ) || $animation == 'None' ) { $animation_html_class = ''; } $featherlight_class = 'fca_eoi_featherlight'; $content = do_shortcode( "[easy-opt-in id=$id]" ); ?>
" ); jQuery( "head" ).append( viewport ); } var viewport_content = viewport.attr( "content" ); this.fca_eoi_viewport_content = viewport_content; viewport.attr( "content", "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" ); this.fca_eoi_orientation_change_listener = function() { window.scrollTo( 0, 0 ); jQuery( ".fca_eoi_form input" ).each( function() { this.blur(); } ); }; window.addEventListener( "orientationchange", this.fca_eoi_orientation_change_listener, false ); this.fca_eoi_touch_move_listener = function( event ) { event.preventDefault(); }; window.addEventListener( "touchmove", this.fca_eoi_touch_move_listener, false ); }, afterOpen: function() { this.$instance.find(".fca_eoi_form_input_element").first().focus(); jQuery( "body" ).append( "
" ); }, beforeClose: function() { jQuery( ".fca_eoi_featherlight_pad" ).remove(); }, afterClose: function() { if ( this.hasOwnProperty( "fca_eoi_viewport_content" ) ) { jQuery( "meta[name=viewport]" ).attr( "content", this.fca_eoi_viewport_content ); } if ( this.hasOwnProperty( "fca_eoi_orientation_change_listener" ) ) { window.removeEventListener( "orientationchange", this.fca_eoi_orientation_change_listener ); } if ( this.hasOwnProperty( "fca_eoi_touch_move_listener" ) ) { window.removeEventListener( "touchmove", this.fca_eoi_touch_move_listener ); } }'; } else { $ios_specific_options = ', afterOpen: function() { this.$instance.find(".fca_eoi_form_input_element").first().focus(); }'; } return '{ namespace: "fca_eoi_featherlight", otherClose: ".fca_eoi_layout_popup_close"' . $ios_specific_options . ', variant: ' . ( $is_iphone ? '"fca_eoi_device_iphone"' : 'null' ) . ' }'; } } function k_selector( $name, $selected_options = array(), $return = false ) { global $post; // Dirty fix to restore the global $post $post_bak = $post; // Get all post types except media $post_types = get_post_types( array( 'public' => true ) ); unset( $post_types[ 'attachment' ] ); $ret = ob_start(); // Start ouput echo ''; $ret = ob_get_clean(); if ( $return ) { return $ret; } else { echo $ret; } } function fca_eoi_comp( $a, $b, $op, $negate = false ) { switch ( $op ) { case 'eq': return $negate ? ( ! ( $a == $b ) ) : ( $a == $b ); case 'gt': return $negate ? ( ! ( $a > $b ) ) : ( $a > $b ); case 'gte': return $negate ? ( ! ( $a >= $b ) ) : ( $a >= $b ); case 'lt': return $negate ? ( ! ( $a < $b ) ) : ( $a < $b ); case 'lte': return $negate ? ( ! ( $a <= $b ) ) : ( $a <= $b ); } }