| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 2 | + | |
| 3 | 3 | class EasyOptInsPostTypes { |
| 4 | 4 | |
| 5 | 5 | public $settings; |
| 6 | 6 | |
| @@ -8,10 +8,8 @@ | ||
| 8 | 8 | 'form_list' => null, |
| 9 | 9 | 'dashboard_widget' => 30 |
| 10 | 10 | ); |
| 11 | 11 | |
| 12 | - private $targeting_cat_path = 'assets/vendor/targeting-cat/TargetingCat-OptinCat-1.2.min.js'; | |
| 13 | - | |
| 14 | 12 | private $two_step_ids_on_page = array(); |
| 15 | 13 | |
| 16 | 14 | public function __construct( $settings ) { |
| 17 | 15 | |
| @@ -47,8 +45,11 @@ | ||
| 47 | 45 | if ( $this->settings['distribution'] === 'free' ) { |
| 48 | 46 | add_action( 'admin_notices', array( $this, 'review_notice' ) ); |
| 49 | 47 | } |
| 50 | 48 | |
| 49 | + //V 2.0 BLOG POST NOTICE | |
| 50 | + add_action( 'admin_notices', array( $this, 'google_changes_notice' ) ); | |
| 51 | + | |
| 51 | 52 | add_filter( 'admin_body_class', array( $this, 'add_body_class' ) ); |
| 52 | 53 | |
| 53 | 54 | add_filter( 'wp_insert_post_data', array( $this, 'force_published' ) ); |
| 54 | 55 | |
| @@ -72,10 +73,8 @@ | ||
| 72 | 73 | add_filter( 'enter_title_here', array( $this, 'change_default_title' ) ); |
| 73 | 74 | |
| 74 | 75 | add_filter( 'init', array( $this, 'bind_content_filter' ), 10 ); |
| 75 | 76 | |
| 76 | - add_filter( 'template_redirect', array( $this, 'parse_tc_condition_request' ), 1 ); | |
| 77 | - | |
| 78 | 77 | add_filter( 'plugin_action_links_' . FCA_EOI_PLUGIN_BASENAME, array( $this, 'add_plugin_action_links' ) ); |
| 79 | 78 | |
| 80 | 79 | //ADD ACTIONS TO GET THE ENTIRE PAGE OUTPUT IN BUFFER |
| 81 | 80 | |
| @@ -84,12 +83,10 @@ | ||
| 84 | 83 | } else { |
| 85 | 84 | add_action('wp_head', array( $this, 'fca_eoi_buffer_start' )); |
| 86 | 85 | add_action('wp_footer', array( $this, 'fca_eoi_buffer_end' )); |
| 87 | 86 | } |
| 88 | - | |
| 89 | - add_filter( 'init', array( $this, 'request_prepare_lightbox' ) ); | |
| 90 | 87 | |
| 91 | - add_filter( 'wp_footer', array( $this, 'show_lightbox' ) ); | |
| 88 | + add_filter( 'wp_footer', array( $this, 'maybe_show_lightbox' ) ); | |
| 92 | 89 | |
| 93 | 90 | foreach ( $providers_available as $provider ) { |
| 94 | 91 | add_action( 'wp_ajax_fca_eoi_' . $provider . '_get_lists', $provider . '_ajax_get_lists' ); |
| 95 | 92 | } |
| @@ -166,9 +163,9 @@ | ||
| 166 | 163 | register_post_type('easy-opt-ins', $args); |
| 167 | 164 | } |
| 168 | 165 | |
| 169 | 166 | private function enqueue_activity_style() { |
| 170 | - wp_enqueue_style( 'admin-cpt-easy-opt-ins-activity', FCA_EOI_PLUGIN_URL . '/assets/admin/cpt-easy-opt-ins-activity.css', array(), FCA_EOI_VER ); | |
| 167 | + wp_enqueue_style( 'admin-cpt-easy-opt-ins-activity', FCA_EOI_PLUGIN_URL . '/assets/admin/cpt-easy-opt-ins-activity.min.css', array(), FCA_EOI_VER ); | |
| 171 | 168 | } |
| 172 | 169 | |
| 173 | 170 | public function add_new_columns( $columns ) { |
| 174 | 171 | $new_columns = array(); |
| @@ -405,9 +402,19 @@ | ||
| 405 | 402 | $layouts_types_labels = array( |
| 406 | 403 | 'lightbox' => 'Popups', |
| 407 | 404 | 'postbox' => 'Post Boxes', |
| 408 | 405 | 'widget' => 'Sidebar Widgets', |
| 406 | + 'banner' => 'Optin Bars', | |
| 407 | + 'overlay' => 'Slide Ins', | |
| 409 | 408 | ); |
| 409 | + | |
| 410 | + $layout_names = array( | |
| 411 | + 'banner_10' => __( 'Optin Bar 1', 'easy-opt-ins'), | |
| 412 | + 'banner_11' => __( 'Optin Bar 2', 'easy-opt-ins'), | |
| 413 | + 'banner_12' => __( 'Optin Bar 3', 'easy-opt-ins'), | |
| 414 | + 'overlay_13' => __( 'Slide In Light', 'easy-opt-ins'), | |
| 415 | + 'overlay_14' => __( 'Slide In Dark', 'easy-opt-ins'), | |
| 416 | + ); | |
| 410 | 417 | |
| 411 | 418 | // Build the layouts array |
| 412 | 419 | $layouts = $layouts_types = $layouts_types_found = array(); |
| 413 | 420 | foreach ( glob( FCA_EOI_PLUGIN_DIR . 'layouts/*', GLOB_ONLYDIR ) as $v) { |
| @@ -438,13 +445,11 @@ | ||
| 438 | 445 | } |
| 439 | 446 | echo '<button type="button" class="button button-primary" id="fca_eoi_layout_revert_button" style="display: none">' . __('Back', 'easy-opt-in') . '</button>'; |
| 440 | 447 | |
| 441 | 448 | echo '</ul>'; |
| 442 | - | |
| 443 | - | |
| 444 | - | |
| 449 | + | |
| 445 | 450 | //GENERATE SCREENSHOTS / OPTIN THEME PICKER |
| 446 | - //RN NOTE: COULD CACHE THIS (?) | |
| 451 | + //RN NOTE: MAYBE CACHE THIS | |
| 447 | 452 | $output = ''; |
| 448 | 453 | foreach ( $layouts_types as $layout_type ) { |
| 449 | 454 | |
| 450 | 455 | $output .= "<div class='fca_eoi_accordion_tab' id='layouts_type_$layout_type'>"; |
| @@ -451,8 +456,10 @@ | ||
| 451 | 456 | $layout_counter = 1; |
| 452 | 457 | foreach ( glob( FCA_EOI_PLUGIN_DIR . "layouts/$layout_type/*", GLOB_ONLYDIR ) as $layout_path ) { |
| 453 | 458 | $layout_id = basename( $layout_path ); |
| 454 | 459 | |
| 460 | + | |
| 461 | + | |
| 455 | 462 | $layout_helper = new EasyOptInsLayout( $layout_id ); |
| 456 | 463 | $layout_type = ucfirst ( $layout_helper->layout_type ); |
| 457 | 464 | |
| 458 | 465 | $screenshot_path = $layout_helper->path_to_resource( 'screenshot', 'png' ); |
| @@ -458,10 +465,15 @@ | ||
| 458 | 465 | $screenshot_path = $layout_helper->path_to_resource( 'screenshot', 'png' ); |
| 459 | 466 | $screenshot_url = $layout_helper->url_to_resource( 'screenshot', 'png' ); |
| 460 | 467 | $screenshot = file_exists( $screenshot_path ) ? $screenshot_url : FCA_EOI_PLUGIN_URL . '/layouts/no-image.jpg'; |
| 461 | 468 | |
| 462 | - $layout_name = ucfirst ( str_replace( 'layout', 'widget', str_replace('_', ' ', $layout_id) ) ); | |
| 463 | - $layout_name = str_replace( array('Postbox 0', 'Widget 0'), 'No CSS', $layout_name ); | |
| 469 | + if ( array_key_exists ( $layout_id, $layout_names ) ) { | |
| 470 | + $layout_name = $layout_names[$layout_id]; | |
| 471 | + } else { | |
| 472 | + $layout_name = ucfirst ( str_replace( 'layout', 'widget', str_replace('_', ' ', $layout_id) ) ); | |
| 473 | + $layout_name = str_replace( array('Postbox 0', 'Widget 0'), 'No CSS', $layout_name ); | |
| 474 | + } | |
| 475 | + | |
| 464 | 476 | $output .= "<div class='fca_eoi_layout has-tip fca_eoi_layout_preview' data-layout-id='$layout_id' data-layout-type='$layout_type'>"; |
| 465 | 477 | $output .= "<img src='$screenshot'>"; |
| 466 | 478 | $output .= "<div class='fca_eoi_layout_info'>"; |
| 467 | 479 | $output .= "<h3>$layout_name</h3>"; |
| @@ -535,10 +547,56 @@ | ||
| 535 | 547 | $conditions_options = array( |
| 536 | 548 | '' => __( 'Choose a rule...' ), |
| 537 | 549 | 'time_on_page' => __( 'Time on page' ), |
| 538 | 550 | ); |
| 551 | + ob_start(); | |
| 552 | + ?> | |
| 553 | + <tr> | |
| 554 | + <th><select class="fca_eoi_condition_select"> | |
| 555 | + <option selected="selected"> | |
| 556 | + Choose a rule... | |
| 557 | + </option> | |
| 558 | + | |
| 559 | + <option value="scrolled_percent"> | |
| 560 | + Scrolled down | |
| 561 | + </option> | |
| 562 | + <optgroup label="Premium Only"> | |
| 563 | + | |
| 564 | + <option value="pageviews" disabled> | |
| 565 | + Number of Pageviews | |
| 566 | + </option> | |
| 567 | + | |
| 568 | + <option value="time_on_page" disabled> | |
| 569 | + Time on page | |
| 570 | + </option> | |
| 571 | + | |
| 572 | + <option value="include" disabled> | |
| 573 | + Only display on these pages | |
| 574 | + </option> | |
| 575 | + | |
| 576 | + <option value="exclude" disabled> | |
| 577 | + Never display on these pages | |
| 578 | + </option> | |
| 579 | + | |
| 580 | + <option value="exit_intervention" disabled> | |
| 581 | + Exit Intervention | |
| 582 | + </option> | |
| 583 | + </optgroup> | |
| 584 | + </select><span class='fca_eoi_at_least' style= | |
| 585 | + 'display:none'>at least</span></th> | |
| 586 | + | |
| 587 | + <td></td> | |
| 588 | + | |
| 589 | + <td class='fca_eoi_delete_condition' title='Click to remove'><span class='fca_eoi_close_icon dashicons dashicons-no'></span></td> | |
| 590 | + </tr> | |
| 591 | + | |
| 592 | + <?php | |
| 593 | + | |
| 594 | + $rowNew = ob_get_clean(); | |
| 539 | 595 | break; |
| 596 | + | |
| 540 | 597 | case 'premium': |
| 598 | + | |
| 541 | 599 | $conditions_options = array( |
| 542 | 600 | '' => __( 'Choose a rule...' ), |
| 543 | 601 | 'scrolled_percent' => __( 'Scrolled down' ), |
| 544 | 602 | 'pageviews' => __( 'Number of Pageviews' ), |
| @@ -546,23 +604,26 @@ | ||
| 546 | 604 | 'include' => __( 'Only display on these pages' ), |
| 547 | 605 | 'exclude' => __( 'Never display on these pages' ), |
| 548 | 606 | 'exit_intervention' => __( 'Exit Intervention' ), |
| 549 | 607 | ); |
| 608 | + | |
| 609 | + $rowNew = "<tr><th>" . | |
| 610 | + K::select( | |
| 611 | + '', | |
| 612 | + array( | |
| 613 | + 'class' => 'fca_eoi_condition_select', | |
| 614 | + ), | |
| 615 | + array( | |
| 616 | + 'options' => $conditions_options, | |
| 617 | + 'return' => true, | |
| 618 | + ) | |
| 619 | + ) . "<span class='fca_eoi_at_least' style='display:none' >at least</span></th><td></td><td class='fca_eoi_delete_condition' title='Click to remove'><span class='fca_eoi_close_icon dashicons dashicons-no'></span></td></tr>"; | |
| 620 | + | |
| 550 | 621 | break; |
| 551 | 622 | } |
| 552 | 623 | |
| 553 | 624 | $ruleTableHtml = array ( |
| 554 | - 'rowNew' => "<tr><th>" . | |
| 555 | - K::select( | |
| 556 | - '', | |
| 557 | - array( | |
| 558 | - 'class' => 'fca_eoi_condition_select', | |
| 559 | - ), | |
| 560 | - array( | |
| 561 | - 'options' => $conditions_options, | |
| 562 | - 'return' => true, | |
| 563 | - ) | |
| 564 | - ) . "<span class='fca_eoi_at_least' style='display:none' >at least</span></th><td></td><td class='fca_eoi_delete_condition' title='Click to remove'><span class='fca_eoi_close_icon dashicons dashicons-no'></span></td></tr>", | |
| 625 | + 'rowNew' => $rowNew, | |
| 565 | 626 | |
| 566 | 627 | 'dataScroll' => K::input( |
| 567 | 628 | 'fca_eoi[publish_lightbox][conditions][scrolled_percent]', |
| 568 | 629 | array( |
| @@ -567,8 +628,9 @@ | ||
| 567 | 628 | 'fca_eoi[publish_lightbox][conditions][scrolled_percent]', |
| 568 | 629 | array( |
| 569 | 630 | 'type' => 'number', |
| 570 | 631 | 'min' => '0', |
| 632 | + 'max' => '100', | |
| 571 | 633 | 'value' => '30', |
| 572 | 634 | 'class' => '', |
| 573 | 635 | ), |
| 574 | 636 | array( |
| @@ -616,11 +678,11 @@ | ||
| 616 | 678 | 'dataInclude' => k_selector( 'fca_eoi[publish_lightbox][conditions][include]', array(), true ), |
| 617 | 679 | 'dataExclude' => k_selector( 'fca_eoi[publish_lightbox][conditions][exclude]', array(), true ), |
| 618 | 680 | ); |
| 619 | 681 | |
| 620 | - wp_localize_script( 'fca-eoi-rules', 'ruleTableHtml', $ruleTableHtml ); | |
| 621 | - wp_localize_script( 'fca-eoi-rules', 'rules', $rules ); | |
| 622 | - wp_localize_script( 'fca-eoi-rules', 'distro', $this->settings['distribution'] ); | |
| 682 | + wp_localize_script( 'fca-eoi-rules', 'fcaEoiRuleTableHtml', $ruleTableHtml ); | |
| 683 | + wp_localize_script( 'fca-eoi-rules', 'fcaEoiRules', $rules ); | |
| 684 | + wp_localize_script( 'fca-eoi-rules', 'fcaEoiDistro', $this->settings['distribution'] ); | |
| 623 | 685 | } |
| 624 | 686 | |
| 625 | 687 | public function meta_box_content_publish( $post ) { |
| 626 | 688 | |
| @@ -687,10 +749,8 @@ | ||
| 687 | 749 | array( |
| 688 | 750 | 'format' => '<p><label>:input Two-Step Optin (Trigger popup only when the visitor clicks on a call to action link)</label></p>', |
| 689 | 751 | ) |
| 690 | 752 | ); |
| 691 | - | |
| 692 | - | |
| 693 | 753 | } |
| 694 | 754 | |
| 695 | 755 | K::input( 'fca_eoi[publish_lightbox_mode]', |
| 696 | 756 | array( |
| @@ -707,15 +767,14 @@ | ||
| 707 | 767 | echo '<div id="fca_eoi_publish_lightbox_mode_traditional_popup">'; |
| 708 | 768 | echo "<h3>Rules</h3>"; |
| 709 | 769 | |
| 710 | 770 | echo "<table class='fca_eoi_display_rules_table'>"; |
| 711 | - echo "<tr><th>Display Frequency</th><td>"; | |
| 771 | + echo "<tr><th>Display Frequency" . fca_eoi_tooltip ( __('Set the minimum time between visits your optin will display to each user', 'easy-opt-ins') ) . "</th><td>"; | |
| 712 | 772 | K::select( |
| 713 | 773 | 'fca_eoi[publish_lightbox][show_every]', |
| 714 | 774 | array(), |
| 715 | 775 | array( |
| 716 | 776 | 'options' => array( |
| 717 | - 'never' => __( 'Never' ), | |
| 718 | 777 | 'always' => __( 'On every pageview' ), |
| 719 | 778 | 'session' => __( 'Once per visit' ), |
| 720 | 779 | 'day' => __( 'Once per day' ), |
| 721 | 780 | 'month' => __( 'Once per month' ), |
| @@ -720,9 +779,9 @@ | ||
| 720 | 779 | 'day' => __( 'Once per day' ), |
| 721 | 780 | 'month' => __( 'Once per month' ), |
| 722 | 781 | 'once' => __( 'Only once' ), |
| 723 | 782 | ), |
| 724 | - 'selected' => K::get_var( 'show_every', $fca_eoi[ 'publish_lightbox' ], 'once' ), | |
| 783 | + 'selected' => K::get_var( 'show_every', $fca_eoi[ 'publish_lightbox' ], 'month' ), | |
| 725 | 784 | ) |
| 726 | 785 | ); |
| 727 | 786 | echo "</td></tr>"; |
| 728 | 787 | |
| @@ -735,13 +794,25 @@ | ||
| 735 | 794 | 'desktop' => __( 'Desktop Only' ), |
| 736 | 795 | 'mobile' => __( 'Mobile Only' ), |
| 737 | 796 | 'all' => __( 'Desktop & Mobile' ), |
| 738 | 797 | ), |
| 739 | - 'selected' => K::get_var( 'devices', $fca_eoi[ 'publish_lightbox' ], 'desktop' ), | |
| 798 | + 'selected' => K::get_var( 'devices', $fca_eoi[ 'publish_lightbox' ], 'all' ), | |
| 740 | 799 | ) |
| 741 | 800 | ); |
| 742 | 801 | echo "</td></tr>"; |
| 743 | 802 | |
| 803 | + echo "<tr><th>Success Cookie Duration" . fca_eoi_tooltip ( __('The number of days before the optin will display again once the user successfully opts in to your campaign.', 'easy-opt-ins') ) . "</th><td>"; | |
| 804 | + K::input( 'fca_eoi[publish_lightbox][success_duration]', | |
| 805 | + array( | |
| 806 | + 'type' => 'number', | |
| 807 | + 'class' => 'regular-text', | |
| 808 | + 'min' => 0, | |
| 809 | + 'value' => K::get_var( 'success_duration', $fca_eoi[ 'publish_lightbox' ], 365 ), | |
| 810 | + ) | |
| 811 | + ); | |
| 812 | + | |
| 813 | + echo " days</td></tr>"; | |
| 814 | + | |
| 744 | 815 | |
| 745 | 816 | echo "</table>"; |
| 746 | 817 | |
| 747 | 818 | echo "<table class='fca_eoi_display_rules_table' id='fca_eoi_primary_rules_table' >"; |
| @@ -751,9 +822,9 @@ | ||
| 751 | 822 | echo "<a href='#' id='fca_eoi_add_rule'>+ Add a rule</a>"; |
| 752 | 823 | |
| 753 | 824 | echo "<h3>Go Live</h3>"; |
| 754 | 825 | echo "<table class='fca_eoi_display_rules_table' >"; |
| 755 | - echo "<tr><th>Deployed (makes this popup go live)</th><td>"; | |
| 826 | + echo "<tr><th>Deployed (makes this optin go live)</th><td>"; | |
| 756 | 827 | K::input( 'fca_eoi[publish_lightbox][live]', |
| 757 | 828 | array( |
| 758 | 829 | 'type' => 'checkbox', |
| 759 | 830 | 'checked' => K::get_var( 'live', $fca_eoi[ 'publish_lightbox' ], '' ), |
| @@ -879,8 +950,53 @@ | ||
| 879 | 950 | echo '<span id="accordion-info-layout">Layout</span><button title="Change Layout" type="button" id="fca_eoi_layout_select_button" class="button button-secondary"><span style="margin-top: 3px; margin-right: 3px;" class="dashicons dashicons-admin-appearance"></span>Change Layout</button>'; |
| 880 | 951 | echo '</div>'; |
| 881 | 952 | |
| 882 | 953 | $this->meta_box_field( 'fca_eoi_fieldset_form', 'Form', array( |
| 954 | + | |
| 955 | + array( 'input', 'fca_eoi[toggle_overlay_position]', | |
| 956 | + array( | |
| 957 | + 'type' => 'checkbox', | |
| 958 | + 'checked' => K::get_var( 'toggle_overlay_position', $post_meta, 'off' ) === 'off' ? '' : 'on', | |
| 959 | + 'class' => 'switch-input' | |
| 960 | + ), | |
| 961 | + array( | |
| 962 | + 'format' => '<p id="fca_eoi_overlay_position_p"><span class="control-title">Placement</span><br><label class="switch">:input<span class="switch-label" data-on="" data-off=""></span><span class="switch-handle"></span></label></p>' | |
| 963 | + ), | |
| 964 | + ), | |
| 965 | + array( 'input', 'fca_eoi[show_close]', | |
| 966 | + array( | |
| 967 | + 'type' => 'checkbox', | |
| 968 | + 'checked' => K::get_var( 'show_close', $post_meta, 'on' ) === 'on' ? 'on' : '', | |
| 969 | + 'class' => 'switch-input' | |
| 970 | + ), | |
| 971 | + array( | |
| 972 | + 'format' => '<p id="fca_eoi_close_button_p"><span class="control-title">Close Button</span><br><label class="switch">:input<span class="switch-label" data-on="Show" data-off="Hide"></span><span class="switch-handle"></span></label></p>' | |
| 973 | + ), | |
| 974 | + ), | |
| 975 | + | |
| 976 | + array( 'input', 'fca_eoi[push_page]', | |
| 977 | + array( | |
| 978 | + 'type' => 'checkbox', | |
| 979 | + 'checked' => K::get_var( 'push_page', $post_meta, 'on' ) === 'on' ? 'on' : '', | |
| 980 | + 'class' => 'switch-input' | |
| 981 | + ), | |
| 982 | + array( | |
| 983 | + 'format' => '<p id="fca_eoi_push_page_p"><span class="control-title">Push Page Down</span><br><label class="switch">:input<span class="switch-label" data-on="On" data-off="Off"></span><span class="switch-handle"></span></label></p>' | |
| 984 | + ), | |
| 985 | + ), | |
| 986 | + | |
| 987 | + array( 'input', "fca_eoi[offset]", | |
| 988 | + array( | |
| 989 | + 'type' => 'number', | |
| 990 | + 'min' => '0', | |
| 991 | + 'value' => K::get_var( 'offset', $post_meta, 0 ), | |
| 992 | + 'class' => 'fca_eoi_number_input', | |
| 993 | + ), | |
| 994 | + array( | |
| 995 | + 'format' => "<p id='fca_eoi_offset_p'><label><span class='control-title'>Offset</span></label><br />:inputpx</p>", | |
| 996 | + ) | |
| 997 | + ), | |
| 998 | + | |
| 883 | 999 | $this->generate_hidden_css_select_input('form_background_color_selector'), |
| 884 | 1000 | $this->generate_color_picker('form_background_color','Form Background Color'), |
| 885 | 1001 | $this->generate_hidden_css_select_input('form_border_color_selector'), |
| 886 | 1002 | $this->generate_color_picker('form_border_color','Border Color'), |
| @@ -1180,12 +1296,12 @@ | ||
| 1180 | 1296 | // Get the previous thank you page if this is a new post |
| 1181 | 1297 | $last_form_meta = get_option( 'fca_eoi_last_form_meta', '' ); |
| 1182 | 1298 | $thank_you_page_suggestion = empty ($last_form_meta['thank_you_page']) ? '~' : $last_form_meta['thank_you_page']; |
| 1183 | 1299 | $thank_you_mode_suggestion = empty ($last_form_meta['thankyou_page_mode']) ? 'ajax' : $last_form_meta['thankyou_page_mode']; |
| 1184 | - $thank_you_text_suggestion = empty ($last_form_meta['thankyou_ajax']) ? __('Thank you! Please check your inbox for your confirmation email.', 'easy-opt-ins') : $last_form_meta['thankyou_ajax']; | |
| 1185 | - $subscribing_suggestion = empty ($last_form_meta['subscribing_message']) ? __('Subscribing...', 'easy-opt-ins') : $last_form_meta['subscribing_message']; | |
| 1186 | - $text_error_suggestion = empty ($last_form_meta['error_text_field_required']) ? __('Please fill out this field to continue', 'easy-opt-ins') : $last_form_meta['error_text_field_required']; | |
| 1187 | - $email_error_suggestion = empty ($last_form_meta['error_text_invalid_email']) ? __('Please enter a valid email address. For example "hi@fatcatapps.com".', 'easy-opt-ins') : $last_form_meta['error_text_invalid_email']; | |
| 1300 | + $thank_you_text_suggestion = empty ($last_form_meta['thankyou_ajax']) ? __('Thank you! Please check your inbox for your confirmation email.', 'easy-opt-ins') : stripslashes( $last_form_meta['thankyou_ajax'] ); | |
| 1301 | + $subscribing_suggestion = empty ($last_form_meta['subscribing_message']) ? __('Subscribing...', 'easy-opt-ins') : stripslashes( $last_form_meta['subscribing_message'] ); | |
| 1302 | + $text_error_suggestion = empty ($last_form_meta['error_text_field_required']) ? __('Please fill out this field to continue', 'easy-opt-ins') : stripslashes( $last_form_meta['error_text_field_required'] ); | |
| 1303 | + $email_error_suggestion = empty ($last_form_meta['error_text_invalid_email']) ? __('Please enter a valid email address. For example "example@example.com".', 'easy-opt-ins') : stripslashes( $last_form_meta['error_text_invalid_email'] ); | |
| 1188 | 1304 | |
| 1189 | 1305 | echo '<h3>' . __('Subscribing Message', 'easy-opt-ins') . fca_eoi_tooltip ( __('This message will be displayed after your visitors submit your form.', 'easy-opt-ins') ) . '</h3>'; |
| 1190 | 1306 | echo '<table class="fca_eoi_text_messages_table">'; |
| 1191 | 1307 | echo '<tr><th>Message</th><td>'; |
| @@ -1340,10 +1456,11 @@ | ||
| 1340 | 1456 | $toggles = array ( |
| 1341 | 1457 | 'show_headline_field', |
| 1342 | 1458 | 'show_description_field', |
| 1343 | 1459 | 'show_name_field', |
| 1460 | + 'show_close', | |
| 1344 | 1461 | 'show_privacy_field', |
| 1345 | - | |
| 1462 | + 'push_page', | |
| 1346 | 1463 | ); |
| 1347 | 1464 | |
| 1348 | 1465 | forEach ( $toggles as $field ) { |
| 1349 | 1466 | $meta[$field] = empty ( $meta[$field] ) ? 'off' : 'on'; |
| @@ -1375,14 +1492,8 @@ | ||
| 1375 | 1492 | 'privacy_font_color_selector' => 'color', |
| 1376 | 1493 | 'branding_font_color_selector' => 'color', |
| 1377 | 1494 | ); |
| 1378 | 1495 | |
| 1379 | - $animation = isset($_POST['fca_eoi_animations']) ? $_POST['fca_eoi_animations'] : ''; | |
| 1380 | - $animationValue = isset($_POST['fca_eoi_show_animation_checkbox']) ? $_POST['fca_eoi_show_animation_checkbox'] : ''; | |
| 1381 | - if ($animationValue != 'on') { | |
| 1382 | - $animation = ''; | |
| 1383 | - } | |
| 1384 | - | |
| 1385 | 1496 | // Add provider if missing (happens on free distros where there is only one provider) |
| 1386 | 1497 | if( ! K::get_var( 'provider', $meta ) ) { |
| 1387 | 1498 | $meta[ 'provider' ] = $this->settings[ 'provider' ]; |
| 1388 | 1499 | } |
| @@ -1461,8 +1572,27 @@ | ||
| 1461 | 1572 | if ( $show_description_field === 'off' ) { |
| 1462 | 1573 | $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_description_copy_wrapper {display: none !important;}"; |
| 1463 | 1574 | } |
| 1464 | 1575 | |
| 1576 | + $show_close = K::get_var( 'show_close', $meta, 'on' ); | |
| 1577 | + if ( $show_close === 'off' ) { | |
| 1578 | + $css .= "#fca_eoi_form_$form_id .fca_eoi_banner_close_btn {display: none !important;}"; | |
| 1579 | + } | |
| 1580 | + | |
| 1581 | + $toggle_position = K::get_var( 'toggle_overlay_position', $meta, 'off' ); | |
| 1582 | + $offset = K::get_var( 'offset', $meta, 0 ) . 'px'; | |
| 1583 | + | |
| 1584 | + if ( $toggle_position === 'on' && strrpos( $layout_id, 'overlay' ) !== false ) { | |
| 1585 | + $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_overlay { left: $offset !important; right: initial !important; }"; | |
| 1586 | + } else if ( strrpos( $layout_id, 'overlay' ) !== false ) { | |
| 1587 | + $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_overlay { right: $offset !important; }"; | |
| 1588 | + } | |
| 1589 | + if ( $toggle_position === 'on' && strrpos( $layout_id, 'banner' ) !== false ) { | |
| 1590 | + $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_banner { bottom: $offset !important; top: initial !important; }"; | |
| 1591 | + } else if ( strrpos( $layout_id, 'banner' ) !== false ) { | |
| 1592 | + $css .= "#fca_eoi_form_$form_id .fca_eoi_layout_banner { top: $offset !important; }"; | |
| 1593 | + } | |
| 1594 | + | |
| 1465 | 1595 | //VENDOR PREFIXED PLACEHOLDER COLORS |
| 1466 | 1596 | $placeholder_color = K::get_var( 'email_font_color', $meta, '#000000' ); |
| 1467 | 1597 | $css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element::-webkit-input-placeholder {opacity:0.6;color:$placeholder_color;}"; |
| 1468 | 1598 | $css .= "#fca_eoi_form_$form_id .fca_eoi_form_input_element::-moz-placeholder {opacity:0.6;color:$placeholder_color;}"; |
| @@ -1520,8 +1650,11 @@ | ||
| 1520 | 1650 | |
| 1521 | 1651 | } |
| 1522 | 1652 | } |
| 1523 | 1653 | |
| 1654 | + $animation = isset( $_POST['fca_eoi_animations'] ) && isset( $_POST['fca_eoi_show_animation_checkbox'] ) ? $_POST['fca_eoi_animations'] : ''; | |
| 1655 | + update_post_meta( $post->ID, 'fca_eoi_animation', $animation ); | |
| 1656 | + | |
| 1524 | 1657 | $head = $css . '</style>'; |
| 1525 | 1658 | |
| 1526 | 1659 | $html = fca_eoi_get_html ( $form_id, $meta ); |
| 1527 | 1660 | |
| @@ -1535,9 +1668,8 @@ | ||
| 1535 | 1668 | forEach ( $conditions as $key => $value ) { |
| 1536 | 1669 | $new_conditions[] = array ( |
| 1537 | 1670 | 'parameter' => $key, |
| 1538 | 1671 | 'value' => $value, |
| 1539 | - | |
| 1540 | 1672 | ); |
| 1541 | 1673 | } |
| 1542 | 1674 | $meta['publish_lightbox']['conditions'] = $new_conditions; |
| 1543 | 1675 | |
| @@ -1549,9 +1681,8 @@ | ||
| 1549 | 1681 | update_post_meta( $post->ID, 'fca_eoi_meta_format', '2.0' ); |
| 1550 | 1682 | update_post_meta( $post->ID, 'fca_eoi', $meta ); |
| 1551 | 1683 | update_post_meta( $post->ID, 'fca_eoi_layout', $meta[ 'layout' ] ); |
| 1552 | 1684 | update_post_meta( $post->ID, 'fca_eoi_provider', $meta[ 'provider' ] ); |
| 1553 | - update_post_meta( $post->ID, 'fca_eoi_animation', $animation ); | |
| 1554 | 1685 | update_post_meta( $post->ID, 'fca_eoi_head', $head ); |
| 1555 | 1686 | |
| 1556 | 1687 | } |
| 1557 | 1688 | } |
| @@ -1596,27 +1727,27 @@ | ||
| 1596 | 1727 | wp_enqueue_style( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css', array(), FCA_EOI_VER ); |
| 1597 | 1728 | wp_enqueue_script( 'accordion' ); |
| 1598 | 1729 | |
| 1599 | 1730 | if ( !empty( $options['animation'] ) ) { |
| 1600 | - wp_enqueue_style( 'fca_eoi_powerups_animate', FCA_EOI_PLUGIN_URL . '/assets/vendor/animate/animate.css', array(), FCA_EOI_VER ); | |
| 1731 | + wp_enqueue_style( 'fca_eoi_powerups_animate', FCA_EOI_PLUGIN_URL . '/assets/vendor/animate/animate.min.css', array(), FCA_EOI_VER ); | |
| 1601 | 1732 | } |
| 1602 | 1733 | |
| 1603 | 1734 | //LOAD CUSTOM AJAX SPINNER CODE/CSS |
| 1604 | - wp_enqueue_script( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.js', array(), FCA_EOI_VER, true ); | |
| 1605 | - wp_enqueue_style( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.css', array(), FCA_EOI_VER ); | |
| 1735 | + wp_enqueue_script( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.min.js', array(), FCA_EOI_VER, true ); | |
| 1736 | + wp_enqueue_style( 'fca-eoi-ajax-spinner', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-ajax-spinner.min.css', array(), FCA_EOI_VER ); | |
| 1606 | 1737 | |
| 1607 | 1738 | //LOAD COMMON CSS |
| 1608 | - wp_enqueue_style( 'fca_eoi', FCA_EOI_PLUGIN_URL .'/assets/style-new.css', array(), FCA_EOI_VER ); | |
| 1739 | + wp_enqueue_style( 'fca-eoi-common-css', FCA_EOI_PLUGIN_URL .'/assets/style-new.min.css', array(), FCA_EOI_VER ); | |
| 1609 | 1740 | |
| 1610 | 1741 | //LOAD EDITOR JS |
| 1611 | - 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 ); | |
| 1612 | - wp_enqueue_script( 'fca-eoi-rules', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-rules.js', array('jquery' ), FCA_EOI_VER, true ); | |
| 1742 | + wp_enqueue_script( 'fca-eoi-editor', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-editor.min.js', array('jquery', 'fca_eoi_tooltipster', 'wp-color-picker', 'select2', 'accordion' ), FCA_EOI_VER, true ); | |
| 1743 | + wp_enqueue_script( 'fca-eoi-rules', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-rules.min.js', array('jquery' ), FCA_EOI_VER, true ); | |
| 1613 | 1744 | |
| 1614 | 1745 | //LOAD PROVIDER JS AND CSS |
| 1615 | 1746 | foreach ( $providers_available as $provider ) { |
| 1616 | - 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 ); | |
| 1747 | + wp_enqueue_script( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . '/providers/' . $provider . '/cpt-easy-opt-ins.min.js', array(), FCA_EOI_VER, true ); | |
| 1617 | 1748 | |
| 1618 | - $css_path = '/providers/' . $provider . '/cpt-easy-opt-ins.css'; | |
| 1749 | + $css_path = '/providers/' . $provider . '/cpt-easy-opt-ins.min.css'; | |
| 1619 | 1750 | if ( is_readable( FCA_EOI_PLUGIN_DIR . $css_path ) ) { |
| 1620 | 1751 | wp_enqueue_style( 'admin-cpt-easy-opt-ins-' . $provider, FCA_EOI_PLUGIN_URL . $css_path, array(), FCA_EOI_VER ); |
| 1621 | 1752 | } |
| 1622 | 1753 | } |
| @@ -1621,26 +1752,26 @@ | ||
| 1621 | 1752 | } |
| 1622 | 1753 | } |
| 1623 | 1754 | //SEND VARIABLES TO JS |
| 1624 | 1755 | $useGroups = empty ( $options['mailchimp_groups'] ) ? array('off') : array('on') ; |
| 1625 | - wp_localize_script( 'admin-cpt-easy-opt-ins-mailchimp', 'useGroups', $useGroups ); | |
| 1756 | + wp_localize_script( 'admin-cpt-easy-opt-ins-mailchimp', 'fcaEoiUseGroups', $useGroups ); | |
| 1626 | 1757 | |
| 1627 | 1758 | $tags = empty($meta['aweber_tags']) ? '' : $meta['aweber_tags']; |
| 1628 | 1759 | $aweberSettings = array( |
| 1629 | 1760 | 'tags' => $tags, |
| 1630 | 1761 | ); |
| 1631 | - wp_localize_script( 'admin-cpt-easy-opt-ins-aweber', 'aweberSettings', $aweberSettings ); | |
| 1762 | + wp_localize_script( 'admin-cpt-easy-opt-ins-aweber', 'fcaEoiAweberSettings', $aweberSettings ); | |
| 1632 | 1763 | |
| 1633 | 1764 | $file = plugin_dir_path( __FILE__ ) . "layout-cache"; |
| 1634 | 1765 | $layout_data = unserialize (file_get_contents($file)); |
| 1635 | 1766 | |
| 1636 | - wp_localize_script( 'fca-eoi-editor', 'layouts', $layout_data ); | |
| 1767 | + wp_localize_script( 'fca-eoi-editor', 'fcaEoiLayouts', $layout_data ); | |
| 1637 | 1768 | |
| 1638 | 1769 | //EDITOR CSS |
| 1639 | - wp_enqueue_style( 'admin-cpt-easy-opt-ins', FCA_EOI_PLUGIN_URL . '/assets/admin/cpt-easy-opt-ins.css', array(), FCA_EOI_VER ); | |
| 1770 | + wp_enqueue_style( 'fca-eoi-editor-css', FCA_EOI_PLUGIN_URL . '/assets/admin/fca-eoi-editor.min.css', array(), FCA_EOI_VER ); | |
| 1640 | 1771 | |
| 1641 | 1772 | if ( has_action( 'fca_eoi_powerups' ) ) { |
| 1642 | - wp_enqueue_script('fca_eoi_powerups', FCA_EOI_PLUGIN_URL . '/assets/powerups/fca_eoi_powerups.js', array(), FCA_EOI_VER, true); | |
| 1773 | + wp_enqueue_script('fca_eoi_powerups', FCA_EOI_PLUGIN_URL . '/assets/powerups/fca_eoi_powerups.min.js', array(), FCA_EOI_VER, true); | |
| 1643 | 1774 | } |
| 1644 | 1775 | } |
| 1645 | 1776 | if( 'widgets' === $screen->id ){ |
| 1646 | 1777 | wp_enqueue_script( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js', array(), FCA_EOI_VER, true ); |
| @@ -1670,9 +1801,9 @@ | ||
| 1670 | 1801 | $posts = get_posts( 'posts_per_page=-1&post_type=easy-opt-ins' ); |
| 1671 | 1802 | |
| 1672 | 1803 | if ( empty ( $posts ) ) { |
| 1673 | 1804 | |
| 1674 | - wp_enqueue_style( 'fca_eoi_onboard_stylesheet', FCA_EOI_PLUGIN_URL . '/assets/admin/onboard.css', array(), FCA_EOI_VER ); | |
| 1805 | + wp_enqueue_style( 'fca_eoi_onboard_stylesheet', FCA_EOI_PLUGIN_URL . '/assets/admin/onboard.min.css', array(), FCA_EOI_VER ); | |
| 1675 | 1806 | |
| 1676 | 1807 | echo '<div class="error fca_eoi_onboard_div">'; |
| 1677 | 1808 | |
| 1678 | 1809 | echo '<img id="fca_eoi_onboard_text" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/onboarding-text.png' . '">'; |
| @@ -1681,8 +1812,32 @@ | ||
| 1681 | 1812 | } |
| 1682 | 1813 | } |
| 1683 | 1814 | } |
| 1684 | 1815 | |
| 1816 | + public function google_changes_notice() { | |
| 1817 | + | |
| 1818 | + $dismissed = get_option ( 'fca_eoi_dismiss_google_changes' ); | |
| 1819 | + | |
| 1820 | + if ( $dismissed !== 'true' ) { | |
| 1821 | + | |
| 1822 | + wp_enqueue_script( 'fca_eoi_dismiss_review_js', FCA_EOI_PLUGIN_URL . '/assets/admin/dismiss.min.js', array(), FCA_EOI_VER ); | |
| 1823 | + wp_localize_script( 'fca_eoi_dismiss_review_js', 'fcaEoiDismiss', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'fca_eoi_dismiss' ) ) ); | |
| 1824 | + $blog_link = 'https://fatcatapps.com/interstitials-update/'; | |
| 1825 | + | |
| 1826 | + echo '<div class="notice notice-info fca_eoi_review_div" style="padding-bottom: 8px;">'; | |
| 1827 | + echo '<img style="float:left" width="120" height="120" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/optincat.png' . '">'; | |
| 1828 | + echo '<p><strong>' . __( "Optin Cat: New Google algorithm update may affect your rankings", 'easy-opt-ins' ) . '</strong></p>'; | |
| 1829 | + | |
| 1830 | + echo '<p>' . __( "Google has recently made changes to its mobile search results. These changes may negatively impact sites that use popups on mobile devices if no action is taken.", 'easy-opt-ins') . '</p>'; | |
| 1831 | + echo '<br>'; | |
| 1832 | + | |
| 1833 | + echo "<a target='_blank' href='$blog_link' class='button button-primary'>" . __( 'Learn More & Fix This', 'easy-opt-ins') . "</a> "; | |
| 1834 | + echo "<button type='button' class='button button-secondary' data-option='fca_eoi_dismiss_google_changes' id='fca-eoi-dismiss-review-btn'>" . __( 'Dismiss', 'easy-opt-ins') . "</button>"; | |
| 1835 | + echo '<br style="clear:both">'; | |
| 1836 | + echo '</div>'; | |
| 1837 | + } | |
| 1838 | + } | |
| 1839 | + | |
| 1685 | 1840 | public function review_notice() { |
| 1686 | 1841 | |
| 1687 | 1842 | $dismissed = get_option ( 'fca_eoi_dismiss_review' ); |
| 1688 | 1843 | |
| @@ -1694,10 +1849,10 @@ | ||
| 1694 | 1849 | |
| 1695 | 1850 | if ( $conversions >= 25 ) { |
| 1696 | 1851 | $review_link = 'https://wordpress.org/support/plugin/' . FCA_EOI_PLUGIN_SLUG . '/reviews/?rate=5#new-post'; |
| 1697 | 1852 | |
| 1698 | - wp_enqueue_script( 'fca_eoi_dismiss_review_js', FCA_EOI_PLUGIN_URL . '/assets/admin/dismiss.js', array(), FCA_EOI_VER ); | |
| 1699 | - wp_localize_script( 'fca_eoi_dismiss_review_js', 'fca_eoi', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'fca_eoi_dismiss' ) ) ); | |
| 1853 | + wp_enqueue_script( 'fca_eoi_dismiss_review_js', FCA_EOI_PLUGIN_URL . '/assets/admin/dismiss.min.js', array(), FCA_EOI_VER ); | |
| 1854 | + wp_localize_script( 'fca_eoi_dismiss_review_js', 'fcaEoiDismiss', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'fca_eoi_dismiss' ) ) ); | |
| 1700 | 1855 | |
| 1701 | 1856 | echo '<div class="notice notice-success fca_eoi_review_div">'; |
| 1702 | 1857 | echo '<img style="float:left" width="120" height="120" src="' . FCA_EOI_PLUGIN_URL . '/assets/admin/optincat.png' . '">'; |
| 1703 | 1858 | echo '<p><strong>' . __( "Great work! You've gotten more than 25 email subscribers using Optin Cat.", 'easy-opt-ins' ) . '</strong></p>'; |
| @@ -1705,9 +1860,9 @@ | ||
| 1705 | 1860 | echo '<p>' . sprintf( __( "If you love Optin Cat, why not leave us a nice review on %sWordPress.org%s? Reviews keeps us motivated - we'd really appreciate it.", 'easy-opt-ins' ), "<a target='_blank' href='$review_link'>", '</a>') . '</p>'; |
| 1706 | 1861 | echo '<br>'; |
| 1707 | 1862 | |
| 1708 | 1863 | echo "<a target='_blank' href='$review_link' class='button button-primary'>" . __( 'Leave a Review', 'easy-opt-ins') . "</a> "; |
| 1709 | - echo "<button type='button' class='button button-secondary' id='fca-eoi-dismiss-review-btn'>" . __( 'Dismiss', 'easy-opt-ins') . "</button>"; | |
| 1864 | + echo "<button type='button' class='button button-secondary' data-option='fca_eoi_dismiss_review' id='fca-eoi-dismiss-review-btn'>" . __( 'Dismiss', 'easy-opt-ins') . "</button>"; | |
| 1710 | 1865 | echo '<br style="clear:both">'; |
| 1711 | 1866 | echo '</div>'; |
| 1712 | 1867 | |
| 1713 | 1868 | } |
| @@ -1716,17 +1871,16 @@ | ||
| 1716 | 1871 | |
| 1717 | 1872 | public function ajax_dismiss_notice() { |
| 1718 | 1873 | |
| 1719 | 1874 | $nonce = empty ( $_REQUEST['nonce'] ) ? '' : $_REQUEST['nonce']; |
| 1875 | + $option = empty ( $_REQUEST['option'] ) ? 'fca_eoi_dismiss_review' : $_REQUEST['option']; | |
| 1720 | 1876 | |
| 1721 | 1877 | if ( wp_verify_nonce ( $nonce, 'fca_eoi_dismiss') == 1 ) { |
| 1722 | - $result = update_option( 'fca_eoi_dismiss_review', 'true' ); | |
| 1723 | - if ( $result ) { | |
| 1724 | - echo 'success'; | |
| 1878 | + if ( update_option( $option, 'true' ) ) { | |
| 1879 | + wp_send_json_success( $option ); | |
| 1725 | 1880 | } |
| 1726 | - | |
| 1727 | 1881 | } |
| 1728 | - wp_die(); // this is required to terminate immediately and return a proper response | |
| 1882 | + wp_send_json_error(); | |
| 1729 | 1883 | } |
| 1730 | 1884 | |
| 1731 | 1885 | /** |
| 1732 | 1886 | * Forces one column |
| @@ -1963,27 +2117,22 @@ | ||
| 1963 | 2117 | } |
| 1964 | 2118 | |
| 1965 | 2119 | add_action( 'wp', array( $this, 'content' ), 10 ); |
| 1966 | 2120 | } |
| 1967 | - | |
| 2121 | + | |
| 2122 | + //SEARCH THE CONTENT AND APPEND ANY RELEVANT POST BOXES | |
| 1968 | 2123 | public function content() { |
| 1969 | - //RN NOTE WAT | |
| 2124 | + | |
| 1970 | 2125 | global $post; |
| 1971 | - | |
| 1972 | - if ( empty( $post ) ) { | |
| 2126 | + | |
| 2127 | + // Work only when viewing a post of any type & not viewing an opt-in editor | |
| 2128 | + if ( empty( $post ) OR $post->post_type === 'easy-opt-ins' ) { | |
| 1973 | 2129 | return; |
| 1974 | 2130 | } |
| 2131 | + | |
| 2132 | + //ADD SESSION COOKIE TRACKING SCRIPT | |
| 2133 | + wp_enqueue_script( 'fca_eoi_pagecount_js', FCA_EOI_PLUGIN_URL.'/assets/pagecount.min.js', array(), FCA_EOI_VER, true ); | |
| 1975 | 2134 | |
| 1976 | - // Do nothing if viewing an opt-in | |
| 1977 | - if ( 'easy-opt-ins' === $post->post_type ) { | |
| 1978 | - return; | |
| 1979 | - } | |
| 1980 | - | |
| 1981 | - // Work only when viewing a post of any type | |
| 1982 | - if ( empty( $post ) ) { | |
| 1983 | - return; | |
| 1984 | - } | |
| 1985 | - | |
| 1986 | 2135 | $priorities = array(); |
| 1987 | 2136 | |
| 1988 | 2137 | // Post details |
| 1989 | 2138 | $post_ID = $post->ID; |
| @@ -2000,10 +2149,10 @@ | ||
| 2000 | 2149 | } |
| 2001 | 2150 | |
| 2002 | 2151 | $priorities[] = '#' . $post_ID; |
| 2003 | 2152 | |
| 2004 | - $taxonomies = get_taxonomies('','names'); | |
| 2005 | - $post_taxonomies = wp_get_object_terms( $post->ID,$taxonomies); | |
| 2153 | + $taxonomies = get_taxonomies('', 'names'); | |
| 2154 | + $post_taxonomies = wp_get_object_terms( $post->ID, $taxonomies); | |
| 2006 | 2155 | foreach ( $post_taxonomies as $t ) { |
| 2007 | 2156 | $condition = $post_type . ':' . $t->term_id; |
| 2008 | 2157 | |
| 2009 | 2158 | $post_cond[] = $condition; |
| @@ -2012,28 +2161,22 @@ | ||
| 2012 | 2161 | |
| 2013 | 2162 | $priorities[] = $post_type; |
| 2014 | 2163 | $priorities[] = '*'; |
| 2015 | 2164 | |
| 2016 | - $fca_eoi_last_99_forms = array(); | |
| 2017 | - foreach (get_posts( 'posts_per_page=99&post_type=easy-opt-ins' ) as $i => $f ) { | |
| 2018 | - $fca_eoi_last_99_forms[ $i ][ 'post' ] = $f; | |
| 2019 | - $fca_eoi_last_99_forms[ $i ][ 'fca_eoi' ] = get_post_meta( $f->ID, 'fca_eoi', true ); | |
| 2165 | + $optins = get_posts( 'posts_per_page=99&post_type=easy-opt-ins' ); | |
| 2166 | + | |
| 2167 | + $fca_eoi_postboxes = array(); | |
| 2168 | + | |
| 2169 | + foreach ( $optins as $i => $p ) { | |
| 2170 | + $fca_eoi_postboxes[ $i ][ 'post' ] = $p; | |
| 2171 | + $fca_eoi_postboxes[ $i ][ 'fca_eoi' ] = get_post_meta( $p->ID, 'fca_eoi', true ); | |
| 2020 | 2172 | } |
| 2021 | - // wp_reset_query(); | |
| 2022 | 2173 | |
| 2023 | 2174 | $postboxes = array(); |
| 2024 | 2175 | |
| 2025 | 2176 | // Append postcode shortcode when the conditions match |
| 2026 | - foreach( $fca_eoi_last_99_forms as $f) { | |
| 2177 | + foreach( $fca_eoi_postboxes as $f ) { | |
| 2027 | 2178 | |
| 2028 | - // Exclude other layout types | |
| 2029 | - if ( empty ( $f[ 'fca_eoi' ][ 'layout' ] ) ) { | |
| 2030 | - continue; | |
| 2031 | - } | |
| 2032 | - if ( strpos( $f[ 'fca_eoi' ][ 'layout' ], 'postbox_' ) !== 0 ) { | |
| 2033 | - continue; | |
| 2034 | - } | |
| 2035 | - | |
| 2036 | 2179 | // Get conditions |
| 2037 | 2180 | $eoi_form_cond = K::get_var( 'publish_postbox', $f[ 'fca_eoi' ], array() ); |
| 2038 | 2181 | |
| 2039 | 2182 | // Append |
| @@ -2047,9 +2190,9 @@ | ||
| 2047 | 2190 | } |
| 2048 | 2191 | |
| 2049 | 2192 | if ( ! empty( $postboxes ) ) { |
| 2050 | 2193 | foreach ( $priorities as $cond ) { |
| 2051 | - if ( ! empty( $postboxes[ $cond ] ) ) { | |
| 2194 | + if ( !empty( $postboxes[ $cond ] ) ) { | |
| 2052 | 2195 | $post->post_content .= $postboxes[ $cond ]; |
| 2053 | 2196 | return; |
| 2054 | 2197 | } |
| 2055 | 2198 | } |
| @@ -2058,144 +2201,168 @@ | ||
| 2058 | 2201 | return; |
| 2059 | 2202 | } |
| 2060 | 2203 | } |
| 2061 | 2204 | |
| 2062 | - private function get_tc_token( $form_id ) { | |
| 2063 | - return "$form_id"; | |
| 2064 | - } | |
| 2065 | - | |
| 2066 | - private function to_call_tc_condition( $name, $arguments ) { | |
| 2067 | - return array_merge( array( $name ), $arguments ); | |
| 2068 | - } | |
| 2069 | - | |
| 2070 | - private function to_value_tc_condition( $form_id, $name, $eoi_condition ) { | |
| 2071 | - $value = intval( $eoi_condition['value'] ); | |
| 2072 | - $params = array( $value ); | |
| 2073 | - | |
| 2074 | - if ( $name === 'page_views' ) { | |
| 2075 | - $params[] = $this->get_tc_token( $form_id ); | |
| 2076 | - } else if ( $name === 'time_on_page' ) { | |
| 2077 | - $params[0] *= 1000; | |
| 2205 | + public function scan_for_shortcodes( $content ) { | |
| 2206 | + if ( preg_match_all( '/data-optin-cat\s*=\s*["\']?\s*(\d+)/', $content, $matches ) ) { | |
| 2207 | + $this->two_step_ids_on_page = array_map( 'intval', $matches[1] ); | |
| 2078 | 2208 | } |
| 2079 | 2209 | |
| 2080 | - return $this->to_call_tc_condition( $name, $params ); | |
| 2210 | + return $content; | |
| 2081 | 2211 | } |
| 2082 | 2212 | |
| 2083 | - private function to_server_pass_tc_condition( $post_id, $parameter, $eoi_condition ) { | |
| 2084 | - $url = add_query_arg( array( | |
| 2085 | - 'fca_eoi_tc_condition_pass' => urlencode( $parameter ), | |
| 2086 | - 'fca_eoi_tc_condition_value' => urlencode( implode( ',', $eoi_condition['value'] ) ), | |
| 2087 | - 'fca_eoi_tc_condition_post_id' => $post_id | |
| 2213 | + public function maybe_show_lightbox() { | |
| 2214 | + | |
| 2215 | + // Get lightboxes | |
| 2216 | + $lightboxes = get_posts( array( | |
| 2217 | + 'post_type' => 'easy-opt-ins', | |
| 2218 | + 'posts_per_page' => -1, | |
| 2219 | + 'orderby' => 'ID', | |
| 2220 | + 'meta_key' => 'fca_eoi_layout', | |
| 2221 | + 'meta_value' => 'lightbox_', | |
| 2222 | + 'meta_compare' => 'like', | |
| 2088 | 2223 | ) ); |
| 2224 | + | |
| 2225 | + // BANNERS | |
| 2226 | + $banners = get_posts( array( | |
| 2227 | + 'post_type' => 'easy-opt-ins', | |
| 2228 | + 'posts_per_page' => -1, | |
| 2229 | + 'orderby' => 'ID', | |
| 2230 | + 'meta_key' => 'fca_eoi_layout', | |
| 2231 | + 'meta_value' => 'banner_', | |
| 2232 | + 'meta_compare' => 'like', | |
| 2233 | + ) ); | |
| 2234 | + | |
| 2235 | + //OVERLAY AND BANNERS WORK FUNCTIONALLY THE SAME | |
| 2236 | + $banners = array_merge ( $banners, get_posts( array( | |
| 2237 | + 'post_type' => 'easy-opt-ins', | |
| 2238 | + 'posts_per_page' => -1, | |
| 2239 | + 'orderby' => 'ID', | |
| 2240 | + 'meta_key' => 'fca_eoi_layout', | |
| 2241 | + 'meta_value' => 'overlay_', | |
| 2242 | + 'meta_compare' => 'like', | |
| 2243 | + ) ) ); | |
| 2089 | 2244 | |
| 2090 | - return $this->to_call_tc_condition( 'server_pass', array( $url, 'true' ) ); | |
| 2091 | - } | |
| 2092 | - | |
| 2093 | - private function to_tc_condition( $form_id, $post_id, $eoi_condition ) { | |
| 2094 | - $eoi_to_tc_value_map = array( | |
| 2095 | - 'pageviews' => 'page_views', | |
| 2096 | - 'scrolled_percent' => 'scroll_percent', | |
| 2097 | - 'time_on_page' => 'time_on_page' | |
| 2098 | - ); | |
| 2099 | - | |
| 2100 | - $eoi_server_pass_conditions = array( 'include', 'exclude' ); | |
| 2101 | - | |
| 2102 | - $parameter = $eoi_condition['parameter']; | |
| 2103 | - if ( array_key_exists( $parameter, $eoi_to_tc_value_map ) ) { | |
| 2104 | - return $this->to_value_tc_condition( $form_id, $eoi_to_tc_value_map[ $parameter ], $eoi_condition ); | |
| 2105 | - } else if ( in_array( $parameter, $eoi_server_pass_conditions ) ) { | |
| 2106 | - return $this->to_server_pass_tc_condition( $post_id, $parameter, $eoi_condition ); | |
| 2245 | + if( empty( $lightboxes ) && empty ( $banners ) ) { | |
| 2246 | + return false; | |
| 2107 | 2247 | } |
| 2108 | 2248 | |
| 2109 | - return null; | |
| 2110 | - } | |
| 2111 | - | |
| 2112 | - private function to_show_every_tc_condition( $form_id, $condition ) { | |
| 2113 | - if ( in_array( $condition, array( 'day', 'month', 'once', 'session' ) ) ) { | |
| 2114 | - return array( $condition, $this->get_tc_token( $form_id ) ); | |
| 2115 | - } elseif ( $condition === 'always' ) { | |
| 2116 | - return 'true'; | |
| 2117 | - } elseif ( $condition === 'never' ) { | |
| 2118 | - return 'false'; | |
| 2249 | + $two_step_popups = array(); | |
| 2250 | + $traditional_popups = array(); | |
| 2251 | + $banners_to_show = array(); | |
| 2252 | + | |
| 2253 | + foreach ( $banners as $banner ) { | |
| 2254 | + $m = get_post_meta( $banner->ID , 'fca_eoi', true ); | |
| 2255 | + $conditions = K::get_var( 'publish_lightbox', $m, array() ); | |
| 2256 | + | |
| 2257 | + if ( $this->test_server_conditions( $conditions ) ) { | |
| 2258 | + $banners_to_show[] = array( | |
| 2259 | + 'id' => $banner->ID, | |
| 2260 | + 'meta' => $m, | |
| 2261 | + 'conditions' => $conditions, | |
| 2262 | + ); | |
| 2263 | + } | |
| 2119 | 2264 | } |
| 2265 | + | |
| 2266 | + foreach ( $lightboxes as $lightbox ) { | |
| 2120 | 2267 | |
| 2121 | - return $condition; | |
| 2122 | - } | |
| 2123 | - | |
| 2124 | - private function get_tc_conditions( $form_id, $post_id, $conditions ) { | |
| 2125 | - $tc_conditions = array(); | |
| 2126 | - $sequence_conditions = array(); | |
| 2127 | - | |
| 2128 | - if ( isSet( $conditions['live'] ) && $conditions['live'] === false ) { | |
| 2129 | - return array( 'false' ); | |
| 2130 | - } | |
| 2131 | - if ( ! empty( $conditions['show_every'] ) ) { | |
| 2132 | - $condition = $this->to_show_every_tc_condition( $form_id, $conditions['show_every'] ); | |
| 2268 | + // Get conditions | |
| 2269 | + $lightbox->fca_eoi = get_post_meta( $lightbox->ID , 'fca_eoi', true ); | |
| 2270 | + $publish_lightbox_mode = K::get_var( 'publish_lightbox_mode', $lightbox->fca_eoi, array() ); | |
| 2133 | 2271 | |
| 2134 | - if ( $condition === 'false' ) { | |
| 2135 | - return array( 'false' ); | |
| 2136 | - } else { | |
| 2137 | - $sequence_conditions[] = $condition; | |
| 2272 | + $lightbox_conditions = K::get_var( 'publish_lightbox', $lightbox->fca_eoi, array() ); | |
| 2273 | + | |
| 2274 | + // If on a free distribution, force traditional popup mode | |
| 2275 | + if ( $this->settings['distribution'] === 'free' ) { | |
| 2276 | + $publish_lightbox_mode = 'traditional_popup'; | |
| 2138 | 2277 | } |
| 2278 | + | |
| 2279 | + if ( 'two_step_optin' === $publish_lightbox_mode ) { | |
| 2280 | + $two_step_popups[] = $lightbox->ID; | |
| 2281 | + } else if ( $this->test_server_conditions( $lightbox_conditions ) ) { | |
| 2282 | + $traditional_popups[] = array( | |
| 2283 | + 'id' => $lightbox->ID, | |
| 2284 | + 'meta' => $lightbox->fca_eoi, | |
| 2285 | + 'conditions' => $lightbox_conditions, | |
| 2286 | + ); | |
| 2287 | + } | |
| 2139 | 2288 | } |
| 2140 | - | |
| 2141 | - if ( ! empty( $conditions['conditions'] ) ) { | |
| 2142 | - foreach ( $conditions['conditions'] as $condition ) { | |
| 2143 | - if ( $condition['parameter'] === 'exit_intervention' ) { | |
| 2144 | - $sequence_conditions[] = 'exit'; | |
| 2145 | - continue; | |
| 2146 | - } | |
| 2147 | - | |
| 2148 | - $tc_condition = $this->to_tc_condition( $form_id, $post_id, $condition ); | |
| 2149 | - if ( ! empty( $tc_condition ) ) { | |
| 2150 | - $tc_conditions[] = $tc_condition; | |
| 2151 | - } | |
| 2152 | - } | |
| 2289 | + | |
| 2290 | + $two_step_popups = array_intersect( $two_step_popups, $this->two_step_ids_on_page ); | |
| 2291 | + | |
| 2292 | + if ( !empty( $traditional_popups ) OR !empty( $two_step_popups ) OR !empty( $banners_to_show ) ) { | |
| 2293 | + wp_enqueue_script ( 'jquery' ); | |
| 2294 | + wp_enqueue_style( 'fca_eoi_tooltipster_css', FCA_EOI_PLUGIN_URL.'/assets/vendor/tooltipster/tooltipster.bundle.min.css', array(), FCA_EOI_VER ); | |
| 2295 | + wp_enqueue_style( 'fca_eoi_tooltipster_borderless', FCA_EOI_PLUGIN_URL.'/assets/vendor/tooltipster/tooltipster-borderless.min.css', array(), FCA_EOI_VER ); | |
| 2296 | + wp_enqueue_script( 'fca_eoi_tooltipster_js', FCA_EOI_PLUGIN_URL.'/assets/vendor/tooltipster/tooltipster.bundle.min.js', array(), FCA_EOI_VER, true ); | |
| 2297 | + | |
| 2298 | + wp_enqueue_script( 'fca_eoi_featherlight_js', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.js', array(), FCA_EOI_VER, true ); | |
| 2299 | + wp_enqueue_style( 'fca_eoi_featherlight_css', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.css', array(), FCA_EOI_VER ); | |
| 2300 | + | |
| 2301 | + wp_enqueue_script( 'fca_eoi_jstz', FCA_EOI_PLUGIN_URL . '/assets/vendor/jstz/jstz.min.js', array(), FCA_EOI_VER, true ); | |
| 2302 | + | |
| 2303 | + wp_enqueue_script( 'fca_eoi_script_js', FCA_EOI_PLUGIN_URL.'/assets/script.min.js', array( 'fca_eoi_jstz', 'jquery', 'fca_eoi_tooltipster_js', 'fca_eoi_featherlight_js' ), FCA_EOI_VER, true ); | |
| 2304 | + | |
| 2305 | + $data = array ( | |
| 2306 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 2307 | + 'nonce' => wp_create_nonce( 'fca_eoi_submit_form' ), | |
| 2308 | + ); | |
| 2309 | + wp_localize_script( 'fca_eoi_script_js', 'fcaEoiScriptData', $data ); | |
| 2310 | + | |
| 2311 | + empty ( $traditional_popups ) ? '' : $this->display_traditional_popups( $traditional_popups ); | |
| 2312 | + empty ( $two_step_popups ) ? '' : $this->display_two_step_popups( $two_step_popups ); | |
| 2313 | + empty ( $banners_to_show ) ? '' : $this->display_banners( $banners_to_show ); | |
| 2153 | 2314 | } |
| 2154 | 2315 | |
| 2155 | - $has_conditions = ! empty ( $tc_conditions ); | |
| 2156 | - if ( $has_conditions ) { | |
| 2157 | - $tc_conditions = array( 'and' => $tc_conditions ); | |
| 2316 | + } | |
| 2317 | + | |
| 2318 | + public function test_server_conditions( $conditions ) { | |
| 2319 | + | |
| 2320 | + //CHECK FOR LIVE | |
| 2321 | + if ( ! K::get_var( 'live', $conditions, true ) ) { | |
| 2322 | + return false; | |
| 2158 | 2323 | } |
| 2159 | - | |
| 2160 | - if ( $sequence_conditions ) { | |
| 2161 | - if ( $has_conditions ) { | |
| 2162 | - $tc_conditions = array( 'sequence' => array( $tc_conditions ) ); | |
| 2163 | - } else { | |
| 2164 | - $tc_conditions = array( 'sequence' => array() ); | |
| 2324 | + | |
| 2325 | + //CHECK MOBILE | |
| 2326 | + $mobile_detect = new Mobile_Detect; | |
| 2327 | + $is_mobile = $mobile_detect->isMobile(); | |
| 2328 | + | |
| 2329 | + $mobile_mode = K::get_var( 'devices', $conditions, 'all' ); | |
| 2330 | + $fail_mobile = $mobile_mode === 'mobile' && !$is_mobile; | |
| 2331 | + $fail_desktop = $mobile_mode === 'desktop' && $is_mobile; | |
| 2332 | + $pass_mobile = !$fail_mobile && !$fail_desktop; | |
| 2333 | + | |
| 2334 | + if ( empty( $conditions['conditions'] ) ) { | |
| 2335 | + return $pass_mobile; | |
| 2336 | + } | |
| 2337 | + | |
| 2338 | + //CHECK INCLUDED AND EXCLUDED PAGES & TAXONOMIES | |
| 2339 | + global $post; | |
| 2340 | + $post_id = $post->ID; | |
| 2341 | + | |
| 2342 | + $includes = array(); | |
| 2343 | + $excludes = array(); | |
| 2344 | + | |
| 2345 | + forEach ( $conditions['conditions'] as $condition ) { | |
| 2346 | + if ( $condition['parameter'] === 'exclude' ) { | |
| 2347 | + $excludes = $condition['value']; | |
| 2348 | + } else if ( $condition['parameter'] === 'include' ) { | |
| 2349 | + $includes = $condition['value']; | |
| 2165 | 2350 | } |
| 2166 | - foreach ( $sequence_conditions as $condition ) { | |
| 2167 | - $tc_conditions['sequence'][] = $condition; | |
| 2168 | - } | |
| 2169 | 2351 | } |
| 2170 | - | |
| 2171 | - return $tc_conditions; | |
| 2172 | - } | |
| 2173 | - | |
| 2174 | - private function echo_tc_conditions_for_form( $form_id, $post_id ) { | |
| 2175 | - $fca_eoi = get_post_meta( $form_id , 'fca_eoi', true ); | |
| 2176 | - $publish_lightbox = K::get_var( 'publish_lightbox', $fca_eoi, array() ); | |
| 2177 | - | |
| 2178 | - header( 'Content-Type: application/json' ); | |
| 2179 | - exit( json_encode( $this->get_tc_conditions( $form_id, $post_id, $publish_lightbox ) ) ); | |
| 2180 | - } | |
| 2181 | - | |
| 2182 | - private function echo_tc_condition_pass( $post_id, $type, $values ) { | |
| 2352 | + | |
| 2183 | 2353 | $post_cond = array( '*' ); |
| 2184 | - | |
| 2354 | + | |
| 2185 | 2355 | if ( is_front_page() ) { |
| 2186 | 2356 | $post_cond[] = '~'; |
| 2187 | 2357 | } |
| 2188 | - | |
| 2358 | + | |
| 2189 | 2359 | if ( $post_id ) { |
| 2190 | 2360 | $post_type = get_post_type( $post_id ); |
| 2191 | - | |
| 2192 | 2361 | $post_cond[] = $post_type; |
| 2193 | 2362 | $post_cond[] = '#' . $post_id; |
| 2194 | - | |
| 2195 | 2363 | $taxonomies = get_taxonomies( '', 'names' ); |
| 2196 | 2364 | $post_taxonomies = wp_get_object_terms( $post_id, $taxonomies ); |
| 2197 | - | |
| 2198 | 2365 | foreach ( $post_taxonomies as $t ) { |
| 2199 | 2366 | $post_cond[] = $post_type . ':' . $t->term_id; |
| 2200 | 2367 | } |
| 2201 | 2368 | } else { |
| @@ -2204,595 +2371,81 @@ | ||
| 2204 | 2371 | $post_cond[] = '#' . get_option('page_for_posts'); |
| 2205 | 2372 | } |
| 2206 | 2373 | |
| 2207 | 2374 | } |
| 2208 | - | |
| 2209 | - $intersect = array_intersect( $values, $post_cond ); | |
| 2210 | - | |
| 2211 | - if ( $type === 'include' ) { | |
| 2212 | - echo $intersect ? 'true' : 'false'; | |
| 2213 | - } else if ( $type === 'exclude' ) { | |
| 2214 | - echo $intersect ? 'false' : 'true'; | |
| 2215 | - } | |
| 2216 | - | |
| 2217 | - exit; | |
| 2375 | + | |
| 2376 | + $pass_includes = empty( $includes ) ? true : count ( array_intersect( $includes, $post_cond ) ) > 0; | |
| 2377 | + $pass_excludes = empty( $excludes ) ? true : count ( array_intersect( $excludes, $post_cond ) ) == 0; | |
| 2378 | + | |
| 2379 | + return $pass_includes && $pass_excludes && $pass_mobile; | |
| 2380 | + | |
| 2218 | 2381 | } |
| 2219 | 2382 | |
| 2220 | - public function parse_tc_condition_request() { | |
| 2221 | - $post_id = empty( $_REQUEST['fca_eoi_tc_condition_post_id'] ) ? 0 : (int) $_REQUEST['fca_eoi_tc_condition_post_id']; | |
| 2383 | + private function display_two_step_popups( $lightbox_ids ) { | |
| 2384 | + wp_enqueue_script( 'fca_eoi_twostep_js', FCA_EOI_PLUGIN_URL.'/assets/twostep.min.js', array( 'jquery', 'fca_eoi_tooltipster_js', 'fca_eoi_featherlight_js', 'fca_eoi_script_js' ), FCA_EOI_VER, true ); | |
| 2222 | 2385 | |
| 2223 | - if ( ! empty( $_REQUEST['fca_eoi_tc_conditions_for'] ) ) { | |
| 2224 | - $form_id = (int) $_REQUEST['fca_eoi_tc_conditions_for']; | |
| 2225 | - $this->echo_tc_conditions_for_form( $form_id, $post_id ); | |
| 2386 | + foreach ( $lightbox_ids as $id ) { | |
| 2387 | + $this->prepare_lightbox_html( $id ); | |
| 2226 | 2388 | } |
| 2227 | - | |
| 2228 | - if ( ! empty( $_REQUEST['fca_eoi_tc_condition_pass'] ) ) { | |
| 2229 | - $this->echo_tc_condition_pass( | |
| 2230 | - $post_id, | |
| 2231 | - $_REQUEST['fca_eoi_tc_condition_pass'], | |
| 2232 | - explode( ',', $_REQUEST['fca_eoi_tc_condition_value'] ) | |
| 2233 | - ); | |
| 2234 | - } | |
| 2235 | 2389 | } |
| 2390 | + | |
| 2391 | + private function display_banners( $banners ) { | |
| 2392 | + | |
| 2393 | + $target_data = array(); | |
| 2236 | 2394 | |
| 2237 | - private function get_cookie_configuration() { | |
| 2238 | - $cookie_configuration = array(); | |
| 2395 | + forEach ( $banners as $p ) { | |
| 2396 | + $id = $p['id']; | |
| 2397 | + $target_data[$id] = empty( $p['conditions'] ) ? array() : $p['conditions']; | |
| 2239 | 2398 | |
| 2240 | - if ( defined( 'COOKIEPATH' ) ) { | |
| 2241 | - $path = COOKIEPATH; | |
| 2242 | - if ( ! empty( $path ) ) { | |
| 2243 | - $cookie_configuration['path'] = $path; | |
| 2244 | - } | |
| 2399 | + echo "<div id='fca_eoi_banner_$id' style='display:none;'>"; | |
| 2400 | + echo do_shortcode( "[easy-opt-in id=$id]" ); | |
| 2401 | + echo '</div>'; | |
| 2245 | 2402 | } |
| 2246 | 2403 | |
| 2247 | - if ( defined( 'COOKIE_DOMAIN' ) ) { | |
| 2248 | - $domain = COOKIE_DOMAIN; | |
| 2249 | - if ( ! empty( $domain ) ) { | |
| 2250 | - $cookie_configuration['domain'] = $domain; | |
| 2251 | - } | |
| 2252 | - } | |
| 2253 | - | |
| 2254 | - return $cookie_configuration; | |
| 2255 | - } | |
| 2256 | - | |
| 2257 | - public function scan_for_shortcodes( $content ) { | |
| 2258 | - if ( preg_match_all( '/data-optin-cat\s*=\s*["\']?\s*(\d+)/', $content, $matches ) ) { | |
| 2259 | - $this->two_step_ids_on_page = array_map( 'intval', $matches[1] ); | |
| 2260 | - } | |
| 2261 | - | |
| 2262 | - return $content; | |
| 2263 | - } | |
| 2264 | - | |
| 2265 | - public function show_lightbox() { | |
| 2404 | + wp_enqueue_script( 'fca_eoi_targeting_js', FCA_EOI_PLUGIN_URL.'/assets/targeting.min.js', array( 'jquery' ), FCA_EOI_VER, true ); | |
| 2266 | 2405 | |
| 2267 | - // Get lightboxes | |
| 2268 | - $lightboxes = get_posts( array( | |
| 2269 | - 'post_type' => 'easy-opt-ins', | |
| 2270 | - 'posts_per_page' => -1, | |
| 2271 | - 'orderby' => 'ID', | |
| 2272 | - 'meta_key' => 'fca_eoi_layout', | |
| 2273 | - 'meta_value' => 'lightbox_', | |
| 2274 | - 'meta_compare' => 'like', | |
| 2275 | - ) ); | |
| 2276 | - | |
| 2277 | - // Exit function if no lightbox found | |
| 2278 | - if( ! $lightboxes ) { | |
| 2279 | - return; | |
| 2280 | - } | |
| 2281 | - | |
| 2282 | - $two_step_ids = array(); | |
| 2283 | - $traditional_ids = array(); | |
| 2406 | + $targetData = array ( | |
| 2407 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 2408 | + 'nonce' => wp_create_nonce( 'fca_eoi_activity' ), | |
| 2409 | + 'banners' => $target_data, | |
| 2410 | + ); | |
| 2284 | 2411 | |
| 2285 | - $mobile_detect = new Mobile_Detect; | |
| 2286 | - $is_mobile = $mobile_detect->isMobile(); | |
| 2287 | - | |
| 2288 | - foreach ( $lightboxes as $lightbox ) { | |
| 2289 | - | |
| 2290 | - // Get conditions | |
| 2291 | - $lightbox->fca_eoi = get_post_meta( $lightbox->ID , 'fca_eoi', true ); | |
| 2292 | - $publish_lightbox_mode = K::get_var( 'publish_lightbox_mode', $lightbox->fca_eoi, array() ); | |
| 2293 | - | |
| 2294 | - $lightbox_conditions = K::get_var( 'publish_lightbox', $lightbox->fca_eoi, array() ); | |
| 2295 | - | |
| 2296 | - $mobile_mode = K::get_var( 'devices', $lightbox_conditions, 'all' ); | |
| 2297 | - $fail_mobile = $mobile_mode === 'mobile' && !$is_mobile; | |
| 2298 | - $fail_desktop = $mobile_mode === 'desktop' && $is_mobile; | |
| 2299 | - | |
| 2300 | - // If on a free distribution, force traditional popup mode | |
| 2301 | - if ( $this->settings['distribution'] === 'free' ) { | |
| 2302 | - $publish_lightbox_mode = 'traditional_popup'; | |
| 2303 | - } | |
| 2412 | + wp_localize_script( 'fca_eoi_targeting_js', 'fcaEoiBannerTargetingData', $targetData ); | |
| 2304 | 2413 | |
| 2305 | - if ( 'two_step_optin' === $publish_lightbox_mode ) { | |
| 2306 | - $two_step_ids[] = $lightbox->ID; | |
| 2307 | - } else if ( !$fail_mobile && !$fail_desktop ) { | |
| 2308 | - $traditional_ids[] = $lightbox->ID; | |
| 2309 | - } | |
| 2310 | - | |
| 2311 | - | |
| 2312 | - } | |
| 2313 | - | |
| 2314 | - $this->display_traditional_popups($traditional_ids, $this->display_two_step_popups($two_step_ids)); | |
| 2414 | + return true; | |
| 2315 | 2415 | } |
| 2316 | 2416 | |
| 2317 | - private function display_two_step_popups($lightbox_ids) { | |
| 2318 | - $lightbox_ids = array_intersect( $lightbox_ids, $this->two_step_ids_on_page ); | |
| 2417 | + private function display_traditional_popups( $popups ) { | |
| 2418 | + | |
| 2419 | + $target_data = array(); | |
| 2319 | 2420 | |
| 2320 | - if ( empty( $lightbox_ids ) ) { | |
| 2321 | - return false; | |
| 2421 | + forEach ( $popups as $p ) { | |
| 2422 | + $this->prepare_lightbox_html( $p['id'] ); | |
| 2423 | + $target_data[$p['id']] = empty( $p['conditions'] ) ? array() : $p['conditions']; | |
| 2322 | 2424 | } |
| 2323 | - do_action( 'fca_eoi_display_lightbox' ); | |
| 2324 | - | |
| 2325 | - foreach ( $lightbox_ids as $lightbox_id ) { | |
| 2326 | - $this->prepare_lightbox( $lightbox_id ); | |
| 2327 | - } | |
| 2328 | 2425 | |
| 2329 | - ?> | |
| 2330 | - <script> | |
| 2331 | - jQuery( function() { | |
| 2332 | - jQuery( document ).on( 'click', '[data-optin-cat]', function( e ) { | |
| 2333 | - var lightbox_id = jQuery( this ).data( 'optin-cat' ); | |
| 2334 | - <?php echo EasyOptInsActivity::get_instance()->get_tracking_code( 'lightbox_id', false ) ?> | |
| 2335 | - jQuery.featherlight( jQuery( '#fca_eoi_lightbox_' + lightbox_id ), <?php echo $this->get_featherlight_options() ?> ); | |
| 2336 | - e.preventDefault(); | |
| 2337 | - } ); | |
| 2338 | - } ); | |
| 2339 | - </script> | |
| 2340 | - <?php | |
| 2341 | - | |
| 2342 | - return true; | |
| 2343 | - } | |
| 2344 | - | |
| 2345 | - private function display_traditional_popups( $lightbox_ids, $prerequisites_loaded = false ) { | |
| 2346 | - if ( empty( $lightbox_ids ) ) { | |
| 2347 | - return false; | |
| 2348 | - } | |
| 2426 | + wp_enqueue_script( 'fca_eoi_targeting_js', FCA_EOI_PLUGIN_URL.'/assets/targeting.min.js', array( 'jquery' ), FCA_EOI_VER, true ); | |
| 2349 | 2427 | |
| 2350 | - wp_enqueue_script( 'fca_eoi_script_js', FCA_EOI_PLUGIN_URL.'/assets/script.js', array(), FCA_EOI_VER, true ); | |
| 2351 | - //PASS VARIABLES TO JAVASCRIPT | |
| 2352 | - $data = array ( | |
| 2428 | + $targetData = array ( | |
| 2353 | 2429 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 2354 | - 'nonce' => wp_create_nonce( 'fca_eoi_submit_form' ), | |
| 2430 | + 'nonce' => wp_create_nonce( 'fca_eoi_activity' ), | |
| 2431 | + 'popups' => $target_data, | |
| 2355 | 2432 | ); |
| 2356 | 2433 | |
| 2357 | - wp_localize_script( 'fca_eoi_script_js', 'fca_eoi', $data ); | |
| 2358 | - wp_enqueue_script( 'fca_eoi_featherlight_js', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.js', array(), FCA_EOI_VER, true ); | |
| 2359 | - wp_enqueue_style( 'fca_eoi_featherlight_css', FCA_EOI_PLUGIN_URL.'/assets/vendor/featherlight/release/featherlight.min.css', array(), FCA_EOI_VER ); | |
| 2434 | + wp_localize_script( 'fca_eoi_targeting_js', 'fcaEoiTargetingData', $targetData ); | |
| 2360 | 2435 | |
| 2361 | - ?> | |
| 2362 | - <script type="text/javascript" src="<?php echo FCA_EOI_PLUGIN_URL . '/' . $this->targeting_cat_path ?>"></script> | |
| 2363 | - <script> | |
| 2364 | - (function() { | |
| 2365 | - if ( typeof fca_eoi === "undefined" ) { | |
| 2366 | - fca_eoi = {}; | |
| 2367 | - } | |
| 2368 | - | |
| 2369 | - fca_eoi.ajax_url = <?php echo json_encode( admin_url( 'admin-ajax.php' ) ) ?>; | |
| 2370 | - })(); | |
| 2371 | - | |
| 2372 | - <?php $v = array( | |
| 2373 | - 'prerequisites_loaded' => 'p', | |
| 2374 | - 'load_prerequisites' => 'l', | |
| 2375 | - 'head' => 'h', | |
| 2376 | - 'load_script' => 'c', | |
| 2377 | - 'load_style' => 'y', | |
| 2378 | - 'callback' => 'k', | |
| 2379 | - 'vendor_url' => 'v', | |
| 2380 | - 'done' => 'n', | |
| 2381 | - 'document' => 'd', | |
| 2382 | - 'window.location.href' => 'w', | |
| 2383 | - 'display_popup' => 's', | |
| 2384 | - 'false' => '!1', | |
| 2385 | - 'true' => '1', | |
| 2386 | - 'evaluable' => 'e', | |
| 2387 | - 'descriptors' => 'r', | |
| 2388 | - 'form_id' => 'm', | |
| 2389 | - 'TargetingCat_OptinCat' => 'g', | |
| 2390 | - 'url' => 'u' | |
| 2391 | - ); ?> | |
| 2392 | - | |
| 2393 | - <?php ob_start(); ?> | |
| 2394 | - | |
| 2395 | - jQuery( function( $ ) { | |
| 2396 | - var | |
| 2397 | - <?php echo $v['document'] ?> = document, | |
| 2398 | - <?php echo $v['window.location.href'] ?> = window.location.href, | |
| 2399 | - <?php echo $v['TargetingCat_OptinCat'] ?> = TargetingCat_OptinCat; | |
| 2400 | - | |
| 2401 | - <?php if ( ! $prerequisites_loaded ) { ?> | |
| 2402 | - | |
| 2403 | - var | |
| 2404 | - <?php echo $v['prerequisites_loaded'] ?> = <?php echo $v['false'] ?>, | |
| 2405 | - <?php echo $v['head'] ?> = <?php echo $v['document'] ?>.head; | |
| 2406 | - | |
| 2407 | - function <?php echo $v['load_script'] ?>( <?php echo $v['url'] ?>, <?php echo $v['callback'] ?> ) { | |
| 2408 | - var e = <?php echo $v['document'] ?>.createElement( 'script' ); | |
| 2409 | - | |
| 2410 | - e.type = 'text/javascript'; | |
| 2411 | - e.src = <?php echo $v['url'] ?>; | |
| 2412 | - e.onload = <?php echo $v['callback'] ?>; | |
| 2413 | - | |
| 2414 | - <?php echo $v['head'] ?>.appendChild( e ); | |
| 2415 | - } | |
| 2416 | - | |
| 2417 | - function <?php echo $v['load_style'] ?>( <?php echo $v['url'] ?>, <?php echo $v['callback'] ?> ) { | |
| 2418 | - var e = <?php echo $v['document'] ?>.createElement( 'link' ); | |
| 2419 | - | |
| 2420 | - e.rel = 'stylesheet'; | |
| 2421 | - e.type = 'text/css'; | |
| 2422 | - e.href = <?php echo $v['url'] ?>; | |
| 2423 | - e.onload = <?php echo $v['callback'] ?>; | |
| 2424 | - | |
| 2425 | - <?php echo $v['head'] ?>.appendChild( e ); | |
| 2426 | - } | |
| 2427 | - | |
| 2428 | - function <?php echo $v['load_prerequisites'] ?>( <?php echo $v['callback'] ?> ) { | |
| 2429 | - if ( <?php echo $v['prerequisites_loaded'] ?> ) { | |
| 2430 | - <?php echo $v['callback'] ?>(); | |
| 2431 | - return; | |
| 2432 | - } | |
| 2433 | - | |
| 2434 | - var t = 4, | |
| 2435 | - <?php echo $v['url'] ?> = <?php echo json_encode( FCA_EOI_PLUGIN_URL . '/assets/' ) ?>, | |
| 2436 | - <?php echo $v['vendor_url'] ?> = <?php echo $v['url'] ?> + 'vendor/', | |
| 2437 | - <?php echo $v['done'] ?> = function() { | |
| 2438 | - if ( ! --t ) { | |
| 2439 | - <?php echo $v['prerequisites_loaded'] ?> = <?php echo $v['true'] ?>; | |
| 2440 | - <?php echo $v['callback'] ?>(); | |
| 2441 | - } | |
| 2442 | - }; | |
| 2443 | - | |
| 2444 | - <?php echo $v['load_style'] ?>( '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css', <?php echo $v['done'] ?> ); | |
| 2445 | - | |
| 2446 | - | |
| 2447 | - <?php echo $v['load_style'] ?>( <?php echo $v['url'] ?> + 'style-new.css', <?php echo $v['done'] ?> ); | |
| 2448 | - | |
| 2449 | - <?php echo $v['load_script'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/tooltipster.bundle.min.js', <?php echo $v['done'] ?> ); | |
| 2450 | - <?php echo $v['load_style'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/tooltipster.bundle.min.css', <?php echo $v['done'] ?> ); | |
| 2451 | - <?php echo $v['load_style'] ?>( <?php echo $v['vendor_url'] ?> + 'tooltipster/tooltipster-borderless.min.css', <?php echo $v['done'] ?> ); | |
| 2452 | - | |
| 2453 | - <?php | |
| 2454 | - | |
| 2455 | - $loadAnim = false; | |
| 2456 | - forEach ($lightbox_ids as $id) { | |
| 2457 | - $animation = get_post_meta( $id, 'fca_eoi_animation', true ); | |
| 2458 | - if ($animation != '') { | |
| 2459 | - $loadAnim = true; | |
| 2460 | - break; | |
| 2461 | - } | |
| 2462 | - } | |
| 2463 | - | |
| 2464 | - if ( $loadAnim ) { | |
| 2465 | - | |
| 2466 | - echo $v['load_style'] . "(" . $v['vendor_url'] . "+ 'animate/animate.css'," . $v['done'] . ');'; } ?> | |
| 2467 | - } | |
| 2468 | - | |
| 2469 | - <?php } ?> | |
| 2470 | - | |
| 2471 | - function <?php echo $v['display_popup'] ?>( <?php echo $v['form_id'] ?> ) { | |
| 2472 | - var t = <?php echo $prerequisites_loaded ? 1 : 2 ?>, | |
| 2473 | - <?php echo $v['done'] ?> = function() { | |
| 2474 | - if ( ! --t ) { | |
| 2475 | - $.featherlight( | |
| 2476 | - $( '#fca_eoi_lightbox_' + <?php echo $v['form_id'] ?> ), | |
| 2477 | - <?php echo $this->get_featherlight_options() ?> | |
| 2478 | - ); | |
| 2479 | - | |
| 2480 | - <?php echo EasyOptInsActivity::get_instance()->get_tracking_code( $v['form_id'], false ) ?> | |
| 2481 | - } | |
| 2482 | - }; | |
| 2483 | - | |
| 2484 | - $.post( <?php echo $v['window.location.href'] ?>, { | |
| 2485 | - fca_eoi_prepare_lightbox: <?php echo $v['form_id'] ?> | |
| 2486 | - }, function( html ) { | |
| 2487 | - $( 'body' ).append( html ); | |
| 2488 | - <?php echo $v['done'] ?>(); | |
| 2489 | - } ); | |
| 2490 | - | |
| 2491 | - <?php if ( ! $prerequisites_loaded ) { ?> | |
| 2492 | - <?php echo $v['load_prerequisites'] ?>( <?php echo $v['done'] ?> ); | |
| 2493 | - <?php } ?> | |
| 2494 | - } | |
| 2495 | - | |
| 2496 | - <?php echo $v['TargetingCat_OptinCat'] ?>.StorageManagerSessionPermanent.get_instance().default_configuration = <?php echo json_encode( $this->get_cookie_configuration() ) ?>; | |
| 2497 | - | |
| 2498 | - <?php echo json_encode( $lightbox_ids ) ?>.forEach( function( <?php echo $v['form_id'] ?> ) { | |
| 2499 | - $.post( <?php echo $v['window.location.href'] ?>, { | |
| 2500 | - <?php if ( is_single() || is_page() ) { ?> | |
| 2501 | - 'fca_eoi_tc_condition_post_id': <?php echo get_the_ID() ?>, | |
| 2502 | - <?php } ?> | |
| 2503 | - 'fca_eoi_tc_conditions_for': <?php echo $v['form_id'] ?> | |
| 2504 | - }, function( <?php echo $v['descriptors'] ?> ) { | |
| 2505 | - var <?php echo $v['evaluable'] ?> = <?php echo $v['TargetingCat_OptinCat'] ?>.ConditionManager.get_instance().parse_descriptors( | |
| 2506 | - typeof <?php echo $v['descriptors'] ?> === 'string' | |
| 2507 | - ? JSON.parse( <?php echo $v['descriptors'] ?> ) | |
| 2508 | - : <?php echo $v['descriptors'] ?> | |
| 2509 | - ); | |
| 2510 | - if ( <?php echo $v['evaluable'] ?> ) { | |
| 2511 | - <?php echo $v['evaluable'] ?>.set_pass_callback( function() { | |
| 2512 | - <?php echo $v['display_popup'] ?>( <?php echo $v['form_id'] ?> ); | |
| 2513 | - } ); | |
| 2514 | - <?php echo $v['evaluable'] ?>.evaluate(); | |
| 2515 | - } | |
| 2516 | - } ); | |
| 2517 | - } ); | |
| 2518 | - | |
| 2519 | - var lightbox_ids_Count = <?php echo count ($lightbox_ids) ?>; | |
| 2520 | - var currentLightBoxCount = 0; | |
| 2521 | - var totalAddedLightboxes = 0; | |
| 2522 | - | |
| 2523 | - function waitUntilPopupsAreMade() { | |
| 2524 | - | |
| 2525 | - if( totalAddedLightboxes < lightbox_ids_Count ) { | |
| 2526 | - | |
| 2527 | - if (document.getElementsByClassName("fca_eoi_featherlight").length > currentLightBoxCount) { | |
| 2528 | - | |
| 2529 | - totalAddedLightboxes++; | |
| 2530 | - currentLightBoxCount = document.getElementsByClassName("fca_eoi_featherlight").length; | |
| 2531 | - attachDeleteButtons(); | |
| 2532 | - window.setTimeout(waitUntilPopupsAreMade, 200); | |
| 2533 | - }else { | |
| 2534 | - | |
| 2535 | - currentLightBoxCount = document.getElementsByClassName("fca_eoi_featherlight").length; | |
| 2536 | - window.setTimeout(waitUntilPopupsAreMade, 200); | |
| 2537 | - } | |
| 2538 | - | |
| 2539 | - } else { | |
| 2540 | - | |
| 2541 | - attachDeleteButtons(); | |
| 2542 | - } | |
| 2543 | - } | |
| 2544 | - if (lightbox_ids_Count > 1) { | |
| 2545 | - waitUntilPopupsAreMade(); | |
| 2546 | - } | |
| 2547 | - | |
| 2548 | - function attachDeleteButtons() { | |
| 2549 | - myNodes = document.getElementsByClassName("fca_eoi_layout_popup_close"); | |
| 2550 | - | |
| 2551 | - for (var i=0; i<myNodes.length; i++) { | |
| 2552 | - myNodes[i].onclick = function(e) { | |
| 2553 | - $(this).parents(".fca_eoi_featherlight").hide(); | |
| 2554 | - }; | |
| 2555 | - | |
| 2556 | - } | |
| 2557 | - } | |
| 2558 | - | |
| 2559 | - | |
| 2560 | - } ); | |
| 2561 | - | |
| 2562 | - <?php | |
| 2563 | - | |
| 2564 | - echo preg_replace( | |
| 2565 | - array( '/\s+/', '/([-+|\(\){}&=;,:?])\s+/', '/\s+([-+|\(\){}&=?])/', '/;}/' ), | |
| 2566 | - array( ' ', '$1', '$1', '}' ), | |
| 2567 | - trim( ob_get_clean() ) | |
| 2568 | - ); | |
| 2569 | - | |
| 2570 | - ?> | |
| 2571 | - </script> | |
| 2572 | - <?php | |
| 2573 | - | |
| 2574 | 2436 | return true; |
| 2575 | 2437 | } |
| 2576 | 2438 | |
| 2577 | - public function request_prepare_lightbox() { | |
| 2578 | - if (array_key_exists('fca_eoi_prepare_lightbox', $_POST)) { | |
| 2579 | - $lightbox_id = (int) $_POST['fca_eoi_prepare_lightbox']; | |
| 2580 | - if ( $lightbox_id > 0 ) { | |
| 2581 | - $this->prepare_lightbox( $lightbox_id ); | |
| 2582 | - exit; | |
| 2583 | - } | |
| 2584 | - } | |
| 2585 | - } | |
| 2586 | - | |
| 2587 | - public function prepare_lightbox( $id ) { | |
| 2439 | + public function prepare_lightbox_html( $id ) { | |
| 2588 | 2440 | $id = (int) $id; |
| 2589 | 2441 | |
| 2590 | - global $post; | |
| 2442 | + $content = do_shortcode( "[easy-opt-in id=$id]" ); | |
| 2591 | 2443 | |
| 2592 | - $animation = get_post_meta( $id, 'fca_eoi_animation', true ); | |
| 2593 | - $animation_html_class = "animated $animation"; | |
| 2594 | - | |
| 2595 | - if ( empty ( $animation ) || $animation == 'None' ) { | |
| 2596 | - $animation_html_class = ''; | |
| 2597 | - } | |
| 2598 | - | |
| 2599 | - | |
| 2600 | - $featherlight_class = 'fca_eoi_featherlight'; | |
| 2601 | - $content = do_shortcode( "[easy-opt-in id=$id]" ); | |
| 2602 | - | |
| 2603 | 2444 | ?> |
| 2604 | 2445 | <div style="display:none"> |
| 2605 | - <style>.<?php echo $featherlight_class ?>-content { background: transparent !important; }</style> | |
| 2606 | - <div class="<?php echo $animation_html_class ?>" id="fca_eoi_lightbox_<?php echo $id ?>"><?php echo $content ?></div> | |
| 2446 | + <div id="fca_eoi_lightbox_<?php echo $id ?>"><?php echo $content ?></div> | |
| 2607 | 2447 | </div> |
| 2608 | 2448 | <?php |
| 2609 | 2449 | } |
| 2610 | 2450 | |
| 2611 | - private function get_featherlight_options() { | |
| 2612 | - | |
| 2613 | - $is_iphone = preg_match('/(?:iPhone|iPod);/i', $_SERVER['HTTP_USER_AGENT']); | |
| 2614 | - $is_ios = preg_match( '/(?:iPhone|iPad|iPod).* OS ([\d])_.* Safari/', $_SERVER['HTTP_USER_AGENT'], $matches ); | |
| 2615 | - | |
| 2616 | - if ( $is_ios ) { | |
| 2617 | - $ios_specific_options = ', | |
| 2618 | - beforeOpen: function() { | |
| 2619 | - var viewport = jQuery( "meta[name=viewport]" ); | |
| 2620 | - if ( viewport.length == 0 ) { | |
| 2621 | - viewport = jQuery( "<meta name=\"viewport\" content=\"\"/>" ); | |
| 2622 | - jQuery( "head" ).append( viewport ); | |
| 2623 | - } | |
| 2624 | - | |
| 2625 | - var viewport_content = viewport.attr( "content" ); | |
| 2626 | - this.fca_eoi_viewport_content = viewport_content; | |
| 2627 | - viewport.attr( "content", "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" ); | |
| 2628 | - | |
| 2629 | - this.fca_eoi_orientation_change_listener = function() { | |
| 2630 | - window.scrollTo( 0, 0 ); | |
| 2631 | - jQuery( ".fca_eoi_form input" ).each( function() { | |
| 2632 | - this.blur(); | |
| 2633 | - } ); | |
| 2634 | - }; | |
| 2635 | - window.addEventListener( "orientationchange", this.fca_eoi_orientation_change_listener, false ); | |
| 2636 | - | |
| 2637 | - this.fca_eoi_touch_move_listener = function( event ) { | |
| 2638 | - event.preventDefault(); | |
| 2639 | - }; | |
| 2640 | - window.addEventListener( "touchmove", this.fca_eoi_touch_move_listener, false ); | |
| 2641 | - }, | |
| 2642 | - afterOpen: function() { | |
| 2643 | - this.$instance.find(".fca_eoi_form_input_element").first().focus(); | |
| 2644 | - jQuery( "body" ).append( "<div class=\"fca_eoi_featherlight_pad\" style=\"display: block; height: 1000px;\"/>" ); | |
| 2645 | - }, | |
| 2646 | - beforeClose: function() { | |
| 2647 | - jQuery( ".fca_eoi_featherlight_pad" ).remove(); | |
| 2648 | - }, | |
| 2649 | - afterClose: function() { | |
| 2650 | - if ( this.hasOwnProperty( "fca_eoi_viewport_content" ) ) { | |
| 2651 | - jQuery( "meta[name=viewport]" ).attr( "content", this.fca_eoi_viewport_content ); | |
| 2652 | - } | |
| 2653 | - | |
| 2654 | - if ( this.hasOwnProperty( "fca_eoi_orientation_change_listener" ) ) { | |
| 2655 | - window.removeEventListener( "orientationchange", this.fca_eoi_orientation_change_listener ); | |
| 2656 | - } | |
| 2657 | - | |
| 2658 | - if ( this.hasOwnProperty( "fca_eoi_touch_move_listener" ) ) { | |
| 2659 | - window.removeEventListener( "touchmove", this.fca_eoi_touch_move_listener ); | |
| 2660 | - } | |
| 2661 | - }'; | |
| 2662 | - } else { | |
| 2663 | - $ios_specific_options = ', | |
| 2664 | - afterOpen: function() { | |
| 2665 | - this.$instance.find(".fca_eoi_form_input_element").first().focus(); | |
| 2666 | - }'; | |
| 2667 | - } | |
| 2668 | - | |
| 2669 | - return '{ | |
| 2670 | - namespace: "fca_eoi_featherlight", | |
| 2671 | - otherClose: ".fca_eoi_layout_popup_close"' . $ios_specific_options . ', | |
| 2672 | - variant: ' . ( $is_iphone ? '"fca_eoi_device_iphone"' : 'null' ) . ' | |
| 2673 | - }'; | |
| 2674 | - } | |
| 2675 | -} | |
| 2676 | - | |
| 2677 | -function k_selector( $name, $selected_options = array(), $return = false ) { | |
| 2678 | - | |
| 2679 | - global $post; | |
| 2680 | - // Dirty fix to restore the global $post | |
| 2681 | - $post_bak = $post; | |
| 2682 | - | |
| 2683 | - // Get all post types except media | |
| 2684 | - $post_types = get_post_types( array( 'public' => true ) ); | |
| 2685 | - unset( $post_types[ 'attachment' ] ); | |
| 2686 | - | |
| 2687 | - $ret = ob_start(); | |
| 2688 | - | |
| 2689 | - // Start ouput | |
| 2690 | - echo '<select data-placeholder="' . __( 'Type to search for posts, categories or pages.' ) . '" name = "' . $name . '[]" class="select2" multiple="multiple" style="width: 100%;">'; | |
| 2691 | - | |
| 2692 | - // Front page | |
| 2693 | - K::wrap( __( 'Front page' ) | |
| 2694 | - , array( | |
| 2695 | - 'value' => '~', | |
| 2696 | - 'selected' => in_array( '~', $selected_options ), | |
| 2697 | - ) | |
| 2698 | - , array( 'in' => 'option' ) | |
| 2699 | - ); | |
| 2700 | - | |
| 2701 | - foreach ($post_types as $post_type => $post_type_args ) { | |
| 2702 | - | |
| 2703 | - $post_type_obj = get_post_type_object( $post_type ); | |
| 2704 | - $post_type_name = $post_type_obj->labels->singular_name; | |
| 2705 | - | |
| 2706 | - $options = array(); | |
| 2707 | - | |
| 2708 | - // Add taxonomy/terms options | |
| 2709 | - $taxonomies = get_object_taxonomies( $post_type ); | |
| 2710 | - foreach ( $taxonomies as $taxonomy ) { | |
| 2711 | - $taxonomy_obj = get_taxonomy( $taxonomy ); | |
| 2712 | - $taxonomy_name = $taxonomy_obj->labels->singular_name; | |
| 2713 | - $terms = get_categories("taxonomy=$taxonomy&type=$post_type"); | |
| 2714 | - foreach ($terms as $term) { | |
| 2715 | - $options[ 'taxonomies' ][ "$post_type:$term->term_id" ] = | |
| 2716 | - $post_type_name | |
| 2717 | - . " › $taxonomy_name" | |
| 2718 | - . " › $term->name" | |
| 2719 | - ; | |
| 2720 | - } | |
| 2721 | - } | |
| 2722 | - | |
| 2723 | - // Add posts options | |
| 2724 | - $the_query = new WP_Query( "post_type=$post_type&posts_per_page=-1" ); | |
| 2725 | - if ( $the_query->have_posts() ) { | |
| 2726 | - | |
| 2727 | - while ( $the_query->have_posts() ) { | |
| 2728 | - $the_query->the_post(); | |
| 2729 | - $options[ 'posts' ][ '#' . get_the_ID() ] = $post_type_name | |
| 2730 | - . ' ' . __( '›' ) . ' ' | |
| 2731 | - . '#' . get_the_ID() . ' – ' | |
| 2732 | - . ( get_the_title() ? get_the_title() : __('[Untitled]') ) | |
| 2733 | - ; | |
| 2734 | - } | |
| 2735 | - } | |
| 2736 | - | |
| 2737 | - // Dirty fix to restore the global $post | |
| 2738 | - $post = $post_bak; | |
| 2739 | - | |
| 2740 | - // Posts > All | |
| 2741 | - echo '<optgroup label="' . $post_type_name . '">'; | |
| 2742 | - printf( | |
| 2743 | - '<option value="%s" %s >%s</option>' | |
| 2744 | - , $post_type | |
| 2745 | - , ( in_array( $post_type, $selected_options ) ? 'selected' : '' ) | |
| 2746 | - , $post_type_name . ' ' . ( '›' ) . ' ' . __( 'All' ) | |
| 2747 | - ); | |
| 2748 | - echo '</optgroup>'; | |
| 2749 | - | |
| 2750 | - // Posts > Taoxonomies | |
| 2751 | - if ( ! empty( $options[ 'taxonomies' ] ) ) { | |
| 2752 | - printf( | |
| 2753 | - '<optgroup label="%s">' | |
| 2754 | - , $post_type_name . ' ' . __( '›' ) . ' ' . __( 'Taxonomies' ) | |
| 2755 | - ); | |
| 2756 | - foreach ( $options[ 'taxonomies' ] as $k => $v ) { | |
| 2757 | - $selected = ( in_array( $k, $selected_options ) ) ? 'selected="selected"' : ''; | |
| 2758 | - printf( '<option value="%s" %s >%s</option>', $k, $selected, $v ); | |
| 2759 | - } | |
| 2760 | - echo '</optgroup>'; | |
| 2761 | - } | |
| 2762 | - | |
| 2763 | - // Posts > content | |
| 2764 | - if ( ! empty( $options[ 'posts' ] ) ) { | |
| 2765 | - printf( '<optgroup label="%s">' | |
| 2766 | - , $post_type_name . ' ' . __( '›' ) . ' ' . __( 'Content' ) | |
| 2767 | - ); | |
| 2768 | - foreach ( $options[ 'posts' ] as $k => $v ) { | |
| 2769 | - $selected = ( in_array( $k, $selected_options ) ) ? 'selected="selected"' : ''; | |
| 2770 | - printf( '<option value="%s" %s >%s</option>' | |
| 2771 | - , $k | |
| 2772 | - , $selected | |
| 2773 | - , $v | |
| 2774 | - ); | |
| 2775 | - } | |
| 2776 | - echo '</optgroup>'; | |
| 2777 | - } | |
| 2778 | - } | |
| 2779 | - echo '</select>'; | |
| 2780 | - | |
| 2781 | - $ret = ob_get_clean(); | |
| 2782 | - | |
| 2783 | - if ( $return ) { | |
| 2784 | - return $ret; | |
| 2785 | - } else { | |
| 2786 | - echo $ret; | |
| 2787 | - } | |
| 2788 | -} | |
| 2789 | - | |
| 2790 | -function fca_eoi_comp( $a, $b, $op, $negate = false ) { | |
| 2791 | - switch ( $op ) { | |
| 2792 | - case 'eq': return $negate ? ( ! ( $a == $b ) ) : ( $a == $b ); | |
| 2793 | - case 'gt': return $negate ? ( ! ( $a > $b ) ) : ( $a > $b ); | |
| 2794 | - case 'gte': return $negate ? ( ! ( $a >= $b ) ) : ( $a >= $b ); | |
| 2795 | - case 'lt': return $negate ? ( ! ( $a < $b ) ) : ( $a < $b ); | |
| 2796 | - case 'lte': return $negate ? ( ! ( $a <= $b ) ) : ( $a <= $b ); | |
| 2797 | - } | |
| 2798 | 2451 | } |