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

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

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