PluginProbe
WP Directory Kit / 1.2.4
WP Directory Kit v1.2.4
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.4, at application/helpers/Basic.php

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