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

1,114 lines 32.9 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 if($image)
144 $output[] = $image[0];
145 }
146 }
147 } else if(is_numeric($image_ids))
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;
152 }
153 return $output;
154 }
155 }
156
157 if(!function_exists('wdk_listing_images_fast_access')) {
158 /**
159 * Initialize the class and set its properties, work only with column listing_images and listing_images_path
160 *
161 * @param int|object|array $listing listing data
162 * @param string $size The size of image
163 * @param string $default The default value, will be return if empty or no exists
164 * @return array
165 */
166 function wdk_listing_images_fast_access ($listing = array(), $size = 'thumb', $default = '') {
167 $output = array();
168 if(!empty(wdk_show_data('listing_images_path', $listing, '', TRUE, TRUE))) {
169 $images = explode(',', wdk_show_data('listing_images_path', $listing, '', TRUE, TRUE));
170 if(is_array($images)) {
171 foreach ($images as $key => $image_path) {
172 $output[] = WP_CONTENT_URL. '/uploads/'.$image_path;
173 }
174 } else {
175 $output[] = WP_CONTENT_URL. '/uploads/'.$images;
176 }
177 } else {
178 $image_ids = explode(',', wdk_show_data('listing_images', $listing, '', TRUE, TRUE));
179 if(is_array($image_ids)) {
180 foreach ($image_ids as $key => $image_id) {
181 if(is_numeric($image_id))
182 {
183 $image = wp_get_attachment_image_src( $image_id, $size );
184 $output[] = $image[0];
185 }
186 }
187 } else if(is_numeric($image_ids)) {
188 $image = wp_get_attachment_image_src( $image_ids, $size );
189 $output[] = $image[0];
190 }
191 }
192
193 return $output;
194 }
195 }
196
197 if(!function_exists('wdk_listing_images_data')) {
198 /**
199 * Initialize the class and set its properties.
200 *
201 * @param string|object|array $listing object or string with ids of images
202 * @param string $size The size of image
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
205 * @return array
206 */
207 function wdk_listing_images_data ($listing = array(), $size = 'thumb', $default = '', $ext_list = array()) {
208 $output = array();
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 }
224 if(is_array($image_ids)) {
225 foreach ($image_ids as $key => $image_id) {
226 if(is_numeric($image_id))
227 {
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']);
239 }
240 }
241 } else if(is_numeric($image_ids))
242 {
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 }
248 }
249 return $output;
250 }
251 }
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
306 if(!function_exists('wdk_image_src')) {
307 /**
308 * Initialize the class and set its properties.
309 *
310 * @param int|object|array $listing listing data
311 * @param string $size The size of image
312 * @param string $default The default value, will be return if empty or no exists
313 * @return string
314 */
315 function wdk_image_src ($listing = array(), $size = 'thumb', $default = '', $field_image = 'listing_images', $field_images_paths = 'listing_images_path') {
316 $output = wdk_placeholder_image_src();
317 if(!empty($default)) {
318 $output = $default;
319 }
320
321 if(!empty(wdk_show_data($field_images_paths, $listing, '', TRUE, TRUE))) {
322 $images = explode(',', wdk_show_data($field_images_paths, $listing, '', TRUE, TRUE));
323
324 if(is_array($images))
325 $image = $images[0];
326
327 if(!empty($image) && file_exists(WP_CONTENT_DIR. '/uploads/'.$image))
328 {
329 $output = WP_CONTENT_URL. '/uploads/'.$image;
330 }
331 } else {
332 $image_ids = explode(',', trim(wdk_show_data($field_image , $listing, '', TRUE, TRUE), ','));
333
334 if(is_array($image_ids))
335 $image_id = $image_ids[0];
336
337 if(is_numeric($image_id) && !empty($image_id) /*&& file_exists(get_attached_file($image_id))*/)
338 {
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]))*/)
341 $output = $image[0];
342 }
343 }
344
345 return $output;
346 }
347 }
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
380 if(!function_exists('wdk_resultitem_fields')) {
381 /**
382 * Initialize the class and set its properties.
383 *
384 * @param int $id The id of the resultitem list.
385 * @return array
386 */
387 function wdk_resultitem_fields($id = 1)
388 {
389 static $fields_data = array();
390 $WMVC = &wdk_get_instance();
391
392 $WMVC->model('resultitem_m');
393 $fields = NULL;
394 if(isset($fields_data[$id])) {
395 return $fields_data[$id];
396 }
397
398 $db_data = wdk_resultitem($id);
399 // generate/decode used fields
400
401 if(is_object($db_data))
402 $fields = json_decode($db_data->resultitem_json);
403
404 $fields_data[$id] = $fields;
405
406 return $fields;
407 }
408 }
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
436 if(!function_exists('wdk_resultitem_fields_section')) {
437 /**
438 * Initialize the class and set its properties.
439 *
440 * @param int $section_index section id
441 * @param int $id The id of the resultitem list.
442 * @return array
443 */
444 function wdk_resultitem_fields_section($section_index=1, $id = 1)
445 {
446 $fields = array();
447 $list = wdk_resultitem_fields($id);
448
449 if(isset($list[$section_index])) {
450 $fields = $list[$section_index];
451 }
452
453 return $fields;
454 }
455 }
456
457 if(!function_exists('wdk_resultitem_fields_section_value')) {
458 /**
459 * Initialize the class and set its properties.
460 *
461 * @param int $id The id of the resultitem list.
462 * @param int $section_index The id of section in resultitem_m
463 * @param int|object|array $listing listing data or listing id
464 * @param string $default Default Value if empty
465
466 * @return array
467 */
468 function wdk_resultitem_fields_section_value($id = 1, $section_index=1, $listing='', $default='')
469 {
470 $output = [];
471 $list = wdk_resultitem_fields_section($section_index, $id);
472 $WMVC = &wdk_get_instance();
473 $WMVC->model('field_m');
474 $WMVC->model('category_m');
475 $WMVC->model('location_m');
476
477 static $category_static = array();
478 static $location_static = array();
479 foreach ($list as $key => $field) {
480 $row = array();
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
490 if(empty($row['value'])) continue;
491
492 if(wmvc_show_data('field_id', $field) == 'category_id') {
493
494 if(!isset($category_static[$row['value']]))
495 {
496 $tree_data = $WMVC->category_m->get($row['value'], TRUE);
497
498 $category_static[$row['value']] = $tree_data;
499 }
500 else
501 {
502 $tree_data = $category_static[$row['value']];
503 }
504
505 $row['field_label'] = esc_html__('Category','wpdirectorykit');
506 $row['value'] = wmvc_show_data('category_title', $tree_data);
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') {
514
515 if(!isset($location_static[$row['value']]))
516 {
517 $tree_data = $WMVC->location_m->get($row['value'], TRUE);
518
519 $location_static[$row['value']] = $tree_data;
520 }
521 else
522 {
523 $tree_data = $location_static[$row['value']];
524 }
525
526 $row['field_label'] = esc_html__('Location','wpdirectorykit');
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
542 }
543
544 $field_data = $WMVC->field_m->get_fields_data($field->field_id);
545 $row += (array) $field;
546 $row += (array) $field_data;
547
548 $output [] = $row;
549 }
550 if(empty($output)) return NULL;
551 return $output;
552 }
553 }
554 if(!function_exists('wdk_generate_resultitem_fields_section_value')) {
555 /**
556 * Initialize the class and set its properties.
557 *
558 * @param int $id The id of the resultitem list.
559 * @param int $section_index The id of section in resultitem_m
560 * @param int|object|array $listing listing object|array or id
561 * @param string $default Default Value if empty
562 * @param string $html Html for sprintf(), where
563 * %1$s - value
564 * %2$s - title
565 * %3$s - prefix
566 * %4$s - suffix
567 * @return array
568 */
569 function wdk_generate_resultitem_fields_section_value($id = 1, $section_index=1, $listing='', $default='', $html =' %3$s %1$s %4$s ')
570 {
571 $output = '';
572 $list = wdk_resultitem_fields_section($section_index, $id);
573 foreach ($list as $key => $field) {
574 $value = wdk_field_value($field->field_id, $listing, $default);
575 if(empty($value)) continue;
576 if(wdk_field_option($field->field_id,'field_type') == 'CHECKBOX') {
577 $html ='<span> %2$s </span>';
578 }
579 $output .= sprintf($html,
580 $value,
581 wdk_field_option($field->field_id,'field_label'),
582 wdk_field_option($field->field_id,'prefix'),
583 wdk_field_option($field->field_id,'suffix')
584 );
585 }
586
587 return trim($output);
588 }
589 }
590
591 if(!function_exists('wdk_listing_card')) {
592 /**
593 * Generate listing card html
594 *
595 * @param array $listing The listing data.
596 * @param array $settings The settings.
597 * @param bool $json_output Encode for json, default false
598 * @param string $html Html for sprintf(), where
599 * %1$s - content
600 * @return string
601 */
602
603 function wdk_listing_card($listing = array(), $settings = array(), $json_output = FALSE, $html_sprintf = '%1$s', $template = 'result_item_card') {
604 $data = ['listing'=>$listing, 'settings'=>$settings];
605
606 $WMVC = &wdk_get_instance();
607
608 /* Favorite module */
609 $data ['favorite_added'] = wmvc_show_data('is_favorite', $listing, false, TRUE, TRUE);
610 /* End Favorite module */
611
612 if(is_intval($template)) {
613 $output = '';
614 $post_data = get_post($template);
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 }
632 $output = sprintf($html_sprintf, $output);
633
634 if($json_output) {
635 $output = str_replace("'", "\'", $output);
636 $output = str_replace('"', '\"', $output);
637 $output = str_replace(array("\n", "\r"), '', $output);
638 }
639
640 return $output;
641 }
642 }
643
644 if(!function_exists('wdk_image_alt')) {
645 /**
646 * Generate alt tag
647 *
648 * @param string|int $link|id The url or id of image.
649 * @return string alt or title
650 */
651
652 function wdk_image_alt($link_id = '') {
653 $alt = '';
654
655 if(is_intval($link_id)) {
656 $attached_id = $link_id;
657 } else {
658 $attached_id = attachment_url_to_postid($link_id);
659 }
660
661 $alt = get_post_meta($attached_id, '_wp_attachment_image_alt', true);
662 if($alt == '') {
663 $alt = get_the_title($attached_id);
664 }
665
666 return $alt;
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 }
1113 }
1114