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

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

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