| @@ -1,13 +1,35 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - if ( ! defined('WPINC') ) { | |
| 4 | - wp_die(); | |
| 3 | +if ( ! defined('ABSPATH') ) { | |
| 4 | + exit; | |
| 5 | +} | |
| 6 | + | |
| 7 | + $set_id = $post->ID; | |
| 8 | + $filters = flrt_get_configured_filters( $set_id ); | |
| 9 | + | |
| 10 | + $filterSet = \FilterEverything\Filter\Container::instance()->getFilterSetService(); | |
| 11 | + $the_set = $filterSet->getSet( $set_id ); | |
| 12 | + $under_limit_filter_set = $filterSet->under_limit_filter_set($set_id); | |
| 13 | + | |
| 14 | + $order = 1; | |
| 15 | + | |
| 16 | + $search_field_order = ( isset( $the_set['search_field_menu_order']['value'] ) && $the_set['search_field_menu_order']['value'] > -1 ) ? (int)$the_set['search_field_menu_order']['value'] : (count($filters) + 1); | |
| 17 | + // To avoid equal order for both elements | |
| 18 | + if ( isset( $the_set['apply_button_menu_order']['value'] ) && $the_set['apply_button_menu_order']['value'] > -1 ){ | |
| 19 | + $apply_button_order = (int)$the_set['apply_button_menu_order']['value']; | |
| 20 | + } else { | |
| 21 | + $apply_button_order = ($search_field_order + 1); | |
| 5 | 22 | } |
| 23 | + if ( $apply_button_order === $search_field_order ) { | |
| 24 | + $apply_button_order++; | |
| 25 | + } | |
| 6 | 26 | |
| 7 | - $post_id = $post->ID; | |
| 8 | - $filters = flrt_get_configured_filters( $post_id ); | |
| 9 | - $filterSet = \FilterEverything\Filter\Container::instance()->getFilterSetService(); | |
| 27 | + $apply_btn_displayed = false; | |
| 28 | + $search_fld_displayed = false; | |
| 29 | + if ( isset( $the_set['use_search_field']['value'] ) && $the_set['use_search_field']['value'] === 'yes' ) { | |
| 30 | + $search_fld_displayed = true; | |
| 31 | + } | |
| 10 | 32 | |
| 11 | 33 | ?> |
| 12 | 34 | <div class="wpc-filter-set-wrapper"> |
| 13 | 35 | <div class="wpc-filter-set-hidden-fields"> |
| @@ -16,9 +38,11 @@ | ||
| 16 | 38 | <div class="wpc-column-labels-wrapper"> |
| 17 | 39 | <table class="wpc-form-fields-table"> |
| 18 | 40 | <?php |
| 19 | 41 | |
| 20 | - $attributes = $filterSet->getPostTypeField($post_id); | |
| 42 | + $attributes['post_type'] = $the_set['post_type']; | |
| 43 | + $post_type = ( isset( $the_set['post_type']['value'] ) && $the_set['post_type']['value'] ) ? $the_set['post_type']['value'] : $the_set['post_type']['default']; | |
| 44 | + | |
| 21 | 45 | flrt_include_admin_view('filter-field', array( |
| 22 | 46 | 'field_key' => key($attributes), |
| 23 | 47 | 'attributes' => reset($attributes) |
| 24 | 48 | ) |
| @@ -29,10 +53,10 @@ | ||
| 29 | 53 | </div> |
| 30 | 54 | <div class="wpc-column-labels-wrapper"> |
| 31 | 55 | <div class="wpc-column-labels widget-title"> |
| 32 | 56 | <ul class="wpc-custom-row"> |
| 33 | - <li class="wpc-filter-order"><?php esc_html_e('#', 'filter-everything'); ?></li> | |
| 34 | - <li class="wpc-filter-label"><?php esc_html_e('Label', 'filter-everything' ); ?></li> | |
| 57 | + <li class="wpc-filter-order"> </li> | |
| 58 | + <li class="wpc-filter-label"><?php esc_html_e('Title', 'filter-everything' ); ?></li> | |
| 35 | 59 | <li class="wpc-filter-entity"><?php esc_html_e('Filter by', 'filter-everything' ); ?></li> |
| 36 | 60 | <li class="wpc-filter-view"><?php esc_html_e('View', 'filter-everything' ); ?></li> |
| 37 | 61 | <li class="wpc-filter-slug"><?php esc_html_e('URL Prefix', 'filter-everything' ); ?></li> |
| 38 | 62 | </ul> |
| @@ -37,24 +61,69 @@ | ||
| 37 | 61 | <li class="wpc-filter-slug"><?php esc_html_e('URL Prefix', 'filter-everything' ); ?></li> |
| 38 | 62 | </ul> |
| 39 | 63 | </div> |
| 40 | 64 | </div> |
| 41 | - <div class="wpc-no-filters"<?php if( ! $filters ){ echo ' style="display: block;"'; }?>> | |
| 65 | + <div class="wpc-no-filters"<?php if( ! $filters && ! $search_fld_displayed ){ echo ' style="display: block;"'; }?>> | |
| 42 | 66 | <?php |
| 43 | 67 | echo wp_kses( |
| 44 | - __('No filters yet. Click the <strong>Add Filter</strong> button to create your first one.', 'filter-everything' ), | |
| 68 | + __('There are no filters yet. Click the <strong>Add Filter</strong> button to create your first one.', 'filter-everything' ), | |
| 45 | 69 | array( 'strong' => array() ) |
| 46 | 70 | ); |
| 47 | 71 | ?> |
| 48 | 72 | </div> |
| 49 | - <div class="wpc-filters-list"> | |
| 73 | + <div id="wpc-filters-list" class="wpc-filters-list" data-posttype="<?php echo $post_type; ?>"> | |
| 50 | 74 | |
| 51 | - <?php if( $filters ): | |
| 75 | + <?php | |
| 76 | + $filters_and_fields = []; | |
| 77 | + $filters = array_reverse( $filters, true ); | |
| 78 | + $to = count( $filters ) + 2; | |
| 52 | 79 | |
| 53 | - foreach( $filters as $filter ): | |
| 80 | + for ( $i = 1; $i <= $to; $i++ ) { | |
| 81 | + if ( $apply_button_order === $i ) { | |
| 82 | + $filters_and_fields[-1] = array(); | |
| 83 | + } else if ( $search_field_order === $i ) { | |
| 84 | + $filters_and_fields[-2] = array(); | |
| 85 | + } else { | |
| 86 | + // To avoid "empty" filter | |
| 87 | + if ( ! empty( $filters ) ) { | |
| 88 | + $key = array_key_last( $filters ); | |
| 89 | + $value = array_pop( $filters ); | |
| 90 | + $filters_and_fields[$key] = $value; | |
| 91 | + } | |
| 92 | + } | |
| 93 | + } | |
| 54 | 94 | |
| 55 | - flrt_include_admin_view( 'filter-row', array( 'filter' => $filter ) ); | |
| 95 | + if( $filters_and_fields ): | |
| 56 | 96 | |
| 97 | + foreach( $filters_and_fields as $filter_id => $filter ): | |
| 98 | + | |
| 99 | + if ( $filter_id >= 0 ) { | |
| 100 | + flrt_include_admin_view( 'filter-row', array( 'filter' => $filter ) ); | |
| 101 | + } else { | |
| 102 | + if ( $search_field_order == $order ) { | |
| 103 | + flrt_include_admin_view( 'filter-search-field', array( | |
| 104 | + 'search_field_order' => $the_set['search_field_menu_order'], | |
| 105 | + 'use_search_field' => $the_set['use_search_field'], | |
| 106 | + 'search_field_placeholder' => $the_set['search_field_placeholder'], | |
| 107 | + 'search_field_label' => $the_set['search_field_label'], | |
| 108 | + 'post_type_args' => $the_set['post_type'], | |
| 109 | + ) | |
| 110 | + ); | |
| 111 | + } | |
| 112 | + | |
| 113 | + if ( $apply_button_order == $order ) { | |
| 114 | + flrt_include_admin_view( 'filter-apply-button', array( | |
| 115 | + 'apply_button' => $the_set['apply_button_menu_order'], | |
| 116 | + 'use_apply_button' => $the_set['use_apply_button'], | |
| 117 | + 'apply_button_text' => $the_set['apply_button_text'], | |
| 118 | + 'reset_button_text' => $the_set['reset_button_text'], | |
| 119 | + 'apply_button_order' => $apply_button_order | |
| 120 | + ) | |
| 121 | + ); | |
| 122 | + } | |
| 123 | + } | |
| 124 | + | |
| 125 | + $order++; | |
| 57 | 126 | endforeach; |
| 58 | 127 | |
| 59 | 128 | endif; ?> |
| 60 | 129 | </div> |
| @@ -59,15 +128,41 @@ | ||
| 59 | 128 | endif; ?> |
| 60 | 129 | </div> |
| 61 | 130 | |
| 62 | 131 | <div class="wpc-add-filter-wrapper"> |
| 63 | - <div class="wpc-add-filter-div"> | |
| 64 | - <a href="#" class="button button-primary button-large wpc-add-filter"><?php esc_html_e('Add Filter','filter-everything' ); ?></a> | |
| 132 | + <?php $button_text = esc_html__('Add Filter','filter-everything' );?> | |
| 133 | + <div class="wpc-add-filter-div<?php echo ($under_limit_filter_set) ? ' wpc_under_limit_filter_set' : ''; ?>"> | |
| 134 | + <a href="javascript:void(0);" class="button button-primary button-large wpc-add-filter"><?php echo $button_text; ?></a> | |
| 135 | + <?php | |
| 136 | + if(!defined('FLRT_FILTERS_PRO')){ | |
| 137 | + echo flrt_unlock_in_pro($button_text); | |
| 138 | + } | |
| 139 | + ?> | |
| 65 | 140 | </div> |
| 66 | 141 | </div> |
| 67 | 142 | |
| 68 | 143 | <script type="text/html" id="wpc-new-filter"> |
| 69 | 144 | <?php |
| 70 | - flrt_include_admin_view( 'filter-row', array( 'filter' => flrt_get_empty_filter() ) ); | |
| 145 | + flrt_include_admin_view( 'filter-row', array( 'filter' => flrt_get_empty_filter( $set_id ) ) ); | |
| 71 | 146 | ?> |
| 72 | 147 | </script> |
| 148 | + <div id="wpc-filter-set-pro-dialog" style="display:none;"> | |
| 149 | + <?php | |
| 150 | + $dialog_post_type_field = $filterSet->getPostTypeField($set_id); | |
| 151 | + $dialog_post_type = !empty($dialog_post_type_field['post_type']['value']) ? $dialog_post_type_field['post_type']['value'] : ''; | |
| 152 | + $dialog_limit = $filterSet->getFreeLimitForPostType($dialog_post_type); | |
| 153 | + ?> | |
| 154 | + <p><?php echo wp_kses( | |
| 155 | + sprintf( | |
| 156 | + /* translators: 1: maximum number of free filter sets per post type, 2: PRO upgrade URL */ | |
| 157 | + __('The free version allows up to %1$d filter sets per post type. Upgrade to <a href=\'%2$s\' target=\'_blank\'>PRO</a> for unlimited filter sets.', 'filter-everything' ), | |
| 158 | + $dialog_limit, | |
| 159 | + esc_url(FLRT_PLUGIN_URL .'/pricing/?utm_source=free_plugin&utm_medium=internal&utm_campaign=free_plugin_upgrade&utm_content=msg_three_set') ), | |
| 160 | + array( | |
| 161 | + 'a' => array( | |
| 162 | + 'href'=> true, | |
| 163 | + 'target' => true | |
| 164 | + ) | |
| 165 | + ) | |
| 166 | + ) ?></p> | |
| 167 | + </div> | |
| 73 | 168 | </div> |