PluginProbe
WP Directory Kit / trunk
WP Directory Kit vtrunk
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 1.4.0 1.4.1 All 35 releases
wpdirectorykit / application / helpers / Basic.php

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

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