PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
wpdirectorykit / application / views / search_fields / CATEGORY.php

CATEGORY.php in WP Directory Kit 1.5.9, at application/views/search_fields/CATEGORY.php

228 lines 9.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The template for Search field CATEGORY.
4 *
5 * This is the template that field layout for search form
6 *
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12 ?>
13 <?php
14 $field_key = 'search_category';
15 $field_attr_id = 'wdk_search_'.wmvc_show_data('idfield', $field_data);
16 $placeholder = wmvc_show_data('field_label', $field_data);
17 $field_value = '';
18 // Dynamic field values are registered in the translation catalog separately.
19 // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
20 $placeholder = esc_html__($placeholder,'wpdirectorykit');
21
22 $filter_ids = array();
23 if(isset($predefinedfields_query) && !empty($predefinedfields_query[$field_key])) {
24 $field_value = intval($predefinedfields_query[$field_key]);
25 }
26
27 if(isset($_GET['category_root'])) {
28 $predefinedfields_query['custom_category_root'] = sanitize_text_field(wp_unslash($_GET['category_root']));
29 }
30
31 if(isset($predefinedfields_query) && !empty($predefinedfields_query['custom_category_root'])) {
32 $custom_field_value = intval($predefinedfields_query['custom_category_root']);
33 global $Winter_MVC_WDK;
34 $Winter_MVC_WDK->load_helper('listing');
35 $Winter_MVC_WDK->model('category_m');
36 $category = $Winter_MVC_WDK->category_m->get($custom_field_value, TRUE);
37
38 /* if root search childs */
39 if($category) {
40 $filter_ids = wdk_category_get_all_childs($custom_field_value);
41 if(!empty($filter_ids)) {
42 if(in_array($field_value, $filter_ids) === FALSE) {
43 $field_value = $custom_field_value;
44 }
45 } else {
46 $filter_ids[] = $custom_field_value;
47 }
48 } else {
49 /* category missing */
50 $custom_field_value = null;
51 }
52 }
53
54 if(isset($_GET[$field_key])) {
55 $field_value = ($_GET[$field_key]);
56 }
57
58 $hide_fields = '';
59 if(wmvc_show_data('search_type_tree_hide', $field_data)) {
60 $hide_fields = wmvc_show_data('search_type_tree_hide', $field_data);
61 }
62 wdk_search_fields_toggle();
63 ?>
64 <?php if(isset($custom_field_value)):?>
65 <input type="hidden" name="search_category[]" value="<?php echo esc_attr($custom_field_value);?>">
66 <?php endif;?>
67 <?php if(wdk_get_option('wdk_multi_categories_search_field_type') == 'wdk_treefield_dropdown'):?>
68 <?php
69 global $Winter_MVC_WDK;
70 $Winter_MVC_WDK->load_helper('listing');
71 $Winter_MVC_WDK->model('category_m');
72
73 $categories = array();
74 if(!empty($field_value)) {
75 $categories[] = $field_value;
76 $category = $Winter_MVC_WDK->category_m->get($field_value, TRUE);
77
78 while(!empty($category->parent_id)) {
79 $category = $Winter_MVC_WDK->category_m->get($category->parent_id, TRUE);
80 $categories[] = $category->idcategory;
81 }
82 krsort($categories);
83 } else {
84 $categories[] = 0;
85 }
86
87 wp_enqueue_style('wdk-treefield-dropdown');
88 wp_enqueue_script('wdk-treefield-dropdown');
89 wp_enqueue_style( 'dashicons' );
90
91
92 $level_max = $Winter_MVC_WDK->category_m->get_max_level();
93
94 $placeholder = [
95 0 => esc_html__('Select Categories','wpdirectorykit'),
96 1 => esc_html__('Select Sub Categories','wpdirectorykit'),
97 2 => esc_html__('Select Sub Categories','wpdirectorykit'),
98 3 => esc_html__('Select Sub Categories','wpdirectorykit'),
99 4 => esc_html__('Select Sub Categories','wpdirectorykit'),
100 5 => esc_html__('Select Sub Categories','wpdirectorykit'),
101 ];
102
103
104 ?>
105
106 <input name="<?php echo esc_attr($field_key); ?>" type="hidden" value="<?php echo esc_attr($field_value); ?>">
107 <?php
108 $level = 0;
109 foreach ($categories as $category) {
110 $current = $Winter_MVC_WDK->category_m->get($category, TRUE);
111
112 $list = $Winter_MVC_WDK->category_m->get_by(array('parent_id = '.$current->parent_id => NULL));
113
114 if(isset($placeholder[$level])) {
115 $values_list = array(''=> $placeholder[$level]);
116 } else {
117 $values_list = array(''=> esc_html__('Select Sub Categories','wpdirectorykit'));
118 }
119
120 foreach ($list as $list_value) {
121 $values_list[$list_value->idcategory] = $list_value->category_title;
122 }
123 ?>
124
125 <div data-level="<?php echo esc_attr($level);?>" data-field="<?php echo esc_attr($field_key); ?>" class="wdk-field wdk-col wdk_treefield_dropdown <?php echo esc_attr(wmvc_show_data('field_type', $field_data)); ?> <?php echo esc_attr(wmvc_show_data('class', $field_data)); ?>
126 wdk_field_id_category">
127 <label class="wdk-field-label"><?php echo esc_html(wmvc_show_data('field_label', $field_data)); ?></label>
128 <div class="wdk-field-group">
129 <?php
130 echo wp_kses(
131 wmvc_select_option('category_'.$level, $values_list, $category, 'class="wdk-control"'),
132 array(
133 'select' => array(
134 'id' => true,
135 'name' => true,
136 'class' => true,
137 'style' => true,
138 'multiple' => true,
139 'size' => true,
140 ),
141 'option' => array(
142 'value' => true,
143 'selected' => true,
144 'disabled' => true,
145 ),
146 )
147 );
148 ?>
149
150 </div>
151 </div>
152
153 <?php
154 $level++;
155 }
156
157 if($level<$level_max ) {
158 for (; $level<$level_max;) {
159
160 if(isset($placeholder[$level])) {
161 $values_list = array(''=> $placeholder[$level]);
162 } else {
163 $values_list = array(''=> esc_html__('Select Sub Categories','wpdirectorykit'));
164 }
165
166 ?>
167
168 <div data-level="<?php echo esc_attr($level);?>" data-field="<?php echo esc_attr($field_key); ?>" class="wdk-field wdk-col wdk_treefield_dropdown <?php echo esc_attr(wmvc_show_data('field_type', $field_data)); ?> <?php echo esc_attr(wmvc_show_data('class', $field_data)); ?>">
169 <label class="wdk-field-label"><?php echo esc_html(wmvc_show_data('field_label', $field_data)); ?></label>
170 <div class="wdk-field-group">
171 <?php
172 echo wp_kses(
173 wmvc_select_option('category_'.$level, $values_list, NULL, 'class="wdk-control"'),
174 array(
175 'select' => array(
176 'id' => true,
177 'name' => true,
178 'class' => true,
179 'style' => true,
180 'multiple' => true,
181 'size' => true,
182 ),
183 'option' => array(
184 'value' => true,
185 'selected' => true,
186 'disabled' => true,
187 ),
188 )
189 );
190 ?>
191
192 </div>
193 </div>
194
195 <?php
196 $level++;
197 }
198 }
199 ?>
200 <?php else:?>
201 <div class="wdk-field wdk-col <?php echo esc_attr(wmvc_show_data('field_type', $field_data)); ?> <?php echo esc_attr(wmvc_show_data('class', $field_data)); ?>">
202 <label class="wdk-field-label"><?php echo esc_html(wmvc_show_data('field_label', $field_data)); ?></label>
203 <div class="wdk-field-group">
204 <?php if(wdk_get_option('wdk_multi_categories_search_field_type') == 'select2'):?>
205 <?php
206 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.WP.I18n.NonSingularStringLiteralText
207 echo wdk_treefield_select_ajax ($field_key.'[]', 'category_m', $field_value, 'category_title','idcategory', '', __('All Categories', 'wpdirectorykit'), $filter_ids);?>
208 <?php elseif(wdk_get_option('wdk_multi_categories_search_field_type') == 'wdk_treefield_checkboxes'):?>
209 <?php
210 wp_enqueue_style( 'wdk-treefield-checkboxes');
211 wp_enqueue_script( 'wdk-treefield-checkboxes');
212 ?>
213 <?php
214 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.WP.I18n.NonSingularStringLiteralText
215 echo wdk_treefield_option_checkboxes('search_category', 'category_m', $field_value, 'category_title', '', __('All Categories', 'wpdirectorykit'), $filter_ids);
216
217 ?>
218
219 <?php else:?>
220 <?php
221 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.WP.I18n.NonSingularStringLiteralText
222 echo wdk_treefield_option('search_category', 'category_m', $field_value, 'category_title', '', __('All Categories', 'wpdirectorykit'), $filter_ids, FALSE, '', $hide_fields);
223 ?>
224
225 <?php endif;?>
226 </div>
227 </div>
228 <?php endif;?>