PluginProbe
WP Directory Kit / 1.4.8
WP Directory Kit v1.4.8
1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 All 36 releases
← All changes | application/helpers/Basic.php +1641 -132 1.2.71.4.8 View file →
@@ -3,9 +3,9 @@
3 3 if ( ! defined( 'ABSPATH' ) ) {
4 4 exit; // Exit if accessed directly.
5 5 }
6 6
7 -function wdk_generate_fields($fields, $db_data)
7 +function wdk_generate_fields($fields, $db_data, $form = NULL)
8 8 {
9 9 if(is_array($fields))
10 10 foreach($fields as $field)
11 11 {
@@ -107,8 +107,18 @@
107 107 "suffix" => '',
108 108 "values_list" => '',
109 109 "placeholder" => '',
110 110 );
111 + }else if(function_exists('run_wdk_bookings') && $used_field->field_id == 'booking_guest') {
112 + $field = array(
113 + "idfield" => 'booking_guest',
114 + "field_type" => 'NUMBER',
115 + "field_label" => __('Booking Max Guests', 'wpdirectorykit'),
116 + "prefix" => '',
117 + "suffix" => '',
118 + "values_list" => '',
119 + "placeholder" => '',
120 + );
111 121 }else if($used_field->field_id == 'more') {
112 122 $field = array(
113 123 "idfield" => 'MORE',
114 124 "field_type" => 'MORE',
@@ -140,9 +150,10 @@
140 150 "field_label" =>wmvc_show_data('field_label', $field_data),
141 151 "prefix" => wmvc_show_data('prefix', $field_data),
142 152 "suffix" => wmvc_show_data('suffix', $field_data),
143 153 "values_list" => wmvc_show_data('values_list', $field_data),
144 - "placeholder" => wmvc_show_data('placeholder', $field_data)
154 + "placeholder" => wmvc_show_data('placeholder', $field_data),
155 + "is_select_2_ajax_field_db_suggestion" => wmvc_show_data('is_select_2_ajax_field_db_suggestion', $used_field),
145 156 );
146 157 }
147 158 }
148 159 }
@@ -187,8 +198,178 @@
187 198 return $output;
188 199 }
189 200 }
190 201
202 +if ( ! function_exists('wdk_generate_search_form_fields_elementor'))
203 +{
204 + function wdk_generate_search_form_fields_elementor($fields_array = array(), $subfolder='', $print = TRUE, $predefinedfields_query = array())
205 + {
206 + /* load WMVC data */
207 + $WMVC = &wdk_get_instance();
208 + $WMVC->model('searchform_m');
209 + $WMVC->model('field_m');
210 + $output = '';
211 +
212 + foreach ($fields_array as $key => $el_field_data) {
213 + $field_id = wmvc_show_data('field_id', $el_field_data, '');
214 + if(empty($field_id)) continue;
215 +
216 + if(strpos($field_id,'__') !== FALSE){
217 + $field_id = substr($field_id, strpos($field_id,'__')+2);
218 + }
219 +
220 + $field = NULL;
221 + if($field_id == 'category_id') {
222 + $field = array(
223 + "idfield" => 'category',
224 + "field_type" => 'CATEGORY',
225 + "field_label" => __('Category', 'wpdirectorykit'),
226 + "prefix" => '',
227 + "suffix" => '',
228 + "values_list" => '',
229 + "placeholder" => '',
230 + );
231 + }else if($field_id == 'location_id') {
232 + $field = array(
233 + "idfield" => 'location',
234 + "field_type" => 'LOCATION',
235 + "field_label" => __('Location', 'wpdirectorykit'),
236 + "prefix" => '',
237 + "suffix" => '',
238 + "values_list" => '',
239 + "placeholder" => '',
240 + );
241 + }else if($field_id == 'address') {
242 + $field = array(
243 + "idfield" => 'address',
244 + "field_type" => 'INPUTBOX',
245 + "field_label" => __('Address', 'wpdirectorykit'),
246 + "prefix" => '',
247 + "suffix" => '',
248 + "values_list" => '',
249 + "placeholder" => '',
250 + );
251 + }else if($field_id == 'post_title') {
252 + $field = array(
253 + "idfield" => 'post_title',
254 + "field_type" => 'INPUTBOX',
255 + "field_label" => __('Title', 'wpdirectorykit'),
256 + "prefix" => '',
257 + "suffix" => '',
258 + "values_list" => '',
259 + "placeholder" => '',
260 + );
261 + }else if($field_id == 'search') {
262 + $field = array(
263 + "idfield" => 'search',
264 + "field_type" => 'INPUTBOX',
265 + "field_label" => __('Search', 'wpdirectorykit'),
266 + "prefix" => '',
267 + "suffix" => '',
268 + "values_list" => '',
269 + "placeholder" => '',
270 + );
271 + }else if(function_exists('run_wdk_bookings') && $field_id == 'booking_date') {
272 + $field = array(
273 + "idfield" => 'booking_date',
274 + "field_type" => 'BOOKINGS_DATE',
275 + "field_label" => __('Booking Date', 'wpdirectorykit'),
276 + "prefix" => '',
277 + "suffix" => '',
278 + "values_list" => '',
279 + "placeholder" => '',
280 + );
281 + }else if($field_id == 'more') {
282 + $field = array(
283 + "idfield" => 'MORE',
284 + "field_type" => 'MORE',
285 + "field_label" => __('MORE', 'wpdirectorykit'),
286 + "prefix" => '',
287 + "suffix" => '',
288 + "values_list" => '',
289 + "placeholder" => '',
290 + );
291 + } else {
292 + $field_data = $WMVC->field_m->get_fields_data($field_id);
293 +
294 + if($field_data) {
295 + if(wmvc_show_data('search_type', $el_field_data, '') == 'slider_range') {
296 + $field = array(
297 + "idfield" => wmvc_show_data('idfield', $field_data),
298 + "field_type" => 'SLIDER_RANGE',
299 + "field_label" =>wmvc_show_data('field_label', $field_data),
300 + "prefix" => wmvc_show_data('prefix', $field_data),
301 + "suffix" => wmvc_show_data('suffix', $field_data),
302 + "value_min" => wmvc_show_data('value_min', $el_field_data),
303 + "value_max" => wmvc_show_data('value_max', $el_field_data),
304 + "values_list" => wmvc_show_data('values_list', $field_data),
305 + "placeholder" => wmvc_show_data('placeholder', $field_data)
306 + );
307 + } else {
308 + $field = array(
309 + "idfield" => wmvc_show_data('idfield', $field_data),
310 + "field_type" => wmvc_show_data('field_type', $field_data),
311 + "field_label" =>wmvc_show_data('field_label', $field_data),
312 + "prefix" => wmvc_show_data('prefix', $field_data),
313 + "suffix" => wmvc_show_data('suffix', $field_data),
314 + "values_list" => wmvc_show_data('values_list', $field_data),
315 + "placeholder" => wmvc_show_data('placeholder', $field_data)
316 + );
317 + }
318 + }
319 + }
320 +
321 + if(wmvc_show_data('field_placeholder', $el_field_data, false)) {
322 + $field['placeholder'] = wmvc_show_data('field_placeholder', $el_field_data, false);
323 + }
324 +
325 + if(wmvc_show_data('search_type_tree_hide', $el_field_data, false)) {
326 + $field['search_type_tree_hide'] = wmvc_show_data('search_type_tree_hide', $el_field_data, false);
327 + }
328 +
329 + /* if field not detected or remove from fields list, skip field in search */
330 + if(empty($field)) continue;
331 +
332 + /* add from user fields data */
333 + $field['field_id'] = wmvc_show_data('idfield', $field);
334 + $field['class'] = wmvc_show_data('field_css_class', $el_field_data);
335 + $field['query_type'] = wmvc_show_data('search_type', $el_field_data);
336 + $field['columns'] = wmvc_show_data('field_columns_number', $el_field_data);
337 +
338 +
339 + $field_data = array();
340 + $field_data ['field_data'] = $field;
341 + $field_data ['predefinedfields_query'] = $predefinedfields_query;
342 +
343 + if(in_array(wmvc_show_data('field_type', $field),array('SECTION'))) {
344 + continue;
345 + }
346 +
347 + $field_suffix = strtoupper(wmvc_show_data('search_type_tree', $el_field_data,''));
348 +
349 + $field_view_path = WPDIRECTORYKIT_PATH.'application/views/search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)).$field_suffix.'.php';
350 + if(file_exists($field_view_path))
351 + {
352 + $output .= $WMVC->view('search_fields/'.$subfolder.(wmvc_show_data('field_type', $field)).$field_suffix, $field_data, FALSE);
353 + }
354 + else
355 + {
356 + /* show missing view file of field, only if print enable */
357 + if($print)
358 + $output .= __('Missing VIEW file:', 'wpdirectorykit').' '.esc_html($subfolder).(wmvc_show_data('field_type', $field)).$field_suffix.'.php';
359 + }
360 + }
361 +
362 + if($print){
363 + echo $output;
364 + return FALSE;
365 + }
366 +
367 + return $output;
368 + }
369 +}
370 +
371 +
191 372 function &wdk_get_instance()
192 373 {
193 374 global $Winter_MVC_WDK;
194 375
@@ -210,9 +391,10 @@
210 391 $wdk_bookings_joinded = false;
211 392 static $available_fields_listings = NULL;
212 393 static $available_fields_static = array();
213 394 static $list_fields_static = NULL;
214 -
395 + $fields_type = array();
396 +
215 397 /* add if missing columns */
216 398 if(!in_array('post_id', $columns)) {
217 399 $columns[] = $Winter_MVC_WDK->db->prefix.'wdk_listings.post_id';
218 400 }
@@ -224,14 +406,14 @@
224 406
225 407 if(isset($_GET_clone['order_by']) && $_GET_clone['order_by'] =='undefined') {
226 408 unset($_GET_clone['order_by']);
227 409 }
228 -
410 +
229 411 if(isset($custom_parameters['order_by'])) {
230 412
231 413 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 {
414 + $_GET_clone['order_by'] = ((!empty($custom_parameters['order_by'])) ? $custom_parameters['order_by'].', ':'').sanitize_text_field($_GET_clone['order_by']);
415 + } elseif(!empty( $custom_parameters['order_by'])) {
234 416 $_GET_clone['order_by'] = $custom_parameters['order_by'];
235 417 }
236 418
237 419 unset($custom_parameters['order_by']);
@@ -246,12 +428,12 @@
246 428 $WMVC->model('listingfield_m');
247 429
248 430 $smart_search = '';
249 431 if(isset($_GET_clone['search']))
250 - $smart_search = sanitize_text_field($_GET_clone['search']);
432 + $smart_search = wdk_esc_sql(sanitize_text_field($_GET_clone['search']));
251 433
252 434 if(isset($_GET_clone['field_search']))
253 - $smart_search = sanitize_text_field($_GET_clone['field_search']);
435 + $smart_search = wdk_esc_sql(sanitize_text_field($_GET_clone['field_search']));
254 436
255 437 if(!isset($available_fields_static[$model_name]))
256 438 {
257 439 $available_fields = $WMVC->$model_name->get_available_fields();
@@ -284,8 +466,10 @@
284 466 foreach($list_fields as $field_data) {
285 467
286 468 $field_id = wmvc_show_data('idfield',$field_data);
287 469 $field_type = wmvc_show_data('field_type',$field_data);
470 +
471 + $fields_type[$field_id] = $field_type;
288 472 $column_name ='field_'.$field_id.'_'.$field_type;
289 473 if(!isset($available_fields_listings[$column_name])) continue;
290 474
291 475 if(isset($_GET_clone['field_'.$field_id])) {
@@ -303,9 +487,9 @@
303 487 if(isset($_GET_clone['field_'.$field_id.'_min'])) {
304 488 $_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 489 }
306 490 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']);
491 + $_GET_clone['field_'.$field_id.'_'.$field_type.'_exactly'] = wdk_clean_mixed($_GET_clone['field_'.$field_id.'_exactly']);
308 492 }
309 493
310 494 $columns[] = $column_name;
311 495 $columns[] = $column_name.'_max';
@@ -360,13 +544,34 @@
360 544 }
361 545
362 546 if(isset($_GET_clone['field_post_id'])) {
363 547 $column_name ='ID_exactly';
364 - $_GET_clone[$column_name] = intval($_GET_clone['field_post_id']);
548 + $_GET_clone[$column_name] = sanitize_text_field($_GET_clone['field_post_id']);
365 549 $columns[] = $column_name;
366 550 $external_columns[] = $column_name;
367 551 }
368 552
553 + if(isset($_GET_clone['field_post_date'])) {
554 + $column_name ='post_DATE';
555 + $_GET_clone[$column_name] = ($_GET_clone['field_post_date']);
556 + $columns[] = $column_name;
557 + $external_columns[] = $column_name;
558 + }
559 +
560 + if(isset($_GET_clone['field_post_date_min'])) {
561 + $column_name ='post_DATE_min';
562 + $_GET_clone[$column_name] = ($_GET_clone['field_post_date_min']);
563 + $columns[] = $column_name;
564 + $external_columns[] = $column_name;
565 + }
566 +
567 + if(isset($_GET_clone['field_post_date_max'])) {
568 + $column_name ='post_DATE_max';
569 + $_GET_clone[$column_name] = ($_GET_clone['field_post_date_max']);
570 + $columns[] = $column_name;
571 + $external_columns[] = $column_name;
572 + }
573 +
369 574 if (function_exists('run_wdk_bookings') && isset($_GET_clone['field_booking_date_from'])) {
370 575 $column_name ='field_booking_date_from';
371 576 $_GET_clone[$column_name] = $_GET_clone['field_booking_date_from'];
372 577 $columns[] = $column_name;
@@ -379,8 +584,36 @@
379 584 $columns[] = $column_name;
380 585 $external_columns[] = $column_name;
381 586 }
382 587
588 + if (function_exists('run_wdk_bookings') && isset($_GET_clone['field_booking_guest'])) {
589 + $column_name ='field_booking_guest';
590 + $_GET_clone[$column_name] = $_GET_clone['field_booking_guest'];
591 + $columns[] = $column_name;
592 + $external_columns[] = $column_name;
593 + }
594 +
595 + if (isset($_GET_clone['search_rank'])) {
596 + $column_name ='`rank`';
597 + $_GET_clone[$column_name] = $_GET_clone['search_rank'];
598 + $columns[] = $column_name;
599 + $external_columns[] = $column_name;
600 + }
601 +
602 + if (isset($_GET_clone['search_rank_min'])) {
603 + $column_name ='`rank`_min';
604 + $_GET_clone[$column_name] = $_GET_clone['search_rank_min'];
605 + $columns[] = $column_name;
606 + $external_columns[] = $column_name;
607 + }
608 +
609 + if (isset($_GET_clone['search_rank_max'])) {
610 + $column_name ='`rank`_max';
611 + $_GET_clone[$column_name] = $_GET_clone['search_rank_max'];
612 + $columns[] = $column_name;
613 + $external_columns[] = $column_name;
614 + }
615 +
383 616 //$table_name = substr($model_name, 0, -2);
384 617 $columns_original = array();
385 618 foreach($columns as $key=>$val)
386 619 {
@@ -408,8 +641,10 @@
408 641 {
409 642 unset($_GET_clone['search']);
410 643 unset($_GET_clone['field_search']);
411 644
645 + $WMVC->db->join($WMVC->listing_m->_table_name.' ON '.$WMVC->listing_m->_table_name.'.post_id = '.$WMVC->db->prefix.'posts'.'.ID', NULL, 'LEFT');
646 +
412 647 // For quick/smart search
413 648 if(wmvc_count($columns) > 0 && !empty($smart_search))
414 649 {
415 650 $gen_q = '';
@@ -415,9 +650,9 @@
415 650 $gen_q = '';
416 651 foreach($columns as $key=>$value)
417 652 {
418 653
419 - if($value == 'field_booking_date_from' || $value == 'field_booking_date_to' || $value == 'agents_ids' || $value == 'gps' || $value == 'is_featured') continue;
654 + if($value == 'field_booking_date_from' || $value == 'field_booking_date_to' || $value == 'agents_ids' || $value == 'gps' || $value == 'is_featured' || $value == 'field_booking_guest') continue;
420 655
421 656 if(strpos($value, '_CHECKBOX') !== FALSE) continue;
422 657
423 658 // if smart is number, search only im number fields
@@ -524,9 +759,9 @@
524 759
525 760 if(!empty($gen_q))
526 761 $WMVC->db->where("($gen_q)");
527 762 }
528 -
763 +
529 764 // For column search
530 765 if(isset($_GET_clone))
531 766 {
532 767 $gen_q = '';
@@ -534,9 +769,9 @@
534 769 {
535 770 if(!empty($val) && in_array($key, $columns))
536 771 {
537 772 $col_name = $key;
538 -
773 +
539 774 $val = esc_sql($val);
540 775 //if(isset($key))
541 776 // $col_name = $key;
542 777
@@ -541,28 +776,31 @@
541 776 // $col_name = $key;
542 777
543 778 if(strpos($key, 'skip') !== FALSE) continue;
544 779
545 - if(defined( 'WP_DEBUG' ) && WP_DEBUG)
546 - if(function_exists('pll_current_language'))
780 + if($key == 'field_booking_guest')
547 781 {
548 - $lang_term_id = pll_current_language('term_id');
782 + if(!$wdk_bookings_joinded){
783 + $WMVC->db->join($WMVC->db->prefix.'wdk_booking_price ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_price.post_id', NULL, 'LEFT');
784 + $WMVC->db->distinct($WMVC->db->prefix.'posts.ID');
785 + $WMVC->db->join($WMVC->db->prefix.'wdk_booking_reservation ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_reservation.post_id', NULL, 'LEFT');
786 + $wdk_bookings_joinded = true;
787 + $gen_q.= $WMVC->db->prefix.'wdk_booking_price.is_activated = 1 AND ';
788 + $WMVC->db->join($WMVC->db->prefix.'wdk_booking_calendar ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_calendar.post_id', NULL, 'LEFT');
789 + }
549 790
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 - }
791 + $gen_q.= $WMVC->db->prefix."wdk_booking_calendar.guests >='".intval($val)."' AND ";
792 +
555 793 }
556 -
557 - if($key == 'field_booking_date_from')
794 + elseif($key == 'field_booking_date_from')
558 795 {
559 796 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');
797 + $WMVC->db->join($WMVC->db->prefix.'wdk_booking_price ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_price.post_id', NULL, 'LEFT');
798 + $WMVC->db->distinct($WMVC->db->prefix.'posts.ID');
799 + $WMVC->db->join($WMVC->db->prefix.'wdk_booking_reservation ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_reservation.post_id', NULL, 'LEFT');
563 800 $wdk_bookings_joinded = true;
564 801 $gen_q.= $WMVC->db->prefix.'wdk_booking_price.is_activated = 1 AND ';
802 + $WMVC->db->join($WMVC->db->prefix.'wdk_booking_calendar ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_calendar.post_id', NULL, 'LEFT');
565 803 }
566 804
567 805 if(wdk_is_date($val))
568 806 {
@@ -580,9 +818,9 @@
580 818 if(!get_option('wdk_bookings_is_hours_enabled')) {
581 819 $gen_search_from = wdk_normalize_date_db($_GET_clone['field_booking_date_from'], 'Y-m-d H:i:s', 'Y-m-d');
582 820 $gen_search_to = wdk_normalize_date_db($_GET_clone['field_booking_date_to'], 'Y-m-d H:i:s', 'Y-m-d');
583 821
584 - $gen_q.= $WMVC->listing_m->_table_name.".post_id NOT IN (
822 + $gen_q.= $WMVC->db->prefix."posts.ID NOT IN (
585 823 SELECT post_id
586 824 FROM ".$WMVC->db->prefix."wdk_booking_reservation
587 825 WHERE
588 826 ".$WMVC->db->prefix."wdk_booking_reservation.is_approved = 1
@@ -595,9 +833,9 @@
595 833 } else {
596 834 $gen_search_from = wdk_normalize_date_db($_GET_clone['field_booking_date_from']);
597 835 $gen_search_to = wdk_normalize_date_db($_GET_clone['field_booking_date_to']);
598 836
599 - $gen_q.= $WMVC->listing_m->_table_name.".post_id NOT IN (
837 + $gen_q.= $WMVC->db->prefix."posts.ID NOT IN (
600 838 SELECT post_id
601 839 FROM ".$WMVC->db->prefix."wdk_booking_reservation
602 840 WHERE
603 841 ".$WMVC->db->prefix."wdk_booking_reservation.is_approved = 1
@@ -612,12 +850,13 @@
612 850 }
613 851 elseif($key == 'field_booking_date_to')
614 852 {
615 853 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');
854 + $WMVC->db->join($WMVC->db->prefix.'wdk_booking_price ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_price.post_id',NULL, 'LEFT');
855 + $WMVC->db->join($WMVC->db->prefix.'wdk_booking_reservation ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_reservation.post_id',NULL, 'LEFT');
618 856 $wdk_bookings_joinded = true;
619 857 $gen_q.= $WMVC->db->prefix.'wdk_booking_price.is_activated = 1 AND ';
858 + $WMVC->db->join($WMVC->db->prefix.'wdk_booking_calendar ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_booking_calendar.post_id', NULL, 'LEFT');
620 859 }
621 860
622 861 if(wdk_is_date($val))
623 862 {
@@ -633,9 +872,33 @@
633 872 }
634 873 elseif(substr($key, -8) == '_exactly')
635 874 {
636 875 $col_name = substr($key, 0, -8);
637 - $gen_q.=$col_name." = '".$val."' AND ";
876 +
877 + if(is_string($val) && strpos($val, ',') !== FALSE){
878 + $val =explode(',', $val);
879 + } elseif(is_string($val)){
880 + $val =array($val);
881 + }
882 +
883 + if(is_array($val))
884 + {
885 + $sql_search = '';
886 + foreach ($val as $v) {
887 + if(empty($v)) continue;
888 +
889 + if(!empty($sql_search))
890 + $sql_search .= " OR ";
891 +
892 + $sql_search .= " ".$col_name." = '".$v."' ";
893 + }
894 +
895 + if(!empty($sql_search))
896 + $gen_q.=" ( ".$sql_search." ) AND ";
897 + } else {
898 +
899 + $gen_q.=$col_name." = '".$val."' AND ";
900 + }
638 901 }
639 902 elseif(substr($key, -4) == '_max')
640 903 {
641 904 $col_name = substr($key, 0, -4);
@@ -654,9 +917,9 @@
654 917 }
655 918 else if(substr($key, -4) == '_min')
656 919 {
657 920 $col_name = substr($key, 0, -4);
658 -
921 +
659 922 if(strpos($key, 'NUMBER') !== FALSE) {
660 923 $gen_q.=$col_name." >= ".intval($val)." AND ";
661 924 } else if(strpos($key, 'DATE') !== FALSE) {
662 925 if(wdk_is_date($val))
@@ -725,9 +988,9 @@
725 988 }
726 989
727 990 if(is_array($val)) {
728 991
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');
992 + $WMVC->db->join($WMVC->db->prefix.'wdk_listings_users ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'wdk_listings_users.post_id', NULL, 'LEFT');
730 993 $WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id');
731 994 $sql_search = '';
732 995 foreach ($val as $v) {
733 996 if(empty($v)) continue;
@@ -742,9 +1005,9 @@
742 1005 if(!empty($sql_search))
743 1006 $gen_q.=" ( ".$sql_search." ) AND ";
744 1007
745 1008 } 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');
1009 + $WMVC->db->join($WMVC->db->prefix.'wdk_listings_users ON '.$WMVC->db->prefix.'posts.post_id = '.$WMVC->db->prefix.'wdk_listings_users.post_id', NULL, 'LEFT');
747 1010 $WMVC->db->distinct($WMVC->listing_m->_table_name.'.post_id');
748 1011 $sql_search =" ".$WMVC->listing_m->_table_name.".`user_id_editor` = ".intval($val)." OR `".$WMVC->db->prefix."wdk_listings_users`.`user_id` = ".intval($val)." ";
749 1012 $gen_q.=" ( ".$sql_search." ) AND ";
750 1013 }
@@ -901,10 +1164,15 @@
901 1164
902 1165 if(!empty($sql_search))
903 1166 $gen_q.=" ( ".$sql_search." ) AND ";
904 1167 }
1168 + } elseif ($val == 0) {
1169 + $col_name = $key;
1170 + $val = esc_sql($val);
1171 + if(in_array($col_name, ['`rank`'])) {
1172 + $gen_q.=" ( ".$col_name." = 0 OR ".$col_name." IS NULL ) AND ";
1173 + }
905 1174 }
906 -
907 1175 }
908 1176
909 1177 $gen_q = substr($gen_q, 0, -5);
910 1178
@@ -910,14 +1178,119 @@
910 1178
911 1179 if(!empty($gen_q))
912 1180 $WMVC->db->where("($gen_q)");
913 1181 }
1182 +
1183 + //if(defined( 'WP_DEBUG' ) && WP_DEBUG)
1184 + if(function_exists('pll_current_language'))
1185 + {
1186 + $lang_term_id = pll_current_language('term_id');
1187 +
1188 + if(is_numeric($lang_term_id))
1189 + {
1190 + //echo $lang_term_id.'<br />';
1191 + $WMVC->db->join($WMVC->db->prefix.'term_relationships ON '.$WMVC->db->prefix.'posts.ID = '.$WMVC->db->prefix.'term_relationships.object_id', NULL, NULL);
1192 + $WMVC->db->where("({$WMVC->db->prefix}term_relationships.term_taxonomy_id = $lang_term_id)");
1193 + }
1194 + }
1195 +
1196 + // [RECTANGLE SEARCH]
1197 + if(isset($_GET_clone['rectangle_ne']) && isset($_GET_clone['rectangle_sw']))
1198 + {
1199 + if(wdk_is_gps($_GET_clone['rectangle_ne']) && wdk_is_gps($_GET_clone['rectangle_sw'])) {
1200 +
1201 + $gps_ne = explode(',', $_GET_clone['rectangle_ne']);
1202 + $gps_sw = explode(',', $_GET_clone['rectangle_sw']);
1203 +
1204 + $WMVC->db->where("(".$WMVC->db->prefix."wdk_listings.lat < '$gps_ne[0]' AND ".$WMVC->db->prefix."wdk_listings.lat > '$gps_sw[0]' AND
1205 + ".$WMVC->db->prefix."wdk_listings.lng > '$gps_ne[1]' AND ".$WMVC->db->prefix."wdk_listings.lng < '$gps_sw[1]')");
1206 + }
1207 + }
1208 + // [/RECTANGLE SEARCH]
914 1209
915 1210 // order
916 - if(isset($_GET_clone['order_by']))
917 - {
918 - $_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_listings.post_id', $_GET_clone['order_by']);
919 - $WMVC->db->order_by($_GET_clone['order_by']);
1211 + if (isset($_GET_clone['order_by'])) {
1212 + // Merge available fields + system columns
1213 + $order_columns = array_fill_keys([
1214 + 'post_id',
1215 + 'counter_views',
1216 + 'date_modified',
1217 + 'post_title',
1218 + 'address',
1219 + 'category_id',
1220 + 'location_id',
1221 + 'rank'
1222 + ], true);
1223 +
1224 + $order_columns = apply_filters('wdk/listings/order_columns', $order_columns);
1225 +
1226 + $_GET_clone['order_by'] = str_replace(
1227 + 'post_id',
1228 + $WMVC->db->prefix . 'wdk_listings.post_id',
1229 + sanitize_text_field($_GET_clone['order_by'])
1230 + );
1231 +
1232 + // Fix common typos: ask → asc, desk → desc
1233 + $_GET_clone['order_by'] = str_ireplace([' ask', ' desk'], [' asc', ' desc'], $_GET_clone['order_by']);
1234 +
1235 + /* we no need field type in get link now */
1236 + $_GET_clone['order_by'] = str_ireplace(['_NUMBER', '_SECTION', '_TEXTAREA', '_DATE', '_DROPDOWN', '_DROPDOWNMULTIPLE', '_CHECKBOX'], '', $_GET_clone['order_by']);
1237 +
1238 + // Parse order_by string into parts
1239 + $order_by_array = explode(',', $_GET_clone['order_by']);
1240 + $final_order_by = [];
1241 + foreach ($order_by_array as $order_part) {
1242 + $order_part = trim($order_part);
1243 +
1244 + // detect direction asc/desc
1245 + $direction = 'DESC';
1246 + if (stripos($order_part, ' asc') !== false) {
1247 + $direction = 'ASC';
1248 + } elseif (stripos($order_part, ' desc') !== false) {
1249 + $direction = 'DESC';
1250 + }
1251 +
1252 + $order_part = str_ireplace(['desc', 'asc'], '', $order_part);
1253 + $order_part = str_replace(' ', '', $order_part);
1254 +
1255 + // Try to detect field_(id)
1256 + if (preg_match('/field_(\d+)\b/', $order_part, $matches)) {
1257 +
1258 + $search_field_id = $matches[1];
1259 + if (!empty($fields_type[$search_field_id])) {
1260 + $field_name = "field_{$search_field_id}_{$fields_type[$search_field_id]}";
1261 +
1262 + // Check if field exists in order_columns
1263 + if (isset($available_fields_listings[$field_name])) {
1264 + $final_order_by[] = $field_name . ' ' . $direction;
1265 + }
1266 + }
1267 +
1268 + // else → skip invalid field automatically
1269 +
1270 + } else {
1271 + // Extract only the part after the last '.' if exists, else use entire string
1272 + $col_field = $order_part;
1273 + if (strpos($col_field, '.') !== false) {
1274 + $parts = explode('.', $col_field);
1275 + $col_field = end($parts);
1276 + }
1277 +
1278 + // Check if field exists in order_columns
1279 + if (isset($order_columns[$col_field]) || isset($available_fields_listings[$col_field])) {
1280 + $final_order_by[] = $order_part . ' ' . $direction;
1281 + }
1282 + }
1283 + }
1284 +
1285 + // Apply final order if any valid fields left
1286 + if (!empty($final_order_by)) {
1287 + $_GET_clone['order_by'] = implode(', ', $final_order_by);
1288 + $WMVC->db->order_by($_GET_clone['order_by']);
1289 + } else {
1290 + $WMVC->db->order_by('');
1291 + }
1292 +
920 1293 }
921 1294
922 1295 }
923 1296 }
@@ -934,9 +1307,9 @@
934 1307
935 1308 if(isset($custom_parameters['order_by'])) {
936 1309
937 1310 if(isset($_GET_clone['order_by']) && !empty($_GET_clone['order_by'])) {
938 - $_GET_clone['order_by'] = $custom_parameters['order_by'].', '.$_GET_clone['order_by'];
1311 + $_GET_clone['order_by'] = $custom_parameters['order_by'].', '.sanitize_text_field($_GET_clone['order_by']);
939 1312 } else {
940 1313 $_GET_clone['order_by'] = $custom_parameters['order_by'];
941 1314 }
942 1315
@@ -950,9 +1323,9 @@
950 1323 $WMVC->model($model_name);
951 1324
952 1325 $smart_search = '';
953 1326 if(isset($_GET_clone['profile_search']))
954 - $smart_search = sanitize_text_field($_GET_clone['profile_search']);
1327 + $smart_search = wdk_esc_sql(sanitize_text_field($_GET_clone['profile_search']));
955 1328
956 1329 $available_fields = array('user_login','user_nicename','user_email','user_url','display_name');
957 1330
958 1331 if(isset($_GET_clone['is_activated'])){
@@ -1119,9 +1492,9 @@
1119 1492 // order
1120 1493 if(isset($_GET_clone['order_by']))
1121 1494 {
1122 1495 $_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_favorite.post_id', $_GET_clone['order_by']);
1123 - $WMVC->db->order_by($_GET_clone['order_by']);
1496 + $WMVC->db->order_by(wdk_esc_sql(sanitize_text_field($_GET_clone['order_by'])));
1124 1497 }
1125 1498
1126 1499 }
1127 1500 }
@@ -1137,9 +1510,9 @@
1137 1510 //$WMVC->model('listing_m');
1138 1511
1139 1512 $smart_search = '';
1140 1513 if(isset($_GET_clone['search']))
1141 - $smart_search = sanitize_text_field($_GET_clone['search']);
1514 + $smart_search = wdk_esc_sql(sanitize_text_field($_GET_clone['search']));
1142 1515
1143 1516 $available_fields = $WMVC->$model_name->get_available_fields();
1144 1517
1145 1518 /* Пet column names from wdk_package and add to allow search +
@@ -1290,9 +1663,9 @@
1290 1663 // order
1291 1664 if(isset($_GET_clone['order_by']))
1292 1665 {
1293 1666 $_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_messages.post_id', $_GET_clone['order_by']);
1294 - $WMVC->db->order_by($_GET_clone['order_by']);
1667 + $WMVC->db->order_by(wdk_esc_sql(sanitize_text_field($_GET_clone['order_by'])));
1295 1668 }
1296 1669
1297 1670 }
1298 1671 }
@@ -1325,18 +1698,20 @@
1325 1698
1326 1699 if(isset($_GET[$page_var]))
1327 1700 $current_page = intval(wmvc_xss_clean($_GET[$page_var]));
1328 1701
1329 - if(!isset($texts['previous_page']))$texts['previous_page'] = 'Previous page';
1330 - if(!isset($texts['next_page']))$texts['next_page'] = 'Next page';
1702 + if(!isset($texts['previous_page']))$texts['previous_page'] = esc_html__('Previous page', 'wpdirectorykit');
1703 + if(!isset($texts['next_page']))$texts['next_page'] = esc_html__('Next page', 'wpdirectorykit');
1331 1704 if(!isset($texts['first_page']))$texts['first_page'] = '';
1332 1705 if(!isset($texts['last_page']))$texts['last_page'] = '';
1333 - if(!isset($texts['items']))$texts['items'] = 'items';
1706 + if(!isset($texts['items']))$texts['items'] = esc_html__('items', 'wpdirectorykit');
1334 1707
1335 1708 if(empty($current_page))$current_page = 1;
1336 1709
1337 1710 // get url
1338 - $url = strtok($_SERVER["REQUEST_URI"], '?');
1711 + $url = strtok(wdk_server_current_url(), '?');
1712 +
1713 +
1339 1714 $qs_parameters = wmvc_xss_clean( $_GET );
1340 1715 unset($qs_parameters[$page_var]);
1341 1716 $qs_part = http_build_query($qs_parameters);
1342 1717 $url = wdk_url_suffix($url, $qs_part);
@@ -1359,16 +1734,16 @@
1359 1734
1360 1735 $output .= '<div class="nav-links">';
1361 1736
1362 1737 if($enable_latest_first && $current_page-1 > 0)
1363 - $output.= '<a class="next page-numbers" href="'.esc_url($url).'#results"><span class="screen-reader-text">'.esc_html($texts['first_page']).'</span><span aria-hidden="true">«</span></a>';
1738 + $output.= '<a class="next page-numbers scroll-ignore" href="'.esc_url($url).'#results"><span class="screen-reader-text">'.esc_html($texts['first_page']).'</span><span aria-hidden="true">«</span></a>';
1364 1739
1365 1740 if ($current_page-1 > 0) {
1366 1741
1367 - $output.= '<a class="next page-numbers" href="'.esc_url(wdk_url_suffix($url,esc_attr($page_var).'='.esc_attr($current_page-1))).'#results"><span class="screen-reader-text">'.esc_html($texts['previous_page']).'</span><span aria-hidden="true">‹</span></a>';
1742 + $output.= '<a class="next page-numbers scroll-ignore" href="'.esc_url(wdk_url_suffix($url,esc_attr($page_var).'='.esc_attr($current_page-1))).'#results"><span class="screen-reader-text">'.esc_html($texts['previous_page']).'</span><span aria-hidden="true">‹</span></a>';
1368 1743 } elseif($enable_compact)
1369 1744 {
1370 - $output.= '<span class="next page-numbers disabled" href=""><span class="screen-reader-text">'.esc_html($texts['previous_page']).'</span><span aria-hidden="true">‹</span></span>';
1745 + $output.= '<span class="next page-numbers disabled " href=""><span class="screen-reader-text">'.esc_html($texts['previous_page']).'</span><span aria-hidden="true">‹</span></span>';
1371 1746 }
1372 1747
1373 1748 if (!$enable_compact) {
1374 1749 for ($i = 1 ; $i <= $total_pages; $i++) {
@@ -1376,9 +1751,9 @@
1376 1751 if(($current_page-$limit_items) <= $i && ($current_page+$limit_items) >= $i) {
1377 1752 if (($current_page == $i)) {
1378 1753 $output.= '<span aria-current="page" class="page-numbers current">'.$i.'</span>';
1379 1754 } else {
1380 - $output.= '<a class="page-numbers" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($i))).'#results">'.esc_attr($i).'</a>';
1755 + $output.= '<a class="page-numbers scroll-ignore" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($i))).'#results">'.esc_attr($i).'</a>';
1381 1756 }
1382 1757 }
1383 1758 }
1384 1759 } else {
@@ -1386,17 +1761,17 @@
1386 1761 }
1387 1762
1388 1763 if($current_page+1 <= $total_pages)
1389 1764 {
1390 - $output.= '<a class="next page-numbers" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($current_page+1))).'#results"><span class="screen-reader-text">'.esc_html($texts['next_page']).'</span><span aria-hidden="true">›</span></a>';
1765 + $output.= '<a class="next page-numbers scroll-ignore" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($current_page+1))).'#results"><span class="screen-reader-text">'.esc_html($texts['next_page']).'</span><span aria-hidden="true">›</span></a>';
1391 1766 }
1392 1767 elseif($enable_compact)
1393 1768 {
1394 - $output.= '<a class="next page-numbers disabled" href=""><span class="screen-reader-text">'.esc_html($texts['next_page']).'</span><span aria-hidden="true">›</span></a>';
1769 + $output.= '<a class="next page-numbers disabled scroll-ignore" href=""><span class="screen-reader-text">'.esc_html($texts['next_page']).'</span><span aria-hidden="true">›</span></a>';
1395 1770 }
1396 1771
1397 1772 if($enable_latest_first && $current_page+1 <= $total_pages)
1398 - $output.= '<a class="next page-numbers" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($total_pages))).'#results"><span class="screen-reader-text">'.esc_html($texts['last_page']).'</span><span aria-hidden="true">»</span></a>';
1773 + $output.= '<a class="next page-numbers scroll-ignore" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($total_pages))).'#results"><span class="screen-reader-text">'.esc_html($texts['last_page']).'</span><span aria-hidden="true">»</span></a>';
1399 1774
1400 1775
1401 1776 $output.= '</div>';
1402 1777 $output.= '</nav>';
@@ -1454,15 +1829,15 @@
1454 1829 <div class="wdk-col wdk-col-btns">
1455 1830 <div class="wdk-field wdk-field-btn">
1456 1831 <div class="wdk-field-group wdk-field-group-additional">
1457 1832 <button id="wdk-search-additional" type="button" class="wdk-search-additional-btn"><?php echo esc_html($wdk_text_more_button); ?><i class="wdk-toggle-icon"></i></button>
1458 - <input type='checkbox' style="display: none !important" value='1' name='wdk_search_additional_opened' />
1833 + <input type='checkbox' style="display: none !important" value='1' <?php if(isset($_GET['wdk_search_additional_opened']) && wmvc_xss_clean($_GET['wdk_search_additional_opened']) == 1):?> checked <?php endif;?> name='wdk_search_additional_opened' />
1459 1834 </div>
1460 1835 <div class="wdk-field-group wdk-field-group-reset">
1461 - <button id="wdk-reset-primary" type="reset" class="wdk-search-start wdk-search-reset wdk-click-load-animation"><?php echo esc_html($wdk_text_reset_button);?></button>
1836 + <button title="<?php echo esc_attr__('Reset','wpdirectorykit');?>" id="wdk-reset-primary" type="reset" class="wdk-search-start wdk-search-reset wdk-click-load-animation"><?php echo esc_html($wdk_text_reset_button);?></button>
1462 1837 </div>
1463 1838 <div class="wdk-field-group wdk-field-group-search">
1464 - <button id="wdk-start-primary" type="submit" class="wdk-search-start wdk-click-load-animation">&nbsp;&nbsp;<?php echo esc_html($wdk_text_search_button);?>&nbsp;<i class="fa fa-spinner fa-spin fa-ajax-indicator" style="display: none;"></i>&nbsp;</button>
1839 + <button title="<?php echo esc_attr__('Search','wpdirectorykit');?>" id="wdk-start-primary" type="submit" class="wdk-search-start wdk-click-load-animation">&nbsp;&nbsp;<?php echo esc_html($wdk_text_search_button);?>&nbsp;<i class="fa fa-spinner fa-spin fa-ajax-indicator" style="display: none;"></i>&nbsp;</button>
1465 1840
1466 1841 <?php if(function_exists('run_wdk_save_search') && get_option('wdk_save_search_show_on_searchform')):?>
1467 1842 <div class="section-widget-control right">
1468 1843 <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">
@@ -1488,9 +1863,9 @@
1488 1863 */
1489 1864 if ( ! function_exists('wdk_treefield_option'))
1490 1865 {
1491 1866 function wdk_treefield_option($name = '', $table=NULL, $selected = NULL,
1492 - $column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE, $sql_where='')
1867 + $column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE, $sql_where='', $hide_fields = '')
1493 1868 {
1494 1869 $WMVC = &wdk_get_instance();
1495 1870
1496 1871 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
@@ -1533,14 +1908,16 @@
1533 1908 ajax_param: {
1534 1909 "page": 'wdk_frontendajax',
1535 1910 "function": 'treefieldid',
1536 1911 "action": 'wdk_public_action',
1912 + "wdk_secure": '<?php echo wp_create_nonce( 'wdk_secure_treefieldid' );?>',
1537 1913 "table": '<?php echo esc_js($table); ?>',
1538 1914 "filter_ids": '<?php echo esc_js($filter_ids); ?>',
1539 1915 "start_id": '<?php if(!empty($filter_ids)) esc_js($selected); else echo ""; ?>',
1540 1916 "empty_value": '<?php echo esc_js($empty_value); ?>',
1541 1917 "user_check": '<?php echo esc_js($user_check); ?>',
1542 - "sql_where": '<?php echo esc_js($sql_where); ?>'
1918 + "sql_where": '<?php echo esc_js($sql_where); ?>',
1919 + "hide_fields": '<?php echo esc_js($hide_fields); ?>'
1543 1920 },
1544 1921 attribute_id: '<?php echo esc_js($attribute_id); ?>',
1545 1922 language_id: '<?php echo esc_js($language_id); ?>',
1546 1923 attribute_value: '<?php echo esc_js($column); ?>',
@@ -1566,9 +1943,9 @@
1566 1943 */
1567 1944 if ( ! function_exists('wdk_treefield_option_checkboxes'))
1568 1945 {
1569 1946 function wdk_treefield_option_checkboxes($name = '', $table=NULL, $selected = NULL,
1570 - $column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE)
1947 + $column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE, $sql_where='', $hide_fields = '')
1571 1948 {
1572 1949 $WMVC = &wdk_get_instance();
1573 1950
1574 1951 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
@@ -1587,12 +1964,11 @@
1587 1964
1588 1965 $values = '';
1589 1966 if(!empty($selected)){
1590 1967 $ids = array();
1591 -
1592 1968 if(is_string($selected) && strpos($selected, ',') !== FALSE){
1593 1969 $val_selected = explode(',', $selected);
1594 - } elseif(is_string($selected)){
1970 + } elseif($selected){
1595 1971 $val_selected = array($selected);
1596 1972 }
1597 1973
1598 1974 foreach($val_selected as $selected_item) {
@@ -1642,12 +2018,14 @@
1642 2018 ajax_param: {
1643 2019 "page": 'wdk_frontendajax',
1644 2020 "function": 'treefieldid_checkboxes',
1645 2021 "action": 'wdk_public_action',
2022 + "wdk_secure": '<?php echo wp_create_nonce( 'wdk_secure_treefieldid_checkboxes' );?>',
1646 2023 "table": '<?php echo esc_js($table); ?>',
1647 2024 "filter_ids": '<?php echo esc_js($filter_ids); ?>',
1648 2025 "empty_value": '<?php echo esc_js($empty_value); ?>',
1649 2026 "user_check": '<?php echo esc_js($user_check); ?>',
2027 + "hide_fields": '<?php echo esc_js($hide_fields); ?>',
1650 2028 },
1651 2029 selected: '<?php echo esc_js($selected); ?>',
1652 2030 attribute_id: '<?php echo esc_js($attribute_id); ?>',
1653 2031 language_id: '<?php echo esc_js($language_id); ?>',
@@ -1671,11 +2049,19 @@
1671 2049 if ( ! function_exists('wdk_filter_decimal'))
1672 2050 {
1673 2051 function wdk_filter_decimal($string = '')
1674 2052 {
1675 - if(substr($string, -3, 3) === ".00") {
1676 - return substr($string, 0, -3);
1677 - }
2053 + if(wdk_get_option('wdk_enable_filter_zero_decimal')) {
2054 + if(substr($string, -3, 3) === ",00") {
2055 + return substr($string, 0, -3);
2056 + }
2057 + if(substr($string, -3, 3) === ".00") {
2058 + return substr($string, 0, -3);
2059 + }
2060 + if(substr($string, -3, 1) === "." && substr($string, -1, 1) === "0") {
2061 + return substr($string, 0, -1);
2062 + }
2063 + }
1678 2064
1679 2065 return $string;
1680 2066 }
1681 2067 }
@@ -1753,12 +2139,8 @@
1753 2139 * @return string date in format Y-m-d H:i:s
1754 2140 */
1755 2141 function wdk_normalize_date_db($date, $format = 'Y-m-d H:i:s', $return_format = 'Y-m-d H:i:s')
1756 2142 {
1757 - /* check is date on strtotime */
1758 - if((bool)strtotime($date)){
1759 - return date($return_format, strtotime($date));
1760 - }
1761 2143
1762 2144 /* check is date from argument */
1763 2145 $d = \DateTime::createFromFormat($format, $date);
1764 2146 if($d) {
@@ -1789,24 +2171,29 @@
1789 2171 return $d->format($return_format);
1790 2172 }
1791 2173 }
1792 2174
1793 - /* issue with pm/am inside date, example bug format like "2023 01 19 pm8:06" => 'Y n j ag:i' */
1794 - $format = get_option('date_format').' '.get_option('time_format');
1795 - if(strpos($format, 'a') !== FALSE) {
1796 - $format = str_replace('a', '',$format).' a';
1797 - if(strpos($date, 'am') !== FALSE) {
1798 - $date = str_replace('am', '',$date).' am';
1799 - }
1800 - if(strpos($date, 'pm') !== FALSE) {
1801 - $date = str_replace('pm', '',$date).' pm';
1802 - }
1803 - $d = \DateTime::createFromFormat($format, $date);
1804 - if($d) {
1805 - return $d->format($return_format);
1806 - }
1807 - }
2175 + /* issue with pm/am inside date, example bug format like "2023 01 19 pm8:06" => 'Y n j ag:i' */
2176 + $format = get_option('date_format').' '.get_option('time_format');
2177 + if(strpos($format, 'a') !== FALSE) {
2178 + $format = str_replace('a', '',$format).' a';
2179 + if(strpos($date, 'am') !== FALSE) {
2180 + $date = str_replace('am', '',$date).' am';
2181 + }
2182 + if(strpos($date, 'pm') !== FALSE) {
2183 + $date = str_replace('pm', '',$date).' pm';
2184 + }
2185 + $d = \DateTime::createFromFormat($format, $date);
2186 + if($d) {
2187 + return $d->format($return_format);
2188 + }
2189 + }
1808 2190
2191 + /* check is date on strtotime */
2192 + if((bool)strtotime($date)){
2193 + return date($return_format, strtotime($date));
2194 + }
2195 +
1809 2196 return false;
1810 2197 }
1811 2198 }
1812 2199
@@ -1824,9 +2211,100 @@
1824 2211 return $base_url.$extension_url;
1825 2212 }
1826 2213 }
1827 2214
2215 +
1828 2216 /**
2217 + * Insert an attachment from a remote URL.
2218 + *
2219 + * @param string $url Remote file URL.
2220 + * @param int|null $parent_post_id Post ID to attach the image to.
2221 + * @return int|false Attachment ID or false on failure.
2222 + */
2223 +function wdk_insert_attachment_from_cloud_url($url, $parent_post_id = null) {
2224 + // Request with headers (Google blocks requests without UA sometimes)
2225 + $response = wp_remote_get($url, array(
2226 + 'timeout' => 30,
2227 + 'redirection' => 5,
2228 + 'headers' => array(
2229 + 'User-Agent' => 'Mozilla/5.0 (WordPress)',
2230 + 'Referer' => home_url()
2231 + )
2232 + ));
2233 +
2234 + if (is_wp_error($response)) {
2235 + return false;
2236 + }
2237 +
2238 + $code = wp_remote_retrieve_response_code($response);
2239 + if ($code != 200) {
2240 + return false;
2241 + }
2242 +
2243 + $body = wp_remote_retrieve_body($response);
2244 + if (empty($body)) {
2245 + return false;
2246 + }
2247 +
2248 + // Try to get filename from URL or headers
2249 + $filename = basename(parse_url($url, PHP_URL_PATH));
2250 +
2251 + // If filename empty (Google Drive case)
2252 + if (!$filename || strpos($filename, '.') === false) {
2253 + // Try content-disposition header
2254 + $headers = wp_remote_retrieve_headers($response);
2255 + if (!empty($headers['content-disposition']) &&
2256 + preg_match('/filename="?([^"]+)"?/i', $headers['content-disposition'], $matches)) {
2257 + $filename = sanitize_file_name($matches[1]);
2258 + }
2259 + }
2260 +
2261 + // If still no extension, detect from mime
2262 + $ext = pathinfo($filename, PATHINFO_EXTENSION);
2263 + if (empty($ext)) {
2264 + $data = getimagesizefromstring($body);
2265 + if (!$data || empty($data['mime'])) {
2266 + return false;
2267 + }
2268 + $ext = wdk_mime2ext($data['mime']);
2269 + $filename = time() . '-' . wp_generate_password(6, false) . '.' . $ext;
2270 + }
2271 +
2272 + // Save file to uploads dir
2273 + $upload = wp_upload_bits($filename, null, $body);
2274 + if (!empty($upload['error'])) {
2275 + return false;
2276 + }
2277 +
2278 + $file_path = $upload['file'];
2279 + $file_name = basename($file_path);
2280 + $file_type = wp_check_filetype($file_name, null);
2281 + $wp_upload_dir = wp_upload_dir();
2282 +
2283 + $post_info = array(
2284 + 'guid' => $wp_upload_dir['url'] . '/' . $file_name,
2285 + 'post_mime_type' => $file_type['type'],
2286 + 'post_title' => sanitize_file_name(pathinfo($file_name, PATHINFO_FILENAME)),
2287 + 'post_content' => '',
2288 + 'post_status' => 'inherit',
2289 + );
2290 +
2291 + // Insert attachment
2292 + $attach_id = wp_insert_attachment($post_info, $file_path, $parent_post_id);
2293 +
2294 + if (!$attach_id) {
2295 + return false;
2296 + }
2297 +
2298 + // Generate metadata
2299 + require_once ABSPATH . 'wp-admin/includes/image.php';
2300 + $attach_data = wp_generate_attachment_metadata($attach_id, $file_path);
2301 + wp_update_attachment_metadata($attach_id, $attach_data);
2302 +
2303 + return $attach_id;
2304 +}
2305 +
2306 +/**
1829 2307 * Insert an attachment from an URL address.
1830 2308 *
1831 2309 * @param String $url
1832 2310 * @param Int $parent_post_id
@@ -1848,9 +2326,9 @@
1848 2326 $filename = substr($filename, 0, strpos($filename, '?'));
1849 2327 }
1850 2328
1851 2329 /* if unsoported extension */
1852 - if(in_array(wdk_file_extension($filename), array('php','asp'))){
2330 + if(in_array(wdk_file_extension($filename), array('php','asp')) || strlen(wdk_file_extension($filename)) > 5){
1853 2331 $data = getimagesizefromstring($response['body']);
1854 2332 if(!$data) return false;
1855 2333 if(empty($data['mime'])) return false;
1856 2334
@@ -1947,17 +2425,12 @@
1947 2425 */
1948 2426
1949 2427 function wdk_generate_profile_permalink($profile = array())
1950 2428 {
1951 -
1952 2429 $profile_slug = '';
1953 - if(wmvc_show_data('user_login', $profile, false)){
1954 - $profile_slug = wmvc_show_data('user_login', $profile);
1955 - if(wmvc_show_data('wdk_slug', $profile))
1956 - $profile_slug = wmvc_show_data('wdk_slug', $profile);
1957 - } else if(is_intval($profile)){
2430 + if(is_intval($profile)){
1958 2431 $profile_data = get_userdata($profile);
1959 - if(wmvc_show_data('wdk_slug', $profile, false)){
2432 + if(wmvc_show_data('wdk_slug', $profile_data, false)){
1960 2433 $profile_slug = wmvc_show_data('wdk_slug', $profile);
1961 2434 }elseif(wmvc_show_data('user_login', $profile_data, false)){
1962 2435 $profile_slug = wmvc_show_data('user_login', $profile_data);
1963 2436 } else {
@@ -1962,10 +2435,14 @@
1962 2435 $profile_slug = wmvc_show_data('user_login', $profile_data);
1963 2436 } else {
1964 2437 $profile_slug = $profile;
1965 2438 }
1966 - }
1967 -
2439 + } else if(wmvc_show_data('user_login', $profile, false)){
2440 + $profile_slug = wmvc_show_data('user_login', $profile);
2441 + if(wmvc_show_data('wdk_slug', $profile))
2442 + $profile_slug = wmvc_show_data('wdk_slug', $profile);
2443 + }
2444 +
1968 2445 $user_profile_page = get_option('wdk_membership_profile_preview_page');
1969 2446 if(!$user_profile_page) {
1970 2447 return '#';
1971 2448 }
@@ -2054,17 +2531,23 @@
2054 2531 * Return date in format
2055 2532 * @param string|url redirect url
2056 2533 * @param string custom_message, showed on login form like alert, visible only on wdk login form
2057 2534 */
2058 - function wdk_login_url($url_redirect = NULL, $custom_message = '')
2535 + function wdk_login_url($url_redirect = '', $custom_message = '')
2059 2536 {
2060 2537 $url = wp_login_url($url_redirect);
2061 2538
2062 2539 if(get_option('wdk_membership_login_page')){
2063 - $url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')), 'redirect_to='. urlencode($url_redirect).'&custom_message='. urlencode($custom_message));
2540 + $url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')));
2541 + if(!empty($url_redirect)) {
2542 + $url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')), 'redirect_to='. urlencode($url_redirect));
2543 + }
2544 + if(!empty($custom_message)) {
2545 + $url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')), 'custom_message='. urlencode($custom_message));
2546 + }
2064 2547 }
2065 2548
2066 - return $url;
2549 + return trim($url, '?');
2067 2550 }
2068 2551 }
2069 2552
2070 2553 if(!function_exists('wdk_mail')) {
@@ -2083,10 +2566,10 @@
2083 2566 if(empty($subject))
2084 2567 $subject = __("New message", "wpdirectorykit");
2085 2568
2086 2569 $headers = array('Content-Type: text/html; charset=UTF-8');
2087 - $headers[] = 'From: '.$email_from;
2088 -
2570 + $headers[] = 'From: "'.get_bloginfo('name').'" <'.$email_from.'>';
2571 +
2089 2572 if(!empty($reply_to)) {
2090 2573 $headers[] = 'Reply-To: '.$reply_to;
2091 2574 } else {
2092 2575 $headers[] = 'Reply-To: '.$email_from;
@@ -2218,9 +2701,9 @@
2218 2701 <?php echo esc_html__('Select file','wmvc_win') ?>
2219 2702 </a>
2220 2703 <a class="delete-custom-img <?php if ( ! $you_have_file ) { echo 'hidden'; } ?>"
2221 2704 href="#">
2222 - <?php echo esc_html__('Remove file','wmvc_win') ?>
2705 + <?php echo esc_html__('Remove all files','wmvc_win') ?>
2223 2706 </a>
2224 2707 </p>
2225 2708 <?php //endif; ?>
2226 2709
@@ -2287,18 +2770,14 @@
2287 2770 {
2288 2771 static $media_element_counter = 0;
2289 2772
2290 2773 if(!isset($texts['file_select']))$texts['file_select'] = esc_html__('Select file','wmvc_win');
2291 - if(!isset($texts['file_remove']))$texts['file_remove'] = esc_html__('Remove file','wmvc_win');
2774 + if(!isset($texts['file_remove']))$texts['file_remove'] = esc_html__('Remove all files','wmvc_win');
2292 2775
2293 2776 $media_element_counter++;
2294 2777
2295 2778 $img_field = $field_name.'_'.$media_element_counter;
2296 2779
2297 - wp_register_script( 'wpmediaelement_file', WPDIRECTORYKIT_URL . 'admin/js/jquery.wpmediaelement_file.js', array( 'jquery' ), false, false );
2298 - wp_enqueue_script( 'wpmediaelement_file' );
2299 - wp_enqueue_media();
2300 -
2301 2780 wp_enqueue_script( 'wpmediamultiple' );
2302 2781 wp_enqueue_script( 'jquery-ui-mouse' );
2303 2782 wp_enqueue_media();
2304 2783
@@ -2367,9 +2846,12 @@
2367 2846 $('#".esc_js($field_name)."meta-box-id.postbox-upload-multiple').wpMediaMultiple({
2368 2847 frame: {
2369 2848 title: '".esc_js(__('Select or Upload Media Of Your Chosen Persuasion','wpdirectorykit'))."',
2370 2849 button: '".esc_js(__('Use this media','wpdirectorykit'))."',
2371 - }
2850 + },
2851 + library: {
2852 + type: ['application', 'image', 'video']
2853 + },
2372 2854 });
2373 2855 /* order */
2374 2856 var re_order = function(media_element){
2375 2857 var list_media = '';
@@ -2448,9 +2930,9 @@
2448 2930
2449 2931 if(empty($user_id))
2450 2932 $user_id = get_current_user_id();
2451 2933
2452 - if(wmvc_user_in_role('administrator')) {
2934 + if(wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) {
2453 2935 return true;
2454 2936 }
2455 2937
2456 2938 if(substr($model_name,-2,2) == '_m')
@@ -2478,8 +2960,52 @@
2478 2960
2479 2961 }
2480 2962 }
2481 2963
2964 +if ( ! function_exists('wdk_recaptcha_field_v3'))
2965 +{
2966 + function wdk_recaptcha_field_v3($wdk_recaptcha_site_key=null, $wdk_recaptcha_secret_key=null, $load_script=true)
2967 + {
2968 + static $counter = 0;
2969 +
2970 + if(empty($wdk_recaptcha_site_key) && empty($wdk_recaptcha_site_key)) {
2971 + $wdk_recaptcha_site_key = get_option('wdk_recaptcha_site_key_v3');
2972 + $wdk_recaptcha_secret_key = get_option('wdk_recaptcha_secret_key_v3');
2973 + }
2974 +
2975 + if($wdk_recaptcha_site_key && $wdk_recaptcha_secret_key)
2976 + {
2977 + if($load_script && $counter===0)
2978 + {
2979 + echo "<script src='https://www.google.com/recaptcha/api.js?render=".esc_attr(trim($wdk_recaptcha_site_key))."'></script>";
2980 + }
2981 + $counter++;
2982 + ?>
2983 + <input type="hidden" name="g-recaptcha-response" id="recaptcha_called_v3_count_<?php echo esc_html($counter);?>">
2984 + <script>
2985 + (function(){
2986 + const field_token = document.getElementById('recaptcha_called_v3_count_<?php echo esc_html($counter);?>');
2987 + grecaptcha.ready(function() {
2988 + grecaptcha.execute('<?php echo esc_attr(trim($wdk_recaptcha_site_key));?>', {action: 'submit'}).then(function(token) {
2989 + field_token.value = token;
2990 + });
2991 + });
2992 +
2993 + // Reload token after form submit
2994 + field_token.closest('form').addEventListener('submit', function(e) {
2995 + e.preventDefault();
2996 + grecaptcha.execute('<?php echo esc_attr(trim($wdk_recaptcha_site_key));?>', {action: 'submit'}).then(function(token) {
2997 + field_token.value = token;
2998 + });
2999 + });
3000 + })();
3001 + </script>
3002 + <?php
3003 + }
3004 + }
3005 +}
3006 +
3007 +
2482 3008 if ( ! function_exists('wdk_recaptcha_field'))
2483 3009 {
2484 3010 function wdk_recaptcha_field($is_compact=false, $style="", $load_script=true)
2485 3011 {
@@ -2503,15 +3029,15 @@
2503 3029 }
2504 3030
2505 3031 $recaptcha_array[$counter] = array('size'=>$size_tag);
2506 3032
2507 - echo '<div id="recaptcha_called_'.$counter.'" class="g-recaptcha" style="'.$style.'" '.$compact_tag.' data-sitekey="'.get_option('wdk_recaptcha_site_key').'"></div>';
3033 + echo '<div id="recaptcha_called_'.$counter.'" class="g-recaptcha" style="'.$style.'" '.$compact_tag.' data-sitekey="'.esc_attr(get_option('wdk_recaptcha_site_key')).'"></div>';
2508 3034 ?>
2509 3035
2510 3036 <script>
2511 3037 <?php if($counter===1)echo 'var ';?>CaptchaCallback = function(){
2512 3038 <?php for($j=1;$j<=$counter;$j++): ?>
2513 - grecaptcha.render(document.getElementById('recaptcha_called_<?php echo $j;?>'), {'size' : '<?php echo $recaptcha_array[$j]['size']; ?>', 'sitekey' : '<?php echo get_option('wdk_recaptcha_site_key'); ?>'});
3039 + grecaptcha.render(document.getElementById('recaptcha_called_<?php echo $j;?>'), {'size' : '<?php echo esc_attr($recaptcha_array[$j]['size']); ?>', 'sitekey' : '<?php echo esc_attr(get_option('wdk_recaptcha_site_key')); ?>'});
2514 3040 <?php endfor; ?>
2515 3041 };
2516 3042 </script>
2517 3043
@@ -2613,9 +3139,9 @@
2613 3139 if(is_array($val))
2614 3140 {
2615 3141 return wdk_clean($_POST);
2616 3142 }
2617 - else
3143 + elseif(is_string($val))
2618 3144 {
2619 3145 if(strpos($val, '<iframe') === 0)
2620 3146 $val = str_replace("'",'"', $val);
2621 3147
@@ -2654,9 +3180,9 @@
2654 3180 if(is_array($val))
2655 3181 {
2656 3182 $arr_cleaned[sanitize_text_field($key)] = wdk_clean($val);
2657 3183 }
2658 - else
3184 + elseif(is_string($val))
2659 3185 {
2660 3186 $arr_cleaned[sanitize_text_field($key)] = wp_kses_post($val);
2661 3187 }
2662 3188
@@ -2666,8 +3192,34 @@
2666 3192
2667 3193 return $arr_cleaned;
2668 3194 }
2669 3195
3196 +function wdk_clean_mixed($item)
3197 +{
3198 + $arr_cleaned = array();
3199 +
3200 + if(is_array($item))
3201 + {
3202 + foreach($item as $key=>$val)
3203 + {
3204 + if(is_array($val))
3205 + {
3206 + $arr_cleaned[sanitize_text_field($key)] = wdk_clean_mixed($val);
3207 + }
3208 + else
3209 + {
3210 + $arr_cleaned[sanitize_text_field($key)] = wp_kses_post($val);
3211 + }
3212 + }
3213 + }
3214 + else
3215 + {
3216 + return wp_kses_post($item);
3217 + }
3218 +
3219 + return $arr_cleaned;
3220 +}
3221 +
2670 3222 /*
2671 3223 <select class="form-control" name="<?php echo 'control_operator_'.$i_fieldnum; ?>">
2672 3224 <option value="CONTAINS">CONTAINS</option>
2673 3225 <option value="NOT_CONTAINS">NOT_CONTAINS</option>
@@ -2682,9 +3234,9 @@
2682 3234
2683 3235 if(is_array($options) && count($options) > 0)
2684 3236 foreach($options as $key=>$val)
2685 3237 {
2686 - $output.= '<option value="'.$key.'" '.($selected==$key?'selected':'').'>'.$val.'</option>';
3238 + $output.= '<option value="'.$key.'" '.($selected==$key&&$selected != ''?'selected':'').'>'.$val.'</option>';
2687 3239 }
2688 3240
2689 3241 $output.= '</select>';
2690 3242
@@ -2737,15 +3289,15 @@
2737 3289
2738 3290 $results = $WMVC->$table->get();
2739 3291 foreach ($results as $item) {
2740 3292 if($item)
2741 - $form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data($column_key, $item, false, TRUE, TRUE)).'">'.esc_html(wmvc_show_data($column_print, $item, false, TRUE, TRUE)).'</option>';
3293 + $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),'wpdirectorykit').'</option>';
2742 3294 }
2743 3295 }
2744 3296 } elseif(is_intval($selected)) {
2745 3297 $db_item = $WMVC->$table->get($selected, TRUE);
2746 3298 if($db_item)
2747 - $form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data($column_key, $db_item, false, TRUE, TRUE)).'">'.esc_attr(wmvc_show_data($column_print, $db_item, false, TRUE, TRUE)).'</option>';
3299 + $form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data($column_key, $db_item, false, TRUE, TRUE)).'">'.esc_html__(wmvc_show_data($column_print, $db_item, false, TRUE, TRUE),'wpdirectorykit').'</option>';
2748 3300 }
2749 3301 } else {
2750 3302 //$form .= '<option value="" selected="selected">'.esc_html__('Not selected', 'wpdirectorykit').'</option>';
2751 3303 }
@@ -2753,11 +3305,11 @@
2753 3305
2754 3306 //load javascript library
2755 3307 if($counter==0)
2756 3308 {
2757 - wp_enqueue_script('select2');
3309 + wp_enqueue_script('select2-select2');
2758 3310 wp_enqueue_script('wdk-select2');
2759 - wp_enqueue_style('select2');
3311 + wp_enqueue_style('select2-select2');
2760 3312 }
2761 3313 ?>
2762 3314 <?php
2763 3315 $counter++;
@@ -2801,11 +3353,11 @@
2801 3353
2802 3354 //load javascript library
2803 3355 if($counter==0)
2804 3356 {
2805 - wp_enqueue_script('select2');
3357 + wp_enqueue_script('select2-select2');
2806 3358 wp_enqueue_script('wdk-select2');
2807 - wp_enqueue_style('select2');
3359 + wp_enqueue_style('select2-select2');
2808 3360 }
2809 3361 ?>
2810 3362 <?php
2811 3363 $counter++;
@@ -2883,11 +3435,30 @@
2883 3435 'r'=>'llll',
2884 3436 'u'=>'x',
2885 3437 );
2886 3438
2887 - $replaced_from = array_keys($replaced);
2888 - $date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format);
2889 - return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format);
3439 +
3440 + $result = '';
3441 + $escaped = false;
3442 + $length = strlen($date_format);
3443 +
3444 + for ($i = 0; $i < $length; $i++) {
3445 + $char = $date_format[$i];
3446 +
3447 + if ($char === '\\') {
3448 + $escaped = true;
3449 + continue;
3450 + }
3451 +
3452 + if ($escaped) {
3453 + $result .= "'".$char."'";
3454 + $escaped = false;
3455 + } else {
3456 + $result .= isset($replaced[$char]) ? $replaced[$char] : $char;
3457 + }
3458 + }
3459 +
3460 + return str_replace("''", '',$result);
2890 3461 }
2891 3462 }
2892 3463
2893 3464 if ( ! function_exists('wdk_convert_date_format_jquery'))
@@ -2928,11 +3499,29 @@
2928 3499 'u'=>'@',
2929 3500 ':'=>'',
2930 3501 );
2931 3502
2932 - $replaced_from = array_keys($replaced);
2933 - $date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format);
2934 - return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format);
3503 + $result = '';
3504 + $escaped = false;
3505 + $length = strlen($date_format);
3506 +
3507 + for ($i = 0; $i < $length; $i++) {
3508 + $char = $date_format[$i];
3509 +
3510 + if ($char === '\\') {
3511 + $escaped = true;
3512 + continue;
3513 + }
3514 +
3515 + if ($escaped) {
3516 + $result .= "'".$char."'";
3517 + $escaped = false;
3518 + } else {
3519 + $result .= isset($replaced[$char]) ? $replaced[$char] : $char;
3520 + }
3521 + }
3522 +
3523 + return str_replace("''", '',$result);
2935 3524 }
2936 3525 }
2937 3526
2938 3527 if ( ! function_exists('wdk_convert_date_format_jquery'))
@@ -2973,11 +3562,31 @@
2973 3562 'u'=>'@',
2974 3563 ':'=>'',
2975 3564 );
2976 3565
2977 - $replaced_from = array_keys($replaced);
2978 - $date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format);
2979 - return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format);
3566 +
3567 + $result = '';
3568 + $escaped = false;
3569 + $length = strlen($date_format);
3570 +
3571 + for ($i = 0; $i < $length; $i++) {
3572 + $char = $date_format[$i];
3573 +
3574 + if ($char === '\\') {
3575 + $escaped = true;
3576 + continue;
3577 + }
3578 +
3579 + if ($escaped) {
3580 + $result .= "'".$char."'";
3581 + $escaped = false;
3582 + } else {
3583 + $result .= isset($replaced[$char]) ? $replaced[$char] : $char;
3584 + }
3585 + }
3586 +
3587 + return str_replace("''", '',$result);
3588 +
2980 3589 }
2981 3590 }
2982 3591
2983 3592 if ( ! function_exists('wdk_get_gps'))
@@ -3005,9 +3614,17 @@
3005 3614
3006 3615 if(!isset($results[$address])) {
3007 3616 $results[$address] = NULL;
3008 3617 $url = 'https://nominatim.openstreetmap.org/search?format=json&q=' . $address;
3009 - $request = wp_remote_get( $url );
3618 +
3619 + // Add required User-Agent header
3620 + $args = [
3621 + 'timeout' => 10,
3622 + 'headers' => [
3623 + 'User-Agent' => get_bloginfo('name') . '/1.0 (' . get_bloginfo('admin_email') . ')',
3624 + ],
3625 + ];
3626 + $request = wp_remote_get( $url, $args);
3010 3627 $response = '';
3011 3628
3012 3629 // request failed
3013 3630 if ( is_wp_error( $request ) ) {
@@ -3163,8 +3780,32 @@
3163 3780 return false;
3164 3781 }
3165 3782 }
3166 3783
3784 +if ( ! function_exists('is_wdk_whatsapp'))
3785 +{
3786 + // Validation phone
3787 + /**
3788 + * @param string $value phone in string
3789 + * @return bool
3790 + */
3791 + function is_wdk_whatsapp($value = '') {
3792 + return true;
3793 + }
3794 +}
3795 +
3796 +if ( ! function_exists('is_wdk_viber'))
3797 +{
3798 + // Validation phone
3799 + /**
3800 + * @param string $value phone in string
3801 + * @return bool
3802 + */
3803 + function is_wdk_viber($value = '') {
3804 + return true;
3805 + }
3806 +}
3807 +
3167 3808 if ( ! function_exists('wdk_filter_phone'))
3168 3809 {
3169 3810 // Validation phone
3170 3811 /**
@@ -3300,9 +3941,12 @@
3300 3941
3301 3942 $value = filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
3302 3943 $value = (float)str_replace(array(","," ",'&nbsp;'), "", $value);
3303 3944
3304 - return number_format_i18n($value);
3945 + // Allow decimal precision to be filtered (default is 0)
3946 + $decimals = apply_filters('wdk_number_format_decimals', ((wdk_get_option('wdk_number_format_decimals')) ? wdk_get_option('wdk_number_format_decimals') : 0));
3947 +
3948 + return number_format_i18n($value, $decimals);
3305 3949 }
3306 3950 }
3307 3951
3308 3952 if ( ! function_exists('wdk_currency_symbol'))
@@ -3432,11 +4076,23 @@
3432 4076 $user_data['wdk_viber'] = wmvc_show_data('cacheduser_wdk_viber', $row);
3433 4077 $user_data['wdk_iban'] = wmvc_show_data('cacheduser_wdk_iban', $row);
3434 4078 $user_data['wdk_telegram'] = wmvc_show_data('cacheduser_wdk_telegram', $row);
3435 4079 $user_data['wdk_position_title'] = wmvc_show_data('cacheduser_wdk_position_title', $row);
4080 + $user_data['agency_name'] = wmvc_show_data('cacheduser_agency_name', $row);
3436 4081 $user_data['description'] = wmvc_show_data('cacheduser_description', $row);
3437 4082 $user_data['user_url'] = wmvc_show_data('cacheduser_user_url', $row);
3438 - $user_data['roles'] = explode(',', wmvc_show_data('cacheduser_roles', $value));
4083 + $user_data['roles'] = explode(',', wmvc_show_data('cacheduser_roles', $row));
4084 + $user_data['wdk_slug'] = wmvc_show_data('cacheduser_wdk_slug', $row);
4085 + $user_data['user_login'] = wmvc_show_data('cacheduser_user_login', $row);
4086 + $user_data['user_id'] = wmvc_show_data('cacheduser_user_id', $row);
4087 +
4088 + if(function_exists('wdk_generate_profile_permalink') && $user_data['profile_url'] == '#') {
4089 + if($user_data['user_login']) {
4090 + $user_data['profile_url'] = wdk_generate_profile_permalink($user_data);
4091 + } else {
4092 + $user_data['profile_url'] = wdk_generate_profile_permalink(wmvc_show_data('user_id', $user_data));
4093 + }
4094 + }
3439 4095
3440 4096 return $user_data;
3441 4097 }
3442 4098 }
@@ -3796,5 +4452,858 @@
3796 4452 return array('lat' => $newLatitude, 'lng' => $newLongitude);
3797 4453 }
3798 4454 }
3799 4455
3800 -?>
4456 +if ( ! function_exists('wdk_is_listing_preview_page'))
4457 +{
4458 + function wdk_is_listing_preview_page() {
4459 + global $wdk_listing_id;
4460 +
4461 + if(!empty($wdk_listing_id))
4462 + return TRUE;
4463 +
4464 + return FALSE;
4465 + }
4466 +}
4467 +
4468 +if ( ! function_exists('wdk_is_listing_field_exists'))
4469 +{
4470 + function wdk_is_listing_field_exists($field_name = '', $udpate_cache = FALSE) {
4471 + static $available_fields_listings = array();
4472 + $custom_fields = array();
4473 +
4474 + $WMVC = &wdk_get_instance();
4475 + $WMVC->model('listingfield_m');
4476 +
4477 + if(empty($available_fields_listings) || $udpate_cache) {
4478 + $available_fields_listings = $WMVC->listingfield_m->get_available_fields();
4479 + }
4480 +
4481 + if(isset($available_fields_listings[$field_name]) || isset($custom_fields[$field_name])) {
4482 + return TRUE;
4483 + }
4484 +
4485 + return FALSE;
4486 + }
4487 +}
4488 +
4489 +if ( ! function_exists('wdk_cached_field_get'))
4490 +{
4491 + function wdk_cached_field_get($udpate_cache = FALSE) {
4492 + static $fields = NULL;
4493 +
4494 + $WMVC = &wdk_get_instance();
4495 + $WMVC->model('field_m');
4496 +
4497 + if(is_null($fields) || $udpate_cache) {
4498 + $fields = $WMVC->field_m->get();
4499 + }
4500 +
4501 + return $fields;
4502 + }
4503 +}
4504 +
4505 +if (! function_exists('wdk_generate_slug'))
4506 +{
4507 + function wdk_generate_slug($str, $separator = 'dash', $lowercase = TRUE)
4508 + {
4509 + if ($separator == 'dash')
4510 + {
4511 + $search = '_';
4512 + $replace = '-';
4513 + }
4514 + else
4515 + {
4516 + $search = '-';
4517 + $replace = '_';
4518 + }
4519 +
4520 + $dot='';
4521 + if($separator == 'dot'){
4522 + $str = str_replace(' ', '.', $str);
4523 + $dot='.';
4524 + }
4525 +
4526 + $trans = array(
4527 + $search => $replace,
4528 + "\s+" => $replace,
4529 + "[^a-z0-9".$replace.$dot."]" => '',
4530 + $replace."+" => $replace,
4531 + $replace."$" => '',
4532 + "^".$replace => ''
4533 + );
4534 +
4535 + // For Croatia
4536 + $str = str_replace(array('č','ć','ž','š','đ', 'Č','Ć','Ž','Š','Đ'),
4537 + array('c','c','z','s','d', 'c','c','z','s','d'), $str);
4538 +
4539 + // For Turkish
4540 + $str = str_replace(array('ş','Ş','ı','İ','ğ','Ğ','Ü','ü','Ö','ö','ç','Ç'),
4541 + array('s','s','i','i','g','g','u','u','o','o','c','c'), $str);
4542 +
4543 + // Russian alphabet
4544 + $str = str_replace(array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я'),
4545 + array('a','b','v','g','d','e','e','zh','z','i','y','k','l','m','n','o','p','r','s','t','u','f','kh','c','ch','sh','sh','','y','','e','yu','ya'), $str);
4546 + $str = str_replace(array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я'),
4547 + array('a','b','v','g','d','e','e','zh','z','i','y','k','l','m','n','o','p','r','s','t','u','f','kh','c','ch','sh','sh','','y','','e','yu','ya'), $str);
4548 +
4549 + // Ukrainian alphabet
4550 + $str = str_replace(array('Ґ','Є','І','Ї'),
4551 + array('G','E','I','I'), $str);
4552 + $str = str_replace(array('ґ','є','і','ї'),
4553 + array('g','e','i','i'), $str);
4554 + // Symbols
4555 + $str = str_replace(array("  ","’","–",'«','»','№','„','”'),
4556 + array("","","-",'','','no','',''), $str);
4557 +
4558 + // Alphabets Czech Croatian Turkish and other
4559 + $str = str_replace(array('Á','Ä','Ď','É','Ě','Ë','Í','Ň','Ń','Ó','Ŕ','Ř','Ť','Ú','Ů','Ý','Ź','Č','Ć','Ž','Š','Đ','Ş','İ','Ğ','Ü','Ö','Ç'),
4560 + array('a','a','d','e','e','e','i','n','n','o','r','r','t','u','u','y','z','c','c','z','s','d','s','i','g','u','o','c'), $str);
4561 + $str = str_replace(array('á','ä','ď','é','ě','ë','í','ň','ń','ó','ŕ','ř','ť','ú','ů','ý','ź','č','ć','ž','š','đ','ş','ı','ğ','ü','ö','ç'),
4562 + array('a','a','d','e','e','e','i','n','n','o','r','r','t','u','u','y','z','c','c','z','s','d','s','i','g','u','o','c'), $str);
4563 +
4564 + // For french
4565 + $str = str_replace(array('â','é','è','û','ê', 'à','Â','ç','ï','î','ä','î'),
4566 + array('a','e','e','u','e', 'a','c','c','i','î','a','î'), $str);
4567 +
4568 + $str = strip_tags(strtolower($str));
4569 +
4570 +
4571 + foreach ($trans as $key => $val)
4572 + {
4573 + $str = preg_replace("#".$key."#", $val, $str);
4574 + }
4575 +
4576 + return trim(stripslashes($str));
4577 + }
4578 +}
4579 +
4580 +
4581 +if (! function_exists('wdk_is_gps'))
4582 +{
4583 + function wdk_is_gps($gps = '')
4584 + {
4585 +
4586 + if(stripos($gps,',') === FALSE) {
4587 + return FALSE;
4588 + }
4589 +
4590 + $gps_coor = explode(',', $gps);
4591 +
4592 + if(count($gps_coor) != 2)
4593 + {
4594 + return FALSE;
4595 + }
4596 +
4597 + if(!is_numeric($gps_coor[0]) || !is_numeric($gps_coor[1]))
4598 + {
4599 + return FALSE;
4600 + }
4601 +
4602 + if($gps_coor[0] < -90 || $gps_coor[0] > 90 || $gps_coor[1] < -180 || $gps_coor[1] > 180)
4603 + {
4604 + return FALSE;
4605 + }
4606 +
4607 + return TRUE;
4608 + }
4609 +}
4610 +
4611 +if ( ! function_exists('is_wdk_is_useremail_exists'))
4612 +{
4613 + function is_wdk_is_useremail_exists($param)
4614 + {
4615 +
4616 + if(null == username_exists( $param ) && !email_exists($param)) {
4617 + return true;
4618 + }
4619 +
4620 + return false;
4621 + }
4622 +}
4623 +
4624 +
4625 +/*
4626 + Validation is natural integer
4627 +*/
4628 +if ( ! function_exists('is_wdk_is_natural'))
4629 +{
4630 + function is_wdk_is_natural($param)
4631 + {
4632 +
4633 + if (is_intval($param) && stripos($param, '.') === FALSE && stripos($param, ',') === FALSE) {
4634 + return true;
4635 + }
4636 +
4637 + return false;
4638 + }
4639 +}
4640 +
4641 +
4642 +/**
4643 + * Check is listing preview page exits
4644 + *
4645 + * @return bool
4646 +*/
4647 +if ( ! function_exists('wdk_is_listing_page_enabled'))
4648 +{
4649 + function wdk_is_listing_page_enabled ()
4650 + {
4651 +
4652 + if(get_option('wdk_listing_page') && get_post_status(get_option('wdk_listing_page')) =='publish') {
4653 + return true;
4654 + }
4655 +
4656 + return false;
4657 + }
4658 +}
4659 +
4660 +
4661 +/**
4662 + * Check is listing preview page exits
4663 + *
4664 + * @return bool
4665 +*/
4666 +if ( ! function_exists('replace_smart_data'))
4667 +{
4668 + function replace_smart_data($output = '', $replace_data = array()) {
4669 + // Match all occurrences of the pattern
4670 + if (preg_match_all('/\{([^}]+)\}/', $output, $matches)) {
4671 + foreach ($matches[1] as $key => $value) {
4672 + foreach ($replace_data as $replace_key => $replace_value) {
4673 + $output = str_replace('{'.$replace_key.'}', $replace_value, $output);
4674 + }
4675 + }
4676 + }
4677 + return $output;
4678 + }
4679 +}
4680 +
4681 +if ( ! function_exists('wdk_generate_missing_image_sizes'))
4682 +{
4683 + /**
4684 + * Wdk_generate_missing_image_sizes and update meta
4685 + * @param int $attachment_id of iamge
4686 + * @param string $size_name size of image based on wp intermediate_size
4687 + *
4688 + * @return bool
4689 + */
4690 + function wdk_generate_missing_image_sizes($attachment_id, $size_name = '') {
4691 + if(empty($size_name) || $size_name == 'full' || !get_option( "{$size_name}_size_w" )) {
4692 + return true;
4693 + }
4694 +
4695 + // Check if the attachment is an image
4696 + if (!wp_attachment_is_image($attachment_id)) {
4697 + return false;
4698 + }
4699 +
4700 + $file = get_attached_file( $attachment_id );
4701 + require_once(ABSPATH . "wp-admin" . '/includes/image.php');
4702 + $metadata = wp_generate_attachment_metadata($attachment_id, $file);
4703 + if ( ! isset( $metadata['sizes'][ $size_name ] ) ) {
4704 + // Generate the missing image size
4705 + $resized = image_make_intermediate_size( $file, get_option( "{$size_name}_size_w" ), get_option( "{$size_name}_size_h" ), get_option( "{$size_name}_crop" ) );
4706 +
4707 + // If the resizing was successful, add it to the metadata
4708 + if ( $resized ) {
4709 + $metadata['sizes'][ $size_name ] = $resized;
4710 + wp_update_attachment_metadata( $attachment_id, $metadata );
4711 + }
4712 + }
4713 + return true;
4714 + }
4715 +}
4716 +
4717 +if (!function_exists('wdk_get_languages')) {
4718 +
4719 + function wdk_get_languages($lang_code_id = null)
4720 + {
4721 + $lang_pattern = ['title' => '', 'lang_code' => '', 'id' => '', 'icon' => '', 'url' => ''];
4722 + $languages = [];
4723 +
4724 + // [qTranslate X]
4725 + if (function_exists('qtranxf_getSortedLanguages')) {
4726 + global $q_config;
4727 +
4728 + if (empty($q_config)) {
4729 + // Initialize qTranslate X language settings if needed
4730 + // qtranxf_init_language();
4731 + }
4732 +
4733 + $all_langs = qtranxf_getSortedLanguages();
4734 + if (count($all_langs) > 0) {
4735 + foreach ($all_langs as $key => $lang_code) {
4736 + $languages[$key + 1] = array_merge(
4737 + $lang_pattern,
4738 + [
4739 + 'title' => $q_config['language_name'][$lang_code],
4740 + 'lang_code' => $lang_code,
4741 + 'id' => $key + 1,
4742 + 'icon' => '',
4743 + 'url' => wdk_get_language_url($lang_code),
4744 + ]
4745 + );
4746 + }
4747 + }
4748 + }
4749 + // [/qTranslate X]
4750 +
4751 + // [WPML]
4752 + if (function_exists('icl_get_languages')) {
4753 + $wpml_langs = icl_get_languages('orderby=KEY&order=DIR&link_empty_to=str');
4754 + $k = 1;
4755 + foreach ($wpml_langs as $key => $lang_data) {
4756 + $languages[$k] = array_merge(
4757 + $lang_pattern,
4758 + [
4759 + 'title' => (!empty($lang_data['translated_name'])) ? $lang_data['translated_name'] : $lang_data['native_name'],
4760 + 'lang_code' => $lang_data['language_code'],
4761 + 'id' => $k,
4762 + 'icon' => (!empty($lang_data['country_flag_url'])) ? $lang_data['country_flag_url'] : WPDIRECTORYKIT_URL.'public/img/flags/'.$lang_data['language_code'].'.png',
4763 + 'url' => wdk_get_language_url($lang_data['language_code']),
4764 + ]
4765 + );
4766 + $k++;
4767 + }
4768 + } elseif (has_filter('wpml_active_languages')) {
4769 + $wpml_langs = apply_filters('wpml_active_languages', null) ?: get_query_var('lang', 'all');
4770 + if (is_array($wpml_langs)) {
4771 + foreach ($wpml_langs as $lang_data) {
4772 + if (!isset($lang_data['code']) && isset($lang_data['language_code'])) {
4773 + $lang_data['code'] = $lang_data['language_code'];
4774 + }
4775 + if (empty($lang_data['translated_name']) && !empty($lang_data['native_name'])) {
4776 + $lang_data['translated_name'] = $lang_data['native_name'];
4777 + }
4778 + $languages[$lang_data['id']] = array_merge(
4779 + $lang_pattern,
4780 + [
4781 + 'title' => (!empty($lang_data['translated_name'])) ? $lang_data['translated_name'] : $lang_data['native_name'],
4782 + 'lang_code' => $lang_data['code'],
4783 + 'id' => $lang_data['id'],
4784 + 'icon' => (!empty($lang_data['country_flag_url'])) ? $lang_data['country_flag_url'] : WPDIRECTORYKIT_URL.'public/img/flags/'.$lang_data['language_code'].'.png',
4785 + 'url' => wdk_get_language_url($lang_data['code']),
4786 + ]
4787 + );
4788 + }
4789 + }
4790 + }
4791 + // [/WPML]
4792 +
4793 + // [TranslatePress]
4794 + if (function_exists('trp_custom_language_switcher')) {
4795 + $k = 1;
4796 + foreach (trp_custom_language_switcher() as $lang_data) {
4797 + $languages[$k++] = array_merge(
4798 + $lang_pattern,
4799 + [
4800 + 'title' => $lang_data['language_name'],
4801 + 'lang_code' => $lang_data['language_code'],
4802 + 'id' => $k,
4803 + 'icon' => $lang_data['flag_link'],
4804 + 'url' => $lang_data['current_page_url'],
4805 + ]
4806 + );
4807 + }
4808 + }
4809 + // [/TranslatePress]
4810 +
4811 + if (!empty($lang_code_id)) {
4812 + foreach ($languages as $lang) {
4813 + if (($lang['id'] == $lang_code_id) || ($lang['lang_code'] == $lang_code_id)) {
4814 + return $lang['id'] == $lang_code_id ? $lang['lang_code'] : $lang['id'];
4815 + }
4816 + }
4817 + return false;
4818 + }
4819 +
4820 + return $languages;
4821 + }
4822 +}
4823 +
4824 +if (!function_exists('wdk_default_language')) {
4825 + function wdk_default_language()
4826 + {
4827 + // [qTranslate X]
4828 + if (function_exists('qtranxf_getLanguageDefault')) {
4829 + return qtranxf_getLanguageDefault();
4830 + }
4831 + // [/qTranslate X]
4832 +
4833 + // [WPML]
4834 + if (function_exists('icl_get_languages')) {
4835 + $wpml_langs = icl_get_languages('orderby=KEY&order=DIR&link_empty_to=str');
4836 + foreach ($wpml_langs as $lang_data) {
4837 + if ($lang_data['major'] == 1) {
4838 + return $lang_data['code'];
4839 + }
4840 + }
4841 + } elseif (has_filter('wpml_default_language')) {
4842 + return apply_filters('wpml_default_language', null);
4843 + }
4844 + // [/WPML]
4845 +
4846 + return 'en';
4847 + }
4848 +}
4849 +
4850 +if (!function_exists('wdk_current_language')) {
4851 + function wdk_current_language()
4852 + {
4853 + if (function_exists('trp_get_languages')) {
4854 + global $TRP_LANGUAGE;
4855 + $trp = TRP_Translate_Press::get_trp_instance();
4856 + $settings = $trp->get_component('settings')->get_settings();
4857 + $translation_languages = $trp->get_component('languages')->get_language_names($settings['publish-languages']);
4858 + if (isset($translation_languages[$TRP_LANGUAGE])) {
4859 + return $translation_languages[$TRP_LANGUAGE];
4860 + }
4861 + }
4862 +
4863 + // [qTranslate X]
4864 + if (function_exists('qtranxf_getLanguage')) {
4865 + return qtranxf_getLanguage();
4866 + }
4867 + // [/qTranslate X]
4868 +
4869 + // [WPML]
4870 + if (function_exists('icl_get_languages')) {
4871 + $wpml_langs = icl_get_languages('orderby=KEY&order=DIR&link_empty_to=str');
4872 + foreach ($wpml_langs as $lang_data) {
4873 + if ($lang_data['active'] == 1) {
4874 + return (!empty($lang_data['native_name'])) ? $lang_data['native_name'] : $lang_data['language_code'];
4875 + }
4876 + }
4877 + } elseif (has_filter('wpml_current_language')) {
4878 + return apply_filters('wpml_current_language', null);
4879 + }
4880 + // [/WPML]
4881 +
4882 + return 'en';
4883 + }
4884 +}
4885 +
4886 +if (!function_exists('wdk_current_language_id')) {
4887 + function wdk_current_language_id()
4888 + {
4889 + $lang_id = wdk_get_languages(wdk_current_language());
4890 + return is_numeric($lang_id) ? $lang_id : wdk_default_language_id();
4891 + }
4892 +}
4893 +
4894 +if (!function_exists('wdk_default_language_id')) {
4895 + function wdk_default_language_id()
4896 + {
4897 + $lang_id = wdk_get_languages(wdk_default_language());
4898 + return is_numeric($lang_id) ? $lang_id : '1';
4899 + }
4900 +}
4901 +
4902 +if (!function_exists('wdk_get_language_name')) {
4903 + function wdk_get_language_name($id_or_code)
4904 + {
4905 + $langs = wdk_get_languages();
4906 + foreach ($langs as $lang) {
4907 + if ($lang['lang_code'] == $id_or_code || $lang['id'] == $id_or_code) {
4908 + return $lang['title'];
4909 + }
4910 + }
4911 + return '';
4912 + }
4913 +}
4914 +
4915 +if (!function_exists('wdk_get_language_url')) {
4916 + function wdk_get_language_url($lang_code)
4917 + {
4918 + // [qTranslate X]
4919 + if (function_exists('qtranxf_convertURL')) {
4920 + return qtranxf_convertURL('', $lang_code, false, true);
4921 + }
4922 + // [/qTranslate X]
4923 +
4924 + // [WPML]
4925 + if (function_exists('icl_get_languages')) {
4926 + $wpml_langs = icl_get_languages('orderby=KEY&order=DIR&link_empty_to=str');
4927 + foreach ($wpml_langs as $lang_data) {
4928 + if ($lang_data['language_code'] == $lang_code) {
4929 + return $lang_data['url'];
4930 + }
4931 + }
4932 + } elseif (has_filter('wpml_active_languages')) {
4933 + $wpml_langs = apply_filters('wpml_active_languages', null);
4934 + foreach ($wpml_langs as $lang_data) {
4935 + if (!isset($lang_data['language_code']) && isset($lang_data['language_code'])) {
4936 + $lang_data['language_code'] = $lang_data['language_code'];
4937 + }
4938 + if (empty($lang_data['translated_name']) && !empty($lang_data['native_name'])) {
4939 + $lang_data['translated_name'] = $lang_data['native_name'];
4940 + }
4941 + $url = wdk_wpml_ls_language_url($lang_data['url'], $lang_data);
4942 + if ($lang_data['language_code'] == $lang_code) {
4943 + return $url;
4944 + }
4945 + }
4946 + }
4947 + // [/WPML]
4948 +
4949 + return '';
4950 + }
4951 +}
4952 +
4953 +function wdk_set_user_default_language($user_id = null)
4954 +{
4955 + if (is_null($user_id)) {
4956 + $user_id = get_current_user_id();
4957 + }
4958 +
4959 + $get_language = get_user_meta($user_id, 'user_language', true);
4960 +
4961 + if (!$get_language && (function_exists('icl_get_languages') || has_filter('wpml_active_languages'))) {
4962 + do_action('wpml_switch_language', $get_language);
4963 + }
4964 +}
4965 +
4966 +function wdk_set_language($lang_code = null)
4967 +{
4968 + if (!is_null($lang_code) && (function_exists('icl_get_languages') || has_filter('wpml_active_languages'))) {
4969 + do_action('wpml_switch_language', $lang_code);
4970 + }
4971 +}
4972 +
4973 +function wdk_wpml_ls_language_url($url, $data)
4974 +{
4975 + global $sitepress;
4976 +
4977 + if (is_object($sitepress)) {
4978 + $sitepress_settings = $sitepress->get_settings();
4979 + }
4980 +
4981 + return $url;
4982 +}
4983 +
4984 +add_filter('wpml_ls_language_url', 'wdk_wpml_ls_language_url', 10, 3);
4985 +
4986 +if (!function_exists('wdk_calculate_nights')) {
4987 + /**
4988 + * Calculate the number of nights between two dates
4989 + *
4990 + * This function takes two date strings as input and calculates the number of nights
4991 + * (i.e., the difference in days) between them. It returns the total number of nights
4992 + * between the provided start and end dates. The date format must be valid for PHP's
4993 + * DateTime class.
4994 + *
4995 + * @param string $start_date The start date in 'Y-m-d' format.
4996 + * @param string $end_date The end date in 'Y-m-d' format.
4997 + * @return int The number of nights (days between the two dates).
4998 + */
4999 + function wdk_calculate_nights($start_date, $end_date) {
5000 +
5001 + /* normalize date */
5002 + $start_date = wdk_normalize_date_db($start_date, 'Y-m-d H:i:s', 'Y-m-d');
5003 + $end_date = wdk_normalize_date_db($end_date, 'Y-m-d H:i:s', 'Y-m-d');
5004 +
5005 + // Create DateTime objects for start and end dates
5006 + $start = new DateTime($start_date);
5007 + $end = new DateTime($end_date);
5008 +
5009 + // Calculate the difference between the two dates
5010 + $difference = $start->diff($end);
5011 +
5012 + // Return the number of nights (difference in days)
5013 + return $difference->days;
5014 + }
5015 +}
5016 +
5017 +if ( ! function_exists('wdk_select_db_field_ajax'))
5018 +{
5019 + /**
5020 + * Return select2 ajax
5021 + *
5022 + * @param string option Option key
5023 + * @return string alt or title
5024 + */
5025 + function wdk_select_db_field_ajax($name = '', $selected = NULL, $empty_value='', $filter_id = '')
5026 + {
5027 + $WMVC = &wdk_get_instance();
5028 +
5029 + static $counter = 0;
5030 + $form = '<select data-ajax="'.admin_url('admin-ajax.php').'" name="'.$name.'" data-id="'.$filter_id.'" data-placeholder="'.$empty_value.'" class="form-control wdk_select2_field_suggestion" id="wdk_select2_field_'.$filter_id.'_'.$counter.'" multiple="">';
5031 + if($selected) {
5032 + if(is_array($selected)) {
5033 + /* where in */
5034 + foreach ($selected as $item) {
5035 + $form .= '<option selected="selected" value="'.esc_attr($item).'">'.esc_html($item).'</option>';
5036 + }
5037 + } elseif(is_string($selected)) {
5038 + $form .= '<option selected="selected" value="'.esc_attr($selected).'">'.esc_html($selected).'</option>';
5039 + }
5040 + } else {
5041 + //$form .= '<option value="" selected="selected">'.esc_html__('Not selected', 'wpdirectorykit').'</option>';
5042 + }
5043 + $form .= '</select>';
5044 +
5045 + //load javascript library
5046 + if($counter==0)
5047 + {
5048 + wp_enqueue_script('select2-select2');
5049 + wp_enqueue_script('wdk-select2');
5050 + wp_enqueue_style('select2-select2');
5051 + }
5052 + ?>
5053 + <?php
5054 + $counter++;
5055 + return $form;
5056 +
5057 + }
5058 +}
5059 +
5060 +if ( ! function_exists('wdk_next_month_payment_day'))
5061 +{
5062 + /**
5063 + * Gets the next payment date one month later, considering the number of days in the next month.
5064 + *
5065 + * @param string $currentDate The current payment date in 'Y-m-d H:i:s' format.
5066 + * @return string|false The next payment date in 'Y-m-d H:i:s' format or false on error.
5067 + */
5068 + function wdk_next_month_payment_day($currentDate, $time = false, $wanted_day = NULL) {
5069 + $nextDate = null;
5070 + $timestamp = strtotime($currentDate);
5071 + $daysInNextMonth = date('t', strtotime('+1 month', strtotime(date('Y-m', $timestamp))));
5072 + $currentDay = (int)date('d', $timestamp);
5073 +
5074 + $timeFormat = $time ? "H:i:s" : "00:00:00";
5075 +
5076 +
5077 + // Determine the wanted day
5078 + if ($wanted_day !== NULL) {
5079 + $wanted_day = (int)date('d', strtotime($wanted_day));
5080 + } else {
5081 + $wanted_day = (int)date('d', $timestamp);
5082 + }
5083 +
5084 + $nextMonth = strtotime('first day of next month', $timestamp);
5085 + $daysInNextMonth = date('t', $nextMonth);
5086 +
5087 + // Adjust for the wanted day
5088 + if ($wanted_day > $daysInNextMonth ||
5089 + (
5090 + get_option('wdk_membership_next_month_calculation_with_last_day')
5091 +
5092 + && (
5093 + $currentDay >= 30 || $currentDay == date('t', $timestamp)
5094 + )
5095 + )
5096 + ) {
5097 + // If the wanted day exceeds the max days of the next month, use the last day of the month
5098 + $nextDate = date("Y-m-{$daysInNextMonth} {$timeFormat}", $nextMonth);
5099 + } else {
5100 + // Otherwise, set the exact wanted day
5101 + $nextDate = date("Y-m-{$wanted_day} {$timeFormat}", $nextMonth);
5102 + }
5103 +
5104 + return ($nextDate) ? $nextDate : false;
5105 + }
5106 +}
5107 +
5108 +if ( ! function_exists('wdk_next_year_payment_day'))
5109 +{
5110 + /**
5111 + * Gets the next payment date one year later, considering the number of days in the next month.
5112 + *
5113 + * @param string $currentDate The current payment date in 'Y-m-d H:i:s' format.
5114 + * @return string|false The next payment date in 'Y-m-d H:i:s' format or false on error.
5115 + */
5116 +
5117 + function wdk_next_year_payment_day($currentDate, $time = false) {
5118 + $nextDate = null;
5119 + $timestamp = strtotime($currentDate);
5120 + $nextYearTimestamp = strtotime('+1 year', strtotime(date('Y-m', $timestamp)));
5121 + $daysInNextMonth = date('t', $nextYearTimestamp);
5122 + $currentDay = date('j', $timestamp);
5123 + $timeFormat = "00:00:00";
5124 + if($time) {
5125 + $timeFormat = "H:i:s";
5126 + }
5127 + if ($currentDay > $daysInNextMonth) {
5128 + $nextDate = date('Y-m-d '.$timeFormat, strtotime('last day of this month', $nextYearTimestamp));
5129 + } else {
5130 + $nextDate = date('Y-m-d '.$timeFormat, strtotime('+1 year', $timestamp));
5131 + }
5132 +
5133 + return ($nextDate) ? $nextDate : false;
5134 + }
5135 +}
5136 +
5137 +if ( ! function_exists('wdk_generate_auto_login_link'))
5138 +{
5139 + function wdk_generate_auto_login_link( $user_id = null ) {
5140 + $token = substr(md5($user_id.NONCE_KEY.'wpdirectorykit'),0,10);
5141 +
5142 + $login_url = site_url( "/?auto-login=1&user_id={$user_id}&token={$token}" );
5143 + return $login_url;
5144 + }
5145 +}
5146 +
5147 +if ( ! function_exists('wdk_get_user_subscription_id'))
5148 +{
5149 + function wdk_get_user_subscription_id($user_id = null) {
5150 + global $Winter_MVC_wdk_membership;
5151 + if(!isset($Winter_MVC_wdk_membership)) {
5152 + return false;
5153 + }
5154 + $Winter_MVC_wdk_membership->model('subscription_user_m');
5155 + $user_subscription = $Winter_MVC_wdk_membership->subscription_user_m->get_by(array('user_id'=>$user_id), TRUE);
5156 + return wmvc_show_data('subscription_id', $user_subscription, '', TRUE, TRUE);
5157 + }
5158 +}
5159 +
5160 +if ( ! function_exists('is_wdk_related_validation'))
5161 + /**
5162 + * IS WDK related validation
5163 + *
5164 + * @return bool true if exists dash
5165 + */
5166 + {
5167 + function is_wdk_related_validation($param)
5168 + {
5169 +
5170 + if(empty($param)) {
5171 + return TRUE;
5172 + }
5173 +
5174 + $listing_id = (!empty($_GET['id'])) ? intval(sanitize_text_field($_GET['id'])) : null;
5175 +
5176 +
5177 + global $Winter_MVC_WDK;
5178 + $Winter_MVC_WDK->model('listing_m');
5179 +
5180 + $Winter_MVC_WDK->db->select('post_id');
5181 + $Winter_MVC_WDK->db->where(array(
5182 + '(post_id IN ('.esc_sql(sanitize_text_field($param)).'))' => NULL,
5183 + '((`listing_related_ids` IS NOT NULL AND `listing_related_ids` !="") OR (`listing_parent_post_id` IS NOT NULL AND `listing_parent_post_id` !=0))' => NULL,
5184 + ));
5185 +
5186 + if($listing_id) {
5187 + $Winter_MVC_WDK->db->where(array(
5188 + '`listing_parent_post_id` !='.esc_sql($listing_id).'' => NULL,
5189 + ));
5190 + }
5191 +
5192 + $Winter_MVC_WDK->db->from($Winter_MVC_WDK->listing_m->_table_name);
5193 + $Winter_MVC_WDK->db->limit(5);
5194 +
5195 + $Winter_MVC_WDK->db->get();
5196 + if ($Winter_MVC_WDK->db->num_rows() > 0) {
5197 + $db_results = $Winter_MVC_WDK->db->results();
5198 + } else {
5199 + $db_results = null;
5200 + }
5201 +
5202 + if (!empty($db_results)) {
5203 + return false;
5204 + }
5205 +
5206 + return TRUE;
5207 + }
5208 + }
5209 +
5210 + /**
5211 + * Renders an Elementor template by its title or post ID.
5212 + *
5213 + * Attempts to find and render an Elementor layout/template using the post title or post ID.
5214 + * If the post is found and public, its rendered Elementor content is returned, otherwise post content fallback or error.
5215 + *
5216 + * @since 1.0.0
5217 + * @param string|int $title The title (or ID if $id=true) of the Elementor template to render.
5218 + * @param bool $id Optional. If true, $title is treated as a post ID. If false (default), searches by title.
5219 + * @return string|false Rendered template HTML on success, public/content fallback, or error message/false on failure.
5220 + */
5221 + function wdk_render_elementor_template( $title, $id = false ) {
5222 + // Initialize variables.
5223 + $layout_id = null;
5224 + $template_content = '';
5225 +
5226 + // Determine the layout/post ID.
5227 + if ( ! $id ) {
5228 + // Search by post title. Returns WP_Post/object or null.
5229 + $found_post = wdk_page_by_title( $title, OBJECT, ['elementor_library','page'] );
5230 + $layout_id = $found_post ? $found_post->ID : null;
5231 +
5232 + // Support WPML translation if present.
5233 + // The filter may change $layout_id to a translated post's ID if needed.
5234 + $layout_id = apply_filters( 'wpml_object_id', $layout_id, 'elementor_library', true );
5235 + } else {
5236 + // ID provided directly.
5237 + $layout_id = intval($title);
5238 + }
5239 +
5240 + // Early return if no valid layout found.
5241 + if ( empty( $layout_id ) ) {
5242 + return false;
5243 + }
5244 +
5245 + // Get post object (Elementor template or WP Page).
5246 + $post_data = get_post( $layout_id );
5247 +
5248 +
5249 + // Validate post: should exist, be published, and not password protected.
5250 + if ( ! $post_data || $post_data->post_status !== 'publish' || post_password_required( $post_data ) ) {
5251 + return esc_html__( 'Layout is not public', 'wpdirectorykit' );
5252 + }
5253 +
5254 + // Render content depending on post type.
5255 + if (
5256 + ( isset($post_data->post_type) && $post_data->post_type === 'elementor_library' ) ||
5257 + ( isset($post_data->post_type) && $post_data->post_type === 'page' )
5258 + ) {
5259 + // Try to render using Elementor's frontend builder.
5260 + if ( class_exists('\Elementor\Plugin') && method_exists('\Elementor\Plugin', 'instance') ) {
5261 + $elementor_instance = \Elementor\Plugin::instance();
5262 + $content = $elementor_instance->frontend->get_builder_content_for_display( $layout_id );
5263 + $template_content = ! empty( $content ) ? $content : $post_data->post_content;
5264 + } else {
5265 + // Elementor not present; fallback to post content.
5266 + $template_content = $post_data->post_content;
5267 + }
5268 + } else {
5269 + // Non-Elementor post types, fallback to post content.
5270 + $template_content = $post_data->post_content;
5271 + }
5272 +
5273 + /**
5274 + * Filter: Allows modification of the rendered Elementor template content before returning.
5275 + *
5276 + * @param string $template_content The rendered template content.
5277 + * @param int $layout_id The ID of the layout/template.
5278 + * @param WP_Post $post_data The WP_Post object of the layout/template.
5279 + */
5280 + return apply_filters( 'wdk_render_elementor_template_output', $template_content, $layout_id, $post_data );
5281 + }
5282 +
5283 + if(!function_exists('wdk_esc_sql')) {
5284 + function wdk_esc_sql ($value = '') {
5285 + return esc_sql(trim(preg_replace([
5286 + '/\bselect\b/i',
5287 + '/\binsert\b/i',
5288 + '/\bupdate\b/i',
5289 + '/\bdelete\b/i',
5290 + '/\bunion\b/i',
5291 + '/\bextractvalue\b/i',
5292 + '/\bversion\s*\(\)/i',
5293 + '/\bdatabase\s*\(\)/i',
5294 + '/\bconcat\s*\(/i',
5295 + '/\bdrop\b/i',
5296 + '/\bsleep\s*\(/i',
5297 + '/\bbenchmark\s*\(/i',
5298 + '/--/',
5299 + '/#/i',
5300 + '/\/\*/',
5301 +
5302 + // EXTRA BLOCK YOU REQUESTED
5303 + '/\\\\/', // remove backslash \
5304 + '/\|/', // remove |
5305 + '/%/', // remove %
5306 + ], '', sanitize_text_field($value))));
5307 + }
5308 + }
5309 +?>