PluginProbe
WP Directory Kit / 1.3.4
WP Directory Kit v1.3.4
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.3.4, at application/helpers/Listing.php

1,032 lines 30.1 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_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
114 if(!function_exists('wdk_listing_images')) {
115 /**
116 * Initialize the class and set its properties.
117 *
118 * @param string|object|array $listing object or string with ids of images
119 * @param string $size The size of image
120 * @param string $default The default value, will be return if empty or no exists
121 * @return array
122 */
123 function wdk_listing_images ($listing = array(), $size = 'thumb', $default = '') {
124 $output = array();
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
132 if(is_array($image_ids)) {
133 foreach ($image_ids as $key => $image_id) {
134 if(is_numeric($image_id))
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 */
142 $image = wp_get_attachment_image_src( $image_id, $size );
143 $output[] = $image[0];
144 }
145 }
146 } else if(is_numeric($image_ids))
147 {
148 do_action('wdk/helpers/wdk_listing_images/get_attached/before', $image_ids, $size);
149 $image = wp_get_attachment_url( $image_ids, $size );
150 $output[] = $image;
151 }
152 return $output;
153 }
154 }
155
156 if(!function_exists('wdk_listing_images_fast_access')) {
157 /**
158 * Initialize the class and set its properties, work only with column listing_images and listing_images_path
159 *
160 * @param int|object|array $listing listing data
161 * @param string $size The size of image
162 * @param string $default The default value, will be return if empty or no exists
163 * @return array
164 */
165 function wdk_listing_images_fast_access ($listing = array(), $size = 'thumb', $default = '') {
166 $output = array();
167 if(!empty(wdk_show_data('listing_images_path', $listing, '', TRUE, TRUE))) {
168 $images = explode(',', wdk_show_data('listing_images_path', $listing, '', TRUE, TRUE));
169 if(is_array($images)) {
170 foreach ($images as $key => $image_path) {
171 $output[] = WP_CONTENT_URL. '/uploads/'.$image_path;
172 }
173 } else {
174 $output[] = WP_CONTENT_URL. '/uploads/'.$images;
175 }
176 } else {
177 $image_ids = explode(',', wdk_show_data('listing_images', $listing, '', TRUE, TRUE));
178 if(is_array($image_ids)) {
179 foreach ($image_ids as $key => $image_id) {
180 if(is_numeric($image_id))
181 {
182 $image = wp_get_attachment_image_src( $image_id, $size );
183 $output[] = $image[0];
184 }
185 }
186 } else if(is_numeric($image_ids)) {
187 $image = wp_get_attachment_image_src( $image_ids, $size );
188 $output[] = $image[0];
189 }
190 }
191
192 return $output;
193 }
194 }
195
196 if(!function_exists('wdk_listing_images_data')) {
197 /**
198 * Initialize the class and set its properties.
199 *
200 * @param string|object|array $listing object or string with ids of images
201 * @param string $size The size of image
202 * @param string $default The default value, will be return if empty or no exists
203 * @param string|array $ext_list Allowed extensions, mixed sring with separated like jpg,doc,pdf or array
204 * @return array
205 */
206 function wdk_listing_images_data ($listing = array(), $size = 'thumb', $default = '', $ext_list = array()) {
207 $output = array();
208
209 $image_ids = '';
210 if(is_array($listing) || is_object($listing)) {
211 $image_ids = explode(',', wdk_show_data('listing_images', $listing, '', TRUE, TRUE));
212 } else if(is_string($listing)){
213 $image_ids = explode(',', $listing);
214 }
215
216 if(is_string($ext_list)){
217 if(!empty($ext_list)) {
218 $ext_list = explode(',', $ext_list);
219 } else {
220 $ext_list = array();
221 }
222 }
223 if(is_array($image_ids)) {
224 foreach ($image_ids as $key => $image_id) {
225 if(is_numeric($image_id))
226 {
227 $image = wp_get_attachment_url( $image_id, $size );
228 if(!empty($ext_list) && !in_array(wdk_file_extension($image), $ext_list)) {
229 continue;
230 }
231
232 if(empty($image)/* || !file_exists(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $image))*/)
233 {
234 $image = wdk_placeholder_image_src();
235 }
236 $attr = wdk_image_attr($image_id);
237 $output[] = array('src' =>$image, 'title' => $attr['title'], 'alt' => $attr['alt']);
238 }
239 }
240 } else if(is_numeric($image_ids))
241 {
242 $image = wp_get_attachment_url( $image_ids, $size );
243 if(!empty($ext_list) && !in_array(wdk_file_extension($image), $ext_list)) {
244 $attr = wdk_image_attr($image_ids);
245 $output[] = array('src' =>$image, 'title' => $attr['title'], 'alt' => $attr['alt']);
246 }
247 }
248 return $output;
249 }
250 }
251
252 if(!function_exists('wdk_image_src')) {
253 /**
254 * Initialize the class and set its properties.
255 *
256 * @param int|object|array $listing listing data
257 * @param string $size The size of image
258 * @param string $default The default value, will be return if empty or no exists
259 * @return string
260 */
261 function wdk_image_src ($listing = array(), $size = 'thumb', $default = '', $field_image = 'listing_images', $field_images_paths = 'listing_images_path') {
262 $output = wdk_placeholder_image_src();
263 if(!empty($default)) {
264 $output = $default;
265 }
266
267 if(!empty(wdk_show_data($field_images_paths, $listing, '', TRUE, TRUE))) {
268 $images = explode(',', wdk_show_data($field_images_paths, $listing, '', TRUE, TRUE));
269
270 if(is_array($images))
271 $image = $images[0];
272
273 if(!empty($image) && file_exists(WP_CONTENT_DIR. '/uploads/'.$image))
274 {
275 $output = WP_CONTENT_URL. '/uploads/'.$image;
276 }
277 } else {
278 $image_ids = explode(',', trim(wdk_show_data($field_image , $listing, '', TRUE, TRUE), ','));
279
280 if(is_array($image_ids))
281 $image_id = $image_ids[0];
282
283 if(is_numeric($image_id) && !empty($image_id) /*&& file_exists(get_attached_file($image_id))*/)
284 {
285 $image = wp_get_attachment_image_src( $image_id, 'full' );
286 if(!empty($image)/* && file_exists(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR,$image[0]))*/)
287 $output = $image[0];
288 }
289 }
290
291 return $output;
292 }
293 }
294
295 if(!function_exists('wdk_listing_media_src')) {
296 /**
297 * Initialize the class and set its properties.
298 *
299 * @param int|object|array $listing listing data
300 * @param string $default The default value, will be return if empty or no exists
301 * @return string
302 */
303 function wdk_listing_media_src ($listing = array(), $default = '', $field_image = 'listing_images') {
304 $output = wdk_placeholder_image_src();
305 if(!empty($default)) {
306 $output = $default;
307 }
308
309 $image_ids = explode(',', trim(wdk_show_data($field_image , $listing, '', TRUE, TRUE), ','));
310
311 if(is_array($image_ids))
312 $image_id = $image_ids[0];
313
314 if(is_numeric($image_id) && !empty($image_id) /*&& file_exists(get_attached_file($image_id))*/)
315 {
316 $image = wp_get_attachment_url( $image_id);
317 if(!empty($image)/* && file_exists(str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $image))*/)
318 $output = $image;
319 }
320
321 return $output;
322 }
323 }
324
325
326 if(!function_exists('wdk_resultitem_fields')) {
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_fields($id = 1)
334 {
335 static $fields_data = array();
336 $WMVC = &wdk_get_instance();
337
338 $WMVC->model('resultitem_m');
339 $fields = NULL;
340 if(isset($fields_data[$id])) {
341 return $fields_data[$id];
342 }
343
344 $db_data = wdk_resultitem($id);
345 // generate/decode used fields
346
347 if(is_object($db_data))
348 $fields = json_decode($db_data->resultitem_json);
349
350 $fields_data[$id] = $fields;
351
352 return $fields;
353 }
354 }
355
356 if(!function_exists('wdk_resultitem')) {
357 /**
358 * Initialize the class and set its properties.
359 *
360 * @param int $id The id of the resultitem list.
361 * @return array
362 */
363 function wdk_resultitem($id = 1)
364 {
365 static $fields_data = array();
366 $WMVC = &wdk_get_instance();
367
368 $WMVC->model('resultitem_m');
369 $db_data = NULL;
370 if(isset($fields_data[$id])) {
371 return $fields_data[$id];
372 }
373
374 $db_data = $WMVC->resultitem_m->get($id, TRUE);
375
376 $fields_data[$id] = $db_data;
377
378 return $db_data;
379 }
380 }
381
382 if(!function_exists('wdk_resultitem_fields_section')) {
383 /**
384 * Initialize the class and set its properties.
385 *
386 * @param int $section_index section id
387 * @param int $id The id of the resultitem list.
388 * @return array
389 */
390 function wdk_resultitem_fields_section($section_index=1, $id = 1)
391 {
392 $fields = array();
393 $list = wdk_resultitem_fields($id);
394
395 if(isset($list[$section_index])) {
396 $fields = $list[$section_index];
397 }
398
399 return $fields;
400 }
401 }
402
403 if(!function_exists('wdk_resultitem_fields_section_value')) {
404 /**
405 * Initialize the class and set its properties.
406 *
407 * @param int $id The id of the resultitem list.
408 * @param int $section_index The id of section in resultitem_m
409 * @param int|object|array $listing listing data or listing id
410 * @param string $default Default Value if empty
411
412 * @return array
413 */
414 function wdk_resultitem_fields_section_value($id = 1, $section_index=1, $listing='', $default='')
415 {
416 $output = [];
417 $list = wdk_resultitem_fields_section($section_index, $id);
418 $WMVC = &wdk_get_instance();
419 $WMVC->model('field_m');
420 $WMVC->model('category_m');
421 $WMVC->model('location_m');
422
423 static $category_static = array();
424 static $location_static = array();
425 foreach ($list as $key => $field) {
426 $row = array();
427 $row['value'] = wdk_field_value($field->field_id, $listing, $default);
428
429 if(wmvc_show_data('field_id', $field) == 'agent_image') {
430 $row['value'] = wmvc_show_data('user_id_editor', $listing);
431 }
432
433 if(empty($row['value']) && !empty(wdk_field_option($field->field_id,'empty_value', false)))
434 $row['value'] = wdk_field_option($field->field_id,'empty_value');
435
436 if(empty($row['value'])) continue;
437
438 if(wmvc_show_data('field_id', $field) == 'category_id') {
439
440 if(!isset($category_static[$row['value']]))
441 {
442 $tree_data = $WMVC->category_m->get($row['value'], TRUE);
443
444 $category_static[$row['value']] = $tree_data;
445 }
446 else
447 {
448 $tree_data = $category_static[$row['value']];
449 }
450
451 $row['value'] = wmvc_show_data('category_title', $tree_data);
452
453 if(isset($listing->categories_list)){
454 $other_categories = wdk_generate_other_categories_fast($listing->categories_list);
455 if(!empty($other_categories))
456 $row['value'] .=', '.join(', ',$other_categories);
457 }
458 } else if(wmvc_show_data('field_id', $field) == 'location_id') {
459
460 if(!isset($location_static[$row['value']]))
461 {
462 $tree_data = $WMVC->location_m->get($row['value'], TRUE);
463
464 $location_static[$row['value']] = $tree_data;
465 }
466 else
467 {
468 $tree_data = $location_static[$row['value']];
469 }
470
471 $row['value'] = wmvc_show_data('location_title', $tree_data);
472
473 if(isset($listing->locations_list)){
474 $other_locations = wdk_generate_other_locations_fast($listing->locations_list);
475 if(!empty($other_locations))
476 $row['value'] .=', '.join(', ',$other_locations);
477 }
478 } else if(wdk_field_option($field->field_id, 'field_type') == 'DATE') {
479 $row['value'] = wdk_generate_field_date($field->field_id, $listing);
480 } else {
481
482 }
483
484 $field_data = $WMVC->field_m->get_fields_data($field->field_id);
485 $row += (array) $field;
486 $row += (array) $field_data;
487
488 $output [] = $row;
489 }
490 if(empty($output)) return NULL;
491 return $output;
492 }
493 }
494 if(!function_exists('wdk_generate_resultitem_fields_section_value')) {
495 /**
496 * Initialize the class and set its properties.
497 *
498 * @param int $id The id of the resultitem list.
499 * @param int $section_index The id of section in resultitem_m
500 * @param int|object|array $listing listing object|array or id
501 * @param string $default Default Value if empty
502 * @param string $html Html for sprintf(), where
503 * %1$s - value
504 * %2$s - title
505 * %3$s - prefix
506 * %4$s - suffix
507 * @return array
508 */
509 function wdk_generate_resultitem_fields_section_value($id = 1, $section_index=1, $listing='', $default='', $html =' %3$s %1$s %4$s ')
510 {
511 $output = '';
512 $list = wdk_resultitem_fields_section($section_index, $id);
513 foreach ($list as $key => $field) {
514 $value = wdk_field_value($field->field_id, $listing, $default);
515 if(empty($value)) continue;
516 if(wdk_field_option($field->field_id,'field_type') == 'CHECKBOX') {
517 $html ='<span> %2$s </span>';
518 }
519 $output .= sprintf($html,
520 $value,
521 wdk_field_option($field->field_id,'field_label'),
522 wdk_field_option($field->field_id,'prefix'),
523 wdk_field_option($field->field_id,'suffix')
524 );
525 }
526
527 return trim($output);
528 }
529 }
530
531 if(!function_exists('wdk_listing_card')) {
532 /**
533 * Generate listing card html
534 *
535 * @param array $listing The listing data.
536 * @param array $settings The settings.
537 * @param bool $json_output Encode for json, default false
538 * @param string $html Html for sprintf(), where
539 * %1$s - content
540 * @return string
541 */
542
543 function wdk_listing_card($listing = array(), $settings = array(), $json_output = FALSE, $html_sprintf = '%1$s', $template = 'result_item_card') {
544 $data = ['listing'=>$listing, 'settings'=>$settings];
545
546 $WMVC = &wdk_get_instance();
547
548 /* Favorite module */
549 $data ['favorite_added'] = wmvc_show_data('is_favorite', $listing, false, TRUE, TRUE);
550 /* End Favorite module */
551
552 $output = $WMVC->view('frontend/'.$template, $data, FALSE);
553
554 $output = sprintf($html_sprintf, $output);
555 if($json_output) {
556 $output = str_replace("'", "\'", $output);
557 $output = str_replace('"', '\"', $output);
558 $output = str_replace(array("\n", "\r"), '', $output);
559 }
560
561 return ($output);
562 }
563 }
564
565 if(!function_exists('wdk_image_alt')) {
566 /**
567 * Generate alt tag
568 *
569 * @param string|int $link|id The url or id of image.
570 * @return string alt or title
571 */
572
573 function wdk_image_alt($link_id = '') {
574 $alt = '';
575
576 if(is_intval($link_id)) {
577 $attached_id = $link_id;
578 } else {
579 $attached_id = attachment_url_to_postid($link_id);
580 }
581
582 $alt = get_post_meta($attached_id, '_wp_attachment_image_alt', true);
583 if($alt == '') {
584 $alt = get_the_title($attached_id);
585 }
586
587 return $alt;
588 }
589 }
590
591 if(!function_exists('wdk_image_attr')) {
592 /**
593 * Generate array with alt and title, if alt missing, return title like alt
594 *
595 * @param string|int $link|id The url or id of image.
596 * @return array alt and title
597 */
598
599 function wdk_image_attr($link_id = '') {
600 $alt = '';
601 $title = '';
602
603 if(is_intval($link_id)) {
604 $attached_id = $link_id;
605 } else {
606 $attached_id = attachment_url_to_postid($link_id);
607 }
608
609 $alt = get_post_meta($attached_id, '_wp_attachment_image_alt', true);
610 $title = get_the_title($attached_id);
611 if($alt == '') {
612 $alt = $title;
613 }
614
615 return array('title'=>$title, 'alt'=>$alt);
616 }
617 }
618
619
620
621 if(!function_exists('wdk_generate_other_locations')) {
622 /**
623 * Return array with locations id from listing
624 *
625 * @param int post_id the listings id
626 * @return array locations
627 */
628
629 function wdk_generate_other_locations($post_id = NULL) {
630 $WMVC = &wdk_get_instance();
631 $WMVC->model('locationslistings_m');
632 $locations_array = array();
633 $locations = $WMVC->locationslistings_m->get_locations($post_id);
634
635 if($locations) foreach ($locations as $item) {
636 if($item)
637 $locations_array[wmvc_show_data('idlocation', $item, false, TRUE, TRUE)] = wmvc_show_data('location_title', $item, false, TRUE, TRUE);
638 }
639 return $locations_array;
640 }
641 }
642
643 if(!function_exists('wdk_generate_other_categories')) {
644 /**
645 * Return array with categories id from listing
646 *
647 * @param int post_id the listings id
648 * @return array categories
649 */
650
651 function wdk_generate_other_categories($post_id = NULL) {
652 $WMVC = &wdk_get_instance();
653 $WMVC->model('categorieslistings_m');
654 $categories_array = array();
655 $categories = $WMVC->categorieslistings_m->get_categories($post_id);
656
657 if($categories) foreach ($categories as $item) {
658 if($item)
659 $categories_array[wmvc_show_data('idcategory', $item, false, TRUE, TRUE)] = wmvc_show_data('category_title', $item, false, TRUE, TRUE);
660 }
661 return $categories_array;
662 }
663 }
664
665 if(!function_exists('wdk_generate_other_locations_keys')) {
666 /**
667 * Return array with locations id from listing
668 *
669 * @param int post_id the listings id
670 * @return array locations keys
671 */
672
673 function wdk_generate_other_locations_keys($post_id = NULL) {
674 $WMVC = &wdk_get_instance();
675 $WMVC->model('locationslistings_m');
676 $locations_array = array();
677 $locations = $WMVC->locationslistings_m->get($post_id);
678
679 if($locations) foreach ($locations as $item) {
680 if($item)
681 $locations_array[] = wmvc_show_data('location_id', $item, false, TRUE, TRUE);
682 }
683 return $locations_array;
684 }
685 }
686
687 if(!function_exists('wdk_generate_other_categories_keys')) {
688 /**
689 * Return array with categories id from listing
690 *
691 * @param int post_id the listings id
692 * @return array categories keys
693 */
694
695 function wdk_generate_other_categories_keys($post_id = NULL) {
696 $WMVC = &wdk_get_instance();
697 $WMVC->model('categorieslistings_m');
698 $categories_array = array();
699 $categories = $WMVC->categorieslistings_m->get($post_id);
700
701 if($categories) foreach ($categories as $item) {
702 if($item)
703 $categories_array[] = wmvc_show_data('category_id', $item, false, TRUE, TRUE);
704 }
705 return $categories_array;
706 }
707 }
708
709 if(!function_exists('wdk_generate_other_categories_fast')) {
710 /**
711 * Return array with categories id from listing
712 *
713 * @param string ids list separeted with ','
714 * @return array with categories list
715 */
716
717 function wdk_generate_other_categories_fast($ids = NULL) {
718 static $categories_list = NULL;
719 $categories_array = array();
720
721 if(is_null($categories_list)) {
722 $categories_list = array();
723 $WMVC = &wdk_get_instance();
724 $WMVC->model('category_m');
725 $categories = $WMVC->category_m->get();
726
727 if($categories) foreach ($categories as $item) {
728 $categories_list[$item->idcategory] = $item->category_title;
729 }
730 }
731
732 if(is_string($ids))
733 foreach(explode(',', $ids) as $item_id) {
734 if(empty($item_id)) continue;
735
736
737 if(isset($categories_list[$item_id]))
738 $categories_array[$item_id] = $categories_list[$item_id];
739 }
740
741 return $categories_array;
742 }
743 }
744
745 if(!function_exists('wdk_generate_other_locations_fast')) {
746 /**
747 * Return array with locations id from listing
748 *
749 * @param string ids list separeted with ','
750 * @return array with locations list
751 */
752
753 function wdk_generate_other_locations_fast($ids = NULL) {
754 static $locations_list = NULL;
755 $locations_array = array();
756
757 if(is_null($locations_list)) {
758 $locations_list = array();
759 $WMVC = &wdk_get_instance();
760 $WMVC->model('location_m');
761 $locations = $WMVC->location_m->get();
762
763 if($locations) foreach ($locations as $item) {
764 $locations_list[$item->idlocation] = $item->location_title;
765 }
766 }
767
768 if(is_string($ids))
769 foreach(explode(',', $ids) as $item_id) {
770 if(empty($item_id)) continue;
771
772
773 if(isset($locations_list[$item_id]))
774 $locations_array[$item_id] = $locations_list[$item_id];
775 }
776
777 return $locations_array;
778 }
779 }
780
781
782 if(!function_exists('wdk_field_value_on_type')) {
783 /**
784 * Generate field value, based on type
785 *
786 * @param int|string $field_id field id
787 * @param int|object|array $listing listing object|array or id
788 * @param string $default The default value, will be return if empty or no exists
789 * @return string
790 */
791 function wdk_field_value_on_type ($field_id='', $listing = array(), $default = '') {
792
793 $value = wdk_field_value($field_id, $listing, $default);
794
795 /* filter per type */
796 if(empty($value)) {
797 return $default;
798 }
799
800 if(wdk_field_option($field_id, 'is_price_format') && wdk_field_option($field_id, 'field_type') == 'NUMBER') {
801 $value = wdk_number_format_i18n(wdk_filter_decimal($value));
802 } elseif(wdk_field_option($field_id, 'field_type') == 'DATE') {
803 $value = wdk_get_date($value, FALSE);
804 } else {
805 $value = wdk_filter_decimal($value);
806 }
807
808 return $value;
809 }
810 }
811
812 if(!function_exists('wdk_location_get_all_childs')) {
813 /**
814 * Get cached childs of location
815 *
816 * @param int $field_id location id
817 * @return array
818 */
819 function wdk_location_get_all_childs ($field_id='') {
820 static $childs_cache = array();
821 $childs = array();
822 if(isset($childs_cache[$field_id])) {
823 $childs = $childs_cache [$field_id];
824 } else {
825 global $Winter_MVC_WDK;
826 $Winter_MVC_WDK->load_helper('listing');
827 $Winter_MVC_WDK->model('location_m');
828
829 $childs = $Winter_MVC_WDK->location_m->get_all_childs($field_id);
830 if($childs) {
831 $childs_cache [$field_id] = $childs;
832 } else {
833 $childs_cache [$field_id] = $childs;
834 }
835 }
836 return $childs;
837 }
838 }
839
840 if(!function_exists('wdk_category_get_all_childs')) {
841 /**
842 * Get cached childs of category
843 *
844 * @param int $field_id category id
845 * @return array
846 */
847 function wdk_category_get_all_childs ($field_id='') {
848 static $childs_cache = array();
849 $childs = array();
850 if(isset($childs_cache[$field_id])) {
851 $childs = $childs_cache [$field_id];
852 } else {
853 global $Winter_MVC_WDK;
854 $Winter_MVC_WDK->load_helper('listing');
855 $Winter_MVC_WDK->model('category_m');
856
857 $childs = $Winter_MVC_WDK->category_m->get_all_childs($field_id);
858 if($childs) {
859 $childs_cache [$field_id] = $childs;
860 } else {
861 $childs_cache [$field_id] = $childs;
862 }
863 }
864 return $childs;
865 }
866 }
867
868 if(!function_exists('wdk_get_user_data')) {
869 /**
870 * Get user data
871 *
872 * @param int $user id
873 * @return array user data ('userdata'=>$userdata, 'avatar'=>get_avatar_url($user_id),'user_id'=>$user_id, 'profile_url'=>'url on profile');
874 */
875 function wdk_get_user_data ($user_id='') {
876 static $users_cache = array();
877
878 $user = array();
879 if(isset($users_cache[$user_id])) {
880 $user = $users_cache [$user_id];
881 } else {
882
883 $userdata = get_userdata($user_id);
884 if($userdata) {
885 $user = array('userdata'=>$userdata, 'avatar'=>get_avatar_url($user_id, array("size"=>300)),'user_id'=>$user_id);
886 $user['profile_url'] =NULL;
887
888 if(function_exists('wdk_generate_profile_permalink'))
889 $user['profile_url'] = wdk_generate_profile_permalink($userdata);
890 }
891
892 if($user) {
893 $users_cache [$user_id] = $user;
894 } else {
895 $users_cache [$user_id] = $user;
896 }
897 }
898 return $user;
899 }
900 }
901
902 if(!function_exists('wdk_get_user_field')) {
903 /**
904 * Get user field
905 *
906 * @param int $user id
907 * @param string $field use field
908 * @param string $default, value if empty or not find user
909 * @return string|array user field data or default value
910 */
911 function wdk_get_user_field ($user_id='', $field = '', $default = '') {
912 $user_data = wdk_get_user_data ($user_id);
913 $output = $default;
914
915 if(!empty($user_data)) {
916 if(wmvc_show_data($field,$user_data['userdata'], false, TRUE, TRUE)) {
917 $output = wmvc_show_data($field,$user_data['userdata'], false, TRUE, TRUE);
918 }
919 }
920
921 return $output;
922 }
923 }
924
925 if(!function_exists('wdk_get_category_title')) {
926 /**
927 * Get user field
928 *
929 * @param int $user id
930 * @param string $field use field
931 * @param string $default, value if empty or not find user
932 * @return string|array user field data or default value
933 */
934 function wdk_get_category_title ($category_id='', $empty = false) {
935 $output = $empty;
936 $category = wdk_generate_other_categories_fast($category_id);
937
938 if(!empty($category)) {
939 $output = $category[$category_id];
940 }
941
942 return $output;
943 }
944 }
945
946 if(!function_exists('wdk_get_location_title')) {
947 /**
948 * Get user field
949 *
950 * @param int $user id
951 * @param string $field use field
952 * @param string $default, value if empty or not find user
953 * @return string|array user field data or default value
954 */
955 function wdk_get_location_title ($location_id='', $empty = false) {
956 $output = $empty;
957 $location = wdk_generate_other_locations_fast($location_id);
958
959 if(!empty($location)) {
960 $output = $location[$location_id];
961 }
962
963 return $output;
964 }
965 }
966
967 if(!function_exists('wdk_get_category_id')) {
968 /**
969 * Get Category id by category name
970 *
971 * @param int $category_name category name
972 * @param string $empty, value if empty or not find
973 * @return string category_id
974 */
975 function wdk_get_category_id ($category_name='', $empty = false) {
976 $output = $empty;
977 $category_name = trim($category_name);
978 static $categories_list = NULL;
979
980 if(is_null($categories_list)) {
981 $categories_list = array();
982 $WMVC = &wdk_get_instance();
983 $WMVC->model('category_m');
984 $categories = $WMVC->category_m->get();
985
986 if($categories) foreach ($categories as $item) {
987 $categories_list[$item->idcategory] = $item->category_title;
988 }
989 }
990
991 $key = array_search($category_name, $categories_list);
992 if($key) {
993 $output = $key;
994 }
995 return $output;
996 }
997 }
998
999 if(!function_exists('wdk_get_location_id')) {
1000 /**
1001 * Get Location id by location name
1002 *
1003 * @param int $location_name location name
1004 * @param string $empty, value if empty or not find
1005 * @return string location_id
1006 */
1007 function wdk_get_location_id ($location_name='', $empty = false) {
1008 $output = $empty;
1009 $location_name = trim($location_name);
1010
1011 static $locations_list = NULL;
1012
1013 if(is_null($locations_list)) {
1014 $locations_list = array();
1015 $WMVC = &wdk_get_instance();
1016 $WMVC->model('location_m');
1017 $locations = $WMVC->location_m->get();
1018
1019 if($locations) foreach ($locations as $item) {
1020 $locations_list[$item->idlocation] = $item->location_title;
1021 }
1022 }
1023
1024 $key = array_search($location_name, $locations_list);
1025 if($key) {
1026 $output = $key;
1027 }
1028
1029 return $output;
1030 }
1031 }
1032