PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
← All changes | application/controllers/Wdk_frontendajax.php +350 -39 1.3.8 → 1.5.9 View file →
@@ -32,11 +32,28 @@
32 32 if(isset($_POST['listing_post_id']))
33 33 $listing_post_id = sanitize_text_field($_POST['listing_post_id']);
34 34
35 35 $listing = $this->load->listing_m->get($listing_post_id, TRUE);
36 +
37 + if (!$listing || $listing->post_status != 'publish' || !empty($listing->post_password)) {
38 + return false;
39 + }
36 40
41 + /* protect check */
42 + if (
43 + !wdk_field_value('is_activated', $listing, false) || !wdk_field_value('is_approved', $listing,false)
44 + ) {
45 + $data['popup_content'] = __( 'Listing is not public', 'wpdirectorykit' );
46 + $this->output($data);
47 + }
48 +
49 + $popup_layout = 'result_item_card';
50 + if(!empty($_POST['custom_layout_id'])) {
51 + $popup_layout = (int) sanitize_text_field($_POST['custom_layout_id']);
52 + }
53 +
37 54 if(!empty($listing)) {
38 - $data['popup_content'] = wdk_listing_card($listing, array('infobox' => true), false, '<div class="infobox map-box">%1$s<div>');
55 + $data['popup_content'] = wdk_listing_card($listing, array('infobox' => true), false, '<div class="infobox map-box">%1$s<div>', $popup_layout);
39 56 } else {
40 57 $data['popup_content'] = __( 'Listing is missing', 'wpdirectorykit' );
41 58 }
42 59
@@ -57,8 +74,21 @@
57 74 $listing_post_id = sanitize_text_field($_POST['listing_post_id']);
58 75
59 76 $listing = $this->load->listing_m->get($listing_post_id, TRUE);
60 77
78 +
79 + if (!$listing || $listing->post_status != 'publish' || !empty($listing->post_password)) {
80 + return false;
81 + }
82 +
83 + /* protect check */
84 + if (
85 + !wdk_field_value('is_activated', $listing, false) || !wdk_field_value('is_approved', $listing,false)
86 + ) {
87 + $data['popup_content'] = __( 'Listing is not public', 'wpdirectorykit' );
88 + $this->output($data);
89 + }
90 +
61 91 if(!empty($listing)) {
62 92 $data['popup_content'] = wdk_listing_card($listing, [], false, '<div class="infobox map-box">%1$s<div>', 'result_item_card_dash_edit');
63 93 } else {
64 94 $data['popup_content'] = __( 'Listing is missing', 'wpdirectorykit' );
@@ -70,8 +100,11 @@
70 100 }
71 101
72 102 public function treefieldid($output="", $atts=array(), $instance=NULL)
73 103 {
104 +
105 + check_ajax_referer('wdk_secure_treefieldid', 'wdk_secure');
106 +
74 107 $this->load->load_helper('listing');
75 108 $this->load->model('listing_m');
76 109 $this->load->model('listingfield_m');
77 110
@@ -132,11 +165,11 @@
132 165 $attr_id = preg_replace("/[^0-9a-zA-Z_\-]/", "",sanitize_text_field($parameters['attribute_id']));
133 166 $attr_val = preg_replace("/[^0-9a-zA-Z_\-]/", "",sanitize_text_field($parameters['attribute_value']));
134 167
135 168
136 - $attr_search = sanitize_text_field($parameters['search_term']);
137 - $skip_id = intval($parameters['skip_id']);
138 - $language_id = intval($parameters['language_id']);
169 + $attr_search = wdk_esc_sql(sanitize_text_field($parameters['search_term'] ?? ''));
170 + $skip_id = intval($parameters['skip_id'] ?? 0);
171 + $language_id = intval($parameters['language_id'] ?? 0);
139 172
140 173 if(empty($language_id))
141 174 $language_id = NULL;
142 175
@@ -178,13 +211,30 @@
178 211 } elseif($attr_val == 'category_title'){
179 212 $this->load->model($table);
180 213 $attr_val_sql = $this->$table->_table_name.'.category_title';
181 214 }
215 +
216 + /* if category/locations search also in translated field */
217 + if($attr_val == 'location_title' || $attr_val == 'category_title') {
218 + $where["($id_part $attr_val_sql LIKE '%$attr_search%' OR ".$this->$table->_table_name.".titles_for_search LIKE '%$attr_search%')"] = NULL;
219 + } else {
220 + $where["($id_part $attr_val_sql LIKE '%$attr_search%')"] = NULL;
221 + }
222 + }
182 223
183 - $where["($id_part $attr_val_sql LIKE '%$attr_search%')"] = NULL;
224 + if(!empty($parameters['sql_where'] )) {
225 + $sql_where = '';
226 + if($parameters['sql_where'] == 'only_nochilds') {
227 + $sql_where = "((".$this->listing_m->_table_name.".listing_parent_post_id IS NULL OR ".$this->listing_m->_table_name.".listing_parent_post_id = 0) AND (".$this->listing_m->_table_name.".`listing_related_ids` IS NULL OR ".$this->listing_m->_table_name.".`listing_related_ids` = '') )";
228 + } else {
229 +
230 + }
231 + if(!empty($sql_where))
232 + $where[$sql_where] = NULL;
184 233 }
185 234
186 235 if(!empty($parameters['hide_fields'])) {
236 + $parameters['hide_fields'] = preg_replace('/[^0-9,]/', '', $parameters['hide_fields']);
187 237 if($table == 'location_m') {
188 238 $sql_where = esc_sql($this->$table->_table_name.'.idlocation').' NOT IN ('.esc_sql(sanitize_text_field($parameters['hide_fields'])).')';
189 239 foreach (explode(',', $parameters['hide_fields']) as $key => $id) {
190 240 $sql_where .= ' AND CONCAT(",", '.$this->$table->_table_name.'.parent_path, ",") NOT LIKE CONCAT("%,", '.intval($id).', ",%")';
@@ -201,11 +251,8 @@
201 251 $where[$sql_where] = NULL;
202 252 }
203 253 }
204 254
205 - if(!empty($parameters['attr_search']))
206 - $where[$parameters['attr_search']] = NULL;
207 -
208 255 if(isset($parameters['user_check']) && ($parameters['user_check'] == 'true' || $parameters['user_check'] == '1')) {
209 256 if($table == 'listing_m') {
210 257 if($parameters['table'] == 'calendar_listing_m') {
211 258 global $Winter_MVC_wdk_bookings;
@@ -216,9 +263,9 @@
216 263 $tree_results = $this->$table->get_pagination(intval($parameters['limit']),intval($parameters['offset']), $where, TRUE, get_current_user_id());
217 264 } else {
218 265
219 266 if(!empty($parameters['filter_ids'])){
220 - $this->db->where(array( esc_sql($this->$table->_table_name.'.'.$this->$table->_primary_key).' IN ('.esc_sql($parameters['filter_ids']).')' => NULL));
267 + $this->db->where(array( esc_sql($this->$table->_table_name.'.'.$this->$table->_primary_key).' IN ('.esc_sql(preg_replace('/[^0-9,]/', '', $parameters['filter_ids'])).')' => NULL));
221 268 }
222 269
223 270 $tree_results = $this->$table->get_pagination(intval($parameters['limit']),intval($parameters['offset']), $where );
224 271 }
@@ -229,9 +276,9 @@
229 276 $this->db->join($Winter_MVC_wdk_bookings->calendar_m->_table_name.' ON '.$post_table.'.ID = '.$Winter_MVC_wdk_bookings->calendar_m->_table_name.'.post_id');
230 277 }
231 278
232 279 if(!empty($parameters['filter_ids'])){
233 - $this->db->where(array( esc_sql($this->$table->_table_name.'.'.$this->$table->_primary_key).' IN ('.esc_sql($parameters['filter_ids']).')' => NULL));
280 + $this->db->where(array( esc_sql($this->$table->_table_name.'.'.$this->$table->_primary_key).' IN ('.esc_sql(preg_replace('/[^0-9,]/', '', $parameters['filter_ids'])).')' => NULL));
234 281 }
235 282
236 283 if($table == 'user_m') {
237 284 $like = "(meta_value LIKE '%wdk_%' )";
@@ -248,8 +295,9 @@
248 295 $tree_results = $this->$table->get_pagination_simple(intval($parameters['limit']),intval($parameters['offset']), $where);
249 296 } else {
250 297 $tree_results = $this->$table->get_pagination(intval($parameters['limit']),intval($parameters['offset']), $where);
251 298 }
299 +
252 300 }
253 301 }
254 302
255 303 }
@@ -266,9 +314,12 @@
266 314 $results[$ind_order]['value'] = $level_gen
267 315 .'#'.wmvc_show_data($attr_id, $row).', '.wmvc_show_data($attr_val, $row);
268 316 } elseif($table == 'user_m') {
269 317 $results[$ind_order]['value'] = $level_gen
270 - .'#'.wmvc_show_data($attr_id, $row).', '.wmvc_show_data($attr_val, $row).' ('.wmvc_show_data('user_email', $row).')';
318 + .'#'.wmvc_show_data($attr_id, $row).', '.wmvc_show_data('display_name', $row);
319 +
320 + //if(current_user_can('wdk_listings_manage'))
321 + // $results[$ind_order]['value'] .= ' ('.wmvc_show_data('user_email', $row).')';
271 322 } elseif($table == 'icons_list') {
272 323 $results[$ind_order]['key'] = $row;
273 324 if(defined('ELEMENTOR_ASSETS_URL')){
274 325 $results[$ind_order]['value'] = '<i class="'. $row.'"></i>&nbsp;&nbsp;'.$row;
@@ -276,8 +327,10 @@
276 327 $results[$ind_order]['value'] = $row;
277 328 }
278 329 } else {
279 330 $results[$ind_order]['value'] = $level_gen
331 + // Dynamic field values are registered in the translation catalog separately.
332 + // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
280 333 .esc_html__(wmvc_show_data($attr_val, $row), 'wpdirectorykit');
281 334 }
282 335 $ind_order++;
283 336 }
@@ -303,11 +356,14 @@
303 356 $level_gen = str_pad('', $row->level*12, '&nbsp;').'';
304 357
305 358 if($table == 'user_m') {
306 359 $data['curr_val'] = $level_gen
307 - .wmvc_show_data(wmvc_show_data('attribute_value', $parameters), $row).' ('.wmvc_show_data('user_email', $row).')'.' #'.wmvc_show_data($attr_id, $row);
360 + .wmvc_show_data('display_name', $row);
361 +
308 362 } else {
309 363 $data['curr_val'] = $level_gen
364 + // Dynamic field values are registered in the translation catalog separately.
365 + // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
310 366 .esc_html__(wmvc_show_data(wmvc_show_data('attribute_value', $parameters), $row), 'wpdirectorykit');
311 367 }
312 368
313 369
@@ -321,14 +377,16 @@
321 377
322 378 $this->data['success'] = true;
323 379
324 380 $data['results'] = $results;
325 - //$data['sql'] = $this->db->last_query();
381 + $data['sql'] = $this->db->last_query();
326 382 $this->output($data);
327 383 }
328 384
329 385 public function treefieldid_checkboxes($output="", $atts=array(), $instance=NULL)
330 386 {
387 + check_ajax_referer('wdk_secure_treefieldid_checkboxes', 'wdk_secure');
388 +
331 389 $this->load->load_helper('listing');
332 390 $this->load->model('listing_m');
333 391 $this->load->model('listingfield_m');
334 392
@@ -385,9 +443,9 @@
385 443 $table_name = substr($table,0, -2);
386 444 $attr_id = preg_replace("/[^0-9a-zA-Z_\-]/", "",sanitize_text_field($parameters['attribute_id']));
387 445 $attr_val = preg_replace("/[^0-9a-zA-Z_\-]/", "",sanitize_text_field($parameters['attribute_value']));
388 446
389 - $attr_search = sanitize_text_field($parameters['search_term']);
447 + $attr_search = wdk_esc_sql(sanitize_text_field($parameters['search_term']));
390 448 $skip_id = intval($parameters['skip_id']);
391 449 $language_id = intval($parameters['language_id']);
392 450
393 451 if(empty($language_id))
@@ -400,9 +458,23 @@
400 458 $this->load->model($table);
401 459
402 460 $where = array();
403 461 if(!empty($attr_search))
404 - $where["($id_part $attr_val LIKE '%$attr_search%')"] = NULL;
462 + $attr_val_sql = $attr_val;
463 + if($attr_val == 'location_title') {
464 + $this->load->model($table);
465 + $attr_val_sql = $this->$table->_table_name.'.location_title';
466 + } elseif($attr_val == 'category_title'){
467 + $this->load->model($table);
468 + $attr_val_sql = $this->$table->_table_name.'.category_title';
469 + }
470 +
471 + /* if category/locations search also in translated field */
472 + if($attr_val == 'location_title' || $attr_val == 'category_title') {
473 + $where["($id_part $attr_val_sql LIKE '%$attr_search%' OR ".$this->$table->_table_name.".titles_for_search LIKE '%$attr_search%')"] = NULL;
474 + } else {
475 + $where["($id_part $attr_val_sql LIKE '%$attr_search%')"] = NULL;
476 + }
405 477
406 478 if(isset($parameters['selected']) && !empty($parameters['selected'])) {
407 479
408 480 if(is_string($parameters['selected']) && strpos($parameters['selected'], ',') !== FALSE){
@@ -427,12 +499,13 @@
427 499 }
428 500 }
429 501
430 502 if(!empty($parameters['filter_ids'])){
431 - $this->db->where(array( esc_sql($this->$table->_table_name.'.'.$this->$table->_primary_key).' IN ('.esc_sql($parameters['filter_ids']).')' => NULL));
503 + $this->db->where(array( esc_sql($this->$table->_table_name.'.'.$this->$table->_primary_key).' IN ('.esc_sql(preg_replace('/[^0-9,]/', '', $parameters['filter_ids'])).')' => NULL));
432 504 }
433 505
434 506 if(!empty($parameters['hide_fields'])) {
507 + $parameters['hide_fields'] = preg_replace('/[^0-9,]/', '', $parameters['hide_fields']);
435 508 if($table == 'location_m') {
436 509 $sql_where = esc_sql($this->$table->_table_name.'.idlocation').' NOT IN ('.esc_sql(sanitize_text_field($parameters['hide_fields'])).')';
437 510 foreach (explode(',', $parameters['hide_fields']) as $key => $id) {
438 511 $sql_where .= ' AND CONCAT(",", '.$this->$table->_table_name.'.parent_path, ",") NOT LIKE CONCAT("%,", '.intval($id).', ",%")';
@@ -460,8 +533,10 @@
460 533 $level_gen = str_pad('', $row->level*12, '&nbsp;').'';
461 534
462 535 $results[$ind_order]['key'] = wmvc_show_data($attr_id, $row);
463 536 $results[$ind_order]['value'] = $level_gen
537 + // Dynamic field values are registered in the translation catalog separately.
538 + // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
464 539 .esc_html__(wmvc_show_data($attr_val, $row), 'wpdirectorykit');
465 540 $ind_order++;
466 541 }
467 542
@@ -474,10 +549,11 @@
474 549 {
475 550 $level_gen='';
476 551 if(isset($row->level))
477 552 $level_gen = str_pad('', $row->level*12, '&nbsp;').'';
478 -
479 - $data['curr_val'] = $level_gen
553 + $data['curr_val'] = $level_gen
554 + // Dynamic field values are registered in the translation catalog separately.
555 + // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
480 556 .esc_html__(wmvc_show_data(wmvc_show_data('attribute_value', $parameters), $row), 'wpdirectorykit');
481 557
482 558 }
483 559 else
@@ -507,8 +583,11 @@
507 583
508 584
509 585 public function select_2_ajax($output="", $atts=array(), $instance=NULL)
510 586 {
587 +
588 + check_ajax_referer('wdk_secure_ajax', 'wdk_secure');
589 +
511 590 $this->load->load_helper('listing');
512 591 $this->load->model('listing_m');
513 592 $this->load->model('listingfield_m');
514 593
@@ -525,8 +604,14 @@
525 604 if(empty($parameters['table'])) return false;
526 605
527 606 $model_name = $parameters['table'];
528 607
608 + // allow only 'listing_m', 'category_m', or 'location_m' for security
609 + $allowed_models = array('listing_m', 'category_m', 'location_m');
610 + if (!in_array($model_name, $allowed_models)) {
611 + return false;
612 + }
613 +
529 614 $key_column = '';
530 615 $print_column = '';
531 616
532 617 $search_column = '';
@@ -533,13 +618,13 @@
533 618 if(empty($parameters['columns_search'])) {
534 619 switch ($model_name) {
535 620 case 'category_m':
536 621 $this->load->model($model_name);
537 - $search_column = $this->$model_name->_table_name.'.idcategory,'.$this->$model_name->_table_name.'.category_title';
622 + $search_column = $this->$model_name->_table_name.'.idcategory,'.$this->$model_name->_table_name.'.category_title, '.$this->$model_name->_table_name.'.titles_for_search';
538 623 break;
539 624 case 'location_m':
540 625 $this->load->model($model_name);
541 - $search_column = $this->$model_name->_table_name.'.idlocation,'.$this->$model_name->_table_name.'.location_title';
626 + $search_column = $this->$model_name->_table_name.'.idlocation,'.$this->$model_name->_table_name.'.location_title, '.$this->$model_name->_table_name.'.titles_for_search';
542 627 break;
543 628
544 629 default:
545 630 # code...
@@ -546,9 +631,9 @@
546 631 break;
547 632 }
548 633
549 634 } else {
550 - $search_column = $parameters['columns_search'];
635 + $search_column = esc_sql(preg_replace('/[^a-z0-9_,]/i', '', $parameters['columns_search']));
551 636 }
552 637
553 638 if(empty($parameters['key_column'])) {
554 639 switch ($model_name) {
@@ -612,9 +697,8 @@
612 697 }
613 698
614 699 $db_results_total = $this->$model_name->total($where);
615 700 $db_results = $this->$model_name->get_pagination($limit,$offset, $where);
616 - $data['output'] = $db_results;
617 701
618 702 if (!$db_results) {
619 703 $data['errors'] = '';
620 704 } else {
@@ -625,8 +709,10 @@
625 709 $level_gen = str_pad('', $row->level*12, '&nbsp;').'';
626 710
627 711 $results[] = [
628 712 'id'=> wmvc_show_data($key_column, $row),
713 + // Dynamic field values are registered in the translation catalog separately.
714 +// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
629 715 'text'=> $level_gen.esc_html__(trim(wmvc_show_data($print_column, $row)), 'wpdirectorykit'),
630 716 ];
631 717 }
632 718
@@ -676,9 +762,13 @@
676 762 $offset = (intval($parameters['page_result']) - 1) * $limit;
677 763 }
678 764
679 765 $this->load->model($model_name);
680 - $search_column = 'display_name,user_email,user_login,ID';
766 + $search_column = 'display_name,user_login,ID';
767 + if(current_user_can('administrator')) {
768 + $search_column = 'display_name,user_email,user_login,ID';
769 + }
770 +
681 771 $where = array();
682 772 if(!empty($_POST['q']['term']) && !empty($search_column)) {
683 773 $sql_search = '';
684 774 foreach (explode(',', $search_column) as $column) {
@@ -696,9 +786,8 @@
696 786 $like = "(meta_value LIKE '%wdk_%' )";
697 787 $db_results_total = $this->$model_name->total($where, NULL, $like);
698 788
699 789 $db_results = $this->$model_name->get_pagination($limit,$offset, $where, NULL, $like);
700 - $data['output'] = $db_results;
701 790
702 791 if (!$db_results) {
703 792 $data['errors'] = '';
704 793 } else {
@@ -848,8 +937,10 @@
848 937
849 938 foreach($db_results as $row) {
850 939 $results[] = [
851 940 'id'=> wmvc_show_data($key_column, $row),
941 + // Dynamic field values are registered in the translation catalog separately.
942 +// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
852 943 'text'=> esc_html__(trim(wmvc_show_data($print_column, $row)),'wpdirectorykit'),
853 944 ];
854 945 }
855 946
@@ -917,9 +1008,9 @@
917 1008 foreach ($categories_search_column as $column) {
918 1009 if(!empty($sql_search))
919 1010 $sql_search .= " OR ";
920 1011
921 - $sql_search .= " ".esc_sql($column)." LIKE '%".esc_sql($search_text)."%'";
1012 + $sql_search .= " ".$this->category_m->_table_name.'.'.esc_sql($column)." LIKE '%".esc_sql($search_text)."%'";
922 1013 }
923 1014 $where ["($sql_search)"] = NULL;
924 1015 $db_results = $this->category_m->get_pagination($categories_limit, NULL, $where);
925 1016 } else {
@@ -931,9 +1022,11 @@
931 1022 'field_key' => 'search_category',
932 1023 'value' => $row->category_title,
933 1024 'print' => [
934 1025 'parsed_content' => [
935 - 'icon_class' => (!empty(wmvc_show_data('font_icon_code', $row, false))) ? wmvc_show_data('font_icon_code', $row) : 'fa fa-tag',
1026 + 'icon_class' => (!empty(wmvc_show_data('font_icon_code', $row, false))) ? esc_attr(wmvc_show_data('font_icon_code', $row)): 'fa fa-tag',
1027 + // Dynamic field values are registered in the translation catalog separately.
1028 + // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
936 1029 'title' => esc_html__($row->category_title, 'wpdirectorykit'),
937 1030 'sub_title' => '',
938 1031 'right_text' => __('Category', 'wpdirectorykit')
939 1032 ]
@@ -984,10 +1077,14 @@
984 1077 'field_key' => 'search_location',
985 1078 'value' => $row->location_title,
986 1079 'print' => [
987 1080 'parsed_content' => [
988 - 'icon_class' => (!empty(wmvc_show_data('font_icon_code', $row, false))) ? wmvc_show_data('font_icon_code', $row) : 'fa fa-map-marker',
1081 + 'icon_class' => (!empty(wmvc_show_data('font_icon_code', $row, false))) ? esc_attr(wmvc_show_data('font_icon_code', $row)) : 'fa fa-map-marker',
1082 + // Dynamic field values are registered in the translation catalog separately.
1083 + // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
989 1084 'title' => esc_html__($row->location_title, 'wpdirectorykit'),
1085 + // Dynamic field values are registered in the translation catalog separately.
1086 + // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
990 1087 'sub_title' => esc_html__($subtitle, 'wpdirectorykit'),
991 1088 'right_text' => __('Location', 'wpdirectorykit')
992 1089 ]
993 1090 ]
@@ -996,14 +1093,15 @@
996 1093
997 1094 /* END Locations */
998 1095
999 1096 /* address suggestion if empty other */
1000 - if(empty($results)) {
1097 + $limit = apply_filters('wdk/search_suggestion/address_limit', 5);
1098 + if(count($results)<10) {
1001 1099 $this->db->select('address');
1002 1100 $db_results = $this->db->where(array("address LIKE '%".esc_sql($search_text)."%'" => NULL));
1003 1101 $this->db->from($this->listing_m->_table_name);
1004 1102 $this->db->group_by('address');
1005 - $this->db->limit(5);
1103 + $this->db->limit($limit);
1006 1104
1007 1105 $query = $this->db->get();
1008 1106 if ($this->db->num_rows() > 0) {
1009 1107 $db_results = $this->db->results();
@@ -1027,10 +1125,15 @@
1027 1125 }
1028 1126 }
1029 1127
1030 1128 /* listings by title suggestion */
1129 + // Example of how to use add_filter for 'wdk/search_suggestion/listings_limit'
1130 + // In your theme's functions.php or a custom plugin, you can add:
1131 + // add_filter('wdk/search_suggestion/listings_limit', function($limit) { return 10; });
1132 +
1133 + $limit = apply_filters('wdk/search_suggestion/listings_limit', 5);
1031 1134 $this->db->where(array("post_title LIKE '%".esc_sql($search_text)."%'" => NULL));
1032 - $db_results = $this->listing_m->get_pagination(5, NULL, array('is_activated' => 1,'is_approved'=>1));
1135 + $db_results = $this->listing_m->get_pagination($limit, NULL, array('is_activated' => 1,'is_approved'=>1));
1033 1136
1034 1137 if($db_results) foreach($db_results as $row) {
1035 1138 $results[] = [
1036 1139 'field_key' => 'link',
@@ -1045,9 +1148,9 @@
1045 1148 ]
1046 1149 ];
1047 1150 }
1048 1151
1049 - if(empty($results)) {
1152 + if(count($results)<10) {
1050 1153
1051 1154 $name_part = str_replace(' ','+',$search_text);
1052 1155
1053 1156 //$url = 'http://photon.komoot.de/api/?q='.$name_part;
@@ -1121,21 +1224,28 @@
1121 1224
1122 1225 if(isset($parameters['post_id'])) {
1123 1226 $post_id = $parameters['post_id'];
1124 1227 }
1228 +
1229 + $calendar = $Winter_MVC_wdk_bookings->calendar_m->get_by(array('post_id'=>$post_id), TRUE);
1230 + $time_format = "00:00:00";
1231 + if($calendar && $calendar->is_hour_enabled == 1)
1232 + $time_format = "H:i:s";
1233 +
1125 1234
1126 1235 if(isset($parameters['date_from'])) {
1127 - $date_from = wdk_normalize_date_db($parameters['date_from']);
1236 + $date_from = wdk_normalize_date_db($parameters['date_from'], 'Y-m-d H:i:s', 'Y-m-d '.$time_format);
1128 1237 }
1129 1238
1130 1239 if(isset($parameters['date_to'])) {
1131 - $date_to = wdk_normalize_date_db($parameters['date_to']);
1240 + $date_to = wdk_normalize_date_db($parameters['date_to'], 'Y-m-d H:i:s', 'Y-m-d '.$time_format);
1132 1241 }
1133 1242
1243 +
1134 1244 if($post_id && $date_from && $date_to) {
1135 1245 $price = $Winter_MVC_wdk_bookings->reservation_m->calculate_price($post_id, $date_from, $date_to);
1136 1246
1137 - $calendar = $Winter_MVC_wdk_bookings->calendar_m->get_by(array('post_id'=>$post_id), TRUE); // date_package_expire package_id
1247 +
1138 1248 $calendar_fees = array();
1139 1249 if($calendar && !empty($calendar->json_data_fees))
1140 1250 $calendar_fees = json_decode($calendar->json_data_fees );
1141 1251
@@ -1244,9 +1354,9 @@
1244 1354 $options['current_page'] = intval(wmvc_xss_clean($custom_parameters['wmvc_paged']));
1245 1355
1246 1356 $get_settings_el_results = new WdkGetElementSettings($parameters['el_results_page_id'],$parameters['el_results_id'],$parameters['el_results_type']);
1247 1357 $settings_el_results = $get_settings_el_results->get_settings();
1248 - $settings_el_results = $settings_el_results['settings'];
1358 + $settings_el_results = $settings_el_results['settings'] ?? [];
1249 1359
1250 1360 if(wmvc_show_data('per_page', $settings_el_results, false)) {
1251 1361 $options['limit'] = wmvc_show_data('per_page', $settings_el_results, false);
1252 1362 }
@@ -1356,9 +1466,9 @@
1356 1466
1357 1467 $pin_icon = "";
1358 1468 $font_class = "";
1359 1469 $font_icon = (wmvc_show_data('conf_custom_map_pin_icon', $settings_el_map)) ? esc_url($get_settings_el_map->generate_icon($settings_el_map['conf_custom_map_pin_icon'])) : '<i class="fa fa-home"></i>';
1360 - $pin_icon = (isset( $settings_el_map['conf_custom_map_pin'])) ? esc_url($get_settings_el_map['conf_custom_map_pin']['url']) : '';
1470 + $pin_icon = (isset( $settings_el_map['conf_custom_map_pin'])) ? esc_url($settings_el_map['conf_custom_map_pin']['url']) : '';
1361 1471
1362 1472 if(wmvc_show_data('conf_hide_real_location', $category) == 'yes') {
1363 1473 $listing->listing_lat = wdk_move_gps($listing->listing_lat);
1364 1474 $listing->listing_lng = wdk_move_gps($listing->listing_lng);
@@ -1390,9 +1500,210 @@
1390 1500 $data['success'] = true;
1391 1501 $this->output($data);
1392 1502
1393 1503 }
1504 +
1394 1505
1506 + public function suggestion_locations (&$output=NULL, $atts=array())
1507 + {
1508 +
1509 + $this->load->load_helper('listing');
1510 + $this->load->model('category_m');
1511 + $this->load->model('location_m');
1512 + $this->load->model('listing_m');
1513 +
1514 + $data = array();
1515 + $data['message'] = __('No message returned!', 'wpdirectorykit');
1516 +
1517 + $data['results'] = array();
1518 + $parameters = array();
1519 + foreach ($_POST as $key => $value) {
1520 + $parameters[$key] = sanitize_text_field($value);
1521 + }
1522 +
1523 + $search_text = '';
1524 + if(!empty($parameters['search']))
1525 + $search_text = trim($parameters['search']);
1526 +
1527 + if(!empty($search_text)) {
1528 + $this->db->select("location_title as value");
1529 + $this->db->from($this->location_m->_table_name);
1530 + $this->db->where(array("location_title LIKE '%".esc_sql($search_text)."%'" => NULL));
1531 +
1532 + $query = $this->db->get();
1533 + if($this->db->num_rows() > 0) foreach($this->db->results() as $row) {
1534 + $data['results'][] = $row->value;
1535 + }
1536 + }
1537 +
1538 + $data['success'] = true;
1539 + $this->output($data);
1540 + }
1541 +
1542 + public function suggestion_categories (&$output=NULL, $atts=array())
1543 + {
1544 +
1545 + $this->load->load_helper('listing');
1546 + $this->load->model('category_m');
1547 +
1548 + $data = array();
1549 + $data['message'] = __('No message returned!', 'wpdirectorykit');
1550 +
1551 + $data['results'] = array();
1552 + $parameters = array();
1553 + foreach ($_POST as $key => $value) {
1554 + $parameters[$key] = sanitize_text_field($value);
1555 + }
1556 +
1557 + $search_text = '';
1558 + if(!empty($parameters['search']))
1559 + $search_text = trim($parameters['search']);
1560 +
1561 + if(!empty($search_text)) {
1562 + $this->db->select("category_title as value");
1563 + $this->db->from($this->category_m->_table_name);
1564 + $this->db->where(array("category_title LIKE '%".esc_sql($search_text)."%'" => NULL));
1565 +
1566 + $query = $this->db->get();
1567 + if($this->db->num_rows() > 0) foreach($this->db->results() as $row) {
1568 + $data['results'][] = $row->value;
1569 + }
1570 + }
1571 +
1572 + $data['success'] = true;
1573 + $this->output($data);
1574 + }
1575 +
1576 + public function suggestion_db_field (&$output=NULL, $atts=array())
1577 + {
1578 + $this->load->load_helper('listing');
1579 + $this->load->model('category_m');
1580 + $this->load->model('location_m');
1581 + $this->load->model('listing_m');
1582 +
1583 + $data = array();
1584 + $data['message'] = __('No message returned!', 'wpdirectorykit');
1585 +
1586 + $data['results'] = array();
1587 + $parameters = array();
1588 + foreach ($_POST as $key => $value) {
1589 + $parameters[$key] = sanitize_text_field($value);
1590 + }
1591 +
1592 + $search_text = '';
1593 + if(!empty($parameters['search']))
1594 + $search_text = trim($parameters['search']);
1595 +
1596 + $search_field_id = '';
1597 + if(!empty($parameters['field_id']))
1598 + $search_field_id = (int) trim($parameters['field_id']);
1599 +
1600 + if(!empty($search_field_id) && wdk_field_option($search_field_id, 'field_type', false)) {
1601 +
1602 + /* listings by title suggestion */
1603 + $this->db->select("DISTINCT field_".$search_field_id."_".wdk_field_option($search_field_id, 'field_type', false)." as value");
1604 + $this->db->from($this->db->prefix.'wdk_listings_fields');
1605 + $this->db->where(array("field_".$search_field_id."_".wdk_field_option($search_field_id, 'field_type', false)." LIKE '%".esc_sql($search_text)."%'" => NULL));
1606 +
1607 + $query = $this->db->get();
1608 + if($this->db->num_rows() > 0) foreach($this->db->results() as $row) {
1609 + $data['results'][] = $row->value;
1610 + }
1611 +
1612 + $field_values = wdk_field_option($search_field_id, 'values', '');
1613 + $field_values = explode(',', $field_values);
1614 + if(!empty($field_values)) {
1615 + foreach($field_values as $value) {
1616 + if(empty($value)) continue;
1617 + $data['results'][] = $value;
1618 + }
1619 + }
1620 +
1621 + }
1622 +
1623 + $data['success'] = true;
1624 + $this->output($data);
1625 +
1626 + }
1627 +
1628 + function select_2_ajax_field_db_suggestion($output="", $atts=array(), $instance=NULL)
1629 + {
1630 + global $Winter_MVC_WDK;
1631 + $Winter_MVC_WDK->load_helper('listing');
1632 + $Winter_MVC_WDK->model('location_m');
1633 +
1634 + $data = array();
1635 + $data['message'] = __('No message returned!', 'wpdirectorykit');
1636 + $data['pagination'] = true;
1637 + $results = array();
1638 +
1639 + $parameters = array();
1640 + foreach ($_POST as $key => $value) {
1641 + $parameters[$key] = sanitize_text_field($value);
1642 + }
1643 +
1644 + $limit = 10;
1645 + if(!empty($parameters['limit'])) {
1646 + $limit = intval($parameters['limit']);
1647 + }
1648 +
1649 + $offset = 0;
1650 + if(!empty($parameters['page_result']) && $parameters['page_result'] > 1) {
1651 + $offset = (intval($parameters['page_result']) - 1) * $limit;
1652 + }
1653 +
1654 + $search_text = '';
1655 + if(!empty($_POST['q']['term']))
1656 + $search_text = sanitize_text_field($_POST['q']['term']);
1657 +
1658 + $search_field_id = '';
1659 + if(!empty($parameters['field_id']))
1660 + $search_field_id = (int) trim($parameters['field_id']);
1661 +
1662 + if(!empty($search_field_id) && wdk_field_option($search_field_id, 'field_type', false)) {
1663 +
1664 + /* listings by title suggestion */
1665 + $Winter_MVC_WDK->db->select("DISTINCT field_".$search_field_id."_".wdk_field_option($search_field_id, 'field_type', false)." as value");
1666 + $Winter_MVC_WDK->db->from($Winter_MVC_WDK->db->prefix.'wdk_listings_fields');
1667 + $Winter_MVC_WDK->db->where(array("field_".$search_field_id."_".wdk_field_option($search_field_id, 'field_type', false)." LIKE '%".esc_sql($search_text)."%'" => NULL));
1668 +
1669 + $query = $Winter_MVC_WDK->db->get();
1670 + if($Winter_MVC_WDK->db->num_rows() > 0) foreach($Winter_MVC_WDK->db->results() as $row) {
1671 +
1672 + $results[] = [
1673 + 'id'=> $row->value,
1674 + 'text'=> $row->value,
1675 + ];
1676 + }
1677 +
1678 + $field_values = wdk_field_option($search_field_id, 'values', '');
1679 + $field_values = explode(',', $field_values);
1680 + if(!empty($field_values)) {
1681 + foreach($field_values as $value) {
1682 + if(empty($value)) continue;
1683 +
1684 + $results[] = [
1685 + 'id'=> $value,
1686 + 'text'=> $value,
1687 + ];
1688 + }
1689 + }
1690 +
1691 + }
1692 +
1693 + $data['success'] = true;
1694 +
1695 + $data['results'] = array_slice($results, $offset, $limit);
1696 + if(count($results) >= $limit + $offset) {
1697 + $data['pagination'] =[
1698 + "more"=> true
1699 + ];
1700 + }
1701 +
1702 + $data['success'] = true;
1703 + $this->output($data);
1704 + }
1705 +
1395 1706 private function get_fa_icons() {
1396 1707
1397 1708 /* icons font Awesome 5 */
1398 1709
@@ -1465,9 +1776,9 @@
1465 1776 "fas fa-user-circle","far fa-user-circle","fas fa-user-md","fas fa-user-plus","fas fa-user-secret","fas fa-user-times","fas fa-users","fab fa-ussunnah","fas fa-utensil-spoon","fas fa-utensils","fab fa-vaadin","fas fa-venus",
1466 1777 "fas fa-venus-double","fas fa-venus-mars","fab fa-viacoin","fab fa-viadeo","fab fa-viadeo-square","fab fa-viber","fas fa-video","fab fa-vimeo","fab fa-vimeo-square","fab fa-vimeo-v","fab fa-vine","fab fa-vk","fab fa-vnv",
1467 1778 "fas fa-volume-down","fas fa-volume-off","fas fa-volume-up","fab fa-vuejs","fab fa-weibo","fab fa-weixin","fab fa-whatsapp","fab fa-whatsapp-square","fas fa-wheelchair","fab fa-whmcs","fas fa-wifi","fab fa-wikipedia-w","fas fa-window-close",
1468 1779 "far fa-window-close","fas fa-window-maximize","far fa-window-maximize","fas fa-window-minimize","fas fa-window-restore","far fa-window-restore","fab fa-windows","fas fa-won-sign","fab fa-wordpress","fab fa-wordpress-simple",
1469 - "fab fa-wpbeginner","fab fa-wpexplorer","fab fa-wpforms","fas fa-wrench","fab fa-xbox","fab fa-xing","fab fa-xing-square","fab fa-y-combinator","fab fa-yahoo","fab fa-yandex","fab fa-yandex-international","fab fa-yelp","fas fa-yen-sign","fab fa-yoast","fab fa-youtube");
1780 + "fab fa-wpbeginner","fab fa-wpexplorer","fab fa-wpforms","fas fa-wrench","fab fa-xbox","fab fa-xing","fab fa-xing-square","fab fa-y-combinator","fab fa-yahoo","fab fa-yandex","fab fa-yandex-international","fab fa-yelp","fas fa-yen-sign","fab fa-yoast","fab fa-youtube","fas fa-school");
1470 1781
1471 1782
1472 1783 /* icons font Awesome 4 */
1473 1784 return array("fa fa-500px","fa fa-address-book","fa fa-address-book-o","fa fa-address-card","fa fa-address-card-o","fa fa-adjust","fa fa-adn","fa fa-align-center","fa fa-align-justify","fa fa-align-left","fa fa-align-right",
@@ -1516,14 +1827,14 @@
1516 1827 "fa fa-stop-circle-o","fa fa-street-view","fa fa-strikethrough","fa fa-stumbleupon","fa fa-stumbleupon-circle","fa fa-subscript","fa fa-subway","fa fa-suitcase","fa fa-sun-o","fa fa-superpowers","fa fa-superscript","fa fa-table",
1517 1828 "fa fa-tablet","fa fa-tachometer","fa fa-tag","fa fa-tags","fa fa-tasks","fa fa-taxi","fa fa-telegram","fa fa-television","fa fa-tencent-weibo","fa fa-terminal","fa fa-text-height","fa fa-text-width","fa fa-th","fa fa-th-large","fa fa-th-list",
1518 1829 "fa fa-themeisle","fa fa-thermometer-empty","fa fa-thermometer-full","fa fa-thermometer-half","fa fa-thermometer-quarter","fa fa-thermometer-three-quarters","fa fa-thumb-tack","fa fa-thumbs-down","fa fa-thumbs-o-down",
1519 1830 "fa fa-thumbs-o-up","fa fa-thumbs-up","fa fa-ticket","fa fa-times","fa fa-times-circle","fa fa-times-circle-o","fa fa-tint","fa fa-toggle-off","fa fa-toggle-on","fa fa-trademark","fa fa-train","fa fa-transgender","fa fa-transgender-alt",
1520 - "fa fa-trash","fa fa-trash-o","fa fa-tree","fa fa-trello","fa fa-tripadvisor","fa fa-trophy","fa fa-truck","fa fa-try","fa fa-tty","fa fa-tumblr","fa fa-tumblr-square","fa fa-twitch","fa fa-twitter","fa fa-twitter-square","fa fa-umbrella",
1831 + "fa fa-trash","fa fa-trash-o","fa fa-tree","fa fa-trello","fa fa-tripadvisor","fa fa-trophy","fa fa-truck","fa fa-try","fa fa-tty","fa fa-tumblr","fa fa-tumblr-square","fa fa-twitch","fab fa-x-twitter","fab fa-x-twitter-square","fa fa-umbrella",
1521 1832 "fa fa-underline","fa fa-undo","fa fa-universal-access","fa fa-university","fa fa-unlock","fa fa-unlock-alt","fa fa-upload","fa fa-usb","fa fa-usd","fa fa-user","fa fa-user-circle","fa fa-user-circle-o","fa fa-user-md","fa fa-user-o",
1522 1833 "fa fa-user-plus","fa fa-user-secret","fa fa-user-times","fa fa-users","fa fa-venus","fa fa-venus-double","fa fa-venus-mars","fa fa-viacoin","fa fa-viadeo","fa fa-viadeo-square","fa fa-video-camera","fa fa-vimeo","fa fa-vimeo-square","fa fa-vine",
1523 1834 "fa fa-vk","fa fa-volume-control-phone","fa fa-volume-down","fa fa-volume-off","fa fa-volume-up","fa fa-weibo","fa fa-weixin","fa fa-whatsapp","fa fa-wheelchair","fa fa-wheelchair-alt","fa fa-wifi","fa fa-wikipedia-w","fa fa-window-close",
1524 1835 "fa fa-window-close-o","fa fa-window-maximize","fa fa-window-minimize","fa fa-window-restore","fa fa-windows","fa fa-wordpress","fa fa-wpbeginner","fa fa-wpexplorer","fa fa-wpforms","fa fa-wrench","fa fa-xing","fa fa-xing-square",
1525 - "fa fa-y-combinator","fa fa-yahoo","fa fa-yelp","fa fa-yoast","fa fa-youtube","fa fa-youtube-play","fa fa-youtube-square");
1836 + "fa fa-y-combinator","fa fa-yahoo","fa fa-yelp","fa fa-yoast","fa fa-youtube","fa fa-youtube-play","fa fa-youtube-square","fa-solid fa-school");
1526 1837 }
1527 1838
1528 1839 }
1529 1840