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/helpers/Listing.php +700 -47 1.1.0 → 1.5.9 View file →
@@ -51,10 +51,10 @@
51 51 if(!function_exists('wdk_field_value')) {
52 52 /**
53 53 * Initialize the class and set its properties.
54 54 *
55 - * @param int|string $field_id The name of this plugin.
56 - * @param int|object|array $listing The name of this plugin.
55 + * @param int|string $field_id field id
56 + * @param int|object|array $listing listing object|array or id
57 57 * @param string $default The default value, will be return if empty or no exists
58 58 * @return string
59 59 */
60 60 function wdk_field_value ($field_id='', $listing = array(), $default = '') {
@@ -87,13 +87,36 @@
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 *
95 - * @param int|object|array $listing The name of this plugin.
118 + * @param string|object|array $listing object or string with ids of images
96 119 * @param string $size The size of image
97 120 * @param string $default The default value, will be return if empty or no exists
98 121 * @return array
99 122 */
@@ -98,21 +121,35 @@
98 121 * @return array
99 122 */
100 123 function wdk_listing_images ($listing = array(), $size = 'thumb', $default = '') {
101 124 $output = array();
102 - $image_ids = explode(',', wdk_show_data('listing_images', $listing, '', TRUE, TRUE));
125 + $image_ids = '';
126 + if(is_array($listing) || is_object($listing)) {
127 + $image_ids = explode(',', wdk_show_data('listing_images', $listing, '', TRUE, TRUE));
128 + } else if(is_string($listing)){
129 + $image_ids = explode(',', $listing);
130 + }
131 +
103 132 if(is_array($image_ids)) {
104 133 foreach ($image_ids as $key => $image_id) {
105 134 if(is_numeric($image_id))
106 135 {
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 + */
107 142 $image = wp_get_attachment_image_src( $image_id, $size );
108 - $output[] = $image[0];
143 + if($image)
144 + $output[] = $image[0];
109 145 }
110 146 }
111 147 } else if(is_numeric($image_ids))
112 - {
113 - $image = wp_get_attachment_image_src( $image_ids, $size );
114 - $output[] = $image[0];
148 + {
149 + do_action('wdk/helpers/wdk_listing_images/get_attached/before', $image_ids, $size);
150 + $image = wp_get_attachment_url( $image_ids, $size );
151 + $output[] = $image;
115 152 }
116 153 return $output;
117 154 }
118 155 }
@@ -118,11 +155,11 @@
118 155 }
119 156
120 157 if(!function_exists('wdk_listing_images_fast_access')) {
121 158 /**
122 - * Initialize the class and set its properties.
159 + * Initialize the class and set its properties, work only with column listing_images and listing_images_path
123 160 *
124 - * @param int|object|array $listing The name of this plugin.
161 + * @param int|object|array $listing listing data
125 162 * @param string $size The size of image
126 163 * @param string $default The default value, will be return if empty or no exists
127 164 * @return array
128 165 */
@@ -160,38 +197,118 @@
160 197 if(!function_exists('wdk_listing_images_data')) {
161 198 /**
162 199 * Initialize the class and set its properties.
163 200 *
164 - * @param int|object|array $listing The name of this plugin.
201 + * @param string|object|array $listing object or string with ids of images
165 202 * @param string $size The size of image
166 203 * @param string $default The default value, will be return if empty or no exists
204 + * @param string|array $ext_list Allowed extensions, mixed sring with separated like jpg,doc,pdf or array
167 205 * @return array
168 206 */
169 - function wdk_listing_images_data ($listing = array(), $size = 'thumb', $default = '') {
207 + function wdk_listing_images_data ($listing = array(), $size = 'thumb', $default = '', $ext_list = array()) {
170 208 $output = array();
171 - $image_ids = explode(',', wmvc_show_data('listing_images', $listing, ''));
209 +
210 + $image_ids = '';
211 + if(is_array($listing) || is_object($listing)) {
212 + $image_ids = explode(',', wdk_show_data('listing_images', $listing, '', TRUE, TRUE));
213 + } else if(is_string($listing)){
214 + $image_ids = explode(',', $listing);
215 + }
216 +
217 + if(is_string($ext_list)){
218 + if(!empty($ext_list)) {
219 + $ext_list = explode(',', $ext_list);
220 + } else {
221 + $ext_list = array();
222 + }
223 + }
172 224 if(is_array($image_ids)) {
173 225 foreach ($image_ids as $key => $image_id) {
174 226 if(is_numeric($image_id))
175 227 {
176 - $image = wp_get_attachment_image_src( $image_id, $size );
177 - $output[] = array('src' =>$image[0], 'alt' => wdk_image_alt($image_id));
228 + $image = wp_get_attachment_url( $image_id, $size );
229 + if(!empty($ext_list) && !in_array(wdk_file_extension($image), $ext_list)) {
230 + continue;
231 + }
232 +
233 + if(empty($image)/* || !file_exists(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $image))*/)
234 + {
235 + $image = wdk_placeholder_image_src();
236 + }
237 + $attr = wdk_image_attr($image_id);
238 + $output[] = array('src' =>$image, 'title' => $attr['title'], 'alt' => $attr['alt']);
178 239 }
179 240 }
180 241 } else if(is_numeric($image_ids))
181 242 {
182 - $image = wp_get_attachment_image_src( $image_ids, $size );
183 - $output[] = array('src' =>$image[0], 'alt' => wdk_image_alt($image_ids));
243 + $image = wp_get_attachment_url( $image_ids, $size );
244 + if(!empty($ext_list) && !in_array(wdk_file_extension($image), $ext_list)) {
245 + $attr = wdk_image_attr($image_ids);
246 + $output[] = array('src' =>$image, 'title' => $attr['title'], 'alt' => $attr['alt']);
247 + }
184 248 }
185 249 return $output;
186 250 }
187 251 }
188 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 +
189 306 if(!function_exists('wdk_image_src')) {
190 307 /**
191 308 * Initialize the class and set its properties.
192 309 *
193 - * @param int|object|array $listing The name of this plugin.
310 + * @param int|object|array $listing listing data
194 311 * @param string $size The size of image
195 312 * @param string $default The default value, will be return if empty or no exists
196 313 * @return string
197 314 */
@@ -206,23 +323,22 @@
206 323
207 324 if(is_array($images))
208 325 $image = $images[0];
209 326
210 - if(!empty($image))
327 + if(!empty($image) && file_exists(WP_CONTENT_DIR. '/uploads/'.$image))
211 328 {
212 329 $output = WP_CONTENT_URL. '/uploads/'.$image;
213 330 }
214 331 } else {
215 332 $image_ids = explode(',', trim(wdk_show_data($field_image , $listing, '', TRUE, TRUE), ','));
216 -
333 +
217 334 if(is_array($image_ids))
218 335 $image_id = $image_ids[0];
219 336
220 337 if(is_numeric($image_id) && !empty($image_id) /*&& file_exists(get_attached_file($image_id))*/)
221 338 {
222 - $image = wp_get_attachment_image_src( $image_id, $size );
223 -
224 - if(!empty($image))
339 + $image = wp_get_attachment_image_src( $image_id, 'full' );
340 + if(!empty($image)/* && file_exists(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR,$image[0]))*/)
225 341 $output = $image[0];
226 342 }
227 343 }
228 344
@@ -229,8 +345,39 @@
229 345 return $output;
230 346 }
231 347 }
232 348
349 +if(!function_exists('wdk_listing_media_src')) {
350 + /**
351 + * Initialize the class and set its properties.
352 + *
353 + * @param int|object|array $listing listing data
354 + * @param string $default The default value, will be return if empty or no exists
355 + * @return string
356 + */
357 + function wdk_listing_media_src ($listing = array(), $default = '', $field_image = 'listing_images') {
358 + $output = wdk_placeholder_image_src();
359 + if(!empty($default)) {
360 + $output = $default;
361 + }
362 +
363 + $image_ids = explode(',', trim(wdk_show_data($field_image , $listing, '', TRUE, TRUE), ','));
364 +
365 + if(is_array($image_ids))
366 + $image_id = $image_ids[0];
367 +
368 + if(is_numeric($image_id) && !empty($image_id) /*&& file_exists(get_attached_file($image_id))*/)
369 + {
370 + $image = wp_get_attachment_url( $image_id);
371 + if(!empty($image)/* && file_exists(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $image))*/)
372 + $output = $image;
373 + }
374 +
375 + return $output;
376 + }
377 +}
378 +
379 +
233 380 if(!function_exists('wdk_resultitem_fields')) {
234 381 /**
235 382 * Initialize the class and set its properties.
236 383 *
@@ -247,9 +394,9 @@
247 394 if(isset($fields_data[$id])) {
248 395 return $fields_data[$id];
249 396 }
250 397
251 - $db_data = $WMVC->resultitem_m->get($id, TRUE);
398 + $db_data = wdk_resultitem($id);
252 399 // generate/decode used fields
253 400
254 401 if(is_object($db_data))
255 402 $fields = json_decode($db_data->resultitem_json);
@@ -259,13 +406,39 @@
259 406 return $fields;
260 407 }
261 408 }
262 409
410 +if(!function_exists('wdk_resultitem')) {
411 + /**
412 + * Initialize the class and set its properties.
413 + *
414 + * @param int $id The id of the resultitem list.
415 + * @return array
416 + */
417 + function wdk_resultitem($id = 1)
418 + {
419 + static $fields_data = array();
420 + $WMVC = &wdk_get_instance();
421 +
422 + $WMVC->model('resultitem_m');
423 + $db_data = NULL;
424 + if(isset($fields_data[$id])) {
425 + return $fields_data[$id];
426 + }
427 +
428 + $db_data = $WMVC->resultitem_m->get($id, TRUE);
429 +
430 + $fields_data[$id] = $db_data;
431 +
432 + return $db_data;
433 + }
434 +}
435 +
263 436 if(!function_exists('wdk_resultitem_fields_section')) {
264 437 /**
265 438 * Initialize the class and set its properties.
266 439 *
267 - * @param int $section_index The name of this plugin.
440 + * @param int $section_index section id
268 441 * @param int $id The id of the resultitem list.
269 442 * @return array
270 443 */
271 444 function wdk_resultitem_fields_section($section_index=1, $id = 1)
@@ -286,9 +459,9 @@
286 459 * Initialize the class and set its properties.
287 460 *
288 461 * @param int $id The id of the resultitem list.
289 462 * @param int $section_index The id of section in resultitem_m
290 - * @param int|object|array $listing The name of this plugin.
463 + * @param int|object|array $listing listing data or listing id
291 464 * @param string $default Default Value if empty
292 465
293 466 * @return array
294 467 */
@@ -302,12 +475,19 @@
302 475 $WMVC->model('location_m');
303 476
304 477 static $category_static = array();
305 478 static $location_static = array();
306 -
307 479 foreach ($list as $key => $field) {
308 480 $row = array();
309 481 $row['value'] = wdk_field_value($field->field_id, $listing, $default);
482 +
483 + if(in_array(wmvc_show_data('field_id', $field), array('agent_image','agent_email','agent_name'))) {
484 + $row['value'] = wmvc_show_data('user_id_editor', $listing);
485 + }
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 +
310 490 if(empty($row['value'])) continue;
311 491
312 492 if(wmvc_show_data('field_id', $field) == 'category_id') {
313 493
@@ -321,13 +501,18 @@
321 501 {
322 502 $tree_data = $category_static[$row['value']];
323 503 }
324 504
505 + $row['field_label'] = esc_html__('Category','wpdirectorykit');
325 506 $row['value'] = wmvc_show_data('category_title', $tree_data);
326 - }
507 +
508 + if(isset($listing->categories_list)){
509 + $other_categories = wdk_generate_other_categories_fast($listing->categories_list);
510 + if(!empty($other_categories))
511 + $row['value'] .=', '.join(', ',$other_categories);
512 + }
513 + } else if(wmvc_show_data('field_id', $field) == 'location_id') {
327 514
328 - if(wmvc_show_data('field_id', $field) == 'location_id') {
329 -
330 515 if(!isset($location_static[$row['value']]))
331 516 {
332 517 $tree_data = $WMVC->location_m->get($row['value'], TRUE);
333 518
@@ -337,9 +522,24 @@
337 522 {
338 523 $tree_data = $location_static[$row['value']];
339 524 }
340 525
526 + $row['field_label'] = esc_html__('Location','wpdirectorykit');
341 527 $row['value'] = wmvc_show_data('location_title', $tree_data);
528 +
529 + if(isset($listing->locations_list)){
530 + $other_locations = wdk_generate_other_locations_fast($listing->locations_list);
531 + if(!empty($other_locations))
532 + $row['value'] .=', '.join(', ',$other_locations);
533 + }
534 + } else if(wdk_field_option($field->field_id, 'field_type') == 'DATE') {
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);
540 + } else {
541 +
342 542 }
343 543
344 544 $field_data = $WMVC->field_m->get_fields_data($field->field_id);
345 545 $row += (array) $field;
@@ -356,9 +556,9 @@
356 556 * Initialize the class and set its properties.
357 557 *
358 558 * @param int $id The id of the resultitem list.
359 559 * @param int $section_index The id of section in resultitem_m
360 - * @param int|object|array $listing The name of this plugin.
560 + * @param int|object|array $listing listing object|array or id
361 561 * @param string $default Default Value if empty
362 562 * @param string $html Html for sprintf(), where
363 563 * %1$s - value
364 564 * %2$s - title
@@ -399,38 +599,46 @@
399 599 * %1$s - content
400 600 * @return string
401 601 */
402 602
403 - function wdk_listing_card($listing = array(), $settings = array(), $json_output = FALSE, $html_sprintf = '%1$s') {
603 + function wdk_listing_card($listing = array(), $settings = array(), $json_output = FALSE, $html_sprintf = '%1$s', $template = 'result_item_card') {
404 604 $data = ['listing'=>$listing, 'settings'=>$settings];
405 605
406 606 $WMVC = &wdk_get_instance();
407 607
408 608 /* Favorite module */
409 - $favorite_added=false;
410 -
411 - global $Winter_MVC_wdk_favorites;
412 - if(get_current_user_id() != 0 && isset($Winter_MVC_wdk_favorites))
413 - {
414 - $Winter_MVC_wdk_favorites->model('favorite_m');
415 - $favorite_added = $Winter_MVC_wdk_favorites->favorite_m->check_if_exists(get_current_user_id(),
416 - wmvc_show_data('post_id', $listing));
417 - if($favorite_added>0)$favorite_added = true;
418 - }
419 -
420 - $data ['favorite_added'] = $favorite_added;
609 + $data ['favorite_added'] = wmvc_show_data('is_favorite', $listing, false, TRUE, TRUE);
421 610 /* End Favorite module */
422 611
423 - $output = $WMVC->view('frontend/result_item_card', $data, FALSE);
612 + if(is_intval($template)) {
613 + $output = '';
614 + $post_data = get_post($template);
424 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 + }
425 632 $output = sprintf($html_sprintf, $output);
633 +
426 634 if($json_output) {
427 635 $output = str_replace("'", "\'", $output);
428 636 $output = str_replace('"', '\"', $output);
429 637 $output = str_replace(array("\n", "\r"), '', $output);
430 638 }
431 -
432 - return ($output);
639 +
640 + return $output;
433 641 }
434 642 }
435 643
436 644 if(!function_exists('wdk_image_alt')) {
@@ -456,5 +664,450 @@
456 664 }
457 665
458 666 return $alt;
459 667 }
668 +}
669 +
670 +if(!function_exists('wdk_image_attr')) {
671 + /**
672 + * Generate array with alt and title, if alt missing, return title like alt
673 + *
674 + * @param string|int $link|id The url or id of image.
675 + * @return array alt and title
676 + */
677 +
678 + function wdk_image_attr($link_id = '') {
679 + $alt = '';
680 + $title = '';
681 +
682 + if(is_intval($link_id)) {
683 + $attached_id = $link_id;
684 + } else {
685 + $attached_id = attachment_url_to_postid($link_id);
686 + }
687 +
688 + $alt = get_post_meta($attached_id, '_wp_attachment_image_alt', true);
689 + $title = get_the_title($attached_id);
690 + if($alt == '') {
691 + $alt = $title;
692 + }
693 +
694 + return array('title'=>$title, 'alt'=>$alt);
695 + }
696 +}
697 +
698 +
699 +
700 +if(!function_exists('wdk_generate_other_locations')) {
701 + /**
702 + * Return array with locations id from listing
703 + *
704 + * @param int post_id the listings id
705 + * @return array locations
706 + */
707 +
708 + function wdk_generate_other_locations($post_id = NULL) {
709 + $WMVC = &wdk_get_instance();
710 + $WMVC->model('locationslistings_m');
711 + $locations_array = array();
712 + $locations = $WMVC->locationslistings_m->get_locations($post_id);
713 +
714 + if($locations) foreach ($locations as $item) {
715 + if($item)
716 + $locations_array[wmvc_show_data('idlocation', $item, false, TRUE, TRUE)] = wmvc_show_data('location_title', $item, false, TRUE, TRUE);
717 + }
718 + return $locations_array;
719 + }
720 +}
721 +
722 +if(!function_exists('wdk_generate_other_categories')) {
723 + /**
724 + * Return array with categories id from listing
725 + *
726 + * @param int post_id the listings id
727 + * @return array categories
728 + */
729 +
730 + function wdk_generate_other_categories($post_id = NULL) {
731 + $WMVC = &wdk_get_instance();
732 + $WMVC->model('categorieslistings_m');
733 + $categories_array = array();
734 + $categories = $WMVC->categorieslistings_m->get_categories($post_id);
735 +
736 + if($categories) foreach ($categories as $item) {
737 + if($item)
738 + $categories_array[wmvc_show_data('idcategory', $item, false, TRUE, TRUE)] = wmvc_show_data('category_title', $item, false, TRUE, TRUE);
739 + }
740 + return $categories_array;
741 + }
742 +}
743 +
744 +if(!function_exists('wdk_generate_other_locations_keys')) {
745 + /**
746 + * Return array with locations id from listing
747 + *
748 + * @param int post_id the listings id
749 + * @return array locations keys
750 + */
751 +
752 + function wdk_generate_other_locations_keys($post_id = NULL) {
753 + $WMVC = &wdk_get_instance();
754 + $WMVC->model('locationslistings_m');
755 + $locations_array = array();
756 + $locations = $WMVC->locationslistings_m->get($post_id);
757 +
758 + if($locations) foreach ($locations as $item) {
759 + if($item)
760 + $locations_array[] = wmvc_show_data('location_id', $item, false, TRUE, TRUE);
761 + }
762 + return $locations_array;
763 + }
764 +}
765 +
766 +if(!function_exists('wdk_generate_other_categories_keys')) {
767 + /**
768 + * Return array with categories id from listing
769 + *
770 + * @param int post_id the listings id
771 + * @return array categories keys
772 + */
773 +
774 + function wdk_generate_other_categories_keys($post_id = NULL) {
775 + $WMVC = &wdk_get_instance();
776 + $WMVC->model('categorieslistings_m');
777 + $categories_array = array();
778 + $categories = $WMVC->categorieslistings_m->get($post_id);
779 +
780 + if($categories) foreach ($categories as $item) {
781 + if($item)
782 + $categories_array[] = wmvc_show_data('category_id', $item, false, TRUE, TRUE);
783 + }
784 + return $categories_array;
785 + }
786 +}
787 +
788 +if(!function_exists('wdk_generate_other_categories_fast')) {
789 + /**
790 + * Return array with categories id from listing
791 + *
792 + * @param string ids list separeted with ','
793 + * @return array with categories list
794 + */
795 +
796 + function wdk_generate_other_categories_fast($ids = NULL) {
797 + static $categories_list = NULL;
798 + $categories_array = array();
799 +
800 + if(is_null($categories_list)) {
801 + $categories_list = array();
802 + $WMVC = &wdk_get_instance();
803 + $WMVC->model('category_m');
804 + $categories = $WMVC->category_m->get();
805 +
806 + if($categories) foreach ($categories as $item) {
807 + $categories_list[$item->idcategory] = $item->category_title;
808 + }
809 + }
810 +
811 + if(is_string($ids))
812 + foreach(explode(',', $ids) as $item_id) {
813 + if(empty($item_id)) continue;
814 +
815 +
816 + if(isset($categories_list[$item_id]))
817 + $categories_array[$item_id] = $categories_list[$item_id];
818 + }
819 +
820 + return $categories_array;
821 + }
822 +}
823 +
824 +if(!function_exists('wdk_generate_other_locations_fast')) {
825 + /**
826 + * Return array with locations id from listing
827 + *
828 + * @param string ids list separeted with ','
829 + * @return array with locations list
830 + */
831 +
832 + function wdk_generate_other_locations_fast($ids = NULL) {
833 + static $locations_list = NULL;
834 + $locations_array = array();
835 +
836 + if(is_null($locations_list)) {
837 + $locations_list = array();
838 + $WMVC = &wdk_get_instance();
839 + $WMVC->model('location_m');
840 + $locations = $WMVC->location_m->get();
841 +
842 + if($locations) foreach ($locations as $item) {
843 + $locations_list[$item->idlocation] = $item->location_title;
844 + }
845 + }
846 +
847 + if(is_string($ids))
848 + foreach(explode(',', $ids) as $item_id) {
849 + if(empty($item_id)) continue;
850 +
851 +
852 + if(isset($locations_list[$item_id]))
853 + $locations_array[$item_id] = $locations_list[$item_id];
854 + }
855 +
856 + return $locations_array;
857 + }
858 +}
859 +
860 +
861 +if(!function_exists('wdk_field_value_on_type')) {
862 + /**
863 + * Generate field value, based on type
864 + *
865 + * @param int|string $field_id field id
866 + * @param int|object|array $listing listing object|array or id
867 + * @param string $default The default value, will be return if empty or no exists
868 + * @return string
869 + */
870 + function wdk_field_value_on_type ($field_id='', $listing = array(), $default = '') {
871 +
872 + $value = wdk_field_value($field_id, $listing, $default);
873 +
874 + /* filter per type */
875 + if(empty($value)) {
876 + return $default;
877 + }
878 +
879 + if(wdk_field_option($field_id, 'is_price_format') && wdk_field_option($field_id, 'field_type') == 'NUMBER') {
880 + $value = wdk_filter_decimal(wdk_number_format_i18n($value));
881 + } elseif(wdk_field_option($field_id, 'field_type') == 'DATE') {
882 + $value = wdk_get_date($value, FALSE);
883 + } else {
884 + $value = wdk_filter_decimal($value);
885 + }
886 +
887 + return $value;
888 + }
889 +}
890 +
891 +if(!function_exists('wdk_location_get_all_childs')) {
892 + /**
893 + * Get cached childs of location
894 + *
895 + * @param int $field_id location id
896 + * @return array
897 + */
898 + function wdk_location_get_all_childs ($field_id='') {
899 + static $childs_cache = array();
900 + $childs = array();
901 + if(isset($childs_cache[$field_id])) {
902 + $childs = $childs_cache [$field_id];
903 + } else {
904 + global $Winter_MVC_WDK;
905 + $Winter_MVC_WDK->load_helper('listing');
906 + $Winter_MVC_WDK->model('location_m');
907 +
908 + $childs = $Winter_MVC_WDK->location_m->get_all_childs($field_id);
909 + if($childs) {
910 + $childs_cache [$field_id] = $childs;
911 + } else {
912 + $childs_cache [$field_id] = $childs;
913 + }
914 + }
915 + return $childs;
916 + }
917 +}
918 +
919 +if(!function_exists('wdk_category_get_all_childs')) {
920 + /**
921 + * Get cached childs of category
922 + *
923 + * @param int $field_id category id
924 + * @return array
925 + */
926 + function wdk_category_get_all_childs ($field_id='') {
927 + static $childs_cache = array();
928 + $childs = array();
929 + if(isset($childs_cache[$field_id])) {
930 + $childs = $childs_cache [$field_id];
931 + } else {
932 + global $Winter_MVC_WDK;
933 + $Winter_MVC_WDK->load_helper('listing');
934 + $Winter_MVC_WDK->model('category_m');
935 +
936 + $childs = $Winter_MVC_WDK->category_m->get_all_childs($field_id);
937 + if($childs) {
938 + $childs_cache [$field_id] = $childs;
939 + } else {
940 + $childs_cache [$field_id] = $childs;
941 + }
942 + }
943 + return $childs;
944 + }
945 +}
946 +
947 +if(!function_exists('wdk_get_user_data')) {
948 + /**
949 + * Get user data
950 + *
951 + * @param int $user id
952 + * @return array user data ('userdata'=>$userdata, 'avatar'=>get_avatar_url($user_id),'user_id'=>$user_id, 'profile_url'=>'url on profile');
953 + */
954 + function wdk_get_user_data ($user_id='') {
955 + static $users_cache = array();
956 +
957 + $user = array();
958 + if(isset($users_cache[$user_id])) {
959 + $user = $users_cache [$user_id];
960 + } else {
961 +
962 + $userdata = get_userdata($user_id);
963 + if($userdata) {
964 + $user = array('userdata'=>$userdata, 'avatar'=>get_avatar_url($user_id, array("size"=>300)),'user_id'=>$user_id);
965 + $user['profile_url'] =NULL;
966 +
967 + if(function_exists('wdk_generate_profile_permalink'))
968 + $user['profile_url'] = wdk_generate_profile_permalink($userdata);
969 + }
970 +
971 + if($user) {
972 + $users_cache [$user_id] = $user;
973 + } else {
974 + $users_cache [$user_id] = $user;
975 + }
976 + }
977 + return $user;
978 + }
979 +}
980 +
981 +if(!function_exists('wdk_get_user_field')) {
982 + /**
983 + * Get user field
984 + *
985 + * @param int $user id
986 + * @param string $field use field
987 + * @param string $default, value if empty or not find user
988 + * @return string|array user field data or default value
989 + */
990 + function wdk_get_user_field ($user_id='', $field = '', $default = '') {
991 + $user_data = wdk_get_user_data ($user_id);
992 + $output = $default;
993 +
994 + if(!empty($user_data)) {
995 + if(wmvc_show_data($field,$user_data['userdata'], false, TRUE, TRUE)) {
996 + $output = wmvc_show_data($field,$user_data['userdata'], false, TRUE, TRUE);
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;
1109 + }
1110 +
1111 + return $output;
1112 + }
460 1113 }