PluginProbe
WP Directory Kit / 1.1.6
WP Directory Kit v1.1.6
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
wpdirectorykit / application / helpers / Listing.php

Listing.php in WP Directory Kit 1.1.6, at application/helpers/Listing.php

885 lines 25.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 if(!function_exists('wdk_field_label')) {
8 /**
9 * Get field name
10 * @param int $field_id The id of field
11 * @param string $default The default data if field not defined
12 * @return string field name
13 */
14 function wdk_field_label ($field_id='', $default = '') {
15 $field_name = $default;
16
17 $WMVC = &wdk_get_instance();
18 $WMVC->model('field_m');
19 $field_data = $WMVC->field_m->get_fields_data($field_id);
20
21 if($field_data && isset($field_data->field_label) && !empty($field_data->field_label)) {
22 $field_name = $field_data->field_label;
23 }
24
25 return $field_name;
26 }
27 }
28
29 if(!function_exists('wdk_field_option')) {
30 /**
31 * Get field option
32 * @param int $field_id The id of field
33 * @param string $option The option of field (prefix,suffix,label)
34 * @return string
35 */
36 function wdk_field_option ($field_id='', $option = '', $default = '') {
37 $field_option = $default;
38
39 $WMVC = &wdk_get_instance();
40 $WMVC->model('field_m');
41 $field_data = $WMVC->field_m->get_fields_data($field_id);
42
43 if($field_data && isset($field_data->$option)) {
44 $field_option = $field_data->$option;
45 }
46
47 return $field_option;
48 }
49 }
50
51 if(!function_exists('wdk_field_value')) {
52 /**
53 * Initialize the class and set its properties.
54 *
55 * @param int|string $field_id field id
56 * @param int|object|array $listing listing object|array or id
57 * @param string $default The default value, will be return if empty or no exists
58 * @return string
59 */
60 function wdk_field_value ($field_id='', $listing = array(), $default = '') {
61 static $listings_data = array();
62 $WMVC = &wdk_get_instance();
63 $WMVC->model('listing_m');
64 $WMVC->model('listingfield_m');
65 $f_key = $field_id;
66
67 if(is_intval($f_key))
68 $f_key = 'field_'.wdk_field_option($field_id,'idfield').'_'.wdk_field_option($field_id,'field_type');
69
70 $listing_data = array();
71 if(is_array($listing) || is_object($listing)) {
72 $listing_data = (array) $listing;
73 }
74 elseif(is_intval($listing)) {
75 if(!isset($listings_data[$listing])) {
76 $listing_data = $WMVC->listing_m->get($listing, TRUE);
77 $listings_data[$listing] = $listing_data;
78 } else {
79 $listing_data = $listings_data[$listing];
80 }
81 }
82
83 if(!empty(wdk_show_data($f_key, $listing_data, '', FALSE, TRUE))) {
84 return wdk_show_data($f_key, $listing_data, '', FALSE, TRUE);
85 }
86
87 return $default;
88 }
89 }
90
91 if(!function_exists('wdk_listing_images')) {
92 /**
93 * Initialize the class and set its properties.
94 *
95 * @param string|object|array $listing object or string with ids of images
96 * @param string $size The size of image
97 * @param string $default The default value, will be return if empty or no exists
98 * @return array
99 */
100 function wdk_listing_images ($listing = array(), $size = 'thumb', $default = '') {
101 $output = array();
102 $image_ids = '';
103 if(is_array($listing) || is_object($listing)) {
104 $image_ids = explode(',', wdk_show_data('listing_images', $listing, '', TRUE, TRUE));
105 } else if(is_string($listing)){
106 $image_ids = explode(',', $listing);
107 }
108
109 if(is_array($image_ids)) {
110 foreach ($image_ids as $key => $image_id) {
111 if(is_numeric($image_id))
112 {
113 $image = wp_get_attachment_url( $image_id, $size );
114 $output[] = $image;
115 }
116 }
117 } else if(is_numeric($image_ids))
118 {
119 $image = wp_get_attachment_url( $image_ids, $size );
120 $output[] = $image;
121 }
122 return $output;
123 }
124 }
125
126 if(!function_exists('wdk_listing_images_fast_access')) {
127 /**
128 * Initialize the class and set its properties, work only with column listing_images and listing_images_path
129 *
130 * @param int|object|array $listing listing data
131 * @param string $size The size of image
132 * @param string $default The default value, will be return if empty or no exists
133 * @return array
134 */
135 function wdk_listing_images_fast_access ($listing = array(), $size = 'thumb', $default = '') {
136 $output = array();
137 if(!empty(wdk_show_data('listing_images_path', $listing, '', TRUE, TRUE))) {
138 $images = explode(',', wdk_show_data('listing_images_path', $listing, '', TRUE, TRUE));
139 if(is_array($images)) {
140 foreach ($images as $key => $image_path) {
141 $output[] = WP_CONTENT_URL. '/uploads/'.$image_path;
142 }
143 } else {
144 $output[] = WP_CONTENT_URL. '/uploads/'.$images;
145 }
146 } else {
147 $image_ids = explode(',', wdk_show_data('listing_images', $listing, '', TRUE, TRUE));
148 if(is_array($image_ids)) {
149 foreach ($image_ids as $key => $image_id) {
150 if(is_numeric($image_id))
151 {
152 $image = wp_get_attachment_image_src( $image_id, $size );
153 $output[] = $image[0];
154 }
155 }
156 } else if(is_numeric($image_ids)) {
157 $image = wp_get_attachment_image_src( $image_ids, $size );
158 $output[] = $image[0];
159 }
160 }
161
162 return $output;
163 }
164 }
165
166 if(!function_exists('wdk_listing_images_data')) {
167 /**
168 * Initialize the class and set its properties.
169 *
170 * @param string|object|array $listing object or string with ids of images
171 * @param string $size The size of image
172 * @param string $default The default value, will be return if empty or no exists
173 * @param string|array $ext_list Allowed extensions, mixed sring with separated like jpg,doc,pdf or array
174 * @return array
175 */
176 function wdk_listing_images_data ($listing = array(), $size = 'thumb', $default = '', $ext_list = array()) {
177 $output = array();
178
179 $image_ids = '';
180 if(is_array($listing) || is_object($listing)) {
181 $image_ids = explode(',', wdk_show_data('listing_images', $listing, '', TRUE, TRUE));
182 } else if(is_string($listing)){
183 $image_ids = explode(',', $listing);
184 }
185
186 if(is_string($ext_list)){
187 if(!empty($ext_list)) {
188 $ext_list = explode(',', $ext_list);
189 } else {
190 $ext_list = array();
191 }
192 }
193 if(is_array($image_ids)) {
194 foreach ($image_ids as $key => $image_id) {
195 if(is_numeric($image_id))
196 {
197 $image = wp_get_attachment_url( $image_id, $size );
198 if(!empty($ext_list) && !in_array(wdk_file_extension($image), $ext_list)) {
199 continue;
200 }
201
202 if(empty($image)/* || !file_exists(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $image))*/)
203 {
204 $image = wdk_placeholder_image_src();
205 }
206 $attr = wdk_image_attr($image_id);
207 $output[] = array('src' =>$image, 'title' => $attr['title'], 'alt' => $attr['alt']);
208 }
209 }
210 } else if(is_numeric($image_ids))
211 {
212 $image = wp_get_attachment_url( $image_ids, $size );
213 if(!empty($ext_list) && !in_array(wdk_file_extension($image), $ext_list)) {
214 $attr = wdk_image_attr($image_ids);
215 $output[] = array('src' =>$image, 'title' => $attr['title'], 'alt' => $attr['alt']);
216 }
217 }
218 return $output;
219 }
220 }
221
222 if(!function_exists('wdk_image_src')) {
223 /**
224 * Initialize the class and set its properties.
225 *
226 * @param int|object|array $listing listing data
227 * @param string $size The size of image
228 * @param string $default The default value, will be return if empty or no exists
229 * @return string
230 */
231 function wdk_image_src ($listing = array(), $size = 'thumb', $default = '', $field_image = 'listing_images', $field_images_paths = 'listing_images_path') {
232 $output = wdk_placeholder_image_src();
233 if(!empty($default)) {
234 $output = $default;
235 }
236
237 if(!empty(wdk_show_data($field_images_paths, $listing, '', TRUE, TRUE))) {
238 $images = explode(',', wdk_show_data($field_images_paths, $listing, '', TRUE, TRUE));
239
240 if(is_array($images))
241 $image = $images[0];
242
243 if(!empty($image) && file_exists(WP_CONTENT_DIR. '/uploads/'.$image))
244 {
245 $output = WP_CONTENT_URL. '/uploads/'.$image;
246 }
247 } else {
248 $image_ids = explode(',', trim(wdk_show_data($field_image , $listing, '', TRUE, TRUE), ','));
249
250 if(is_array($image_ids))
251 $image_id = $image_ids[0];
252
253 if(is_numeric($image_id) && !empty($image_id) /*&& file_exists(get_attached_file($image_id))*/)
254 {
255 $image = wp_get_attachment_image_src( $image_id, 'full' );
256 if(!empty($image)/* && file_exists(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR,$image[0]))*/)
257 $output = $image[0];
258 }
259 }
260
261 return $output;
262 }
263 }
264
265 if(!function_exists('wdk_listing_media_src')) {
266 /**
267 * Initialize the class and set its properties.
268 *
269 * @param int|object|array $listing listing data
270 * @param string $default The default value, will be return if empty or no exists
271 * @return string
272 */
273 function wdk_listing_media_src ($listing = array(), $default = '', $field_image = 'listing_images') {
274 $output = wdk_placeholder_image_src();
275 if(!empty($default)) {
276 $output = $default;
277 }
278
279 $image_ids = explode(',', trim(wdk_show_data($field_image , $listing, '', TRUE, TRUE), ','));
280
281 if(is_array($image_ids))
282 $image_id = $image_ids[0];
283
284 if(is_numeric($image_id) && !empty($image_id) /*&& file_exists(get_attached_file($image_id))*/)
285 {
286 $image = wp_get_attachment_url( $image_id);
287 if(!empty($image)/* && file_exists(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $image))*/)
288 $output = $image;
289 }
290
291 return $output;
292 }
293 }
294
295
296 if(!function_exists('wdk_resultitem_fields')) {
297 /**
298 * Initialize the class and set its properties.
299 *
300 * @param int $id The id of the resultitem list.
301 * @return array
302 */
303 function wdk_resultitem_fields($id = 1)
304 {
305 static $fields_data = array();
306 $WMVC = &wdk_get_instance();
307
308 $WMVC->model('resultitem_m');
309 $fields = NULL;
310 if(isset($fields_data[$id])) {
311 return $fields_data[$id];
312 }
313
314 $db_data = wdk_resultitem($id);
315 // generate/decode used fields
316
317 if(is_object($db_data))
318 $fields = json_decode($db_data->resultitem_json);
319
320 $fields_data[$id] = $fields;
321
322 return $fields;
323 }
324 }
325
326 if(!function_exists('wdk_resultitem')) {
327 /**
328 * Initialize the class and set its properties.
329 *
330 * @param int $id The id of the resultitem list.
331 * @return array
332 */
333 function wdk_resultitem($id = 1)
334 {
335 static $fields_data = array();
336 $WMVC = &wdk_get_instance();
337
338 $WMVC->model('resultitem_m');
339 $db_data = NULL;
340 if(isset($fields_data[$id])) {
341 return $fields_data[$id];
342 }
343
344 $db_data = $WMVC->resultitem_m->get($id, TRUE);
345
346 $fields_data[$id] = $db_data;
347
348 return $db_data;
349 }
350 }
351
352 if(!function_exists('wdk_resultitem_fields_section')) {
353 /**
354 * Initialize the class and set its properties.
355 *
356 * @param int $section_index section id
357 * @param int $id The id of the resultitem list.
358 * @return array
359 */
360 function wdk_resultitem_fields_section($section_index=1, $id = 1)
361 {
362 $fields = array();
363 $list = wdk_resultitem_fields($id);
364
365 if(isset($list[$section_index])) {
366 $fields = $list[$section_index];
367 }
368
369 return $fields;
370 }
371 }
372
373 if(!function_exists('wdk_resultitem_fields_section_value')) {
374 /**
375 * Initialize the class and set its properties.
376 *
377 * @param int $id The id of the resultitem list.
378 * @param int $section_index The id of section in resultitem_m
379 * @param int|object|array $listing listing data or listing id
380 * @param string $default Default Value if empty
381
382 * @return array
383 */
384 function wdk_resultitem_fields_section_value($id = 1, $section_index=1, $listing='', $default='')
385 {
386 $output = [];
387 $list = wdk_resultitem_fields_section($section_index, $id);
388 $WMVC = &wdk_get_instance();
389 $WMVC->model('field_m');
390 $WMVC->model('category_m');
391 $WMVC->model('location_m');
392
393 static $category_static = array();
394 static $location_static = array();
395 foreach ($list as $key => $field) {
396 $row = array();
397 $row['value'] = wdk_field_value($field->field_id, $listing, $default);
398
399 if(wmvc_show_data('field_id', $field) == 'agent_image') {
400 $row['value'] = wmvc_show_data('user_id_editor', $listing);
401 }
402
403 if(empty($row['value'])) continue;
404
405 if(wmvc_show_data('field_id', $field) == 'category_id') {
406
407 if(!isset($category_static[$row['value']]))
408 {
409 $tree_data = $WMVC->category_m->get($row['value'], TRUE);
410
411 $category_static[$row['value']] = $tree_data;
412 }
413 else
414 {
415 $tree_data = $category_static[$row['value']];
416 }
417
418 $row['value'] = wmvc_show_data('category_title', $tree_data);
419
420 if(isset($listing->categories_list)){
421 $other_categories = wdk_generate_other_categories_fast($listing->categories_list);
422 if(!empty($other_categories))
423 $row['value'] .=', '.join(', ',$other_categories);
424 }
425 } else if(wmvc_show_data('field_id', $field) == 'location_id') {
426
427 if(!isset($location_static[$row['value']]))
428 {
429 $tree_data = $WMVC->location_m->get($row['value'], TRUE);
430
431 $location_static[$row['value']] = $tree_data;
432 }
433 else
434 {
435 $tree_data = $location_static[$row['value']];
436 }
437
438 $row['value'] = wmvc_show_data('location_title', $tree_data);
439
440 if(isset($listing->locations_list)){
441 $other_locations = wdk_generate_other_locations_fast($listing->locations_list);
442 if(!empty($other_locations))
443 $row['value'] .=', '.join(', ',$other_locations);
444 }
445 } else if(wdk_field_option($field->field_id, 'field_type') == 'DATE') {
446 $row['value'] = wdk_get_date($row['value'], FALSE);
447 } else {
448
449 }
450
451 $field_data = $WMVC->field_m->get_fields_data($field->field_id);
452 $row += (array) $field;
453 $row += (array) $field_data;
454
455 $output [] = $row;
456 }
457 if(empty($output)) return NULL;
458 return $output;
459 }
460 }
461 if(!function_exists('wdk_generate_resultitem_fields_section_value')) {
462 /**
463 * Initialize the class and set its properties.
464 *
465 * @param int $id The id of the resultitem list.
466 * @param int $section_index The id of section in resultitem_m
467 * @param int|object|array $listing listing object|array or id
468 * @param string $default Default Value if empty
469 * @param string $html Html for sprintf(), where
470 * %1$s - value
471 * %2$s - title
472 * %3$s - prefix
473 * %4$s - suffix
474 * @return array
475 */
476 function wdk_generate_resultitem_fields_section_value($id = 1, $section_index=1, $listing='', $default='', $html =' %3$s %1$s %4$s ')
477 {
478 $output = '';
479 $list = wdk_resultitem_fields_section($section_index, $id);
480 foreach ($list as $key => $field) {
481 $value = wdk_field_value($field->field_id, $listing, $default);
482 if(empty($value)) continue;
483 if(wdk_field_option($field->field_id,'field_type') == 'CHECKBOX') {
484 $html ='<span> %2$s </span>';
485 }
486 $output .= sprintf($html,
487 $value,
488 wdk_field_option($field->field_id,'field_label'),
489 wdk_field_option($field->field_id,'prefix'),
490 wdk_field_option($field->field_id,'suffix')
491 );
492 }
493
494 return trim($output);
495 }
496 }
497
498 if(!function_exists('wdk_listing_card')) {
499 /**
500 * Generate listing card html
501 *
502 * @param array $listing The listing data.
503 * @param array $settings The settings.
504 * @param bool $json_output Encode for json, default false
505 * @param string $html Html for sprintf(), where
506 * %1$s - content
507 * @return string
508 */
509
510 function wdk_listing_card($listing = array(), $settings = array(), $json_output = FALSE, $html_sprintf = '%1$s', $template = 'result_item_card') {
511 $data = ['listing'=>$listing, 'settings'=>$settings];
512
513 $WMVC = &wdk_get_instance();
514
515 /* Favorite module */
516 $data ['favorite_added'] = wmvc_show_data('is_favorite', $listing, false, TRUE, TRUE);
517 /* End Favorite module */
518
519 $output = $WMVC->view('frontend/'.$template, $data, FALSE);
520
521 $output = sprintf($html_sprintf, $output);
522 if($json_output) {
523 $output = str_replace("'", "\'", $output);
524 $output = str_replace('"', '\"', $output);
525 $output = str_replace(array("\n", "\r"), '', $output);
526 }
527
528 return ($output);
529 }
530 }
531
532 if(!function_exists('wdk_image_alt')) {
533 /**
534 * Generate alt tag
535 *
536 * @param string|int $link|id The url or id of image.
537 * @return string alt or title
538 */
539
540 function wdk_image_alt($link_id = '') {
541 $alt = '';
542
543 if(is_intval($link_id)) {
544 $attached_id = $link_id;
545 } else {
546 $attached_id = attachment_url_to_postid($link_id);
547 }
548
549 $alt = get_post_meta($attached_id, '_wp_attachment_image_alt', true);
550 if($alt == '') {
551 $alt = get_the_title($attached_id);
552 }
553
554 return $alt;
555 }
556 }
557
558 if(!function_exists('wdk_image_attr')) {
559 /**
560 * Generate array with alt and title, if alt missing, return title like alt
561 *
562 * @param string|int $link|id The url or id of image.
563 * @return array alt and title
564 */
565
566 function wdk_image_attr($link_id = '') {
567 $alt = '';
568 $title = '';
569
570 if(is_intval($link_id)) {
571 $attached_id = $link_id;
572 } else {
573 $attached_id = attachment_url_to_postid($link_id);
574 }
575
576 $alt = get_post_meta($attached_id, '_wp_attachment_image_alt', true);
577 $title = get_the_title($attached_id);
578 if($alt == '') {
579 $alt = $title;
580 }
581
582 return array('title'=>$title, 'alt'=>$alt);
583 }
584 }
585
586
587
588 if(!function_exists('wdk_generate_other_locations')) {
589 /**
590 * Return array with locations id from listing
591 *
592 * @param int post_id the listings id
593 * @return array locations
594 */
595
596 function wdk_generate_other_locations($post_id = NULL) {
597 $WMVC = &wdk_get_instance();
598 $WMVC->model('locationslistings_m');
599 $locations_array = array();
600 $locations = $WMVC->locationslistings_m->get_locations($post_id);
601
602 if($locations) foreach ($locations as $item) {
603 if($item)
604 $locations_array[wmvc_show_data('idlocation', $item, false, TRUE, TRUE)] = wmvc_show_data('location_title', $item, false, TRUE, TRUE);
605 }
606 return $locations_array;
607 }
608 }
609
610 if(!function_exists('wdk_generate_other_categories')) {
611 /**
612 * Return array with categories id from listing
613 *
614 * @param int post_id the listings id
615 * @return array categories
616 */
617
618 function wdk_generate_other_categories($post_id = NULL) {
619 $WMVC = &wdk_get_instance();
620 $WMVC->model('categorieslistings_m');
621 $categories_array = array();
622 $categories = $WMVC->categorieslistings_m->get_categories($post_id);
623
624 if($categories) foreach ($categories as $item) {
625 if($item)
626 $categories_array[wmvc_show_data('idcategory', $item, false, TRUE, TRUE)] = wmvc_show_data('category_title', $item, false, TRUE, TRUE);
627 }
628 return $categories_array;
629 }
630 }
631
632 if(!function_exists('wdk_generate_other_locations_keys')) {
633 /**
634 * Return array with locations id from listing
635 *
636 * @param int post_id the listings id
637 * @return array locations keys
638 */
639
640 function wdk_generate_other_locations_keys($post_id = NULL) {
641 $WMVC = &wdk_get_instance();
642 $WMVC->model('locationslistings_m');
643 $locations_array = array();
644 $locations = $WMVC->locationslistings_m->get($post_id);
645
646 if($locations) foreach ($locations as $item) {
647 if($item)
648 $locations_array[] = wmvc_show_data('location_id', $item, false, TRUE, TRUE);
649 }
650 return $locations_array;
651 }
652 }
653
654 if(!function_exists('wdk_generate_other_categories_keys')) {
655 /**
656 * Return array with categories id from listing
657 *
658 * @param int post_id the listings id
659 * @return array categories keys
660 */
661
662 function wdk_generate_other_categories_keys($post_id = NULL) {
663 $WMVC = &wdk_get_instance();
664 $WMVC->model('categorieslistings_m');
665 $categories_array = array();
666 $categories = $WMVC->categorieslistings_m->get($post_id);
667
668 if($categories) foreach ($categories as $item) {
669 if($item)
670 $categories_array[] = wmvc_show_data('category_id', $item, false, TRUE, TRUE);
671 }
672 return $categories_array;
673 }
674 }
675
676 if(!function_exists('wdk_generate_other_categories_fast')) {
677 /**
678 * Return array with categories id from listing
679 *
680 * @param string ids list separeted with ','
681 * @return array with categories list
682 */
683
684 function wdk_generate_other_categories_fast($ids = NULL) {
685 static $categories_list = NULL;
686 $categories_array = array();
687
688 if(is_null($categories_list)) {
689 $categories_list = array();
690 $WMVC = &wdk_get_instance();
691 $WMVC->model('category_m');
692 $categories = $WMVC->category_m->get();
693
694 if($categories) foreach ($categories as $item) {
695 $categories_list[$item->idcategory] = $item->category_title;
696 }
697 }
698
699 foreach(explode(',', $ids) as $item_id) {
700 if(empty($item_id)) continue;
701
702
703 if(isset($categories_list[$item_id]))
704 $categories_array[$item_id] = $categories_list[$item_id];
705 }
706
707 return $categories_array;
708 }
709 }
710
711 if(!function_exists('wdk_generate_other_locations_fast')) {
712 /**
713 * Return array with locations id from listing
714 *
715 * @param string ids list separeted with ','
716 * @return array with locations list
717 */
718
719 function wdk_generate_other_locations_fast($ids = NULL) {
720 static $locations_list = NULL;
721 $locations_array = array();
722
723 if(is_null($locations_list)) {
724 $locations_list = array();
725 $WMVC = &wdk_get_instance();
726 $WMVC->model('location_m');
727 $locations = $WMVC->location_m->get();
728
729 if($locations) foreach ($locations as $item) {
730 $locations_list[$item->idlocation] = $item->location_title;
731 }
732 }
733
734 foreach(explode(',', $ids) as $item_id) {
735 if(empty($item_id)) continue;
736
737
738 if(isset($locations_list[$item_id]))
739 $locations_array[$item_id] = $locations_list[$item_id];
740 }
741
742 return $locations_array;
743 }
744 }
745
746
747 if(!function_exists('wdk_field_value_on_type')) {
748 /**
749 * Generate field value, based on type
750 *
751 * @param int|string $field_id field id
752 * @param int|object|array $listing listing object|array or id
753 * @param string $default The default value, will be return if empty or no exists
754 * @return string
755 */
756 function wdk_field_value_on_type ($field_id='', $listing = array(), $default = '') {
757
758 $value = wdk_field_value($field_id, $listing, $default);
759
760 /* filter per type */
761 if(empty($value)) {
762 return $default;
763 }
764
765 if(wdk_field_option($field_id, 'is_price_format') && wdk_field_option($field_id, 'field_type') == 'NUMBER') {
766 $value = number_format_i18n(wdk_filter_decimal($value));
767 } elseif(wdk_field_option($field_id, 'field_type') == 'DATE') {
768 $value = wdk_get_date($value, FALSE);
769 } else {
770 $value = wdk_filter_decimal($value);
771 }
772
773 return $value;
774 }
775 }
776
777 if(!function_exists('wdk_location_get_all_childs')) {
778 /**
779 * Get cached childs of location
780 *
781 * @param int $field_id location id
782 * @return array
783 */
784 function wdk_location_get_all_childs ($field_id='') {
785 static $childs_cache = array();
786 $childs = array();
787 if(isset($childs_cache[$field_id])) {
788 $childs = $childs_cache [$field_id];
789 } else {
790 global $Winter_MVC_WDK;
791 $Winter_MVC_WDK->load_helper('listing');
792 $Winter_MVC_WDK->model('location_m');
793
794 $childs = $Winter_MVC_WDK->location_m->get_all_childs($field_id);
795 if($childs) {
796 $childs_cache [$field_id] = $childs;
797 } else {
798 $childs_cache [$field_id] = $childs;
799 }
800 }
801 return $childs;
802 }
803 }
804
805 if(!function_exists('wdk_category_get_all_childs')) {
806 /**
807 * Get cached childs of category
808 *
809 * @param int $field_id category id
810 * @return array
811 */
812 function wdk_category_get_all_childs ($field_id='') {
813 static $childs_cache = array();
814 $childs = array();
815 if(isset($childs_cache[$field_id])) {
816 $childs = $childs_cache [$field_id];
817 } else {
818 global $Winter_MVC_WDK;
819 $Winter_MVC_WDK->load_helper('listing');
820 $Winter_MVC_WDK->model('category_m');
821
822 $childs = $Winter_MVC_WDK->category_m->get_all_childs($field_id);
823 if($childs) {
824 $childs_cache [$field_id] = $childs;
825 } else {
826 $childs_cache [$field_id] = $childs;
827 }
828 }
829 return $childs;
830 }
831 }
832
833 if(!function_exists('wdk_get_user_data')) {
834 /**
835 * Get user data
836 *
837 * @param int $user id
838 * @return array user data ('userdata'=>$userdata, 'avatar'=>get_avatar_url($user_id),'user_id'=>$user_id);
839 */
840 function wdk_get_user_data ($user_id='') {
841 static $users_cache = array();
842
843 $user = array();
844 if(isset($childs_cache[$user_id])) {
845 $user = $childs_cache [$user_id];
846 } else {
847
848 $userdata = get_userdata($user_id);
849 if($userdata) {
850 $user = array('userdata'=>$userdata, 'avatar'=>get_avatar_url($user_id),'user_id'=>$user_id);
851 }
852
853 if($user) {
854 $users_cache [$user_id] = $user;
855 } else {
856 $users_cache [$user_id] = $user;
857 }
858 }
859 return $user;
860 }
861 }
862
863 if(!function_exists('wdk_get_user_field')) {
864 /**
865 * Get user field
866 *
867 * @param int $user id
868 * @param string $field use field
869 * @param string $default, value if empty or not find user
870 * @return string user field data or default value
871 */
872 function wdk_get_user_field ($user_id='', $field = '', $default = '') {
873 $user_data = wdk_get_user_data ($user_id);
874 $output = $default;
875
876 if(!empty($user_data)) {
877 if(wmvc_show_data($field,$user_data['userdata'], false, TRUE, TRUE)) {
878 $output = wmvc_show_data($field,$user_data['userdata'], false, TRUE, TRUE);
879 }
880 }
881
882 return $output;
883 }
884 }
885