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

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

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