PluginProbe
WP Directory Kit / 1.5.4
WP Directory Kit v1.5.4
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 / helpers / Basic.php

Basic.php in WP Directory Kit 1.5.4, at application/helpers/Basic.php

5,374 lines 209.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 function wdk_generate_fields($fields, $db_data, $form = NULL)
8 {
9 if(is_array($fields))
10 foreach($fields as $field)
11 {
12 $field = (object) $field;
13
14 $field_type = $field->field_type;
15
16 $field_view_path = WPDIRECTORYKIT_PATH.'application/views/fields_edit/'.$field_type.'.php';
17
18 if(file_exists($field_view_path))
19 {
20 include $field_view_path;
21 }
22 else
23 {
24 echo __('Missing VIEW file:', 'wpdirectorykit').' '.esc_html($field_type).'.php';
25 }
26 }
27 }
28
29 if ( ! function_exists('wdk_generate_search_form'))
30 {
31 function wdk_generate_search_form($form_id=1, $subfolder='', $print = TRUE, $predefinedfields_query = array())
32 {
33 /* load WMVC data */
34 $WMVC = &wdk_get_instance();
35 $WMVC->model('searchform_m');
36 $WMVC->model('field_m');
37 $output = '';
38
39 /* get WMVC form data */
40 $fields = $WMVC->searchform_m->get($form_id, TRUE);
41 $user_fields = NULL;
42
43 /* get WMVC form fields */
44 if(is_object($fields))
45 $user_fields = json_decode($fields->searchform_json);
46 /* generate WMVC form fields html */
47 if(is_array($user_fields))
48 foreach($user_fields as $used_field)
49 {
50
51 if($used_field->field_id == 'cat') {
52 $field = array(
53 "idfield" => 'category',
54 "field_type" => 'CATEGORY',
55 "field_label" => __('Category', 'wpdirectorykit'),
56 "prefix" => '',
57 "suffix" => '',
58 "values_list" => '',
59 "placeholder" => '',
60 );
61 }else if($used_field->field_id == 'loc') {
62 $field = array(
63 "idfield" => 'location',
64 "field_type" => 'LOCATION',
65 "field_label" => __('Location', 'wpdirectorykit'),
66 "prefix" => '',
67 "suffix" => '',
68 "values_list" => '',
69 "placeholder" => '',
70 );
71 }else if($used_field->field_id == 'address') {
72 $field = array(
73 "idfield" => 'address',
74 "field_type" => 'INPUTBOX',
75 "field_label" => __('Address', 'wpdirectorykit'),
76 "prefix" => '',
77 "suffix" => '',
78 "values_list" => '',
79 "placeholder" => '',
80 );
81 }else if($used_field->field_id == 'post_title') {
82 $field = array(
83 "idfield" => 'post_title',
84 "field_type" => 'INPUTBOX',
85 "field_label" => __('Title', 'wpdirectorykit'),
86 "prefix" => '',
87 "suffix" => '',
88 "values_list" => '',
89 "placeholder" => '',
90 );
91 }else if($used_field->field_id == 'search') {
92 $field = array(
93 "idfield" => 'search',
94 "field_type" => 'INPUTBOX',
95 "field_label" => __('Search', 'wpdirectorykit'),
96 "prefix" => '',
97 "suffix" => '',
98 "values_list" => '',
99 "placeholder" => '',
100 );
101 }else if(function_exists('run_wdk_bookings') && $used_field->field_id == 'booking_date') {
102 $field = array(
103 "idfield" => 'booking_date',
104 "field_type" => 'BOOKINGS_DATE',
105 "field_label" => __('Booking Date', 'wpdirectorykit'),
106 "prefix" => '',
107 "suffix" => '',
108 "values_list" => '',
109 "placeholder" => '',
110 );
111 }else if(function_exists('run_wdk_bookings') && $used_field->field_id == 'booking_guest') {
112 $field = array(
113 "idfield" => 'booking_guest',
114 "field_type" => 'NUMBER',
115 "field_label" => __('Booking Max Guests', 'wpdirectorykit'),
116 "prefix" => '',
117 "suffix" => '',
118 "values_list" => '',
119 "placeholder" => '',
120 );
121 }else if($used_field->field_id == 'more') {
122 $field = array(
123 "idfield" => 'MORE',
124 "field_type" => 'MORE',
125 "field_label" => __('MORE', 'wpdirectorykit'),
126 "prefix" => '',
127 "suffix" => '',
128 "values_list" => '',
129 "placeholder" => '',
130 );
131 } else {
132 $field_data = $WMVC->field_m->get_fields_data($used_field->field_id);
133 if($field_data) {
134 if($used_field->query_type == 'slider_range') {
135 $field = array(
136 "idfield" => wmvc_show_data('idfield', $field_data),
137 "field_type" => 'SLIDER_RANGE',
138 "field_label" =>wmvc_show_data('field_label', $field_data),
139 "prefix" => wmvc_show_data('prefix', $field_data),
140 "suffix" => wmvc_show_data('suffix', $field_data),
141 "value_min" => wmvc_show_data('value_min', $used_field),
142 "value_max" => wmvc_show_data('value_max', $used_field),
143 "values_list" => wmvc_show_data('values_list', $field_data),
144 "placeholder" => wmvc_show_data('placeholder', $field_data)
145 );
146 } else {
147 $field = array(
148 "idfield" => wmvc_show_data('idfield', $field_data),
149 "field_type" => wmvc_show_data('field_type', $field_data),
150 "field_label" =>wmvc_show_data('field_label', $field_data),
151 "prefix" => wmvc_show_data('prefix', $field_data),
152 "suffix" => wmvc_show_data('suffix', $field_data),
153 "values_list" => wmvc_show_data('values_list', $field_data),
154 "placeholder" => wmvc_show_data('placeholder', $field_data),
155 "is_select_2_ajax_field_db_suggestion" => wmvc_show_data('is_select_2_ajax_field_db_suggestion', $used_field),
156 );
157 }
158 }
159 }
160
161 /* if field not detected or remove from fields list, skip field in search */
162 if(empty($field)) continue;
163
164 /* add from user fields data */
165 $field['field_id'] = wmvc_show_data('field_id', $used_field);
166 $field['class'] = wmvc_show_data('class', $used_field);
167 $field['query_type'] = wmvc_show_data('query_type', $used_field);
168 $field['columns'] = wmvc_show_data('columns', $used_field);
169
170
171 $field_data = array();
172 $field_data ['field_data'] = $field;
173 $field_data ['predefinedfields_query'] = $predefinedfields_query;
174
175 if(in_array(wmvc_show_data('field_type', $field),array('SECTION'))) {
176 continue;
177 }
178
179 $field_view_path = WPDIRECTORYKIT_PATH.'application/views/search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)).'.php';
180 if(file_exists($field_view_path))
181 {
182 $output .= $WMVC->view('search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)), $field_data, FALSE);
183 }
184 else
185 {
186 /* show missing view file of field, only if print enable */
187 if($print)
188 $output .= __('Missing VIEW file:', 'wpdirectorykit').' '.esc_html($subfolder).(wmvc_show_data('field_type', $field)).'.php';
189 }
190
191 }
192
193 if($print){
194 echo $output;
195 return FALSE;
196 }
197
198 return $output;
199 }
200 }
201
202 if ( ! function_exists('wdk_generate_search_form_fields_elementor'))
203 {
204 function wdk_generate_search_form_fields_elementor($fields_array = array(), $subfolder='', $print = TRUE, $predefinedfields_query = array())
205 {
206 /* load WMVC data */
207 $WMVC = &wdk_get_instance();
208 $WMVC->model('searchform_m');
209 $WMVC->model('field_m');
210 $output = '';
211
212 foreach ($fields_array as $key => $el_field_data) {
213 $field_id = wmvc_show_data('field_id', $el_field_data, '');
214 if(empty($field_id)) continue;
215
216 if(strpos($field_id,'__') !== FALSE){
217 $field_id = substr($field_id, strpos($field_id,'__')+2);
218 }
219
220 $field = NULL;
221 if($field_id == 'category_id') {
222 $field = array(
223 "idfield" => 'category',
224 "field_type" => 'CATEGORY',
225 "field_label" => __('Category', 'wpdirectorykit'),
226 "prefix" => '',
227 "suffix" => '',
228 "values_list" => '',
229 "placeholder" => '',
230 );
231 }else if($field_id == 'location_id') {
232 $field = array(
233 "idfield" => 'location',
234 "field_type" => 'LOCATION',
235 "field_label" => __('Location', 'wpdirectorykit'),
236 "prefix" => '',
237 "suffix" => '',
238 "values_list" => '',
239 "placeholder" => '',
240 );
241 }else if($field_id == 'address') {
242 $field = array(
243 "idfield" => 'address',
244 "field_type" => 'INPUTBOX',
245 "field_label" => __('Address', 'wpdirectorykit'),
246 "prefix" => '',
247 "suffix" => '',
248 "values_list" => '',
249 "placeholder" => '',
250 );
251 }else if($field_id == 'post_title') {
252 $field = array(
253 "idfield" => 'post_title',
254 "field_type" => 'INPUTBOX',
255 "field_label" => __('Title', 'wpdirectorykit'),
256 "prefix" => '',
257 "suffix" => '',
258 "values_list" => '',
259 "placeholder" => '',
260 );
261 }else if($field_id == 'search') {
262 $field = array(
263 "idfield" => 'search',
264 "field_type" => 'INPUTBOX',
265 "field_label" => __('Search', 'wpdirectorykit'),
266 "prefix" => '',
267 "suffix" => '',
268 "values_list" => '',
269 "placeholder" => '',
270 );
271 }else if(function_exists('run_wdk_bookings') && $field_id == 'booking_date') {
272 $field = array(
273 "idfield" => 'booking_date',
274 "field_type" => 'BOOKINGS_DATE',
275 "field_label" => __('Booking Date', 'wpdirectorykit'),
276 "prefix" => '',
277 "suffix" => '',
278 "values_list" => '',
279 "placeholder" => '',
280 );
281 }else if($field_id == 'more') {
282 $field = array(
283 "idfield" => 'MORE',
284 "field_type" => 'MORE',
285 "field_label" => __('MORE', 'wpdirectorykit'),
286 "prefix" => '',
287 "suffix" => '',
288 "values_list" => '',
289 "placeholder" => '',
290 );
291 } else {
292 $field_data = $WMVC->field_m->get_fields_data($field_id);
293
294 if($field_data) {
295 if(wmvc_show_data('search_type', $el_field_data, '') == 'slider_range') {
296 $field = array(
297 "idfield" => wmvc_show_data('idfield', $field_data),
298 "field_type" => 'SLIDER_RANGE',
299 "field_label" =>wmvc_show_data('field_label', $field_data),
300 "prefix" => wmvc_show_data('prefix', $field_data),
301 "suffix" => wmvc_show_data('suffix', $field_data),
302 "value_min" => wmvc_show_data('value_min', $el_field_data),
303 "value_max" => wmvc_show_data('value_max', $el_field_data),
304 "values_list" => wmvc_show_data('values_list', $field_data),
305 "placeholder" => wmvc_show_data('placeholder', $field_data)
306 );
307 } else {
308 $field = array(
309 "idfield" => wmvc_show_data('idfield', $field_data),
310 "field_type" => wmvc_show_data('field_type', $field_data),
311 "field_label" =>wmvc_show_data('field_label', $field_data),
312 "prefix" => wmvc_show_data('prefix', $field_data),
313 "suffix" => wmvc_show_data('suffix', $field_data),
314 "values_list" => wmvc_show_data('values_list', $field_data),
315 "placeholder" => wmvc_show_data('placeholder', $field_data)
316 );
317 }
318 }
319 }
320
321 if(wmvc_show_data('field_placeholder', $el_field_data, false)) {
322 $field['placeholder'] = wmvc_show_data('field_placeholder', $el_field_data, false);
323 }
324
325 if(wmvc_show_data('search_type_tree_hide', $el_field_data, false)) {
326 $field['search_type_tree_hide'] = wmvc_show_data('search_type_tree_hide', $el_field_data, false);
327 }
328
329 /* if field not detected or remove from fields list, skip field in search */
330 if(empty($field)) continue;
331
332 /* add from user fields data */
333 $field['field_id'] = wmvc_show_data('idfield', $field);
334 $field['class'] = wmvc_show_data('field_css_class', $el_field_data);
335 $field['query_type'] = wmvc_show_data('search_type', $el_field_data);
336 $field['columns'] = wmvc_show_data('field_columns_number', $el_field_data);
337
338
339 $field_data = array();
340 $field_data ['field_data'] = $field;
341 $field_data ['predefinedfields_query'] = $predefinedfields_query;
342
343 if(in_array(wmvc_show_data('field_type', $field),array('SECTION'))) {
344 continue;
345 }
346
347 $field_suffix = strtoupper(wmvc_show_data('search_type_tree', $el_field_data,''));
348
349 $field_view_path = WPDIRECTORYKIT_PATH.'application/views/search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)).$field_suffix.'.php';
350 if(file_exists($field_view_path))
351 {
352 $output .= $WMVC->view('search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)).$field_suffix, $field_data, FALSE);
353 }
354 else
355 {
356 /* show missing view file of field, only if print enable */
357 if($print)
358 $output .= __('Missing VIEW file:', 'wpdirectorykit').' '.esc_html($subfolder).(wmvc_show_data('field_type', $field)).$field_suffix.'.php';
359 }
360 }
361
362 if($print){
363 echo $output;
364 return FALSE;
365 }
366
367 return $output;
368 }
369 }
370
371
372 function &wdk_get_instance()
373 {
374 global $Winter_MVC_WDK;
375
376 if(empty($Winter_MVC_WDK))
377 {
378 $Winter_MVC_WDK = new MVC_Loader(plugin_dir_path( __FILE__ ).'../../');
379
380 $Winter_MVC_WDK->load_helper('basic');
381 }
382
383 return $Winter_MVC_WDK;
384 }
385
386 function wdk_prepare_search_query_GET($columns = array(), $model_name = NULL, $external_columns = array(), $custom_parameters = array(), $skip_postget = FALSE)
387 {
388
389 global $Winter_MVC_WDK;
390 $WMVC = &$Winter_MVC_WDK;
391 $wdk_bookings_joinded = false;
392 static $available_fields_listings = NULL;
393 static $available_fields_static = array();
394 static $list_fields_static = NULL;
395 $fields_type = array();
396
397 /* add if missing columns */
398 if(!in_array('post_id', $columns)) {
399 $columns[] = $Winter_MVC_WDK->db->prefix.'wdk_listings.post_id';
400 }
401
402 $_GET_clone = array();
403
404 if(!$skip_postget)
405 $_GET_clone = array_merge($_GET, $_POST);
406
407 if(isset($_GET_clone['order_by']) && $_GET_clone['order_by'] =='undefined') {
408 unset($_GET_clone['order_by']);
409 }
410
411 if(isset($custom_parameters['order_by'])) {
412
413 if(isset($_GET_clone['order_by']) && !empty($_GET_clone['order_by'])) {
414 $_GET_clone['order_by'] = ((!empty($custom_parameters['order_by'])) ? $custom_parameters['order_by'].', ':'').sanitize_text_field($_GET_clone['order_by']);
415 } elseif(!empty( $custom_parameters['order_by'])) {
416 $_GET_clone['order_by'] = $custom_parameters['order_by'];
417 }
418
419 unset($custom_parameters['order_by']);
420 }
421
422
423 if(!empty($custom_parameters))
424 $_GET_clone = array_merge($_GET_clone, $custom_parameters);
425
426 $WMVC->model('listing_m');
427 $WMVC->model('field_m');
428 $WMVC->model('listingfield_m');
429
430 $smart_search = '';
431 if(isset($_GET_clone['search']))
432 $smart_search = wdk_esc_sql(sanitize_text_field($_GET_clone['search']));
433
434 if(isset($_GET_clone['field_search']))
435 $smart_search = wdk_esc_sql(sanitize_text_field($_GET_clone['field_search']));
436
437 if(!isset($available_fields_static[$model_name]))
438 {
439 $available_fields = $WMVC->$model_name->get_available_fields();
440
441 $available_fields_static[$model_name] = $available_fields;
442 }
443 else
444 {
445 $available_fields = $available_fields_static[$model_name];
446 }
447
448 if($available_fields_listings === NULL)
449 $available_fields_listings = $WMVC->listingfield_m->get_available_fields();
450
451 /* Пet column names from wdk_listings_fields and add to allow search +
452 in _GET_clone replace field_#id to field_id_TYPE*/
453
454 if($list_fields_static === NULL)
455 {
456 $WMVC->db->where(array('field_type !='=> 'SECTION'));
457 $list_fields = $WMVC->field_m->get();
458 $list_fields_static = $list_fields;
459 }
460 else
461 {
462 $list_fields = $list_fields_static;
463 }
464
465
466 foreach($list_fields as $field_data) {
467
468 $field_id = wmvc_show_data('idfield',$field_data);
469 $field_type = wmvc_show_data('field_type',$field_data);
470
471 $fields_type[$field_id] = $field_type;
472 $column_name ='field_'.$field_id.'_'.$field_type;
473 if(!isset($available_fields_listings[$column_name])) continue;
474
475 if(isset($_GET_clone['field_'.$field_id])) {
476
477 if($field_type == 'DROPDOWNMULTIPLE') {
478 $_GET_clone['field_'.$field_id.'_'.$field_type] = $_GET_clone['field_'.$field_id];
479 } else {
480 $_GET_clone['field_'.$field_id.'_'.$field_type] = apply_filters( 'wdk-currency-conversion/convert/default_value',sanitize_text_field($_GET_clone['field_'.$field_id]), $field_id);
481 }
482 }
483
484 if(isset($_GET_clone['field_'.$field_id.'_max'])) {
485 $_GET_clone['field_'.$field_id.'_'.$field_type.'_max'] = apply_filters( 'wdk-currency-conversion/convert/default_value',sanitize_text_field($_GET_clone['field_'.$field_id.'_max']), $field_id);
486 }
487 if(isset($_GET_clone['field_'.$field_id.'_min'])) {
488 $_GET_clone['field_'.$field_id.'_'.$field_type.'_min'] = apply_filters( 'wdk-currency-conversion/convert/default_value',sanitize_text_field($_GET_clone['field_'.$field_id.'_min']), $field_id);
489 }
490 if(isset($_GET_clone['field_'.$field_id.'_exactly'])) {
491 $_GET_clone['field_'.$field_id.'_'.$field_type.'_exactly'] = wdk_clean_mixed($_GET_clone['field_'.$field_id.'_exactly']);
492 }
493
494 $columns[] = $column_name;
495 $columns[] = $column_name.'_max';
496 $columns[] = $column_name.'_min';
497 $columns[] = $column_name.'_exactly';
498 $external_columns[] = $column_name;
499 $external_columns[] = $column_name.'_max';
500 $external_columns[] = $column_name.'_min';
501 $external_columns[] = $column_name.'_exactly';
502 }
503
504 if(isset($_GET_clone['search_agents_ids'])) {
505 $column_name ='agents_ids';
506 $_GET_clone[$column_name] = $_GET_clone['search_agents_ids'];
507 $columns[] = $column_name;
508 $external_columns[] = $column_name;
509 }
510
511 if(isset($_GET_clone['search_user_editor_ids'])) {
512 $column_name ='user_editor_ids';
513 $_GET_clone[$column_name] = $_GET_clone['search_user_editor_ids'];
514 $columns[] = $column_name;
515 $external_columns[] = $column_name;
516 }
517
518 if(isset($_GET_clone['search_location'])) {
519 $column_name ='location_id';
520 $_GET_clone[$column_name] = $_GET_clone['search_location'];
521 $columns[] = $column_name;
522 $external_columns[] = $column_name;
523 }
524
525 if(isset($_GET_clone['search_category'])) {
526 $column_name ='category_id';
527 $_GET_clone[$column_name] = $_GET_clone['search_category'];
528 $columns[] = $column_name;
529 $external_columns[] = $column_name;
530 }
531
532 if(isset($_GET_clone['search_gps'])) {
533 $column_name ='gps';
534 $_GET_clone[$column_name] = $_GET_clone['search_gps'];
535 $columns[] = $column_name;
536 $external_columns[] = $column_name;
537 }
538
539 if(isset($_GET_clone['field_address'])) {
540 $column_name ='address';
541 $_GET_clone[$column_name] = $_GET_clone['field_address'];
542 $columns[] = $column_name;
543 $external_columns[] = $column_name;
544 }
545
546 if(isset($_GET_clone['field_post_id'])) {
547 $column_name ='ID_exactly';
548 $_GET_clone[$column_name] = sanitize_text_field($_GET_clone['field_post_id']);
549 $columns[] = $column_name;
550 $external_columns[] = $column_name;
551 }
552
553 if(isset($_GET_clone['field_post_date'])) {
554 $column_name ='post_DATE';
555 $_GET_clone[$column_name] = ($_GET_clone['field_post_date']);
556 $columns[] = $column_name;
557 $external_columns[] = $column_name;
558 }
559
560 if(isset($_GET_clone['field_post_date_min'])) {
561 $column_name ='post_DATE_min';
562 $_GET_clone[$column_name] = ($_GET_clone['field_post_date_min']);
563 $columns[] = $column_name;
564 $external_columns[] = $column_name;
565 }
566
567 if(isset($_GET_clone['field_post_date_max'])) {
568 $column_name ='post_DATE_max';
569 $_GET_clone[$column_name] = ($_GET_clone['field_post_date_max']);
570 $columns[] = $column_name;
571 $external_columns[] = $column_name;
572 }
573
574 if (function_exists('run_wdk_bookings') && isset($_GET_clone['field_booking_date_from'])) {
575 $column_name ='field_booking_date_from';
576 $_GET_clone[$column_name] = $_GET_clone['field_booking_date_from'];
577 $columns[] = $column_name;
578 $external_columns[] = $column_name;
579 }
580
581 if (function_exists('run_wdk_bookings') && isset($_GET_clone['field_booking_date_to'])) {
582 $column_name ='field_booking_date_to';
583 $_GET_clone[$column_name] = $_GET_clone['field_booking_date_to'];
584 $columns[] = $column_name;
585 $external_columns[] = $column_name;
586 }
587
588 if (function_exists('run_wdk_bookings') && isset($_GET_clone['field_booking_guest'])) {
589 $column_name ='field_booking_guest';
590 $_GET_clone[$column_name] = $_GET_clone['field_booking_guest'];
591 $columns[] = $column_name;
592 $external_columns[] = $column_name;
593 }
594
595 if (isset($_GET_clone['search_rank'])) {
596 $column_name ='`rank`';
597 $_GET_clone[$column_name] = $_GET_clone['search_rank'];
598 $columns[] = $column_name;
599 $external_columns[] = $column_name;
600 }
601
602 if (isset($_GET_clone['search_rank_min'])) {
603 $column_name ='`rank`_min';
604 $_GET_clone[$column_name] = $_GET_clone['search_rank_min'];
605 $columns[] = $column_name;
606 $external_columns[] = $column_name;
607 }
608
609 if (isset($_GET_clone['search_rank_max'])) {
610 $column_name ='`rank`_max';
611 $_GET_clone[$column_name] = $_GET_clone['search_rank_max'];
612 $columns[] = $column_name;
613 $external_columns[] = $column_name;
614 }
615
616 //$table_name = substr($model_name, 0, -2);
617 $columns_original = array();
618 foreach($columns as $key=>$val)
619 {
620 $columns_original[$val] = $val;
621
622 // if column contain also "table_name.*"
623 $splited = explode('.', $val);
624 if(wmvc_count($splited) == 2)
625 $val = $splited[1];
626
627 if(isset($available_fields[$val]))
628 {
629
630 }
631 else
632 {
633 if(!in_array($columns[$key], $external_columns))
634 {
635 unset($columns[$key]);
636 }
637 }
638 }
639
640 if(wmvc_count($_GET_clone) > 0)
641 {
642 unset($_GET_clone['search']);
643 unset($_GET_clone['field_search']);
644
645 $WMVC->db->join($WMVC->listing_m->_table_name.' ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'posts'.'.ID', NULL, 'LEFT');
646
647 // For quick/smart search
648 if(wmvc_count($columns) > 0 && !empty($smart_search))
649 {
650 $gen_q = '';
651 foreach($columns as $key=>$value)
652 {
653
654 if($value == 'field_booking_date_from' || $value == 'field_booking_date_to' || $value == 'agents_ids' || $value == 'gps' || $value == 'is_featured' || $value == 'field_booking_guest') continue;
655
656 if(strpos($value, '_CHECKBOX') !== FALSE) continue;
657
658 // if smart is number, search only im number fields
659
660
661 if(is_intval($smart_search)) {
662 if(strpos($value, '_NUMBER') === FALSE /*&& $value != 'category_id' && $value != 'location_id'*/ && strpos($value, 'post_id') === FALSE ) continue;
663 } else {
664 if($value == 'category_id' || $value == 'location_id' || strpos($value, 'post_id') !== FALSE) continue;
665 }
666
667 if(substr_count($value, 'id') > 0 && is_numeric($smart_search))
668 {
669 $gen_q.="$value = $smart_search OR ";
670 }
671 else if(substr_count($value, 'date') > 0)
672 {
673 $gen_search = $smart_search;
674
675 $gen_q.="$value LIKE '%$gen_search%' OR ";
676 }
677 elseif(substr($value, -8) == '_exactly')
678 {
679
680 }
681 elseif(substr($value, -4) == '_max')
682 {
683
684 }
685 else if(substr($value, -4) == '_min')
686 {
687
688 }
689 else if(strpos($value, '_NUMBER') !== FALSE)
690 {
691 if(is_intval($smart_search)){
692 $gen_search = $smart_search;
693 $gen_q.="$value = $gen_search OR ";
694 }
695 }
696 else
697 {
698 $gen_q.="$value LIKE '%$smart_search%' OR ";
699 }
700 }
701
702 /* location / categories */
703 if(!is_intval($smart_search)) {
704 $gen_q.="location_title LIKE '%$smart_search%' OR ";
705 $gen_q.="category_title LIKE '%$smart_search%' OR ";
706
707
708 $gen_q.="`category_table`.`titles_for_search` LIKE '%$smart_search%' OR ";
709 $gen_q.="`location_table`.`titles_for_search` LIKE '%$smart_search%' OR ";
710
711 }
712 /* get address and gps */
713 if(strlen($smart_search) > 5) {
714 $coordinates_center = wdk_get_gps($smart_search);
715 $search_radius = 5;
716 if($coordinates_center && $coordinates_center['lat'] != 0 && is_numeric($search_radius))
717 {
718 $distance_unit = 'km';
719 if(__('km', 'wpdirectorykit') == 'm')
720 {
721 $distance_unit = 'm';
722 }
723
724 // calculate rectangle
725 $rectangle_ne = wdk_getDueCoords($coordinates_center['lat'], $coordinates_center['lng'], 45, $search_radius, $distance_unit);
726 $rectangle_sw = wdk_getDueCoords($coordinates_center['lat'], $coordinates_center['lng'], 225, $search_radius, $distance_unit);
727
728 $gps_ne = explode(', ', $rectangle_ne);
729 $gps_sw = explode(', ', $rectangle_sw);
730
731 $gen_q .="(".$WMVC->db->prefix."wdk_listings.lat < '$gps_ne[0]' AND ".$WMVC->db->prefix."wdk_listings.lat > '$gps_sw[0]' AND
732 ".$WMVC->db->prefix."wdk_listings.lng < '$gps_ne[1]' AND ".$WMVC->db->prefix."wdk_listings.lng > '$gps_sw[1]') OR ";
733
734 }
735 }
736
737 /* detect is gps */
738 if(wdk_is_gps($smart_search)) {
739 $gps = explode(',',$smart_search);
740 $coordinates_center = array('lat'=>trim($gps[0]),'lng'=>trim($gps[1]));
741 $search_radius = 5;
742 if($coordinates_center && $coordinates_center['lat'] != 0 && is_numeric($search_radius))
743 {
744 $distance_unit = 'km';
745 if(__('km', 'wpdirectorykit') == 'm')
746 {
747 $distance_unit = 'm';
748 }
749
750 // calculate rectangle
751 $rectangle_ne = wdk_getDueCoords($coordinates_center['lat'], $coordinates_center['lng'], 45, $search_radius, $distance_unit);
752 $rectangle_sw = wdk_getDueCoords($coordinates_center['lat'], $coordinates_center['lng'], 225, $search_radius, $distance_unit);
753
754 $gps_ne = explode(', ', $rectangle_ne);
755 $gps_sw = explode(', ', $rectangle_sw);
756
757 $gen_q .="(".$WMVC->db->prefix."wdk_listings.lat < '$gps_ne[0]' AND ".$WMVC->db->prefix."wdk_listings.lat > '$gps_sw[0]' AND
758 ".$WMVC->db->prefix."wdk_listings.lng < '$gps_ne[1]' AND ".$WMVC->db->prefix."wdk_listings.lng > '$gps_sw[1]') OR ";
759
760 }
761 }
762
763 $gen_q = substr($gen_q, 0, -4);
764
765 if(!empty($gen_q))
766 $WMVC->db->where("($gen_q)");
767 }
768
769 // For column search
770 if(isset($_GET_clone))
771 {
772 $gen_q = '';
773 foreach($_GET_clone as $key=>$val)
774 {
775 if(!empty($val) && in_array($key, $columns))
776 {
777 $col_name = $key;
778
779 $val = esc_sql($val);
780 //if(isset($key))
781 // $col_name = $key;
782
783 if(strpos($key, 'skip') !== FALSE) continue;
784
785 if($key == 'field_booking_guest')
786 {
787 if(!$wdk_bookings_joinded){
788 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_price ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_price.post_id', NULL, 'LEFT');
789 $WMVC->db->distinct($WMVC->db->prefix.'posts.ID');
790 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_reservation ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_reservation.post_id', NULL, 'LEFT');
791 $wdk_bookings_joinded = true;
792 $gen_q.= $WMVC->db->prefix.'wdk_booking_price.is_activated = 1 AND ';
793 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_calendar ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_calendar.post_id', NULL, 'LEFT');
794 }
795
796 $gen_q.= $WMVC->db->prefix."wdk_booking_calendar.guests >='".intval($val)."' AND ";
797
798 }
799 elseif($key == 'field_booking_date_from')
800 {
801 if(!$wdk_bookings_joinded){
802 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_price ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_price.post_id', NULL, 'LEFT');
803 $WMVC->db->distinct($WMVC->db->prefix.'posts.ID');
804 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_reservation ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_reservation.post_id', NULL, 'LEFT');
805 $wdk_bookings_joinded = true;
806 $gen_q.= $WMVC->db->prefix.'wdk_booking_price.is_activated = 1 AND ';
807 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_calendar ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_calendar.post_id', NULL, 'LEFT');
808 }
809
810 if(wdk_is_date($val))
811 {
812 if(!get_option('wdk_bookings_is_hours_enabled')) {
813 $gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d');
814 $gen_q.= "DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_price.date_from, '%Y-%m-%d') <= '".$gen_search."' AND ";
815 } else {
816 $gen_search = wdk_normalize_date_db($val);
817 $gen_q.= $WMVC->db->prefix."wdk_booking_price.date_from >'".$gen_search."' AND ";
818 }
819 }
820
821 if( isset($_GET_clone['field_booking_date_from']) && isset($_GET_clone['field_booking_date_to'])) {
822
823 if(!get_option('wdk_bookings_is_hours_enabled')) {
824 $gen_search_from = wdk_normalize_date_db($_GET_clone['field_booking_date_from'], 'Y-m-d H:i:s', 'Y-m-d');
825 $gen_search_to = wdk_normalize_date_db($_GET_clone['field_booking_date_to'], 'Y-m-d H:i:s', 'Y-m-d');
826
827 $gen_q.= $WMVC->db->prefix."posts.ID NOT IN (
828 SELECT post_id
829 FROM ".$WMVC->db->prefix."wdk_booking_reservation
830 WHERE
831 ".$WMVC->db->prefix."wdk_booking_reservation.is_approved = 1
832 AND
833 DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_reservation.date_from, '%Y-%m-%d') < '".$gen_search_to."'
834 AND
835 DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_reservation.date_to, '%Y-%m-%d') > '".$gen_search_from."'
836 ) AND ";
837
838 } else {
839 $gen_search_from = wdk_normalize_date_db($_GET_clone['field_booking_date_from']);
840 $gen_search_to = wdk_normalize_date_db($_GET_clone['field_booking_date_to']);
841
842 $gen_q.= $WMVC->db->prefix."posts.ID NOT IN (
843 SELECT post_id
844 FROM ".$WMVC->db->prefix."wdk_booking_reservation
845 WHERE
846 ".$WMVC->db->prefix."wdk_booking_reservation.is_approved = 1
847 AND
848 ".$WMVC->db->prefix."wdk_booking_reservation.date_from < '".$gen_search_to."'
849 AND
850 ".$WMVC->db->prefix."wdk_booking_reservation.date_to > '".$gen_search_from."'
851 ) AND ";
852 }
853 }
854
855 }
856 elseif($key == 'field_booking_date_to')
857 {
858 if(!$wdk_bookings_joinded){
859 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_price ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_price.post_id',NULL, 'LEFT');
860 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_reservation ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_reservation.post_id',NULL, 'LEFT');
861 $wdk_bookings_joinded = true;
862 $gen_q.= $WMVC->db->prefix.'wdk_booking_price.is_activated = 1 AND ';
863 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_calendar ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_calendar.post_id', NULL, 'LEFT');
864 }
865
866 if(wdk_is_date($val))
867 {
868 if(!get_option('wdk_bookings_is_hours_enabled')) {
869 $gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d');
870 $gen_q.= "DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_price.date_to, '%Y-%m-%d') >= '".$gen_search."' AND ";
871 } else {
872 $gen_search = wdk_normalize_date_db($val);
873 $gen_q.= $WMVC->db->prefix."wdk_booking_price.date_to >'".$gen_search."' AND ";
874 }
875 }
876
877 }
878 elseif(substr($key, -8) == '_exactly')
879 {
880 $col_name = substr($key, 0, -8);
881
882 if(is_string($val) && strpos($val, ',') !== FALSE){
883 $val =explode(',', $val);
884 } elseif(is_string($val)){
885 $val =array($val);
886 }
887
888 if(is_array($val))
889 {
890 $sql_search = '';
891 foreach ($val as $v) {
892 if(empty($v)) continue;
893
894 if(!empty($sql_search))
895 $sql_search .= " OR ";
896
897 $sql_search .= " ".$col_name." = '".$v."' ";
898 }
899
900 if(!empty($sql_search))
901 $gen_q.=" ( ".$sql_search." ) AND ";
902 } else {
903
904 $gen_q.=$col_name." = '".$val."' AND ";
905 }
906 }
907 elseif(substr($key, -4) == '_max')
908 {
909 $col_name = substr($key, 0, -4);
910
911 if(strpos($key, 'NUMBER') !== FALSE) {
912 $gen_q.=$col_name." <= ".intval($val)." AND ";
913 } else if(strpos($key, 'DATE') !== FALSE) {
914 if(wdk_is_date($val))
915 {
916 $gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d H:i:s');
917 $gen_q.=$col_name." <= '".$gen_search."' AND ";
918 }
919 } else {
920 $gen_q.=$col_name." <= '".$val."' AND ";
921 }
922 }
923 else if(substr($key, -4) == '_min')
924 {
925 $col_name = substr($key, 0, -4);
926
927 if(strpos($key, 'NUMBER') !== FALSE) {
928 $gen_q.=$col_name." >= ".intval($val)." AND ";
929 } else if(strpos($key, 'DATE') !== FALSE) {
930 if(wdk_is_date($val))
931 {
932 $gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d H:i:s');
933 $gen_q.=$col_name." >= '".$gen_search."' AND ";
934 }
935 } else {
936 $gen_q.=$col_name." >= '".$val."' AND ";
937 }
938 }
939 elseif(substr_count($key, 'id') > 0 && is_numeric($val) && $key != 'agents_ids' && $key !='user_editor_ids' && $key !='location_id' && $key !='category_id')
940 {
941 // ID is always numeric
942
943 if($key == 'location_id') {
944 /* $gen_q .= "(`location_table`.`parent_path` = ".$val." OR ";
945 $gen_q .= "`location_2`.`parent_path` = ".$val." OR ";*/
946 $gen_q .= "(`location_table`.`parent_id` = ".$val." OR ";
947 //$gen_q .= "`".$WMVC->db->prefix."wdk_locations `.`level_0_id` = ".$val." OR ";
948
949 $gen_q .= $col_name." = ".$val.") AND ";
950 } elseif($key == 'category_id') {
951 $gen_q .= "('parent_path' = ".$val." OR ";
952 $gen_q .= $col_name." = ".$val.") AND ";
953 } else {
954 $gen_q.=$col_name." = ".$val." AND ";
955 }
956 }
957 else if(substr_count($key, '_DATE') > 0)
958 {
959 // DATE VALUES
960
961 $gen_search = $val;
962 if(wdk_is_date($val))
963 {
964 $gen_search = wdk_normalize_date_db($gen_search, 'Y-m-d H:i:s', 'Y-m-d');
965 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
966 }
967 else
968 {
969 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
970
971 }
972 }
973 else if(substr_count($key, 'is_') > 0)
974 {
975 // CHECKBOXES
976
977 if($val=='on')
978 {
979 $gen_search = 1;
980 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
981 }
982 else if($val=='off')
983 {
984 $gen_q.=$col_name." IS NULL AND ";
985 }
986 }
987 elseif($key == 'agents_ids')
988 {
989 if(is_string($val) && strpos($val, ',') !== FALSE){
990 $val =explode(',', $val);
991 } elseif(is_string($val)){
992 $val =array($val);
993 }
994
995 if(is_array($val)) {
996
997 $WMVC->db->join($WMVC->db->prefix.'wdk_listings_users ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_listings_users.post_id', NULL, 'LEFT');
998 $WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id');
999 $sql_search = '';
1000 foreach ($val as $v) {
1001 if(empty($v)) continue;
1002
1003 if(!empty($sql_search))
1004 $sql_search .= " OR ";
1005
1006
1007 $sql_search .=" ".$WMVC->listing_m->_table_name.".`user_id_editor` = ".intval($v)." OR `".$WMVC->db->prefix."wdk_listings_users`.`user_id` = ".intval($v)." ";
1008 }
1009
1010 if(!empty($sql_search))
1011 $gen_q.=" ( ".$sql_search." ) AND ";
1012
1013 } elseif(is_string($val) && !empty($val)) {
1014 $WMVC->db->join($WMVC->db->prefix.'wdk_listings_users ON '.$WMVC->db->prefix.'posts.post_id = '.$WMVC->db->prefix.'wdk_listings_users.post_id', NULL, 'LEFT');
1015 $WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id');
1016 $sql_search =" ".$WMVC->listing_m->_table_name.".`user_id_editor` = ".intval($val)." OR `".$WMVC->db->prefix."wdk_listings_users`.`user_id` = ".intval($val)." ";
1017 $gen_q.=" ( ".$sql_search." ) AND ";
1018 }
1019 }
1020 elseif($key == 'user_editor_ids')
1021 {
1022
1023 if(is_array($val)) {
1024
1025 $sql_search = '';
1026 foreach ($val as $v) {
1027 if(empty($v)) continue;
1028
1029 if(!empty($sql_search))
1030 $sql_search .= " OR ";
1031
1032
1033 $sql_search .=" ".$WMVC->listing_m->_table_name.".`user_id_editor` = ".intval($v)." ";
1034 }
1035
1036 if(!empty($sql_search))
1037 $gen_q.=" ( ".$sql_search." ) AND ";
1038
1039 } elseif(is_string($val) && !empty($val)) {
1040 $sql_search =" ".$WMVC->listing_m->_table_name.".`user_id_editor` = ".intval($val)." ";
1041 $gen_q.=" ( ".$sql_search." ) AND ";
1042 }
1043 }
1044 elseif($key == 'location_id')
1045 {
1046 if(empty($val)) continue;
1047
1048 if(is_string($val) && strpos($val, ',') !== FALSE){
1049 $val =explode(',', $val);
1050 } elseif(is_string($val)){
1051 $val =array($val);
1052 }
1053
1054 if(is_array($val)) {
1055
1056 if(false){
1057 $WMVC->db->join($WMVC->db->prefix.'wdk_listings_locations ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_listings_locations.post_id', NULL, 'LEFT');
1058 $WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id');
1059 }
1060
1061 $sql_search = '';
1062 foreach ($val as $v) {
1063 if(empty($v) || !is_intval($v)) continue;
1064
1065 if(!empty($sql_search))
1066 $sql_search .= " OR ";
1067
1068 $sql_search .= " ".$WMVC->listing_m->_table_name.".`location_id`=".intval($v)."";
1069 $sql_search .= " OR `location_table`.`parent_id`=".intval($v)."";
1070
1071 $sql_search .= " OR CONCAT(',', location_table.parent_path, ',') LIKE CONCAT('%,', ".intval($v).", ',%')";
1072
1073 /* other locations */
1074 /* multi select */
1075 if(false){
1076 $sql_search .= " OR `".$WMVC->db->prefix."wdk_listings`.`post_id` IN (SELECT `post_id` FROM `".$WMVC->db->prefix."wdk_listings_locations` WHERE `location_id` = ".intval($v).") ";
1077 } elseif(false) {
1078 $sql_search .= " OR ".$WMVC->db->prefix."wdk_listings_locations.location_id=".intval($v)."";
1079 } else {
1080 $sql_search .= " OR ".$WMVC->listing_m->_table_name.".locations_list LIKE '%,".intval($v).",%'";
1081 }
1082
1083 }
1084
1085 if(!empty($sql_search))
1086 $gen_q.=" ( ".$sql_search." ) AND ";
1087 }
1088 }
1089 elseif($key == 'category_id')
1090 {
1091
1092 if(empty($val)) continue;
1093
1094 if(is_string($val) && strpos($val, ',') !== FALSE){
1095 $val =explode(',', $val);
1096 } elseif(is_string($val)){
1097 $val =array($val);
1098 }
1099
1100
1101 if(is_array($val)) {
1102 if(false){
1103 $WMVC->db->join($WMVC->db->prefix.'wdk_listings_categories ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_listings_categories.post_id', NULL, 'LEFT');
1104 }
1105
1106 $sql_search = '';
1107 foreach ($val as $v) {
1108 if(empty($v) || !is_intval($v)) continue;
1109
1110 if(!empty($sql_search))
1111 $sql_search .= " OR ";
1112
1113 $sql_search .= " ".$WMVC->db->prefix."wdk_listings.`category_id` = ".intval($v)."";
1114 $sql_search .= " OR `category_table`.`parent_id`=".intval($v)."";
1115 $sql_search .= " OR CONCAT(',', category_table.parent_path, ',') LIKE CONCAT('%,', ".intval($v).", ',%')";
1116
1117 /* other categories */
1118 if(false){
1119 $sql_search .= " OR `".$WMVC->db->prefix."wdk_listings`.`post_id` IN (SELECT `post_id` FROM `".$WMVC->db->prefix."wdk_listings_categories` WHERE `category_id` = ".intval($v).")";
1120 } elseif(false) {
1121 $sql_search .= " OR ".$WMVC->db->prefix."wdk_listings_categories.category_id=".intval($v)."";
1122 } else {
1123 $sql_search .= " OR ".$WMVC->listing_m->_table_name.".categories_list LIKE '%,".intval($v).",%'";
1124 }
1125
1126 }
1127
1128 if(!empty($sql_search))
1129 $gen_q.=" ( ".$sql_search." ) AND ";
1130 }
1131 }
1132 elseif(is_string($val))
1133 {
1134
1135 if(strpos($val, ',') !== FALSE){
1136 $val = explode(',', $val);
1137 }
1138
1139 if(is_array($val)) {
1140 $sql_search = '';
1141 foreach ($val as $v) {
1142 if(empty($v)) continue;
1143
1144 if(!empty($sql_search))
1145 $sql_search .= " OR ";
1146
1147 $sql_search .= $col_name." LIKE '%".$v."%'";
1148
1149 }
1150
1151 if(!empty($sql_search))
1152 $gen_q.=" ( ".$sql_search." ) AND ";
1153 } else {
1154 $gen_q.=$col_name." LIKE '%".$val."%' AND ";
1155 }
1156
1157 }
1158 elseif(is_array($val))
1159 {
1160 $sql_search = '';
1161 foreach ($val as $v) {
1162 if(empty($v)) continue;
1163
1164 if(!empty($sql_search))
1165 $sql_search .= " OR ";
1166
1167 $sql_search .= " ".$col_name." LIKE '%".esc_sql($v)."%' ";
1168 }
1169
1170 if(!empty($sql_search))
1171 $gen_q.=" ( ".$sql_search." ) AND ";
1172 }
1173 } elseif ($val == 0) {
1174 $col_name = $key;
1175 $val = esc_sql($val);
1176 if(in_array($col_name, ['`rank`'])) {
1177 $gen_q.=" ( ".$col_name." = 0 OR ".$col_name." IS NULL ) AND ";
1178 }
1179 }
1180 }
1181
1182 $gen_q = substr($gen_q, 0, -5);
1183
1184 if(!empty($gen_q))
1185 $WMVC->db->where("($gen_q)");
1186 }
1187
1188 //if(defined( 'WP_DEBUG' ) && WP_DEBUG)
1189 if(function_exists('pll_current_language'))
1190 {
1191 $lang_term_id = pll_current_language('term_id');
1192
1193 if(is_numeric($lang_term_id))
1194 {
1195 //echo $lang_term_id.'<br />';
1196 $WMVC->db->join($WMVC->db->prefix.'term_relationships ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'term_relationships.object_id', NULL, NULL);
1197 $WMVC->db->where("({$WMVC->db->prefix}term_relationships.term_taxonomy_id = $lang_term_id)");
1198 }
1199 }
1200
1201 // [RECTANGLE SEARCH]
1202 if(isset($_GET_clone['rectangle_ne']) && isset($_GET_clone['rectangle_sw']))
1203 {
1204 if(wdk_is_gps($_GET_clone['rectangle_ne']) && wdk_is_gps($_GET_clone['rectangle_sw'])) {
1205
1206 $gps_ne = explode(',', $_GET_clone['rectangle_ne']);
1207 $gps_sw = explode(',', $_GET_clone['rectangle_sw']);
1208
1209 $WMVC->db->where("(".$WMVC->db->prefix."wdk_listings.lat < '$gps_ne[0]' AND ".$WMVC->db->prefix."wdk_listings.lat > '$gps_sw[0]' AND
1210 ".$WMVC->db->prefix."wdk_listings.lng > '$gps_ne[1]' AND ".$WMVC->db->prefix."wdk_listings.lng < '$gps_sw[1]')");
1211 }
1212 }
1213 // [/RECTANGLE SEARCH]
1214
1215 // order
1216 if (isset($_GET_clone['order_by'])) {
1217 // Merge available fields + system columns
1218 $order_columns = [
1219 'post_id' => $WMVC->db->prefix . 'wdk_listings.post_id',
1220 'counter_views' => $WMVC->db->prefix . 'wdk_listings.counter_views',
1221 'date_modified' => $WMVC->db->prefix . 'wdk_listings.date_modified',
1222 'post_title' => $WMVC->db->prefix . 'posts.post_title',
1223 'address' => $WMVC->db->prefix . 'wdk_listings.address',
1224 'category_id' => $WMVC->db->prefix . 'wdk_listings.category_id',
1225 'location_id' => $WMVC->db->prefix . 'wdk_listings.location_id',
1226 'rank' => $WMVC->db->prefix . 'wdk_listings.rank'
1227 ];
1228
1229 $order_columns = apply_filters('wdk/listings/order_columns', $order_columns);
1230
1231 $_GET_clone['order_by'] = str_replace(
1232 'post_id',
1233 $WMVC->db->prefix . 'wdk_listings.post_id',
1234 sanitize_text_field($_GET_clone['order_by'])
1235 );
1236
1237 // Fix common typos: ask → asc, desk → desc
1238 $_GET_clone['order_by'] = str_ireplace([' ask', ' desk'], [' asc', ' desc'], $_GET_clone['order_by']);
1239
1240 /* we no need field type in get link now */
1241 $_GET_clone['order_by'] = str_ireplace(['_NUMBER', '_SECTION', '_TEXTAREA', '_DATE', '_DROPDOWN', '_DROPDOWNMULTIPLE', '_CHECKBOX'], '', $_GET_clone['order_by']);
1242
1243 // Parse order_by string into parts
1244 $order_by_array = explode(',', $_GET_clone['order_by']);
1245 $final_order_by = [];
1246
1247 foreach ($order_by_array as $order_part) {
1248 $order_part = trim($order_part);
1249
1250 // detect direction asc/desc
1251 $direction = 'DESC';
1252 if (stripos($order_part, ' asc') !== false) {
1253 $direction = 'ASC';
1254 } elseif (stripos($order_part, ' desc') !== false) {
1255 $direction = 'DESC';
1256 }
1257
1258 $order_part = str_ireplace(['desc', 'asc'], '', $order_part);
1259 $order_part = esc_sql(sanitize_textarea_field(str_replace(' ', '', $order_part)));
1260
1261 // Try to detect field_(id)
1262 if (preg_match('/field_(\d+)\b/', $order_part, $matches)) {
1263
1264 $search_field_id = $matches[1];
1265 if (!empty($fields_type[$search_field_id])) {
1266 $field_name = "field_{$search_field_id}_{$fields_type[$search_field_id]}";
1267
1268 // Check if field exists in order_columns
1269 if (isset($available_fields_listings[$field_name])) {
1270 $final_order_by[] = $field_name . ' ' . $direction;
1271 }
1272 }
1273
1274 // else → skip invalid field automatically
1275
1276 } else {
1277 // Extract only the part after the last '.' if exists, else use entire string
1278 $col_field = $order_part;
1279 if (strpos($col_field, '.') !== false) {
1280 $parts = explode('.', $col_field);
1281 $col_field = end($parts);
1282 }
1283
1284 // Check if field exists in order_columns
1285 if (isset($order_columns[$col_field])) {
1286 $safe_column = $order_columns[$col_field];
1287 $final_order_by[] = "$safe_column $direction";
1288 }
1289 }
1290 }
1291
1292 // Apply final order if any valid fields left
1293 if (!empty($final_order_by)) {
1294 $_GET_clone['order_by'] = implode(', ', $final_order_by);
1295 $WMVC->db->order_by($_GET_clone['order_by']);
1296 } else {
1297 $WMVC->db->order_by('');
1298 }
1299
1300 }
1301
1302 }
1303 }
1304
1305 function wdk_users_prepare_search_query_GET($columns = array(), $model_name = NULL, $external_columns = array(), $custom_parameters = array(), $skip_postget = FALSE)
1306 {
1307 global $Winter_MVC_WDK;
1308 $WMVC = &$Winter_MVC_WDK;
1309
1310 $_GET_clone = array();
1311
1312 if(!$skip_postget)
1313 $_GET_clone = array_merge($_GET, $_POST);
1314
1315 if(isset($custom_parameters['order_by'])) {
1316
1317 if(isset($_GET_clone['order_by']) && !empty($_GET_clone['order_by'])) {
1318 $_GET_clone['order_by'] = $custom_parameters['order_by'].', '.sanitize_text_field($_GET_clone['order_by']);
1319 } else {
1320 $_GET_clone['order_by'] = $custom_parameters['order_by'];
1321 }
1322
1323 unset($custom_parameters['order_by']);
1324 }
1325
1326
1327 if(!empty($custom_parameters))
1328 $_GET_clone = array_merge($_GET_clone, $custom_parameters);
1329
1330 $WMVC->model($model_name);
1331
1332 $smart_search = '';
1333 if(isset($_GET_clone['profile_search']))
1334 $smart_search = wdk_esc_sql(sanitize_text_field($_GET_clone['profile_search']));
1335
1336 $available_fields = array('user_login','user_nicename','user_email','user_url','display_name');
1337
1338 if(isset($_GET_clone['is_activated'])){
1339 $_GET_clone[$WMVC->$model_name->_table_name.'.is_activated'] = sanitize_text_field($_GET_clone['is_activated']);
1340 unset($_GET_clone['is_activated']);
1341 }
1342
1343 if(isset($_GET_clone['is_approved'])){
1344 $_GET_clone[$WMVC->$model_name->_table_name.'.is_approved'] = sanitize_text_field($_GET_clone['is_approved']);
1345 unset($_GET_clone['is_approved']);
1346 }
1347
1348
1349 //$table_name = substr($model_name, 0, -2);
1350 $columns_original = array();
1351 foreach($columns as $key=>$val)
1352 {
1353 $columns_original[$val] = $val;
1354
1355 // if column contain also "table_name.*"
1356 $splited = explode('.', $val);
1357 if(wmvc_count($splited) == 2)
1358 $val = $splited[1];
1359
1360 if(isset($available_fields[$val]))
1361 {
1362
1363 }
1364 else
1365 {
1366 if(!in_array($columns[$key], $external_columns))
1367 {
1368 unset($columns[$key]);
1369 }
1370 }
1371 }
1372
1373 if(wmvc_count($_GET_clone) > 0)
1374 {
1375 unset($_GET_clone['search']);
1376
1377 // For quick/smart search
1378 if(wmvc_count($columns) > 0 && !empty($smart_search))
1379 {
1380 $gen_q = '';
1381 foreach($columns as $key=>$value)
1382 {
1383
1384 if($value == 'post_type')
1385 {
1386 $value = $WMVC->$model_name->_table_name.'.'.$value;
1387 }
1388
1389 if(substr_count($value, 'id') > 0 && is_numeric($smart_search))
1390 {
1391 $gen_q.="$value = $smart_search OR ";
1392 }
1393 else if(substr_count($value, 'date') > 0)
1394 {
1395 //$gen_search = wmvc_generate_slug($smart_search, ' ');
1396
1397 $gen_search = $smart_search;
1398
1399 $gen_q.="$value LIKE '%$gen_search%' OR ";
1400 }
1401 else
1402 {
1403 $gen_q.="$value LIKE '%$smart_search%' OR ";
1404 }
1405 }
1406 $gen_q = substr($gen_q, 0, -4);
1407
1408 if(!empty($gen_q))
1409 $WMVC->db->where("($gen_q)");
1410 }
1411
1412 // For column search
1413 if(isset($_GET_clone))
1414 {
1415 $gen_q = '';
1416
1417 foreach($_GET_clone as $key=>$val)
1418 {
1419 if(!empty($val) && in_array($key, $columns))
1420 {
1421 $col_name = $key;
1422
1423 if($col_name == 'post_type')
1424 {
1425 $col_name = $WMVC->$model_name->_table_name.'.'.$col_name;
1426 }
1427
1428 //if(isset($key))
1429 // $col_name = $key;
1430
1431 if(strpos($key, 'skip') !== FALSE) continue;
1432
1433 if(substr($key, -8) == '_exactly')
1434 {
1435 $col_name = substr($key, 0, -8);
1436 $gen_q.=$col_name." = '".$val."' AND ";
1437 }
1438 elseif(substr($key, -4) == '_max')
1439 {
1440 $col_name = substr($key, 0, -4);
1441 $gen_q.=$col_name." <= '".$val."' AND ";
1442 }
1443 else if(substr($key, -4) == '_min')
1444 {
1445 $col_name = substr($key, 0, -4);
1446
1447 $gen_q.=$col_name." >= '".$val."' AND ";
1448 }
1449 elseif(substr_count($key, 'id') > 0 && is_numeric($val))
1450 {
1451 // ID is always numeric
1452
1453 $gen_q.=$col_name." = ".$val." AND ";
1454 }
1455 else if(substr_count($key, 'date') > 0)
1456 {
1457 // DATE VALUES
1458
1459 $gen_search = $val;
1460
1461 if(wdk_is_date($val))
1462 {
1463 $gen_search = wdk_normalize_date_db($gen_search);
1464 $gen_q.=$col_name." > '".$gen_search."' AND ";
1465 }
1466 else
1467 {
1468 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
1469 }
1470 }
1471 else if(substr_count($key, 'is_') > 0)
1472 {
1473 // CHECKBOXES
1474
1475 if($val=='on')
1476 {
1477 $gen_search = 1;
1478 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
1479 }
1480 else if($val=='off')
1481 {
1482 $gen_q.=$col_name." IS NULL AND ";
1483 }
1484 }
1485 else
1486 {
1487 $gen_q.=$col_name." LIKE '%".$val."%' AND ";
1488 }
1489 }
1490
1491 }
1492
1493 $gen_q = substr($gen_q, 0, -5);
1494
1495 if(!empty($gen_q))
1496 $WMVC->db->where("($gen_q)");
1497 }
1498
1499 // order
1500 if(isset($_GET_clone['order_by']))
1501 {
1502 $_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_favorite.post_id', $_GET_clone['order_by']);
1503 $WMVC->db->order_by(wdk_esc_sql(sanitize_text_field($_GET_clone['order_by'])));
1504 }
1505
1506 }
1507 }
1508
1509 function wdk_messages_prepare_search_query_GET($columns = array(), $model_name = NULL, $external_columns = array())
1510 {
1511 global $Winter_MVC_WDK;
1512 $WMVC = &$Winter_MVC_WDK;
1513 $_GET_clone = array_merge($_GET, $_POST);
1514
1515 $_GET_clone = ($_GET_clone);
1516
1517 //$WMVC->model('listing_m');
1518
1519 $smart_search = '';
1520 if(isset($_GET_clone['search']))
1521 $smart_search = wdk_esc_sql(sanitize_text_field($_GET_clone['search']));
1522
1523 $available_fields = $WMVC->$model_name->get_available_fields();
1524
1525 /* Пet column names from wdk_package and add to allow search +
1526 in _GET_clone replace field_#id to field_id_TYPE*/
1527 $list_fields = $WMVC->db->list_fields( $WMVC->db->prefix.'wdk_messages');
1528
1529
1530 //$table_name = substr($model_name, 0, -2);
1531 $columns_original = array();
1532 foreach($columns as $key=>$val)
1533 {
1534 $columns_original[$val] = $val;
1535
1536 // if column contain also "table_name.*"
1537 $splited = explode('.', $val);
1538 if(wmvc_count($splited) == 2)
1539 $val = $splited[1];
1540
1541 if(isset($available_fields[$val]))
1542 {
1543
1544 }
1545 else
1546 {
1547 if(!in_array($columns[$key], $external_columns))
1548 {
1549 unset($columns[$key]);
1550 }
1551 }
1552 }
1553
1554 if(wmvc_count($_GET_clone) > 0)
1555 {
1556 unset($_GET_clone['search']);
1557
1558 // For quick/smart search
1559 if(wmvc_count($columns) > 0 && !empty($smart_search))
1560 {
1561 $gen_q = '';
1562 foreach($columns as $key=>$value)
1563 {
1564 if(substr_count($value, 'id') > 0 && is_numeric($smart_search))
1565 {
1566 $gen_q.="$value = $smart_search OR ";
1567 }
1568 else if(substr_count($value, 'date') > 0)
1569 {
1570 //$gen_search = wmvc_generate_slug($smart_search, ' ');
1571
1572 $gen_search = $smart_search;
1573
1574 $gen_q.="$value LIKE '%$gen_search%' OR ";
1575 }
1576 else
1577 {
1578 $gen_q.="$value LIKE '%$smart_search%' OR ";
1579 }
1580 }
1581 $gen_q = substr($gen_q, 0, -4);
1582
1583 if(!empty($gen_q))
1584 $WMVC->db->where("($gen_q)");
1585 }
1586
1587 // For column search
1588 if(isset($_GET_clone))
1589 {
1590 $gen_q = '';
1591
1592 foreach($_GET_clone as $key=>$val)
1593 {
1594 if(!empty($val) && in_array($key, $columns))
1595 {
1596 $col_name = $key;
1597 //if(isset($key))
1598 // $col_name = $key;
1599
1600 if(strpos($key, 'skip') !== FALSE) continue;
1601
1602 if(substr($key, -8) == '_exactly')
1603 {
1604 $col_name = substr($key, 0, -8);
1605 $gen_q.=$col_name." = '".$val."' AND ";
1606 }
1607 elseif(substr($key, -4) == '_max')
1608 {
1609 $col_name = substr($key, 0, -4);
1610 $gen_q.=$col_name." <= '".$val."' AND ";
1611 }
1612 else if(substr($key, -4) == '_min')
1613 {
1614 $col_name = substr($key, 0, -4);
1615
1616 $gen_q.=$col_name." >= '".$val."' AND ";
1617 }
1618 elseif(substr_count($key, 'id') > 0 && is_numeric($val))
1619 {
1620 // ID is always numeric
1621
1622 $gen_q.=$col_name." = ".$val." AND ";
1623 }
1624 else if(substr_count($key, 'date') > 0)
1625 {
1626 // DATE VALUES
1627
1628 $gen_search = $val;
1629
1630 $detect_date = strtotime($gen_search);
1631
1632 if(wdk_payments_is_date($val) && $detect_date > 1000)
1633 {
1634 $gen_search = date('Y-m-d H:i:s', $detect_date);
1635 $gen_q.=$col_name." > '".$gen_search."' AND ";
1636 }
1637 else
1638 {
1639 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
1640 }
1641 }
1642 else if(substr_count($key, 'is_') > 0)
1643 {
1644 // CHECKBOXES
1645
1646 if($val=='on')
1647 {
1648 $gen_search = 1;
1649 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
1650 }
1651 else if($val=='off')
1652 {
1653 $gen_q.=$col_name." IS NULL AND ";
1654 }
1655 }
1656 else
1657 {
1658 $gen_q.=$col_name." LIKE '%".$val."%' AND ";
1659 }
1660 }
1661
1662 }
1663
1664 $gen_q = substr($gen_q, 0, -5);
1665
1666 if(!empty($gen_q))
1667 $WMVC->db->where("($gen_q)");
1668 }
1669
1670 // order
1671 if(isset($_GET_clone['order_by']))
1672 {
1673 $_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_messages.post_id', $_GET_clone['order_by']);
1674 $WMVC->db->order_by(wdk_esc_sql(sanitize_text_field($_GET_clone['order_by'])));
1675 }
1676
1677 }
1678 }
1679
1680 function wdk_date() {
1681 $date_format = get_option('date_format');
1682 $time_format = get_option('time_format');
1683 $date = date("{$date_format} {$time_format}", current_time('timestamp'));
1684 return $date;
1685 }
1686
1687 if(!function_exists('wdk_placeholder_image_src')) {
1688 function wdk_placeholder_image_src () {
1689 $i = WPDIRECTORYKIT_URL.'public/img/placeholder.jpg';
1690
1691 if(wdk_get_option('wdk_placeholder')) {
1692 $image = wp_get_attachment_image_src(wdk_get_option('wdk_placeholder'), 'full' );
1693 if(!empty($image) && file_exists(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $image[0])))
1694 $i = $image[0];
1695 }
1696
1697 return $i;
1698 }
1699 }
1700
1701
1702 function wdk_wp_frontend_paginate($total_items, $per_page = 10, $page_var = 'wmvc_paged', $texts = array(), $enable_latest_first = TRUE, $enable_count = FALSE, $enable_compact = FALSE, $limit_items = 1)
1703 {
1704 $current_page = 1;
1705
1706 if(isset($_GET[$page_var]))
1707 $current_page = intval(wmvc_xss_clean($_GET[$page_var]));
1708
1709 if(!isset($texts['previous_page']))$texts['previous_page'] = esc_html__('Previous page', 'wpdirectorykit');
1710 if(!isset($texts['next_page']))$texts['next_page'] = esc_html__('Next page', 'wpdirectorykit');
1711 if(!isset($texts['first_page']))$texts['first_page'] = '';
1712 if(!isset($texts['last_page']))$texts['last_page'] = '';
1713 if(!isset($texts['items']))$texts['items'] = esc_html__('items', 'wpdirectorykit');
1714
1715 if(empty($current_page))$current_page = 1;
1716
1717 // get url
1718 $url = strtok(wdk_server_current_url(), '?');
1719
1720
1721 $qs_parameters = wmvc_xss_clean( $_GET );
1722 unset($qs_parameters[$page_var]);
1723 $qs_part = http_build_query($qs_parameters);
1724 $url = wdk_url_suffix($url, $qs_part);
1725
1726 // total pages
1727 $total_pages = intval($total_items/$per_page+0.99);
1728
1729 if($current_page == 1) {
1730 $limit_items = $limit_items * 2;
1731 }
1732
1733 if($current_page == $total_pages) {
1734 $limit_items = $limit_items * 2;
1735 }
1736
1737 $output = '<nav class="wdk-pagination navigation pagination" role="navigation">';
1738 if($enable_count){
1739 $output.= '<span class="displaying-num">'.$total_items.' '.$texts['items'].'</span>';
1740 }
1741
1742 $output .= '<div class="nav-links">';
1743
1744 if($enable_latest_first && $current_page-1 > 0)
1745 $output.= '<a class="next page-numbers scroll-ignore" href="'.esc_url($url).'#results"><span class="screen-reader-text">'.esc_html($texts['first_page']).'</span><span aria-hidden="true">«</span></a>';
1746
1747 if ($current_page-1 > 0) {
1748
1749 $output.= '<a class="next page-numbers scroll-ignore" href="'.esc_url(wdk_url_suffix($url,esc_attr($page_var).'='.esc_attr($current_page-1))).'#results"><span class="screen-reader-text">'.esc_html($texts['previous_page']).'</span><span aria-hidden="true">‹</span></a>';
1750 } elseif($enable_compact)
1751 {
1752 $output.= '<span class="next page-numbers disabled " href=""><span class="screen-reader-text">'.esc_html($texts['previous_page']).'</span><span aria-hidden="true">‹</span></span>';
1753 }
1754
1755 if (!$enable_compact) {
1756 for ($i = 1 ; $i <= $total_pages; $i++) {
1757 $class = ($current_page == $i) ? "active" : "";
1758 if(($current_page-$limit_items) <= $i && ($current_page+$limit_items) >= $i) {
1759 if (($current_page == $i)) {
1760 $output.= '<span aria-current="page" class="page-numbers current">'.$i.'</span>';
1761 } else {
1762 $output.= '<a class="page-numbers scroll-ignore" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($i))).'#results">'.esc_attr($i).'</a>';
1763 }
1764 }
1765 }
1766 } else {
1767 $output.= '<span class="wdk_pages_range">'.$current_page.' '.esc_html__('of','wpdirectorykit').' '.$total_pages.'</span>';
1768 }
1769
1770 if($current_page+1 <= $total_pages)
1771 {
1772 $output.= '<a class="next page-numbers scroll-ignore" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($current_page+1))).'#results"><span class="screen-reader-text">'.esc_html($texts['next_page']).'</span><span aria-hidden="true">›</span></a>';
1773 }
1774 elseif($enable_compact)
1775 {
1776 $output.= '<a class="next page-numbers disabled scroll-ignore" href=""><span class="screen-reader-text">'.esc_html($texts['next_page']).'</span><span aria-hidden="true">›</span></a>';
1777 }
1778
1779 if($enable_latest_first && $current_page+1 <= $total_pages)
1780 $output.= '<a class="next page-numbers scroll-ignore" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($total_pages))).'#results"><span class="screen-reader-text">'.esc_html($texts['last_page']).'</span><span aria-hidden="true">»</span></a>';
1781
1782
1783 $output.= '</div>';
1784 $output.= '</nav>';
1785
1786 return $output;
1787 }
1788
1789 function wdk_viewe($content) {
1790 // @codingStandardsIgnoreStart
1791 echo wp_kses_post($content); // WPCS: XSS ok, sanitization ok.
1792 // @codingStandardsIgnoreEnd
1793 }
1794
1795
1796 if(!function_exists('wdk_search_fields_toggle')){
1797 function wdk_search_fields_toggle ($class_add = NULL){
1798 static $wdk_visible_filters = 0;
1799 global $wdk_visible_filters_limit;
1800 global $wdk_button_search_defined;
1801 global $wdk_enable_search_fields_toggle;
1802 global $wdk_activate_more;
1803
1804 if(!$wdk_enable_search_fields_toggle) return false;
1805
1806 global $wdk_search_fields_toggle_reset;
1807 if($wdk_search_fields_toggle_reset) {
1808 $wdk_visible_filters = 0;
1809 $wdk_search_fields_toggle_reset = false;
1810 }
1811
1812 $wdk_visible_filters++;
1813
1814 if($wdk_activate_more || (!empty($wdk_visible_filters_limit) && !$wdk_button_search_defined && $wdk_visible_filters == $wdk_visible_filters_limit)){
1815 $wdk_button_search_defined=true;
1816 $wdk_activate_more = false;
1817
1818 global $wdk_text_search_button;
1819 if(empty($wdk_text_search_button))
1820 $wdk_text_search_button = esc_html__('Search','wpdirectorykit');
1821
1822 global $wdk_text_reset_button;
1823 if(empty($wdk_text_reset_button))
1824 $wdk_text_reset_button = esc_html__('Reset','wpdirectorykit');
1825
1826 global $wdk_text_more_button;
1827 if(empty($wdk_text_more_button))
1828 $wdk_text_more_button = esc_html__('More','wpdirectorykit');
1829
1830 $form_closed = 'display: none;';
1831 if(isset($_GET['wdk_search_additional_opened']) && wmvc_xss_clean($_GET['wdk_search_additional_opened']) == 1) {
1832 $form_closed = '';
1833 }
1834
1835 ?>
1836 <div class="wdk-col wdk-col-btns">
1837 <div class="wdk-field wdk-field-btn">
1838 <div class="wdk-field-group wdk-field-group-additional">
1839 <button id="wdk-search-additional" type="button" class="wdk-search-additional-btn"><?php echo esc_html($wdk_text_more_button); ?><i class="wdk-toggle-icon"></i></button>
1840 <input type='checkbox' style="display: none !important" value='1' <?php if(isset($_GET['wdk_search_additional_opened']) && wmvc_xss_clean($_GET['wdk_search_additional_opened']) == 1):?> checked <?php endif;?> name='wdk_search_additional_opened' />
1841 </div>
1842 <div class="wdk-field-group wdk-field-group-reset">
1843 <button title="<?php echo esc_attr__('Reset','wpdirectorykit');?>" id="wdk-reset-primary" type="reset" class="wdk-search-start wdk-search-reset wdk-click-load-animation"><?php echo esc_html($wdk_text_reset_button);?></button>
1844 </div>
1845 <div class="wdk-field-group wdk-field-group-search">
1846 <button title="<?php echo esc_attr__('Search','wpdirectorykit');?>" id="wdk-start-primary" type="submit" class="wdk-search-start wdk-click-load-animation">&nbsp;&nbsp;<?php echo esc_html($wdk_text_search_button);?>&nbsp;<i class="fa fa-spinner fa-spin fa-ajax-indicator" style="display: none;"></i>&nbsp;</button>
1847
1848 <?php if(function_exists('run_wdk_save_search') && get_option('wdk_save_search_show_on_searchform')):?>
1849 <div class="section-widget-control right">
1850 <a class="wdk-c-btn wdk-c-edit wdk-save-search-button" href="#" data-url="<?php echo esc_url(admin_url('admin-ajax.php')); ?>" title="<?php echo esc_attr_e('Save Search', 'selio'); ?>" target="_blank">
1851 <i class="fas fa-save" aria-hidden="true"></i>
1852 <i class="fa fa-spinner fa-spin fa-ajax-indicator"></i>
1853 </a>
1854 </div>
1855 <?php endif;?>
1856 </div>
1857 </div>
1858 </div>
1859 <div id='wdk-form-additional' class="wdk-col" style="<?php echo esc_attr($form_closed) ;?>">
1860 <div class="wdk-row">
1861 <?php
1862 }
1863 }
1864 }
1865
1866
1867 /*
1868 * @param $filter_ids string|array, included ids, what will be visible, other skiped, if set 1_fetch_child, where 1 is category_id, will be detected all childs and filtered, for visible
1869 *
1870 */
1871 if ( ! function_exists('wdk_treefield_option'))
1872 {
1873 function wdk_treefield_option($name = '', $table=NULL, $selected = NULL,
1874 $column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE, $sql_where='', $hide_fields = '')
1875 {
1876 $WMVC = &wdk_get_instance();
1877
1878 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
1879
1880 static $counter = 0;
1881
1882 $model_name = $table;
1883 if($table == 'calendar_listing_m')
1884 $model_name = 'listing_m';
1885
1886 $table_name = str_replace('_m', '', $table);
1887
1888 $attribute_id = 'id'.$table_name;
1889
1890 if($table_name == 'icons_list') {
1891
1892 } else {
1893 $WMVC->model($model_name);
1894 $attribute_id = $WMVC ->$model_name->_primary_key;
1895 $selected = (int) $selected;
1896 }
1897
1898 if(empty($selected))
1899 $selected='';
1900
1901 $form = '<input name="'.$name.'" value="'.$selected.'" class="wdk-hidden" type="text" id="wdktreeelem'.$counter.'" readonly/>';
1902
1903 $skip_id = '';
1904 //load javascript library
1905 if($counter==0)
1906 {
1907 wp_enqueue_script('wdk-treefield');
1908 wp_enqueue_style('wdk-treefield');
1909 }
1910 ?>
1911 <script>
1912 jQuery(document).ready(function($) {
1913 $('#wdktreeelem<?php echo esc_js($counter);?>:not(.init)').wdkTreefield({
1914 ajax_url: '<?php echo admin_url('admin-ajax.php'); ?>',
1915 ajax_param: {
1916 "page": 'wdk_frontendajax',
1917 "function": 'treefieldid',
1918 "action": 'wdk_public_action',
1919 "wdk_secure": '<?php echo wp_create_nonce( 'wdk_secure_treefieldid' );?>',
1920 "table": '<?php echo esc_js($table); ?>',
1921 "filter_ids": '<?php echo esc_js($filter_ids); ?>',
1922 "start_id": '<?php if(!empty($filter_ids)) esc_js($selected); else echo ""; ?>',
1923 "empty_value": '<?php echo esc_js($empty_value); ?>',
1924 "user_check": '<?php echo esc_js($user_check); ?>',
1925 "sql_where": '<?php echo esc_js($sql_where); ?>',
1926 "hide_fields": '<?php echo esc_js($hide_fields); ?>'
1927 },
1928 attribute_id: '<?php echo esc_js($attribute_id); ?>',
1929 language_id: '<?php echo esc_js($language_id); ?>',
1930 attribute_value: '<?php echo esc_js($column); ?>',
1931 skip_id: '<?php echo esc_js($skip_id); ?>',
1932 empty_value: ' - ',
1933 text_search: '<?php esc_html_e('Search term', 'wpdirectorykit');?>',
1934 text_no_results: '<?php esc_html_e('No results found', 'wpdirectorykit');?>',
1935 callback_selected: function(key) {
1936 $('#wdktreeelem<?php echo esc_js($counter);?>').trigger("change");
1937 }
1938 }).addClass('init');
1939 });
1940 </script>
1941 <?php
1942 $counter++;
1943 return $form;
1944 }
1945 }
1946
1947 /*
1948 * @param $filter_ids string|array, included ids, what will be visible, other skiped, if set 1_fetch_child, where 1 is category_id, will be detected all childs and filtered, for visible
1949 *
1950 */
1951 if ( ! function_exists('wdk_treefield_option_checkboxes'))
1952 {
1953 function wdk_treefield_option_checkboxes($name = '', $table=NULL, $selected = NULL,
1954 $column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE, $sql_where='', $hide_fields = '')
1955 {
1956 $WMVC = &wdk_get_instance();
1957
1958 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
1959
1960 static $counter = 0;
1961
1962 $model_name = $table;
1963
1964 $table_name = str_replace('_m', '', $table);
1965
1966 $attribute_id = 'id'.$table_name;
1967
1968
1969 $WMVC->model($model_name);
1970 $attribute_id = $WMVC ->$model_name->_primary_key;
1971
1972 $values = '';
1973 if(!empty($selected)){
1974 $ids = array();
1975 if(is_string($selected) && strpos($selected, ',') !== FALSE){
1976 $val_selected = explode(',', $selected);
1977 } elseif($selected){
1978 $val_selected = array($selected);
1979 }
1980
1981 foreach($val_selected as $selected_item) {
1982 if(!empty($selected_item) && is_intval($selected_item)) {
1983 $ids [] = $selected_item;
1984 }
1985 }
1986
1987 /* where in */
1988 if(!empty($ids)){
1989 $WMVC->db->select($WMVC->$table->_table_name.'.*');
1990 $WMVC->db->where($WMVC->$table->_table_name.'.'.$WMVC->$table->_primary_key.' IN(' . implode(',', $ids) . ')', null, false);
1991 $WMVC->db->order_by('FIELD('.$WMVC->$table->_table_name.'.'.$WMVC->$table->_primary_key.', '. implode(',', $ids) . ')');
1992
1993 $results = $WMVC->$table->get();
1994 foreach ($results as $item) {
1995 if($item) {
1996 $values .= wmvc_show_data($column, $item, false, TRUE, TRUE).',';
1997 }
1998 }
1999 $values = substr($values,0,-1);
2000
2001 if(strlen($values)>23) {
2002 $values = substr($values,0,20).'...';
2003 }
2004 }
2005 }
2006
2007 if(empty($values)) {
2008 $values = $empty_value;
2009 }
2010
2011 $form = '<input name="'.$name.'" value="'.esc_html($selected).'" data-placehoder="'.esc_html($values).'" class="wdk-hidden" type="text" id="wdktreeelem_checkbox'.$counter.'" readonly/>';
2012
2013 $skip_id = '';
2014 //load javascript library
2015 if($counter==0)
2016 {
2017 wp_enqueue_script('wdk-treefield');
2018 wp_enqueue_style('wdk-treefield');
2019 }
2020 ?>
2021 <script>
2022 jQuery(document).ready(function($) {
2023 $('#wdktreeelem_checkbox<?php echo esc_js($counter);?>:not(.init)').wdkTreefieldCheckboxes({
2024 ajax_url: '<?php echo admin_url('admin-ajax.php'); ?>',
2025 ajax_param: {
2026 "page": 'wdk_frontendajax',
2027 "function": 'treefieldid_checkboxes',
2028 "action": 'wdk_public_action',
2029 "wdk_secure": '<?php echo wp_create_nonce( 'wdk_secure_treefieldid_checkboxes' );?>',
2030 "table": '<?php echo esc_js($table); ?>',
2031 "filter_ids": '<?php echo esc_js($filter_ids); ?>',
2032 "empty_value": '<?php echo esc_js($empty_value); ?>',
2033 "user_check": '<?php echo esc_js($user_check); ?>',
2034 "hide_fields": '<?php echo esc_js($hide_fields); ?>',
2035 },
2036 selected: '<?php echo esc_js($selected); ?>',
2037 attribute_id: '<?php echo esc_js($attribute_id); ?>',
2038 language_id: '<?php echo esc_js($language_id); ?>',
2039 attribute_value: '<?php echo esc_js($column); ?>',
2040 skip_id: '<?php echo esc_js($skip_id); ?>',
2041 empty_value: ' - ',
2042 text_search: '<?php esc_html_e('Search term', 'wpdirectorykit');?>',
2043 text_no_results: '<?php esc_html_e('No results found', 'wpdirectorykit');?>',
2044 callback_selected: function(key) {
2045 $('#wdktreeelem_checkbox<?php echo esc_js($counter);?>').trigger("change");
2046 }
2047 }).addClass('init');
2048 });
2049 </script>
2050 <?php
2051 $counter++;
2052 return $form;
2053 }
2054 }
2055
2056 if ( ! function_exists('wdk_filter_decimal'))
2057 {
2058 function wdk_filter_decimal($string = '')
2059 {
2060 if(wdk_get_option('wdk_enable_filter_zero_decimal')) {
2061 if(substr($string, -3, 3) === ",00") {
2062 return substr($string, 0, -3);
2063 }
2064 if(substr($string, -3, 3) === ".00") {
2065 return substr($string, 0, -3);
2066 }
2067 if(substr($string, -3, 1) === "." && substr($string, -1, 1) === "0") {
2068 return substr($string, 0, -1);
2069 }
2070 }
2071
2072 return $string;
2073 }
2074 }
2075
2076 if ( ! function_exists('wdk_is_date'))
2077 {
2078 function wdk_is_date($date, $format = 'Y-m-d H:i:s')
2079 {
2080
2081 /* check is date on strtotime */
2082 if((bool)strtotime($date)){
2083 return true;
2084 }
2085
2086 /* check is date from argument */
2087 $d = \DateTime::createFromFormat($format, $date);
2088 if($d) {
2089 return true;
2090 }
2091
2092 /* check is date from wp date and time */
2093 $d = \DateTime::createFromFormat(get_option('date_format').' '.get_option('time_format'), $date);
2094 if($d) {
2095 return true;
2096 }
2097
2098 /* check is date from wp date */
2099 $d = \DateTime::createFromFormat(get_option('date_format'), $date);
2100 if($d) {
2101 return true;
2102 }
2103
2104 /* try with default */
2105 if('Y-m-d H:i:s' != $format) {
2106 $d = \DateTime::createFromFormat('Y-m-d H:i:s', $date);
2107 if($d) {
2108 return true;
2109 }
2110
2111 $d = \DateTime::createFromFormat('Y-m-d', $date);
2112 if($d) {
2113 return true;
2114 }
2115 }
2116
2117 /* issue with pm/am inside date, example bug format like "2023 01 19 pm8:06" => 'Y n j ag:i' */
2118 $format = get_option('date_format').' '.get_option('time_format');
2119 if(strpos($format, 'a') !== FALSE) {
2120 $format = str_replace('a', '',$format).' a';
2121 if(strpos($date, 'am') !== FALSE) {
2122 $date = str_replace('am', '',$date).' am';
2123 }
2124 if(strpos($date, 'pm') !== FALSE) {
2125 $date = str_replace('pm', '',$date).' pm';
2126 }
2127 $d = \DateTime::createFromFormat($format, $date);
2128 if($d) {
2129 return true;
2130 }
2131 }
2132
2133 return false;
2134 }
2135 }
2136
2137
2138 if ( ! function_exists('wdk_normalize_date_db'))
2139 {
2140 /**
2141 * Convert date to db format, from wp format
2142 * @param string $date Date in string
2143 * @param string $format Special format
2144 * @param string $format Special format
2145 * @param string $return_format return date format
2146 * @return string date in format Y-m-d H:i:s
2147 */
2148 function wdk_normalize_date_db($date, $format = 'Y-m-d H:i:s', $return_format = 'Y-m-d H:i:s')
2149 {
2150
2151 /* check is date from argument */
2152 $d = \DateTime::createFromFormat($format, $date);
2153 if($d) {
2154 return $d->format($return_format);
2155 }
2156
2157 /* check is date from wp date and time */
2158 $d = \DateTime::createFromFormat(get_option('date_format').' '.get_option('time_format'), $date);
2159 if($d) {
2160 return $d->format($return_format);
2161 }
2162
2163 /* check is date from wp date */
2164 $d = \DateTime::createFromFormat(get_option('date_format'), $date);
2165 if($d) {
2166 return $d->format($return_format);
2167 }
2168
2169 /* try with default */
2170 if('Y-m-d H:i:s' != $format) {
2171 $d = \DateTime::createFromFormat('Y-m-d H:i:s', $date);
2172 if($d) {
2173 return $d->format($return_format);
2174 }
2175
2176 $d = \DateTime::createFromFormat('Y-m-d', $date);
2177 if($d) {
2178 return $d->format($return_format);
2179 }
2180 }
2181
2182 /* issue with pm/am inside date, example bug format like "2023 01 19 pm8:06" => 'Y n j ag:i' */
2183 $format = get_option('date_format').' '.get_option('time_format');
2184 if(strpos($format, 'a') !== FALSE) {
2185 $format = str_replace('a', '',$format).' a';
2186 if(strpos($date, 'am') !== FALSE) {
2187 $date = str_replace('am', '',$date).' am';
2188 }
2189 if(strpos($date, 'pm') !== FALSE) {
2190 $date = str_replace('pm', '',$date).' pm';
2191 }
2192 $d = \DateTime::createFromFormat($format, $date);
2193 if($d) {
2194 return $d->format($return_format);
2195 }
2196 }
2197
2198 /* check is date on strtotime */
2199 if((bool)strtotime($date)){
2200 return date($return_format, strtotime($date));
2201 }
2202
2203 return false;
2204 }
2205 }
2206
2207 if ( ! function_exists('wdk_url_suffix'))
2208 {
2209 function wdk_url_suffix($base_url, $extension_url="")
2210 {
2211 if(substr($base_url, -1) == '?'){
2212 $base_url .='';
2213 } elseif(strpos($base_url,'?') !== FALSE){
2214 $base_url .='&';
2215 } else {
2216 $base_url .='?';
2217 }
2218 return $base_url.$extension_url;
2219 }
2220 }
2221
2222
2223 /**
2224 * Insert an attachment from a remote URL.
2225 *
2226 * @param string $url Remote file URL.
2227 * @param int|null $parent_post_id Post ID to attach the image to.
2228 * @return int|false Attachment ID or false on failure.
2229 */
2230 function wdk_insert_attachment_from_cloud_url($url, $parent_post_id = null) {
2231 // Request with headers (Google blocks requests without UA sometimes)
2232 $response = wp_remote_get($url, array(
2233 'timeout' => 30,
2234 'redirection' => 5,
2235 'headers' => array(
2236 'User-Agent' => 'Mozilla/5.0 (WordPress)',
2237 'Referer' => home_url()
2238 )
2239 ));
2240
2241 if (is_wp_error($response)) {
2242 return false;
2243 }
2244
2245 $code = wp_remote_retrieve_response_code($response);
2246 if ($code != 200) {
2247 return false;
2248 }
2249
2250 $body = wp_remote_retrieve_body($response);
2251 if (empty($body)) {
2252 return false;
2253 }
2254
2255 // Try to get filename from URL or headers
2256 $filename = basename(parse_url($url, PHP_URL_PATH));
2257
2258 // If filename empty (Google Drive case)
2259 if (!$filename || strpos($filename, '.') === false) {
2260 // Try content-disposition header
2261 $headers = wp_remote_retrieve_headers($response);
2262 if (!empty($headers['content-disposition']) &&
2263 preg_match('/filename="?([^"]+)"?/i', $headers['content-disposition'], $matches)) {
2264 $filename = sanitize_file_name($matches[1]);
2265 }
2266 }
2267
2268 // If still no extension, detect from mime
2269 $ext = pathinfo($filename, PATHINFO_EXTENSION);
2270 if (empty($ext)) {
2271 $data = getimagesizefromstring($body);
2272 if (!$data || empty($data['mime'])) {
2273 return false;
2274 }
2275 $ext = wdk_mime2ext($data['mime']);
2276 $filename = time() . '-' . wp_generate_password(6, false) . '.' . $ext;
2277 }
2278
2279 // Save file to uploads dir
2280 $upload = wp_upload_bits($filename, null, $body);
2281 if (!empty($upload['error'])) {
2282 return false;
2283 }
2284
2285 $file_path = $upload['file'];
2286 $file_name = basename($file_path);
2287 $file_type = wp_check_filetype($file_name, null);
2288 $wp_upload_dir = wp_upload_dir();
2289
2290 $post_info = array(
2291 'guid' => $wp_upload_dir['url'] . '/' . $file_name,
2292 'post_mime_type' => $file_type['type'],
2293 'post_title' => sanitize_file_name(pathinfo($file_name, PATHINFO_FILENAME)),
2294 'post_content' => '',
2295 'post_status' => 'inherit',
2296 );
2297
2298 // Insert attachment
2299 $attach_id = wp_insert_attachment($post_info, $file_path, $parent_post_id);
2300
2301 if (!$attach_id) {
2302 return false;
2303 }
2304
2305 // Generate metadata
2306 require_once ABSPATH . 'wp-admin/includes/image.php';
2307 $attach_data = wp_generate_attachment_metadata($attach_id, $file_path);
2308 wp_update_attachment_metadata($attach_id, $attach_data);
2309
2310 return $attach_id;
2311 }
2312
2313 /**
2314 * Insert an attachment from an URL address.
2315 *
2316 * @param String $url
2317 * @param Int $parent_post_id
2318 * @return Int Attachment ID
2319 */
2320 function wdk_insert_attachment_from_url($url, $parent_post_id = null) {
2321
2322 if( !class_exists( 'WP_Http' ) )
2323 include_once( ABSPATH . WPINC . '/class-http.php' );
2324
2325 $http = new WP_Http();
2326 $response = $http->request( $url );
2327 if( is_wp_error($response) || $response['response']['code'] != 200 ) {
2328 return false;
2329 }
2330
2331 $filename = basename($url);
2332 if(strpos($filename, '?')!==FALSE) {
2333 $filename = substr($filename, 0, strpos($filename, '?'));
2334 }
2335
2336 /* if unsoported extension */
2337 if(in_array(wdk_file_extension($filename), array('php','asp')) || strlen(wdk_file_extension($filename)) > 5){
2338 $data = getimagesizefromstring($response['body']);
2339 if(!$data) return false;
2340 if(empty($data['mime'])) return false;
2341
2342 $filename = time().rand(0000,9999).'.'.wdk_mime2ext($data['mime']);
2343 }
2344 $upload = wp_upload_bits( $filename, null, $response['body'] );
2345
2346 if( !empty( $upload['error'] ) ) {
2347 return false;
2348 }
2349
2350 $file_path = $upload['file'];
2351 $file_name = basename( $file_path );
2352 $file_type = wp_check_filetype( $file_name, null );
2353 $attachment_title = sanitize_file_name( pathinfo( $file_name, PATHINFO_FILENAME ) );
2354 $wp_upload_dir = wp_upload_dir();
2355
2356 $post_info = array(
2357 'guid' => $wp_upload_dir['url'] . '/' . $file_name,
2358 'post_mime_type' => $file_type['type'],
2359 'post_title' => $attachment_title,
2360 'post_content' => '',
2361 'post_status' => 'inherit',
2362 );
2363 // Create the attachment
2364 $attach_id = wp_insert_attachment( $post_info, $file_path, $parent_post_id );
2365
2366 // Include image.php
2367 require_once( ABSPATH . 'wp-admin/includes/image.php' );
2368
2369 // Define attachment metadata
2370 $attach_data = wp_generate_attachment_metadata( $attach_id, $file_path );
2371
2372 // Assign metadata to attachment
2373 wp_update_attachment_metadata( $attach_id, $attach_data );
2374
2375 return $attach_id;
2376
2377 }
2378
2379 if(!function_exists('wdk_jsdateformat')) {
2380 function wdk_jsdateformat($format = '') {
2381 $date_specific = array(
2382 // Day
2383 'd' => 'dd',
2384 'D' => 'D',
2385 'j' => 'd',
2386 'l' => 'DD',
2387 'N' => '',
2388 'S' => '',
2389 'w' => '',
2390 'z' => 'o',
2391 // Week
2392 'W' => '',
2393 // Month
2394 'F' => 'MM',
2395 'm' => 'mm',
2396 'M' => 'M',
2397 'n' => 'm',
2398 't' => '',
2399 // Year
2400 'L' => '',
2401 'o' => '',
2402 'y' => 'y',
2403 'Y' => 'yy',
2404 // Time
2405 'a' => '',
2406 'A' => '',
2407 'B' => '',
2408 'g' => '',
2409 'G' => '',
2410 'h' => '',
2411 'H' => '',
2412 'i' => '',
2413 's' => '',
2414 'u' => ''
2415 );
2416 return str_replace(array_keys($date_specific), array_values($date_specific), $format);
2417 }
2418
2419 }
2420
2421 function wdk_current_url()
2422 {
2423 global $wp;
2424 return add_query_arg( $wp->query_vars, home_url( $wp->request ) );
2425 }
2426
2427 if(!function_exists('wdk_generate_profile_permalink')) {
2428 /**
2429 * Insert user id and return link on user profile page
2430 *
2431 * @return Int user ID
2432 */
2433
2434 function wdk_generate_profile_permalink($profile = array())
2435 {
2436 $profile_slug = '';
2437 if(is_intval($profile)){
2438 $profile_data = get_userdata($profile);
2439 if(wmvc_show_data('wdk_slug', $profile_data, false)){
2440 $profile_slug = wmvc_show_data('wdk_slug', $profile);
2441 }elseif(wmvc_show_data('user_login', $profile_data, false)){
2442 $profile_slug = wmvc_show_data('user_login', $profile_data);
2443 } else {
2444 $profile_slug = $profile;
2445 }
2446 } else if(wmvc_show_data('user_login', $profile, false)){
2447 $profile_slug = wmvc_show_data('user_login', $profile);
2448 if(wmvc_show_data('wdk_slug', $profile))
2449 $profile_slug = wmvc_show_data('wdk_slug', $profile);
2450 }
2451
2452 $user_profile_page = get_option('wdk_membership_profile_preview_page');
2453 if(!$user_profile_page) {
2454 return '#';
2455 }
2456 // for polylang to detect translated page version
2457 if(function_exists('pll_get_post'))
2458 $user_profile_page = pll_get_post($user_profile_page);
2459
2460 return wdk_url_suffix(get_permalink($user_profile_page), 'slug='. $profile_slug);
2461 }
2462 }
2463
2464 if(!function_exists('wdk_get_profile_page_id')) {
2465 /**
2466 * Insert user id and return link on user profile page
2467 *
2468 * @return Int user ID
2469 */
2470
2471 function wdk_get_profile_page_id()
2472 {
2473 global $wp_query;
2474 if(get_option('wdk_membership_profile_preview_page') && isset($wp_query->post) && get_option('wdk_membership_profile_preview_page') == $wp_query->post->ID) {
2475 if (wmvc_show_data('slug', $_GET, false)) {
2476 if(is_intval(wmvc_show_data('slug', $_GET))) {
2477 return wmvc_show_data('slug', $_GET);
2478 } else {
2479
2480 $args = array(
2481 'meta_key' => 'wdk_slug',
2482 'meta_value' => sanitize_text_field(wmvc_show_data('slug', $_GET)),
2483 'meta_compare' => '='
2484 );
2485 $by_slug_user_detected = get_users($args);
2486
2487 $profile = false;
2488 if(!empty($by_slug_user_detected)) {
2489 $profile = $by_slug_user_detected[0];
2490 } else {
2491 $profile = get_user_by('login',wmvc_show_data('slug', $_GET));
2492 }
2493
2494 return (wmvc_show_data('ID', $profile, false)) ? wmvc_show_data('ID', $profile, false) : false;
2495 }
2496 }
2497 }
2498
2499 return false;
2500 }
2501 }
2502
2503 if(!function_exists('wdk_get_date')) {
2504 /**
2505 * Return date in format
2506 *
2507 */
2508 function wdk_get_date($datetime = NULL, $time = TRUE, $default='timestamp')
2509 {
2510 $init_datetime = $datetime;
2511 if(is_null($datetime))
2512 {
2513 if($default == 'timestamp')
2514 {
2515 $datetime = current_time('timestamp');
2516 }
2517 else
2518 {
2519 return $default;
2520 }
2521 }
2522 else if(!is_numeric($datetime))
2523 {
2524 $datetime = strtotime($datetime);
2525 }
2526
2527 $date_format = get_option('date_format');
2528
2529 $time_format = ($time && strpos($init_datetime, '00:00:00')===FALSE) ? get_option('time_format') : '';
2530
2531 $date = date_i18n("{$date_format} {$time_format}", $datetime);
2532 return $date;
2533 }
2534 }
2535
2536 if(!function_exists('wdk_login_url')) {
2537 /**
2538 * Return date in format
2539 * @param string|url redirect url
2540 * @param string custom_message, showed on login form like alert, visible only on wdk login form
2541 */
2542 function wdk_login_url($url_redirect = '', $custom_message = '')
2543 {
2544 $url = wp_login_url($url_redirect);
2545
2546 if(get_option('wdk_membership_login_page')){
2547 $url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')));
2548 if(!empty($url_redirect)) {
2549 $url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')), 'redirect_to='. urlencode($url_redirect));
2550 }
2551 if(!empty($custom_message)) {
2552 $url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')), 'custom_message='. urlencode($custom_message));
2553 }
2554 }
2555
2556 return trim($url, '?');
2557 }
2558 }
2559
2560 if(!function_exists('wdk_mail')) {
2561 /**
2562 * Return date in format
2563 * @param string|url redirect url
2564 */
2565 function wdk_mail( $email_to, $subject = '', $data = array(), $layout = 'default', $email_from = '', $attachments = array(), $reply_to = '')
2566 {
2567 $WMVC = &wdk_get_instance();
2568
2569 $ret = false;
2570 if(empty($email_from))
2571 $email_from = get_bloginfo('admin_email');
2572
2573 if(empty($subject))
2574 $subject = __("New message", "wpdirectorykit");
2575
2576 $headers = array('Content-Type: text/html; charset=UTF-8');
2577 $headers[] = 'From: "'.get_bloginfo('name').'" <'.$email_from.'>';
2578
2579 if(!empty($reply_to)) {
2580 $headers[] = 'Reply-To: '.$reply_to;
2581 } else {
2582 $headers[] = 'Reply-To: '.$email_from;
2583 }
2584
2585 $data['subject'] = $subject;
2586
2587 $message = $WMVC->view('email/'.$layout, $data, FALSE);
2588 $ret = wp_mail( $email_to, $subject, $message, $headers, $attachments );
2589
2590 return $ret;
2591 }
2592 }
2593
2594 if(!function_exists('wdk_show_data')) {
2595 function wdk_show_data($field_name, &$db_value = NULL, $default = '', $xss_clean = TRUE, $skip_post = FALSE)
2596 {
2597 if(!$skip_post && isset($_POST[$field_name]))
2598 {
2599 if($xss_clean === FALSE)
2600 return stripslashes($_POST[$field_name]);
2601
2602 return wmvc_xss_clean(stripslashes($_POST[$field_name]));
2603 }
2604
2605
2606 if(is_array($db_value))
2607 {
2608 if(isset($db_value[$field_name]))
2609 {
2610 if($xss_clean === FALSE)
2611 return $db_value[$field_name];
2612
2613 return wmvc_xss_clean($db_value[$field_name]);
2614 }
2615 else
2616 {
2617 return $default;
2618 }
2619 }
2620
2621 if(is_object($db_value))
2622 {
2623 if(isset($db_value->$field_name))
2624 {
2625 if($xss_clean === FALSE)
2626 return $db_value->$field_name;
2627
2628 return wmvc_xss_clean($db_value->$field_name);
2629 }
2630 else
2631 {
2632 return $default;
2633 }
2634 }
2635
2636 if(!empty($db_value))
2637 {
2638 if($xss_clean === FALSE)
2639 return $db_value;
2640
2641 return wmvc_xss_clean($db_value);
2642 }
2643
2644 if($xss_clean === FALSE)
2645 return $default;
2646
2647 return wmvc_xss_clean($default);
2648 }
2649 }
2650
2651
2652 if (!function_exists('wdk_input_checked'))
2653 {
2654 function wdk_input_checked($field_id, $db_data, $value = 1)
2655 {
2656
2657 if(wmvc_show_data($field_id, $db_data, false) && wmvc_show_data($field_id, $db_data) == $value)
2658 {
2659 return 'checked';
2660 }
2661
2662 return '';
2663 }
2664 }
2665
2666 function wdk_upload_file($field_name, $file_id)
2667 {
2668 static $media_element_counter = 0;
2669
2670 $media_element_counter++;
2671
2672 $img_field = $field_name.'_'.$media_element_counter;
2673
2674 wp_register_script( 'wpmediaelement_file', WPDIRECTORYKIT_URL . 'admin/js/jquery.wpmediaelement_file.js', array( 'jquery' ), false, false );
2675 wp_enqueue_script( 'wpmediaelement_file' );
2676 wp_enqueue_media();
2677
2678 ?>
2679 <div id="<?php echo esc_attr($field_name); ?>meta-box-id" class="postbox-upload">
2680 <?php
2681 // Get WordPress' media upload URL
2682 $upload_link = '#';
2683
2684 // Get the file src
2685
2686 // Get the file src
2687 $your_file_src = get_attached_file(intval( $file_id));
2688
2689 // For convenience, see if the array is valid
2690 $you_have_file = false;
2691 if($your_file_src)
2692 $you_have_file = basename($your_file_src);
2693
2694 ?>
2695
2696 <!-- Your file container, which can be manipulated with js -->
2697 <div class="custom-img-container">
2698 <?php if ( $you_have_file ) : ?>
2699 <?php echo esc_html($you_have_file); ?>
2700 <?php endif; ?>
2701 </div>
2702
2703 <?php //if(sw_user_in_role('administrator')): ?>
2704 <!-- Your add & remove file links -->
2705 <p class="hide-if-no-js">
2706 <a class="upload-custom-img <?php if ( $you_have_file ) { echo 'hidden'; } ?>"
2707 href="<?php echo esc_url($upload_link) ?>">
2708 <?php echo esc_html__('Select file','wmvc_win') ?>
2709 </a>
2710 <a class="delete-custom-img <?php if ( ! $you_have_file ) { echo 'hidden'; } ?>"
2711 href="#">
2712 <?php echo esc_html__('Remove all files','wmvc_win') ?>
2713 </a>
2714 </p>
2715 <?php //endif; ?>
2716
2717 <!-- A hidden input to set and post the chosen file id -->
2718 <input class="logo_file_id" type="hidden" id="<?php echo esc_html($field_name); ?>" name="<?php echo esc_html($field_name); ?>" value="<?php echo esc_html($file_id); ?>" />
2719 </div>
2720
2721 <?php
2722 $custom_js ='';
2723 $custom_js .=" jQuery(function($) {
2724 if( typeof jQuery.fn.wpMediaElementFile == 'function')
2725 $('#".esc_js($field_name)."meta-box-id.postbox-upload').wpMediaElementFile();
2726 });";
2727
2728 echo "<script>".$custom_js."</script>";
2729
2730 ?>
2731
2732 <?php
2733 }
2734
2735 if ( ! function_exists('wdk_file_extension'))
2736 {
2737 function wdk_file_extension($filepath)
2738 {
2739
2740 /* filters */
2741 if(strpos($filepath, '?') !== FALSE) {
2742 $filepath = $filepath;
2743 $filepath = substr($filepath, 0,strpos($filepath, '?'));
2744 }
2745 if(strpos($filepath, '#') !== FALSE) {
2746 $filepath = $filepath;
2747 $filepath = substr($filepath, 0,strpos($filepath, '#'));
2748 }
2749
2750 return substr($filepath, strrpos($filepath, '.')+1);
2751 }
2752 }
2753
2754 if ( ! function_exists('wdk_file_extension_type'))
2755 {
2756 /**
2757 * Get image type based on extension
2758 *
2759 * @param string $filepath string path(url) to file with extension
2760 * @return string type of file (image,video,docs)
2761 */
2762 function wdk_file_extension_type($filepath = NULL)
2763 {
2764
2765 if(in_array(wdk_file_extension($filepath),array('jpg','jpeg','bmp','png','webp'))) {
2766 return 'image';
2767 }
2768 if(in_array(wdk_file_extension($filepath),array('mp4','mov','flv','mkv','avi','webm'))) {
2769 return 'video';
2770 }
2771
2772 return 'docs';
2773 }
2774 }
2775
2776 function wdk_upload_multi_files($field_name, $image_ids='', $texts = array())
2777 {
2778 static $media_element_counter = 0;
2779
2780 if(!isset($texts['file_select']))$texts['file_select'] = esc_html__('Select file','wmvc_win');
2781 if(!isset($texts['file_remove']))$texts['file_remove'] = esc_html__('Remove all files','wmvc_win');
2782
2783 $media_element_counter++;
2784
2785 $img_field = $field_name.'_'.$media_element_counter;
2786
2787 wp_enqueue_script( 'wpmediamultiple' );
2788 wp_enqueue_script( 'jquery-ui-mouse' );
2789 wp_enqueue_media();
2790
2791 ?>
2792 <div id="<?php echo esc_attr($field_name); ?>meta-box-id" class="postbox-upload-multiple">
2793 <?php
2794 // Get WordPress' media upload URL
2795 $upload_link = '#';
2796
2797
2798 // Get the image src
2799
2800 $your_img_src = array();
2801
2802 foreach(explode(',', $image_ids) as $image_id)
2803 {
2804 if(is_numeric($image_id)){
2805 $src = wp_get_attachment_url( $image_id, 'full' );
2806 if(!in_array(wdk_file_extension($src),array('jpg','jpeg','bmp','png','webp'))) {
2807 if(file_exists(WPDIRECTORYKIT_PATH.'/public/img/filetype/'.wdk_file_extension($src).'.png')) {
2808 $src = WPDIRECTORYKIT_URL.'public/img/filetype/'.wdk_file_extension($src).'.png';
2809 } else {
2810 $src = WPDIRECTORYKIT_URL.'public/img/filetype/_blank.png';
2811 }
2812 }
2813 $your_img_src[$image_id] = $src;
2814 }
2815 }
2816
2817 // For convenience, see if the array is valid
2818 $you_have_img = count($your_img_src) > 0;
2819 ?>
2820
2821 <!-- Your image container, which can be manipulated with js -->
2822 <div class="custom-img-container winter_mvc-media">
2823 <?php if($you_have_img)foreach($your_img_src as $image_id => $img_src) : ?>
2824 <div class="winter_mvc-media-card" data-media-id="<?php echo esc_attr($image_id);?>">
2825 <img src="<?php echo esc_html($img_src); ?>" style="object-fit: contain;" alt="<?php echo esc_attr__('thumb', 'wmvc_win');?>" style="max-width:100%;" class="thumbnail"/>
2826 <a href="#" class="remove"></a>
2827 </div>
2828 <?php endforeach; ?>
2829 </div>
2830 <br style="clear:both;" />
2831
2832 <?php //if(sw_user_in_role('administrator')): ?>
2833 <!-- Your add & remove image links -->
2834 <p class="hide-if-no-js">
2835 <a class="button button-primary upload-custom-img <?php if ( $you_have_img ) { echo ''; } ?>"
2836 href="<?php echo esc_url($upload_link) ?>">
2837 <?php echo esc_html($texts['file_select']) ?>
2838 </a>
2839 <a class="button button-secondary delete-custom-img <?php if ( ! $you_have_img ) { echo 'hidden'; } ?>"
2840 href="#">
2841 <?php echo esc_html($texts['file_remove']) ?>
2842 </a>
2843 </p>
2844 <?php //endif; ?>
2845
2846 <!-- A hidden input to set and post the chosen image id -->
2847 <input class="logo_image_id" type="hidden" id="<?php echo esc_html(esc_html($field_name)); ?>" name="<?php echo esc_html($field_name); ?>" value="<?php echo esc_html($image_ids); ?>" />
2848 </div>
2849 <?php
2850 $custom_js ='';
2851 $custom_js .=" jQuery(function($) {
2852 if( typeof jQuery.fn.wpMediaMultiple == 'function')
2853 $('#".esc_js($field_name)."meta-box-id.postbox-upload-multiple').wpMediaMultiple({
2854 frame: {
2855 title: '".esc_js(__('Upload and select your images here for use with your listing','wpdirectorykit'))."',
2856 button: '".esc_js(__('Use this media','wpdirectorykit'))."',
2857 },
2858 library: {
2859 type: ['application', 'image', 'video']
2860 },
2861 });
2862 /* order */
2863 var re_order = function(media_element){
2864 var list_media = '';
2865 media_element.find('.winter_mvc-media-card').each(function(){
2866 if(list_media !='')
2867 list_media +=',';
2868
2869 list_media += $(this).attr('data-media-id');
2870 })
2871 media_element.closest('.postbox-upload-multiple').find('.logo_image_id').val(list_media);
2872 }
2873 /* Sort table */
2874 $( '.winter_mvc-media' ).sortable({
2875 update: function(event, ui) {
2876 re_order($(this));
2877 }
2878 });
2879 /* remove media */
2880 $( '.winter_mvc-media' ).find('.winter_mvc-media-card .remove').on('click', function(e){
2881 e.preventDefault();
2882 var media = $(this).closest('.winter_mvc-media')
2883 $(this).closest('.winter_mvc-media-card').remove();
2884 re_order(media)
2885 })
2886 });
2887 ";
2888
2889 echo "<script>".$custom_js."</script>";
2890
2891 ?>
2892
2893 <?php
2894 }
2895
2896
2897 if(!function_exists('wdk_access_check')) {
2898 /**
2899 * Generate listing card html
2900 *
2901 * @param array $listing The listing data.
2902 * @param array $settings The settings.
2903 * @param bool $json_output Encode for json, default false
2904 * @param string $html Html for sprintf(), where
2905 * %1$s - content
2906 * @return string
2907 */
2908 function wdk_access_check($model_name, $item_id, $user_id=NULL, $method='edit') {
2909
2910 if(!empty($item_id) && !is_numeric($item_id))
2911 exit('Issue with ID');
2912
2913 if (in_array($model_name, array('reviews_m','reviews_type_m','reviews_option_m','reviews_data_m'))) {
2914 global $Winter_MVC_wdk_reviews;
2915 $WMVC = $Winter_MVC_wdk_reviews;
2916 }elseif(in_array($model_name,array('package_m','payment_m'))) {
2917 global $Winter_MVC_wdk_payments;
2918 $WMVC = $Winter_MVC_wdk_payments;
2919 }elseif(in_array($model_name,array('favorite_m','favoritecategory_m'))) {
2920 global $Winter_MVC_wdk_favorites;
2921 $WMVC = $Winter_MVC_wdk_favorites;
2922 }elseif(in_array($model_name,array('currency_m'))) {
2923 global $Winter_MVC_wdk_currency;
2924 $WMVC = $Winter_MVC_wdk_currency;
2925 }elseif(in_array($model_name,array('calendar_m','price_m','reservation_m'))) {
2926 global $Winter_MVC_wdk_bookings;
2927 $WMVC = $Winter_MVC_wdk_bookings;
2928 }elseif(in_array($model_name,array('save_search_m'))) {
2929 global $Winter_MVC_wdk_save_search;
2930 $WMVC = $Winter_MVC_wdk_save_search;
2931 }elseif(in_array($model_name,array('messageschat_m'))) {
2932 global $Winter_MVC_wdk_messages_chat;
2933 $WMVC = $Winter_MVC_wdk_messages_chat;
2934 } else {
2935 $WMVC = &wdk_get_instance();
2936 }
2937
2938 if(empty($user_id))
2939 $user_id = get_current_user_id();
2940
2941 if(wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) {
2942 return true;
2943 }
2944
2945 if(substr($model_name,-2,2) == '_m')
2946 {
2947 // its model
2948 $WMVC->model($model_name);
2949
2950 if(empty($item_id) || $WMVC->$model_name->is_related($item_id, $user_id, $method))
2951 {
2952 // User is related
2953 return true;
2954 }
2955 else
2956 {
2957 //echo $CI->db->last_query();
2958 exit('Access denied ROLES RELATED');
2959 }
2960 }
2961 else
2962 {
2963 return true;
2964 }
2965
2966 exit('Access denied ROLES');
2967
2968 }
2969 }
2970
2971 if ( ! function_exists('wdk_recaptcha_field_v3'))
2972 {
2973 function wdk_recaptcha_field_v3($wdk_recaptcha_site_key=null, $wdk_recaptcha_secret_key=null, $load_script=true)
2974 {
2975 static $counter = 0;
2976
2977 if(empty($wdk_recaptcha_site_key) && empty($wdk_recaptcha_site_key)) {
2978 $wdk_recaptcha_site_key = get_option('wdk_recaptcha_site_key_v3');
2979 $wdk_recaptcha_secret_key = get_option('wdk_recaptcha_secret_key_v3');
2980 }
2981
2982 if($wdk_recaptcha_site_key && $wdk_recaptcha_secret_key)
2983 {
2984 if($load_script && $counter===0)
2985 {
2986 echo "<script src='https://www.google.com/recaptcha/api.js?render=".esc_attr(trim($wdk_recaptcha_site_key))."'></script>";
2987 }
2988 $counter++;
2989 ?>
2990 <input type="hidden" name="g-recaptcha-response" id="recaptcha_called_v3_count_<?php echo esc_html($counter);?>">
2991 <script>
2992 (function(){
2993 const field_token = document.getElementById('recaptcha_called_v3_count_<?php echo esc_html($counter);?>');
2994 grecaptcha.ready(function() {
2995 grecaptcha.execute('<?php echo esc_attr(trim($wdk_recaptcha_site_key));?>', {action: 'submit'}).then(function(token) {
2996 field_token.value = token;
2997 });
2998 });
2999
3000 // Reload token after form submit
3001 field_token.closest('form').addEventListener('submit', function(e) {
3002 e.preventDefault();
3003 grecaptcha.execute('<?php echo esc_attr(trim($wdk_recaptcha_site_key));?>', {action: 'submit'}).then(function(token) {
3004 field_token.value = token;
3005 });
3006 });
3007 })();
3008 </script>
3009 <?php
3010 }
3011 }
3012 }
3013
3014
3015 if ( ! function_exists('wdk_recaptcha_field'))
3016 {
3017 function wdk_recaptcha_field($is_compact=false, $style="", $load_script=true)
3018 {
3019 static $counter = 0;
3020 static $recaptcha_array = array();
3021
3022 if(get_option('wdk_recaptcha_site_key') !== FALSE && get_option('wdk_recaptcha_secret_key') !== NULL)
3023 {
3024 if($load_script && $counter===0)
3025 {
3026 echo "<script src='https://www.google.com/recaptcha/api.js?onload=CaptchaCallback&amp;render=explicit'></script>";
3027 }
3028 $counter++;
3029
3030 $compact_tag='';
3031 $size_tag='';
3032 if($is_compact)
3033 {
3034 $compact_tag='data-size="compact"';
3035 $size_tag='compact';
3036 }
3037
3038 $recaptcha_array[$counter] = array('size'=>$size_tag);
3039
3040 echo '<div id="recaptcha_called_'.$counter.'" class="g-recaptcha" style="'.$style.'" '.$compact_tag.' data-sitekey="'.esc_attr(get_option('wdk_recaptcha_site_key')).'"></div>';
3041 ?>
3042
3043 <script>
3044 <?php if($counter===1)echo 'var ';?>CaptchaCallback = function(){
3045 <?php for($j=1;$j<=$counter;$j++): ?>
3046 grecaptcha.render(document.getElementById('recaptcha_called_<?php echo $j;?>'), {'size' : '<?php echo esc_attr($recaptcha_array[$j]['size']); ?>', 'sitekey' : '<?php echo esc_attr(get_option('wdk_recaptcha_site_key')); ?>'});
3047 <?php endfor; ?>
3048 };
3049 </script>
3050
3051 <?php
3052 }
3053 }
3054 }
3055
3056 function is_wdk_valid_recaptcha()
3057 {
3058 if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){
3059 //your site secret key
3060 if(wdk_valid_recaptcha_curl($_POST['g-recaptcha-response']))
3061 {
3062 return TRUE;
3063 }
3064 }
3065 return FALSE;
3066 }
3067
3068 function wdk_valid_recaptcha_curl($g_recaptcha_response='') {
3069 $url = 'https://www.google.com/recaptcha/api/siteverify';
3070 $args = array(
3071 'timeout' => 200,
3072 'blocking' => true,
3073 'headers' => array(),
3074 'body' => array(
3075 'secret' => get_option('wdk_recaptcha_secret_key'),
3076 'response' => $g_recaptcha_response,
3077 'remoteip' => sanitize_textarea_field($_SERVER['REMOTE_ADDR'])
3078 ),
3079 'cookies' => array()
3080 );
3081 $response = wp_remote_post( $url, $args );
3082
3083 if ( is_wp_error( $response ) ) {
3084 /*$error_message = $response->get_error_message();*/
3085 return true;
3086 } else {
3087 $response = json_decode($response['body']);
3088 return $response->success;
3089 }
3090 }
3091
3092 if(!function_exists('wdk_get_option')) {
3093 /**
3094 * Cached and get wp options
3095 *
3096 * @param string option Option key
3097 * @return string alt or title
3098 */
3099
3100 function wdk_get_option($option_key = '') {
3101 return get_option($option_key);
3102 if(isset($options[$option_key])) {
3103 return $options[$option_key];
3104 }
3105
3106 $options[$option_key] = get_option($option_key);
3107
3108 return $options[$option_key];
3109 }
3110 }
3111
3112 if(!function_exists('wdk_server_current_url')) {
3113 /**
3114 * Get current url basic on $_SERVER, exists function wdk_current_url(), on some urls have issue on listing preview page
3115 *
3116 * @return string url
3117 */
3118
3119 function wdk_server_current_url()
3120 {
3121 return (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
3122 }
3123 }
3124
3125
3126 if(!function_exists('wdk_filter_date_decimal')) {
3127 /**
3128 * Filter 00:00:00 from date
3129 *
3130 * @param string
3131 * @return string date without 00:00:00
3132 */
3133
3134 function wdk_filter_date_decimal($data)
3135 {
3136 return str_replace(' 00:00:00','', $data);
3137 }
3138 }
3139
3140 function wdk_get_post()
3141 {
3142 $post = array();
3143
3144 foreach($_POST as $key => $val)
3145 {
3146 if(is_array($val))
3147 {
3148 return wdk_clean($_POST);
3149 }
3150 elseif(is_string($val))
3151 {
3152 if(strpos($val, '<iframe') === 0)
3153 $val = str_replace("'",'"', $val);
3154
3155 $post[sanitize_text_field($key)] = wp_kses_post($val);
3156 }
3157 }
3158
3159 return $post;
3160 }
3161
3162
3163 function wdk_get_get()
3164 {
3165 $log_array = array();
3166
3167 foreach($_GET as $key => $val)
3168 {
3169 if(is_array($val))
3170 {
3171 return wdk_clean($_POST);
3172 }
3173 else
3174 {
3175 $log_array[sanitize_text_field($key)] = wp_kses_post($val);
3176 }
3177 }
3178
3179 return $log_array;
3180 }
3181
3182 function wdk_clean($array)
3183 {
3184 $arr_cleaned = array();
3185 foreach($array as $key=>$val)
3186 {
3187 if(is_array($val))
3188 {
3189 $arr_cleaned[sanitize_text_field($key)] = wdk_clean($val);
3190 }
3191 elseif(is_string($val))
3192 {
3193 $arr_cleaned[sanitize_text_field($key)] = wp_kses_post($val);
3194 }
3195
3196 }
3197
3198 //dump($arr_cleaned);
3199
3200 return $arr_cleaned;
3201 }
3202
3203 function wdk_clean_mixed($item)
3204 {
3205 $arr_cleaned = array();
3206
3207 if(is_array($item))
3208 {
3209 foreach($item as $key=>$val)
3210 {
3211 if(is_array($val))
3212 {
3213 $arr_cleaned[sanitize_text_field($key)] = wdk_clean_mixed($val);
3214 }
3215 else
3216 {
3217 $arr_cleaned[sanitize_text_field($key)] = wp_kses_post($val);
3218 }
3219 }
3220 }
3221 else
3222 {
3223 return wp_kses_post($item);
3224 }
3225
3226 return $arr_cleaned;
3227 }
3228
3229 /*
3230 <select class="form-control" name="<?php echo 'control_operator_'.$i_fieldnum; ?>">
3231 <option value="CONTAINS">CONTAINS</option>
3232 <option value="NOT_CONTAINS">NOT_CONTAINS</option>
3233 </select>
3234 */
3235 function wdk_select_multi_option($field_name, $options = array(), $selected = NULL, $extra=NULL, $empty_text = NULL, $empty_val = '')
3236 {
3237 $output = '<select name="'.$field_name.'" '.$extra.' multiple="multiple">';
3238
3239 if(!is_null($empty_text))
3240 $output.= '<option value="'.esc_attr($empty_val).'">'.esc_html($empty_text).'</option>';
3241
3242 if(is_array($options) && count($options) > 0)
3243 foreach($options as $key=>$val)
3244 {
3245 $output.= '<option value="'.$key.'" '.($selected==$key&&$selected != ''?'selected':'').'>'.$val.'</option>';
3246 }
3247
3248 $output.= '</select>';
3249
3250 return $output;
3251 }
3252
3253
3254 if ( ! function_exists('wdk_treefield_select_ajax'))
3255 {
3256 /**
3257 * Return select2 ajax
3258 *
3259 * @param string option Option key
3260 * @return string alt or title
3261 */
3262 function wdk_treefield_select_ajax($name = '', $table=NULL, $selected = NULL,
3263 $column_print = 'category_title', $column_key = 'idcategory', $language_id=NULL, $empty_value='', $filter_ids = '', $attr = '')
3264 {
3265 $WMVC = &wdk_get_instance();
3266 $WMVC->model($table);
3267
3268 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
3269
3270 static $counter = 0;
3271 $form = '<select data-ajax="'.admin_url('admin-ajax.php').'" name="'.$name.'" data-table="'.$table.'" '.$attr.' data-placeholder="'.$empty_value.'" class="form-control select_ajax" id="wdk_select2_'.$counter.'" multiple="">';
3272
3273
3274 if(false)
3275 if( $column_key == 'idcategory') {
3276 $form .= '<option selected="selected" value="">'.esc_html__('Select Category', 'wpdirectorykit').'</option>';
3277 } else {
3278 $form .= '<option selected="selected" value="">'.esc_html__('Select Location', 'wpdirectorykit').'</option>';
3279 }
3280
3281 if($selected) {
3282 if(is_array($selected)) {
3283
3284 $ids = array();
3285 foreach($selected as $selected_item) {
3286 if(!empty($selected_item)) {
3287 $ids [] = $selected_item;
3288 }
3289 }
3290
3291 /* where in */
3292 if(!empty($ids)){
3293 $WMVC->db->select($WMVC->$table->_table_name.'.*');
3294 $WMVC->db->where($WMVC->$table->_table_name.'.'.$column_key.' IN(' . implode(',', $ids) . ')', null, false);
3295 $WMVC->db->order_by('FIELD('.$WMVC->$table->_table_name.'.'.$column_key.', '. implode(',', $ids) . ')');
3296
3297 $results = $WMVC->$table->get();
3298 foreach ($results as $item) {
3299 if($item)
3300 $form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data($column_key, $item, false, TRUE, TRUE)).'">'.esc_html__(wmvc_show_data($column_print, $item, false, TRUE, TRUE),'wpdirectorykit').'</option>';
3301 }
3302 }
3303 } elseif(is_intval($selected)) {
3304 $db_item = $WMVC->$table->get($selected, TRUE);
3305 if($db_item)
3306 $form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data($column_key, $db_item, false, TRUE, TRUE)).'">'.esc_html__(wmvc_show_data($column_print, $db_item, false, TRUE, TRUE),'wpdirectorykit').'</option>';
3307 }
3308 } else {
3309 //$form .= '<option value="" selected="selected">'.esc_html__('Not selected', 'wpdirectorykit').'</option>';
3310 }
3311 $form .= '</select>';
3312
3313 //load javascript library
3314 if($counter==0)
3315 {
3316 wp_enqueue_script('select2-select2');
3317 wp_enqueue_script('wdk-select2');
3318 wp_enqueue_style('select2-select2');
3319 }
3320 ?>
3321 <?php
3322 $counter++;
3323 return $form;
3324 }
3325 }
3326
3327 if ( ! function_exists('wdk_user_select_ajax'))
3328 {
3329 /**
3330 * Return select2 ajax
3331 *
3332 * @param string option Option key
3333 * @return string alt or title
3334 */
3335 function wdk_user_select_ajax($name = '', $selected = NULL, $empty_value='', $filter_ids = '')
3336 {
3337 $WMVC = &wdk_get_instance();
3338
3339 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
3340
3341 static $counter = 0;
3342 $form = '<select data-ajax="'.admin_url('admin-ajax.php').'" name="'.$name.'" data-placeholder="'.$empty_value.'" class="form-control select_ajax_user" id="wdk_select2_user_'.$counter.'" multiple="">';
3343 if($selected) {
3344 if(is_array($selected)) {
3345 /* where in */
3346 foreach ($selected as $item) {
3347 $user_data = get_userdata($item);
3348 if($user_data)
3349 $form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data('ID', $user_data, false, TRUE, TRUE)).'">'.esc_html(wmvc_show_data('display_name', $user_data, false, TRUE, TRUE)).'</option>';
3350 }
3351 } elseif(is_intval($selected)) {
3352 $user_data = get_userdata($selected);
3353 if($user_data)
3354 $form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data('ID', $user_data, false, TRUE, TRUE)).'">'.esc_html(wmvc_show_data('display_name', $user_data, false, TRUE, TRUE)).'</option>';
3355 }
3356 } else {
3357 //$form .= '<option value="" selected="selected">'.esc_html__('Not selected', 'wpdirectorykit').'</option>';
3358 }
3359 $form .= '</select>';
3360
3361 //load javascript library
3362 if($counter==0)
3363 {
3364 wp_enqueue_script('select2-select2');
3365 wp_enqueue_script('wdk-select2');
3366 wp_enqueue_style('select2-select2');
3367 }
3368 ?>
3369 <?php
3370 $counter++;
3371 return $form;
3372 }
3373 }
3374
3375
3376 /*
3377 <select class="form-control" name="<?php echo 'control_operator_'.$i_fieldnum; ?>">
3378 <option value="CONTAINS">CONTAINS</option>
3379 <option value="NOT_CONTAINS">NOT_CONTAINS</option>
3380 </select>
3381 */
3382 function wdk_select_option_multiple($field_name, $options = array(), $selected = array(), $extra=NULL, $empty_text = NULL, $empty_val = '')
3383 {
3384 $output = '<select name="'.$field_name.'" '.$extra.' multiple >';
3385
3386 if(!is_null($empty_text))
3387 $output.= '<option value="'.esc_attr($empty_val).'">'.esc_html($empty_text).'</option>';
3388
3389 if(is_array($options) && count($options) > 0)
3390 foreach($options as $key=>$val)
3391 {
3392 if(is_string($selected)) {
3393 $output.= '<option value="'.$key.'" '.(($selected == $key)?'selected="selected"':'').'>'.$val.'</option>';
3394 } else if(is_array($selected)){
3395 $output.= '<option value="'.$key.'" '.((in_array($key, $selected) === TRUE)?'selected="selected"':'').'>'.$val.'</option>';
3396 }
3397 }
3398
3399 $output.= '</select>';
3400
3401 return $output;
3402 }
3403
3404
3405
3406 if ( ! function_exists('wdk_convert_date_format_js'))
3407 {
3408 /**
3409 * Convert date format for support in js
3410 * From: https://wordpress.org/support/article/formatting-date-and-time/
3411 * To: https://momentjscom.readthedocs.io/en/latest/moment/04-displaying/01-format/
3412 *
3413 * @param string php date format Option key
3414 * @return string js date format
3415 */
3416 function wdk_convert_date_format_js($date_format)
3417 {
3418 $replaced = array(
3419 'D'=>'ddd',
3420 'j'=>'D',
3421 'd'=>'DD',
3422 'l'=>'dddd',
3423 'F'=>'MMMM',
3424 'Y'=>'YYYY',
3425 'S'=>'Do',
3426 'm'=>'MM',
3427 'n'=>'MM',
3428 'F'=>'MMMM',
3429 'M'=>'MMM',
3430 'Y'=>'YYYY',
3431 'y'=>'YY',
3432 'a'=>'a',
3433 'A'=>'A',
3434 'h'=>'hh',
3435 'G'=>'H',
3436 'H'=>'HH',
3437 'g'=>'h',
3438 'i'=>'mm',
3439 's'=>'ss',
3440 'T'=>'zz',
3441 'c'=>'',
3442 'r'=>'llll',
3443 'u'=>'x',
3444 );
3445
3446
3447 $result = '';
3448 $escaped = false;
3449 $length = strlen($date_format);
3450
3451 for ($i = 0; $i < $length; $i++) {
3452 $char = $date_format[$i];
3453
3454 if ($char === '\\') {
3455 $escaped = true;
3456 continue;
3457 }
3458
3459 if ($escaped) {
3460 $result .= "'".$char."'";
3461 $escaped = false;
3462 } else {
3463 $result .= isset($replaced[$char]) ? $replaced[$char] : $char;
3464 }
3465 }
3466
3467 return str_replace("''", '',$result);
3468 }
3469 }
3470
3471 if ( ! function_exists('wdk_convert_date_format_jquery'))
3472 {
3473 /**
3474 * Convert date format for support in js
3475 * From: https://wordpress.org/support/article/formatting-date-and-time/
3476 * To: https://api.jqueryui.com/datepicker/
3477 *
3478 * @param string php date format Option key
3479 * @return string js date format
3480 */
3481 function wdk_convert_date_format_jquery($date_format)
3482 {
3483 $replaced = array(
3484 'D'=>'D',
3485 'd'=>'dd',
3486 'j'=>'d',
3487 'l'=>'DD',
3488 'Y'=>'yy',
3489 'S'=>'d',
3490 'm'=>'mm',
3491 'n'=>'m',
3492 'M'=>'m',
3493 'F'=>'MM',
3494 'y'=>'y',
3495 'a'=>'',
3496 'A'=>'',
3497 'h'=>'',
3498 'G'=>'',
3499 'H'=>'',
3500 'g'=>'',
3501 'i'=>'',
3502 's'=>'',
3503 'T'=>'',
3504 'c'=>'ISO_8601',
3505 'r'=>'RFC_2822',
3506 'u'=>'@',
3507 ':'=>'',
3508 );
3509
3510 $result = '';
3511 $escaped = false;
3512 $length = strlen($date_format);
3513
3514 for ($i = 0; $i < $length; $i++) {
3515 $char = $date_format[$i];
3516
3517 if ($char === '\\') {
3518 $escaped = true;
3519 continue;
3520 }
3521
3522 if ($escaped) {
3523 $result .= "'".$char."'";
3524 $escaped = false;
3525 } else {
3526 $result .= isset($replaced[$char]) ? $replaced[$char] : $char;
3527 }
3528 }
3529
3530 return str_replace("''", '',$result);
3531 }
3532 }
3533
3534 if ( ! function_exists('wdk_convert_date_format_jquery'))
3535 {
3536 /**
3537 * Convert date format for support in js
3538 * From: https://wordpress.org/support/article/formatting-date-and-time/
3539 * To: https://api.jqueryui.com/datepicker/
3540 *
3541 * @param string php date format Option key
3542 * @return string js date format
3543 */
3544 function wdk_convert_date_format_jquery($date_format)
3545 {
3546 $replaced = array(
3547 'D'=>'D',
3548 'd'=>'dd',
3549 'j'=>'d',
3550 'l'=>'DD',
3551 'Y'=>'yy',
3552 'S'=>'d',
3553 'm'=>'mm',
3554 'n'=>'m',
3555 'M'=>'m',
3556 'F'=>'MM',
3557 'y'=>'y',
3558 'a'=>'',
3559 'A'=>'',
3560 'h'=>'',
3561 'G'=>'',
3562 'H'=>'',
3563 'g'=>'',
3564 'i'=>'',
3565 's'=>'',
3566 'T'=>'',
3567 'c'=>'ISO_8601',
3568 'r'=>'RFC_2822',
3569 'u'=>'@',
3570 ':'=>'',
3571 );
3572
3573
3574 $result = '';
3575 $escaped = false;
3576 $length = strlen($date_format);
3577
3578 for ($i = 0; $i < $length; $i++) {
3579 $char = $date_format[$i];
3580
3581 if ($char === '\\') {
3582 $escaped = true;
3583 continue;
3584 }
3585
3586 if ($escaped) {
3587 $result .= "'".$char."'";
3588 $escaped = false;
3589 } else {
3590 $result .= isset($replaced[$char]) ? $replaced[$char] : $char;
3591 }
3592 }
3593
3594 return str_replace("''", '',$result);
3595
3596 }
3597 }
3598
3599 if ( ! function_exists('wdk_get_gps'))
3600 {
3601
3602 /**
3603 * Get Latitude/Longitude/Altitude based on an address
3604 * @param string $address The address for converting into coordinates
3605 * @return array An array containing Latitude/Longitude/Altitude data
3606 */
3607 function wdk_get_gps($address = '')
3608 {
3609
3610 $address_key = 'cached_address_gps';
3611
3612 static $results = array();
3613
3614 if(empty($results)) {
3615 $gps_option = wdk_get_option($address_key, $results);
3616 if($gps_option)
3617 $results = $gps_option;
3618 }
3619
3620 $address = str_replace(' ','+',$address);
3621
3622 if(!isset($results[$address])) {
3623 $results[$address] = NULL;
3624 $url = 'https://nominatim.openstreetmap.org/search?format=json&q=' . $address;
3625
3626 // Add required User-Agent header
3627 $args = [
3628 'timeout' => 10,
3629 'headers' => [
3630 'User-Agent' => get_bloginfo('name') . '/1.0 (' . get_bloginfo('admin_email') . ')',
3631 ],
3632 ];
3633 $request = wp_remote_get( $url, $args);
3634 $response = '';
3635
3636 // request failed
3637 if ( is_wp_error( $request ) ) {
3638 $response = $request;
3639 }
3640 $code = (int) wp_remote_retrieve_response_code( $request );
3641 // make sure the fetch was successful
3642 if (empty($response) && $code == 200 ) {
3643 $response = wp_remote_retrieve_body( $request );
3644 // Decode the json
3645 $resp = json_decode( $response, true );
3646
3647 if(!empty($resp) && isset($resp[0]) && isset($resp[0]['lat']) && isset($resp[0]['lon'])) {
3648 $results[$address] = array('lat' => $resp[0]['lat'], 'lng' => $resp[0]['lon'], 'alt' => 0);
3649
3650 return $results[$address];
3651 }
3652 }
3653 } else {
3654 return $results[$address];
3655 }
3656 return false;
3657 }
3658 }
3659
3660 if ( ! function_exists('wdk_get_gps_google'))
3661 {
3662
3663 /**
3664 * Get Latitude/Longitude/Altitude based on an address from Google Api
3665 * @param string $address The address for converting into coordinates
3666 * @param string $api_key Custom google API Key
3667 *
3668 * @return array An array containing Latitude/Longitude/Altitude data
3669 */
3670 function wdk_get_gps_google($address = '', $api_key = NULL)
3671 {
3672 static $results = array();
3673
3674 if ( empty( $api_key ) ) {
3675 $api_key = wdk_get_option('wdk_geo_google_api_key');
3676 }
3677
3678 $address = str_replace(' ','+',$address);
3679
3680 if(!isset($results[$address])) {
3681 $results[$address] = NULL;
3682 $url = 'https://maps.googleapis.com/maps/api/geocode/json?address='.trim($address).'&key='.$api_key;
3683 $request = wp_remote_get( $url );
3684 $response = '';
3685
3686 // request failed
3687 if ( is_wp_error( $request ) ) {
3688 $response = $request;
3689 }
3690 $code = (int) wp_remote_retrieve_response_code( $request );
3691
3692 // make sure the fetch was successful
3693 if (empty($response) && $code == 200 ) {
3694 $response = wp_remote_retrieve_body( $request );
3695 // Decode the json
3696 $resp = json_decode( $response, true );
3697 $status = $resp['status'];
3698
3699 //if request status is successful
3700 if($status == "OK"){
3701 //get address from json data
3702 $lat = $resp['results'][0]['geometry']['location']['lat'];
3703 $lng = $resp['results'][0]['geometry']['location']['lng'];
3704
3705 $results[$address] = array('lat' => $lat , 'lng' => $lng, 'alt' => 0);
3706 return $results[$address];
3707 }
3708 }
3709 } else {
3710 return $results[$address];
3711 }
3712
3713 return false;
3714 }
3715 }
3716
3717
3718 if ( ! function_exists('wdk_getDueCoords'))
3719 {
3720 // Modified from:
3721 // http://www.sitepoint.com/forums/showthread.php?656315-adding-distance-gps-coordinates-get-bounding-box
3722 /**
3723 * bearing is 0 = north, 180 = south, 90 = east, 270 = west
3724 *
3725 */
3726 function wdk_getDueCoords($latitude, $longitude, $bearing, $distance, $distance_unit = "km", $return_as_array = FALSE) {
3727
3728 if ($distance_unit == "m") {
3729 // Distance is in miles.
3730 $radius = 3963.1676;
3731 }
3732 else {
3733 // distance is in km.
3734 $radius = 6378.1;
3735 }
3736
3737 // New latitude in degrees.
3738 $new_latitude = rad2deg(asin(sin(deg2rad($latitude)) * cos($distance / $radius) + cos(deg2rad($latitude)) * sin($distance / $radius) * cos(deg2rad($bearing))));
3739
3740 // New longitude in degrees.
3741 $new_longitude = rad2deg(deg2rad($longitude) + atan2(sin(deg2rad($bearing)) * sin($distance / $radius) * cos(deg2rad($latitude)), cos($distance / $radius) - sin(deg2rad($latitude)) * sin(deg2rad($new_latitude))));
3742
3743 if ($return_as_array) {
3744 // Assign new latitude and longitude to an array to be returned to the caller.
3745 $coord = array();
3746 $coord['lat'] = $new_latitude;
3747 $coord['lng'] = $new_longitude;
3748 }
3749 else {
3750 $coord = $new_latitude . ", " . $new_longitude;
3751 }
3752
3753 return $coord;
3754
3755 }
3756 }
3757
3758 if ( ! function_exists('wdk_is_gps'))
3759 {
3760 // Validation gps
3761 /**
3762 * @param string $string_gps gps in string like xx.xxxx,xx.xxxxx
3763 * @return bool
3764 */
3765 function wdk_is_gps($string_gps = '') {
3766 if(preg_match('/^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$/', $string_gps)) {
3767 return true;
3768 }
3769
3770 return false;
3771 }
3772 }
3773
3774
3775 if ( ! function_exists('wdk_is_phone'))
3776 {
3777 // Validation phone
3778 /**
3779 * @param string $value phone in string
3780 * @return bool
3781 */
3782 function wdk_is_phone($value = '') {
3783 if(preg_match("/^[.+]{0,1}[0-9-)(]{0,25}$/", $value)) {
3784 return true;
3785 }
3786
3787 return false;
3788 }
3789 }
3790
3791 if ( ! function_exists('is_wdk_whatsapp'))
3792 {
3793 // Validation phone
3794 /**
3795 * @param string $value phone in string
3796 * @return bool
3797 */
3798 function is_wdk_whatsapp($value = '') {
3799 return true;
3800 }
3801 }
3802
3803 if ( ! function_exists('is_wdk_viber'))
3804 {
3805 // Validation phone
3806 /**
3807 * @param string $value phone in string
3808 * @return bool
3809 */
3810 function is_wdk_viber($value = '') {
3811 return true;
3812 }
3813 }
3814
3815 if ( ! function_exists('wdk_filter_phone'))
3816 {
3817 // Validation phone
3818 /**
3819 * @param string $value phone in string
3820 * @return bool
3821 */
3822 function wdk_filter_phone($value = '') {
3823 return str_replace(array(' ','-','(',')'),'',$value);
3824 }
3825 }
3826
3827
3828 if ( ! function_exists('wdk_generate_media_field'))
3829 {
3830 // Based on value return video embed, youtube, source video tag
3831 /**
3832 * @param string $value value
3833 * @param string $class help css class
3834 * @return string html or NULL
3835 */
3836 function wdk_generate_media_field($value = '', $class="wdk-image") {
3837 $output = NULL;
3838
3839 if(strpos($value, 'vimeo.com') !== FALSE)
3840 {
3841 $output = wp_oembed_get($value, array("width"=>"800", "height"=>"450"));
3842 $output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output);
3843 }
3844 elseif(strpos($value, 'watch?v=') !== FALSE)
3845 {
3846 $embed_code = substr($value, strpos($value, 'watch?v=')+8);
3847 $output = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455"));
3848 $output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output );
3849 }
3850 elseif(strpos($value, 'youtu.be/') !== FALSE)
3851 {
3852 $embed_code = substr($value, strpos($value, 'youtu.be/')+9);
3853 $output = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455"));
3854 $output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output );
3855 }
3856 elseif(strpos($value, 'youtube.com/embed/') !== FALSE)
3857 {
3858 $embed_code = substr($value, strpos($value, 'youtube.com/embed/')+18);
3859 $output = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455"));
3860 $output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output );
3861 }
3862 elseif(filter_var($value, FILTER_VALIDATE_URL) !== FALSE && preg_match('/\.(mp4|flv|wmw|ogv|webm|ogg)$/i', $value))
3863 {
3864 $output = '<video src="'.$value.'" controls class="'.$class.'"></video> ';
3865 }
3866
3867 return $output;
3868 }
3869 }
3870
3871
3872 if ( ! function_exists('wdk_depend_get_hidden_fields'))
3873 {
3874 // Based on value return video embed, youtube, source video tag
3875 /**
3876 * @param int $tree_id tree_id of category
3877 * @param string $type type, default 'categories'
3878 * @return string string with hidden fields like ,1,2,3,4, or NULL
3879 */
3880 function wdk_depend_get_hidden_fields($tree_id = NULL, $type="categories") {
3881 static $output = array();
3882
3883 if(isset($output[$tree_id])) {
3884 return $output[$tree_id];
3885 }
3886 if(empty($tree_id)) {
3887 return NULL;
3888 } else {
3889 $output[$tree_id] = false;
3890
3891 global $Winter_MVC_WDK;
3892 $Winter_MVC_WDK->model('dependfields_m');
3893
3894 $depend_fields = $Winter_MVC_WDK->dependfields_m->get_by(array('field_id' => $tree_id,'main_field' => $type), TRUE);
3895
3896 if($depend_fields && !empty($depend_fields->hidden_fields_list)) {
3897 $output[$tree_id] = ','.$depend_fields->hidden_fields_list. ',';
3898 }
3899 return $output[$tree_id];
3900 }
3901
3902 return false;
3903 }
3904 }
3905
3906 if ( ! function_exists('wdk_depend_is_hidden_field'))
3907 {
3908 // Based on value return video embed, youtube, source video tag
3909 /**
3910 * @param int $field_id field_id
3911 * @param int $tree_id id for category
3912 * @param string $type type, default 'categories'
3913 * @return string string with hidden fields like ,1,2,3,4, or NULL
3914 */
3915 function wdk_depend_is_hidden_field($field_id = NULL, $tree_id = NULL, $type="categories") {
3916 $hidden_fields = wdk_depend_get_hidden_fields($tree_id, $type);
3917 if($hidden_fields && strpos($hidden_fields, ','.trim($field_id).',') !== FALSE) {
3918 return true;
3919 }
3920
3921 return false;
3922 }
3923 }
3924
3925
3926 if ( ! function_exists('is_wdk_slug_format'))
3927 {
3928 function is_wdk_slug_format($string)
3929 {
3930 if(empty($string))return FALSE;
3931
3932
3933 if (preg_match("/^[a-z0-9-_]+\$/", $string)) {
3934
3935 return TRUE;
3936 }
3937
3938 return FALSE;
3939 }
3940 }
3941
3942 if ( ! function_exists('wdk_number_format_i18n'))
3943 {
3944 function wdk_number_format_i18n($value)
3945 {
3946 if(empty($value))return NULL;
3947
3948
3949 $value = filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
3950 $value = (float)str_replace(array(","," ",'&nbsp;'), "", $value);
3951
3952 // Allow decimal precision to be filtered (default is 0)
3953 $decimals = apply_filters('wdk_number_format_decimals', ((wdk_get_option('wdk_number_format_decimals')) ? wdk_get_option('wdk_number_format_decimals') : 0));
3954
3955 if(!get_option('wdk_disable_custom_muber_format')) {
3956 global $wp_locale;
3957 return number_format(
3958 $value,
3959 $decimals,
3960 $wp_locale->number_format['decimal_point'],
3961 $wp_locale->number_format['thousands_sep']
3962 );
3963 }
3964
3965 return number_format_i18n($value, $decimals);
3966 }
3967 }
3968
3969 if ( ! function_exists('wdk_currency_symbol'))
3970 {
3971 /**
3972 * Return currency symbol
3973 *
3974 * @return string currency symbol
3975 */
3976 function wdk_currency_symbol()
3977 {
3978
3979 if(function_exists('get_woocommerce_currency_symbol'))
3980 return get_woocommerce_currency_symbol();
3981
3982 if(wdk_get_option('wdk_default_currency_symbol'))
3983 return wdk_get_option('wdk_default_currency_symbol');
3984
3985 return '$';
3986 }
3987 }
3988
3989 if ( ! function_exists('wdk_generate_path_image'))
3990 {
3991 /**
3992 * Generate path of images
3993 *
3994 * @param string $id or ids of images, separeted by comma
3995 * @param bool $multi multi images, separeted by comma
3996 * @param int $limit limit characters for path
3997 * @param int $limit limit images for path
3998 *
3999 * @return string with path of image or multi images
4000 */
4001 function wdk_generate_path_image($ids = NULL, $multi = FALSE, $limit = 95, $limit_images = 10)
4002 {
4003 $path = '';
4004 if(empty($ids))
4005 return $path;
4006
4007 $image_ids = explode(',', $ids);
4008 $count_images = 0;
4009 if(is_array($image_ids)) {
4010 foreach ($image_ids as $image_id) {
4011 if(is_numeric($image_id))
4012 {
4013
4014 if($count_images>=$limit_images)
4015 break;
4016
4017 $image_path = wp_get_original_image_path($image_id);
4018 if($image_path) {
4019 /* path of image */
4020 $next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path);
4021
4022 /* check length listing_images_path + next image + comma, should be less then $limit */
4023 if(strlen($path.$next_path)<$limit) {
4024
4025 if($multi) {
4026 if(!empty($path))
4027 $path .= ',';
4028 }
4029
4030 $path .= $next_path;
4031 }
4032
4033 if(!$multi)
4034 break;
4035
4036 $count_images++;
4037 }
4038 }
4039 }
4040 }
4041
4042 return $path;
4043 }
4044 }
4045
4046 if ( ! function_exists('wdk_booking_currency_symbol'))
4047 {
4048 /**
4049 * Return currency symbol
4050 *
4051 * @return string currency symbol
4052 */
4053 function wdk_booking_currency_symbol()
4054 {
4055
4056 if(function_exists('get_woocommerce_currency_symbol'))
4057 return get_woocommerce_currency_symbol();
4058
4059 if(wdk_get_option('wdk_default_currency_symbol'))
4060 return wdk_get_option('wdk_default_currency_symbol');
4061
4062 return '$';
4063 }
4064 }
4065
4066 if ( ! function_exists('wdk_generated_cached_row_userdata'))
4067 {
4068 /**
4069 * Return currency symbol
4070 *
4071 * @return string currency symbol
4072 */
4073 function wdk_generated_cached_row_userdata($row)
4074 {
4075 $user_data = array();
4076
4077 $user_data['display_name'] = wmvc_show_data('cacheduser_display_name', $row);
4078 $user_data['user_email'] = wmvc_show_data('cacheduser_email', $row);
4079 $user_data['profile_url'] = wmvc_show_data('cacheduser_profile_url', $row);
4080 $user_data['avatar_url'] = wmvc_show_data('cacheduser_avatar_url', $row);
4081
4082 /* meta */
4083 $user_data['wdk_address'] = wmvc_show_data('cacheduser_wdk_address', $row);
4084 $user_data['wdk_phone'] = wmvc_show_data('cacheduser_wdk_phone', $row);
4085 $user_data['wdk_city'] = wmvc_show_data('cacheduser_wdk_city', $row);
4086 $user_data['wdk_company_name'] = wmvc_show_data('cacheduser_wdk_company_name', $row);
4087 $user_data['wdk_facebook'] = wmvc_show_data('cacheduser_wdk_facebook', $row);
4088 $user_data['wdk_youtube'] = wmvc_show_data('cacheduser_wdk_youtube', $row);
4089 $user_data['wdk_linkedin'] = wmvc_show_data('cacheduser_wdk_linkedin', $row);
4090 $user_data['wdk_twitter'] = wmvc_show_data('cacheduser_wdk_twitter', $row);
4091 $user_data['wdk_instagram'] = wmvc_show_data('cacheduser_wdk_instagram', $row);
4092 $user_data['wdk_whatsapp'] = wmvc_show_data('cacheduser_wdk_whatsapp', $row);
4093 $user_data['wdk_viber'] = wmvc_show_data('cacheduser_wdk_viber', $row);
4094 $user_data['wdk_iban'] = wmvc_show_data('cacheduser_wdk_iban', $row);
4095 $user_data['wdk_telegram'] = wmvc_show_data('cacheduser_wdk_telegram', $row);
4096 $user_data['wdk_position_title'] = wmvc_show_data('cacheduser_wdk_position_title', $row);
4097 $user_data['agency_name'] = wmvc_show_data('cacheduser_agency_name', $row);
4098 $user_data['description'] = wmvc_show_data('cacheduser_description', $row);
4099 $user_data['user_url'] = wmvc_show_data('cacheduser_user_url', $row);
4100 $user_data['roles'] = explode(',', wmvc_show_data('cacheduser_roles', $row));
4101 $user_data['wdk_slug'] = wmvc_show_data('cacheduser_wdk_slug', $row);
4102 $user_data['user_login'] = wmvc_show_data('cacheduser_user_login', $row);
4103 $user_data['user_id'] = wmvc_show_data('cacheduser_user_id', $row);
4104
4105 if(function_exists('wdk_generate_profile_permalink') && $user_data['profile_url'] == '#') {
4106 if($user_data['user_login']) {
4107 $user_data['profile_url'] = wdk_generate_profile_permalink($user_data);
4108 } else {
4109 $user_data['profile_url'] = wdk_generate_profile_permalink(wmvc_show_data('user_id', $user_data));
4110 }
4111 }
4112
4113 return $user_data;
4114 }
4115 }
4116
4117 if ( ! function_exists('wdk_mime2extd'))
4118 {
4119 /**
4120 * Return currency symbol
4121 *
4122 * @return string currency symbol
4123 */
4124 function wdk_mime2ext($mime) {
4125 $mime_map = [
4126 'video/3gpp2' => '3g2',
4127 'video/3gp' => '3gp',
4128 'video/3gpp' => '3gp',
4129 'application/x-compressed' => '7zip',
4130 'audio/x-acc' => 'aac',
4131 'audio/ac3' => 'ac3',
4132 'application/postscript' => 'ai',
4133 'audio/x-aiff' => 'aif',
4134 'audio/aiff' => 'aif',
4135 'audio/x-au' => 'au',
4136 'video/x-msvideo' => 'avi',
4137 'video/msvideo' => 'avi',
4138 'video/avi' => 'avi',
4139 'application/x-troff-msvideo' => 'avi',
4140 'application/macbinary' => 'bin',
4141 'application/mac-binary' => 'bin',
4142 'application/x-binary' => 'bin',
4143 'application/x-macbinary' => 'bin',
4144 'image/bmp' => 'bmp',
4145 'image/x-bmp' => 'bmp',
4146 'image/x-bitmap' => 'bmp',
4147 'image/x-xbitmap' => 'bmp',
4148 'image/x-win-bitmap' => 'bmp',
4149 'image/x-windows-bmp' => 'bmp',
4150 'image/ms-bmp' => 'bmp',
4151 'image/x-ms-bmp' => 'bmp',
4152 'application/bmp' => 'bmp',
4153 'application/x-bmp' => 'bmp',
4154 'application/x-win-bitmap' => 'bmp',
4155 'application/cdr' => 'cdr',
4156 'application/coreldraw' => 'cdr',
4157 'application/x-cdr' => 'cdr',
4158 'application/x-coreldraw' => 'cdr',
4159 'image/cdr' => 'cdr',
4160 'image/x-cdr' => 'cdr',
4161 'zz-application/zz-winassoc-cdr' => 'cdr',
4162 'application/mac-compactpro' => 'cpt',
4163 'application/pkix-crl' => 'crl',
4164 'application/pkcs-crl' => 'crl',
4165 'application/x-x509-ca-cert' => 'crt',
4166 'application/pkix-cert' => 'crt',
4167 'text/css' => 'css',
4168 'text/x-comma-separated-values' => 'csv',
4169 'text/comma-separated-values' => 'csv',
4170 'application/vnd.msexcel' => 'csv',
4171 'application/x-director' => 'dcr',
4172 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
4173 'application/x-dvi' => 'dvi',
4174 'message/rfc822' => 'eml',
4175 'application/x-msdownload' => 'exe',
4176 'video/x-f4v' => 'f4v',
4177 'audio/x-flac' => 'flac',
4178 'video/x-flv' => 'flv',
4179 'image/gif' => 'gif',
4180 'application/gpg-keys' => 'gpg',
4181 'application/x-gtar' => 'gtar',
4182 'application/x-gzip' => 'gzip',
4183 'application/mac-binhex40' => 'hqx',
4184 'application/mac-binhex' => 'hqx',
4185 'application/x-binhex40' => 'hqx',
4186 'application/x-mac-binhex40' => 'hqx',
4187 'text/html' => 'html',
4188 'image/x-icon' => 'ico',
4189 'image/x-ico' => 'ico',
4190 'image/vnd.microsoft.icon' => 'ico',
4191 'text/calendar' => 'ics',
4192 'application/java-archive' => 'jar',
4193 'application/x-java-application' => 'jar',
4194 'application/x-jar' => 'jar',
4195 'image/jp2' => 'jp2',
4196 'video/mj2' => 'jp2',
4197 'image/jpx' => 'jp2',
4198 'image/jpm' => 'jp2',
4199 'image/jpeg' => 'jpeg',
4200 'image/pjpeg' => 'jpeg',
4201 'application/x-javascript' => 'js',
4202 'application/json' => 'json',
4203 'text/json' => 'json',
4204 'application/vnd.google-earth.kml+xml' => 'kml',
4205 'application/vnd.google-earth.kmz' => 'kmz',
4206 'text/x-log' => 'log',
4207 'audio/x-m4a' => 'm4a',
4208 'application/vnd.mpegurl' => 'm4u',
4209 'audio/midi' => 'mid',
4210 'application/vnd.mif' => 'mif',
4211 'video/quicktime' => 'mov',
4212 'video/x-sgi-movie' => 'movie',
4213 'audio/mpeg' => 'mp3',
4214 'audio/mpg' => 'mp3',
4215 'audio/mpeg3' => 'mp3',
4216 'audio/mp3' => 'mp3',
4217 'video/mp4' => 'mp4',
4218 'video/mpeg' => 'mpeg',
4219 'application/oda' => 'oda',
4220 'application/vnd.oasis.opendocument.text' => 'odt',
4221 'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
4222 'application/vnd.oasis.opendocument.presentation' => 'odp',
4223 'audio/ogg' => 'ogg',
4224 'video/ogg' => 'ogg',
4225 'application/ogg' => 'ogg',
4226 'application/x-pkcs10' => 'p10',
4227 'application/pkcs10' => 'p10',
4228 'application/x-pkcs12' => 'p12',
4229 'application/x-pkcs7-signature' => 'p7a',
4230 'application/pkcs7-mime' => 'p7c',
4231 'application/x-pkcs7-mime' => 'p7c',
4232 'application/x-pkcs7-certreqresp' => 'p7r',
4233 'application/pkcs7-signature' => 'p7s',
4234 'application/pdf' => 'pdf',
4235 'application/octet-stream' => 'pdf',
4236 'application/x-x509-user-cert' => 'pem',
4237 'application/x-pem-file' => 'pem',
4238 'application/pgp' => 'pgp',
4239 'application/x-httpd-php' => 'php',
4240 'application/php' => 'php',
4241 'application/x-php' => 'php',
4242 'text/php' => 'php',
4243 'text/x-php' => 'php',
4244 'application/x-httpd-php-source' => 'php',
4245 'image/png' => 'png',
4246 'image/x-png' => 'png',
4247 'application/powerpoint' => 'ppt',
4248 'application/vnd.ms-powerpoint' => 'ppt',
4249 'application/vnd.ms-office' => 'ppt',
4250 'application/msword' => 'doc',
4251 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
4252 'application/x-photoshop' => 'psd',
4253 'image/vnd.adobe.photoshop' => 'psd',
4254 'audio/x-realaudio' => 'ra',
4255 'audio/x-pn-realaudio' => 'ram',
4256 'application/x-rar' => 'rar',
4257 'application/rar' => 'rar',
4258 'application/x-rar-compressed' => 'rar',
4259 'audio/x-pn-realaudio-plugin' => 'rpm',
4260 'application/x-pkcs7' => 'rsa',
4261 'text/rtf' => 'rtf',
4262 'text/richtext' => 'rtx',
4263 'video/vnd.rn-realvideo' => 'rv',
4264 'application/x-stuffit' => 'sit',
4265 'application/smil' => 'smil',
4266 'text/srt' => 'srt',
4267 'image/svg+xml' => 'svg',
4268 'application/x-shockwave-flash' => 'swf',
4269 'application/x-tar' => 'tar',
4270 'application/x-gzip-compressed' => 'tgz',
4271 'image/tiff' => 'tiff',
4272 'text/plain' => 'txt',
4273 'text/x-vcard' => 'vcf',
4274 'application/videolan' => 'vlc',
4275 'text/vtt' => 'vtt',
4276 'audio/x-wav' => 'wav',
4277 'audio/wave' => 'wav',
4278 'audio/wav' => 'wav',
4279 'application/wbxml' => 'wbxml',
4280 'video/webm' => 'webm',
4281 'audio/x-ms-wma' => 'wma',
4282 'application/wmlc' => 'wmlc',
4283 'video/x-ms-wmv' => 'wmv',
4284 'video/x-ms-asf' => 'wmv',
4285 'application/xhtml+xml' => 'xhtml',
4286 'application/excel' => 'xl',
4287 'application/msexcel' => 'xls',
4288 'application/x-msexcel' => 'xls',
4289 'application/x-ms-excel' => 'xls',
4290 'application/x-excel' => 'xls',
4291 'application/x-dos_ms_excel' => 'xls',
4292 'application/xls' => 'xls',
4293 'application/x-xls' => 'xls',
4294 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
4295 'application/vnd.ms-excel' => 'xlsx',
4296 'application/xml' => 'xml',
4297 'text/xml' => 'xml',
4298 'text/xsl' => 'xsl',
4299 'application/xspf+xml' => 'xspf',
4300 'application/x-compress' => 'z',
4301 'application/x-zip' => 'zip',
4302 'application/zip' => 'zip',
4303 'application/x-zip-compressed' => 'zip',
4304 'application/s-compressed' => 'zip',
4305 'multipart/x-zip' => 'zip',
4306 'text/x-scriptzsh' => 'zsh',
4307 ];
4308
4309 return isset($mime_map[$mime]) === true ? $mime_map[$mime] : false;
4310 }
4311 }
4312
4313 if ( ! function_exists('wdk_is_dash_enabled'))
4314 {
4315 /**
4316 * IS Dash pages exists
4317 *
4318 * @return bool true if exists dash
4319 */
4320 function wdk_is_dash_enabled() {
4321 if(function_exists('run_wdk_membership') && wdk_get_option('wdk_membership_dash_page') && get_post_status(wdk_get_option('wdk_membership_dash_page')) =='publish'){
4322 return true;
4323 }
4324
4325 return false;
4326 }
4327 }
4328
4329 if(!function_exists('wdk_page_by_title')) {
4330 function wdk_page_by_title ( $page_title, $output = OBJECT, $post_type = 'page' ) {
4331 global $wpdb;
4332
4333 if ( is_array( $post_type ) ) {
4334 $post_type = esc_sql( $post_type );
4335 $post_type_in_string = "'" . implode( "','", $post_type ) . "'";
4336 $sql = $wpdb->prepare(
4337 "
4338 SELECT ID
4339 FROM $wpdb->posts
4340 WHERE post_title = %s
4341 AND post_type IN ($post_type_in_string)
4342 ",
4343 $page_title
4344 );
4345 } else {
4346 $sql = $wpdb->prepare(
4347 "
4348 SELECT ID
4349 FROM $wpdb->posts
4350 WHERE post_title = %s
4351 AND post_type = %s
4352 ",
4353 $page_title,
4354 $post_type
4355 );
4356 }
4357
4358 $page = $wpdb->get_var( $sql );
4359
4360 if ( $page ) {
4361 return get_post( $page, $output );
4362 }
4363
4364 return null;
4365 }
4366 }
4367
4368
4369 if ( ! function_exists('is_wdk_gps_single'))
4370 {
4371 function is_wdk_gps_single($param)
4372 {
4373
4374 if (is_numeric($param) && $param > -180 && $param < 180) {
4375 return true;
4376 }
4377
4378 return false;
4379 }
4380 }
4381
4382 if ( ! function_exists('wdk_get_tgmpa_link'))
4383 {
4384 function wdk_get_tgmpa_link()
4385 {
4386 if(file_exists(get_template_directory().'/includes/tgm_pa/class-tgm-plugin-activation.php') || file_exists(get_template_directory().'/tgm_pa/class-tgm-plugin-activation.php')) {
4387 return get_admin_url() . "themes.php?page=tgmpa-install-plugins";
4388 } else {
4389 return get_admin_url() . "plugins.php?page=tgmpa-install-plugins";
4390 }
4391
4392 return false;
4393 }
4394 }
4395
4396 if ( ! function_exists('wdk_sprintf'))
4397 {
4398 function wdk_sprintf($string = '')
4399 {
4400 $arg_list = func_get_args();
4401
4402 if(count($arg_list)<2) {
4403 return $string;
4404 }
4405
4406 if(stripos($string, '%1$s') === FALSE) {
4407 return $string;
4408 }
4409
4410 return call_user_func_array("sprintf", $arg_list);
4411 }
4412 }
4413
4414 if ( ! function_exists('wdk_db_table'))
4415 {
4416 function wdk_db_table($data, $columns = array()) {
4417 $output = '<table>';
4418 foreach($data as $key => $var) {
4419 if($key === 0)
4420 {
4421 $output .= '<tr>';
4422 foreach($var as $k => $v) {
4423 if(count($columns) > 0 && !in_array($k, $columns))continue;
4424
4425 $output .= '<td><strong>' . $k . '</strong></td>';
4426 }
4427 $output .= '</tr>';
4428 }
4429
4430 $output .= '<tr>';
4431 foreach($var as $k => $v) {
4432 if(count($columns) > 0 && !in_array($k, $columns))continue;
4433
4434 $output .= '<td>' . $v . '</td>';
4435 }
4436 $output .= '</tr>';
4437 }
4438 $output .= '</table>';
4439 echo $output;
4440 }
4441 }
4442
4443 if ( ! function_exists('wdk_move_gps'))
4444 {
4445 function wdk_move_gps($value) {
4446 return $value+0.001 * rand(1, 9);
4447 }
4448 }
4449
4450 if ( ! function_exists('wdk_get_near_location'))
4451 {
4452 function wdk_get_near_location($latitude, $longitude, $radius = 10000) {
4453 // Convert radius from meters to degrees
4454 $radiusInDegrees = $radius / 111000;
4455
4456 $u = mt_rand() / mt_getrandmax();
4457 $v = mt_rand() / mt_getrandmax();
4458 $w = $radiusInDegrees * sqrt($u);
4459 $t = 2 * M_PI * $v;
4460 $x = $w * cos($t);
4461 $y = $w * sin($t);
4462
4463 // Adjust the x-coordinate for the shrinking of the east-west distances
4464 $newX = $x / cos(deg2rad($latitude));
4465
4466 $newLongitude = $longitude + $newX;
4467 $newLatitude = $latitude + $y;
4468
4469 return array('lat' => $newLatitude, 'lng' => $newLongitude);
4470 }
4471 }
4472
4473 if ( ! function_exists('wdk_is_listing_preview_page'))
4474 {
4475 function wdk_is_listing_preview_page() {
4476 global $wdk_listing_id;
4477
4478 if(!empty($wdk_listing_id))
4479 return TRUE;
4480
4481 return FALSE;
4482 }
4483 }
4484
4485 if ( ! function_exists('wdk_is_listing_field_exists'))
4486 {
4487 function wdk_is_listing_field_exists($field_name = '', $udpate_cache = FALSE) {
4488 static $available_fields_listings = array();
4489 $custom_fields = array();
4490
4491 $WMVC = &wdk_get_instance();
4492 $WMVC->model('listingfield_m');
4493
4494 if(empty($available_fields_listings) || $udpate_cache) {
4495 $available_fields_listings = $WMVC->listingfield_m->get_available_fields();
4496 }
4497
4498 if(isset($available_fields_listings[$field_name]) || isset($custom_fields[$field_name])) {
4499 return TRUE;
4500 }
4501
4502 return FALSE;
4503 }
4504 }
4505
4506 if ( ! function_exists('wdk_cached_field_get'))
4507 {
4508 function wdk_cached_field_get($udpate_cache = FALSE) {
4509 static $fields = NULL;
4510
4511 $WMVC = &wdk_get_instance();
4512 $WMVC->model('field_m');
4513
4514 if(is_null($fields) || $udpate_cache) {
4515 $fields = $WMVC->field_m->get();
4516 }
4517
4518 return $fields;
4519 }
4520 }
4521
4522 if (! function_exists('wdk_generate_slug'))
4523 {
4524 function wdk_generate_slug($str, $separator = 'dash', $lowercase = TRUE)
4525 {
4526 if ($separator == 'dash')
4527 {
4528 $search = '_';
4529 $replace = '-';
4530 }
4531 else
4532 {
4533 $search = '-';
4534 $replace = '_';
4535 }
4536
4537 $dot='';
4538 if($separator == 'dot'){
4539 $str = str_replace(' ', '.', $str);
4540 $dot='.';
4541 }
4542
4543 $trans = array(
4544 $search => $replace,
4545 "\s+" => $replace,
4546 "[^a-z0-9".$replace.$dot."]" => '',
4547 $replace."+" => $replace,
4548 $replace."$" => '',
4549 "^".$replace => ''
4550 );
4551
4552 // For Croatia
4553 $str = str_replace(array('č','ć','ž','š','đ', 'Č','Ć','Ž','Š','Đ'),
4554 array('c','c','z','s','d', 'c','c','z','s','d'), $str);
4555
4556 // For Turkish
4557 $str = str_replace(array('ş','Ş','ı','İ','ğ','Ğ','Ü','ü','Ö','ö','ç','Ç'),
4558 array('s','s','i','i','g','g','u','u','o','o','c','c'), $str);
4559
4560 // Russian alphabet
4561 $str = str_replace(array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я'),
4562 array('a','b','v','g','d','e','e','zh','z','i','y','k','l','m','n','o','p','r','s','t','u','f','kh','c','ch','sh','sh','','y','','e','yu','ya'), $str);
4563 $str = str_replace(array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','�
4564 ','ц','ч','ш','щ','ъ','ы','ь','э','ю','я'),
4565 array('a','b','v','g','d','e','e','zh','z','i','y','k','l','m','n','o','p','r','s','t','u','f','kh','c','ch','sh','sh','','y','','e','yu','ya'), $str);
4566
4567 // Ukrainian alphabet
4568 $str = str_replace(array('Ґ','Є','І','Ї'),
4569 array('G','E','I','I'), $str);
4570 $str = str_replace(array('ґ','є','і','ї'),
4571 array('g','e','i','i'), $str);
4572 // Symbols
4573 $str = str_replace(array("  ","’","–",'«','»','№','„','”'),
4574 array("","","-",'','','no','',''), $str);
4575
4576 // Alphabets Czech Croatian Turkish and other
4577 $str = str_replace(array('Á','Ä','Ď','É','Ě','Ë','Í','Ň','Ń','Ó','Ŕ','Ř','Ť','Ú','Ů','Ý','Ź','Č','Ć','Ž','Š','Đ','Ş','İ','Ğ','Ü','Ö','Ç'),
4578 array('a','a','d','e','e','e','i','n','n','o','r','r','t','u','u','y','z','c','c','z','s','d','s','i','g','u','o','c'), $str);
4579 $str = str_replace(array('á','ä','ď','é','ě','ë','í','ň','ń','ó','ŕ','ř','ť','ú','ů','ý','ź','č','ć','ž','š','đ','ş','ı','ğ','ü','ö','ç'),
4580 array('a','a','d','e','e','e','i','n','n','o','r','r','t','u','u','y','z','c','c','z','s','d','s','i','g','u','o','c'), $str);
4581
4582 // For french
4583 $str = str_replace(array('â','é','è','û','ê', 'à','Â','ç','ï','î','ä','î'),
4584 array('a','e','e','u','e', 'a','c','c','i','î','a','î'), $str);
4585
4586 $str = strip_tags(strtolower($str));
4587
4588
4589 foreach ($trans as $key => $val)
4590 {
4591 $str = preg_replace("#".$key."#", $val, $str);
4592 }
4593
4594 return trim(stripslashes($str));
4595 }
4596 }
4597
4598
4599 if (! function_exists('wdk_is_gps'))
4600 {
4601 function wdk_is_gps($gps = '')
4602 {
4603
4604 if(stripos($gps,',') === FALSE) {
4605 return FALSE;
4606 }
4607
4608 $gps_coor = explode(',', $gps);
4609
4610 if(count($gps_coor) != 2)
4611 {
4612 return FALSE;
4613 }
4614
4615 if(!is_numeric($gps_coor[0]) || !is_numeric($gps_coor[1]))
4616 {
4617 return FALSE;
4618 }
4619
4620 if($gps_coor[0] < -90 || $gps_coor[0] > 90 || $gps_coor[1] < -180 || $gps_coor[1] > 180)
4621 {
4622 return FALSE;
4623 }
4624
4625 return TRUE;
4626 }
4627 }
4628
4629 if ( ! function_exists('is_wdk_is_useremail_exists'))
4630 {
4631 function is_wdk_is_useremail_exists($param)
4632 {
4633
4634 if(null == username_exists( $param ) && !email_exists($param)) {
4635 return true;
4636 }
4637
4638 return false;
4639 }
4640 }
4641
4642
4643 /*
4644 Validation is natural integer
4645 */
4646 if ( ! function_exists('is_wdk_is_natural'))
4647 {
4648 function is_wdk_is_natural($param)
4649 {
4650
4651 if (is_intval($param) && stripos($param, '.') === FALSE && stripos($param, ',') === FALSE) {
4652 return true;
4653 }
4654
4655 return false;
4656 }
4657 }
4658
4659
4660 /**
4661 * Check is listing preview page exits
4662 *
4663 * @return bool
4664 */
4665 if ( ! function_exists('wdk_is_listing_page_enabled'))
4666 {
4667 function wdk_is_listing_page_enabled ()
4668 {
4669
4670 if(get_option('wdk_listing_page') && get_post_status(get_option('wdk_listing_page')) =='publish') {
4671 return true;
4672 }
4673
4674 return false;
4675 }
4676 }
4677
4678
4679 /**
4680 * Check is listing preview page exits
4681 *
4682 * @return bool
4683 */
4684 if ( ! function_exists('replace_smart_data'))
4685 {
4686 function replace_smart_data($output = '', $replace_data = array()) {
4687 // Match all occurrences of the pattern
4688 if (preg_match_all('/\{([^}]+)\}/', $output, $matches)) {
4689 foreach ($matches[1] as $key => $value) {
4690 foreach ($replace_data as $replace_key => $replace_value) {
4691 $output = str_replace('{'.$replace_key.'}', $replace_value, $output);
4692 }
4693 }
4694 }
4695 return $output;
4696 }
4697 }
4698
4699 if ( ! function_exists('wdk_generate_missing_image_sizes'))
4700 {
4701 /**
4702 * Wdk_generate_missing_image_sizes and update meta
4703 * @param int $attachment_id of iamge
4704 * @param string $size_name size of image based on wp intermediate_size
4705 *
4706 * @return bool
4707 */
4708 function wdk_generate_missing_image_sizes($attachment_id, $size_name = '') {
4709 if(empty($size_name) || $size_name == 'full' || !get_option( "{$size_name}_size_w" )) {
4710 return true;
4711 }
4712
4713 // Check if the attachment is an image
4714 if (!wp_attachment_is_image($attachment_id)) {
4715 return false;
4716 }
4717
4718 $file = get_attached_file( $attachment_id );
4719 require_once(ABSPATH . "wp-admin" . '/includes/image.php');
4720 $metadata = wp_generate_attachment_metadata($attachment_id, $file);
4721 if ( ! isset( $metadata['sizes'][ $size_name ] ) ) {
4722 // Generate the missing image size
4723 $resized = image_make_intermediate_size( $file, get_option( "{$size_name}_size_w" ), get_option( "{$size_name}_size_h" ), get_option( "{$size_name}_crop" ) );
4724
4725 // If the resizing was successful, add it to the metadata
4726 if ( $resized ) {
4727 $metadata['sizes'][ $size_name ] = $resized;
4728 wp_update_attachment_metadata( $attachment_id, $metadata );
4729 }
4730 }
4731 return true;
4732 }
4733 }
4734
4735 if (!function_exists('wdk_get_languages')) {
4736
4737 function wdk_get_languages($lang_code_id = null)
4738 {
4739 $lang_pattern = ['title' => '', 'lang_code' => '', 'id' => '', 'icon' => '', 'url' => ''];
4740 $languages = [];
4741
4742 // [qTranslate X]
4743 if (function_exists('qtranxf_getSortedLanguages')) {
4744 global $q_config;
4745
4746 if (empty($q_config)) {
4747 // Initialize qTranslate X language settings if needed
4748 // qtranxf_init_language();
4749 }
4750
4751 $all_langs = qtranxf_getSortedLanguages();
4752 if (count($all_langs) > 0) {
4753 foreach ($all_langs as $key => $lang_code) {
4754 $languages[$key + 1] = array_merge(
4755 $lang_pattern,
4756 [
4757 'title' => $q_config['language_name'][$lang_code],
4758 'lang_code' => $lang_code,
4759 'id' => $key + 1,
4760 'icon' => '',
4761 'url' => wdk_get_language_url($lang_code),
4762 ]
4763 );
4764 }
4765 }
4766 }
4767 // [/qTranslate X]
4768
4769 // [WPML]
4770 if (function_exists('icl_get_languages')) {
4771 $wpml_langs = icl_get_languages('orderby=KEY&order=DIR&link_empty_to=str');
4772 $k = 1;
4773 foreach ($wpml_langs as $key => $lang_data) {
4774 $languages[$k] = array_merge(
4775 $lang_pattern,
4776 [
4777 'title' => (!empty($lang_data['translated_name'])) ? $lang_data['translated_name'] : $lang_data['native_name'],
4778 'lang_code' => $lang_data['language_code'],
4779 'id' => $k,
4780 'icon' => (!empty($lang_data['country_flag_url'])) ? $lang_data['country_flag_url'] : WPDIRECTORYKIT_URL.'public/img/flags/'.$lang_data['language_code'].'.png',
4781 'url' => wdk_get_language_url($lang_data['language_code']),
4782 ]
4783 );
4784 $k++;
4785 }
4786 } elseif (has_filter('wpml_active_languages')) {
4787 $wpml_langs = apply_filters('wpml_active_languages', null) ?: get_query_var('lang', 'all');
4788 if (is_array($wpml_langs)) {
4789 foreach ($wpml_langs as $lang_data) {
4790 if (!isset($lang_data['code']) && isset($lang_data['language_code'])) {
4791 $lang_data['code'] = $lang_data['language_code'];
4792 }
4793 if (empty($lang_data['translated_name']) && !empty($lang_data['native_name'])) {
4794 $lang_data['translated_name'] = $lang_data['native_name'];
4795 }
4796 $languages[$lang_data['id']] = array_merge(
4797 $lang_pattern,
4798 [
4799 'title' => (!empty($lang_data['translated_name'])) ? $lang_data['translated_name'] : $lang_data['native_name'],
4800 'lang_code' => $lang_data['code'],
4801 'id' => $lang_data['id'],
4802 'icon' => (!empty($lang_data['country_flag_url'])) ? $lang_data['country_flag_url'] : WPDIRECTORYKIT_URL.'public/img/flags/'.$lang_data['language_code'].'.png',
4803 'url' => wdk_get_language_url($lang_data['code']),
4804 ]
4805 );
4806 }
4807 }
4808 }
4809 // [/WPML]
4810
4811 // [TranslatePress]
4812 if (function_exists('trp_custom_language_switcher')) {
4813 $k = 1;
4814 foreach (trp_custom_language_switcher() as $lang_data) {
4815 $languages[$k++] = array_merge(
4816 $lang_pattern,
4817 [
4818 'title' => $lang_data['language_name'],
4819 'lang_code' => $lang_data['language_code'],
4820 'id' => $k,
4821 'icon' => $lang_data['flag_link'],
4822 'url' => $lang_data['current_page_url'],
4823 ]
4824 );
4825 }
4826 }
4827 // [/TranslatePress]
4828
4829 if (!empty($lang_code_id)) {
4830 foreach ($languages as $lang) {
4831 if (($lang['id'] == $lang_code_id) || ($lang['lang_code'] == $lang_code_id)) {
4832 return $lang['id'] == $lang_code_id ? $lang['lang_code'] : $lang['id'];
4833 }
4834 }
4835 return false;
4836 }
4837
4838 return $languages;
4839 }
4840 }
4841
4842 if (!function_exists('wdk_default_language')) {
4843 function wdk_default_language()
4844 {
4845 // [qTranslate X]
4846 if (function_exists('qtranxf_getLanguageDefault')) {
4847 return qtranxf_getLanguageDefault();
4848 }
4849 // [/qTranslate X]
4850
4851 // [WPML]
4852 if (function_exists('icl_get_languages')) {
4853 $wpml_langs = icl_get_languages('orderby=KEY&order=DIR&link_empty_to=str');
4854 foreach ($wpml_langs as $lang_data) {
4855 if ($lang_data['major'] == 1) {
4856 return $lang_data['code'];
4857 }
4858 }
4859 } elseif (has_filter('wpml_default_language')) {
4860 return apply_filters('wpml_default_language', null);
4861 }
4862 // [/WPML]
4863
4864 return 'en';
4865 }
4866 }
4867
4868 if (!function_exists('wdk_current_language')) {
4869 function wdk_current_language()
4870 {
4871 if (function_exists('trp_get_languages')) {
4872 global $TRP_LANGUAGE;
4873 $trp = TRP_Translate_Press::get_trp_instance();
4874 $settings = $trp->get_component('settings')->get_settings();
4875 $translation_languages = $trp->get_component('languages')->get_language_names($settings['publish-languages']);
4876 if (isset($translation_languages[$TRP_LANGUAGE])) {
4877 return $translation_languages[$TRP_LANGUAGE];
4878 }
4879 }
4880
4881 // [qTranslate X]
4882 if (function_exists('qtranxf_getLanguage')) {
4883 return qtranxf_getLanguage();
4884 }
4885 // [/qTranslate X]
4886
4887 // [WPML]
4888 if (function_exists('icl_get_languages')) {
4889 $wpml_langs = icl_get_languages('orderby=KEY&order=DIR&link_empty_to=str');
4890 foreach ($wpml_langs as $lang_data) {
4891 if ($lang_data['active'] == 1) {
4892 return (!empty($lang_data['native_name'])) ? $lang_data['native_name'] : $lang_data['language_code'];
4893 }
4894 }
4895 } elseif (has_filter('wpml_current_language')) {
4896 return apply_filters('wpml_current_language', null);
4897 }
4898 // [/WPML]
4899
4900 return 'en';
4901 }
4902 }
4903
4904 if (!function_exists('wdk_current_language_id')) {
4905 function wdk_current_language_id()
4906 {
4907 $lang_id = wdk_get_languages(wdk_current_language());
4908 return is_numeric($lang_id) ? $lang_id : wdk_default_language_id();
4909 }
4910 }
4911
4912 if (!function_exists('wdk_default_language_id')) {
4913 function wdk_default_language_id()
4914 {
4915 $lang_id = wdk_get_languages(wdk_default_language());
4916 return is_numeric($lang_id) ? $lang_id : '1';
4917 }
4918 }
4919
4920 if (!function_exists('wdk_get_language_name')) {
4921 function wdk_get_language_name($id_or_code)
4922 {
4923 $langs = wdk_get_languages();
4924 foreach ($langs as $lang) {
4925 if ($lang['lang_code'] == $id_or_code || $lang['id'] == $id_or_code) {
4926 return $lang['title'];
4927 }
4928 }
4929 return '';
4930 }
4931 }
4932
4933 if (!function_exists('wdk_get_language_url')) {
4934 function wdk_get_language_url($lang_code)
4935 {
4936 // [qTranslate X]
4937 if (function_exists('qtranxf_convertURL')) {
4938 return qtranxf_convertURL('', $lang_code, false, true);
4939 }
4940 // [/qTranslate X]
4941
4942 // [WPML]
4943 if (function_exists('icl_get_languages')) {
4944 $wpml_langs = icl_get_languages('orderby=KEY&order=DIR&link_empty_to=str');
4945 foreach ($wpml_langs as $lang_data) {
4946 if ($lang_data['language_code'] == $lang_code) {
4947 return $lang_data['url'];
4948 }
4949 }
4950 } elseif (has_filter('wpml_active_languages')) {
4951 $wpml_langs = apply_filters('wpml_active_languages', null);
4952 foreach ($wpml_langs as $lang_data) {
4953 if (!isset($lang_data['language_code']) && isset($lang_data['language_code'])) {
4954 $lang_data['language_code'] = $lang_data['language_code'];
4955 }
4956 if (empty($lang_data['translated_name']) && !empty($lang_data['native_name'])) {
4957 $lang_data['translated_name'] = $lang_data['native_name'];
4958 }
4959 $url = wdk_wpml_ls_language_url($lang_data['url'], $lang_data);
4960 if ($lang_data['language_code'] == $lang_code) {
4961 return $url;
4962 }
4963 }
4964 }
4965 // [/WPML]
4966
4967 return '';
4968 }
4969 }
4970
4971 function wdk_set_user_default_language($user_id = null)
4972 {
4973 if (is_null($user_id)) {
4974 $user_id = get_current_user_id();
4975 }
4976
4977 $get_language = get_user_meta($user_id, 'user_language', true);
4978
4979 if (!$get_language && (function_exists('icl_get_languages') || has_filter('wpml_active_languages'))) {
4980 do_action('wpml_switch_language', $get_language);
4981 }
4982 }
4983
4984 function wdk_set_language($lang_code = null)
4985 {
4986 if (!is_null($lang_code) && (function_exists('icl_get_languages') || has_filter('wpml_active_languages'))) {
4987 do_action('wpml_switch_language', $lang_code);
4988 }
4989 }
4990
4991 function wdk_wpml_ls_language_url($url, $data)
4992 {
4993 global $sitepress;
4994
4995 if (is_object($sitepress)) {
4996 $sitepress_settings = $sitepress->get_settings();
4997 }
4998
4999 return $url;
5000 }
5001
5002 add_filter('wpml_ls_language_url', 'wdk_wpml_ls_language_url', 10, 3);
5003
5004 if (!function_exists('wdk_calculate_nights')) {
5005 /**
5006 * Calculate the number of nights between two dates
5007 *
5008 * This function takes two date strings as input and calculates the number of nights
5009 * (i.e., the difference in days) between them. It returns the total number of nights
5010 * between the provided start and end dates. The date format must be valid for PHP's
5011 * DateTime class.
5012 *
5013 * @param string $start_date The start date in 'Y-m-d' format.
5014 * @param string $end_date The end date in 'Y-m-d' format.
5015 * @return int The number of nights (days between the two dates).
5016 */
5017 function wdk_calculate_nights($start_date, $end_date) {
5018
5019 /* normalize date */
5020 $start_date = wdk_normalize_date_db($start_date, 'Y-m-d H:i:s', 'Y-m-d');
5021 $end_date = wdk_normalize_date_db($end_date, 'Y-m-d H:i:s', 'Y-m-d');
5022
5023 // Create DateTime objects for start and end dates
5024 $start = new DateTime($start_date);
5025 $end = new DateTime($end_date);
5026
5027 // Calculate the difference between the two dates
5028 $difference = $start->diff($end);
5029
5030 // Return the number of nights (difference in days)
5031 return $difference->days;
5032 }
5033 }
5034
5035 if ( ! function_exists('wdk_select_db_field_ajax'))
5036 {
5037 /**
5038 * Return select2 ajax
5039 *
5040 * @param string option Option key
5041 * @return string alt or title
5042 */
5043 function wdk_select_db_field_ajax($name = '', $selected = NULL, $empty_value='', $filter_id = '')
5044 {
5045 $WMVC = &wdk_get_instance();
5046
5047 static $counter = 0;
5048 $form = '<select data-ajax="'.admin_url('admin-ajax.php').'" name="'.$name.'" data-id="'.$filter_id.'" data-placeholder="'.$empty_value.'" class="form-control wdk_select2_field_suggestion" id="wdk_select2_field_'.$filter_id.'_'.$counter.'" multiple="">';
5049 if($selected) {
5050 if(is_array($selected)) {
5051 /* where in */
5052 foreach ($selected as $item) {
5053 $form .= '<option selected="selected" value="'.esc_attr($item).'">'.esc_html($item).'</option>';
5054 }
5055 } elseif(is_string($selected)) {
5056 $form .= '<option selected="selected" value="'.esc_attr($selected).'">'.esc_html($selected).'</option>';
5057 }
5058 } else {
5059 //$form .= '<option value="" selected="selected">'.esc_html__('Not selected', 'wpdirectorykit').'</option>';
5060 }
5061 $form .= '</select>';
5062
5063 //load javascript library
5064 if($counter==0)
5065 {
5066 wp_enqueue_script('select2-select2');
5067 wp_enqueue_script('wdk-select2');
5068 wp_enqueue_style('select2-select2');
5069 }
5070 ?>
5071 <?php
5072 $counter++;
5073 return $form;
5074
5075 }
5076 }
5077
5078 if ( ! function_exists('wdk_next_month_payment_day'))
5079 {
5080 /**
5081 * Gets the next payment date one month later, considering the number of days in the next month.
5082 *
5083 * @param string $currentDate The current payment date in 'Y-m-d H:i:s' format.
5084 * @return string|false The next payment date in 'Y-m-d H:i:s' format or false on error.
5085 */
5086 function wdk_next_month_payment_day($currentDate, $time = false, $wanted_day = NULL) {
5087 $nextDate = null;
5088 $timestamp = strtotime($currentDate);
5089 $daysInNextMonth = date('t', strtotime('+1 month', strtotime(date('Y-m', $timestamp))));
5090 $currentDay = (int)date('d', $timestamp);
5091
5092 $timeFormat = $time ? "H:i:s" : "00:00:00";
5093
5094
5095 // Determine the wanted day
5096 if ($wanted_day !== NULL) {
5097 $wanted_day = (int)date('d', strtotime($wanted_day));
5098 } else {
5099 $wanted_day = (int)date('d', $timestamp);
5100 }
5101
5102 $nextMonth = strtotime('first day of next month', $timestamp);
5103 $daysInNextMonth = date('t', $nextMonth);
5104
5105 // Adjust for the wanted day
5106 if ($wanted_day > $daysInNextMonth ||
5107 (
5108 get_option('wdk_membership_next_month_calculation_with_last_day')
5109
5110 && (
5111 $currentDay >= 30 || $currentDay == date('t', $timestamp)
5112 )
5113 )
5114 ) {
5115 // If the wanted day exceeds the max days of the next month, use the last day of the month
5116 $nextDate = date("Y-m-{$daysInNextMonth} {$timeFormat}", $nextMonth);
5117 } else {
5118 // Otherwise, set the exact wanted day
5119 $nextDate = date("Y-m-{$wanted_day} {$timeFormat}", $nextMonth);
5120 }
5121
5122 return ($nextDate) ? $nextDate : false;
5123 }
5124 }
5125
5126 if ( ! function_exists('wdk_next_year_payment_day'))
5127 {
5128 /**
5129 * Gets the next payment date one year later, considering the number of days in the next month.
5130 *
5131 * @param string $currentDate The current payment date in 'Y-m-d H:i:s' format.
5132 * @return string|false The next payment date in 'Y-m-d H:i:s' format or false on error.
5133 */
5134
5135 function wdk_next_year_payment_day($currentDate, $time = false) {
5136 $nextDate = null;
5137 $timestamp = strtotime($currentDate);
5138 $nextYearTimestamp = strtotime('+1 year', strtotime(date('Y-m', $timestamp)));
5139 $daysInNextMonth = date('t', $nextYearTimestamp);
5140 $currentDay = date('j', $timestamp);
5141 $timeFormat = "00:00:00";
5142 if($time) {
5143 $timeFormat = "H:i:s";
5144 }
5145 if ($currentDay > $daysInNextMonth) {
5146 $nextDate = date('Y-m-d '.$timeFormat, strtotime('last day of this month', $nextYearTimestamp));
5147 } else {
5148 $nextDate = date('Y-m-d '.$timeFormat, strtotime('+1 year', $timestamp));
5149 }
5150
5151 return ($nextDate) ? $nextDate : false;
5152 }
5153 }
5154
5155 if ( ! function_exists('wdk_generate_auto_login_link'))
5156 {
5157 function wdk_generate_auto_login_link( $user_id = null ) {
5158 $token = substr(md5($user_id.NONCE_KEY.'wpdirectorykit'),0,10);
5159
5160 $login_url = site_url( "/?auto-login=1&user_id={$user_id}&token={$token}" );
5161 return $login_url;
5162 }
5163 }
5164
5165 if ( ! function_exists('wdk_get_user_subscription_id'))
5166 {
5167 function wdk_get_user_subscription_id($user_id = null) {
5168 global $Winter_MVC_wdk_membership;
5169 if(!isset($Winter_MVC_wdk_membership)) {
5170 return false;
5171 }
5172 $Winter_MVC_wdk_membership->model('subscription_user_m');
5173 $user_subscription = $Winter_MVC_wdk_membership->subscription_user_m->get_by(array('user_id'=>$user_id), TRUE);
5174 return wmvc_show_data('subscription_id', $user_subscription, '', TRUE, TRUE);
5175 }
5176 }
5177
5178 if ( ! function_exists('is_wdk_related_validation'))
5179 /**
5180 * IS WDK related validation
5181 *
5182 * @return bool true if exists dash
5183 */
5184 {
5185 function is_wdk_related_validation($param)
5186 {
5187
5188 if(empty($param)) {
5189 return TRUE;
5190 }
5191
5192 $listing_id = (!empty($_GET['id'])) ? intval(sanitize_text_field($_GET['id'])) : null;
5193
5194
5195 global $Winter_MVC_WDK;
5196 $Winter_MVC_WDK->model('listing_m');
5197
5198 $Winter_MVC_WDK->db->select('post_id');
5199 $Winter_MVC_WDK->db->where(array(
5200 '(post_id IN ('.esc_sql(sanitize_text_field($param)).'))' => NULL,
5201 '((`listing_related_ids` IS NOT NULL AND `listing_related_ids` !="") OR (`listing_parent_post_id` IS NOT NULL AND `listing_parent_post_id` !=0))' => NULL,
5202 ));
5203
5204 if($listing_id) {
5205 $Winter_MVC_WDK->db->where(array(
5206 '`listing_parent_post_id` !='.esc_sql($listing_id).'' => NULL,
5207 ));
5208 }
5209
5210 $Winter_MVC_WDK->db->from($Winter_MVC_WDK->listing_m->_table_name);
5211 $Winter_MVC_WDK->db->limit(5);
5212
5213 $Winter_MVC_WDK->db->get();
5214 if ($Winter_MVC_WDK->db->num_rows() > 0) {
5215 $db_results = $Winter_MVC_WDK->db->results();
5216 } else {
5217 $db_results = null;
5218 }
5219
5220 if (!empty($db_results)) {
5221 return false;
5222 }
5223
5224 return TRUE;
5225 }
5226 }
5227
5228 /**
5229 * Renders an Elementor template by its title or post ID.
5230 *
5231 * Attempts to find and render an Elementor layout/template using the post title or post ID.
5232 * If the post is found and public, its rendered Elementor content is returned, otherwise post content fallback or error.
5233 *
5234 * @since 1.0.0
5235 * @param string|int $title The title (or ID if $id=true) of the Elementor template to render.
5236 * @param bool $id Optional. If true, $title is treated as a post ID. If false (default), searches by title.
5237 * @return string|false Rendered template HTML on success, public/content fallback, or error message/false on failure.
5238 */
5239 function wdk_render_elementor_template( $title, $id = false ) {
5240 // Initialize variables.
5241 $layout_id = null;
5242 $template_content = '';
5243
5244 // Determine the layout/post ID.
5245 if ( ! $id ) {
5246 // Search by post title. Returns WP_Post/object or null.
5247 $found_post = wdk_page_by_title( $title, OBJECT, ['elementor_library','page'] );
5248 $layout_id = $found_post ? $found_post->ID : null;
5249
5250 // Support WPML translation if present.
5251 // The filter may change $layout_id to a translated post's ID if needed.
5252 $layout_id = apply_filters( 'wpml_object_id', $layout_id, 'elementor_library', true );
5253 } else {
5254 // ID provided directly.
5255 $layout_id = intval($title);
5256 }
5257
5258 // Early return if no valid layout found.
5259 if ( empty( $layout_id ) ) {
5260 return false;
5261 }
5262
5263 // Get post object (Elementor template or WP Page).
5264 $post_data = get_post( $layout_id );
5265
5266
5267 // Validate post: should exist, be published, and not password protected.
5268 if ( ! $post_data || $post_data->post_status !== 'publish' || post_password_required( $post_data ) ) {
5269 return esc_html__( 'Layout is not public', 'wpdirectorykit' );
5270 }
5271
5272 // Render content depending on post type.
5273 if (
5274 ( isset($post_data->post_type) && $post_data->post_type === 'elementor_library' ) ||
5275 ( isset($post_data->post_type) && $post_data->post_type === 'page' )
5276 ) {
5277 // Try to render using Elementor's frontend builder.
5278 if ( class_exists('\Elementor\Plugin') && method_exists('\Elementor\Plugin', 'instance') ) {
5279 $elementor_instance = \Elementor\Plugin::instance();
5280 $content = $elementor_instance->frontend->get_builder_content_for_display( $layout_id );
5281 $template_content = ! empty( $content ) ? $content : $post_data->post_content;
5282 } else {
5283 // Elementor not present; fallback to post content.
5284 $template_content = $post_data->post_content;
5285 }
5286 } else {
5287 // Non-Elementor post types, fallback to post content.
5288 $template_content = $post_data->post_content;
5289 }
5290
5291 /**
5292 * Filter: Allows modification of the rendered Elementor template content before returning.
5293 *
5294 * @param string $template_content The rendered template content.
5295 * @param int $layout_id The ID of the layout/template.
5296 * @param WP_Post $post_data The WP_Post object of the layout/template.
5297 */
5298 return apply_filters( 'wdk_render_elementor_template_output', $template_content, $layout_id, $post_data );
5299 }
5300
5301 if(!function_exists('wdk_esc_sql')) {
5302 function wdk_esc_sql ($value = '') {
5303 return esc_sql(trim(preg_replace([
5304 '/\bselect\b/i',
5305 '/\binsert\b/i',
5306 '/\bupdate\b/i',
5307 '/\bdelete\b/i',
5308 '/\bunion\b/i',
5309 '/\bextractvalue\b/i',
5310 '/\bversion\s*\(\)/i',
5311 '/\bdatabase\s*\(\)/i',
5312 '/\bconcat\s*\(/i',
5313 '/\bdrop\b/i',
5314 '/\bsleep\s*\(/i',
5315 '/\bbenchmark\s*\(/i',
5316 '/--/',
5317 '/#/i',
5318 '/\/\*/',
5319
5320 // EXTRA BLOCK YOU REQUESTED
5321 '/\\\\/', // remove backslash \
5322 '/\|/', // remove |
5323 '/%/', // remove %
5324 ], '', sanitize_text_field($value))));
5325 }
5326 }
5327
5328 if(!function_exists('wdk_listing_seo_title')) {
5329 function wdk_listing_seo_title () {
5330 static $cached_seo_title = null;
5331 if ($cached_seo_title !== null) {
5332 return $cached_seo_title;
5333 }
5334
5335 $seo_title ='';
5336 global $wp_query;
5337 $wdk_listing_id = $wp_query->post->ID;
5338 if(wdk_get_option('wdk_seo_listing_title')) {
5339 global $Winter_MVC_WDK;
5340 $Winter_MVC_WDK->model('field_m');
5341 $Winter_MVC_WDK->load_helper('listing');
5342
5343 $seo_template = wdk_get_option('wdk_seo_listing_title');
5344
5345 $matches = [];
5346 preg_match_all('/{(?:field_)?([^}]+)}/', $seo_template, $matches);
5347 $fields_in_template = isset($matches[1]) ? $matches[1] : [];
5348
5349 $fields_values = [];
5350
5351 foreach ($fields_in_template as $field_id) {
5352 $key_id = '{field_' . $field_id . '}';
5353 if($field_id == 'category') {
5354 $field_id = 'category_title';
5355 }
5356 if($field_id == 'location') {
5357 $field_id = 'location_title';
5358 }
5359 // Try to get value for field_id for this listing
5360 $fields_values[$key_id] = wdk_field_value($field_id, $wdk_listing_id);
5361 }
5362 // Replace the fields in template with real values
5363 $seo_title = strtr($seo_template, $fields_values);
5364 }
5365
5366 $cached_seo_title = $seo_title;
5367 return $seo_title;
5368 }
5369 }
5370
5371
5372
5373 ?>
5374