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

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

3,751 lines 148.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 function wdk_generate_fields($fields, $db_data)
8 {
9 if(is_array($fields))
10 foreach($fields as $field)
11 {
12 $field = (object) $field;
13
14 $field_type = $field->field_type;
15
16 $field_view_path = WPDIRECTORYKIT_PATH.'application/views/fields_edit/'.$field_type.'.php';
17
18 if(file_exists($field_view_path))
19 {
20 include $field_view_path;
21 }
22 else
23 {
24 echo __('Missing VIEW file: ', 'wpdirectorykit').esc_html($field_type).'.php';
25 }
26 }
27 }
28
29 if ( ! function_exists('wdk_generate_search_form'))
30 {
31 function wdk_generate_search_form($form_id=1, $subfolder='', $print = TRUE, $predefinedfields_query = array())
32 {
33 /* load WMVC data */
34 $WMVC = &wdk_get_instance();
35 $WMVC->model('searchform_m');
36 $WMVC->model('field_m');
37 $output = '';
38
39 /* get WMVC form data */
40 $fields = $WMVC->searchform_m->get($form_id, TRUE);
41 $user_fields = NULL;
42
43 /* get WMVC form fields */
44 if(is_object($fields))
45 $user_fields = json_decode($fields->searchform_json);
46 /* generate WMVC form fields html */
47 if(is_array($user_fields))
48 foreach($user_fields as $used_field)
49 {
50
51 if($used_field->field_id == 'cat') {
52 $field = array(
53 "idfield" => 'category',
54 "field_type" => 'CATEGORY',
55 "field_label" => __('Category', 'wpdirectorykit'),
56 "prefix" => '',
57 "suffix" => '',
58 "values_list" => '',
59 "placeholder" => '',
60 );
61 }else if($used_field->field_id == 'loc') {
62 $field = array(
63 "idfield" => 'location',
64 "field_type" => 'LOCATION',
65 "field_label" => __('Location', 'wpdirectorykit'),
66 "prefix" => '',
67 "suffix" => '',
68 "values_list" => '',
69 "placeholder" => '',
70 );
71 }else if($used_field->field_id == 'address') {
72 $field = array(
73 "idfield" => 'address',
74 "field_type" => 'INPUTBOX',
75 "field_label" => __('Address', 'wpdirectorykit'),
76 "prefix" => '',
77 "suffix" => '',
78 "values_list" => '',
79 "placeholder" => '',
80 );
81 }else if($used_field->field_id == 'post_title') {
82 $field = array(
83 "idfield" => 'post_title',
84 "field_type" => 'INPUTBOX',
85 "field_label" => __('Title', 'wpdirectorykit'),
86 "prefix" => '',
87 "suffix" => '',
88 "values_list" => '',
89 "placeholder" => '',
90 );
91 }else if($used_field->field_id == 'search') {
92 $field = array(
93 "idfield" => 'search',
94 "field_type" => 'INPUTBOX',
95 "field_label" => __('Search', 'wpdirectorykit'),
96 "prefix" => '',
97 "suffix" => '',
98 "values_list" => '',
99 "placeholder" => '',
100 );
101 }else if(function_exists('run_wdk_bookings') && $used_field->field_id == 'booking_date') {
102 $field = array(
103 "idfield" => 'booking_date',
104 "field_type" => 'BOOKINGS_DATE',
105 "field_label" => __('Booking Date', 'wpdirectorykit'),
106 "prefix" => '',
107 "suffix" => '',
108 "values_list" => '',
109 "placeholder" => '',
110 );
111 }else if($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_more_button;
1441 if(empty($wdk_text_more_button))
1442 $wdk_text_more_button = esc_html__('More','wpdirectorykit');
1443
1444 $form_closed = 'display: none;';
1445 if(isset($_GET['wdk_search_additional_opened']) && wmvc_xss_clean($_GET['wdk_search_additional_opened']) == 1) {
1446 $form_closed = '';
1447 }
1448
1449 ?>
1450 <div class="wdk-col wdk-col-btns">
1451 <div class="wdk-field wdk-field-btn">
1452 <div class="wdk-field-group wdk-field-group-additional">
1453 <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>
1454 <input type='checkbox' style="display: none !important" value='1' name='wdk_search_additional_opened' />
1455 </div>
1456 <div class="wdk-field-group wdk-field-group-search">
1457 <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>
1458 <?php if(function_exists('run_wdk_save_search') && get_option('wdk_save_search_show_on_searchform')):?>
1459 <div class="section-widget-control right">
1460 <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">
1461 <i class="fas fa-save" aria-hidden="true"></i>
1462 <i class="fa fa-spinner fa-spin fa-ajax-indicator"></i>
1463 </a>
1464 </div>
1465 <?php endif;?>
1466 </div>
1467 </div>
1468 </div>
1469 <div id='wdk-form-additional' class="wdk-col" style="<?php echo esc_attr($form_closed) ;?>">
1470 <div class="wdk-row">
1471 <?php
1472 }
1473 }
1474 }
1475
1476
1477 /*
1478 * @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
1479 *
1480 */
1481 if ( ! function_exists('wdk_treefield_option'))
1482 {
1483 function wdk_treefield_option($name = '', $table=NULL, $selected = NULL,
1484 $column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE, $sql_where='')
1485 {
1486 $WMVC = &wdk_get_instance();
1487
1488 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
1489
1490 static $counter = 0;
1491
1492 $model_name = $table;
1493 if($table == 'calendar_listing_m')
1494 $model_name = 'listing_m';
1495
1496 $table_name = str_replace('_m', '', $table);
1497
1498 $attribute_id = 'id'.$table_name;
1499
1500 if($table_name == 'icons_list') {
1501
1502 } else {
1503 $WMVC->model($model_name);
1504 $attribute_id = $WMVC ->$model_name->_primary_key;
1505 $selected = (int) $selected;
1506 }
1507
1508 if(empty($selected))
1509 $selected='';
1510
1511 $form = '<input name="'.$name.'" value="'.$selected.'" class="wdk-hidden" type="text" id="wdktreeelem'.$counter.'" readonly/>';
1512
1513 $skip_id = '';
1514 //load javascript library
1515 if($counter==0)
1516 {
1517 wp_enqueue_script('wdk-treefield');
1518 wp_enqueue_style('wdk-treefield');
1519 }
1520 ?>
1521 <script>
1522 jQuery(document).ready(function($) {
1523 $('#wdktreeelem<?php echo esc_js($counter);?>:not(.init)').wdkTreefield({
1524 ajax_url: '<?php echo admin_url('admin-ajax.php'); ?>',
1525 ajax_param: {
1526 "page": 'wdk_frontendajax',
1527 "function": 'treefieldid',
1528 "action": 'wdk_public_action',
1529 "table": '<?php echo esc_js($table); ?>',
1530 "filter_ids": '<?php echo esc_js($filter_ids); ?>',
1531 "start_id": '<?php if(!empty($filter_ids)) esc_js($selected); else echo ""; ?>',
1532 "empty_value": '<?php echo esc_js($empty_value); ?>',
1533 "user_check": '<?php echo esc_js($user_check); ?>',
1534 "sql_where": '<?php echo esc_js($sql_where); ?>'
1535 },
1536 attribute_id: '<?php echo esc_js($attribute_id); ?>',
1537 language_id: '<?php echo esc_js($language_id); ?>',
1538 attribute_value: '<?php echo esc_js($column); ?>',
1539 skip_id: '<?php echo esc_js($skip_id); ?>',
1540 empty_value: ' - ',
1541 text_search: '<?php esc_html_e('Search term', 'wpdirectorykit');?>',
1542 text_no_results: '<?php esc_html_e('No results found', 'wpdirectorykit');?>',
1543 callback_selected: function(key) {
1544 $('#wdktreeelem<?php echo esc_js($counter);?>').trigger("change");
1545 }
1546 }).addClass('init');
1547 });
1548 </script>
1549 <?php
1550 $counter++;
1551 return $form;
1552 }
1553 }
1554
1555 /*
1556 * @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
1557 *
1558 */
1559 if ( ! function_exists('wdk_treefield_option_checkboxes'))
1560 {
1561 function wdk_treefield_option_checkboxes($name = '', $table=NULL, $selected = NULL,
1562 $column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE)
1563 {
1564 $WMVC = &wdk_get_instance();
1565
1566 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
1567
1568 static $counter = 0;
1569
1570 $model_name = $table;
1571
1572 $table_name = str_replace('_m', '', $table);
1573
1574 $attribute_id = 'id'.$table_name;
1575
1576
1577 $WMVC->model($model_name);
1578 $attribute_id = $WMVC ->$model_name->_primary_key;
1579
1580 $values = '';
1581 if(!empty($selected)){
1582 $ids = array();
1583
1584 if(is_string($selected) && strpos($selected, ',') !== FALSE){
1585 $val_selected = explode(',', $selected);
1586 } elseif(is_string($selected)){
1587 $val_selected = array($selected);
1588 }
1589
1590 foreach($val_selected as $selected_item) {
1591 if(!empty($selected_item) && is_intval($selected_item)) {
1592 $ids [] = $selected_item;
1593 }
1594 }
1595
1596 /* where in */
1597 if(!empty($ids)){
1598 $WMVC->db->select($WMVC->$table->_table_name.'.*');
1599 $WMVC->db->where($WMVC->$table->_table_name.'.'.$WMVC->$table->_primary_key.' IN(' . implode(',', $ids) . ')', null, false);
1600 $WMVC->db->order_by('FIELD('.$WMVC->$table->_table_name.'.'.$WMVC->$table->_primary_key.', '. implode(',', $ids) . ')');
1601
1602 $results = $WMVC->$table->get();
1603 foreach ($results as $item) {
1604 if($item) {
1605 $values .= wmvc_show_data($column, $item, false, TRUE, TRUE).',';
1606 }
1607 }
1608 $values = substr($values,0,-1);
1609
1610 if(strlen($values)>23) {
1611 $values = substr($values,0,20).'...';
1612 }
1613 }
1614 }
1615
1616 if(empty($values)) {
1617 $values = $empty_value;
1618 }
1619
1620 $form = '<input name="'.$name.'" value="'.esc_html($selected).'" data-placehoder="'.esc_html($values).'" class="wdk-hidden" type="text" id="wdktreeelem_checkbox'.$counter.'" readonly/>';
1621
1622 $skip_id = '';
1623 //load javascript library
1624 if($counter==0)
1625 {
1626 wp_enqueue_script('wdk-treefield');
1627 wp_enqueue_style('wdk-treefield');
1628 }
1629 ?>
1630 <script>
1631 jQuery(document).ready(function($) {
1632 $('#wdktreeelem_checkbox<?php echo esc_js($counter);?>:not(.init)').wdkTreefieldCheckboxes({
1633 ajax_url: '<?php echo admin_url('admin-ajax.php'); ?>',
1634 ajax_param: {
1635 "page": 'wdk_frontendajax',
1636 "function": 'treefieldid_checkboxes',
1637 "action": 'wdk_public_action',
1638 "table": '<?php echo esc_js($table); ?>',
1639 "filter_ids": '<?php echo esc_js($filter_ids); ?>',
1640 "empty_value": '<?php echo esc_js($empty_value); ?>',
1641 "user_check": '<?php echo esc_js($user_check); ?>',
1642 },
1643 selected: '<?php echo esc_js($selected); ?>',
1644 attribute_id: '<?php echo esc_js($attribute_id); ?>',
1645 language_id: '<?php echo esc_js($language_id); ?>',
1646 attribute_value: '<?php echo esc_js($column); ?>',
1647 skip_id: '<?php echo esc_js($skip_id); ?>',
1648 empty_value: ' - ',
1649 text_search: '<?php esc_html_e('Search term', 'wpdirectorykit');?>',
1650 text_no_results: '<?php esc_html_e('No results found', 'wpdirectorykit');?>',
1651 callback_selected: function(key) {
1652 $('#wdktreeelem_checkbox<?php echo esc_js($counter);?>').trigger("change");
1653 }
1654 }).addClass('init');
1655 });
1656 </script>
1657 <?php
1658 $counter++;
1659 return $form;
1660 }
1661 }
1662
1663 if ( ! function_exists('wdk_filter_decimal'))
1664 {
1665 function wdk_filter_decimal($string = '')
1666 {
1667 if(substr($string, -3, 3) === ".00") {
1668 return substr($string, 0, -3);
1669 }
1670
1671 return $string;
1672 }
1673 }
1674
1675 if ( ! function_exists('wdk_is_date'))
1676 {
1677 function wdk_is_date($date, $format = 'Y-m-d H:i:s')
1678 {
1679
1680 /* check is date on strtotime */
1681 if((bool)strtotime($date)){
1682 return true;
1683 }
1684
1685 /* check is date from argument */
1686 $d = \DateTime::createFromFormat($format, $date);
1687 if($d) {
1688 return true;
1689 }
1690
1691 /* check is date from wp date and time */
1692 $d = \DateTime::createFromFormat(get_option('date_format').' '.get_option('time_format'), $date);
1693 if($d) {
1694 return true;
1695 }
1696
1697 /* check is date from wp date */
1698 $d = \DateTime::createFromFormat(get_option('date_format'), $date);
1699 if($d) {
1700 return true;
1701 }
1702
1703 /* try with default */
1704 if('Y-m-d H:i:s' != $format) {
1705 $d = \DateTime::createFromFormat('Y-m-d H:i:s', $date);
1706 if($d) {
1707 return true;
1708 }
1709
1710 $d = \DateTime::createFromFormat('Y-m-d', $date);
1711 if($d) {
1712 return true;
1713 }
1714 }
1715
1716 /* issue with pm/am inside date, example bug format like "2023 01 19 pm8:06" => 'Y n j ag:i' */
1717 $format = get_option('date_format').' '.get_option('time_format');
1718 if(strpos($format, 'a') !== FALSE) {
1719 $format = str_replace('a', '',$format).' a';
1720 if(strpos($date, 'am') !== FALSE) {
1721 $date = str_replace('am', '',$date).' am';
1722 }
1723 if(strpos($date, 'pm') !== FALSE) {
1724 $date = str_replace('pm', '',$date).' pm';
1725 }
1726 $d = \DateTime::createFromFormat($format, $date);
1727 if($d) {
1728 return true;
1729 }
1730 }
1731
1732 return false;
1733 }
1734 }
1735
1736
1737 if ( ! function_exists('wdk_normalize_date_db'))
1738 {
1739 /**
1740 * Convert date to db format, from wp format
1741 * @param string $date Date in string
1742 * @param string $format Special format
1743 * @param string $format Special format
1744 * @param string $return_format return date format
1745 * @return string date in format Y-m-d H:i:s
1746 */
1747 function wdk_normalize_date_db($date, $format = 'Y-m-d H:i:s', $return_format = 'Y-m-d H:i:s')
1748 {
1749 /* check is date on strtotime */
1750 if((bool)strtotime($date)){
1751 return date($return_format, strtotime($date));
1752 }
1753
1754 /* check is date from argument */
1755 $d = \DateTime::createFromFormat($format, $date);
1756 if($d) {
1757 return $d->format($return_format);
1758 }
1759
1760 /* check is date from wp date and time */
1761 $d = \DateTime::createFromFormat(get_option('date_format').' '.get_option('time_format'), $date);
1762 if($d) {
1763 return $d->format($return_format);
1764 }
1765
1766 /* check is date from wp date */
1767 $d = \DateTime::createFromFormat(get_option('date_format'), $date);
1768 if($d) {
1769 return $d->format($return_format);
1770 }
1771
1772 /* try with default */
1773 if('Y-m-d H:i:s' != $format) {
1774 $d = \DateTime::createFromFormat('Y-m-d H:i:s', $date);
1775 if($d) {
1776 return $d->format($return_format);
1777 }
1778
1779 $d = \DateTime::createFromFormat('Y-m-d', $date);
1780 if($d) {
1781 return $d->format($return_format);
1782 }
1783 }
1784
1785 /* issue with pm/am inside date, example bug format like "2023 01 19 pm8:06" => 'Y n j ag:i' */
1786 $format = get_option('date_format').' '.get_option('time_format');
1787 if(strpos($format, 'a') !== FALSE) {
1788 $format = str_replace('a', '',$format).' a';
1789 if(strpos($date, 'am') !== FALSE) {
1790 $date = str_replace('am', '',$date).' am';
1791 }
1792 if(strpos($date, 'pm') !== FALSE) {
1793 $date = str_replace('pm', '',$date).' pm';
1794 }
1795 $d = \DateTime::createFromFormat($format, $date);
1796 if($d) {
1797 return $d->format($return_format);
1798 }
1799 }
1800
1801 return false;
1802 }
1803 }
1804
1805 if ( ! function_exists('wdk_url_suffix'))
1806 {
1807 function wdk_url_suffix($base_url, $extension_url="")
1808 {
1809 if(substr($base_url, -1) == '?'){
1810 $base_url .='';
1811 } elseif(strpos($base_url,'?') !== FALSE){
1812 $base_url .='&';
1813 } else {
1814 $base_url .='?';
1815 }
1816 return $base_url.$extension_url;
1817 }
1818 }
1819
1820 /**
1821 * Insert an attachment from an URL address.
1822 *
1823 * @param String $url
1824 * @param Int $parent_post_id
1825 * @return Int Attachment ID
1826 */
1827 function wdk_insert_attachment_from_url($url, $parent_post_id = null) {
1828
1829 if( !class_exists( 'WP_Http' ) )
1830 include_once( ABSPATH . WPINC . '/class-http.php' );
1831
1832 $http = new WP_Http();
1833 $response = $http->request( $url );
1834 if( is_wp_error($response) || $response['response']['code'] != 200 ) {
1835 return false;
1836 }
1837
1838 $filename = basename($url);
1839 if(strpos($filename, '?')!==FALSE) {
1840 $filename = substr($filename, 0, strpos($filename, '?'));
1841 }
1842
1843 /* if unsoported extension */
1844 if(in_array(wdk_file_extension($filename), array('php','asp'))){
1845 $data = getimagesizefromstring($response['body']);
1846 if(!$data) return false;
1847 if(empty($data['mime'])) return false;
1848
1849 $filename = time().rand(0000,9999).'.'.wdk_mime2ext($data['mime']);
1850 }
1851 $upload = wp_upload_bits( $filename, null, $response['body'] );
1852
1853 if( !empty( $upload['error'] ) ) {
1854 return false;
1855 }
1856
1857 $file_path = $upload['file'];
1858 $file_name = basename( $file_path );
1859 $file_type = wp_check_filetype( $file_name, null );
1860 $attachment_title = sanitize_file_name( pathinfo( $file_name, PATHINFO_FILENAME ) );
1861 $wp_upload_dir = wp_upload_dir();
1862
1863 $post_info = array(
1864 'guid' => $wp_upload_dir['url'] . '/' . $file_name,
1865 'post_mime_type' => $file_type['type'],
1866 'post_title' => $attachment_title,
1867 'post_content' => '',
1868 'post_status' => 'inherit',
1869 );
1870 // Create the attachment
1871 $attach_id = wp_insert_attachment( $post_info, $file_path, $parent_post_id );
1872
1873 // Include image.php
1874 require_once( ABSPATH . 'wp-admin/includes/image.php' );
1875
1876 // Define attachment metadata
1877 $attach_data = wp_generate_attachment_metadata( $attach_id, $file_path );
1878
1879 // Assign metadata to attachment
1880 wp_update_attachment_metadata( $attach_id, $attach_data );
1881
1882 return $attach_id;
1883
1884 }
1885
1886 if(!function_exists('wdk_jsdateformat')) {
1887 function wdk_jsdateformat($format = '') {
1888 $date_specific = array(
1889 // Day
1890 'd' => 'dd',
1891 'D' => 'D',
1892 'j' => 'd',
1893 'l' => 'DD',
1894 'N' => '',
1895 'S' => '',
1896 'w' => '',
1897 'z' => 'o',
1898 // Week
1899 'W' => '',
1900 // Month
1901 'F' => 'MM',
1902 'm' => 'mm',
1903 'M' => 'M',
1904 'n' => 'm',
1905 't' => '',
1906 // Year
1907 'L' => '',
1908 'o' => '',
1909 'y' => 'y',
1910 'Y' => 'yy',
1911 // Time
1912 'a' => '',
1913 'A' => '',
1914 'B' => '',
1915 'g' => '',
1916 'G' => '',
1917 'h' => '',
1918 'H' => '',
1919 'i' => '',
1920 's' => '',
1921 'u' => ''
1922 );
1923 return str_replace(array_keys($date_specific), array_values($date_specific), $format);
1924 }
1925
1926 }
1927
1928 function wdk_current_url()
1929 {
1930 global $wp;
1931 return add_query_arg( $wp->query_vars, home_url( $wp->request ) );
1932 }
1933
1934 if(!function_exists('wdk_generate_profile_permalink')) {
1935 /**
1936 * Insert user id and return link on user profile page
1937 *
1938 * @return Int user ID
1939 */
1940
1941 function wdk_generate_profile_permalink($profile = array())
1942 {
1943
1944 $profile_slug = '';
1945 if(wmvc_show_data('user_login', $profile, false)){
1946 $profile_slug = wmvc_show_data('user_login', $profile);
1947 if(wmvc_show_data('wdk_slug', $profile))
1948 $profile_slug = wmvc_show_data('wdk_slug', $profile);
1949 } else if(is_intval($profile)){
1950 $profile_data = get_userdata($profile);
1951 if(wmvc_show_data('wdk_slug', $profile, false)){
1952 $profile_slug = wmvc_show_data('wdk_slug', $profile);
1953 }elseif(wmvc_show_data('user_login', $profile_data, false)){
1954 $profile_slug = wmvc_show_data('user_login', $profile_data);
1955 } else {
1956 $profile_slug = $profile;
1957 }
1958 }
1959
1960 $user_profile_page = get_option('wdk_membership_profile_preview_page');
1961 if(!$user_profile_page) {
1962 return '#';
1963 }
1964 // for polylang to detect translated page version
1965 if(function_exists('pll_get_post'))
1966 $user_profile_page = pll_get_post($user_profile_page);
1967
1968 return wdk_url_suffix(get_permalink($user_profile_page), 'slug='. $profile_slug);
1969 }
1970 }
1971
1972 if(!function_exists('wdk_get_profile_page_id')) {
1973 /**
1974 * Insert user id and return link on user profile page
1975 *
1976 * @return Int user ID
1977 */
1978
1979 function wdk_get_profile_page_id()
1980 {
1981 global $wp_query;
1982 if(get_option('wdk_membership_profile_preview_page') && isset($wp_query->post) && get_option('wdk_membership_profile_preview_page') == $wp_query->post->ID) {
1983 if (wmvc_show_data('slug', $_GET, false)) {
1984 if(is_intval(wmvc_show_data('slug', $_GET))) {
1985 return wmvc_show_data('slug', $_GET);
1986 } else {
1987
1988 $args = array(
1989 'meta_key' => 'wdk_slug',
1990 'meta_value' => sanitize_text_field(wmvc_show_data('slug', $_GET)),
1991 'meta_compare' => '='
1992 );
1993 $by_slug_user_detected = get_users($args);
1994
1995 $profile = false;
1996 if(!empty($by_slug_user_detected)) {
1997 $profile = $by_slug_user_detected[0];
1998 } else {
1999 $profile = get_user_by('login',wmvc_show_data('slug', $_GET));
2000 }
2001
2002 return (wmvc_show_data('ID', $profile, false)) ? wmvc_show_data('ID', $profile, false) : false;
2003 }
2004 }
2005 }
2006
2007 return false;
2008 }
2009 }
2010
2011 if(!function_exists('wdk_get_date')) {
2012 /**
2013 * Return date in format
2014 *
2015 */
2016 function wdk_get_date($datetime = NULL, $time = TRUE, $default='timestamp')
2017 {
2018 $init_datetime = $datetime;
2019 if(is_null($datetime))
2020 {
2021 if($default == 'timestamp')
2022 {
2023 $datetime = current_time('timestamp');
2024 }
2025 else
2026 {
2027 return $default;
2028 }
2029 }
2030 else if(!is_numeric($datetime))
2031 {
2032 $datetime = strtotime($datetime);
2033 }
2034
2035 $date_format = get_option('date_format');
2036
2037 $time_format = ($time && strpos($init_datetime, '00:00:00')===FALSE) ? get_option('time_format') : '';
2038
2039 $date = date_i18n("{$date_format} {$time_format}", $datetime);
2040 return $date;
2041 }
2042 }
2043
2044 if(!function_exists('wdk_login_url')) {
2045 /**
2046 * Return date in format
2047 * @param string|url redirect url
2048 * @param string custom_message, showed on login form like alert, visible only on wdk login form
2049 */
2050 function wdk_login_url($url_redirect = NULL, $custom_message = '')
2051 {
2052 $url = wp_login_url($url_redirect);
2053
2054 if(get_option('wdk_membership_login_page')){
2055 $url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')), 'redirect_to='. urlencode($url_redirect).'&custom_message='. urlencode($custom_message));
2056 }
2057
2058 return $url;
2059 }
2060 }
2061
2062 if(!function_exists('wdk_mail')) {
2063 /**
2064 * Return date in format
2065 * @param string|url redirect url
2066 */
2067 function wdk_mail( $email_to, $subject = '', $data = array(), $layout = 'default', $email_from = '', $attachments = array(), $reply_to = '')
2068 {
2069 $WMVC = &wdk_get_instance();
2070
2071 $ret = false;
2072 if(empty($email_from))
2073 $email_from = get_bloginfo('admin_email');
2074
2075 if(empty($subject))
2076 $subject = __("New message", "wpdirectorykit");
2077
2078 $headers = array('Content-Type: text/html; charset=UTF-8');
2079 $headers[] = 'From: '.$email_from;
2080
2081 if(!empty($reply_to)) {
2082 $headers[] = 'Reply-To: '.$reply_to;
2083 } else {
2084 $headers[] = 'Reply-To: '.$email_from;
2085 }
2086
2087 $data['subject'] = $subject;
2088
2089 $message = $WMVC->view('email/'.$layout, $data, FALSE);
2090 $ret = wp_mail( $email_to, $subject, $message, $headers, $attachments );
2091
2092 return $ret;
2093 }
2094 }
2095
2096 if(!function_exists('wdk_show_data')) {
2097 function wdk_show_data($field_name, &$db_value = NULL, $default = '', $xss_clean = TRUE, $skip_post = FALSE)
2098 {
2099 if(!$skip_post && isset($_POST[$field_name]))
2100 {
2101 if($xss_clean === FALSE)
2102 return stripslashes($_POST[$field_name]);
2103
2104 return wmvc_xss_clean(stripslashes($_POST[$field_name]));
2105 }
2106
2107
2108 if(is_array($db_value))
2109 {
2110 if(isset($db_value[$field_name]))
2111 {
2112 if($xss_clean === FALSE)
2113 return $db_value[$field_name];
2114
2115 return wmvc_xss_clean($db_value[$field_name]);
2116 }
2117 else
2118 {
2119 return $default;
2120 }
2121 }
2122
2123 if(is_object($db_value))
2124 {
2125 if(isset($db_value->$field_name))
2126 {
2127 if($xss_clean === FALSE)
2128 return $db_value->$field_name;
2129
2130 return wmvc_xss_clean($db_value->$field_name);
2131 }
2132 else
2133 {
2134 return $default;
2135 }
2136 }
2137
2138 if(!empty($db_value))
2139 {
2140 if($xss_clean === FALSE)
2141 return $db_value;
2142
2143 return wmvc_xss_clean($db_value);
2144 }
2145
2146 if($xss_clean === FALSE)
2147 return $default;
2148
2149 return wmvc_xss_clean($default);
2150 }
2151 }
2152
2153
2154 if (!function_exists('wdk_input_checked'))
2155 {
2156 function wdk_input_checked($field_id, $db_data, $value = 1)
2157 {
2158
2159 if(wmvc_show_data($field_id, $db_data, false) && wmvc_show_data($field_id, $db_data) == $value)
2160 {
2161 return 'checked';
2162 }
2163
2164 return '';
2165 }
2166 }
2167
2168 function wdk_upload_file($field_name, $file_id)
2169 {
2170 static $media_element_counter = 0;
2171
2172 $media_element_counter++;
2173
2174 $img_field = $field_name.'_'.$media_element_counter;
2175
2176 wp_register_script( 'wpmediaelement_file', WPDIRECTORYKIT_URL . 'admin/js/jquery.wpmediaelement_file.js', array( 'jquery' ), false, false );
2177 wp_enqueue_script( 'wpmediaelement_file' );
2178 wp_enqueue_media();
2179
2180 ?>
2181 <div id="<?php echo esc_attr($field_name); ?>meta-box-id" class="postbox-upload">
2182 <?php
2183 // Get WordPress' media upload URL
2184 $upload_link = '#';
2185
2186 // Get the file src
2187
2188 // Get the file src
2189 $your_file_src = get_attached_file(intval( $file_id));
2190
2191 // For convenience, see if the array is valid
2192 $you_have_file = false;
2193 if($your_file_src)
2194 $you_have_file = basename($your_file_src);
2195
2196 ?>
2197
2198 <!-- Your file container, which can be manipulated with js -->
2199 <div class="custom-img-container">
2200 <?php if ( $you_have_file ) : ?>
2201 <?php echo esc_html($you_have_file); ?>
2202 <?php endif; ?>
2203 </div>
2204
2205 <?php //if(sw_user_in_role('administrator')): ?>
2206 <!-- Your add & remove file links -->
2207 <p class="hide-if-no-js">
2208 <a class="upload-custom-img <?php if ( $you_have_file ) { echo 'hidden'; } ?>"
2209 href="<?php echo esc_url($upload_link) ?>">
2210 <?php echo esc_html__('Select file','wmvc_win') ?>
2211 </a>
2212 <a class="delete-custom-img <?php if ( ! $you_have_file ) { echo 'hidden'; } ?>"
2213 href="#">
2214 <?php echo esc_html__('Remove file','wmvc_win') ?>
2215 </a>
2216 </p>
2217 <?php //endif; ?>
2218
2219 <!-- A hidden input to set and post the chosen file id -->
2220 <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); ?>" />
2221 </div>
2222
2223 <?php
2224 $custom_js ='';
2225 $custom_js .=" jQuery(function($) {
2226 if( typeof jQuery.fn.wpMediaElementFile == 'function')
2227 $('#".esc_js($field_name)."meta-box-id.postbox-upload').wpMediaElementFile();
2228 });";
2229
2230 echo "<script>".$custom_js."</script>";
2231
2232 ?>
2233
2234 <?php
2235 }
2236
2237 if ( ! function_exists('wdk_file_extension'))
2238 {
2239 function wdk_file_extension($filepath)
2240 {
2241
2242 /* filters */
2243 if(strpos($filepath, '?') !== FALSE) {
2244 $filepath = $filepath;
2245 $filepath = substr($filepath, 0,strpos($filepath, '?'));
2246 }
2247 if(strpos($filepath, '#') !== FALSE) {
2248 $filepath = $filepath;
2249 $filepath = substr($filepath, 0,strpos($filepath, '#'));
2250 }
2251
2252 return substr($filepath, strrpos($filepath, '.')+1);
2253 }
2254 }
2255
2256 if ( ! function_exists('wdk_file_extension_type'))
2257 {
2258 /**
2259 * Get image type based on extension
2260 *
2261 * @param string $filepath string path(url) to file with extension
2262 * @return string type of file (image,video,docs)
2263 */
2264 function wdk_file_extension_type($filepath = NULL)
2265 {
2266
2267 if(in_array(wdk_file_extension($filepath),array('jpg','jpeg','bmp','png','webp'))) {
2268 return 'image';
2269 }
2270 if(in_array(wdk_file_extension($filepath),array('mp4','mov','flv','mkv','avi','webm'))) {
2271 return 'video';
2272 }
2273
2274 return 'docs';
2275 }
2276 }
2277
2278 function wdk_upload_multi_files($field_name, $image_ids='', $texts = array())
2279 {
2280 static $media_element_counter = 0;
2281
2282 if(!isset($texts['file_select']))$texts['file_select'] = esc_html__('Select file','wmvc_win');
2283 if(!isset($texts['file_remove']))$texts['file_remove'] = esc_html__('Remove file','wmvc_win');
2284
2285 $media_element_counter++;
2286
2287 $img_field = $field_name.'_'.$media_element_counter;
2288
2289 wp_register_script( 'wpmediaelement_file', WPDIRECTORYKIT_URL . 'admin/js/jquery.wpmediaelement_file.js', array( 'jquery' ), false, false );
2290 wp_enqueue_script( 'wpmediaelement_file' );
2291 wp_enqueue_media();
2292
2293 wp_enqueue_script( 'wpmediamultiple' );
2294 wp_enqueue_script( 'jquery-ui-mouse' );
2295 wp_enqueue_media();
2296
2297 ?>
2298 <div id="<?php echo esc_attr($field_name); ?>meta-box-id" class="postbox-upload-multiple">
2299 <?php
2300 // Get WordPress' media upload URL
2301 $upload_link = '#';
2302
2303
2304 // Get the image src
2305
2306 $your_img_src = array();
2307
2308 foreach(explode(',', $image_ids) as $image_id)
2309 {
2310 if(is_numeric($image_id)){
2311 $src = wp_get_attachment_url( $image_id, 'full' );
2312 if(!in_array(wdk_file_extension($src),array('jpg','jpeg','bmp','png','webp'))) {
2313 if(file_exists(WPDIRECTORYKIT_PATH.'/public/img/filetype/'.wdk_file_extension($src).'.png')) {
2314 $src = WPDIRECTORYKIT_URL.'public/img/filetype/'.wdk_file_extension($src).'.png';
2315 } else {
2316 $src = WPDIRECTORYKIT_URL.'public/img/filetype/_blank.png';
2317 }
2318 }
2319 $your_img_src[$image_id] = $src;
2320 }
2321 }
2322
2323 // For convenience, see if the array is valid
2324 $you_have_img = count($your_img_src) > 0;
2325 ?>
2326
2327 <!-- Your image container, which can be manipulated with js -->
2328 <div class="custom-img-container winter_mvc-media">
2329 <?php if($you_have_img)foreach($your_img_src as $image_id => $img_src) : ?>
2330 <div class="winter_mvc-media-card" data-media-id="<?php echo esc_attr($image_id);?>">
2331 <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"/>
2332 <a href="#" class="remove"></a>
2333 </div>
2334 <?php endforeach; ?>
2335 </div>
2336 <br style="clear:both;" />
2337
2338 <?php //if(sw_user_in_role('administrator')): ?>
2339 <!-- Your add & remove image links -->
2340 <p class="hide-if-no-js">
2341 <a class="button button-primary upload-custom-img <?php if ( $you_have_img ) { echo ''; } ?>"
2342 href="<?php echo esc_url($upload_link) ?>">
2343 <?php echo esc_html($texts['file_select']) ?>
2344 </a>
2345 <a class="button button-secondary delete-custom-img <?php if ( ! $you_have_img ) { echo 'hidden'; } ?>"
2346 href="#">
2347 <?php echo esc_html($texts['file_remove']) ?>
2348 </a>
2349 </p>
2350 <?php //endif; ?>
2351
2352 <!-- A hidden input to set and post the chosen image id -->
2353 <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); ?>" />
2354 </div>
2355 <?php
2356 $custom_js ='';
2357 $custom_js .=" jQuery(function($) {
2358 if( typeof jQuery.fn.wpMediaMultiple == 'function')
2359 $('#".esc_js($field_name)."meta-box-id.postbox-upload-multiple').wpMediaMultiple({
2360 frame: {
2361 title: '".esc_js(__('Select or Upload Media Of Your Chosen Persuasion','wpdirectorykit'))."',
2362 button: '".esc_js(__('Use this media','wpdirectorykit'))."',
2363 }
2364 });
2365 /* order */
2366 var re_order = function(media_element){
2367 var list_media = '';
2368 media_element.find('.winter_mvc-media-card').each(function(){
2369 if(list_media !='')
2370 list_media +=',';
2371
2372 list_media += $(this).attr('data-media-id');
2373 })
2374 media_element.closest('.postbox-upload-multiple').find('.logo_image_id').val(list_media);
2375 }
2376 /* Sort table */
2377 $( '.winter_mvc-media' ).sortable({
2378 update: function(event, ui) {
2379 re_order($(this));
2380 }
2381 });
2382 /* remove media */
2383 $( '.winter_mvc-media' ).find('.winter_mvc-media-card .remove').on('click', function(e){
2384 e.preventDefault();
2385 var media = $(this).closest('.winter_mvc-media')
2386 $(this).closest('.winter_mvc-media-card').remove();
2387 re_order(media)
2388 })
2389 });
2390 ";
2391
2392 echo "<script>".$custom_js."</script>";
2393
2394 ?>
2395
2396 <?php
2397 }
2398
2399
2400 if(!function_exists('wdk_access_check')) {
2401 /**
2402 * Generate listing card html
2403 *
2404 * @param array $listing The listing data.
2405 * @param array $settings The settings.
2406 * @param bool $json_output Encode for json, default false
2407 * @param string $html Html for sprintf(), where
2408 * %1$s - content
2409 * @return string
2410 */
2411 function wdk_access_check($model_name, $item_id, $user_id=NULL, $method='edit') {
2412
2413 if(!empty($item_id) && !is_numeric($item_id))
2414 exit('Issue with ID');
2415
2416 if (in_array($model_name, array('reviews_m','reviews_type_m','reviews_option_m','reviews_data_m'))) {
2417 global $Winter_MVC_wdk_reviews;
2418 $WMVC = $Winter_MVC_wdk_reviews;
2419 }elseif(in_array($model_name,array('package_m','payment_m'))) {
2420 global $Winter_MVC_wdk_payments;
2421 $WMVC = $Winter_MVC_wdk_payments;
2422 }elseif(in_array($model_name,array('favorite_m','favoritecategory_m'))) {
2423 global $Winter_MVC_wdk_favorites;
2424 $WMVC = $Winter_MVC_wdk_favorites;
2425 }elseif(in_array($model_name,array('currency_m'))) {
2426 global $Winter_MVC_wdk_currency;
2427 $WMVC = $Winter_MVC_wdk_currency;
2428 }elseif(in_array($model_name,array('calendar_m','price_m','reservation_m'))) {
2429 global $Winter_MVC_wdk_bookings;
2430 $WMVC = $Winter_MVC_wdk_bookings;
2431 }elseif(in_array($model_name,array('save_search_m'))) {
2432 global $Winter_MVC_wdk_save_search;
2433 $WMVC = $Winter_MVC_wdk_save_search;
2434 }elseif(in_array($model_name,array('messageschat_m'))) {
2435 global $Winter_MVC_wdk_messages_chat;
2436 $WMVC = $Winter_MVC_wdk_messages_chat;
2437 } else {
2438 $WMVC = &wdk_get_instance();
2439 }
2440
2441 if(empty($user_id))
2442 $user_id = get_current_user_id();
2443
2444 if(wmvc_user_in_role('administrator')) {
2445 return true;
2446 }
2447
2448 if(substr($model_name,-2,2) == '_m')
2449 {
2450 // its model
2451 $WMVC->model($model_name);
2452
2453 if(empty($item_id) || $WMVC->$model_name->is_related($item_id, $user_id, $method))
2454 {
2455 // User is related
2456 return true;
2457 }
2458 else
2459 {
2460 //echo $CI->db->last_query();
2461 exit('Access denied ROLES RELATED');
2462 }
2463 }
2464 else
2465 {
2466 return true;
2467 }
2468
2469 exit('Access denied ROLES');
2470
2471 }
2472 }
2473
2474 if ( ! function_exists('wdk_recaptcha_field'))
2475 {
2476 function wdk_recaptcha_field($is_compact=false, $style="", $load_script=true)
2477 {
2478 static $counter = 0;
2479 static $recaptcha_array = array();
2480
2481 if(get_option('wdk_recaptcha_site_key') !== FALSE && get_option('wdk_recaptcha_secret_key') !== NULL)
2482 {
2483 if($load_script && $counter===0)
2484 {
2485 echo "<script src='https://www.google.com/recaptcha/api.js?onload=CaptchaCallback&amp;render=explicit'></script>";
2486 }
2487 $counter++;
2488
2489 $compact_tag='';
2490 $size_tag='';
2491 if($is_compact)
2492 {
2493 $compact_tag='data-size="compact"';
2494 $size_tag='compact';
2495 }
2496
2497 $recaptcha_array[$counter] = array('size'=>$size_tag);
2498
2499 echo '<div id="recaptcha_called_'.$counter.'" class="g-recaptcha" style="'.$style.'" '.$compact_tag.' data-sitekey="'.get_option('wdk_recaptcha_site_key').'"></div>';
2500 ?>
2501
2502 <script>
2503 <?php if($counter===1)echo 'var ';?>CaptchaCallback = function(){
2504 <?php for($j=1;$j<=$counter;$j++): ?>
2505 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'); ?>'});
2506 <?php endfor; ?>
2507 };
2508 </script>
2509
2510 <?php
2511 }
2512 }
2513 }
2514
2515 function is_wdk_valid_recaptcha()
2516 {
2517 if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){
2518 //your site secret key
2519 if(wdk_valid_recaptcha_curl($_POST['g-recaptcha-response']))
2520 {
2521 return TRUE;
2522 }
2523 }
2524 return FALSE;
2525 }
2526
2527 function wdk_valid_recaptcha_curl($g_recaptcha_response='') {
2528 $url = 'https://www.google.com/recaptcha/api/siteverify';
2529 $args = array(
2530 'timeout' => 200,
2531 'blocking' => true,
2532 'headers' => array(),
2533 'body' => array(
2534 'secret' => get_option('wdk_recaptcha_secret_key'),
2535 'response' => $g_recaptcha_response,
2536 'remoteip' => sanitize_textarea_field($_SERVER['REMOTE_ADDR'])
2537 ),
2538 'cookies' => array()
2539 );
2540 $response = wp_remote_post( $url, $args );
2541
2542 if ( is_wp_error( $response ) ) {
2543 /*$error_message = $response->get_error_message();*/
2544 return true;
2545 } else {
2546 $response = json_decode($response['body']);
2547 return $response->success;
2548 }
2549 }
2550
2551 if(!function_exists('wdk_get_option')) {
2552 /**
2553 * Cached and get wp options
2554 *
2555 * @param string option Option key
2556 * @return string alt or title
2557 */
2558
2559 function wdk_get_option($option_key = '') {
2560 return get_option($option_key);
2561 if(isset($options[$option_key])) {
2562 return $options[$option_key];
2563 }
2564
2565 $options[$option_key] = get_option($option_key);
2566
2567 return $options[$option_key];
2568 }
2569 }
2570
2571 if(!function_exists('wdk_server_current_url')) {
2572 /**
2573 * Get current url basic on $_SERVER, exists function wdk_current_url(), on some urls have issue on listing preview page
2574 *
2575 * @return string url
2576 */
2577
2578 function wdk_server_current_url()
2579 {
2580 return (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
2581 }
2582 }
2583
2584
2585 if(!function_exists('wdk_filter_date_decimal')) {
2586 /**
2587 * Filter 00:00:00 from date
2588 *
2589 * @param string
2590 * @return string date without 00:00:00
2591 */
2592
2593 function wdk_filter_date_decimal($data)
2594 {
2595 return str_replace(' 00:00:00','', $data);
2596 }
2597 }
2598
2599 function wdk_get_post()
2600 {
2601 $post = array();
2602
2603 foreach($_POST as $key => $val)
2604 {
2605 if(is_array($val))
2606 {
2607 return wdk_clean($_POST);
2608 }
2609 else
2610 {
2611 if(strpos($val, '<iframe') === 0)
2612 $val = str_replace("'",'"', $val);
2613
2614 $post[sanitize_text_field($key)] = wp_kses_post($val);
2615 }
2616 }
2617
2618 return $post;
2619 }
2620
2621
2622 function wdk_get_get()
2623 {
2624 $log_array = array();
2625
2626 foreach($_GET as $key => $val)
2627 {
2628 if(is_array($val))
2629 {
2630 return wdk_clean($_POST);
2631 }
2632 else
2633 {
2634 $log_array[sanitize_text_field($key)] = wp_kses_post($val);
2635 }
2636 }
2637
2638 return $log_array;
2639 }
2640
2641 function wdk_clean($array)
2642 {
2643 $arr_cleaned = array();
2644 foreach($array as $key=>$val)
2645 {
2646 if(is_array($val))
2647 {
2648 $arr_cleaned[sanitize_text_field($key)] = wdk_clean($val);
2649 }
2650 else
2651 {
2652 $arr_cleaned[sanitize_text_field($key)] = wp_kses_post($val);
2653 }
2654
2655 }
2656
2657 //dump($arr_cleaned);
2658
2659 return $arr_cleaned;
2660 }
2661
2662 /*
2663 <select class="form-control" name="<?php echo 'control_operator_'.$i_fieldnum; ?>">
2664 <option value="CONTAINS">CONTAINS</option>
2665 <option value="NOT_CONTAINS">NOT_CONTAINS</option>
2666 </select>
2667 */
2668 function wdk_select_multi_option($field_name, $options = array(), $selected = NULL, $extra=NULL, $empty_text = NULL, $empty_val = '')
2669 {
2670 $output = '<select name="'.$field_name.'" '.$extra.' multiple="multiple">';
2671
2672 if(!is_null($empty_text))
2673 $output.= '<option value="'.esc_attr($empty_val).'">'.esc_html($empty_text).'</option>';
2674
2675 if(is_array($options) && count($options) > 0)
2676 foreach($options as $key=>$val)
2677 {
2678 $output.= '<option value="'.$key.'" '.($selected==$key?'selected':'').'>'.$val.'</option>';
2679 }
2680
2681 $output.= '</select>';
2682
2683 return $output;
2684 }
2685
2686
2687 if ( ! function_exists('wdk_treefield_select_ajax'))
2688 {
2689 /**
2690 * Return select2 ajax
2691 *
2692 * @param string option Option key
2693 * @return string alt or title
2694 */
2695 function wdk_treefield_select_ajax($name = '', $table=NULL, $selected = NULL,
2696 $column_print = 'category_title', $column_key = 'idcategory', $language_id=NULL, $empty_value='', $filter_ids = '', $attr = '')
2697 {
2698 $WMVC = &wdk_get_instance();
2699 $WMVC->model($table);
2700
2701 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
2702
2703 static $counter = 0;
2704 $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="">';
2705
2706
2707 if(false)
2708 if( $column_key == 'idcategory') {
2709 $form .= '<option selected="selected" value="">'.esc_html__('Select Category', 'wpdirectorykit').'</option>';
2710 } else {
2711 $form .= '<option selected="selected" value="">'.esc_html__('Select Location', 'wpdirectorykit').'</option>';
2712 }
2713
2714 if($selected) {
2715 if(is_array($selected)) {
2716
2717 $ids = array();
2718 foreach($selected as $selected_item) {
2719 if(!empty($selected_item)) {
2720 $ids [] = $selected_item;
2721 }
2722 }
2723
2724 /* where in */
2725 if(!empty($ids)){
2726 $WMVC->db->select($WMVC->$table->_table_name.'.*');
2727 $WMVC->db->where($WMVC->$table->_table_name.'.'.$column_key.' IN(' . implode(',', $ids) . ')', null, false);
2728 $WMVC->db->order_by('FIELD('.$WMVC->$table->_table_name.'.'.$column_key.', '. implode(',', $ids) . ')');
2729
2730 $results = $WMVC->$table->get();
2731 foreach ($results as $item) {
2732 if($item)
2733 $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>';
2734 }
2735 }
2736 } elseif(is_intval($selected)) {
2737 $db_item = $WMVC->$table->get($selected, TRUE);
2738 if($db_item)
2739 $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>';
2740 }
2741 } else {
2742 //$form .= '<option value="" selected="selected">'.esc_html__('Not selected', 'wpdirectorykit').'</option>';
2743 }
2744 $form .= '</select>';
2745
2746 //load javascript library
2747 if($counter==0)
2748 {
2749 wp_enqueue_script('select2');
2750 wp_enqueue_script('wdk-select2');
2751 wp_enqueue_style('select2');
2752 }
2753 ?>
2754 <?php
2755 $counter++;
2756 return $form;
2757 }
2758 }
2759
2760 if ( ! function_exists('wdk_user_select_ajax'))
2761 {
2762 /**
2763 * Return select2 ajax
2764 *
2765 * @param string option Option key
2766 * @return string alt or title
2767 */
2768 function wdk_user_select_ajax($name = '', $selected = NULL, $empty_value='', $filter_ids = '')
2769 {
2770 $WMVC = &wdk_get_instance();
2771
2772 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
2773
2774 static $counter = 0;
2775 $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="">';
2776 if($selected) {
2777 if(is_array($selected)) {
2778 /* where in */
2779 foreach ($selected as $item) {
2780 $user_data = get_userdata($item);
2781 if($user_data)
2782 $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>';
2783 }
2784 } elseif(is_intval($selected)) {
2785 $user_data = get_userdata($selected);
2786 if($user_data)
2787 $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>';
2788 }
2789 } else {
2790 //$form .= '<option value="" selected="selected">'.esc_html__('Not selected', 'wpdirectorykit').'</option>';
2791 }
2792 $form .= '</select>';
2793
2794 //load javascript library
2795 if($counter==0)
2796 {
2797 wp_enqueue_script('select2');
2798 wp_enqueue_script('wdk-select2');
2799 wp_enqueue_style('select2');
2800 }
2801 ?>
2802 <?php
2803 $counter++;
2804 return $form;
2805 }
2806 }
2807
2808
2809 /*
2810 <select class="form-control" name="<?php echo 'control_operator_'.$i_fieldnum; ?>">
2811 <option value="CONTAINS">CONTAINS</option>
2812 <option value="NOT_CONTAINS">NOT_CONTAINS</option>
2813 </select>
2814 */
2815 function wdk_select_option_multiple($field_name, $options = array(), $selected = array(), $extra=NULL, $empty_text = NULL, $empty_val = '')
2816 {
2817 $output = '<select name="'.$field_name.'" '.$extra.' multiple >';
2818
2819 if(!is_null($empty_text))
2820 $output.= '<option value="'.esc_attr($empty_val).'">'.esc_html($empty_text).'</option>';
2821
2822 if(is_array($options) && count($options) > 0)
2823 foreach($options as $key=>$val)
2824 {
2825 if(is_string($selected)) {
2826 $output.= '<option value="'.$key.'" '.(($selected == $key)?'selected="selected"':'').'>'.$val.'</option>';
2827 } else if(is_array($selected)){
2828 $output.= '<option value="'.$key.'" '.((in_array($key, $selected) === TRUE)?'selected="selected"':'').'>'.$val.'</option>';
2829 }
2830 }
2831
2832 $output.= '</select>';
2833
2834 return $output;
2835 }
2836
2837
2838
2839 if ( ! function_exists('wdk_convert_date_format_js'))
2840 {
2841 /**
2842 * Convert date format for support in js
2843 * From: https://wordpress.org/support/article/formatting-date-and-time/
2844 * To: https://momentjscom.readthedocs.io/en/latest/moment/04-displaying/01-format/
2845 *
2846 * @param string php date format Option key
2847 * @return string js date format
2848 */
2849 function wdk_convert_date_format_js($date_format)
2850 {
2851 $replaced = array(
2852 'D'=>'ddd',
2853 'j'=>'D',
2854 'd'=>'DD',
2855 'l'=>'dddd',
2856 'F'=>'MMMM',
2857 'Y'=>'YYYY',
2858 'S'=>'Do',
2859 'm'=>'MM',
2860 'n'=>'MM',
2861 'F'=>'MMMM',
2862 'M'=>'MMM',
2863 'Y'=>'YYYY',
2864 'y'=>'YY',
2865 'a'=>'a',
2866 'A'=>'A',
2867 'h'=>'hh',
2868 'G'=>'H',
2869 'H'=>'HH',
2870 'g'=>'h',
2871 'i'=>'mm',
2872 's'=>'ss',
2873 'T'=>'zz',
2874 'c'=>'',
2875 'r'=>'llll',
2876 'u'=>'x',
2877 );
2878
2879 $replaced_from = array_keys($replaced);
2880 $date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format);
2881 return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format);
2882 }
2883 }
2884
2885 if ( ! function_exists('wdk_convert_date_format_jquery'))
2886 {
2887 /**
2888 * Convert date format for support in js
2889 * From: https://wordpress.org/support/article/formatting-date-and-time/
2890 * To: https://api.jqueryui.com/datepicker/
2891 *
2892 * @param string php date format Option key
2893 * @return string js date format
2894 */
2895 function wdk_convert_date_format_jquery($date_format)
2896 {
2897 $replaced = array(
2898 'D'=>'D',
2899 'd'=>'dd',
2900 'j'=>'d',
2901 'l'=>'DD',
2902 'Y'=>'yy',
2903 'S'=>'d',
2904 'm'=>'mm',
2905 'n'=>'m',
2906 'M'=>'m',
2907 'F'=>'MM',
2908 'y'=>'y',
2909 'a'=>'',
2910 'A'=>'',
2911 'h'=>'',
2912 'G'=>'',
2913 'H'=>'',
2914 'g'=>'',
2915 'i'=>'',
2916 's'=>'',
2917 'T'=>'',
2918 'c'=>'ISO_8601',
2919 'r'=>'RFC_2822',
2920 'u'=>'@',
2921 ':'=>'',
2922 );
2923
2924 $replaced_from = array_keys($replaced);
2925 $date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format);
2926 return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format);
2927 }
2928 }
2929
2930 if ( ! function_exists('wdk_convert_date_format_jquery'))
2931 {
2932 /**
2933 * Convert date format for support in js
2934 * From: https://wordpress.org/support/article/formatting-date-and-time/
2935 * To: https://api.jqueryui.com/datepicker/
2936 *
2937 * @param string php date format Option key
2938 * @return string js date format
2939 */
2940 function wdk_convert_date_format_jquery($date_format)
2941 {
2942 $replaced = array(
2943 'D'=>'D',
2944 'd'=>'dd',
2945 'j'=>'d',
2946 'l'=>'DD',
2947 'Y'=>'yy',
2948 'S'=>'d',
2949 'm'=>'mm',
2950 'n'=>'m',
2951 'M'=>'m',
2952 'F'=>'MM',
2953 'y'=>'y',
2954 'a'=>'',
2955 'A'=>'',
2956 'h'=>'',
2957 'G'=>'',
2958 'H'=>'',
2959 'g'=>'',
2960 'i'=>'',
2961 's'=>'',
2962 'T'=>'',
2963 'c'=>'ISO_8601',
2964 'r'=>'RFC_2822',
2965 'u'=>'@',
2966 ':'=>'',
2967 );
2968
2969 $replaced_from = array_keys($replaced);
2970 $date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format);
2971 return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format);
2972 }
2973 }
2974
2975 if ( ! function_exists('wdk_get_gps'))
2976 {
2977
2978 /**
2979 * Get Latitude/Longitude/Altitude based on an address
2980 * @param string $address The address for converting into coordinates
2981 * @return array An array containing Latitude/Longitude/Altitude data
2982 */
2983 function wdk_get_gps($address = '')
2984 {
2985 static $results = array();
2986 $address = str_replace(' ','+',$address);
2987
2988 if(!isset($results[$address])) {
2989 $results[$address] = NULL;
2990 $url = 'https://nominatim.openstreetmap.org/search?format=json&q=' . $address;
2991 $request = wp_remote_get( $url );
2992 $response = '';
2993
2994 // request failed
2995 if ( is_wp_error( $request ) ) {
2996 $response = $request;
2997 }
2998 $code = (int) wp_remote_retrieve_response_code( $request );
2999
3000 // make sure the fetch was successful
3001 if (empty($response) && $code == 200 ) {
3002 $response = wp_remote_retrieve_body( $request );
3003 // Decode the json
3004 $resp = json_decode( $response, true );
3005
3006 if(!empty($resp) && isset($resp[0]) && isset($resp[0]['lat']) && isset($resp[0]['lon'])) {
3007 $results[$address] = array('lat' => $resp[0]['lat'], 'lng' => $resp[0]['lon'], 'alt' => 0);
3008 return $results[$address];
3009 }
3010 }
3011 } else {
3012 return $results[$address];
3013 }
3014 return false;
3015 }
3016 }
3017
3018 if ( ! function_exists('wdk_get_gps_google'))
3019 {
3020
3021 /**
3022 * Get Latitude/Longitude/Altitude based on an address from Google Api
3023 * @param string $address The address for converting into coordinates
3024 * @param string $api_key Custom google API Key
3025 *
3026 * @return array An array containing Latitude/Longitude/Altitude data
3027 */
3028 function wdk_get_gps_google($address = '', $api_key = NULL)
3029 {
3030 static $results = array();
3031
3032 if ( empty( $api_key ) ) {
3033 $api_key = wdk_get_option('wdk_geo_google_api_key');
3034 }
3035
3036 $address = str_replace(' ','+',$address);
3037
3038 if(!isset($results[$address])) {
3039 $results[$address] = NULL;
3040 $url = 'https://maps.googleapis.com/maps/api/geocode/json?address='.trim($address).'&key='.$api_key;
3041 $request = wp_remote_get( $url );
3042 $response = '';
3043
3044 // request failed
3045 if ( is_wp_error( $request ) ) {
3046 $response = $request;
3047 }
3048 $code = (int) wp_remote_retrieve_response_code( $request );
3049
3050 // make sure the fetch was successful
3051 if (empty($response) && $code == 200 ) {
3052 $response = wp_remote_retrieve_body( $request );
3053 // Decode the json
3054 $resp = json_decode( $response, true );
3055 $status = $resp['status'];
3056
3057 //if request status is successful
3058 if($status == "OK"){
3059 //get address from json data
3060 $lat = $resp['results'][0]['geometry']['location']['lat'];
3061 $lng = $resp['results'][0]['geometry']['location']['lng'];
3062
3063 $results[$address] = array('lat' => $lat , 'lng' => $lng, 'alt' => 0);
3064 return $results[$address];
3065 }
3066 }
3067 } else {
3068 return $results[$address];
3069 }
3070
3071 return false;
3072 }
3073 }
3074
3075
3076 if ( ! function_exists('wdk_getDueCoords'))
3077 {
3078 // Modified from:
3079 // http://www.sitepoint.com/forums/showthread.php?656315-adding-distance-gps-coordinates-get-bounding-box
3080 /**
3081 * bearing is 0 = north, 180 = south, 90 = east, 270 = west
3082 *
3083 */
3084 function wdk_getDueCoords($latitude, $longitude, $bearing, $distance, $distance_unit = "km", $return_as_array = FALSE) {
3085
3086 if ($distance_unit == "m") {
3087 // Distance is in miles.
3088 $radius = 3963.1676;
3089 }
3090 else {
3091 // distance is in km.
3092 $radius = 6378.1;
3093 }
3094
3095 // New latitude in degrees.
3096 $new_latitude = rad2deg(asin(sin(deg2rad($latitude)) * cos($distance / $radius) + cos(deg2rad($latitude)) * sin($distance / $radius) * cos(deg2rad($bearing))));
3097
3098 // New longitude in degrees.
3099 $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))));
3100
3101 if ($return_as_array) {
3102 // Assign new latitude and longitude to an array to be returned to the caller.
3103 $coord = array();
3104 $coord['lat'] = $new_latitude;
3105 $coord['lng'] = $new_longitude;
3106 }
3107 else {
3108 $coord = $new_latitude . ", " . $new_longitude;
3109 }
3110
3111 return $coord;
3112
3113 }
3114 }
3115
3116 if ( ! function_exists('wdk_is_gps'))
3117 {
3118 // Validation gps
3119 /**
3120 * @param string $string_gps gps in string like xx.xxxx,xx.xxxxx
3121 * @return bool
3122 */
3123 function wdk_is_gps($string_gps = '') {
3124 if(preg_match('/^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$/', $string_gps)) {
3125 return true;
3126 }
3127
3128 return false;
3129 }
3130 }
3131
3132
3133 if ( ! function_exists('wdk_is_phone'))
3134 {
3135 // Validation phone
3136 /**
3137 * @param string $value phone in string
3138 * @return bool
3139 */
3140 function wdk_is_phone($value = '') {
3141 if(preg_match("/^[.+]{0,1}[0-9-)(]{0,25}$/", $value)) {
3142 return true;
3143 }
3144
3145 return false;
3146 }
3147 }
3148
3149 if ( ! function_exists('wdk_filter_phone'))
3150 {
3151 // Validation phone
3152 /**
3153 * @param string $value phone in string
3154 * @return bool
3155 */
3156 function wdk_filter_phone($value = '') {
3157 return str_replace(array(' ','-','(',')'),'',$value);
3158 }
3159 }
3160
3161
3162 if ( ! function_exists('wdk_generate_media_field'))
3163 {
3164 // Based on value return video embed, youtube, source video tag
3165 /**
3166 * @param string $value value
3167 * @param string $class help css class
3168 * @return string html or NULL
3169 */
3170 function wdk_generate_media_field($value = '', $class="wdk-image") {
3171 $output = NULL;
3172
3173 if(strpos($value, 'vimeo.com') !== FALSE)
3174 {
3175 $output = wp_oembed_get($value, array("width"=>"800", "height"=>"450"));
3176 $output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output);
3177 }
3178 elseif(strpos($value, 'watch?v=') !== FALSE)
3179 {
3180 $embed_code = substr($value, strpos($value, 'watch?v=')+8);
3181 $output = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455"));
3182 $output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output );
3183 }
3184 elseif(strpos($value, 'youtu.be/') !== FALSE)
3185 {
3186 $embed_code = substr($value, strpos($value, 'youtu.be/')+9);
3187 $output = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455"));
3188 $output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output );
3189 }
3190 elseif(strpos($value, 'youtube.com/embed/') !== FALSE)
3191 {
3192 $embed_code = substr($value, strpos($value, 'youtube.com/embed/')+18);
3193 $output = wp_oembed_get('https://www.youtube.com/watch?v='.$embed_code, array("width"=>"800", "height"=>"455"));
3194 $output = str_replace( '<iframe', '<iframe class="'.$class.'" ', $output );
3195 }
3196 elseif(filter_var($value, FILTER_VALIDATE_URL) !== FALSE && preg_match('/\.(mp4|flv|wmw|ogv|webm|ogg)$/i', $value))
3197 {
3198 $output = '<video src="'.$value.'" controls class="'.$class.'"></video> ';
3199 }
3200
3201 return $output;
3202 }
3203 }
3204
3205
3206 if ( ! function_exists('wdk_depend_get_hidden_fields'))
3207 {
3208 // Based on value return video embed, youtube, source video tag
3209 /**
3210 * @param int $tree_id tree_id of category
3211 * @param string $type type, default 'categories'
3212 * @return string string with hidden fields like ,1,2,3,4, or NULL
3213 */
3214 function wdk_depend_get_hidden_fields($tree_id = NULL, $type="categories") {
3215 static $output = array();
3216
3217 if(isset($output[$tree_id])) {
3218 return $output[$tree_id];
3219 }
3220 if(empty($tree_id)) {
3221 return NULL;
3222 } else {
3223 $output[$tree_id] = false;
3224
3225 global $Winter_MVC_WDK;
3226 $Winter_MVC_WDK->model('dependfields_m');
3227
3228 $depend_fields = $Winter_MVC_WDK->dependfields_m->get_by(array('field_id' => $tree_id,'main_field' => $type), TRUE);
3229
3230 if($depend_fields && !empty($depend_fields->hidden_fields_list)) {
3231 $output[$tree_id] = ','.$depend_fields->hidden_fields_list. ',';
3232 }
3233 return $output[$tree_id];
3234 }
3235
3236 return false;
3237 }
3238 }
3239
3240 if ( ! function_exists('wdk_depend_is_hidden_field'))
3241 {
3242 // Based on value return video embed, youtube, source video tag
3243 /**
3244 * @param int $field_id field_id
3245 * @param int $tree_id id for category
3246 * @param string $type type, default 'categories'
3247 * @return string string with hidden fields like ,1,2,3,4, or NULL
3248 */
3249 function wdk_depend_is_hidden_field($field_id = NULL, $tree_id = NULL, $type="categories") {
3250 $hidden_fields = wdk_depend_get_hidden_fields($tree_id, $type);
3251 if($hidden_fields && strpos($hidden_fields, ','.trim($field_id).',') !== FALSE) {
3252 return true;
3253 }
3254
3255 return false;
3256 }
3257 }
3258
3259
3260 if ( ! function_exists('is_wdk_slug_format'))
3261 {
3262 function is_wdk_slug_format($string)
3263 {
3264 if(empty($string))return FALSE;
3265
3266
3267 if (preg_match("/^[a-z0-9-_]+\$/", $string)) {
3268
3269 return TRUE;
3270 }
3271
3272 return FALSE;
3273 }
3274 }
3275
3276 if ( ! function_exists('wdk_number_format_i18n'))
3277 {
3278 function wdk_number_format_i18n($value)
3279 {
3280 if(empty($value))return NULL;
3281
3282
3283 $value = filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
3284 $value = (float)str_replace(array(","," ",'&nbsp;'), "", $value);
3285
3286 return number_format_i18n($value);
3287 }
3288 }
3289
3290 if ( ! function_exists('wdk_currency_symbol'))
3291 {
3292 /**
3293 * Return currency symbol
3294 *
3295 * @return string currency symbol
3296 */
3297 function wdk_currency_symbol()
3298 {
3299
3300 if(function_exists('get_woocommerce_currency_symbol'))
3301 return get_woocommerce_currency_symbol();
3302
3303 if(wdk_get_option('wdk_default_currency_symbol'))
3304 return wdk_get_option('wdk_default_currency_symbol');
3305
3306 return '$';
3307 }
3308 }
3309
3310 if ( ! function_exists('wdk_generate_path_image'))
3311 {
3312 /**
3313 * Generate path of images
3314 *
3315 * @param string $id or ids of images, separeted by comma
3316 * @param bool $multi multi images, separeted by comma
3317 * @param int $limit limit characters for path
3318 * @param int $limit limit images for path
3319 *
3320 * @return string with path of image or multi images
3321 */
3322 function wdk_generate_path_image($ids = NULL, $multi = FALSE, $limit = 95, $limit_images = 10)
3323 {
3324 $path = '';
3325 if(empty($ids))
3326 return $path;
3327
3328 $image_ids = explode(',', $ids);
3329 $count_images = 0;
3330 if(is_array($image_ids)) {
3331 foreach ($image_ids as $image_id) {
3332 if(is_numeric($image_id))
3333 {
3334
3335 if($count_images>=$limit_images)
3336 break;
3337
3338 $image_path = wp_get_original_image_path($image_id);
3339 if($image_path) {
3340 /* path of image */
3341 $next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path);
3342
3343 /* check length listing_images_path + next image + comma, should be less then $limit */
3344 if(strlen($path.$next_path)<$limit) {
3345
3346 if($multi) {
3347 if(!empty($path))
3348 $path .= ',';
3349 }
3350
3351 $path .= $next_path;
3352 }
3353
3354 if(!$multi)
3355 break;
3356
3357 $count_images++;
3358 }
3359 }
3360 }
3361 }
3362
3363 return $path;
3364 }
3365 }
3366
3367 if ( ! function_exists('wdk_booking_currency_symbol'))
3368 {
3369 /**
3370 * Return currency symbol
3371 *
3372 * @return string currency symbol
3373 */
3374 function wdk_booking_currency_symbol()
3375 {
3376
3377 if(function_exists('get_woocommerce_currency_symbol'))
3378 return get_woocommerce_currency_symbol();
3379
3380 if(wdk_get_option('wdk_default_currency_symbol'))
3381 return wdk_get_option('wdk_default_currency_symbol');
3382
3383 return '$';
3384 }
3385 }
3386
3387 if ( ! function_exists('wdk_generated_cached_row_userdata'))
3388 {
3389 /**
3390 * Return currency symbol
3391 *
3392 * @return string currency symbol
3393 */
3394 function wdk_generated_cached_row_userdata($row)
3395 {
3396 $user_data = array();
3397
3398 $user_data['display_name'] = wmvc_show_data('cacheduser_display_name', $row);
3399 $user_data['user_email'] = wmvc_show_data('cacheduser_email', $row);
3400 $user_data['profile_url'] = wmvc_show_data('cacheduser_profile_url', $row);
3401 $user_data['avatar_url'] = wmvc_show_data('cacheduser_avatar_url', $row);
3402
3403 /* meta */
3404 $user_data['wdk_address'] = wmvc_show_data('cacheduser_wdk_address', $row);
3405 $user_data['wdk_phone'] = wmvc_show_data('cacheduser_wdk_phone', $row);
3406 $user_data['wdk_city'] = wmvc_show_data('cacheduser_wdk_city', $row);
3407 $user_data['wdk_company_name'] = wmvc_show_data('cacheduser_wdk_company_name', $row);
3408 $user_data['wdk_facebook'] = wmvc_show_data('cacheduser_wdk_facebook', $row);
3409 $user_data['wdk_youtube'] = wmvc_show_data('cacheduser_wdk_youtube', $row);
3410 $user_data['wdk_linkedin'] = wmvc_show_data('cacheduser_wdk_linkedin', $row);
3411 $user_data['wdk_twitter'] = wmvc_show_data('cacheduser_wdk_twitter', $row);
3412 $user_data['wdk_instagram'] = wmvc_show_data('cacheduser_wdk_instagram', $row);
3413 $user_data['wdk_whatsapp'] = wmvc_show_data('cacheduser_wdk_whatsapp', $row);
3414 $user_data['wdk_viber'] = wmvc_show_data('cacheduser_wdk_viber', $row);
3415 $user_data['wdk_iban'] = wmvc_show_data('cacheduser_wdk_iban', $row);
3416 $user_data['wdk_telegram'] = wmvc_show_data('cacheduser_wdk_telegram', $row);
3417 $user_data['wdk_position_title'] = wmvc_show_data('cacheduser_wdk_position_title', $row);
3418 $user_data['description'] = wmvc_show_data('cacheduser_description', $row);
3419 $user_data['user_url'] = wmvc_show_data('cacheduser_user_url', $row);
3420 $user_data['roles'] = explode(',', wmvc_show_data('cacheduser_roles', $value));
3421
3422 return $user_data;
3423 }
3424 }
3425
3426 if ( ! function_exists('wdk_mime2extd'))
3427 {
3428 /**
3429 * Return currency symbol
3430 *
3431 * @return string currency symbol
3432 */
3433 function wdk_mime2ext($mime) {
3434 $mime_map = [
3435 'video/3gpp2' => '3g2',
3436 'video/3gp' => '3gp',
3437 'video/3gpp' => '3gp',
3438 'application/x-compressed' => '7zip',
3439 'audio/x-acc' => 'aac',
3440 'audio/ac3' => 'ac3',
3441 'application/postscript' => 'ai',
3442 'audio/x-aiff' => 'aif',
3443 'audio/aiff' => 'aif',
3444 'audio/x-au' => 'au',
3445 'video/x-msvideo' => 'avi',
3446 'video/msvideo' => 'avi',
3447 'video/avi' => 'avi',
3448 'application/x-troff-msvideo' => 'avi',
3449 'application/macbinary' => 'bin',
3450 'application/mac-binary' => 'bin',
3451 'application/x-binary' => 'bin',
3452 'application/x-macbinary' => 'bin',
3453 'image/bmp' => 'bmp',
3454 'image/x-bmp' => 'bmp',
3455 'image/x-bitmap' => 'bmp',
3456 'image/x-xbitmap' => 'bmp',
3457 'image/x-win-bitmap' => 'bmp',
3458 'image/x-windows-bmp' => 'bmp',
3459 'image/ms-bmp' => 'bmp',
3460 'image/x-ms-bmp' => 'bmp',
3461 'application/bmp' => 'bmp',
3462 'application/x-bmp' => 'bmp',
3463 'application/x-win-bitmap' => 'bmp',
3464 'application/cdr' => 'cdr',
3465 'application/coreldraw' => 'cdr',
3466 'application/x-cdr' => 'cdr',
3467 'application/x-coreldraw' => 'cdr',
3468 'image/cdr' => 'cdr',
3469 'image/x-cdr' => 'cdr',
3470 'zz-application/zz-winassoc-cdr' => 'cdr',
3471 'application/mac-compactpro' => 'cpt',
3472 'application/pkix-crl' => 'crl',
3473 'application/pkcs-crl' => 'crl',
3474 'application/x-x509-ca-cert' => 'crt',
3475 'application/pkix-cert' => 'crt',
3476 'text/css' => 'css',
3477 'text/x-comma-separated-values' => 'csv',
3478 'text/comma-separated-values' => 'csv',
3479 'application/vnd.msexcel' => 'csv',
3480 'application/x-director' => 'dcr',
3481 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
3482 'application/x-dvi' => 'dvi',
3483 'message/rfc822' => 'eml',
3484 'application/x-msdownload' => 'exe',
3485 'video/x-f4v' => 'f4v',
3486 'audio/x-flac' => 'flac',
3487 'video/x-flv' => 'flv',
3488 'image/gif' => 'gif',
3489 'application/gpg-keys' => 'gpg',
3490 'application/x-gtar' => 'gtar',
3491 'application/x-gzip' => 'gzip',
3492 'application/mac-binhex40' => 'hqx',
3493 'application/mac-binhex' => 'hqx',
3494 'application/x-binhex40' => 'hqx',
3495 'application/x-mac-binhex40' => 'hqx',
3496 'text/html' => 'html',
3497 'image/x-icon' => 'ico',
3498 'image/x-ico' => 'ico',
3499 'image/vnd.microsoft.icon' => 'ico',
3500 'text/calendar' => 'ics',
3501 'application/java-archive' => 'jar',
3502 'application/x-java-application' => 'jar',
3503 'application/x-jar' => 'jar',
3504 'image/jp2' => 'jp2',
3505 'video/mj2' => 'jp2',
3506 'image/jpx' => 'jp2',
3507 'image/jpm' => 'jp2',
3508 'image/jpeg' => 'jpeg',
3509 'image/pjpeg' => 'jpeg',
3510 'application/x-javascript' => 'js',
3511 'application/json' => 'json',
3512 'text/json' => 'json',
3513 'application/vnd.google-earth.kml+xml' => 'kml',
3514 'application/vnd.google-earth.kmz' => 'kmz',
3515 'text/x-log' => 'log',
3516 'audio/x-m4a' => 'm4a',
3517 'application/vnd.mpegurl' => 'm4u',
3518 'audio/midi' => 'mid',
3519 'application/vnd.mif' => 'mif',
3520 'video/quicktime' => 'mov',
3521 'video/x-sgi-movie' => 'movie',
3522 'audio/mpeg' => 'mp3',
3523 'audio/mpg' => 'mp3',
3524 'audio/mpeg3' => 'mp3',
3525 'audio/mp3' => 'mp3',
3526 'video/mp4' => 'mp4',
3527 'video/mpeg' => 'mpeg',
3528 'application/oda' => 'oda',
3529 'application/vnd.oasis.opendocument.text' => 'odt',
3530 'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
3531 'application/vnd.oasis.opendocument.presentation' => 'odp',
3532 'audio/ogg' => 'ogg',
3533 'video/ogg' => 'ogg',
3534 'application/ogg' => 'ogg',
3535 'application/x-pkcs10' => 'p10',
3536 'application/pkcs10' => 'p10',
3537 'application/x-pkcs12' => 'p12',
3538 'application/x-pkcs7-signature' => 'p7a',
3539 'application/pkcs7-mime' => 'p7c',
3540 'application/x-pkcs7-mime' => 'p7c',
3541 'application/x-pkcs7-certreqresp' => 'p7r',
3542 'application/pkcs7-signature' => 'p7s',
3543 'application/pdf' => 'pdf',
3544 'application/octet-stream' => 'pdf',
3545 'application/x-x509-user-cert' => 'pem',
3546 'application/x-pem-file' => 'pem',
3547 'application/pgp' => 'pgp',
3548 'application/x-httpd-php' => 'php',
3549 'application/php' => 'php',
3550 'application/x-php' => 'php',
3551 'text/php' => 'php',
3552 'text/x-php' => 'php',
3553 'application/x-httpd-php-source' => 'php',
3554 'image/png' => 'png',
3555 'image/x-png' => 'png',
3556 'application/powerpoint' => 'ppt',
3557 'application/vnd.ms-powerpoint' => 'ppt',
3558 'application/vnd.ms-office' => 'ppt',
3559 'application/msword' => 'doc',
3560 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
3561 'application/x-photoshop' => 'psd',
3562 'image/vnd.adobe.photoshop' => 'psd',
3563 'audio/x-realaudio' => 'ra',
3564 'audio/x-pn-realaudio' => 'ram',
3565 'application/x-rar' => 'rar',
3566 'application/rar' => 'rar',
3567 'application/x-rar-compressed' => 'rar',
3568 'audio/x-pn-realaudio-plugin' => 'rpm',
3569 'application/x-pkcs7' => 'rsa',
3570 'text/rtf' => 'rtf',
3571 'text/richtext' => 'rtx',
3572 'video/vnd.rn-realvideo' => 'rv',
3573 'application/x-stuffit' => 'sit',
3574 'application/smil' => 'smil',
3575 'text/srt' => 'srt',
3576 'image/svg+xml' => 'svg',
3577 'application/x-shockwave-flash' => 'swf',
3578 'application/x-tar' => 'tar',
3579 'application/x-gzip-compressed' => 'tgz',
3580 'image/tiff' => 'tiff',
3581 'text/plain' => 'txt',
3582 'text/x-vcard' => 'vcf',
3583 'application/videolan' => 'vlc',
3584 'text/vtt' => 'vtt',
3585 'audio/x-wav' => 'wav',
3586 'audio/wave' => 'wav',
3587 'audio/wav' => 'wav',
3588 'application/wbxml' => 'wbxml',
3589 'video/webm' => 'webm',
3590 'audio/x-ms-wma' => 'wma',
3591 'application/wmlc' => 'wmlc',
3592 'video/x-ms-wmv' => 'wmv',
3593 'video/x-ms-asf' => 'wmv',
3594 'application/xhtml+xml' => 'xhtml',
3595 'application/excel' => 'xl',
3596 'application/msexcel' => 'xls',
3597 'application/x-msexcel' => 'xls',
3598 'application/x-ms-excel' => 'xls',
3599 'application/x-excel' => 'xls',
3600 'application/x-dos_ms_excel' => 'xls',
3601 'application/xls' => 'xls',
3602 'application/x-xls' => 'xls',
3603 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
3604 'application/vnd.ms-excel' => 'xlsx',
3605 'application/xml' => 'xml',
3606 'text/xml' => 'xml',
3607 'text/xsl' => 'xsl',
3608 'application/xspf+xml' => 'xspf',
3609 'application/x-compress' => 'z',
3610 'application/x-zip' => 'zip',
3611 'application/zip' => 'zip',
3612 'application/x-zip-compressed' => 'zip',
3613 'application/s-compressed' => 'zip',
3614 'multipart/x-zip' => 'zip',
3615 'text/x-scriptzsh' => 'zsh',
3616 ];
3617
3618 return isset($mime_map[$mime]) === true ? $mime_map[$mime] : false;
3619 }
3620 }
3621
3622 if ( ! function_exists('wdk_is_dash_enabled'))
3623 {
3624 /**
3625 * IS Dash pages exists
3626 *
3627 * @return bool true if exists dash
3628 */
3629 function wdk_is_dash_enabled() {
3630 if(function_exists('run_wdk_membership') && wdk_get_option('wdk_membership_dash_page') && get_post_status(wdk_get_option('wdk_membership_dash_page')) =='publish'){
3631 return true;
3632 }
3633
3634 return false;
3635 }
3636 }
3637
3638 if(!function_exists('wdk_page_by_title')) {
3639 function wdk_page_by_title ( $page_title, $output = OBJECT, $post_type = 'page' ) {
3640 global $wpdb;
3641
3642 if ( is_array( $post_type ) ) {
3643 $post_type = esc_sql( $post_type );
3644 $post_type_in_string = "'" . implode( "','", $post_type ) . "'";
3645 $sql = $wpdb->prepare(
3646 "
3647 SELECT ID
3648 FROM $wpdb->posts
3649 WHERE post_title = %s
3650 AND post_type IN ($post_type_in_string)
3651 ",
3652 $page_title
3653 );
3654 } else {
3655 $sql = $wpdb->prepare(
3656 "
3657 SELECT ID
3658 FROM $wpdb->posts
3659 WHERE post_title = %s
3660 AND post_type = %s
3661 ",
3662 $page_title,
3663 $post_type
3664 );
3665 }
3666
3667 $page = $wpdb->get_var( $sql );
3668
3669 if ( $page ) {
3670 return get_post( $page, $output );
3671 }
3672
3673 return null;
3674 }
3675 }
3676
3677
3678 if ( ! function_exists('is_wdk_gps_single'))
3679 {
3680 function is_wdk_gps_single($param)
3681 {
3682
3683 if (is_numeric($param) && $param > -180 && $param < 180) {
3684 return true;
3685 }
3686
3687 return false;
3688 }
3689 }
3690
3691 if ( ! function_exists('wdk_get_tgmpa_link'))
3692 {
3693 function wdk_get_tgmpa_link()
3694 {
3695 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')) {
3696 return get_admin_url() . "themes.php?page=tgmpa-install-plugins";
3697 } else {
3698 return get_admin_url() . "plugins.php?page=tgmpa-install-plugins";
3699 }
3700
3701 return false;
3702 }
3703 }
3704
3705 if ( ! function_exists('wdk_sprintf'))
3706 {
3707 function wdk_sprintf($string = '')
3708 {
3709 $arg_list = func_get_args();
3710
3711 if(count($arg_list)<2) {
3712 return $string;
3713 }
3714
3715 if(stripos($string, '%1$s') === FALSE) {
3716 return $string;
3717 }
3718
3719 return call_user_func_array("sprintf", $arg_list);
3720 }
3721 }
3722
3723 if ( ! function_exists('wdk_db_table'))
3724 {
3725 function wdk_db_table($data, $columns = array()) {
3726 $output = '<table>';
3727 foreach($data as $key => $var) {
3728 if($key === 0)
3729 {
3730 $output .= '<tr>';
3731 foreach($var as $k => $v) {
3732 if(count($columns) > 0 && !in_array($k, $columns))continue;
3733
3734 $output .= '<td><strong>' . $k . '</strong></td>';
3735 }
3736 $output .= '</tr>';
3737 }
3738
3739 $output .= '<tr>';
3740 foreach($var as $k => $v) {
3741 if(count($columns) > 0 && !in_array($k, $columns))continue;
3742
3743 $output .= '<td>' . $v . '</td>';
3744 }
3745 $output .= '</tr>';
3746 }
3747 $output .= '</table>';
3748 echo $output;
3749 }
3750 }
3751 ?>