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

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

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