PluginProbe
WP Directory Kit / 1.4.8
WP Directory Kit v1.4.8
1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 1.4.1 All 35 releases
← All changes | application/helpers/Basic.php +1781 -142 1.2.31.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 {
@@ -20,9 +20,9 @@
20 20 include $field_view_path;
21 21 }
22 22 else
23 23 {
24 - echo __('Missing VIEW file: ', 'wpdirectorykit').esc_html($field_type).'.php';
24 + echo __('Missing VIEW file:', 'wpdirectorykit').' '.esc_html($field_type).'.php';
25 25 }
26 26 }
27 27 }
28 28
@@ -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 }
@@ -173,9 +184,9 @@
173 184 else
174 185 {
175 186 /* show missing view file of field, only if print enable */
176 187 if($print)
177 - $output .= __('Missing VIEW file: ', 'wpdirectorykit').esc_html($subfolder).(wmvc_show_data('field_type', $field)).'.php';
188 + $output .= __('Missing VIEW file:', 'wpdirectorykit').' '.esc_html($subfolder).(wmvc_show_data('field_type', $field)).'.php';
178 189 }
179 190
180 191 }
181 192
@@ -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);
@@ -644,10 +907,10 @@
644 907 $gen_q.=$col_name." <= ".intval($val)." AND ";
645 908 } else if(strpos($key, 'DATE') !== FALSE) {
646 909 if(wdk_is_date($val))
647 910 {
648 - $gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d');
649 - $gen_q.=$col_name." >= ".$gen_search." AND ";
911 + $gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d H:i:s');
912 + $gen_q.=$col_name." <= '".$gen_search."' AND ";
650 913 }
651 914 } else {
652 915 $gen_q.=$col_name." <= '".$val."' AND ";
653 916 }
@@ -654,16 +917,16 @@
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))
663 926 {
664 - $gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d');
665 - $gen_q.=$col_name." >= ".$gen_search." AND ";
927 + $gen_search = wdk_normalize_date_db($val, 'Y-m-d H:i:s', 'Y-m-d H:i:s');
928 + $gen_q.=$col_name." >= '".$gen_search."' AND ";
666 929 }
667 930 } else {
668 931 $gen_q.=$col_name." >= '".$val."' AND ";
669 932 }
@@ -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 }
@@ -774,8 +1037,9 @@
774 1037 }
775 1038 }
776 1039 elseif($key == 'location_id')
777 1040 {
1041 + if(empty($val)) continue;
778 1042
779 1043 if(is_string($val) && strpos($val, ',') !== FALSE){
780 1044 $val =explode(',', $val);
781 1045 } elseif(is_string($val)){
@@ -790,10 +1054,10 @@
790 1054 }
791 1055
792 1056 $sql_search = '';
793 1057 foreach ($val as $v) {
794 - if(empty($v)) continue;
795 -
1058 + if(empty($v) || !is_intval($v)) continue;
1059 +
796 1060 if(!empty($sql_search))
797 1061 $sql_search .= " OR ";
798 1062
799 1063 $sql_search .= " ".$WMVC->listing_m->_table_name.".`location_id`=".intval($v)."";
@@ -798,8 +1062,10 @@
798 1062
799 1063 $sql_search .= " ".$WMVC->listing_m->_table_name.".`location_id`=".intval($v)."";
800 1064 $sql_search .= " OR `location_table`.`parent_id`=".intval($v)."";
801 1065
1066 + $sql_search .= " OR CONCAT(',', location_table.parent_path, ',') LIKE CONCAT('%,', ".intval($v).", ',%')";
1067 +
802 1068 /* other locations */
803 1069 /* multi select */
804 1070 if(false){
805 1071 $sql_search .= " OR `".$WMVC->db->prefix."wdk_listings`.`post_id` IN (SELECT `post_id` FROM `".$WMVC->db->prefix."wdk_listings_locations` WHERE `location_id` = ".intval($v).") ";
@@ -817,8 +1083,10 @@
817 1083 }
818 1084 elseif($key == 'category_id')
819 1085 {
820 1086
1087 + if(empty($val)) continue;
1088 +
821 1089 if(is_string($val) && strpos($val, ',') !== FALSE){
822 1090 $val =explode(',', $val);
823 1091 } elseif(is_string($val)){
824 1092 $val =array($val);
@@ -831,9 +1099,9 @@
831 1099 }
832 1100
833 1101 $sql_search = '';
834 1102 foreach ($val as $v) {
835 - if(empty($v)) continue;
1103 + if(empty($v) || !is_intval($v)) continue;
836 1104
837 1105 if(!empty($sql_search))
838 1106 $sql_search .= " OR ";
839 1107
@@ -838,9 +1106,10 @@
838 1106 $sql_search .= " OR ";
839 1107
840 1108 $sql_search .= " ".$WMVC->db->prefix."wdk_listings.`category_id` = ".intval($v)."";
841 1109 $sql_search .= " OR `category_table`.`parent_id`=".intval($v)."";
842 -
1110 + $sql_search .= " OR CONCAT(',', category_table.parent_path, ',') LIKE CONCAT('%,', ".intval($v).", ',%')";
1111 +
843 1112 /* other categories */
844 1113 if(false){
845 1114 $sql_search .= " OR `".$WMVC->db->prefix."wdk_listings`.`post_id` IN (SELECT `post_id` FROM `".$WMVC->db->prefix."wdk_listings_categories` WHERE `category_id` = ".intval($v).")";
846 1115 } elseif(false) {
@@ -895,10 +1164,15 @@
895 1164
896 1165 if(!empty($sql_search))
897 1166 $gen_q.=" ( ".$sql_search." ) AND ";
898 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 + }
899 1174 }
900 -
901 1175 }
902 1176
903 1177 $gen_q = substr($gen_q, 0, -5);
904 1178
@@ -904,14 +1178,119 @@
904 1178
905 1179 if(!empty($gen_q))
906 1180 $WMVC->db->where("($gen_q)");
907 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]
908 1209
909 1210 // order
910 - if(isset($_GET_clone['order_by']))
911 - {
912 - $_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_listings.post_id', $_GET_clone['order_by']);
913 - $WMVC->db->order_by($_GET_clone['order_by']);
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 +
914 1293 }
915 1294
916 1295 }
917 1296 }
@@ -928,9 +1307,9 @@
928 1307
929 1308 if(isset($custom_parameters['order_by'])) {
930 1309
931 1310 if(isset($_GET_clone['order_by']) && !empty($_GET_clone['order_by'])) {
932 - $_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']);
933 1312 } else {
934 1313 $_GET_clone['order_by'] = $custom_parameters['order_by'];
935 1314 }
936 1315
@@ -944,9 +1323,9 @@
944 1323 $WMVC->model($model_name);
945 1324
946 1325 $smart_search = '';
947 1326 if(isset($_GET_clone['profile_search']))
948 - $smart_search = sanitize_text_field($_GET_clone['profile_search']);
1327 + $smart_search = wdk_esc_sql(sanitize_text_field($_GET_clone['profile_search']));
949 1328
950 1329 $available_fields = array('user_login','user_nicename','user_email','user_url','display_name');
951 1330
952 1331 if(isset($_GET_clone['is_activated'])){
@@ -1113,9 +1492,9 @@
1113 1492 // order
1114 1493 if(isset($_GET_clone['order_by']))
1115 1494 {
1116 1495 $_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_favorite.post_id', $_GET_clone['order_by']);
1117 - $WMVC->db->order_by($_GET_clone['order_by']);
1496 + $WMVC->db->order_by(wdk_esc_sql(sanitize_text_field($_GET_clone['order_by'])));
1118 1497 }
1119 1498
1120 1499 }
1121 1500 }
@@ -1131,9 +1510,9 @@
1131 1510 //$WMVC->model('listing_m');
1132 1511
1133 1512 $smart_search = '';
1134 1513 if(isset($_GET_clone['search']))
1135 - $smart_search = sanitize_text_field($_GET_clone['search']);
1514 + $smart_search = wdk_esc_sql(sanitize_text_field($_GET_clone['search']));
1136 1515
1137 1516 $available_fields = $WMVC->$model_name->get_available_fields();
1138 1517
1139 1518 /* Пet column names from wdk_package and add to allow search +
@@ -1284,9 +1663,9 @@
1284 1663 // order
1285 1664 if(isset($_GET_clone['order_by']))
1286 1665 {
1287 1666 $_GET_clone['order_by'] = str_replace('post_id', $WMVC->db->prefix.'wdk_messages.post_id', $_GET_clone['order_by']);
1288 - $WMVC->db->order_by($_GET_clone['order_by']);
1667 + $WMVC->db->order_by(wdk_esc_sql(sanitize_text_field($_GET_clone['order_by'])));
1289 1668 }
1290 1669
1291 1670 }
1292 1671 }
@@ -1319,18 +1698,20 @@
1319 1698
1320 1699 if(isset($_GET[$page_var]))
1321 1700 $current_page = intval(wmvc_xss_clean($_GET[$page_var]));
1322 1701
1323 - if(!isset($texts['previous_page']))$texts['previous_page'] = 'Previous page';
1324 - 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');
1325 1704 if(!isset($texts['first_page']))$texts['first_page'] = '';
1326 1705 if(!isset($texts['last_page']))$texts['last_page'] = '';
1327 - if(!isset($texts['items']))$texts['items'] = 'items';
1706 + if(!isset($texts['items']))$texts['items'] = esc_html__('items', 'wpdirectorykit');
1328 1707
1329 1708 if(empty($current_page))$current_page = 1;
1330 1709
1331 1710 // get url
1332 - $url = strtok($_SERVER["REQUEST_URI"], '?');
1711 + $url = strtok(wdk_server_current_url(), '?');
1712 +
1713 +
1333 1714 $qs_parameters = wmvc_xss_clean( $_GET );
1334 1715 unset($qs_parameters[$page_var]);
1335 1716 $qs_part = http_build_query($qs_parameters);
1336 1717 $url = wdk_url_suffix($url, $qs_part);
@@ -1353,16 +1734,16 @@
1353 1734
1354 1735 $output .= '<div class="nav-links">';
1355 1736
1356 1737 if($enable_latest_first && $current_page-1 > 0)
1357 - $output.= '<a class="next page-numbers" href="'.esc_url($url).'#results"><span class="screen-reader-text">'.esc_html($texts['first_page']).'</span><span aria-hidden="true">«</span></a>';
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>';
1358 1739
1359 1740 if ($current_page-1 > 0) {
1360 1741
1361 - $output.= '<a class="next page-numbers" href="'.esc_url(wdk_url_suffix($url,esc_attr($page_var).'='.esc_attr($current_page-1))).'#results"><span class="screen-reader-text">'.esc_html($texts['previous_page']).'</span><span aria-hidden="true">‹</span></a>';
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>';
1362 1743 } elseif($enable_compact)
1363 1744 {
1364 - $output.= '<span class="next page-numbers disabled" href=""><span class="screen-reader-text">'.esc_html($texts['previous_page']).'</span><span aria-hidden="true">‹</span></span>';
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>';
1365 1746 }
1366 1747
1367 1748 if (!$enable_compact) {
1368 1749 for ($i = 1 ; $i <= $total_pages; $i++) {
@@ -1370,9 +1751,9 @@
1370 1751 if(($current_page-$limit_items) <= $i && ($current_page+$limit_items) >= $i) {
1371 1752 if (($current_page == $i)) {
1372 1753 $output.= '<span aria-current="page" class="page-numbers current">'.$i.'</span>';
1373 1754 } else {
1374 - $output.= '<a class="page-numbers" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($i))).'#results">'.esc_attr($i).'</a>';
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>';
1375 1756 }
1376 1757 }
1377 1758 }
1378 1759 } else {
@@ -1380,17 +1761,17 @@
1380 1761 }
1381 1762
1382 1763 if($current_page+1 <= $total_pages)
1383 1764 {
1384 - $output.= '<a class="next page-numbers" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($current_page+1))).'#results"><span class="screen-reader-text">'.esc_html($texts['next_page']).'</span><span aria-hidden="true">›</span></a>';
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>';
1385 1766 }
1386 1767 elseif($enable_compact)
1387 1768 {
1388 - $output.= '<a class="next page-numbers disabled" href=""><span class="screen-reader-text">'.esc_html($texts['next_page']).'</span><span aria-hidden="true">›</span></a>';
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>';
1389 1770 }
1390 1771
1391 1772 if($enable_latest_first && $current_page+1 <= $total_pages)
1392 - $output.= '<a class="next page-numbers" href="'.esc_url(wdk_url_suffix($url, esc_attr($page_var).'='.esc_attr($total_pages))).'#results"><span class="screen-reader-text">'.esc_html($texts['last_page']).'</span><span aria-hidden="true">»</span></a>';
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>';
1393 1774
1394 1775
1395 1776 $output.= '</div>';
1396 1777 $output.= '</nav>';
@@ -1430,8 +1811,12 @@
1430 1811 global $wdk_text_search_button;
1431 1812 if(empty($wdk_text_search_button))
1432 1813 $wdk_text_search_button = esc_html__('Search','wpdirectorykit');
1433 1814
1815 + global $wdk_text_reset_button;
1816 + if(empty($wdk_text_reset_button))
1817 + $wdk_text_reset_button = esc_html__('Reset','wpdirectorykit');
1818 +
1434 1819 global $wdk_text_more_button;
1435 1820 if(empty($wdk_text_more_button))
1436 1821 $wdk_text_more_button = esc_html__('More','wpdirectorykit');
1437 1822
@@ -1444,12 +1829,16 @@
1444 1829 <div class="wdk-col wdk-col-btns">
1445 1830 <div class="wdk-field wdk-field-btn">
1446 1831 <div class="wdk-field-group wdk-field-group-additional">
1447 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>
1448 - <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' />
1449 1834 </div>
1835 + <div class="wdk-field-group wdk-field-group-reset">
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>
1837 + </div>
1450 1838 <div class="wdk-field-group wdk-field-group-search">
1451 - <button id="wdk-start-primary" type="submit" class="wdk-search-start wdk-click-load-animation">&nbsp;&nbsp;<?php echo esc_html($wdk_text_search_button);?>&nbsp;<i class="fa fa-spinner fa-spin fa-ajax-indicator" style="display: none;"></i>&nbsp;</button>
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>
1840 +
1452 1841 <?php if(function_exists('run_wdk_save_search') && get_option('wdk_save_search_show_on_searchform')):?>
1453 1842 <div class="section-widget-control right">
1454 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">
1455 1844 <i class="fas fa-save" aria-hidden="true"></i>
@@ -1474,9 +1863,9 @@
1474 1863 */
1475 1864 if ( ! function_exists('wdk_treefield_option'))
1476 1865 {
1477 1866 function wdk_treefield_option($name = '', $table=NULL, $selected = NULL,
1478 - $column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE, $sql_where='')
1867 + $column = 'category_title', $language_id=NULL, $empty_value='', $filter_ids = '', $user_check = FALSE, $sql_where='', $hide_fields = '')
1479 1868 {
1480 1869 $WMVC = &wdk_get_instance();
1481 1870
1482 1871 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
@@ -1519,14 +1908,16 @@
1519 1908 ajax_param: {
1520 1909 "page": 'wdk_frontendajax',
1521 1910 "function": 'treefieldid',
1522 1911 "action": 'wdk_public_action',
1912 + "wdk_secure": '<?php echo wp_create_nonce( 'wdk_secure_treefieldid' );?>',
1523 1913 "table": '<?php echo esc_js($table); ?>',
1524 1914 "filter_ids": '<?php echo esc_js($filter_ids); ?>',
1525 1915 "start_id": '<?php if(!empty($filter_ids)) esc_js($selected); else echo ""; ?>',
1526 1916 "empty_value": '<?php echo esc_js($empty_value); ?>',
1527 1917 "user_check": '<?php echo esc_js($user_check); ?>',
1528 - "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); ?>'
1529 1920 },
1530 1921 attribute_id: '<?php echo esc_js($attribute_id); ?>',
1531 1922 language_id: '<?php echo esc_js($language_id); ?>',
1532 1923 attribute_value: '<?php echo esc_js($column); ?>',
@@ -1552,9 +1943,9 @@
1552 1943 */
1553 1944 if ( ! function_exists('wdk_treefield_option_checkboxes'))
1554 1945 {
1555 1946 function wdk_treefield_option_checkboxes($name = '', $table=NULL, $selected = NULL,
1556 - $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 = '')
1557 1948 {
1558 1949 $WMVC = &wdk_get_instance();
1559 1950
1560 1951 if(is_array($filter_ids)) $filter_ids = implode(',', $filter_ids);
@@ -1573,12 +1964,11 @@
1573 1964
1574 1965 $values = '';
1575 1966 if(!empty($selected)){
1576 1967 $ids = array();
1577 -
1578 1968 if(is_string($selected) && strpos($selected, ',') !== FALSE){
1579 1969 $val_selected = explode(',', $selected);
1580 - } elseif(is_string($selected)){
1970 + } elseif($selected){
1581 1971 $val_selected = array($selected);
1582 1972 }
1583 1973
1584 1974 foreach($val_selected as $selected_item) {
@@ -1628,12 +2018,14 @@
1628 2018 ajax_param: {
1629 2019 "page": 'wdk_frontendajax',
1630 2020 "function": 'treefieldid_checkboxes',
1631 2021 "action": 'wdk_public_action',
2022 + "wdk_secure": '<?php echo wp_create_nonce( 'wdk_secure_treefieldid_checkboxes' );?>',
1632 2023 "table": '<?php echo esc_js($table); ?>',
1633 2024 "filter_ids": '<?php echo esc_js($filter_ids); ?>',
1634 2025 "empty_value": '<?php echo esc_js($empty_value); ?>',
1635 2026 "user_check": '<?php echo esc_js($user_check); ?>',
2027 + "hide_fields": '<?php echo esc_js($hide_fields); ?>',
1636 2028 },
1637 2029 selected: '<?php echo esc_js($selected); ?>',
1638 2030 attribute_id: '<?php echo esc_js($attribute_id); ?>',
1639 2031 language_id: '<?php echo esc_js($language_id); ?>',
@@ -1657,11 +2049,19 @@
1657 2049 if ( ! function_exists('wdk_filter_decimal'))
1658 2050 {
1659 2051 function wdk_filter_decimal($string = '')
1660 2052 {
1661 - if(substr($string, -3, 3) === ".00") {
1662 - return substr($string, 0, -3);
1663 - }
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 + }
1664 2064
1665 2065 return $string;
1666 2066 }
1667 2067 }
@@ -1739,12 +2139,8 @@
1739 2139 * @return string date in format Y-m-d H:i:s
1740 2140 */
1741 2141 function wdk_normalize_date_db($date, $format = 'Y-m-d H:i:s', $return_format = 'Y-m-d H:i:s')
1742 2142 {
1743 - /* check is date on strtotime */
1744 - if((bool)strtotime($date)){
1745 - return date($return_format, strtotime($date));
1746 - }
1747 2143
1748 2144 /* check is date from argument */
1749 2145 $d = \DateTime::createFromFormat($format, $date);
1750 2146 if($d) {
@@ -1775,24 +2171,29 @@
1775 2171 return $d->format($return_format);
1776 2172 }
1777 2173 }
1778 2174
1779 - /* issue with pm/am inside date, example bug format like "2023 01 19 pm8:06" => 'Y n j ag:i' */
1780 - $format = get_option('date_format').' '.get_option('time_format');
1781 - if(strpos($format, 'a') !== FALSE) {
1782 - $format = str_replace('a', '',$format).' a';
1783 - if(strpos($date, 'am') !== FALSE) {
1784 - $date = str_replace('am', '',$date).' am';
1785 - }
1786 - if(strpos($date, 'pm') !== FALSE) {
1787 - $date = str_replace('pm', '',$date).' pm';
1788 - }
1789 - $d = \DateTime::createFromFormat($format, $date);
1790 - if($d) {
1791 - return $d->format($return_format);
1792 - }
1793 - }
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 + }
1794 2190
2191 + /* check is date on strtotime */
2192 + if((bool)strtotime($date)){
2193 + return date($return_format, strtotime($date));
2194 + }
2195 +
1795 2196 return false;
1796 2197 }
1797 2198 }
1798 2199
@@ -1810,9 +2211,100 @@
1810 2211 return $base_url.$extension_url;
1811 2212 }
1812 2213 }
1813 2214
2215 +
1814 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 +/**
1815 2307 * Insert an attachment from an URL address.
1816 2308 *
1817 2309 * @param String $url
1818 2310 * @param Int $parent_post_id
@@ -1834,9 +2326,9 @@
1834 2326 $filename = substr($filename, 0, strpos($filename, '?'));
1835 2327 }
1836 2328
1837 2329 /* if unsoported extension */
1838 - 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){
1839 2331 $data = getimagesizefromstring($response['body']);
1840 2332 if(!$data) return false;
1841 2333 if(empty($data['mime'])) return false;
1842 2334
@@ -1933,17 +2425,12 @@
1933 2425 */
1934 2426
1935 2427 function wdk_generate_profile_permalink($profile = array())
1936 2428 {
1937 -
1938 2429 $profile_slug = '';
1939 - if(wmvc_show_data('user_login', $profile, false)){
1940 - $profile_slug = wmvc_show_data('user_login', $profile);
1941 - if(wmvc_show_data('wdk_slug', $profile))
1942 - $profile_slug = wmvc_show_data('wdk_slug', $profile);
1943 - } else if(is_intval($profile)){
2430 + if(is_intval($profile)){
1944 2431 $profile_data = get_userdata($profile);
1945 - if(wmvc_show_data('wdk_slug', $profile, false)){
2432 + if(wmvc_show_data('wdk_slug', $profile_data, false)){
1946 2433 $profile_slug = wmvc_show_data('wdk_slug', $profile);
1947 2434 }elseif(wmvc_show_data('user_login', $profile_data, false)){
1948 2435 $profile_slug = wmvc_show_data('user_login', $profile_data);
1949 2436 } else {
@@ -1948,10 +2435,14 @@
1948 2435 $profile_slug = wmvc_show_data('user_login', $profile_data);
1949 2436 } else {
1950 2437 $profile_slug = $profile;
1951 2438 }
1952 - }
1953 -
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 +
1954 2445 $user_profile_page = get_option('wdk_membership_profile_preview_page');
1955 2446 if(!$user_profile_page) {
1956 2447 return '#';
1957 2448 }
@@ -2040,17 +2531,23 @@
2040 2531 * Return date in format
2041 2532 * @param string|url redirect url
2042 2533 * @param string custom_message, showed on login form like alert, visible only on wdk login form
2043 2534 */
2044 - function wdk_login_url($url_redirect = NULL, $custom_message = '')
2535 + function wdk_login_url($url_redirect = '', $custom_message = '')
2045 2536 {
2046 2537 $url = wp_login_url($url_redirect);
2047 2538
2048 2539 if(get_option('wdk_membership_login_page')){
2049 - $url = wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')), 'redirect_to='. urlencode($url_redirect).'&custom_message='. urlencode($custom_message));
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 + }
2050 2547 }
2051 2548
2052 - return $url;
2549 + return trim($url, '?');
2053 2550 }
2054 2551 }
2055 2552
2056 2553 if(!function_exists('wdk_mail')) {
@@ -2069,10 +2566,10 @@
2069 2566 if(empty($subject))
2070 2567 $subject = __("New message", "wpdirectorykit");
2071 2568
2072 2569 $headers = array('Content-Type: text/html; charset=UTF-8');
2073 - $headers[] = 'From: '.$email_from;
2074 -
2570 + $headers[] = 'From: "'.get_bloginfo('name').'" <'.$email_from.'>';
2571 +
2075 2572 if(!empty($reply_to)) {
2076 2573 $headers[] = 'Reply-To: '.$reply_to;
2077 2574 } else {
2078 2575 $headers[] = 'Reply-To: '.$email_from;
@@ -2204,9 +2701,9 @@
2204 2701 <?php echo esc_html__('Select file','wmvc_win') ?>
2205 2702 </a>
2206 2703 <a class="delete-custom-img <?php if ( ! $you_have_file ) { echo 'hidden'; } ?>"
2207 2704 href="#">
2208 - <?php echo esc_html__('Remove file','wmvc_win') ?>
2705 + <?php echo esc_html__('Remove all files','wmvc_win') ?>
2209 2706 </a>
2210 2707 </p>
2211 2708 <?php //endif; ?>
2212 2709
@@ -2273,18 +2770,14 @@
2273 2770 {
2274 2771 static $media_element_counter = 0;
2275 2772
2276 2773 if(!isset($texts['file_select']))$texts['file_select'] = esc_html__('Select file','wmvc_win');
2277 - if(!isset($texts['file_remove']))$texts['file_remove'] = esc_html__('Remove file','wmvc_win');
2774 + if(!isset($texts['file_remove']))$texts['file_remove'] = esc_html__('Remove all files','wmvc_win');
2278 2775
2279 2776 $media_element_counter++;
2280 2777
2281 2778 $img_field = $field_name.'_'.$media_element_counter;
2282 2779
2283 - wp_register_script( 'wpmediaelement_file', WPDIRECTORYKIT_URL . 'admin/js/jquery.wpmediaelement_file.js', array( 'jquery' ), false, false );
2284 - wp_enqueue_script( 'wpmediaelement_file' );
2285 - wp_enqueue_media();
2286 -
2287 2780 wp_enqueue_script( 'wpmediamultiple' );
2288 2781 wp_enqueue_script( 'jquery-ui-mouse' );
2289 2782 wp_enqueue_media();
2290 2783
@@ -2353,9 +2846,12 @@
2353 2846 $('#".esc_js($field_name)."meta-box-id.postbox-upload-multiple').wpMediaMultiple({
2354 2847 frame: {
2355 2848 title: '".esc_js(__('Select or Upload Media Of Your Chosen Persuasion','wpdirectorykit'))."',
2356 2849 button: '".esc_js(__('Use this media','wpdirectorykit'))."',
2357 - }
2850 + },
2851 + library: {
2852 + type: ['application', 'image', 'video']
2853 + },
2358 2854 });
2359 2855 /* order */
2360 2856 var re_order = function(media_element){
2361 2857 var list_media = '';
@@ -2434,9 +2930,9 @@
2434 2930
2435 2931 if(empty($user_id))
2436 2932 $user_id = get_current_user_id();
2437 2933
2438 - if(wmvc_user_in_role('administrator')) {
2934 + if(wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) {
2439 2935 return true;
2440 2936 }
2441 2937
2442 2938 if(substr($model_name,-2,2) == '_m')
@@ -2464,8 +2960,52 @@
2464 2960
2465 2961 }
2466 2962 }
2467 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 +
2468 3008 if ( ! function_exists('wdk_recaptcha_field'))
2469 3009 {
2470 3010 function wdk_recaptcha_field($is_compact=false, $style="", $load_script=true)
2471 3011 {
@@ -2489,15 +3029,15 @@
2489 3029 }
2490 3030
2491 3031 $recaptcha_array[$counter] = array('size'=>$size_tag);
2492 3032
2493 - 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>';
2494 3034 ?>
2495 3035
2496 3036 <script>
2497 3037 <?php if($counter===1)echo 'var ';?>CaptchaCallback = function(){
2498 3038 <?php for($j=1;$j<=$counter;$j++): ?>
2499 - grecaptcha.render(document.getElementById('recaptcha_called_<?php echo $j;?>'), {'size' : '<?php echo $recaptcha_array[$j]['size']; ?>', 'sitekey' : '<?php echo get_option('wdk_recaptcha_site_key'); ?>'});
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')); ?>'});
2500 3040 <?php endfor; ?>
2501 3041 };
2502 3042 </script>
2503 3043
@@ -2599,9 +3139,9 @@
2599 3139 if(is_array($val))
2600 3140 {
2601 3141 return wdk_clean($_POST);
2602 3142 }
2603 - else
3143 + elseif(is_string($val))
2604 3144 {
2605 3145 if(strpos($val, '<iframe') === 0)
2606 3146 $val = str_replace("'",'"', $val);
2607 3147
@@ -2640,9 +3180,9 @@
2640 3180 if(is_array($val))
2641 3181 {
2642 3182 $arr_cleaned[sanitize_text_field($key)] = wdk_clean($val);
2643 3183 }
2644 - else
3184 + elseif(is_string($val))
2645 3185 {
2646 3186 $arr_cleaned[sanitize_text_field($key)] = wp_kses_post($val);
2647 3187 }
2648 3188
@@ -2652,8 +3192,34 @@
2652 3192
2653 3193 return $arr_cleaned;
2654 3194 }
2655 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 +
2656 3222 /*
2657 3223 <select class="form-control" name="<?php echo 'control_operator_'.$i_fieldnum; ?>">
2658 3224 <option value="CONTAINS">CONTAINS</option>
2659 3225 <option value="NOT_CONTAINS">NOT_CONTAINS</option>
@@ -2668,9 +3234,9 @@
2668 3234
2669 3235 if(is_array($options) && count($options) > 0)
2670 3236 foreach($options as $key=>$val)
2671 3237 {
2672 - $output.= '<option value="'.$key.'" '.($selected==$key?'selected':'').'>'.$val.'</option>';
3238 + $output.= '<option value="'.$key.'" '.($selected==$key&&$selected != ''?'selected':'').'>'.$val.'</option>';
2673 3239 }
2674 3240
2675 3241 $output.= '</select>';
2676 3242
@@ -2723,15 +3289,15 @@
2723 3289
2724 3290 $results = $WMVC->$table->get();
2725 3291 foreach ($results as $item) {
2726 3292 if($item)
2727 - $form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data($column_key, $item, false, TRUE, TRUE)).'">'.esc_html(wmvc_show_data($column_print, $item, false, TRUE, TRUE)).'</option>';
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>';
2728 3294 }
2729 3295 }
2730 3296 } elseif(is_intval($selected)) {
2731 3297 $db_item = $WMVC->$table->get($selected, TRUE);
2732 3298 if($db_item)
2733 - $form .= '<option selected="selected" value="'.esc_attr(wmvc_show_data($column_key, $db_item, false, TRUE, TRUE)).'">'.esc_attr(wmvc_show_data($column_print, $db_item, false, TRUE, TRUE)).'</option>';
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>';
2734 3300 }
2735 3301 } else {
2736 3302 //$form .= '<option value="" selected="selected">'.esc_html__('Not selected', 'wpdirectorykit').'</option>';
2737 3303 }
@@ -2739,11 +3305,11 @@
2739 3305
2740 3306 //load javascript library
2741 3307 if($counter==0)
2742 3308 {
2743 - wp_enqueue_script('select2');
3309 + wp_enqueue_script('select2-select2');
2744 3310 wp_enqueue_script('wdk-select2');
2745 - wp_enqueue_style('select2');
3311 + wp_enqueue_style('select2-select2');
2746 3312 }
2747 3313 ?>
2748 3314 <?php
2749 3315 $counter++;
@@ -2787,11 +3353,11 @@
2787 3353
2788 3354 //load javascript library
2789 3355 if($counter==0)
2790 3356 {
2791 - wp_enqueue_script('select2');
3357 + wp_enqueue_script('select2-select2');
2792 3358 wp_enqueue_script('wdk-select2');
2793 - wp_enqueue_style('select2');
3359 + wp_enqueue_style('select2-select2');
2794 3360 }
2795 3361 ?>
2796 3362 <?php
2797 3363 $counter++;
@@ -2869,11 +3435,30 @@
2869 3435 'r'=>'llll',
2870 3436 'u'=>'x',
2871 3437 );
2872 3438
2873 - $replaced_from = array_keys($replaced);
2874 - $date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format);
2875 - return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format);
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);
2876 3461 }
2877 3462 }
2878 3463
2879 3464 if ( ! function_exists('wdk_convert_date_format_jquery'))
@@ -2914,11 +3499,29 @@
2914 3499 'u'=>'@',
2915 3500 ':'=>'',
2916 3501 );
2917 3502
2918 - $replaced_from = array_keys($replaced);
2919 - $date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format);
2920 - return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format);
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);
2921 3524 }
2922 3525 }
2923 3526
2924 3527 if ( ! function_exists('wdk_convert_date_format_jquery'))
@@ -2959,11 +3562,31 @@
2959 3562 'u'=>'@',
2960 3563 ':'=>'',
2961 3564 );
2962 3565
2963 - $replaced_from = array_keys($replaced);
2964 - $date_format = str_replace($replaced_from, array_keys($replaced_from), $date_format);
2965 - return str_replace(array_reverse(array_keys($replaced_from)), array_reverse($replaced), $date_format);
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 +
2966 3589 }
2967 3590 }
2968 3591
2969 3592 if ( ! function_exists('wdk_get_gps'))
@@ -2975,15 +3598,33 @@
2975 3598 * @return array An array containing Latitude/Longitude/Altitude data
2976 3599 */
2977 3600 function wdk_get_gps($address = '')
2978 3601 {
3602 +
3603 + $address_key = 'cached_address_gps';
3604 +
2979 3605 static $results = array();
3606 +
3607 + if(empty($results)) {
3608 + $gps_option = wdk_get_option($address_key, $results);
3609 + if($gps_option)
3610 + $results = $gps_option;
3611 + }
3612 +
2980 3613 $address = str_replace(' ','+',$address);
2981 3614
2982 3615 if(!isset($results[$address])) {
2983 3616 $results[$address] = NULL;
2984 3617 $url = 'https://nominatim.openstreetmap.org/search?format=json&q=' . $address;
2985 - $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);
2986 3627 $response = '';
2987 3628
2988 3629 // request failed
2989 3630 if ( is_wp_error( $request ) ) {
@@ -2989,9 +3630,8 @@
2989 3630 if ( is_wp_error( $request ) ) {
2990 3631 $response = $request;
2991 3632 }
2992 3633 $code = (int) wp_remote_retrieve_response_code( $request );
2993 -
2994 3634 // make sure the fetch was successful
2995 3635 if (empty($response) && $code == 200 ) {
2996 3636 $response = wp_remote_retrieve_body( $request );
2997 3637 // Decode the json
@@ -2998,8 +3638,9 @@
2998 3638 $resp = json_decode( $response, true );
2999 3639
3000 3640 if(!empty($resp) && isset($resp[0]) && isset($resp[0]['lat']) && isset($resp[0]['lon'])) {
3001 3641 $results[$address] = array('lat' => $resp[0]['lat'], 'lng' => $resp[0]['lon'], 'alt' => 0);
3642 +
3002 3643 return $results[$address];
3003 3644 }
3004 3645 }
3005 3646 } else {
@@ -3139,8 +3780,32 @@
3139 3780 return false;
3140 3781 }
3141 3782 }
3142 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 +
3143 3808 if ( ! function_exists('wdk_filter_phone'))
3144 3809 {
3145 3810 // Validation phone
3146 3811 /**
@@ -3276,9 +3941,12 @@
3276 3941
3277 3942 $value = filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
3278 3943 $value = (float)str_replace(array(","," ",'&nbsp;'), "", $value);
3279 3944
3280 - 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);
3281 3949 }
3282 3950 }
3283 3951
3284 3952 if ( ! function_exists('wdk_currency_symbol'))
@@ -3408,11 +4076,23 @@
3408 4076 $user_data['wdk_viber'] = wmvc_show_data('cacheduser_wdk_viber', $row);
3409 4077 $user_data['wdk_iban'] = wmvc_show_data('cacheduser_wdk_iban', $row);
3410 4078 $user_data['wdk_telegram'] = wmvc_show_data('cacheduser_wdk_telegram', $row);
3411 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);
3412 4081 $user_data['description'] = wmvc_show_data('cacheduser_description', $row);
3413 4082 $user_data['user_url'] = wmvc_show_data('cacheduser_user_url', $row);
3414 - $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 + }
3415 4095
3416 4096 return $user_data;
3417 4097 }
3418 4098 }
@@ -3666,5 +4346,964 @@
3666 4346
3667 4347 return null;
3668 4348 }
3669 4349 }
3670 -?>
4350 +
4351 +
4352 +if ( ! function_exists('is_wdk_gps_single'))
4353 +{
4354 + function is_wdk_gps_single($param)
4355 + {
4356 +
4357 + if (is_numeric($param) && $param > -180 && $param < 180) {
4358 + return true;
4359 + }
4360 +
4361 + return false;
4362 + }
4363 +}
4364 +
4365 +if ( ! function_exists('wdk_get_tgmpa_link'))
4366 +{
4367 + function wdk_get_tgmpa_link()
4368 + {
4369 + if(file_exists(get_template_directory().'/includes/tgm_pa/class-tgm-plugin-activation.php') || file_exists(get_template_directory().'/tgm_pa/class-tgm-plugin-activation.php')) {
4370 + return get_admin_url() . "themes.php?page=tgmpa-install-plugins";
4371 + } else {
4372 + return get_admin_url() . "plugins.php?page=tgmpa-install-plugins";
4373 + }
4374 +
4375 + return false;
4376 + }
4377 +}
4378 +
4379 +if ( ! function_exists('wdk_sprintf'))
4380 +{
4381 + function wdk_sprintf($string = '')
4382 + {
4383 + $arg_list = func_get_args();
4384 +
4385 + if(count($arg_list)<2) {
4386 + return $string;
4387 + }
4388 +
4389 + if(stripos($string, '%1$s') === FALSE) {
4390 + return $string;
4391 + }
4392 +
4393 + return call_user_func_array("sprintf", $arg_list);
4394 + }
4395 +}
4396 +
4397 +if ( ! function_exists('wdk_db_table'))
4398 +{
4399 + function wdk_db_table($data, $columns = array()) {
4400 + $output = '<table>';
4401 + foreach($data as $key => $var) {
4402 + if($key === 0)
4403 + {
4404 + $output .= '<tr>';
4405 + foreach($var as $k => $v) {
4406 + if(count($columns) > 0 && !in_array($k, $columns))continue;
4407 +
4408 + $output .= '<td><strong>' . $k . '</strong></td>';
4409 + }
4410 + $output .= '</tr>';
4411 + }
4412 +
4413 + $output .= '<tr>';
4414 + foreach($var as $k => $v) {
4415 + if(count($columns) > 0 && !in_array($k, $columns))continue;
4416 +
4417 + $output .= '<td>' . $v . '</td>';
4418 + }
4419 + $output .= '</tr>';
4420 + }
4421 + $output .= '</table>';
4422 + echo $output;
4423 + }
4424 +}
4425 +
4426 +if ( ! function_exists('wdk_move_gps'))
4427 +{
4428 + function wdk_move_gps($value) {
4429 + return $value+0.001 * rand(1, 9);
4430 + }
4431 +}
4432 +
4433 +if ( ! function_exists('wdk_get_near_location'))
4434 +{
4435 + function wdk_get_near_location($latitude, $longitude, $radius = 10000) {
4436 + // Convert radius from meters to degrees
4437 + $radiusInDegrees = $radius / 111000;
4438 +
4439 + $u = mt_rand() / mt_getrandmax();
4440 + $v = mt_rand() / mt_getrandmax();
4441 + $w = $radiusInDegrees * sqrt($u);
4442 + $t = 2 * M_PI * $v;
4443 + $x = $w * cos($t);
4444 + $y = $w * sin($t);
4445 +
4446 + // Adjust the x-coordinate for the shrinking of the east-west distances
4447 + $newX = $x / cos(deg2rad($latitude));
4448 +
4449 + $newLongitude = $longitude + $newX;
4450 + $newLatitude = $latitude + $y;
4451 +
4452 + return array('lat' => $newLatitude, 'lng' => $newLongitude);
4453 + }
4454 +}
4455 +
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 +?>