PluginProbe
WP Directory Kit / 1.2.7
WP Directory Kit v1.2.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 1.4.0 1.4.1 All 35 releases
wpdirectorykit / application / helpers / Basic.php

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

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