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

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

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