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

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