PluginProbe
WP Directory Kit / 1.3.2
WP Directory Kit v1.3.2
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 1.3.2, at application/helpers/Basic.php

4,263 lines 168.5 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)
8 {
9 if(is_array($fields))
10 foreach($fields as $field)
11 {
12 $field = (object) $field;
13
14 $field_type = $field->field_type;
15
16 $field_view_path = WPDIRECTORYKIT_PATH.'application/views/fields_edit/'.$field_type.'.php';
17
18 if(file_exists($field_view_path))
19 {
20 include $field_view_path;
21 }
22 else
23 {
24 echo __('Missing VIEW file:', 'wpdirectorykit').' '.esc_html($field_type).'.php';
25 }
26 }
27 }
28
29 if ( ! function_exists('wdk_generate_search_form'))
30 {
31 function wdk_generate_search_form($form_id=1, $subfolder='', $print = TRUE, $predefinedfields_query = array())
32 {
33 /* load WMVC data */
34 $WMVC = &wdk_get_instance();
35 $WMVC->model('searchform_m');
36 $WMVC->model('field_m');
37 $output = '';
38
39 /* get WMVC form data */
40 $fields = $WMVC->searchform_m->get($form_id, TRUE);
41 $user_fields = NULL;
42
43 /* get WMVC form fields */
44 if(is_object($fields))
45 $user_fields = json_decode($fields->searchform_json);
46 /* generate WMVC form fields html */
47 if(is_array($user_fields))
48 foreach($user_fields as $used_field)
49 {
50
51 if($used_field->field_id == 'cat') {
52 $field = array(
53 "idfield" => 'category',
54 "field_type" => 'CATEGORY',
55 "field_label" => __('Category', 'wpdirectorykit'),
56 "prefix" => '',
57 "suffix" => '',
58 "values_list" => '',
59 "placeholder" => '',
60 );
61 }else if($used_field->field_id == 'loc') {
62 $field = array(
63 "idfield" => 'location',
64 "field_type" => 'LOCATION',
65 "field_label" => __('Location', 'wpdirectorykit'),
66 "prefix" => '',
67 "suffix" => '',
68 "values_list" => '',
69 "placeholder" => '',
70 );
71 }else if($used_field->field_id == 'address') {
72 $field = array(
73 "idfield" => 'address',
74 "field_type" => 'INPUTBOX',
75 "field_label" => __('Address', 'wpdirectorykit'),
76 "prefix" => '',
77 "suffix" => '',
78 "values_list" => '',
79 "placeholder" => '',
80 );
81 }else if($used_field->field_id == 'post_title') {
82 $field = array(
83 "idfield" => 'post_title',
84 "field_type" => 'INPUTBOX',
85 "field_label" => __('Title', 'wpdirectorykit'),
86 "prefix" => '',
87 "suffix" => '',
88 "values_list" => '',
89 "placeholder" => '',
90 );
91 }else if($used_field->field_id == 'search') {
92 $field = array(
93 "idfield" => 'search',
94 "field_type" => 'INPUTBOX',
95 "field_label" => __('Search', 'wpdirectorykit'),
96 "prefix" => '',
97 "suffix" => '',
98 "values_list" => '',
99 "placeholder" => '',
100 );
101 }else if(function_exists('run_wdk_bookings') && $used_field->field_id == 'booking_date') {
102 $field = array(
103 "idfield" => 'booking_date',
104 "field_type" => 'BOOKINGS_DATE',
105 "field_label" => __('Booking Date', 'wpdirectorykit'),
106 "prefix" => '',
107 "suffix" => '',
108 "values_list" => '',
109 "placeholder" => '',
110 );
111 }else if(function_exists('run_wdk_bookings') && $used_field->field_id == 'booking_guest') {
112 $field = array(
113 "idfield" => 'booking_guest',
114 "field_type" => 'NUMBER',
115 "field_label" => __('Booking Max Guests', 'wpdirectorykit'),
116 "prefix" => '',
117 "suffix" => '',
118 "values_list" => '',
119 "placeholder" => '',
120 );
121 }else if($used_field->field_id == 'more') {
122 $field = array(
123 "idfield" => 'MORE',
124 "field_type" => 'MORE',
125 "field_label" => __('MORE', 'wpdirectorykit'),
126 "prefix" => '',
127 "suffix" => '',
128 "values_list" => '',
129 "placeholder" => '',
130 );
131 } else {
132 $field_data = $WMVC->field_m->get_fields_data($used_field->field_id);
133 if($field_data) {
134 if($used_field->query_type == 'slider_range') {
135 $field = array(
136 "idfield" => wmvc_show_data('idfield', $field_data),
137 "field_type" => 'SLIDER_RANGE',
138 "field_label" =>wmvc_show_data('field_label', $field_data),
139 "prefix" => wmvc_show_data('prefix', $field_data),
140 "suffix" => wmvc_show_data('suffix', $field_data),
141 "value_min" => wmvc_show_data('value_min', $used_field),
142 "value_max" => wmvc_show_data('value_max', $used_field),
143 "values_list" => wmvc_show_data('values_list', $field_data),
144 "placeholder" => wmvc_show_data('placeholder', $field_data)
145 );
146 } else {
147 $field = array(
148 "idfield" => wmvc_show_data('idfield', $field_data),
149 "field_type" => wmvc_show_data('field_type', $field_data),
150 "field_label" =>wmvc_show_data('field_label', $field_data),
151 "prefix" => wmvc_show_data('prefix', $field_data),
152 "suffix" => wmvc_show_data('suffix', $field_data),
153 "values_list" => wmvc_show_data('values_list', $field_data),
154 "placeholder" => wmvc_show_data('placeholder', $field_data)
155 );
156 }
157 }
158 }
159
160 /* if field not detected or remove from fields list, skip field in search */
161 if(empty($field)) continue;
162
163 /* add from user fields data */
164 $field['field_id'] = wmvc_show_data('field_id', $used_field);
165 $field['class'] = wmvc_show_data('class', $used_field);
166 $field['query_type'] = wmvc_show_data('query_type', $used_field);
167 $field['columns'] = wmvc_show_data('columns', $used_field);
168
169
170 $field_data = array();
171 $field_data ['field_data'] = $field;
172 $field_data ['predefinedfields_query'] = $predefinedfields_query;
173
174 if(in_array(wmvc_show_data('field_type', $field),array('SECTION'))) {
175 continue;
176 }
177
178 $field_view_path = WPDIRECTORYKIT_PATH.'application/views/search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)).'.php';
179 if(file_exists($field_view_path))
180 {
181 $output .= $WMVC->view('search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)), $field_data, FALSE);
182 }
183 else
184 {
185 /* show missing view file of field, only if print enable */
186 if($print)
187 $output .= __('Missing VIEW file:', 'wpdirectorykit').' '.esc_html($subfolder).(wmvc_show_data('field_type', $field)).'.php';
188 }
189
190 }
191
192 if($print){
193 echo $output;
194 return FALSE;
195 }
196
197 return $output;
198 }
199 }
200
201 if ( ! function_exists('wdk_generate_search_form_fields_elementor'))
202 {
203 function wdk_generate_search_form_fields_elementor($fields_array = array(), $subfolder='', $print = TRUE, $predefinedfields_query = array())
204 {
205 /* load WMVC data */
206 $WMVC = &wdk_get_instance();
207 $WMVC->model('searchform_m');
208 $WMVC->model('field_m');
209 $output = '';
210
211 foreach ($fields_array as $key => $el_field_data) {
212 $field_id = wmvc_show_data('field_id', $el_field_data, '');
213 if(empty($field_id)) continue;
214
215 if(strpos($field_id,'__') !== FALSE){
216 $field_id = substr($field_id, strpos($field_id,'__')+2);
217 }
218
219 $field = NULL;
220 if($field_id == 'category_id') {
221 $field = array(
222 "idfield" => 'category',
223 "field_type" => 'CATEGORY',
224 "field_label" => __('Category', 'wpdirectorykit'),
225 "prefix" => '',
226 "suffix" => '',
227 "values_list" => '',
228 "placeholder" => '',
229 );
230 }else if($field_id == 'location_id') {
231 $field = array(
232 "idfield" => 'location',
233 "field_type" => 'LOCATION',
234 "field_label" => __('Location', 'wpdirectorykit'),
235 "prefix" => '',
236 "suffix" => '',
237 "values_list" => '',
238 "placeholder" => '',
239 );
240 }else if($field_id == 'address') {
241 $field = array(
242 "idfield" => 'address',
243 "field_type" => 'INPUTBOX',
244 "field_label" => __('Address', 'wpdirectorykit'),
245 "prefix" => '',
246 "suffix" => '',
247 "values_list" => '',
248 "placeholder" => '',
249 );
250 }else if($field_id == 'post_title') {
251 $field = array(
252 "idfield" => 'post_title',
253 "field_type" => 'INPUTBOX',
254 "field_label" => __('Title', 'wpdirectorykit'),
255 "prefix" => '',
256 "suffix" => '',
257 "values_list" => '',
258 "placeholder" => '',
259 );
260 }else if($field_id == 'search') {
261 $field = array(
262 "idfield" => 'search',
263 "field_type" => 'INPUTBOX',
264 "field_label" => __('Search', 'wpdirectorykit'),
265 "prefix" => '',
266 "suffix" => '',
267 "values_list" => '',
268 "placeholder" => '',
269 );
270 }else if(function_exists('run_wdk_bookings') && $field_id == 'booking_date') {
271 $field = array(
272 "idfield" => 'booking_date',
273 "field_type" => 'BOOKINGS_DATE',
274 "field_label" => __('Booking Date', 'wpdirectorykit'),
275 "prefix" => '',
276 "suffix" => '',
277 "values_list" => '',
278 "placeholder" => '',
279 );
280 }else if($field_id == 'more') {
281 $field = array(
282 "idfield" => 'MORE',
283 "field_type" => 'MORE',
284 "field_label" => __('MORE', 'wpdirectorykit'),
285 "prefix" => '',
286 "suffix" => '',
287 "values_list" => '',
288 "placeholder" => '',
289 );
290 } else {
291 $field_data = $WMVC->field_m->get_fields_data($field_id);
292
293 if($field_data) {
294 if(wmvc_show_data('search_type', $el_field_data, '') == 'slider_range') {
295 $field = array(
296 "idfield" => wmvc_show_data('idfield', $field_data),
297 "field_type" => 'SLIDER_RANGE',
298 "field_label" =>wmvc_show_data('field_label', $field_data),
299 "prefix" => wmvc_show_data('prefix', $field_data),
300 "suffix" => wmvc_show_data('suffix', $field_data),
301 "value_min" => wmvc_show_data('value_min', $el_field_data),
302 "value_max" => wmvc_show_data('value_max', $el_field_data),
303 "values_list" => wmvc_show_data('values_list', $field_data),
304 "placeholder" => wmvc_show_data('placeholder', $field_data)
305 );
306 } else {
307 $field = array(
308 "idfield" => wmvc_show_data('idfield', $field_data),
309 "field_type" => wmvc_show_data('field_type', $field_data),
310 "field_label" =>wmvc_show_data('field_label', $field_data),
311 "prefix" => wmvc_show_data('prefix', $field_data),
312 "suffix" => wmvc_show_data('suffix', $field_data),
313 "values_list" => wmvc_show_data('values_list', $field_data),
314 "placeholder" => wmvc_show_data('placeholder', $field_data)
315 );
316 }
317 }
318 }
319
320 if(wmvc_show_data('field_placeholder', $el_field_data, false)) {
321 $field['placeholder'] = wmvc_show_data('field_placeholder', $el_field_data, false);
322 }
323
324 if(wmvc_show_data('search_type_tree_hide', $el_field_data, false)) {
325 $field['search_type_tree_hide'] = wmvc_show_data('search_type_tree_hide', $el_field_data, false);
326 }
327
328 /* if field not detected or remove from fields list, skip field in search */
329 if(empty($field)) continue;
330
331 /* add from user fields data */
332 $field['field_id'] = wmvc_show_data('idfield', $field);
333 $field['class'] = wmvc_show_data('field_css_class', $el_field_data);
334 $field['query_type'] = wmvc_show_data('search_type', $el_field_data);
335 $field['columns'] = wmvc_show_data('field_columns_number', $el_field_data);
336
337
338 $field_data = array();
339 $field_data ['field_data'] = $field;
340 $field_data ['predefinedfields_query'] = $predefinedfields_query;
341
342 if(in_array(wmvc_show_data('field_type', $field),array('SECTION'))) {
343 continue;
344 }
345
346 $field_suffix = strtoupper(wmvc_show_data('search_type_tree', $el_field_data,''));
347
348 $field_view_path = WPDIRECTORYKIT_PATH.'application/views/search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)).$field_suffix.'.php';
349 if(file_exists($field_view_path))
350 {
351 $output .= $WMVC->view('search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)).$field_suffix, $field_data, FALSE);
352 }
353 else
354 {
355 /* show missing view file of field, only if print enable */
356 if($print)
357 $output .= __('Missing VIEW file:', 'wpdirectorykit').' '.esc_html($subfolder).(wmvc_show_data('field_type', $field)).$field_suffix.'.php';
358 }
359 }
360
361 if($print){
362 echo $output;
363 return FALSE;
364 }
365
366 return $output;
367 }
368 }
369
370
371 function &wdk_get_instance()
372 {
373 global $Winter_MVC_WDK;
374
375 if(empty($Winter_MVC_WDK))
376 {
377 $Winter_MVC_WDK = new MVC_Loader(plugin_dir_path( __FILE__ ).'../../');
378
379 $Winter_MVC_WDK->load_helper('basic');
380 }
381
382 return $Winter_MVC_WDK;
383 }
384
385 function wdk_prepare_search_query_GET($columns = array(), $model_name = NULL, $external_columns = array(), $custom_parameters = array(), $skip_postget = FALSE)
386 {
387
388 global $Winter_MVC_WDK;
389 $WMVC = &$Winter_MVC_WDK;
390 $wdk_bookings_joinded = false;
391 static $available_fields_listings = NULL;
392 static $available_fields_static = array();
393 static $list_fields_static = NULL;
394
395 /* add if missing columns */
396 if(!in_array('post_id', $columns)) {
397 $columns[] = $Winter_MVC_WDK->db->prefix.'wdk_listings.post_id';
398 }
399
400 $_GET_clone = array();
401
402 if(!$skip_postget)
403 $_GET_clone = array_merge($_GET, $_POST);
404
405 if(isset($_GET_clone['order_by']) && $_GET_clone['order_by'] =='undefined') {
406 unset($_GET_clone['order_by']);
407 }
408
409 if(isset($custom_parameters['order_by'])) {
410
411 if(isset($_GET_clone['order_by']) && !empty($_GET_clone['order_by'])) {
412 $_GET_clone['order_by'] = $custom_parameters['order_by'].', '.$_GET_clone['order_by'];
413 } else {
414 $_GET_clone['order_by'] = $custom_parameters['order_by'];
415 }
416
417 unset($custom_parameters['order_by']);
418 }
419
420
421 if(!empty($custom_parameters))
422 $_GET_clone = array_merge($_GET_clone, $custom_parameters);
423
424 $WMVC->model('listing_m');
425 $WMVC->model('field_m');
426 $WMVC->model('listingfield_m');
427
428 $smart_search = '';
429 if(isset($_GET_clone['search']))
430 $smart_search = sanitize_text_field($_GET_clone['search']);
431
432 if(isset($_GET_clone['field_search']))
433 $smart_search = sanitize_text_field($_GET_clone['field_search']);
434
435 if(!isset($available_fields_static[$model_name]))
436 {
437 $available_fields = $WMVC->$model_name->get_available_fields();
438
439 $available_fields_static[$model_name] = $available_fields;
440 }
441 else
442 {
443 $available_fields = $available_fields_static[$model_name];
444 }
445
446 if($available_fields_listings === NULL)
447 $available_fields_listings = $WMVC->listingfield_m->get_available_fields();
448
449 /* Пet column names from wdk_listings_fields and add to allow search +
450 in _GET_clone replace field_#id to field_id_TYPE*/
451
452 if($list_fields_static === NULL)
453 {
454 $WMVC->db->where(array('field_type !='=> 'SECTION'));
455 $list_fields = $WMVC->field_m->get();
456 $list_fields_static = $list_fields;
457 }
458 else
459 {
460 $list_fields = $list_fields_static;
461 }
462
463
464 foreach($list_fields as $field_data) {
465
466 $field_id = wmvc_show_data('idfield',$field_data);
467 $field_type = wmvc_show_data('field_type',$field_data);
468 $column_name ='field_'.$field_id.'_'.$field_type;
469 if(!isset($available_fields_listings[$column_name])) continue;
470
471 if(isset($_GET_clone['field_'.$field_id])) {
472
473 if($field_type == 'DROPDOWNMULTIPLE') {
474 $_GET_clone['field_'.$field_id.'_'.$field_type] = $_GET_clone['field_'.$field_id];
475 } else {
476 $_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);
477 }
478 }
479
480 if(isset($_GET_clone['field_'.$field_id.'_max'])) {
481 $_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);
482 }
483 if(isset($_GET_clone['field_'.$field_id.'_min'])) {
484 $_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);
485 }
486 if(isset($_GET_clone['field_'.$field_id.'_exactly'])) {
487 $_GET_clone['field_'.$field_id.'_'.$field_type.'_exactly'] = sanitize_text_field($_GET_clone['field_'.$field_id.'_exactly']);
488 }
489
490 $columns[] = $column_name;
491 $columns[] = $column_name.'_max';
492 $columns[] = $column_name.'_min';
493 $columns[] = $column_name.'_exactly';
494 $external_columns[] = $column_name;
495 $external_columns[] = $column_name.'_max';
496 $external_columns[] = $column_name.'_min';
497 $external_columns[] = $column_name.'_exactly';
498 }
499
500 if(isset($_GET_clone['search_agents_ids'])) {
501 $column_name ='agents_ids';
502 $_GET_clone[$column_name] = $_GET_clone['search_agents_ids'];
503 $columns[] = $column_name;
504 $external_columns[] = $column_name;
505 }
506
507 if(isset($_GET_clone['search_user_editor_ids'])) {
508 $column_name ='user_editor_ids';
509 $_GET_clone[$column_name] = $_GET_clone['search_user_editor_ids'];
510 $columns[] = $column_name;
511 $external_columns[] = $column_name;
512 }
513
514 if(isset($_GET_clone['search_location'])) {
515 $column_name ='location_id';
516 $_GET_clone[$column_name] = $_GET_clone['search_location'];
517 $columns[] = $column_name;
518 $external_columns[] = $column_name;
519 }
520
521 if(isset($_GET_clone['search_category'])) {
522 $column_name ='category_id';
523 $_GET_clone[$column_name] = $_GET_clone['search_category'];
524 $columns[] = $column_name;
525 $external_columns[] = $column_name;
526 }
527
528 if(isset($_GET_clone['search_gps'])) {
529 $column_name ='gps';
530 $_GET_clone[$column_name] = $_GET_clone['search_gps'];
531 $columns[] = $column_name;
532 $external_columns[] = $column_name;
533 }
534
535 if(isset($_GET_clone['field_address'])) {
536 $column_name ='address';
537 $_GET_clone[$column_name] = $_GET_clone['field_address'];
538 $columns[] = $column_name;
539 $external_columns[] = $column_name;
540 }
541
542 if(isset($_GET_clone['field_post_id'])) {
543 $column_name ='ID_exactly';
544 $_GET_clone[$column_name] = intval($_GET_clone['field_post_id']);
545 $columns[] = $column_name;
546 $external_columns[] = $column_name;
547 }
548
549 if(isset($_GET_clone['field_post_date'])) {
550 $column_name ='post_DATE';
551 $_GET_clone[$column_name] = ($_GET_clone['field_post_date']);
552 $columns[] = $column_name;
553 $external_columns[] = $column_name;
554 }
555
556 if(isset($_GET_clone['field_post_date_min'])) {
557 $column_name ='post_DATE_min';
558 $_GET_clone[$column_name] = ($_GET_clone['field_post_date_min']);
559 $columns[] = $column_name;
560 $external_columns[] = $column_name;
561 }
562
563 if(isset($_GET_clone['field_post_date_max'])) {
564 $column_name ='post_DATE_max';
565 $_GET_clone[$column_name] = ($_GET_clone['field_post_date_max']);
566 $columns[] = $column_name;
567 $external_columns[] = $column_name;
568 }
569
570 if (function_exists('run_wdk_bookings') && isset($_GET_clone['field_booking_date_from'])) {
571 $column_name ='field_booking_date_from';
572 $_GET_clone[$column_name] = $_GET_clone['field_booking_date_from'];
573 $columns[] = $column_name;
574 $external_columns[] = $column_name;
575 }
576
577 if (function_exists('run_wdk_bookings') && isset($_GET_clone['field_booking_date_to'])) {
578 $column_name ='field_booking_date_to';
579 $_GET_clone[$column_name] = $_GET_clone['field_booking_date_to'];
580 $columns[] = $column_name;
581 $external_columns[] = $column_name;
582 }
583
584 if (function_exists('run_wdk_bookings') && isset($_GET_clone['field_booking_guest'])) {
585 $column_name ='field_booking_guest';
586 $_GET_clone[$column_name] = $_GET_clone['field_booking_guest'];
587 $columns[] = $column_name;
588 $external_columns[] = $column_name;
589 }
590
591 if (isset($_GET_clone['search_rank_'.NONCE_KEY])) {
592 $column_name ='`rank`';
593 $_GET_clone[$column_name] = $_GET_clone['search_rank_'.NONCE_KEY];
594 $columns[] = $column_name;
595 $external_columns[] = $column_name;
596 }
597
598 //$table_name = substr($model_name, 0, -2);
599 $columns_original = array();
600 foreach($columns as $key=>$val)
601 {
602 $columns_original[$val] = $val;
603
604 // if column contain also "table_name.*"
605 $splited = explode('.', $val);
606 if(wmvc_count($splited) == 2)
607 $val = $splited[1];
608
609 if(isset($available_fields[$val]))
610 {
611
612 }
613 else
614 {
615 if(!in_array($columns[$key], $external_columns))
616 {
617 unset($columns[$key]);
618 }
619 }
620 }
621
622 if(wmvc_count($_GET_clone) > 0)
623 {
624 unset($_GET_clone['search']);
625 unset($_GET_clone['field_search']);
626
627 // For quick/smart search
628 if(wmvc_count($columns) > 0 && !empty($smart_search))
629 {
630 $gen_q = '';
631 foreach($columns as $key=>$value)
632 {
633
634 if($value == 'field_booking_date_from' || $value == 'field_booking_date_to' || $value == 'agents_ids' || $value == 'gps' || $value == 'is_featured' || $value == 'field_booking_guest') continue;
635
636 if(strpos($value, '_CHECKBOX') !== FALSE) continue;
637
638 // if smart is number, search only im number fields
639
640
641 if(is_intval($smart_search)) {
642 if(strpos($value, '_NUMBER') === FALSE /*&& $value != 'category_id' && $value != 'location_id'*/ && strpos($value, 'post_id') === FALSE ) continue;
643 } else {
644 if($value == 'category_id' || $value == 'location_id' || strpos($value, 'post_id') !== FALSE) continue;
645 }
646
647 if(substr_count($value, 'id') > 0 && is_numeric($smart_search))
648 {
649 $gen_q.="$value = $smart_search OR ";
650 }
651 else if(substr_count($value, 'date') > 0)
652 {
653 $gen_search = $smart_search;
654
655 $gen_q.="$value LIKE '%$gen_search%' OR ";
656 }
657 elseif(substr($value, -8) == '_exactly')
658 {
659
660 }
661 elseif(substr($value, -4) == '_max')
662 {
663
664 }
665 else if(substr($value, -4) == '_min')
666 {
667
668 }
669 else if(strpos($value, '_NUMBER') !== FALSE)
670 {
671 if(is_intval($smart_search)){
672 $gen_search = $smart_search;
673 $gen_q.="$value = $gen_search OR ";
674 }
675 }
676 else
677 {
678 $gen_q.="$value LIKE '%$smart_search%' OR ";
679 }
680 }
681
682 /* location / categories */
683 if(!is_intval($smart_search)) {
684 $gen_q.="location_title LIKE '%$smart_search%' OR ";
685 $gen_q.="category_title LIKE '%$smart_search%' OR ";
686 }
687 /* get address and gps */
688 if(strlen($smart_search) > 5) {
689 $coordinates_center = wdk_get_gps($smart_search);
690 $search_radius = 5;
691 if($coordinates_center && $coordinates_center['lat'] != 0 && is_numeric($search_radius))
692 {
693 $distance_unit = 'km';
694 if(__('km', 'wpdirectorykit') == 'm')
695 {
696 $distance_unit = 'm';
697 }
698
699 // calculate rectangle
700 $rectangle_ne = wdk_getDueCoords($coordinates_center['lat'], $coordinates_center['lng'], 45, $search_radius, $distance_unit);
701 $rectangle_sw = wdk_getDueCoords($coordinates_center['lat'], $coordinates_center['lng'], 225, $search_radius, $distance_unit);
702
703 $gps_ne = explode(', ', $rectangle_ne);
704 $gps_sw = explode(', ', $rectangle_sw);
705
706 $gen_q .="(".$WMVC->db->prefix."wdk_listings.lat < '$gps_ne[0]' AND ".$WMVC->db->prefix."wdk_listings.lat > '$gps_sw[0]' AND
707 ".$WMVC->db->prefix."wdk_listings.lng < '$gps_ne[1]' AND ".$WMVC->db->prefix."wdk_listings.lng > '$gps_sw[1]') OR ";
708
709 }
710 }
711
712 /* detect is gps */
713 if(wdk_is_gps($smart_search)) {
714 $gps = explode(',',$smart_search);
715 $coordinates_center = array('lat'=>trim($gps[0]),'lng'=>trim($gps[1]));
716 $search_radius = 5;
717 if($coordinates_center && $coordinates_center['lat'] != 0 && is_numeric($search_radius))
718 {
719 $distance_unit = 'km';
720 if(__('km', 'wpdirectorykit') == 'm')
721 {
722 $distance_unit = 'm';
723 }
724
725 // calculate rectangle
726 $rectangle_ne = wdk_getDueCoords($coordinates_center['lat'], $coordinates_center['lng'], 45, $search_radius, $distance_unit);
727 $rectangle_sw = wdk_getDueCoords($coordinates_center['lat'], $coordinates_center['lng'], 225, $search_radius, $distance_unit);
728
729 $gps_ne = explode(', ', $rectangle_ne);
730 $gps_sw = explode(', ', $rectangle_sw);
731
732 $gen_q .="(".$WMVC->db->prefix."wdk_listings.lat < '$gps_ne[0]' AND ".$WMVC->db->prefix."wdk_listings.lat > '$gps_sw[0]' AND
733 ".$WMVC->db->prefix."wdk_listings.lng < '$gps_ne[1]' AND ".$WMVC->db->prefix."wdk_listings.lng > '$gps_sw[1]') OR ";
734
735 }
736 }
737
738 $gen_q = substr($gen_q, 0, -4);
739
740 if(!empty($gen_q))
741 $WMVC->db->where("($gen_q)");
742 }
743
744 // For column search
745 if(isset($_GET_clone))
746 {
747 $gen_q = '';
748 foreach($_GET_clone as $key=>$val)
749 {
750 if(!empty($val) && in_array($key, $columns))
751 {
752 $col_name = $key;
753
754 $val = esc_sql($val);
755 //if(isset($key))
756 // $col_name = $key;
757
758 if(strpos($key, 'skip') !== FALSE) continue;
759
760 if(defined( 'WP_DEBUG' ) && WP_DEBUG)
761 if(function_exists('pll_current_language'))
762 {
763 $lang_term_id = pll_current_language('term_id');
764
765 if(is_numeric($lang_term_id))
766 {
767 $WMVC->db->join($WMVC->db->prefix.'term_relationships ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'term_relationships.object_id', NULL, NULL);
768 $WMVC->db->where("({$WMVC->db->prefix}term_relationships.term_taxonomy_id = $lang_term_id)");
769 }
770 }
771
772 if($key == 'field_booking_guest')
773 {
774 if(!$wdk_bookings_joinded){
775 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_price ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_booking_price.post_id', NULL, 'LEFT');
776 $WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id');
777 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_reservation ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_booking_price.post_id', NULL, 'LEFT');
778 $wdk_bookings_joinded = true;
779 $gen_q.= $WMVC->db->prefix.'wdk_booking_price.is_activated = 1 AND ';
780 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_calendar ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_booking_calendar.post_id', NULL, 'LEFT');
781 }
782
783 $gen_q.= $WMVC->db->prefix."wdk_booking_calendar.guests <='".intval($val)."' AND ";
784
785 }
786 elseif($key == 'field_booking_date_from')
787 {
788 if(!$wdk_bookings_joinded){
789 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_price ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_booking_price.post_id', NULL, 'LEFT');
790 $WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id');
791 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_reservation ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_booking_price.post_id', NULL, 'LEFT');
792 $wdk_bookings_joinded = true;
793 $gen_q.= $WMVC->db->prefix.'wdk_booking_price.is_activated = 1 AND ';
794 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_calendar ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_booking_calendar.post_id', NULL, 'LEFT');
795 }
796
797 if(wdk_is_date($val))
798 {
799 if(!get_option('wdk_bookings_is_hours_enabled')) {
800 $gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d');
801 $gen_q.= "DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_price.date_from, '%Y-%m-%d') <= '".$gen_search."' AND ";
802 } else {
803 $gen_search = wdk_normalize_date_db($val);
804 $gen_q.= $WMVC->db->prefix."wdk_booking_price.date_from >'".$gen_search."' AND ";
805 }
806 }
807
808 if( isset($_GET_clone['field_booking_date_from']) && isset($_GET_clone['field_booking_date_to'])) {
809
810 if(!get_option('wdk_bookings_is_hours_enabled')) {
811 $gen_search_from = wdk_normalize_date_db($_GET_clone['field_booking_date_from'], 'Y-m-d H:i:s', 'Y-m-d');
812 $gen_search_to = wdk_normalize_date_db($_GET_clone['field_booking_date_to'], 'Y-m-d H:i:s', 'Y-m-d');
813
814 $gen_q.= $WMVC->listing_m->_table_name.".post_id NOT IN (
815 SELECT post_id
816 FROM ".$WMVC->db->prefix."wdk_booking_reservation
817 WHERE
818 ".$WMVC->db->prefix."wdk_booking_reservation.is_approved = 1
819 AND
820 DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_reservation.date_from, '%Y-%m-%d') < '".$gen_search_to."'
821 AND
822 DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_reservation.date_to, '%Y-%m-%d') > '".$gen_search_from."'
823 ) AND ";
824
825 } else {
826 $gen_search_from = wdk_normalize_date_db($_GET_clone['field_booking_date_from']);
827 $gen_search_to = wdk_normalize_date_db($_GET_clone['field_booking_date_to']);
828
829 $gen_q.= $WMVC->listing_m->_table_name.".post_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 ".$WMVC->db->prefix."wdk_booking_reservation.date_from < '".$gen_search_to."'
836 AND
837 ".$WMVC->db->prefix."wdk_booking_reservation.date_to > '".$gen_search_from."'
838 ) AND ";
839 }
840 }
841
842 }
843 elseif($key == 'field_booking_date_to')
844 {
845 if(!$wdk_bookings_joinded){
846 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_price ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_booking_price.post_id',NULL, 'LEFT');
847 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_reservation ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_booking_price.post_id',NULL, 'LEFT');
848 $wdk_bookings_joinded = true;
849 $gen_q.= $WMVC->db->prefix.'wdk_booking_price.is_activated = 1 AND ';
850 $WMVC->db->join($WMVC->db->prefix.'wdk_booking_calendar ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_booking_calendar.post_id', NULL, 'LEFT');
851 }
852
853 if(wdk_is_date($val))
854 {
855 if(!get_option('wdk_bookings_is_hours_enabled')) {
856 $gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d');
857 $gen_q.= "DATE_FORMAT(".$WMVC->db->prefix."wdk_booking_price.date_to, '%Y-%m-%d') >= '".$gen_search."' AND ";
858 } else {
859 $gen_search = wdk_normalize_date_db($val);
860 $gen_q.= $WMVC->db->prefix."wdk_booking_price.date_to >'".$gen_search."' AND ";
861 }
862 }
863
864 }
865 elseif(substr($key, -8) == '_exactly')
866 {
867 $col_name = substr($key, 0, -8);
868 $gen_q.=$col_name." = '".$val."' AND ";
869 }
870 elseif(substr($key, -4) == '_max')
871 {
872 $col_name = substr($key, 0, -4);
873
874 if(strpos($key, 'NUMBER') !== FALSE) {
875 $gen_q.=$col_name." <= ".intval($val)." AND ";
876 } else if(strpos($key, 'DATE') !== FALSE) {
877 if(wdk_is_date($val))
878 {
879 $gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d H:i:s');
880 $gen_q.=$col_name." <= '".$gen_search."' AND ";
881 }
882 } else {
883 $gen_q.=$col_name." <= '".$val."' AND ";
884 }
885 }
886 else if(substr($key, -4) == '_min')
887 {
888 $col_name = substr($key, 0, -4);
889
890 if(strpos($key, 'NUMBER') !== FALSE) {
891 $gen_q.=$col_name." >= ".intval($val)." AND ";
892 } else if(strpos($key, 'DATE') !== FALSE) {
893 if(wdk_is_date($val))
894 {
895 $gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d H:i:s');
896 $gen_q.=$col_name." >= '".$gen_search."' AND ";
897 }
898 } else {
899 $gen_q.=$col_name." >= '".$val."' AND ";
900 }
901 }
902 elseif(substr_count($key, 'id') > 0 && is_numeric($val) && $key != 'agents_ids' && $key !='user_editor_ids' && $key !='location_id' && $key !='category_id')
903 {
904 // ID is always numeric
905
906 if($key == 'location_id') {
907 /* $gen_q .= "(`location_table`.`parent_path` = ".$val." OR ";
908 $gen_q .= "`location_2`.`parent_path` = ".$val." OR ";*/
909 $gen_q .= "(`location_table`.`parent_id` = ".$val." OR ";
910 //$gen_q .= "`".$WMVC->db->prefix."wdk_locations `.`level_0_id` = ".$val." OR ";
911
912 $gen_q .= $col_name." = ".$val.") AND ";
913 } elseif($key == 'category_id') {
914 $gen_q .= "('parent_path' = ".$val." OR ";
915 $gen_q .= $col_name." = ".$val.") AND ";
916 } else {
917 $gen_q.=$col_name." = ".$val." AND ";
918 }
919 }
920 else if(substr_count($key, '_DATE') > 0)
921 {
922 // DATE VALUES
923
924 $gen_search = $val;
925 if(wdk_is_date($val))
926 {
927 $gen_search = wdk_normalize_date_db($gen_search, 'Y-m-d H:i:s', 'Y-m-d');
928 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
929 }
930 else
931 {
932 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
933
934 }
935 }
936 else if(substr_count($key, 'is_') > 0)
937 {
938 // CHECKBOXES
939
940 if($val=='on')
941 {
942 $gen_search = 1;
943 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
944 }
945 else if($val=='off')
946 {
947 $gen_q.=$col_name." IS NULL AND ";
948 }
949 }
950 elseif($key == 'agents_ids')
951 {
952 if(is_string($val) && strpos($val, ',') !== FALSE){
953 $val =explode(',', $val);
954 } elseif(is_string($val)){
955 $val =array($val);
956 }
957
958 if(is_array($val)) {
959
960 $WMVC->db->join($WMVC->db->prefix.'wdk_listings_users ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_listings_users.post_id', NULL, 'LEFT');
961 $WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id');
962 $sql_search = '';
963 foreach ($val as $v) {
964 if(empty($v)) continue;
965
966 if(!empty($sql_search))
967 $sql_search .= " OR ";
968
969
970 $sql_search .=" ".$WMVC->listing_m->_table_name.".`user_id_editor` = ".intval($v)." OR `".$WMVC->db->prefix."wdk_listings_users`.`user_id` = ".intval($v)." ";
971 }
972
973 if(!empty($sql_search))
974 $gen_q.=" ( ".$sql_search." ) AND ";
975
976 } elseif(is_string($val) && !empty($val)) {
977 $WMVC->db->join($WMVC->db->prefix.'wdk_listings_users ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'wdk_listings_users.post_id', NULL, 'LEFT');
978 $WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id');
979 $sql_search =" ".$WMVC->listing_m->_table_name.".`user_id_editor` = ".intval($val)." OR `".$WMVC->db->prefix."wdk_listings_users`.`user_id` = ".intval($val)." ";
980 $gen_q.=" ( ".$sql_search." ) AND ";
981 }
982 }
983 elseif($key == 'user_editor_ids')
984 {
985
986 if(is_array($val)) {
987
988 $sql_search = '';
989 foreach ($val as $v) {
990 if(empty($v)) continue;
991
992 if(!empty($sql_search))
993 $sql_search .= " OR ";
994
995
996 $sql_search .=" ".$WMVC->listing_m->_table_name.".`user_id_editor` = ".intval($v)." ";
997 }
998
999 if(!empty($sql_search))
1000 $gen_q.=" ( ".$sql_search." ) AND ";
1001
1002 } elseif(is_string($val) && !empty($val)) {
1003 $sql_search =" ".$WMVC->listing_m->_table_name.".`user_id_editor` = ".intval($val)." ";
1004 $gen_q.=" ( ".$sql_search." ) AND ";
1005 }
1006 }
1007 elseif($key == 'location_id')
1008 {
1009 if(empty($val)) continue;
1010
1011 if(is_string($val) && strpos($val, ',') !== FALSE){
1012 $val =explode(',', $val);
1013 } elseif(is_string($val)){
1014 $val =array($val);
1015 }
1016
1017 if(is_array($val)) {
1018
1019 if(false){
1020 $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');
1021 $WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id');
1022 }
1023
1024 $sql_search = '';
1025 foreach ($val as $v) {
1026 if(empty($v) || !is_intval($v)) continue;
1027
1028 if(!empty($sql_search))
1029 $sql_search .= " OR ";
1030
1031 $sql_search .= " ".$WMVC->listing_m->_table_name.".`location_id`=".intval($v)."";
1032 $sql_search .= " OR `location_table`.`parent_id`=".intval($v)."";
1033
1034 $sql_search .= " OR CONCAT(',', location_table.parent_path, ',') LIKE CONCAT('%,', ".intval($v).", ',%')";
1035
1036 /* other locations */
1037 /* multi select */
1038 if(false){
1039 $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).") ";
1040 } elseif(false) {
1041 $sql_search .= " OR ".$WMVC->db->prefix."wdk_listings_locations.location_id=".intval($v)."";
1042 } else {
1043 $sql_search .= " OR ".$WMVC->listing_m->_table_name.".locations_list LIKE '%,".intval($v).",%'";
1044 }
1045
1046 }
1047
1048 if(!empty($sql_search))
1049 $gen_q.=" ( ".$sql_search." ) AND ";
1050 }
1051 }
1052 elseif($key == 'category_id')
1053 {
1054
1055 if(empty($val)) continue;
1056
1057 if(is_string($val) && strpos($val, ',') !== FALSE){
1058 $val =explode(',', $val);
1059 } elseif(is_string($val)){
1060 $val =array($val);
1061 }
1062
1063
1064 if(is_array($val)) {
1065 if(false){
1066 $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');
1067 }
1068
1069 $sql_search = '';
1070 foreach ($val as $v) {
1071 if(empty($v) || !is_intval($v)) continue;
1072
1073 if(!empty($sql_search))
1074 $sql_search .= " OR ";
1075
1076 $sql_search .= " ".$WMVC->db->prefix."wdk_listings.`category_id` = ".intval($v)."";
1077 $sql_search .= " OR `category_table`.`parent_id`=".intval($v)."";
1078 $sql_search .= " OR CONCAT(',', category_table.parent_path, ',') LIKE CONCAT('%,', ".intval($v).", ',%')";
1079
1080 /* other categories */
1081 if(false){
1082 $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).")";
1083 } elseif(false) {
1084 $sql_search .= " OR ".$WMVC->db->prefix."wdk_listings_categories.category_id=".intval($v)."";
1085 } else {
1086 $sql_search .= " OR ".$WMVC->listing_m->_table_name.".categories_list LIKE '%,".intval($v).",%'";
1087 }
1088
1089 }
1090
1091 if(!empty($sql_search))
1092 $gen_q.=" ( ".$sql_search." ) AND ";
1093 }
1094 }
1095 elseif(is_string($val))
1096 {
1097
1098 if(strpos($val, ',') !== FALSE){
1099 $val = explode(',', $val);
1100 }
1101
1102 if(is_array($val)) {
1103 $sql_search = '';
1104 foreach ($val as $v) {
1105 if(empty($v)) continue;
1106
1107 if(!empty($sql_search))
1108 $sql_search .= " OR ";
1109
1110 $sql_search .= $col_name." LIKE '%".$v."%'";
1111
1112 }
1113
1114 if(!empty($sql_search))
1115 $gen_q.=" ( ".$sql_search." ) AND ";
1116 } else {
1117 $gen_q.=$col_name." LIKE '%".$val."%' AND ";
1118 }
1119
1120 }
1121 elseif(is_array($val))
1122 {
1123 $sql_search = '';
1124 foreach ($val as $v) {
1125 if(empty($v)) continue;
1126
1127 if(!empty($sql_search))
1128 $sql_search .= " OR ";
1129
1130 $sql_search .= " ".$col_name." LIKE '%".esc_sql($v)."%' ";
1131 }
1132
1133 if(!empty($sql_search))
1134 $gen_q.=" ( ".$sql_search." ) AND ";
1135 }
1136 }
1137
1138 }
1139
1140 $gen_q = substr($gen_q, 0, -5);
1141
1142 if(!empty($gen_q))
1143 $WMVC->db->where("($gen_q)");
1144 }
1145
1146 // [RECTANGLE SEARCH]
1147 if(isset($_GET_clone['rectangle_ne']) && isset($_GET_clone['rectangle_sw']))
1148 {
1149 if(wdk_is_gps($_GET_clone['rectangle_ne']) && wdk_is_gps($_GET_clone['rectangle_sw'])) {
1150
1151 $gps_ne = explode(',', $_GET_clone['rectangle_ne']);
1152 $gps_sw = explode(',', $_GET_clone['rectangle_sw']);
1153
1154 $WMVC->db->where("(".$WMVC->db->prefix."wdk_listings.lat < '$gps_ne[0]' AND ".$WMVC->db->prefix."wdk_listings.lat > '$gps_sw[0]' AND
1155 ".$WMVC->db->prefix."wdk_listings.lng > '$gps_ne[1]' AND ".$WMVC->db->prefix."wdk_listings.lng < '$gps_sw[1]')");
1156 }
1157 }
1158 // [/RECTANGLE SEARCH]
1159
1160 // order
1161 if(isset($_GET_clone['order_by']))
1162 {
1163 $_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_listings.post_id', $_GET_clone['order_by']);
1164 $WMVC->db->order_by($_GET_clone['order_by']);
1165 }
1166
1167 }
1168 }
1169
1170 function wdk_users_prepare_search_query_GET($columns = array(), $model_name = NULL, $external_columns = array(), $custom_parameters = array(), $skip_postget = FALSE)
1171 {
1172 global $Winter_MVC_WDK;
1173 $WMVC = &$Winter_MVC_WDK;
1174
1175 $_GET_clone = array();
1176
1177 if(!$skip_postget)
1178 $_GET_clone = array_merge($_GET, $_POST);
1179
1180 if(isset($custom_parameters['order_by'])) {
1181
1182 if(isset($_GET_clone['order_by']) && !empty($_GET_clone['order_by'])) {
1183 $_GET_clone['order_by'] = $custom_parameters['order_by'].', '.$_GET_clone['order_by'];
1184 } else {
1185 $_GET_clone['order_by'] = $custom_parameters['order_by'];
1186 }
1187
1188 unset($custom_parameters['order_by']);
1189 }
1190
1191
1192 if(!empty($custom_parameters))
1193 $_GET_clone = array_merge($_GET_clone, $custom_parameters);
1194
1195 $WMVC->model($model_name);
1196
1197 $smart_search = '';
1198 if(isset($_GET_clone['profile_search']))
1199 $smart_search = sanitize_text_field($_GET_clone['profile_search']);
1200
1201 $available_fields = array('user_login','user_nicename','user_email','user_url','display_name');
1202
1203 if(isset($_GET_clone['is_activated'])){
1204 $_GET_clone[$WMVC->$model_name->_table_name.'.is_activated'] = sanitize_text_field($_GET_clone['is_activated']);
1205 unset($_GET_clone['is_activated']);
1206 }
1207
1208 if(isset($_GET_clone['is_approved'])){
1209 $_GET_clone[$WMVC->$model_name->_table_name.'.is_approved'] = sanitize_text_field($_GET_clone['is_approved']);
1210 unset($_GET_clone['is_approved']);
1211 }
1212
1213
1214 //$table_name = substr($model_name, 0, -2);
1215 $columns_original = array();
1216 foreach($columns as $key=>$val)
1217 {
1218 $columns_original[$val] = $val;
1219
1220 // if column contain also "table_name.*"
1221 $splited = explode('.', $val);
1222 if(wmvc_count($splited) == 2)
1223 $val = $splited[1];
1224
1225 if(isset($available_fields[$val]))
1226 {
1227
1228 }
1229 else
1230 {
1231 if(!in_array($columns[$key], $external_columns))
1232 {
1233 unset($columns[$key]);
1234 }
1235 }
1236 }
1237
1238 if(wmvc_count($_GET_clone) > 0)
1239 {
1240 unset($_GET_clone['search']);
1241
1242 // For quick/smart search
1243 if(wmvc_count($columns) > 0 && !empty($smart_search))
1244 {
1245 $gen_q = '';
1246 foreach($columns as $key=>$value)
1247 {
1248
1249 if($value == 'post_type')
1250 {
1251 $value = $WMVC->$model_name->_table_name.'.'.$value;
1252 }
1253
1254 if(substr_count($value, 'id') > 0 && is_numeric($smart_search))
1255 {
1256 $gen_q.="$value = $smart_search OR ";
1257 }
1258 else if(substr_count($value, 'date') > 0)
1259 {
1260 //$gen_search = wmvc_generate_slug($smart_search, ' ');
1261
1262 $gen_search = $smart_search;
1263
1264 $gen_q.="$value LIKE '%$gen_search%' OR ";
1265 }
1266 else
1267 {
1268 $gen_q.="$value LIKE '%$smart_search%' OR ";
1269 }
1270 }
1271 $gen_q = substr($gen_q, 0, -4);
1272
1273 if(!empty($gen_q))
1274 $WMVC->db->where("($gen_q)");
1275 }
1276
1277 // For column search
1278 if(isset($_GET_clone))
1279 {
1280 $gen_q = '';
1281
1282 foreach($_GET_clone as $key=>$val)
1283 {
1284 if(!empty($val) && in_array($key, $columns))
1285 {
1286 $col_name = $key;
1287
1288 if($col_name == 'post_type')
1289 {
1290 $col_name = $WMVC->$model_name->_table_name.'.'.$col_name;
1291 }
1292
1293 //if(isset($key))
1294 // $col_name = $key;
1295
1296 if(strpos($key, 'skip') !== FALSE) continue;
1297
1298 if(substr($key, -8) == '_exactly')
1299 {
1300 $col_name = substr($key, 0, -8);
1301 $gen_q.=$col_name." = '".$val."' AND ";
1302 }
1303 elseif(substr($key, -4) == '_max')
1304 {
1305 $col_name = substr($key, 0, -4);
1306 $gen_q.=$col_name." <= '".$val."' AND ";
1307 }
1308 else if(substr($key, -4) == '_min')
1309 {
1310 $col_name = substr($key, 0, -4);
1311
1312 $gen_q.=$col_name." >= '".$val."' AND ";
1313 }
1314 elseif(substr_count($key, 'id') > 0 && is_numeric($val))
1315 {
1316 // ID is always numeric
1317
1318 $gen_q.=$col_name." = ".$val." AND ";
1319 }
1320 else if(substr_count($key, 'date') > 0)
1321 {
1322 // DATE VALUES
1323
1324 $gen_search = $val;
1325
1326 if(wdk_is_date($val))
1327 {
1328 $gen_search = wdk_normalize_date_db($gen_search);
1329 $gen_q.=$col_name." > '".$gen_search."' AND ";
1330 }
1331 else
1332 {
1333 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
1334 }
1335 }
1336 else if(substr_count($key, 'is_') > 0)
1337 {
1338 // CHECKBOXES
1339
1340 if($val=='on')
1341 {
1342 $gen_search = 1;
1343 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
1344 }
1345 else if($val=='off')
1346 {
1347 $gen_q.=$col_name." IS NULL AND ";
1348 }
1349 }
1350 else
1351 {
1352 $gen_q.=$col_name." LIKE '%".$val."%' AND ";
1353 }
1354 }
1355
1356 }
1357
1358 $gen_q = substr($gen_q, 0, -5);
1359
1360 if(!empty($gen_q))
1361 $WMVC->db->where("($gen_q)");
1362 }
1363
1364 // order
1365 if(isset($_GET_clone['order_by']))
1366 {
1367 $_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_favorite.post_id', $_GET_clone['order_by']);
1368 $WMVC->db->order_by($_GET_clone['order_by']);
1369 }
1370
1371 }
1372 }
1373
1374 function wdk_messages_prepare_search_query_GET($columns = array(), $model_name = NULL, $external_columns = array())
1375 {
1376 global $Winter_MVC_WDK;
1377 $WMVC = &$Winter_MVC_WDK;
1378 $_GET_clone = array_merge($_GET, $_POST);
1379
1380 $_GET_clone = ($_GET_clone);
1381
1382 //$WMVC->model('listing_m');
1383
1384 $smart_search = '';
1385 if(isset($_GET_clone['search']))
1386 $smart_search = sanitize_text_field($_GET_clone['search']);
1387
1388 $available_fields = $WMVC->$model_name->get_available_fields();
1389
1390 /* Пet column names from wdk_package and add to allow search +
1391 in _GET_clone replace field_#id to field_id_TYPE*/
1392 $list_fields = $WMVC->db->list_fields( $WMVC->db->prefix.'wdk_messages');
1393
1394
1395 //$table_name = substr($model_name, 0, -2);
1396 $columns_original = array();
1397 foreach($columns as $key=>$val)
1398 {
1399 $columns_original[$val] = $val;
1400
1401 // if column contain also "table_name.*"
1402 $splited = explode('.', $val);
1403 if(wmvc_count($splited) == 2)
1404 $val = $splited[1];
1405
1406 if(isset($available_fields[$val]))
1407 {
1408
1409 }
1410 else
1411 {
1412 if(!in_array($columns[$key], $external_columns))
1413 {
1414 unset($columns[$key]);
1415 }
1416 }
1417 }
1418
1419 if(wmvc_count($_GET_clone) > 0)
1420 {
1421 unset($_GET_clone['search']);
1422
1423 // For quick/smart search
1424 if(wmvc_count($columns) > 0 && !empty($smart_search))
1425 {
1426 $gen_q = '';
1427 foreach($columns as $key=>$value)
1428 {
1429 if(substr_count($value, 'id') > 0 && is_numeric($smart_search))
1430 {
1431 $gen_q.="$value = $smart_search OR ";
1432 }
1433 else if(substr_count($value, 'date') > 0)
1434 {
1435 //$gen_search = wmvc_generate_slug($smart_search, ' ');
1436
1437 $gen_search = $smart_search;
1438
1439 $gen_q.="$value LIKE '%$gen_search%' OR ";
1440 }
1441 else
1442 {
1443 $gen_q.="$value LIKE '%$smart_search%' OR ";
1444 }
1445 }
1446 $gen_q = substr($gen_q, 0, -4);
1447
1448 if(!empty($gen_q))
1449 $WMVC->db->where("($gen_q)");
1450 }
1451
1452 // For column search
1453 if(isset($_GET_clone))
1454 {
1455 $gen_q = '';
1456
1457 foreach($_GET_clone as $key=>$val)
1458 {
1459 if(!empty($val) && in_array($key, $columns))
1460 {
1461 $col_name = $key;
1462 //if(isset($key))
1463 // $col_name = $key;
1464
1465 if(strpos($key, 'skip') !== FALSE) continue;
1466
1467 if(substr($key, -8) == '_exactly')
1468 {
1469 $col_name = substr($key, 0, -8);
1470 $gen_q.=$col_name." = '".$val."' AND ";
1471 }
1472 elseif(substr($key, -4) == '_max')
1473 {
1474 $col_name = substr($key, 0, -4);
1475 $gen_q.=$col_name." <= '".$val."' AND ";
1476 }
1477 else if(substr($key, -4) == '_min')
1478 {
1479 $col_name = substr($key, 0, -4);
1480
1481 $gen_q.=$col_name." >= '".$val."' AND ";
1482 }
1483 elseif(substr_count($key, 'id') > 0 && is_numeric($val))
1484 {
1485 // ID is always numeric
1486
1487 $gen_q.=$col_name." = ".$val." AND ";
1488 }
1489 else if(substr_count($key, 'date') > 0)
1490 {
1491 // DATE VALUES
1492
1493 $gen_search = $val;
1494
1495 $detect_date = strtotime($gen_search);
1496
1497 if(wdk_payments_is_date($val) && $detect_date > 1000)
1498 {
1499 $gen_search = date('Y-m-d H:i:s', $detect_date);
1500 $gen_q.=$col_name." > '".$gen_search."' AND ";
1501 }
1502 else
1503 {
1504 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
1505 }
1506 }
1507 else if(substr_count($key, 'is_') > 0)
1508 {
1509 // CHECKBOXES
1510
1511 if($val=='on')
1512 {
1513 $gen_search = 1;
1514 $gen_q.=$col_name." LIKE '%".$gen_search."%' AND ";
1515 }
1516 else if($val=='off')
1517 {
1518 $gen_q.=$col_name." IS NULL AND ";
1519 }
1520 }
1521 else
1522 {
1523 $gen_q.=$col_name." LIKE '%".$val."%' AND ";
1524 }
1525 }
1526
1527 }
1528
1529 $gen_q = substr($gen_q, 0, -5);
1530
1531 if(!empty($gen_q))
1532 $WMVC->db->where("($gen_q)");
1533 }
1534
1535 // order
1536 if(isset($_GET_clone['order_by']))
1537 {
1538 $_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_messages.post_id', $_GET_clone['order_by']);
1539 $WMVC->db->order_by($_GET_clone['order_by']);
1540 }
1541
1542 }
1543 }
1544
1545 function wdk_date() {
1546 $date_format = get_option('date_format');
1547 $time_format = get_option('time_format');
1548 $date = date("{$date_format} {$time_format}", current_time('timestamp'));
1549 return $date;
1550 }
1551
1552 if(!function_exists('wdk_placeholder_image_src')) {
1553 function wdk_placeholder_image_src () {
1554 $i = WPDIRECTORYKIT_URL.'public/img/placeholder.jpg';
1555
1556 if(wdk_get_option('wdk_placeholder')) {
1557 $image = wp_get_attachment_image_src(wdk_get_option('wdk_placeholder'), 'full' );
1558 if(!empty($image) && file_exists(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $image[0])))
1559 $i = $image[0];
1560 }
1561
1562 return $i;
1563 }
1564 }
1565
1566
1567 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)
1568 {
1569 $current_page = 1;
1570
1571 if(isset($_GET[$page_var]))
1572 $current_page = intval(wmvc_xss_clean($_GET[$page_var]));
1573
1574 if(!isset($texts['previous_page']))$texts['previous_page'] = 'Previous page';
1575 if(!isset($texts['next_page']))$texts['next_page'] = 'Next page';
1576 if(!isset($texts['first_page']))$texts['first_page'] = '';
1577 if(!isset($texts['last_page']))$texts['last_page'] = '';
1578 if(!isset($texts['items']))$texts['items'] = 'items';
1579
1580 if(empty($current_page))$current_page = 1;
1581
1582 // get url
1583 $url = strtok($_SERVER["REQUEST_URI"], '?');
1584 $qs_parameters = wmvc_xss_clean( $_GET );
1585 unset($qs_parameters[$page_var]);
1586 $qs_part = http_build_query($qs_parameters);
1587 $url = wdk_url_suffix($url, $qs_part);
1588
1589 // total pages
1590 $total_pages = intval($total_items/$per_page+0.99);
1591
1592 if($current_page == 1) {
1593 $limit_items = $limit_items * 2;
1594 }
1595
1596 if($current_page == $total_pages) {
1597 $limit_items = $limit_items * 2;
1598 }
1599
1600 $output = '<nav class="wdk-pagination navigation pagination" role="navigation">';
1601 if($enable_count){
1602 $output.= '<span class="displaying-num">'.$total_items.' '.$texts['items'].'</span>';
1603 }
1604
1605 $output .= '<div class="nav-links">';
1606
1607 if($enable_latest_first && $current_page-1 > 0)
1608 $output.= '<a class="next page-numbers" href="'.esc_url($url).'#results"><span class="screen-reader-text">'.esc_html($texts['first_page']).'</span><span aria-hidden="true">«</span></a>';
1609
1610 if ($current_page-1 > 0) {
1611
1612 $output.= '<a class="next page-numbers" 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>';
1613 } elseif($enable_compact)
1614 {
1615 $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>';
1616 }
1617
1618 if (!$enable_compact) {
1619 for ($i = 1 ; $i <= $total_pages; $i++) {
1620 $class = ($current_page == $i) ? "active" : "";
1621 if(($current_page-$limit_items) <= $i && ($current_page+$limit_items) >= $i) {
1622 if (($current_page == $i)) {
1623 $output.= '<span aria-current="page" class="page-numbers current">'.$i.'</span>';
1624 } else {
1625 $output.= '<a class="page-numbers" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($i))).'#results">'.esc_attr($i).'</a>';
1626 }
1627 }
1628 }
1629 } else {
1630 $output.= '<span class="wdk_pages_range">'.$current_page.' '.esc_html__('of','wpdirectorykit').' '.$total_pages.'</span>';
1631 }
1632
1633 if($current_page+1 <= $total_pages)
1634 {
1635 $output.= '<a class="next page-numbers" 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>';
1636 }
1637 elseif($enable_compact)
1638 {
1639 $output.= '<a class="next page-numbers disabled" href=""><span class="screen-reader-text">'.esc_html($texts['next_page']).'</span><span aria-hidden="true">›</span></a>';
1640 }
1641
1642 if($enable_latest_first && $current_page+1 <= $total_pages)
1643 $output.= '<a class="next page-numbers" 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>';
1644
1645
1646 $output.= '</div>';
1647 $output.= '</nav>';
1648
1649 return $output;
1650 }
1651
1652 function wdk_viewe($content) {
1653 // @codingStandardsIgnoreStart
1654 echo wp_kses_post($content); // WPCS: XSS ok, sanitization ok.
1655 // @codingStandardsIgnoreEnd
1656 }
1657
1658
1659 if(!function_exists('wdk_search_fields_toggle')){
1660 function wdk_search_fields_toggle ($class_add = NULL){
1661 static $wdk_visible_filters = 0;
1662 global $wdk_visible_filters_limit;
1663 global $wdk_button_search_defined;
1664 global $wdk_enable_search_fields_toggle;
1665 global $wdk_activate_more;
1666
1667 if(!$wdk_enable_search_fields_toggle) return false;
1668
1669 global $wdk_search_fields_toggle_reset;
1670 if($wdk_search_fields_toggle_reset) {
1671 $wdk_visible_filters = 0;
1672 $wdk_search_fields_toggle_reset = false;
1673 }
1674
1675 $wdk_visible_filters++;
1676
1677 if($wdk_activate_more || (!empty($wdk_visible_filters_limit) && !$wdk_button_search_defined && $wdk_visible_filters == $wdk_visible_filters_limit)){
1678 $wdk_button_search_defined=true;
1679 $wdk_activate_more = false;
1680
1681 global $wdk_text_search_button;
1682 if(empty($wdk_text_search_button))
1683 $wdk_text_search_button = esc_html__('Search','wpdirectorykit');
1684
1685 global $wdk_text_reset_button;
1686 if(empty($wdk_text_reset_button))
1687 $wdk_text_reset_button = esc_html__('Reset','wpdirectorykit');
1688
1689 global $wdk_text_more_button;
1690 if(empty($wdk_text_more_button))
1691 $wdk_text_more_button = esc_html__('More','wpdirectorykit');
1692
1693 $form_closed = 'display: none;';
1694 if(isset($_GET['wdk_search_additional_opened']) && wmvc_xss_clean($_GET['wdk_search_additional_opened']) == 1) {
1695 $form_closed = '';
1696 }
1697
1698 ?>
1699 <div class="wdk-col wdk-col-btns">
1700 <div class="wdk-field wdk-field-btn">
1701 <div class="wdk-field-group wdk-field-group-additional">
1702 <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>
1703 <input type='checkbox' style="display: none !important" value='1' name='wdk_search_additional_opened' />
1704 </div>
1705 <div class="wdk-field-group wdk-field-group-reset">
1706 <button 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>
1707 </div>
1708 <div class="wdk-field-group wdk-field-group-search">
1709 <button 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>
1710
1711 <?php if(function_exists('run_wdk_save_search') && get_option('wdk_save_search_show_on_searchform')):?>
1712 <div class="section-widget-control right">
1713 <a class="wdk-c-btn wdk-c-edit wdk-save-search-button" href="#" data-url="<?php echo esc_url(admin_url('admin-ajax.php')); ?>" title="<?php echo esc_attr_e('Save Search', 'selio'); ?>" target="_blank">
1714 <i class="fas fa-save" aria-hidden="true"></i>
1715 <i class="fa fa-spinner fa-spin fa-ajax-indicator"></i>
1716 </a>
1717 </div>
1718 <?php endif;?>
1719 </div>
1720 </div>
1721 </div>
1722 <div id='wdk-form-additional' class="wdk-col" style="<?php echo esc_attr($form_closed) ;?>">
1723 <div class="wdk-row">
1724 <?php
1725 }
1726 }
1727 }
1728
1729
1730 /*
1731 * @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
1732 *
1733 */
1734 if ( ! function_exists('wdk_treefield_option'))
1735 {
1736 function wdk_treefield_option($name = '', $table=NULL, $selected = NULL,
1737 $column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE, $sql_where='', $hide_fields = '')
1738 {
1739 $WMVC = &wdk_get_instance();
1740
1741 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
1742
1743 static $counter = 0;
1744
1745 $model_name = $table;
1746 if($table == 'calendar_listing_m')
1747 $model_name = 'listing_m';
1748
1749 $table_name = str_replace('_m', '', $table);
1750
1751 $attribute_id = 'id'.$table_name;
1752
1753 if($table_name == 'icons_list') {
1754
1755 } else {
1756 $WMVC->model($model_name);
1757 $attribute_id = $WMVC ->$model_name->_primary_key;
1758 $selected = (int) $selected;
1759 }
1760
1761 if(empty($selected))
1762 $selected='';
1763
1764 $form = '<input name="'.$name.'" value="'.$selected.'" class="wdk-hidden" type="text" id="wdktreeelem'.$counter.'" readonly/>';
1765
1766 $skip_id = '';
1767 //load javascript library
1768 if($counter==0)
1769 {
1770 wp_enqueue_script('wdk-treefield');
1771 wp_enqueue_style('wdk-treefield');
1772 }
1773 ?>
1774 <script>
1775 jQuery(document).ready(function($) {
1776 $('#wdktreeelem<?php echo esc_js($counter);?>:not(.init)').wdkTreefield({
1777 ajax_url: '<?php echo admin_url('admin-ajax.php'); ?>',
1778 ajax_param: {
1779 "page": 'wdk_frontendajax',
1780 "function": 'treefieldid',
1781 "action": 'wdk_public_action',
1782 "table": '<?php echo esc_js($table); ?>',
1783 "filter_ids": '<?php echo esc_js($filter_ids); ?>',
1784 "start_id": '<?php if(!empty($filter_ids)) esc_js($selected); else echo ""; ?>',
1785 "empty_value": '<?php echo esc_js($empty_value); ?>',
1786 "user_check": '<?php echo esc_js($user_check); ?>',
1787 "sql_where": '<?php echo esc_js($sql_where); ?>',
1788 "hide_fields": '<?php echo esc_js($hide_fields); ?>'
1789 },
1790 attribute_id: '<?php echo esc_js($attribute_id); ?>',
1791 language_id: '<?php echo esc_js($language_id); ?>',
1792 attribute_value: '<?php echo esc_js($column); ?>',
1793 skip_id: '<?php echo esc_js($skip_id); ?>',
1794 empty_value: ' - ',
1795 text_search: '<?php esc_html_e('Search term', 'wpdirectorykit');?>',
1796 text_no_results: '<?php esc_html_e('No results found', 'wpdirectorykit');?>',
1797 callback_selected: function(key) {
1798 $('#wdktreeelem<?php echo esc_js($counter);?>').trigger("change");
1799 }
1800 }).addClass('init');
1801 });
1802 </script>
1803 <?php
1804 $counter++;
1805 return $form;
1806 }
1807 }
1808
1809 /*
1810 * @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
1811 *
1812 */
1813 if ( ! function_exists('wdk_treefield_option_checkboxes'))
1814 {
1815 function wdk_treefield_option_checkboxes($name = '', $table=NULL, $selected = NULL,
1816 $column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE, $sql_where='', $hide_fields = '')
1817 {
1818 $WMVC = &wdk_get_instance();
1819
1820 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
1821
1822 static $counter = 0;
1823
1824 $model_name = $table;
1825
1826 $table_name = str_replace('_m', '', $table);
1827
1828 $attribute_id = 'id'.$table_name;
1829
1830
1831 $WMVC->model($model_name);
1832 $attribute_id = $WMVC ->$model_name->_primary_key;
1833
1834 $values = '';
1835 if(!empty($selected)){
1836 $ids = array();
1837 if(is_string($selected) && strpos($selected, ',') !== FALSE){
1838 $val_selected = explode(',', $selected);
1839 } elseif($selected){
1840 $val_selected = array($selected);
1841 }
1842
1843 foreach($val_selected as $selected_item) {
1844 if(!empty($selected_item) && is_intval($selected_item)) {
1845 $ids [] = $selected_item;
1846 }
1847 }
1848
1849 /* where in */
1850 if(!empty($ids)){
1851 $WMVC->db->select($WMVC->$table->_table_name.'.*');
1852 $WMVC->db->where($WMVC->$table->_table_name.'.'.$WMVC->$table->_primary_key.' IN(' . implode(',', $ids) . ')', null, false);
1853 $WMVC->db->order_by('FIELD('.$WMVC->$table->_table_name.'.'.$WMVC->$table->_primary_key.', '. implode(',', $ids) . ')');
1854
1855 $results = $WMVC->$table->get();
1856 foreach ($results as $item) {
1857 if($item) {
1858 $values .= wmvc_show_data($column, $item, false, TRUE, TRUE).',';
1859 }
1860 }
1861 $values = substr($values,0,-1);
1862
1863 if(strlen($values)>23) {
1864 $values = substr($values,0,20).'...';
1865 }
1866 }
1867 }
1868
1869 if(empty($values)) {
1870 $values = $empty_value;
1871 }
1872
1873 $form = '<input name="'.$name.'" value="'.esc_html($selected).'" data-placehoder="'.esc_html($values).'" class="wdk-hidden" type="text" id="wdktreeelem_checkbox'.$counter.'" readonly/>';
1874
1875 $skip_id = '';
1876 //load javascript library
1877 if($counter==0)
1878 {
1879 wp_enqueue_script('wdk-treefield');
1880 wp_enqueue_style('wdk-treefield');
1881 }
1882 ?>
1883 <script>
1884 jQuery(document).ready(function($) {
1885 $('#wdktreeelem_checkbox<?php echo esc_js($counter);?>:not(.init)').wdkTreefieldCheckboxes({
1886 ajax_url: '<?php echo admin_url('admin-ajax.php'); ?>',
1887 ajax_param: {
1888 "page": 'wdk_frontendajax',
1889 "function": 'treefieldid_checkboxes',
1890 "action": 'wdk_public_action',
1891 "table": '<?php echo esc_js($table); ?>',
1892 "filter_ids": '<?php echo esc_js($filter_ids); ?>',
1893 "empty_value": '<?php echo esc_js($empty_value); ?>',
1894 "user_check": '<?php echo esc_js($user_check); ?>',
1895 "hide_fields": '<?php echo esc_js($hide_fields); ?>',
1896 },
1897 selected: '<?php echo esc_js($selected); ?>',
1898 attribute_id: '<?php echo esc_js($attribute_id); ?>',
1899 language_id: '<?php echo esc_js($language_id); ?>',
1900 attribute_value: '<?php echo esc_js($column); ?>',
1901 skip_id: '<?php echo esc_js($skip_id); ?>',
1902 empty_value: ' - ',
1903 text_search: '<?php esc_html_e('Search term', 'wpdirectorykit');?>',
1904 text_no_results: '<?php esc_html_e('No results found', 'wpdirectorykit');?>',
1905 callback_selected: function(key) {
1906 $('#wdktreeelem_checkbox<?php echo esc_js($counter);?>').trigger("change");
1907 }
1908 }).addClass('init');
1909 });
1910 </script>
1911 <?php
1912 $counter++;
1913 return $form;
1914 }
1915 }
1916
1917 if ( ! function_exists('wdk_filter_decimal'))
1918 {
1919 function wdk_filter_decimal($string = '')
1920 {
1921 if(substr($string, -3, 3) === ".00") {
1922 return substr($string, 0, -3);
1923 }
1924 if(substr($string, -3, 1) === "." && substr($string, -1, 1) === "0") {
1925 return substr($string, 0, -1);
1926 }
1927
1928 return $string;
1929 }
1930 }
1931
1932 if ( ! function_exists('wdk_is_date'))
1933 {
1934 function wdk_is_date($date, $format = 'Y-m-d H:i:s')
1935 {
1936
1937 /* check is date on strtotime */
1938 if((bool)strtotime($date)){
1939 return true;
1940 }
1941
1942 /* check is date from argument */
1943 $d = \DateTime::createFromFormat($format, $date);
1944 if($d) {
1945 return true;
1946 }
1947
1948 /* check is date from wp date and time */
1949 $d = \DateTime::createFromFormat(get_option('date_format').' '.get_option('time_format'), $date);
1950 if($d) {
1951 return true;
1952 }
1953
1954 /* check is date from wp date */
1955 $d = \DateTime::createFromFormat(get_option('date_format'), $date);
1956 if($d) {
1957 return true;
1958 }
1959
1960 /* try with default */
1961 if('Y-m-d H:i:s' != $format) {
1962 $d = \DateTime::createFromFormat('Y-m-d H:i:s', $date);
1963 if($d) {
1964 return true;
1965 }
1966
1967 $d = \DateTime::createFromFormat('Y-m-d', $date);
1968 if($d) {
1969 return true;
1970 }
1971 }
1972
1973 /* issue with pm/am inside date, example bug format like "2023 01 19 pm8:06" => 'Y n j ag:i' */
1974 $format = get_option('date_format').' '.get_option('time_format');
1975 if(strpos($format, 'a') !== FALSE) {
1976 $format = str_replace('a', '',$format).' a';
1977 if(strpos($date, 'am') !== FALSE) {
1978 $date = str_replace('am', '',$date).' am';
1979 }
1980 if(strpos($date, 'pm') !== FALSE) {
1981 $date = str_replace('pm', '',$date).' pm';
1982 }
1983 $d = \DateTime::createFromFormat($format, $date);
1984 if($d) {
1985 return true;
1986 }
1987 }
1988
1989 return false;
1990 }
1991 }
1992
1993
1994 if ( ! function_exists('wdk_normalize_date_db'))
1995 {
1996 /**
1997 * Convert date to db format, from wp format
1998 * @param string $date Date in string
1999 * @param string $format Special format
2000 * @param string $format Special format
2001 * @param string $return_format return date format
2002 * @return string date in format Y-m-d H:i:s
2003 */
2004 function wdk_normalize_date_db($date, $format = 'Y-m-d H:i:s', $return_format = 'Y-m-d H:i:s')
2005 {
2006
2007 /* check is date from argument */
2008 $d = \DateTime::createFromFormat($format, $date);
2009 if($d) {
2010 return $d->format($return_format);
2011 }
2012
2013 /* check is date from wp date and time */
2014 $d = \DateTime::createFromFormat(get_option('date_format').' '.get_option('time_format'), $date);
2015 if($d) {
2016 return $d->format($return_format);
2017 }
2018
2019 /* check is date from wp date */
2020 $d = \DateTime::createFromFormat(get_option('date_format'), $date);
2021 if($d) {
2022 return $d->format($return_format);
2023 }
2024
2025 /* try with default */
2026 if('Y-m-d H:i:s' != $format) {
2027 $d = \DateTime::createFromFormat('Y-m-d H:i:s', $date);
2028 if($d) {
2029 return $d->format($return_format);
2030 }
2031
2032 $d = \DateTime::createFromFormat('Y-m-d', $date);
2033 if($d) {
2034 return $d->format($return_format);
2035 }
2036 }
2037
2038 /* issue with pm/am inside date, example bug format like "2023 01 19 pm8:06" => 'Y n j ag:i' */
2039 $format = get_option('date_format').' '.get_option('time_format');
2040 if(strpos($format, 'a') !== FALSE) {
2041 $format = str_replace('a', '',$format).' a';
2042 if(strpos($date, 'am') !== FALSE) {
2043 $date = str_replace('am', '',$date).' am';
2044 }
2045 if(strpos($date, 'pm') !== FALSE) {
2046 $date = str_replace('pm', '',$date).' pm';
2047 }
2048 $d = \DateTime::createFromFormat($format, $date);
2049 if($d) {
2050 return $d->format($return_format);
2051 }
2052 }
2053
2054 /* check is date on strtotime */
2055 if((bool)strtotime($date)){
2056 return date($return_format, strtotime($date));
2057 }
2058
2059 return false;
2060 }
2061 }
2062
2063 if ( ! function_exists('wdk_url_suffix'))
2064 {
2065 function wdk_url_suffix($base_url, $extension_url="")
2066 {
2067 if(substr($base_url, -1) == '?'){
2068 $base_url .='';
2069 } elseif(strpos($base_url,'?') !== FALSE){
2070 $base_url .='&';
2071 } else {
2072 $base_url .='?';
2073 }
2074 return $base_url.$extension_url;
2075 }
2076 }
2077
2078 /**
2079 * Insert an attachment from an URL address.
2080 *
2081 * @param String $url
2082 * @param Int $parent_post_id
2083 * @return Int Attachment ID
2084 */
2085 function wdk_insert_attachment_from_url($url, $parent_post_id = null) {
2086
2087 if( !class_exists( 'WP_Http' ) )
2088 include_once( ABSPATH . WPINC . '/class-http.php' );
2089
2090 $http = new WP_Http();
2091 $response = $http->request( $url );
2092 if( is_wp_error($response) || $response['response']['code'] != 200 ) {
2093 return false;
2094 }
2095
2096 $filename = basename($url);
2097 if(strpos($filename, '?')!==FALSE) {
2098 $filename = substr($filename, 0, strpos($filename, '?'));
2099 }
2100
2101 /* if unsoported extension */
2102 if(in_array(wdk_file_extension($filename), array('php','asp'))){
2103 $data = getimagesizefromstring($response['body']);
2104 if(!$data) return false;
2105 if(empty($data['mime'])) return false;
2106
2107 $filename = time().rand(0000,9999).'.'.wdk_mime2ext($data['mime']);
2108 }
2109 $upload = wp_upload_bits( $filename, null, $response['body'] );
2110
2111 if( !empty( $upload['error'] ) ) {
2112 return false;
2113 }
2114
2115 $file_path = $upload['file'];
2116 $file_name = basename( $file_path );
2117 $file_type = wp_check_filetype( $file_name, null );
2118 $attachment_title = sanitize_file_name( pathinfo( $file_name, PATHINFO_FILENAME ) );
2119 $wp_upload_dir = wp_upload_dir();
2120
2121 $post_info = array(
2122 'guid' => $wp_upload_dir['url'] . '/' . $file_name,
2123 'post_mime_type' => $file_type['type'],
2124 'post_title' => $attachment_title,
2125 'post_content' => '',
2126 'post_status' => 'inherit',
2127 );
2128 // Create the attachment
2129 $attach_id = wp_insert_attachment( $post_info, $file_path, $parent_post_id );
2130
2131 // Include image.php
2132 require_once( ABSPATH . 'wp-admin/includes/image.php' );
2133
2134 // Define attachment metadata
2135 $attach_data = wp_generate_attachment_metadata( $attach_id, $file_path );
2136
2137 // Assign metadata to attachment
2138 wp_update_attachment_metadata( $attach_id, $attach_data );
2139
2140 return $attach_id;
2141
2142 }
2143
2144 if(!function_exists('wdk_jsdateformat')) {
2145 function wdk_jsdateformat($format = '') {
2146 $date_specific = array(
2147 // Day
2148 'd' => 'dd',
2149 'D' => 'D',
2150 'j' => 'd',
2151 'l' => 'DD',
2152 'N' => '',
2153 'S' => '',
2154 'w' => '',
2155 'z' => 'o',
2156 // Week
2157 'W' => '',
2158 // Month
2159 'F' => 'MM',
2160 'm' => 'mm',
2161 'M' => 'M',
2162 'n' => 'm',
2163 't' => '',
2164 // Year
2165 'L' => '',
2166 'o' => '',
2167 'y' => 'y',
2168 'Y' => 'yy',
2169 // Time
2170 'a' => '',
2171 'A' => '',
2172 'B' => '',
2173 'g' => '',
2174 'G' => '',
2175 'h' => '',
2176 'H' => '',
2177 'i' => '',
2178 's' => '',
2179 'u' => ''
2180 );
2181 return str_replace(array_keys($date_specific), array_values($date_specific), $format);
2182 }
2183
2184 }
2185
2186 function wdk_current_url()
2187 {
2188 global $wp;
2189 return add_query_arg( $wp->query_vars, home_url( $wp->request ) );
2190 }
2191
2192 if(!function_exists('wdk_generate_profile_permalink')) {
2193 /**
2194 * Insert user id and return link on user profile page
2195 *
2196 * @return Int user ID
2197 */
2198
2199 function wdk_generate_profile_permalink($profile = array())
2200 {
2201
2202 $profile_slug = '';
2203 if(wmvc_show_data('user_login', $profile, false)){
2204 $profile_slug = wmvc_show_data('user_login', $profile);
2205 if(wmvc_show_data('wdk_slug', $profile))
2206 $profile_slug = wmvc_show_data('wdk_slug', $profile);
2207 } else if(is_intval($profile)){
2208 $profile_data = get_userdata($profile);
2209 if(wmvc_show_data('wdk_slug', $profile, false)){
2210 $profile_slug = wmvc_show_data('wdk_slug', $profile);
2211 }elseif(wmvc_show_data('user_login', $profile_data, false)){
2212 $profile_slug = wmvc_show_data('user_login', $profile_data);
2213 } else {
2214 $profile_slug = $profile;
2215 }
2216 }
2217
2218 $user_profile_page = get_option('wdk_membership_profile_preview_page');
2219 if(!$user_profile_page) {
2220 return '#';
2221 }
2222 // for polylang to detect translated page version
2223 if(function_exists('pll_get_post'))
2224 $user_profile_page = pll_get_post($user_profile_page);
2225
2226 return wdk_url_suffix(get_permalink($user_profile_page), 'slug='. $profile_slug);
2227 }
2228 }
2229
2230 if(!function_exists('wdk_get_profile_page_id')) {
2231 /**
2232 * Insert user id and return link on user profile page
2233 *
2234 * @return Int user ID
2235 */
2236
2237 function wdk_get_profile_page_id()
2238 {
2239 global $wp_query;
2240 if(get_option('wdk_membership_profile_preview_page') && isset($wp_query->post) && get_option('wdk_membership_profile_preview_page') == $wp_query->post->ID) {
2241 if (wmvc_show_data('slug', $_GET, false)) {
2242 if(is_intval(wmvc_show_data('slug', $_GET))) {
2243 return wmvc_show_data('slug', $_GET);
2244 } else {
2245
2246 $args = array(
2247 'meta_key' => 'wdk_slug',
2248 'meta_value' => sanitize_text_field(wmvc_show_data('slug', $_GET)),
2249 'meta_compare' => '='
2250 );
2251 $by_slug_user_detected = get_users($args);
2252
2253 $profile = false;
2254 if(!empty($by_slug_user_detected)) {
2255 $profile = $by_slug_user_detected[0];
2256 } else {
2257 $profile = get_user_by('login',wmvc_show_data('slug', $_GET));
2258 }
2259
2260 return (wmvc_show_data('ID', $profile, false)) ? wmvc_show_data('ID', $profile, false) : false;
2261 }
2262 }
2263 }
2264
2265 return false;
2266 }
2267 }
2268
2269 if(!function_exists('wdk_get_date')) {
2270 /**
2271 * Return date in format
2272 *
2273 */
2274 function wdk_get_date($datetime = NULL, $time = TRUE, $default='timestamp')
2275 {
2276 $init_datetime = $datetime;
2277 if(is_null($datetime))
2278 {
2279 if($default == 'timestamp')
2280 {
2281 $datetime = current_time('timestamp');
2282 }
2283 else
2284 {
2285 return $default;
2286 }
2287 }
2288 else if(!is_numeric($datetime))
2289 {
2290 $datetime = strtotime($datetime);
2291 }
2292
2293 $date_format = get_option('date_format');
2294
2295 $time_format = ($time && strpos($init_datetime, '00:00:00')===FALSE) ? get_option('time_format') : '';
2296
2297 $date = date_i18n("{$date_format} {$time_format}", $datetime);
2298 return $date;
2299 }
2300 }
2301
2302 if(!function_exists('wdk_login_url')) {
2303 /**
2304 * Return date in format
2305 * @param string|url redirect url
2306 * @param string custom_message, showed on login form like alert, visible only on wdk login form
2307 */
2308 function wdk_login_url($url_redirect = '', $custom_message = '')
2309 {
2310 $url = wp_login_url($url_redirect);
2311
2312 if(get_option('wdk_membership_login_page')){
2313 $url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')));
2314 if(!empty($url_redirect)) {
2315 $url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')), 'redirect_to='. urlencode($url_redirect));
2316 }
2317 if(!empty($custom_message)) {
2318 $url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')), 'custom_message='. urlencode($custom_message));
2319 }
2320 }
2321
2322 return trim($url, '?');
2323 }
2324 }
2325
2326 if(!function_exists('wdk_mail')) {
2327 /**
2328 * Return date in format
2329 * @param string|url redirect url
2330 */
2331 function wdk_mail( $email_to, $subject = '', $data = array(), $layout = 'default', $email_from = '', $attachments = array(), $reply_to = '')
2332 {
2333 $WMVC = &wdk_get_instance();
2334
2335 $ret = false;
2336 if(empty($email_from))
2337 $email_from = get_bloginfo('admin_email');
2338
2339 if(empty($subject))
2340 $subject = __("New message", "wpdirectorykit");
2341
2342 $headers = array('Content-Type: text/html; charset=UTF-8');
2343 $headers[] = 'From: "'.get_bloginfo('name').'" <'.$email_from.'>';
2344
2345 if(!empty($reply_to)) {
2346 $headers[] = 'Reply-To: '.$reply_to;
2347 } else {
2348 $headers[] = 'Reply-To: '.$email_from;
2349 }
2350
2351 $data['subject'] = $subject;
2352
2353 $message = $WMVC->view('email/'.$layout, $data, FALSE);
2354 $ret = wp_mail( $email_to, $subject, $message, $headers, $attachments );
2355
2356 return $ret;
2357 }
2358 }
2359
2360 if(!function_exists('wdk_show_data')) {
2361 function wdk_show_data($field_name, &$db_value = NULL, $default = '', $xss_clean = TRUE, $skip_post = FALSE)
2362 {
2363 if(!$skip_post && isset($_POST[$field_name]))
2364 {
2365 if($xss_clean === FALSE)
2366 return stripslashes($_POST[$field_name]);
2367
2368 return wmvc_xss_clean(stripslashes($_POST[$field_name]));
2369 }
2370
2371
2372 if(is_array($db_value))
2373 {
2374 if(isset($db_value[$field_name]))
2375 {
2376 if($xss_clean === FALSE)
2377 return $db_value[$field_name];
2378
2379 return wmvc_xss_clean($db_value[$field_name]);
2380 }
2381 else
2382 {
2383 return $default;
2384 }
2385 }
2386
2387 if(is_object($db_value))
2388 {
2389 if(isset($db_value->$field_name))
2390 {
2391 if($xss_clean === FALSE)
2392 return $db_value->$field_name;
2393
2394 return wmvc_xss_clean($db_value->$field_name);
2395 }
2396 else
2397 {
2398 return $default;
2399 }
2400 }
2401
2402 if(!empty($db_value))
2403 {
2404 if($xss_clean === FALSE)
2405 return $db_value;
2406
2407 return wmvc_xss_clean($db_value);
2408 }
2409
2410 if($xss_clean === FALSE)
2411 return $default;
2412
2413 return wmvc_xss_clean($default);
2414 }
2415 }
2416
2417
2418 if (!function_exists('wdk_input_checked'))
2419 {
2420 function wdk_input_checked($field_id, $db_data, $value = 1)
2421 {
2422
2423 if(wmvc_show_data($field_id, $db_data, false) && wmvc_show_data($field_id, $db_data) == $value)
2424 {
2425 return 'checked';
2426 }
2427
2428 return '';
2429 }
2430 }
2431
2432 function wdk_upload_file($field_name, $file_id)
2433 {
2434 static $media_element_counter = 0;
2435
2436 $media_element_counter++;
2437
2438 $img_field = $field_name.'_'.$media_element_counter;
2439
2440 wp_register_script( 'wpmediaelement_file', WPDIRECTORYKIT_URL . 'admin/js/jquery.wpmediaelement_file.js', array( 'jquery' ), false, false );
2441 wp_enqueue_script( 'wpmediaelement_file' );
2442 wp_enqueue_media();
2443
2444 ?>
2445 <div id="<?php echo esc_attr($field_name); ?>meta-box-id" class="postbox-upload">
2446 <?php
2447 // Get WordPress' media upload URL
2448 $upload_link = '#';
2449
2450 // Get the file src
2451
2452 // Get the file src
2453 $your_file_src = get_attached_file(intval( $file_id));
2454
2455 // For convenience, see if the array is valid
2456 $you_have_file = false;
2457 if($your_file_src)
2458 $you_have_file = basename($your_file_src);
2459
2460 ?>
2461
2462 <!-- Your file container, which can be manipulated with js -->
2463 <div class="custom-img-container">
2464 <?php if ( $you_have_file ) : ?>
2465 <?php echo esc_html($you_have_file); ?>
2466 <?php endif; ?>
2467 </div>
2468
2469 <?php //if(sw_user_in_role('administrator')): ?>
2470 <!-- Your add & remove file links -->
2471 <p class="hide-if-no-js">
2472 <a class="upload-custom-img <?php if ( $you_have_file ) { echo 'hidden'; } ?>"
2473 href="<?php echo esc_url($upload_link) ?>">
2474 <?php echo esc_html__('Select file','wmvc_win') ?>
2475 </a>
2476 <a class="delete-custom-img <?php if ( ! $you_have_file ) { echo 'hidden'; } ?>"
2477 href="#">
2478 <?php echo esc_html__('Remove file','wmvc_win') ?>
2479 </a>
2480 </p>
2481 <?php //endif; ?>
2482
2483 <!-- A hidden input to set and post the chosen file id -->
2484 <input class="logo_file_id" type="hidden" id="<?php echo esc_html($field_name); ?>" name="<?php echo esc_html($field_name); ?>" value="<?php echo esc_html($file_id); ?>" />
2485 </div>
2486
2487 <?php
2488 $custom_js ='';
2489 $custom_js .=" jQuery(function($) {
2490 if( typeof jQuery.fn.wpMediaElementFile == 'function')
2491 $('#".esc_js($field_name)."meta-box-id.postbox-upload').wpMediaElementFile();
2492 });";
2493
2494 echo "<script>".$custom_js."</script>";
2495
2496 ?>
2497
2498 <?php
2499 }
2500
2501 if ( ! function_exists('wdk_file_extension'))
2502 {
2503 function wdk_file_extension($filepath)
2504 {
2505
2506 /* filters */
2507 if(strpos($filepath, '?') !== FALSE) {
2508 $filepath = $filepath;
2509 $filepath = substr($filepath, 0,strpos($filepath, '?'));
2510 }
2511 if(strpos($filepath, '#') !== FALSE) {
2512 $filepath = $filepath;
2513 $filepath = substr($filepath, 0,strpos($filepath, '#'));
2514 }
2515
2516 return substr($filepath, strrpos($filepath, '.')+1);
2517 }
2518 }
2519
2520 if ( ! function_exists('wdk_file_extension_type'))
2521 {
2522 /**
2523 * Get image type based on extension
2524 *
2525 * @param string $filepath string path(url) to file with extension
2526 * @return string type of file (image,video,docs)
2527 */
2528 function wdk_file_extension_type($filepath = NULL)
2529 {
2530
2531 if(in_array(wdk_file_extension($filepath),array('jpg','jpeg','bmp','png','webp'))) {
2532 return 'image';
2533 }
2534 if(in_array(wdk_file_extension($filepath),array('mp4','mov','flv','mkv','avi','webm'))) {
2535 return 'video';
2536 }
2537
2538 return 'docs';
2539 }
2540 }
2541
2542 function wdk_upload_multi_files($field_name, $image_ids='', $texts = array())
2543 {
2544 static $media_element_counter = 0;
2545
2546 if(!isset($texts['file_select']))$texts['file_select'] = esc_html__('Select file','wmvc_win');
2547 if(!isset($texts['file_remove']))$texts['file_remove'] = esc_html__('Remove file','wmvc_win');
2548
2549 $media_element_counter++;
2550
2551 $img_field = $field_name.'_'.$media_element_counter;
2552
2553 wp_register_script( 'wpmediaelement_file', WPDIRECTORYKIT_URL . 'admin/js/jquery.wpmediaelement_file.js', array( 'jquery' ), false, false );
2554 wp_enqueue_script( 'wpmediaelement_file' );
2555 wp_enqueue_media();
2556
2557 wp_enqueue_script( 'wpmediamultiple' );
2558 wp_enqueue_script( 'jquery-ui-mouse' );
2559 wp_enqueue_media();
2560
2561 ?>
2562 <div id="<?php echo esc_attr($field_name); ?>meta-box-id" class="postbox-upload-multiple">
2563 <?php
2564 // Get WordPress' media upload URL
2565 $upload_link = '#';
2566
2567
2568 // Get the image src
2569
2570 $your_img_src = array();
2571
2572 foreach(explode(',', $image_ids) as $image_id)
2573 {
2574 if(is_numeric($image_id)){
2575 $src = wp_get_attachment_url( $image_id, 'full' );
2576 if(!in_array(wdk_file_extension($src),array('jpg','jpeg','bmp','png','webp'))) {
2577 if(file_exists(WPDIRECTORYKIT_PATH.'/public/img/filetype/'.wdk_file_extension($src).'.png')) {
2578 $src = WPDIRECTORYKIT_URL.'public/img/filetype/'.wdk_file_extension($src).'.png';
2579 } else {
2580 $src = WPDIRECTORYKIT_URL.'public/img/filetype/_blank.png';
2581 }
2582 }
2583 $your_img_src[$image_id] = $src;
2584 }
2585 }
2586
2587 // For convenience, see if the array is valid
2588 $you_have_img = count($your_img_src) > 0;
2589 ?>
2590
2591 <!-- Your image container, which can be manipulated with js -->
2592 <div class="custom-img-container winter_mvc-media">
2593 <?php if($you_have_img)foreach($your_img_src as $image_id => $img_src) : ?>
2594 <div class="winter_mvc-media-card" data-media-id="<?php echo esc_attr($image_id);?>">
2595 <img src="<?php echo esc_html($img_src); ?>" style="object-fit: contain;" alt="<?php echo esc_attr__('thumb', 'wmvc_win');?>" style="max-width:100%;" class="thumbnail"/>
2596 <a href="#" class="remove"></a>
2597 </div>
2598 <?php endforeach; ?>
2599 </div>
2600 <br style="clear:both;" />
2601
2602 <?php //if(sw_user_in_role('administrator')): ?>
2603 <!-- Your add & remove image links -->
2604 <p class="hide-if-no-js">
2605 <a class="button button-primary upload-custom-img <?php if ( $you_have_img ) { echo ''; } ?>"
2606 href="<?php echo esc_url($upload_link) ?>">
2607 <?php echo esc_html($texts['file_select']) ?>
2608 </a>
2609 <a class="button button-secondary delete-custom-img <?php if ( ! $you_have_img ) { echo 'hidden'; } ?>"
2610 href="#">
2611 <?php echo esc_html($texts['file_remove']) ?>
2612 </a>
2613 </p>
2614 <?php //endif; ?>
2615
2616 <!-- A hidden input to set and post the chosen image id -->
2617 <input class="logo_image_id" type="hidden" id="<?php echo esc_html(esc_html($field_name)); ?>" name="<?php echo esc_html($field_name); ?>" value="<?php echo esc_html($image_ids); ?>" />
2618 </div>
2619 <?php
2620 $custom_js ='';
2621 $custom_js .=" jQuery(function($) {
2622 if( typeof jQuery.fn.wpMediaMultiple == 'function')
2623 $('#".esc_js($field_name)."meta-box-id.postbox-upload-multiple').wpMediaMultiple({
2624 frame: {
2625 title: '".esc_js(__('Select or Upload Media Of Your Chosen Persuasion','wpdirectorykit'))."',
2626 button: '".esc_js(__('Use this media','wpdirectorykit'))."',
2627 }
2628 });
2629 /* order */
2630 var re_order = function(media_element){
2631 var list_media = '';
2632 media_element.find('.winter_mvc-media-card').each(function(){
2633 if(list_media !='')
2634 list_media +=',';
2635
2636 list_media += $(this).attr('data-media-id');
2637 })
2638 media_element.closest('.postbox-upload-multiple').find('.logo_image_id').val(list_media);
2639 }
2640 /* Sort table */
2641 $( '.winter_mvc-media' ).sortable({
2642 update: function(event, ui) {
2643 re_order($(this));
2644 }
2645 });
2646 /* remove media */
2647 $( '.winter_mvc-media' ).find('.winter_mvc-media-card .remove').on('click', function(e){
2648 e.preventDefault();
2649 var media = $(this).closest('.winter_mvc-media')
2650 $(this).closest('.winter_mvc-media-card').remove();
2651 re_order(media)
2652 })
2653 });
2654 ";
2655
2656 echo "<script>".$custom_js."</script>";
2657
2658 ?>
2659
2660 <?php
2661 }
2662
2663
2664 if(!function_exists('wdk_access_check')) {
2665 /**
2666 * Generate listing card html
2667 *
2668 * @param array $listing The listing data.
2669 * @param array $settings The settings.
2670 * @param bool $json_output Encode for json, default false
2671 * @param string $html Html for sprintf(), where
2672 * %1$s - content
2673 * @return string
2674 */
2675 function wdk_access_check($model_name, $item_id, $user_id=NULL, $method='edit') {
2676
2677 if(!empty($item_id) && !is_numeric($item_id))
2678 exit('Issue with ID');
2679
2680 if (in_array($model_name, array('reviews_m','reviews_type_m','reviews_option_m','reviews_data_m'))) {
2681 global $Winter_MVC_wdk_reviews;
2682 $WMVC = $Winter_MVC_wdk_reviews;
2683 }elseif(in_array($model_name,array('package_m','payment_m'))) {
2684 global $Winter_MVC_wdk_payments;
2685 $WMVC = $Winter_MVC_wdk_payments;
2686 }elseif(in_array($model_name,array('favorite_m','favoritecategory_m'))) {
2687 global $Winter_MVC_wdk_favorites;
2688 $WMVC = $Winter_MVC_wdk_favorites;
2689 }elseif(in_array($model_name,array('currency_m'))) {
2690 global $Winter_MVC_wdk_currency;
2691 $WMVC = $Winter_MVC_wdk_currency;
2692 }elseif(in_array($model_name,array('calendar_m','price_m','reservation_m'))) {
2693 global $Winter_MVC_wdk_bookings;
2694 $WMVC = $Winter_MVC_wdk_bookings;
2695 }elseif(in_array($model_name,array('save_search_m'))) {
2696 global $Winter_MVC_wdk_save_search;
2697 $WMVC = $Winter_MVC_wdk_save_search;
2698 }elseif(in_array($model_name,array('messageschat_m'))) {
2699 global $Winter_MVC_wdk_messages_chat;
2700 $WMVC = $Winter_MVC_wdk_messages_chat;
2701 } else {
2702 $WMVC = &wdk_get_instance();
2703 }
2704
2705 if(empty($user_id))
2706 $user_id = get_current_user_id();
2707
2708 if(wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) {
2709 return true;
2710 }
2711
2712 if(substr($model_name,-2,2) == '_m')
2713 {
2714 // its model
2715 $WMVC->model($model_name);
2716
2717 if(empty($item_id) || $WMVC->$model_name->is_related($item_id, $user_id, $method))
2718 {
2719 // User is related
2720 return true;
2721 }
2722 else
2723 {
2724 //echo $CI->db->last_query();
2725 exit('Access denied ROLES RELATED');
2726 }
2727 }
2728 else
2729 {
2730 return true;
2731 }
2732
2733 exit('Access denied ROLES');
2734
2735 }
2736 }
2737
2738 if ( ! function_exists('wdk_recaptcha_field'))
2739 {
2740 function wdk_recaptcha_field($is_compact=false, $style="", $load_script=true)
2741 {
2742 static $counter = 0;
2743 static $recaptcha_array = array();
2744
2745 if(get_option('wdk_recaptcha_site_key') !== FALSE && get_option('wdk_recaptcha_secret_key') !== NULL)
2746 {
2747 if($load_script && $counter===0)
2748 {
2749 echo "<script src='https://www.google.com/recaptcha/api.js?onload=CaptchaCallback&amp;render=explicit'></script>";
2750 }
2751 $counter++;
2752
2753 $compact_tag='';
2754 $size_tag='';
2755 if($is_compact)
2756 {
2757 $compact_tag='data-size="compact"';
2758 $size_tag='compact';
2759 }
2760
2761 $recaptcha_array[$counter] = array('size'=>$size_tag);
2762
2763 echo '<div id="recaptcha_called_'.$counter.'" class="g-recaptcha" style="'.$style.'" '.$compact_tag.' data-sitekey="'.get_option('wdk_recaptcha_site_key').'"></div>';
2764 ?>
2765
2766 <script>
2767 <?php if($counter===1)echo 'var ';?>CaptchaCallback = function(){
2768 <?php for($j=1;$j<=$counter;$j++): ?>
2769 grecaptcha.render(document.getElementById('recaptcha_called_<?php echo $j;?>'), {'size' : '<?php echo $recaptcha_array[$j]['size']; ?>', 'sitekey' : '<?php echo get_option('wdk_recaptcha_site_key'); ?>'});
2770 <?php endfor; ?>
2771 };
2772 </script>
2773
2774 <?php
2775 }
2776 }
2777 }
2778
2779 function is_wdk_valid_recaptcha()
2780 {
2781 if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){
2782 //your site secret key
2783 if(wdk_valid_recaptcha_curl($_POST['g-recaptcha-response']))
2784 {
2785 return TRUE;
2786 }
2787 }
2788 return FALSE;
2789 }
2790
2791 function wdk_valid_recaptcha_curl($g_recaptcha_response='') {
2792 $url = 'https://www.google.com/recaptcha/api/siteverify';
2793 $args = array(
2794 'timeout' => 200,
2795 'blocking' => true,
2796 'headers' => array(),
2797 'body' => array(
2798 'secret' => get_option('wdk_recaptcha_secret_key'),
2799 'response' => $g_recaptcha_response,
2800 'remoteip' => sanitize_textarea_field($_SERVER['REMOTE_ADDR'])
2801 ),
2802 'cookies' => array()
2803 );
2804 $response = wp_remote_post( $url, $args );
2805
2806 if ( is_wp_error( $response ) ) {
2807 /*$error_message = $response->get_error_message();*/
2808 return true;
2809 } else {
2810 $response = json_decode($response['body']);
2811 return $response->success;
2812 }
2813 }
2814
2815 if(!function_exists('wdk_get_option')) {
2816 /**
2817 * Cached and get wp options
2818 *
2819 * @param string option Option key
2820 * @return string alt or title
2821 */
2822
2823 function wdk_get_option($option_key = '') {
2824 return get_option($option_key);
2825 if(isset($options[$option_key])) {
2826 return $options[$option_key];
2827 }
2828
2829 $options[$option_key] = get_option($option_key);
2830
2831 return $options[$option_key];
2832 }
2833 }
2834
2835 if(!function_exists('wdk_server_current_url')) {
2836 /**
2837 * Get current url basic on $_SERVER, exists function wdk_current_url(), on some urls have issue on listing preview page
2838 *
2839 * @return string url
2840 */
2841
2842 function wdk_server_current_url()
2843 {
2844 return (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
2845 }
2846 }
2847
2848
2849 if(!function_exists('wdk_filter_date_decimal')) {
2850 /**
2851 * Filter 00:00:00 from date
2852 *
2853 * @param string
2854 * @return string date without 00:00:00
2855 */
2856
2857 function wdk_filter_date_decimal($data)
2858 {
2859 return str_replace(' 00:00:00','', $data);
2860 }
2861 }
2862
2863 function wdk_get_post()
2864 {
2865 $post = array();
2866
2867 foreach($_POST as $key => $val)
2868 {
2869 if(is_array($val))
2870 {
2871 return wdk_clean($_POST);
2872 }
2873 else
2874 {
2875 if(strpos($val, '<iframe') === 0)
2876 $val = str_replace("'",'"', $val);
2877
2878 $post[sanitize_text_field($key)] = wp_kses_post($val);
2879 }
2880 }
2881
2882 return $post;
2883 }
2884
2885
2886 function wdk_get_get()
2887 {
2888 $log_array = array();
2889
2890 foreach($_GET as $key => $val)
2891 {
2892 if(is_array($val))
2893 {
2894 return wdk_clean($_POST);
2895 }
2896 else
2897 {
2898 $log_array[sanitize_text_field($key)] = wp_kses_post($val);
2899 }
2900 }
2901
2902 return $log_array;
2903 }
2904
2905 function wdk_clean($array)
2906 {
2907 $arr_cleaned = array();
2908 foreach($array as $key=>$val)
2909 {
2910 if(is_array($val))
2911 {
2912 $arr_cleaned[sanitize_text_field($key)] = wdk_clean($val);
2913 }
2914 else
2915 {
2916 $arr_cleaned[sanitize_text_field($key)] = wp_kses_post($val);
2917 }
2918
2919 }
2920
2921 //dump($arr_cleaned);
2922
2923 return $arr_cleaned;
2924 }
2925
2926 /*
2927 <select class="form-control" name="<?php echo 'control_operator_'.$i_fieldnum; ?>">
2928 <option value="CONTAINS">CONTAINS</option>
2929 <option value="NOT_CONTAINS">NOT_CONTAINS</option>
2930 </select>
2931 */
2932 function wdk_select_multi_option($field_name, $options = array(), $selected = NULL, $extra=NULL, $empty_text = NULL, $empty_val = '')
2933 {
2934 $output = '<select name="'.$field_name.'" '.$extra.' multiple="multiple">';
2935
2936 if(!is_null($empty_text))
2937 $output.= '<option value="'.esc_attr($empty_val).'">'.esc_html($empty_text).'</option>';
2938
2939 if(is_array($options) && count($options) > 0)
2940 foreach($options as $key=>$val)
2941 {
2942 $output.= '<option value="'.$key.'" '.($selected==$key&&$selected != ''?'selected':'').'>'.$val.'</option>';
2943 }
2944
2945 $output.= '</select>';
2946
2947 return $output;
2948 }
2949
2950
2951 if ( ! function_exists('wdk_treefield_select_ajax'))
2952 {
2953 /**
2954 * Return select2 ajax
2955 *
2956 * @param string option Option key
2957 * @return string alt or title
2958 */
2959 function wdk_treefield_select_ajax($name = '', $table=NULL, $selected = NULL,
2960 $column_print = 'category_title', $column_key = 'idcategory', $language_id=NULL, $empty_value='', $filter_ids = '', $attr = '')
2961 {
2962 $WMVC = &wdk_get_instance();
2963 $WMVC->model($table);
2964
2965 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
2966
2967 static $counter = 0;
2968 $form = '<select data-ajax="'.admin_url('admin-ajax.php').'" name="'.$name.'" data-table="'.$table.'" '.$attr.' data-placeholder="'.$empty_value.'" class="form-control select_ajax" id="wdk_select2_'.$counter.'" multiple="">';
2969
2970
2971 if(false)
2972 if( $column_key == 'idcategory') {
2973 $form .= '<option selected="selected" value="">'.esc_html__('Select Category', 'wpdirectorykit').'</option>';
2974 } else {
2975 $form .= '<option selected="selected" value="">'.esc_html__('Select Location', 'wpdirectorykit').'</option>';
2976 }
2977
2978 if($selected) {
2979 if(is_array($selected)) {
2980
2981 $ids = array();
2982 foreach($selected as $selected_item) {
2983 if(!empty($selected_item)) {
2984 $ids [] = $selected_item;
2985 }
2986 }
2987
2988 /* where in */
2989 if(!empty($ids)){
2990 $WMVC->db->select($WMVC->$table->_table_name.'.*');
2991 $WMVC->db->where($WMVC->$table->_table_name.'.'.$column_key.' IN(' . implode(',', $ids) . ')', null, false);
2992 $WMVC->db->order_by('FIELD('.$WMVC->$table->_table_name.'.'.$column_key.', '. implode(',', $ids) . ')');
2993
2994 $results = $WMVC->$table->get();
2995 foreach ($results as $item) {
2996 if($item)
2997 $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)).'</option>';
2998 }
2999 }
3000 } elseif(is_intval($selected)) {
3001 $db_item = $WMVC->$table->get($selected, TRUE);
3002 if($db_item)
3003 $form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data($column_key, $db_item, false, TRUE, TRUE)).'">'.esc_attr(wmvc_show_data($column_print, $db_item, false, TRUE, TRUE)).'</option>';
3004 }
3005 } else {
3006 //$form .= '<option value="" selected="selected">'.esc_html__('Not selected', 'wpdirectorykit').'</option>';
3007 }
3008 $form .= '</select>';
3009
3010 //load javascript library
3011 if($counter==0)
3012 {
3013 wp_enqueue_script('select2');
3014 wp_enqueue_script('wdk-select2');
3015 wp_enqueue_style('select2');
3016 }
3017 ?>
3018 <?php
3019 $counter++;
3020 return $form;
3021 }
3022 }
3023
3024 if ( ! function_exists('wdk_user_select_ajax'))
3025 {
3026 /**
3027 * Return select2 ajax
3028 *
3029 * @param string option Option key
3030 * @return string alt or title
3031 */
3032 function wdk_user_select_ajax($name = '', $selected = NULL, $empty_value='', $filter_ids = '')
3033 {
3034 $WMVC = &wdk_get_instance();
3035
3036 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
3037
3038 static $counter = 0;
3039 $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="">';
3040 if($selected) {
3041 if(is_array($selected)) {
3042 /* where in */
3043 foreach ($selected as $item) {
3044 $user_data = get_userdata($item);
3045 if($user_data)
3046 $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>';
3047 }
3048 } elseif(is_intval($selected)) {
3049 $user_data = get_userdata($selected);
3050 if($user_data)
3051 $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>';
3052 }
3053 } else {
3054 //$form .= '<option value="" selected="selected">'.esc_html__('Not selected', 'wpdirectorykit').'</option>';
3055 }
3056 $form .= '</select>';
3057
3058 //load javascript library
3059 if($counter==0)
3060 {
3061 wp_enqueue_script('select2');
3062 wp_enqueue_script('wdk-select2');
3063 wp_enqueue_style('select2');
3064 }
3065 ?>
3066 <?php
3067 $counter++;
3068 return $form;
3069 }
3070 }
3071
3072
3073 /*
3074 <select class="form-control" name="<?php echo 'control_operator_'.$i_fieldnum; ?>">
3075 <option value="CONTAINS">CONTAINS</option>
3076 <option value="NOT_CONTAINS">NOT_CONTAINS</option>
3077 </select>
3078 */
3079 function wdk_select_option_multiple($field_name, $options = array(), $selected = array(), $extra=NULL, $empty_text = NULL, $empty_val = '')
3080 {
3081 $output = '<select name="'.$field_name.'" '.$extra.' multiple >';
3082
3083 if(!is_null($empty_text))
3084 $output.= '<option value="'.esc_attr($empty_val).'">'.esc_html($empty_text).'</option>';
3085
3086 if(is_array($options) && count($options) > 0)
3087 foreach($options as $key=>$val)
3088 {
3089 if(is_string($selected)) {
3090 $output.= '<option value="'.$key.'" '.(($selected == $key)?'selected="selected"':'').'>'.$val.'</option>';
3091 } else if(is_array($selected)){
3092 $output.= '<option value="'.$key.'" '.((in_array($key, $selected) === TRUE)?'selected="selected"':'').'>'.$val.'</option>';
3093 }
3094 }
3095
3096 $output.= '</select>';
3097
3098 return $output;
3099 }
3100
3101
3102
3103 if ( ! function_exists('wdk_convert_date_format_js'))
3104 {
3105 /**
3106 * Convert date format for support in js
3107 * From: https://wordpress.org/support/article/formatting-date-and-time/
3108 * To: https://momentjscom.readthedocs.io/en/latest/moment/04-displaying/01-format/
3109 *
3110 * @param string php date format Option key
3111 * @return string js date format
3112 */
3113 function wdk_convert_date_format_js($date_format)
3114 {
3115 $replaced = array(
3116 'D'=>'ddd',
3117 'j'=>'D',
3118 'd'=>'DD',
3119 'l'=>'dddd',
3120 'F'=>'MMMM',
3121 'Y'=>'YYYY',
3122 'S'=>'Do',
3123 'm'=>'MM',
3124 'n'=>'MM',
3125 'F'=>'MMMM',
3126 'M'=>'MMM',
3127 'Y'=>'YYYY',
3128 'y'=>'YY',
3129 'a'=>'a',
3130 'A'=>'A',
3131 'h'=>'hh',
3132 'G'=>'H',
3133 'H'=>'HH',
3134 'g'=>'h',
3135 'i'=>'mm',
3136 's'=>'ss',
3137 'T'=>'zz',
3138 'c'=>'',
3139 'r'=>'llll',
3140 'u'=>'x',
3141 );
3142
3143 $replaced_from = array_keys($replaced);
3144 $date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format);
3145 return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format);
3146 }
3147 }
3148
3149 if ( ! function_exists('wdk_convert_date_format_jquery'))
3150 {
3151 /**
3152 * Convert date format for support in js
3153 * From: https://wordpress.org/support/article/formatting-date-and-time/
3154 * To: https://api.jqueryui.com/datepicker/
3155 *
3156 * @param string php date format Option key
3157 * @return string js date format
3158 */
3159 function wdk_convert_date_format_jquery($date_format)
3160 {
3161 $replaced = array(
3162 'D'=>'D',
3163 'd'=>'dd',
3164 'j'=>'d',
3165 'l'=>'DD',
3166 'Y'=>'yy',
3167 'S'=>'d',
3168 'm'=>'mm',
3169 'n'=>'m',
3170 'M'=>'m',
3171 'F'=>'MM',
3172 'y'=>'y',
3173 'a'=>'',
3174 'A'=>'',
3175 'h'=>'',
3176 'G'=>'',
3177 'H'=>'',
3178 'g'=>'',
3179 'i'=>'',
3180 's'=>'',
3181 'T'=>'',
3182 'c'=>'ISO_8601',
3183 'r'=>'RFC_2822',
3184 'u'=>'@',
3185 ':'=>'',
3186 );
3187
3188 $replaced_from = array_keys($replaced);
3189 $date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format);
3190 return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format);
3191 }
3192 }
3193
3194 if ( ! function_exists('wdk_convert_date_format_jquery'))
3195 {
3196 /**
3197 * Convert date format for support in js
3198 * From: https://wordpress.org/support/article/formatting-date-and-time/
3199 * To: https://api.jqueryui.com/datepicker/
3200 *
3201 * @param string php date format Option key
3202 * @return string js date format
3203 */
3204 function wdk_convert_date_format_jquery($date_format)
3205 {
3206 $replaced = array(
3207 'D'=>'D',
3208 'd'=>'dd',
3209 'j'=>'d',
3210 'l'=>'DD',
3211 'Y'=>'yy',
3212 'S'=>'d',
3213 'm'=>'mm',
3214 'n'=>'m',
3215 'M'=>'m',
3216 'F'=>'MM',
3217 'y'=>'y',
3218 'a'=>'',
3219 'A'=>'',
3220 'h'=>'',
3221 'G'=>'',
3222 'H'=>'',
3223 'g'=>'',
3224 'i'=>'',
3225 's'=>'',
3226 'T'=>'',
3227 'c'=>'ISO_8601',
3228 'r'=>'RFC_2822',
3229 'u'=>'@',
3230 ':'=>'',
3231 );
3232
3233 $replaced_from = array_keys($replaced);
3234 $date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format);
3235 return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format);
3236 }
3237 }
3238
3239 if ( ! function_exists('wdk_get_gps'))
3240 {
3241
3242 /**
3243 * Get Latitude/Longitude/Altitude based on an address
3244 * @param string $address The address for converting into coordinates
3245 * @return array An array containing Latitude/Longitude/Altitude data
3246 */
3247 function wdk_get_gps($address = '')
3248 {
3249
3250 $address_key = 'cached_address_gps';
3251
3252 static $results = array();
3253
3254 if(empty($results)) {
3255 $gps_option = wdk_get_option($address_key, $results);
3256 if($gps_option)
3257 $results = $gps_option;
3258 }
3259
3260 $address = str_replace(' ','+',$address);
3261
3262 if(!isset($results[$address])) {
3263 $results[$address] = NULL;
3264 $url = 'https://nominatim.openstreetmap.org/search?format=json&q=' . $address;
3265 $request = wp_remote_get( $url );
3266 $response = '';
3267
3268 // request failed
3269 if ( is_wp_error( $request ) ) {
3270 $response = $request;
3271 }
3272 $code = (int) wp_remote_retrieve_response_code( $request );
3273 // make sure the fetch was successful
3274 if (empty($response) && $code == 200 ) {
3275 $response = wp_remote_retrieve_body( $request );
3276 // Decode the json
3277 $resp = json_decode( $response, true );
3278
3279 if(!empty($resp) && isset($resp[0]) && isset($resp[0]['lat']) && isset($resp[0]['lon'])) {
3280 $results[$address] = array('lat' => $resp[0]['lat'], 'lng' => $resp[0]['lon'], 'alt' => 0);
3281
3282 return $results[$address];
3283 }
3284 }
3285 } else {
3286 return $results[$address];
3287 }
3288 return false;
3289 }
3290 }
3291
3292 if ( ! function_exists('wdk_get_gps_google'))
3293 {
3294
3295 /**
3296 * Get Latitude/Longitude/Altitude based on an address from Google Api
3297 * @param string $address The address for converting into coordinates
3298 * @param string $api_key Custom google API Key
3299 *
3300 * @return array An array containing Latitude/Longitude/Altitude data
3301 */
3302 function wdk_get_gps_google($address = '', $api_key = NULL)
3303 {
3304 static $results = array();
3305
3306 if ( empty( $api_key ) ) {
3307 $api_key = wdk_get_option('wdk_geo_google_api_key');
3308 }
3309
3310 $address = str_replace(' ','+',$address);
3311
3312 if(!isset($results[$address])) {
3313 $results[$address] = NULL;
3314 $url = 'https://maps.googleapis.com/maps/api/geocode/json?address='.trim($address).'&key='.$api_key;
3315 $request = wp_remote_get( $url );
3316 $response = '';
3317
3318 // request failed
3319 if ( is_wp_error( $request ) ) {
3320 $response = $request;
3321 }
3322 $code = (int) wp_remote_retrieve_response_code( $request );
3323
3324 // make sure the fetch was successful
3325 if (empty($response) && $code == 200 ) {
3326 $response = wp_remote_retrieve_body( $request );
3327 // Decode the json
3328 $resp = json_decode( $response, true );
3329 $status = $resp['status'];
3330
3331 //if request status is successful
3332 if($status == "OK"){
3333 //get address from json data
3334 $lat = $resp['results'][0]['geometry']['location']['lat'];
3335 $lng = $resp['results'][0]['geometry']['location']['lng'];
3336
3337 $results[$address] = array('lat' => $lat , 'lng' => $lng, 'alt' => 0);
3338 return $results[$address];
3339 }
3340 }
3341 } else {
3342 return $results[$address];
3343 }
3344
3345 return false;
3346 }
3347 }
3348
3349
3350 if ( ! function_exists('wdk_getDueCoords'))
3351 {
3352 // Modified from:
3353 // http://www.sitepoint.com/forums/showthread.php?656315-adding-distance-gps-coordinates-get-bounding-box
3354 /**
3355 * bearing is 0 = north, 180 = south, 90 = east, 270 = west
3356 *
3357 */
3358 function wdk_getDueCoords($latitude, $longitude, $bearing, $distance, $distance_unit = "km", $return_as_array = FALSE) {
3359
3360 if ($distance_unit == "m") {
3361 // Distance is in miles.
3362 $radius = 3963.1676;
3363 }
3364 else {
3365 // distance is in km.
3366 $radius = 6378.1;
3367 }
3368
3369 // New latitude in degrees.
3370 $new_latitude = rad2deg(asin(sin(deg2rad($latitude)) * cos($distance / $radius) + cos(deg2rad($latitude)) * sin($distance / $radius) * cos(deg2rad($bearing))));
3371
3372 // New longitude in degrees.
3373 $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))));
3374
3375 if ($return_as_array) {
3376 // Assign new latitude and longitude to an array to be returned to the caller.
3377 $coord = array();
3378 $coord['lat'] = $new_latitude;
3379 $coord['lng'] = $new_longitude;
3380 }
3381 else {
3382 $coord = $new_latitude . ", " . $new_longitude;
3383 }
3384
3385 return $coord;
3386
3387 }
3388 }
3389
3390 if ( ! function_exists('wdk_is_gps'))
3391 {
3392 // Validation gps
3393 /**
3394 * @param string $string_gps gps in string like xx.xxxx,xx.xxxxx
3395 * @return bool
3396 */
3397 function wdk_is_gps($string_gps = '') {
3398 if(preg_match('/^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$/', $string_gps)) {
3399 return true;
3400 }
3401
3402 return false;
3403 }
3404 }
3405
3406
3407 if ( ! function_exists('wdk_is_phone'))
3408 {
3409 // Validation phone
3410 /**
3411 * @param string $value phone in string
3412 * @return bool
3413 */
3414 function wdk_is_phone($value = '') {
3415 if(preg_match("/^[.+]{0,1}[0-9-)(]{0,25}$/", $value)) {
3416 return true;
3417 }
3418
3419 return false;
3420 }
3421 }
3422
3423 if ( ! function_exists('wdk_filter_phone'))
3424 {
3425 // Validation phone
3426 /**
3427 * @param string $value phone in string
3428 * @return bool
3429 */
3430 function wdk_filter_phone($value = '') {
3431 return str_replace(array(' ','-','(',')'),'',$value);
3432 }
3433 }
3434
3435
3436 if ( ! function_exists('wdk_generate_media_field'))
3437 {
3438 // Based on value return video embed, youtube, source video tag
3439 /**
3440 * @param string $value value
3441 * @param string $class help css class
3442 * @return string html or NULL
3443 */
3444 function wdk_generate_media_field($value = '', $class="wdk-image") {
3445 $output = NULL;
3446
3447 if(strpos($value, 'vimeo.com') !== FALSE)
3448 {
3449 $output = wp_oembed_get($value, array("width"=>"800", "height"=>"450"));
3450 $output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output);
3451 }
3452 elseif(strpos($value, 'watch?v=') !== FALSE)
3453 {
3454 $embed_code = substr($value, strpos($value, 'watch?v=')+8);
3455 $output = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455"));
3456 $output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output );
3457 }
3458 elseif(strpos($value, 'youtu.be/') !== FALSE)
3459 {
3460 $embed_code = substr($value, strpos($value, 'youtu.be/')+9);
3461 $output = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455"));
3462 $output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output );
3463 }
3464 elseif(strpos($value, 'youtube.com/embed/') !== FALSE)
3465 {
3466 $embed_code = substr($value, strpos($value, 'youtube.com/embed/')+18);
3467 $output = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455"));
3468 $output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output );
3469 }
3470 elseif(filter_var($value, FILTER_VALIDATE_URL) !== FALSE && preg_match('/\.(mp4|flv|wmw|ogv|webm|ogg)$/i', $value))
3471 {
3472 $output = '<video src="'.$value.'" controls class="'.$class.'"></video> ';
3473 }
3474
3475 return $output;
3476 }
3477 }
3478
3479
3480 if ( ! function_exists('wdk_depend_get_hidden_fields'))
3481 {
3482 // Based on value return video embed, youtube, source video tag
3483 /**
3484 * @param int $tree_id tree_id of category
3485 * @param string $type type, default 'categories'
3486 * @return string string with hidden fields like ,1,2,3,4, or NULL
3487 */
3488 function wdk_depend_get_hidden_fields($tree_id = NULL, $type="categories") {
3489 static $output = array();
3490
3491 if(isset($output[$tree_id])) {
3492 return $output[$tree_id];
3493 }
3494 if(empty($tree_id)) {
3495 return NULL;
3496 } else {
3497 $output[$tree_id] = false;
3498
3499 global $Winter_MVC_WDK;
3500 $Winter_MVC_WDK->model('dependfields_m');
3501
3502 $depend_fields = $Winter_MVC_WDK->dependfields_m->get_by(array('field_id' => $tree_id,'main_field' => $type), TRUE);
3503
3504 if($depend_fields && !empty($depend_fields->hidden_fields_list)) {
3505 $output[$tree_id] = ','.$depend_fields->hidden_fields_list. ',';
3506 }
3507 return $output[$tree_id];
3508 }
3509
3510 return false;
3511 }
3512 }
3513
3514 if ( ! function_exists('wdk_depend_is_hidden_field'))
3515 {
3516 // Based on value return video embed, youtube, source video tag
3517 /**
3518 * @param int $field_id field_id
3519 * @param int $tree_id id for category
3520 * @param string $type type, default 'categories'
3521 * @return string string with hidden fields like ,1,2,3,4, or NULL
3522 */
3523 function wdk_depend_is_hidden_field($field_id = NULL, $tree_id = NULL, $type="categories") {
3524 $hidden_fields = wdk_depend_get_hidden_fields($tree_id, $type);
3525 if($hidden_fields && strpos($hidden_fields, ','.trim($field_id).',') !== FALSE) {
3526 return true;
3527 }
3528
3529 return false;
3530 }
3531 }
3532
3533
3534 if ( ! function_exists('is_wdk_slug_format'))
3535 {
3536 function is_wdk_slug_format($string)
3537 {
3538 if(empty($string))return FALSE;
3539
3540
3541 if (preg_match("/^[a-z0-9-_]+\$/", $string)) {
3542
3543 return TRUE;
3544 }
3545
3546 return FALSE;
3547 }
3548 }
3549
3550 if ( ! function_exists('wdk_number_format_i18n'))
3551 {
3552 function wdk_number_format_i18n($value)
3553 {
3554 if(empty($value))return NULL;
3555
3556
3557 $value = filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
3558 $value = (float)str_replace(array(","," ",'&nbsp;'), "", $value);
3559
3560 return number_format_i18n($value);
3561 }
3562 }
3563
3564 if ( ! function_exists('wdk_currency_symbol'))
3565 {
3566 /**
3567 * Return currency symbol
3568 *
3569 * @return string currency symbol
3570 */
3571 function wdk_currency_symbol()
3572 {
3573
3574 if(function_exists('get_woocommerce_currency_symbol'))
3575 return get_woocommerce_currency_symbol();
3576
3577 if(wdk_get_option('wdk_default_currency_symbol'))
3578 return wdk_get_option('wdk_default_currency_symbol');
3579
3580 return '$';
3581 }
3582 }
3583
3584 if ( ! function_exists('wdk_generate_path_image'))
3585 {
3586 /**
3587 * Generate path of images
3588 *
3589 * @param string $id or ids of images, separeted by comma
3590 * @param bool $multi multi images, separeted by comma
3591 * @param int $limit limit characters for path
3592 * @param int $limit limit images for path
3593 *
3594 * @return string with path of image or multi images
3595 */
3596 function wdk_generate_path_image($ids = NULL, $multi = FALSE, $limit = 95, $limit_images = 10)
3597 {
3598 $path = '';
3599 if(empty($ids))
3600 return $path;
3601
3602 $image_ids = explode(',', $ids);
3603 $count_images = 0;
3604 if(is_array($image_ids)) {
3605 foreach ($image_ids as $image_id) {
3606 if(is_numeric($image_id))
3607 {
3608
3609 if($count_images>=$limit_images)
3610 break;
3611
3612 $image_path = wp_get_original_image_path($image_id);
3613 if($image_path) {
3614 /* path of image */
3615 $next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path);
3616
3617 /* check length listing_images_path + next image + comma, should be less then $limit */
3618 if(strlen($path.$next_path)<$limit) {
3619
3620 if($multi) {
3621 if(!empty($path))
3622 $path .= ',';
3623 }
3624
3625 $path .= $next_path;
3626 }
3627
3628 if(!$multi)
3629 break;
3630
3631 $count_images++;
3632 }
3633 }
3634 }
3635 }
3636
3637 return $path;
3638 }
3639 }
3640
3641 if ( ! function_exists('wdk_booking_currency_symbol'))
3642 {
3643 /**
3644 * Return currency symbol
3645 *
3646 * @return string currency symbol
3647 */
3648 function wdk_booking_currency_symbol()
3649 {
3650
3651 if(function_exists('get_woocommerce_currency_symbol'))
3652 return get_woocommerce_currency_symbol();
3653
3654 if(wdk_get_option('wdk_default_currency_symbol'))
3655 return wdk_get_option('wdk_default_currency_symbol');
3656
3657 return '$';
3658 }
3659 }
3660
3661 if ( ! function_exists('wdk_generated_cached_row_userdata'))
3662 {
3663 /**
3664 * Return currency symbol
3665 *
3666 * @return string currency symbol
3667 */
3668 function wdk_generated_cached_row_userdata($row)
3669 {
3670 $user_data = array();
3671
3672 $user_data['display_name'] = wmvc_show_data('cacheduser_display_name', $row);
3673 $user_data['user_email'] = wmvc_show_data('cacheduser_email', $row);
3674 $user_data['profile_url'] = wmvc_show_data('cacheduser_profile_url', $row);
3675 $user_data['avatar_url'] = wmvc_show_data('cacheduser_avatar_url', $row);
3676
3677 /* meta */
3678 $user_data['wdk_address'] = wmvc_show_data('cacheduser_wdk_address', $row);
3679 $user_data['wdk_phone'] = wmvc_show_data('cacheduser_wdk_phone', $row);
3680 $user_data['wdk_city'] = wmvc_show_data('cacheduser_wdk_city', $row);
3681 $user_data['wdk_company_name'] = wmvc_show_data('cacheduser_wdk_company_name', $row);
3682 $user_data['wdk_facebook'] = wmvc_show_data('cacheduser_wdk_facebook', $row);
3683 $user_data['wdk_youtube'] = wmvc_show_data('cacheduser_wdk_youtube', $row);
3684 $user_data['wdk_linkedin'] = wmvc_show_data('cacheduser_wdk_linkedin', $row);
3685 $user_data['wdk_twitter'] = wmvc_show_data('cacheduser_wdk_twitter', $row);
3686 $user_data['wdk_instagram'] = wmvc_show_data('cacheduser_wdk_instagram', $row);
3687 $user_data['wdk_whatsapp'] = wmvc_show_data('cacheduser_wdk_whatsapp', $row);
3688 $user_data['wdk_viber'] = wmvc_show_data('cacheduser_wdk_viber', $row);
3689 $user_data['wdk_iban'] = wmvc_show_data('cacheduser_wdk_iban', $row);
3690 $user_data['wdk_telegram'] = wmvc_show_data('cacheduser_wdk_telegram', $row);
3691 $user_data['wdk_position_title'] = wmvc_show_data('cacheduser_wdk_position_title', $row);
3692 $user_data['agency_name'] = wmvc_show_data('cacheduser_agency_name', $row);
3693 $user_data['description'] = wmvc_show_data('cacheduser_description', $row);
3694 $user_data['user_url'] = wmvc_show_data('cacheduser_user_url', $row);
3695 $user_data['roles'] = explode(',', wmvc_show_data('cacheduser_roles', $value));
3696
3697 return $user_data;
3698 }
3699 }
3700
3701 if ( ! function_exists('wdk_mime2extd'))
3702 {
3703 /**
3704 * Return currency symbol
3705 *
3706 * @return string currency symbol
3707 */
3708 function wdk_mime2ext($mime) {
3709 $mime_map = [
3710 'video/3gpp2' => '3g2',
3711 'video/3gp' => '3gp',
3712 'video/3gpp' => '3gp',
3713 'application/x-compressed' => '7zip',
3714 'audio/x-acc' => 'aac',
3715 'audio/ac3' => 'ac3',
3716 'application/postscript' => 'ai',
3717 'audio/x-aiff' => 'aif',
3718 'audio/aiff' => 'aif',
3719 'audio/x-au' => 'au',
3720 'video/x-msvideo' => 'avi',
3721 'video/msvideo' => 'avi',
3722 'video/avi' => 'avi',
3723 'application/x-troff-msvideo' => 'avi',
3724 'application/macbinary' => 'bin',
3725 'application/mac-binary' => 'bin',
3726 'application/x-binary' => 'bin',
3727 'application/x-macbinary' => 'bin',
3728 'image/bmp' => 'bmp',
3729 'image/x-bmp' => 'bmp',
3730 'image/x-bitmap' => 'bmp',
3731 'image/x-xbitmap' => 'bmp',
3732 'image/x-win-bitmap' => 'bmp',
3733 'image/x-windows-bmp' => 'bmp',
3734 'image/ms-bmp' => 'bmp',
3735 'image/x-ms-bmp' => 'bmp',
3736 'application/bmp' => 'bmp',
3737 'application/x-bmp' => 'bmp',
3738 'application/x-win-bitmap' => 'bmp',
3739 'application/cdr' => 'cdr',
3740 'application/coreldraw' => 'cdr',
3741 'application/x-cdr' => 'cdr',
3742 'application/x-coreldraw' => 'cdr',
3743 'image/cdr' => 'cdr',
3744 'image/x-cdr' => 'cdr',
3745 'zz-application/zz-winassoc-cdr' => 'cdr',
3746 'application/mac-compactpro' => 'cpt',
3747 'application/pkix-crl' => 'crl',
3748 'application/pkcs-crl' => 'crl',
3749 'application/x-x509-ca-cert' => 'crt',
3750 'application/pkix-cert' => 'crt',
3751 'text/css' => 'css',
3752 'text/x-comma-separated-values' => 'csv',
3753 'text/comma-separated-values' => 'csv',
3754 'application/vnd.msexcel' => 'csv',
3755 'application/x-director' => 'dcr',
3756 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
3757 'application/x-dvi' => 'dvi',
3758 'message/rfc822' => 'eml',
3759 'application/x-msdownload' => 'exe',
3760 'video/x-f4v' => 'f4v',
3761 'audio/x-flac' => 'flac',
3762 'video/x-flv' => 'flv',
3763 'image/gif' => 'gif',
3764 'application/gpg-keys' => 'gpg',
3765 'application/x-gtar' => 'gtar',
3766 'application/x-gzip' => 'gzip',
3767 'application/mac-binhex40' => 'hqx',
3768 'application/mac-binhex' => 'hqx',
3769 'application/x-binhex40' => 'hqx',
3770 'application/x-mac-binhex40' => 'hqx',
3771 'text/html' => 'html',
3772 'image/x-icon' => 'ico',
3773 'image/x-ico' => 'ico',
3774 'image/vnd.microsoft.icon' => 'ico',
3775 'text/calendar' => 'ics',
3776 'application/java-archive' => 'jar',
3777 'application/x-java-application' => 'jar',
3778 'application/x-jar' => 'jar',
3779 'image/jp2' => 'jp2',
3780 'video/mj2' => 'jp2',
3781 'image/jpx' => 'jp2',
3782 'image/jpm' => 'jp2',
3783 'image/jpeg' => 'jpeg',
3784 'image/pjpeg' => 'jpeg',
3785 'application/x-javascript' => 'js',
3786 'application/json' => 'json',
3787 'text/json' => 'json',
3788 'application/vnd.google-earth.kml+xml' => 'kml',
3789 'application/vnd.google-earth.kmz' => 'kmz',
3790 'text/x-log' => 'log',
3791 'audio/x-m4a' => 'm4a',
3792 'application/vnd.mpegurl' => 'm4u',
3793 'audio/midi' => 'mid',
3794 'application/vnd.mif' => 'mif',
3795 'video/quicktime' => 'mov',
3796 'video/x-sgi-movie' => 'movie',
3797 'audio/mpeg' => 'mp3',
3798 'audio/mpg' => 'mp3',
3799 'audio/mpeg3' => 'mp3',
3800 'audio/mp3' => 'mp3',
3801 'video/mp4' => 'mp4',
3802 'video/mpeg' => 'mpeg',
3803 'application/oda' => 'oda',
3804 'application/vnd.oasis.opendocument.text' => 'odt',
3805 'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
3806 'application/vnd.oasis.opendocument.presentation' => 'odp',
3807 'audio/ogg' => 'ogg',
3808 'video/ogg' => 'ogg',
3809 'application/ogg' => 'ogg',
3810 'application/x-pkcs10' => 'p10',
3811 'application/pkcs10' => 'p10',
3812 'application/x-pkcs12' => 'p12',
3813 'application/x-pkcs7-signature' => 'p7a',
3814 'application/pkcs7-mime' => 'p7c',
3815 'application/x-pkcs7-mime' => 'p7c',
3816 'application/x-pkcs7-certreqresp' => 'p7r',
3817 'application/pkcs7-signature' => 'p7s',
3818 'application/pdf' => 'pdf',
3819 'application/octet-stream' => 'pdf',
3820 'application/x-x509-user-cert' => 'pem',
3821 'application/x-pem-file' => 'pem',
3822 'application/pgp' => 'pgp',
3823 'application/x-httpd-php' => 'php',
3824 'application/php' => 'php',
3825 'application/x-php' => 'php',
3826 'text/php' => 'php',
3827 'text/x-php' => 'php',
3828 'application/x-httpd-php-source' => 'php',
3829 'image/png' => 'png',
3830 'image/x-png' => 'png',
3831 'application/powerpoint' => 'ppt',
3832 'application/vnd.ms-powerpoint' => 'ppt',
3833 'application/vnd.ms-office' => 'ppt',
3834 'application/msword' => 'doc',
3835 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
3836 'application/x-photoshop' => 'psd',
3837 'image/vnd.adobe.photoshop' => 'psd',
3838 'audio/x-realaudio' => 'ra',
3839 'audio/x-pn-realaudio' => 'ram',
3840 'application/x-rar' => 'rar',
3841 'application/rar' => 'rar',
3842 'application/x-rar-compressed' => 'rar',
3843 'audio/x-pn-realaudio-plugin' => 'rpm',
3844 'application/x-pkcs7' => 'rsa',
3845 'text/rtf' => 'rtf',
3846 'text/richtext' => 'rtx',
3847 'video/vnd.rn-realvideo' => 'rv',
3848 'application/x-stuffit' => 'sit',
3849 'application/smil' => 'smil',
3850 'text/srt' => 'srt',
3851 'image/svg+xml' => 'svg',
3852 'application/x-shockwave-flash' => 'swf',
3853 'application/x-tar' => 'tar',
3854 'application/x-gzip-compressed' => 'tgz',
3855 'image/tiff' => 'tiff',
3856 'text/plain' => 'txt',
3857 'text/x-vcard' => 'vcf',
3858 'application/videolan' => 'vlc',
3859 'text/vtt' => 'vtt',
3860 'audio/x-wav' => 'wav',
3861 'audio/wave' => 'wav',
3862 'audio/wav' => 'wav',
3863 'application/wbxml' => 'wbxml',
3864 'video/webm' => 'webm',
3865 'audio/x-ms-wma' => 'wma',
3866 'application/wmlc' => 'wmlc',
3867 'video/x-ms-wmv' => 'wmv',
3868 'video/x-ms-asf' => 'wmv',
3869 'application/xhtml+xml' => 'xhtml',
3870 'application/excel' => 'xl',
3871 'application/msexcel' => 'xls',
3872 'application/x-msexcel' => 'xls',
3873 'application/x-ms-excel' => 'xls',
3874 'application/x-excel' => 'xls',
3875 'application/x-dos_ms_excel' => 'xls',
3876 'application/xls' => 'xls',
3877 'application/x-xls' => 'xls',
3878 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
3879 'application/vnd.ms-excel' => 'xlsx',
3880 'application/xml' => 'xml',
3881 'text/xml' => 'xml',
3882 'text/xsl' => 'xsl',
3883 'application/xspf+xml' => 'xspf',
3884 'application/x-compress' => 'z',
3885 'application/x-zip' => 'zip',
3886 'application/zip' => 'zip',
3887 'application/x-zip-compressed' => 'zip',
3888 'application/s-compressed' => 'zip',
3889 'multipart/x-zip' => 'zip',
3890 'text/x-scriptzsh' => 'zsh',
3891 ];
3892
3893 return isset($mime_map[$mime]) === true ? $mime_map[$mime] : false;
3894 }
3895 }
3896
3897 if ( ! function_exists('wdk_is_dash_enabled'))
3898 {
3899 /**
3900 * IS Dash pages exists
3901 *
3902 * @return bool true if exists dash
3903 */
3904 function wdk_is_dash_enabled() {
3905 if(function_exists('run_wdk_membership') && wdk_get_option('wdk_membership_dash_page') && get_post_status(wdk_get_option('wdk_membership_dash_page')) =='publish'){
3906 return true;
3907 }
3908
3909 return false;
3910 }
3911 }
3912
3913 if(!function_exists('wdk_page_by_title')) {
3914 function wdk_page_by_title ( $page_title, $output = OBJECT, $post_type = 'page' ) {
3915 global $wpdb;
3916
3917 if ( is_array( $post_type ) ) {
3918 $post_type = esc_sql( $post_type );
3919 $post_type_in_string = "'" . implode( "','", $post_type ) . "'";
3920 $sql = $wpdb->prepare(
3921 "
3922 SELECT ID
3923 FROM $wpdb->posts
3924 WHERE post_title = %s
3925 AND post_type IN ($post_type_in_string)
3926 ",
3927 $page_title
3928 );
3929 } else {
3930 $sql = $wpdb->prepare(
3931 "
3932 SELECT ID
3933 FROM $wpdb->posts
3934 WHERE post_title = %s
3935 AND post_type = %s
3936 ",
3937 $page_title,
3938 $post_type
3939 );
3940 }
3941
3942 $page = $wpdb->get_var( $sql );
3943
3944 if ( $page ) {
3945 return get_post( $page, $output );
3946 }
3947
3948 return null;
3949 }
3950 }
3951
3952
3953 if ( ! function_exists('is_wdk_gps_single'))
3954 {
3955 function is_wdk_gps_single($param)
3956 {
3957
3958 if (is_numeric($param) && $param > -180 && $param < 180) {
3959 return true;
3960 }
3961
3962 return false;
3963 }
3964 }
3965
3966 if ( ! function_exists('wdk_get_tgmpa_link'))
3967 {
3968 function wdk_get_tgmpa_link()
3969 {
3970 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')) {
3971 return get_admin_url() . "themes.php?page=tgmpa-install-plugins";
3972 } else {
3973 return get_admin_url() . "plugins.php?page=tgmpa-install-plugins";
3974 }
3975
3976 return false;
3977 }
3978 }
3979
3980 if ( ! function_exists('wdk_sprintf'))
3981 {
3982 function wdk_sprintf($string = '')
3983 {
3984 $arg_list = func_get_args();
3985
3986 if(count($arg_list)<2) {
3987 return $string;
3988 }
3989
3990 if(stripos($string, '%1$s') === FALSE) {
3991 return $string;
3992 }
3993
3994 return call_user_func_array("sprintf", $arg_list);
3995 }
3996 }
3997
3998 if ( ! function_exists('wdk_db_table'))
3999 {
4000 function wdk_db_table($data, $columns = array()) {
4001 $output = '<table>';
4002 foreach($data as $key => $var) {
4003 if($key === 0)
4004 {
4005 $output .= '<tr>';
4006 foreach($var as $k => $v) {
4007 if(count($columns) > 0 && !in_array($k, $columns))continue;
4008
4009 $output .= '<td><strong>' . $k . '</strong></td>';
4010 }
4011 $output .= '</tr>';
4012 }
4013
4014 $output .= '<tr>';
4015 foreach($var as $k => $v) {
4016 if(count($columns) > 0 && !in_array($k, $columns))continue;
4017
4018 $output .= '<td>' . $v . '</td>';
4019 }
4020 $output .= '</tr>';
4021 }
4022 $output .= '</table>';
4023 echo $output;
4024 }
4025 }
4026
4027 if ( ! function_exists('wdk_move_gps'))
4028 {
4029 function wdk_move_gps($value) {
4030 return $value+0.001 * rand(1, 9);
4031 }
4032 }
4033
4034 if ( ! function_exists('wdk_get_near_location'))
4035 {
4036 function wdk_get_near_location($latitude, $longitude, $radius = 10000) {
4037 // Convert radius from meters to degrees
4038 $radiusInDegrees = $radius / 111000;
4039
4040 $u = mt_rand() / mt_getrandmax();
4041 $v = mt_rand() / mt_getrandmax();
4042 $w = $radiusInDegrees * sqrt($u);
4043 $t = 2 * M_PI * $v;
4044 $x = $w * cos($t);
4045 $y = $w * sin($t);
4046
4047 // Adjust the x-coordinate for the shrinking of the east-west distances
4048 $newX = $x / cos(deg2rad($latitude));
4049
4050 $newLongitude = $longitude + $newX;
4051 $newLatitude = $latitude + $y;
4052
4053 return array('lat' => $newLatitude, 'lng' => $newLongitude);
4054 }
4055 }
4056
4057 if ( ! function_exists('wdk_is_listing_preview_page'))
4058 {
4059 function wdk_is_listing_preview_page() {
4060 global $wdk_listing_id;
4061
4062 if(!empty($wdk_listing_id))
4063 return TRUE;
4064
4065 return FALSE;
4066 }
4067 }
4068
4069 if ( ! function_exists('wdk_is_listing_field_exists'))
4070 {
4071 function wdk_is_listing_field_exists($field_name = '', $udpate_cache = FALSE) {
4072 static $available_fields_listings = array();
4073 $custom_fields = array();
4074
4075 $WMVC = &wdk_get_instance();
4076 $WMVC->model('listingfield_m');
4077
4078 if(empty($available_fields_listings) || $udpate_cache) {
4079 $available_fields_listings = $WMVC->listingfield_m->get_available_fields();
4080 }
4081
4082 if(isset($available_fields_listings[$field_name]) || isset($custom_fields[$field_name])) {
4083 return TRUE;
4084 }
4085
4086 return FALSE;
4087 }
4088 }
4089
4090 if ( ! function_exists('wdk_cached_field_get'))
4091 {
4092 function wdk_cached_field_get($udpate_cache = FALSE) {
4093 static $fields = NULL;
4094
4095 $WMVC = &wdk_get_instance();
4096 $WMVC->model('field_m');
4097
4098 if(is_null($fields) || $udpate_cache) {
4099 $fields = $WMVC->field_m->get();
4100 }
4101
4102 return $fields;
4103 }
4104 }
4105
4106 if (! function_exists('wdk_generate_slug'))
4107 {
4108 function wdk_generate_slug($str, $separator = 'dash', $lowercase = TRUE)
4109 {
4110 if ($separator == 'dash')
4111 {
4112 $search = '_';
4113 $replace = '-';
4114 }
4115 else
4116 {
4117 $search = '-';
4118 $replace = '_';
4119 }
4120
4121 $dot='';
4122 if($separator == 'dot'){
4123 $str = str_replace(' ', '.', $str);
4124 $dot='.';
4125 }
4126
4127 $trans = array(
4128 $search => $replace,
4129 "\s+" => $replace,
4130 "[^a-z0-9".$replace.$dot."]" => '',
4131 $replace."+" => $replace,
4132 $replace."$" => '',
4133 "^".$replace => ''
4134 );
4135
4136 // For Croatia
4137 $str = str_replace(array('č','ć','ž','š','đ', 'Č','Ć','Ž','Š','Đ'),
4138 array('c','c','z','s','d', 'c','c','z','s','d'), $str);
4139
4140 // For Turkish
4141 $str = str_replace(array('ş','Ş','ı','İ','ğ','Ğ','Ü','ü','Ö','ö','ç','Ç'),
4142 array('s','s','i','i','g','g','u','u','o','o','c','c'), $str);
4143
4144 // Russian alphabet
4145 $str = str_replace(array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я'),
4146 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);
4147 $str = str_replace(array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','�
4148 ','ц','ч','ш','щ','ъ','ы','ь','э','ю','я'),
4149 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);
4150
4151 // Ukrainian alphabet
4152 $str = str_replace(array('Ґ','Є','І','Ї'),
4153 array('G','E','I','I'), $str);
4154 $str = str_replace(array('ґ','є','і','ї'),
4155 array('g','e','i','i'), $str);
4156 // Symbols
4157 $str = str_replace(array("  ","’","–",'«','»','','',''),
4158 array("","","-",'','','no','',''), $str);
4159
4160 // Alphabets Czech Croatian Turkish and other
4161 $str = str_replace(array('Á','Ä','Ď','É','Ě','Ë','Í','Ň','Ń','Ó','Ŕ','Ř','Ť','Ú','Ů','Ý','Ź','Č','Ć','Ž','Š','Đ','Ş','İ','Ğ','Ü','Ö','Ç'),
4162 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);
4163 $str = str_replace(array('á','ä','ď','é','ě','ë','í','ň','ń','ó','ŕ','ř','ť','ú','ů','ý','ź','č','ć','ž','š','đ','ş','ı','ğ','ü','ö','ç'),
4164 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);
4165
4166 // For french
4167 $str = str_replace(array('â','é','è','û','ê', 'à','Â','ç','ï','î','ä','î'),
4168 array('a','e','e','u','e', 'a','c','c','i','î','a','î'), $str);
4169
4170 $str = strip_tags(strtolower($str));
4171
4172
4173 foreach ($trans as $key => $val)
4174 {
4175 $str = preg_replace("#".$key."#", $val, $str);
4176 }
4177
4178 return trim(stripslashes($str));
4179 }
4180 }
4181
4182
4183 if (! function_exists('wdk_is_gps'))
4184 {
4185 function wdk_is_gps($gps = '')
4186 {
4187
4188 if(stripos($gps,',') === FALSE) {
4189 return FALSE;
4190 }
4191
4192 $gps_coor = explode(',', $gps);
4193
4194 if(count($gps_coor) != 2)
4195 {
4196 return FALSE;
4197 }
4198
4199 if(!is_numeric($gps_coor[0]) || !is_numeric($gps_coor[1]))
4200 {
4201 return FALSE;
4202 }
4203
4204 if($gps_coor[0] < -90 || $gps_coor[0] > 90 || $gps_coor[1] < -180 || $gps_coor[1] > 180)
4205 {
4206 return FALSE;
4207 }
4208
4209 return TRUE;
4210 }
4211 }
4212
4213 if ( ! function_exists('is_wdk_is_useremail_exists'))
4214 {
4215 function is_wdk_is_useremail_exists($param)
4216 {
4217
4218 if(null == username_exists( $param ) && !email_exists($param)) {
4219 return true;
4220 }
4221
4222 return false;
4223 }
4224 }
4225
4226
4227 /*
4228 Validation is natural integer
4229 */
4230 if ( ! function_exists('is_wdk_is_natural'))
4231 {
4232 function is_wdk_is_natural($param)
4233 {
4234
4235 if (is_intval($param) && stripos($param, '.') === FALSE && stripos($param, ',') === FALSE) {
4236 return true;
4237 }
4238
4239 return false;
4240 }
4241 }
4242
4243
4244 /**
4245 * Check is listing preview page exits
4246 *
4247 * @return bool
4248 */
4249 if ( ! function_exists('wdk_is_listing_page_enabled'))
4250 {
4251 function wdk_is_listing_page_enabled ()
4252 {
4253
4254 if(get_option('wdk_listing_page') && get_post_status(get_option('wdk_listing_page')) =='publish') {
4255 return true;
4256 }
4257
4258 return false;
4259 }
4260 }
4261
4262 ?>
4263