PluginProbe
WP Directory Kit / 1.2.9
WP Directory Kit v1.2.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.2.9, at application/views/search_fields/CATEGORY.php

171 lines 7.4 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 $placeholder = esc_html__($placeholder,'wpdirectorykit');
19
20 $filter_ids = array();
21 if(isset($predefinedfields_query) && !empty($predefinedfields_query[$field_key])) {
22 $field_value = intval($predefinedfields_query[$field_key]);
23 }
24
25 if(isset($_GET['category_root'])) {
26 $predefinedfields_query['custom_category_root'] = sanitize_text_field($_GET['category_root']);
27 }
28
29 if(isset($predefinedfields_query) && !empty($predefinedfields_query['custom_category_root'])) {
30 $custom_field_value = intval($predefinedfields_query['custom_category_root']);
31 global $Winter_MVC_WDK;
32 $Winter_MVC_WDK->load_helper('listing');
33 $Winter_MVC_WDK->model('category_m');
34 $category = $Winter_MVC_WDK->category_m->get($custom_field_value, TRUE);
35 /* if root search childs */
36 if(isset($_GET['category_root']) || empty(wmvc_show_data('parent_id', $category, false, TRUE, TRUE))) {
37 $filter_ids = wdk_category_get_all_childs($custom_field_value);
38 if(!empty($filter_ids)) {
39 if(in_array($field_value, $filter_ids) === FALSE) {
40 $field_value = $custom_field_value;
41 }
42 } else {
43 $filter_ids[] = $custom_field_value;
44 }
45 }
46 }
47
48 if(isset($_GET[$field_key])) {
49 $field_value = ($_GET[$field_key]);
50 }
51
52 $hide_fields = '';
53 if(wmvc_show_data('search_type_tree_hide', $field_data)) {
54 $hide_fields = wmvc_show_data('search_type_tree_hide', $field_data);
55 }
56 wdk_search_fields_toggle();
57 ?>
58 <?php if(isset($custom_field_value)):?>
59 <input type="hidden" name="search_category[]" value="<?php echo esc_attr($custom_field_value);?>">
60 <?php endif;?>
61 <?php if(wdk_get_option('wdk_multi_categories_search_field_type') == 'wdk_treefield_dropdown'):?>
62 <?php
63 global $Winter_MVC_WDK;
64 $Winter_MVC_WDK->load_helper('listing');
65 $Winter_MVC_WDK->model('category_m');
66
67 $categories = array();
68 if(!empty($field_value)) {
69 $categories[] = $field_value;
70 $category = $Winter_MVC_WDK->category_m->get($field_value, TRUE);
71
72 while(!empty($category->parent_id)) {
73 $category = $Winter_MVC_WDK->category_m->get($category->parent_id, TRUE);
74 $categories[] = $category->idcategory;
75 }
76 krsort($categories);
77 } else {
78 $categories[] = 0;
79 }
80
81 wp_enqueue_style('wdk-treefield-dropdown');
82 wp_enqueue_script('wdk-treefield-dropdown');
83 wp_enqueue_style( 'dashicons' );
84
85
86 $level_max = $Winter_MVC_WDK->category_m->get_max_level();
87
88 $placeholder = [
89 0 => esc_html__('Select Categories','wpdirectorykit'),
90 1 => esc_html__('Select Sub Categories','wpdirectorykit'),
91 2 => esc_html__('Select Sub Categories','wpdirectorykit'),
92 3 => esc_html__('Select Sub Categories','wpdirectorykit'),
93 4 => esc_html__('Select Sub Categories','wpdirectorykit'),
94 5 => esc_html__('Select Sub Categories','wpdirectorykit'),
95 ];
96
97
98 ?>
99
100 <input name="<?php echo esc_attr($field_key); ?>" type="hidden" value="<?php echo esc_attr($field_value); ?>">
101 <?php
102 $level = 0;
103 foreach ($categories as $category) {
104 $current = $Winter_MVC_WDK->category_m->get($category, TRUE);
105
106 $list = $Winter_MVC_WDK->category_m->get_by(array('parent_id = '.$current->parent_id => NULL));
107
108 if(isset($placeholder[$level])) {
109 $values_list = array(''=> $placeholder[$level]);
110 } else {
111 $values_list = array(''=> esc_html__('Select Sub Categories','wpdirectorykit'));
112 }
113
114 foreach ($list as $list_value) {
115 $values_list[$list_value->idcategory] = $list_value->category_title;
116 }
117 ?>
118
119 <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)); ?>
120 wdk_field_id_category">
121 <label class="wdk-field-label"><?php echo esc_html(wmvc_show_data('field_label', $field_data)); ?></label>
122 <div class="wdk-field-group">
123 <?php echo wmvc_select_option('category_'.$level, $values_list, $category, 'class="wdk-control"');?>
124 </div>
125 </div>
126
127 <?php
128 $level++;
129 }
130
131 if($level<$level_max ) {
132 for (; $level<$level_max;) {
133
134 if(isset($placeholder[$level])) {
135 $values_list = array(''=> $placeholder[$level]);
136 } else {
137 $values_list = array(''=> esc_html__('Select Sub Categories','wpdirectorykit'));
138 }
139
140 ?>
141
142 <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)); ?>">
143 <label class="wdk-field-label"><?php echo esc_html(wmvc_show_data('field_label', $field_data)); ?></label>
144 <div class="wdk-field-group">
145 <?php echo wmvc_select_option('category_'.$level, $values_list, NULL, 'class="wdk-control"');?>
146 </div>
147 </div>
148
149 <?php
150 $level++;
151 }
152 }
153 ?>
154 <?php else:?>
155 <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)); ?>">
156 <label class="wdk-field-label"><?php echo esc_html(wmvc_show_data('field_label', $field_data)); ?></label>
157 <div class="wdk-field-group">
158 <?php if(wdk_get_option('wdk_multi_categories_search_field_type') == 'select2'):?>
159 <?php echo wdk_treefield_select_ajax ($field_key.'[]', 'category_m', $field_value, 'category_title','idcategory', '', __('All Categories', 'wpdirectorykit'), $filter_ids);?>
160 <?php elseif(wdk_get_option('wdk_multi_categories_search_field_type') == 'wdk_treefield_checkboxes'):?>
161 <?php
162 wp_enqueue_style( 'wdk-treefield-checkboxes');
163 wp_enqueue_script( 'wdk-treefield-checkboxes');
164 ?>
165 <?php echo wdk_treefield_option_checkboxes ('search_category', 'category_m', $field_value, 'category_title', '', __('All Categories', 'wpdirectorykit'), $filter_ids);?>
166 <?php else:?>
167 <?php echo wdk_treefield_option ('search_category', 'category_m', $field_value, 'category_title', '', __('All Categories', 'wpdirectorykit'), $filter_ids, FALSE, '', $hide_fields);?>
168 <?php endif;?>
169 </div>
170 </div>
171 <?php endif;?>