| @@ -87,8 +87,31 @@ | ||
| 87 | 87 | return $default; |
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | +if(!function_exists('wdk_generate_field_date')) { | |
| 92 | + /** | |
| 93 | + * Return Date field | |
| 94 | + * | |
| 95 | + * @param int|string $field_id field id | |
| 96 | + * @param int|object|array $listing listing object|array or id | |
| 97 | + * @param string $default The default value, will be return if empty or no exists | |
| 98 | + * @return string | |
| 99 | + */ | |
| 100 | + function wdk_generate_field_date ($field_id='', $wdk_listing_id = array(), $default = '') { | |
| 101 | + | |
| 102 | + $field_value = wdk_field_value ($field_id, $wdk_listing_id); | |
| 103 | + if(!empty($field_value)) { | |
| 104 | + if(wdk_field_option ($field_id, 'date_format')) { | |
| 105 | + return date_i18n(wdk_field_option ($field_id, 'date_format'), strtotime($field_value)); | |
| 106 | + } else { | |
| 107 | + return wdk_get_date($field_value ); | |
| 108 | + } | |
| 109 | + } | |
| 110 | + return $default; | |
| 111 | + } | |
| 112 | +} | |
| 113 | + | |
| 91 | 114 | if(!function_exists('wdk_listing_images')) { |
| 92 | 115 | /** |
| 93 | 116 | * Initialize the class and set its properties. |
| 94 | 117 | * |
| @@ -109,14 +132,22 @@ | ||
| 109 | 132 | if(is_array($image_ids)) { |
| 110 | 133 | foreach ($image_ids as $key => $image_id) { |
| 111 | 134 | if(is_numeric($image_id)) |
| 112 | 135 | { |
| 113 | - $image = wp_get_attachment_url( $image_id, $size ); | |
| 114 | - $output[] = $image; | |
| 136 | + do_action('wdk/helpers/wdk_listing_images/get_attached/before', $image_id, $size); | |
| 137 | + | |
| 138 | + /* | |
| 139 | + $image = wp_get_attachment_url( $image_id, $size ); | |
| 140 | + $output[] = $image; | |
| 141 | + */ | |
| 142 | + $image = wp_get_attachment_image_src( $image_id, $size ); | |
| 143 | + if($image) | |
| 144 | + $output[] = $image[0]; | |
| 115 | 145 | } |
| 116 | 146 | } |
| 117 | 147 | } else if(is_numeric($image_ids)) |
| 118 | - { | |
| 148 | + { | |
| 149 | + do_action('wdk/helpers/wdk_listing_images/get_attached/before', $image_ids, $size); | |
| 119 | 150 | $image = wp_get_attachment_url( $image_ids, $size ); |
| 120 | 151 | $output[] = $image; |
| 121 | 152 | } |
| 122 | 153 | return $output; |
| @@ -218,8 +249,61 @@ | ||
| 218 | 249 | return $output; |
| 219 | 250 | } |
| 220 | 251 | } |
| 221 | 252 | |
| 253 | +if(!function_exists('wdk_files_data')) { | |
| 254 | + /** | |
| 255 | + * Initialize the class and set its properties. | |
| 256 | + * | |
| 257 | + * @param string files ids | |
| 258 | + * @param string $size The size of image | |
| 259 | + * @param string|array $ext_list Allowed extensions, mixed sring with separated like jpg,doc,pdf or array | |
| 260 | + * @return array | |
| 261 | + */ | |
| 262 | + function wdk_files_data ($listing = '', $size = 'thumb', $ext_list = array()) { | |
| 263 | + $output = array(); | |
| 264 | + | |
| 265 | + $image_ids = ''; | |
| 266 | + if(is_string($listing)){ | |
| 267 | + $image_ids = explode(',', $listing); | |
| 268 | + } | |
| 269 | + | |
| 270 | + if(is_string($ext_list)){ | |
| 271 | + if(!empty($ext_list)) { | |
| 272 | + $ext_list = explode(',', $ext_list); | |
| 273 | + } else { | |
| 274 | + $ext_list = array(); | |
| 275 | + } | |
| 276 | + } | |
| 277 | + if(is_array($image_ids)) { | |
| 278 | + foreach ($image_ids as $key => $image_id) { | |
| 279 | + if(is_numeric($image_id)) | |
| 280 | + { | |
| 281 | + $image = wp_get_attachment_url( $image_id, $size ); | |
| 282 | + if(!empty($ext_list) && !in_array(wdk_file_extension($image), $ext_list)) { | |
| 283 | + continue; | |
| 284 | + } | |
| 285 | + | |
| 286 | + if(empty($image)/* || !file_exists(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $image))*/) | |
| 287 | + { | |
| 288 | + $image = wdk_placeholder_image_src(); | |
| 289 | + } | |
| 290 | + $attr = wdk_image_attr($image_id); | |
| 291 | + $output[] = array('src' =>$image, 'title' => $attr['title'], 'alt' => $attr['alt']); | |
| 292 | + } | |
| 293 | + } | |
| 294 | + } else if(is_numeric($image_ids)) | |
| 295 | + { | |
| 296 | + $image = wp_get_attachment_url( $image_ids, $size ); | |
| 297 | + if(!empty($ext_list) && !in_array(wdk_file_extension($image), $ext_list)) { | |
| 298 | + $attr = wdk_image_attr($image_ids); | |
| 299 | + $output[] = array('src' =>$image, 'title' => $attr['title'], 'alt' => $attr['alt']); | |
| 300 | + } | |
| 301 | + } | |
| 302 | + return $output; | |
| 303 | + } | |
| 304 | +} | |
| 305 | + | |
| 222 | 306 | if(!function_exists('wdk_image_src')) { |
| 223 | 307 | /** |
| 224 | 308 | * Initialize the class and set its properties. |
| 225 | 309 | * |
| @@ -395,12 +479,15 @@ | ||
| 395 | 479 | foreach ($list as $key => $field) { |
| 396 | 480 | $row = array(); |
| 397 | 481 | $row['value'] = wdk_field_value($field->field_id, $listing, $default); |
| 398 | 482 | |
| 399 | - if(wmvc_show_data('field_id', $field) == 'agent_image') { | |
| 483 | + if(in_array(wmvc_show_data('field_id', $field), array('agent_image','agent_email','agent_name'))) { | |
| 400 | 484 | $row['value'] = wmvc_show_data('user_id_editor', $listing); |
| 401 | 485 | } |
| 402 | 486 | |
| 487 | + if(empty($row['value']) && !empty(wdk_field_option($field->field_id,'empty_value', false))) | |
| 488 | + $row['value'] = wdk_field_option($field->field_id,'empty_value'); | |
| 489 | + | |
| 403 | 490 | if(empty($row['value'])) continue; |
| 404 | 491 | |
| 405 | 492 | if(wmvc_show_data('field_id', $field) == 'category_id') { |
| 406 | 493 | |
| @@ -414,8 +501,9 @@ | ||
| 414 | 501 | { |
| 415 | 502 | $tree_data = $category_static[$row['value']]; |
| 416 | 503 | } |
| 417 | 504 | |
| 505 | + $row['field_label'] = esc_html__('Category','wpdirectorykit'); | |
| 418 | 506 | $row['value'] = wmvc_show_data('category_title', $tree_data); |
| 419 | 507 | |
| 420 | 508 | if(isset($listing->categories_list)){ |
| 421 | 509 | $other_categories = wdk_generate_other_categories_fast($listing->categories_list); |
| @@ -434,8 +522,9 @@ | ||
| 434 | 522 | { |
| 435 | 523 | $tree_data = $location_static[$row['value']]; |
| 436 | 524 | } |
| 437 | 525 | |
| 526 | + $row['field_label'] = esc_html__('Location','wpdirectorykit'); | |
| 438 | 527 | $row['value'] = wmvc_show_data('location_title', $tree_data); |
| 439 | 528 | |
| 440 | 529 | if(isset($listing->locations_list)){ |
| 441 | 530 | $other_locations = wdk_generate_other_locations_fast($listing->locations_list); |
| @@ -442,9 +531,13 @@ | ||
| 442 | 531 | if(!empty($other_locations)) |
| 443 | 532 | $row['value'] .=', '.join(', ',$other_locations); |
| 444 | 533 | } |
| 445 | 534 | } else if(wdk_field_option($field->field_id, 'field_type') == 'DATE') { |
| 446 | - $row['value'] = wdk_get_date($row['value'], FALSE); | |
| 535 | + $row['field_label'] = esc_html__('Date','wpdirectorykit'); | |
| 536 | + $row['value'] = wdk_generate_field_date($field->field_id, $listing); | |
| 537 | + } else if(wmvc_show_data('field_id', $field) == 'date_modified') { | |
| 538 | + $row['field_label'] = esc_html__('Date','wpdirectorykit'); | |
| 539 | + $row['value'] = wdk_generate_field_date($field->field_id, $listing); | |
| 447 | 540 | } else { |
| 448 | 541 | |
| 449 | 542 | } |
| 450 | 543 | |
| @@ -515,18 +608,37 @@ | ||
| 515 | 608 | /* Favorite module */ |
| 516 | 609 | $data ['favorite_added'] = wmvc_show_data('is_favorite', $listing, false, TRUE, TRUE); |
| 517 | 610 | /* End Favorite module */ |
| 518 | 611 | |
| 519 | - $output = $WMVC->view('frontend/'.$template, $data, FALSE); | |
| 612 | + if(is_intval($template)) { | |
| 613 | + $output = ''; | |
| 614 | + $post_data = get_post($template); | |
| 520 | 615 | |
| 616 | + global $wdk_listing_id; | |
| 617 | + $wdk_listing_id = wmvc_show_data('post_id', $listing); | |
| 618 | + | |
| 619 | + if ($post_data) { | |
| 620 | + if ($post_data->post_type == 'page' || $post_data->post_type == 'elementor_library') { | |
| 621 | + $elementor_instance = \Elementor\Plugin::instance(); | |
| 622 | + $output = $elementor_instance->frontend->get_builder_content_for_display($template); | |
| 623 | + if (empty($output)) | |
| 624 | + $output = $post_data->post_content; | |
| 625 | + } else { | |
| 626 | + $output = $post_data->post_content; | |
| 627 | + } | |
| 628 | + } | |
| 629 | + } else { | |
| 630 | + $output = $WMVC->view('frontend/'.$template, $data, FALSE); | |
| 631 | + } | |
| 521 | 632 | $output = sprintf($html_sprintf, $output); |
| 633 | + | |
| 522 | 634 | if($json_output) { |
| 523 | 635 | $output = str_replace("'", "\'", $output); |
| 524 | 636 | $output = str_replace('"', '\"', $output); |
| 525 | 637 | $output = str_replace(array("\n", "\r"), '', $output); |
| 526 | 638 | } |
| 527 | - | |
| 528 | - return ($output); | |
| 639 | + | |
| 640 | + return $output; | |
| 529 | 641 | } |
| 530 | 642 | } |
| 531 | 643 | |
| 532 | 644 | if(!function_exists('wdk_image_alt')) { |
| @@ -764,9 +876,9 @@ | ||
| 764 | 876 | return $default; |
| 765 | 877 | } |
| 766 | 878 | |
| 767 | 879 | if(wdk_field_option($field_id, 'is_price_format') && wdk_field_option($field_id, 'field_type') == 'NUMBER') { |
| 768 | - $value = wdk_number_format_i18n(wdk_filter_decimal($value)); | |
| 880 | + $value = wdk_filter_decimal(wdk_number_format_i18n($value)); | |
| 769 | 881 | } elseif(wdk_field_option($field_id, 'field_type') == 'DATE') { |
| 770 | 882 | $value = wdk_get_date($value, FALSE); |
| 771 | 883 | } else { |
| 772 | 884 | $value = wdk_filter_decimal($value); |
| @@ -882,8 +994,119 @@ | ||
| 882 | 994 | if(!empty($user_data)) { |
| 883 | 995 | if(wmvc_show_data($field,$user_data['userdata'], false, TRUE, TRUE)) { |
| 884 | 996 | $output = wmvc_show_data($field,$user_data['userdata'], false, TRUE, TRUE); |
| 885 | 997 | } |
| 998 | + if(wmvc_show_data($field, $user_data, false, TRUE, TRUE)) { | |
| 999 | + $output = wmvc_show_data($field,$user_data, false, TRUE, TRUE); | |
| 1000 | + } | |
| 1001 | + } | |
| 1002 | + | |
| 1003 | + return $output; | |
| 1004 | + } | |
| 1005 | +} | |
| 1006 | + | |
| 1007 | +if(!function_exists('wdk_get_category_title')) { | |
| 1008 | + /** | |
| 1009 | + * Get user field | |
| 1010 | + * | |
| 1011 | + * @param int $user id | |
| 1012 | + * @param string $field use field | |
| 1013 | + * @param string $default, value if empty or not find user | |
| 1014 | + * @return string|array user field data or default value | |
| 1015 | + */ | |
| 1016 | + function wdk_get_category_title ($category_id='', $empty = false) { | |
| 1017 | + $output = $empty; | |
| 1018 | + $category = wdk_generate_other_categories_fast($category_id); | |
| 1019 | + | |
| 1020 | + if(!empty($category)) { | |
| 1021 | + $output = $category[$category_id]; | |
| 1022 | + } | |
| 1023 | + | |
| 1024 | + return $output; | |
| 1025 | + } | |
| 1026 | +} | |
| 1027 | + | |
| 1028 | +if(!function_exists('wdk_get_location_title')) { | |
| 1029 | + /** | |
| 1030 | + * Get user field | |
| 1031 | + * | |
| 1032 | + * @param int $user id | |
| 1033 | + * @param string $field use field | |
| 1034 | + * @param string $default, value if empty or not find user | |
| 1035 | + * @return string|array user field data or default value | |
| 1036 | + */ | |
| 1037 | + function wdk_get_location_title ($location_id='', $empty = false) { | |
| 1038 | + $output = $empty; | |
| 1039 | + $location = wdk_generate_other_locations_fast($location_id); | |
| 1040 | + | |
| 1041 | + if(!empty($location)) { | |
| 1042 | + $output = $location[$location_id]; | |
| 1043 | + } | |
| 1044 | + | |
| 1045 | + return $output; | |
| 1046 | + } | |
| 1047 | +} | |
| 1048 | + | |
| 1049 | +if(!function_exists('wdk_get_category_id')) { | |
| 1050 | + /** | |
| 1051 | + * Get Category id by category name | |
| 1052 | + * | |
| 1053 | + * @param int $category_name category name | |
| 1054 | + * @param string $empty, value if empty or not find | |
| 1055 | + * @return string category_id | |
| 1056 | + */ | |
| 1057 | + function wdk_get_category_id ($category_name='', $empty = false) { | |
| 1058 | + $output = $empty; | |
| 1059 | + $category_name = trim($category_name); | |
| 1060 | + static $categories_list = NULL; | |
| 1061 | + | |
| 1062 | + if(is_null($categories_list)) { | |
| 1063 | + $categories_list = array(); | |
| 1064 | + $WMVC = &wdk_get_instance(); | |
| 1065 | + $WMVC->model('category_m'); | |
| 1066 | + $categories = $WMVC->category_m->get(); | |
| 1067 | + | |
| 1068 | + if($categories) foreach ($categories as $item) { | |
| 1069 | + $categories_list[$item->idcategory] = $item->category_title; | |
| 1070 | + } | |
| 1071 | + } | |
| 1072 | + | |
| 1073 | + $key = array_search($category_name, $categories_list); | |
| 1074 | + if($key) { | |
| 1075 | + $output = $key; | |
| 1076 | + } | |
| 1077 | + return $output; | |
| 1078 | + } | |
| 1079 | +} | |
| 1080 | + | |
| 1081 | +if(!function_exists('wdk_get_location_id')) { | |
| 1082 | + /** | |
| 1083 | + * Get Location id by location name | |
| 1084 | + * | |
| 1085 | + * @param int $location_name location name | |
| 1086 | + * @param string $empty, value if empty or not find | |
| 1087 | + * @return string location_id | |
| 1088 | + */ | |
| 1089 | + function wdk_get_location_id ($location_name='', $empty = false) { | |
| 1090 | + $output = $empty; | |
| 1091 | + $location_name = trim($location_name); | |
| 1092 | + | |
| 1093 | + static $locations_list = NULL; | |
| 1094 | + | |
| 1095 | + if(is_null($locations_list)) { | |
| 1096 | + $locations_list = array(); | |
| 1097 | + $WMVC = &wdk_get_instance(); | |
| 1098 | + $WMVC->model('location_m'); | |
| 1099 | + $locations = $WMVC->location_m->get(); | |
| 1100 | + | |
| 1101 | + if($locations) foreach ($locations as $item) { | |
| 1102 | + $locations_list[$item->idlocation] = $item->location_title; | |
| 1103 | + } | |
| 1104 | + } | |
| 1105 | + | |
| 1106 | + $key = array_search($location_name, $locations_list); | |
| 1107 | + if($key) { | |
| 1108 | + $output = $key; | |
| 886 | 1109 | } |
| 887 | 1110 | |
| 888 | 1111 | return $output; |
| 889 | 1112 | } |