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

461 lines 14.0 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 The name of this plugin.
56 * @param int|object|array $listing The name of this plugin.
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 int|object|array $listing The name of this plugin.
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 = explode(',', wdk_show_data('listing_images', $listing, '', TRUE, TRUE));
103 if(is_array($image_ids)) {
104 foreach ($image_ids as $key => $image_id) {
105 if(is_numeric($image_id))
106 {
107 $image = wp_get_attachment_image_src( $image_id, $size );
108 $output[] = $image[0];
109 }
110 }
111 } else if(is_numeric($image_ids))
112 {
113 $image = wp_get_attachment_image_src( $image_ids, $size );
114 $output[] = $image[0];
115 }
116 return $output;
117 }
118 }
119
120 if(!function_exists('wdk_listing_images_fast_access')) {
121 /**
122 * Initialize the class and set its properties.
123 *
124 * @param int|object|array $listing The name of this plugin.
125 * @param string $size The size of image
126 * @param string $default The default value, will be return if empty or no exists
127 * @return array
128 */
129 function wdk_listing_images_fast_access ($listing = array(), $size = 'thumb', $default = '') {
130 $output = array();
131 if(!empty(wdk_show_data('listing_images_path', $listing, '', TRUE, TRUE))) {
132 $images = explode(',', wdk_show_data('listing_images_path', $listing, '', TRUE, TRUE));
133 if(is_array($images)) {
134 foreach ($images as $key => $image_path) {
135 $output[] = WP_CONTENT_URL. '/uploads/'.$image_path;
136 }
137 } else {
138 $output[] = WP_CONTENT_URL. '/uploads/'.$images;
139 }
140 } else {
141 $image_ids = explode(',', wdk_show_data('listing_images', $listing, '', TRUE, TRUE));
142 if(is_array($image_ids)) {
143 foreach ($image_ids as $key => $image_id) {
144 if(is_numeric($image_id))
145 {
146 $image = wp_get_attachment_image_src( $image_id, $size );
147 $output[] = $image[0];
148 }
149 }
150 } else if(is_numeric($image_ids)) {
151 $image = wp_get_attachment_image_src( $image_ids, $size );
152 $output[] = $image[0];
153 }
154 }
155
156 return $output;
157 }
158 }
159
160 if(!function_exists('wdk_listing_images_data')) {
161 /**
162 * Initialize the class and set its properties.
163 *
164 * @param int|object|array $listing The name of this plugin.
165 * @param string $size The size of image
166 * @param string $default The default value, will be return if empty or no exists
167 * @return array
168 */
169 function wdk_listing_images_data ($listing = array(), $size = 'thumb', $default = '') {
170 $output = array();
171 $image_ids = explode(',', wmvc_show_data('listing_images', $listing, ''));
172 if(is_array($image_ids)) {
173 foreach ($image_ids as $key => $image_id) {
174 if(is_numeric($image_id))
175 {
176 $image = wp_get_attachment_image_src( $image_id, $size );
177 $output[] = array('src' =>$image[0], 'alt' => wdk_image_alt($image_id));
178 }
179 }
180 } else if(is_numeric($image_ids))
181 {
182 $image = wp_get_attachment_image_src( $image_ids, $size );
183 $output[] = array('src' =>$image[0], 'alt' => wdk_image_alt($image_ids));
184 }
185 return $output;
186 }
187 }
188
189 if(!function_exists('wdk_image_src')) {
190 /**
191 * Initialize the class and set its properties.
192 *
193 * @param int|object|array $listing The name of this plugin.
194 * @param string $size The size of image
195 * @param string $default The default value, will be return if empty or no exists
196 * @return string
197 */
198 function wdk_image_src ($listing = array(), $size = 'thumb', $default = '', $field_image = 'listing_images', $field_images_paths = 'listing_images_path') {
199 $output = wdk_placeholder_image_src();
200 if(!empty($default)) {
201 $output = $default;
202 }
203
204 if(!empty(wdk_show_data($field_images_paths, $listing, '', TRUE, TRUE))) {
205 $images = explode(',', wdk_show_data($field_images_paths, $listing, '', TRUE, TRUE));
206
207 if(is_array($images))
208 $image = $images[0];
209
210 if(!empty($image))
211 {
212 $output = WP_CONTENT_URL. '/uploads/'.$image;
213 }
214 } else {
215 $image_ids = explode(',', trim(wdk_show_data($field_image , $listing, '', TRUE, TRUE), ','));
216
217 if(is_array($image_ids))
218 $image_id = $image_ids[0];
219
220 if(is_numeric($image_id) && !empty($image_id) /*&& file_exists(get_attached_file($image_id))*/)
221 {
222 $image = wp_get_attachment_image_src( $image_id, $size );
223
224 if(!empty($image))
225 $output = $image[0];
226 }
227 }
228
229 return $output;
230 }
231 }
232
233 if(!function_exists('wdk_resultitem_fields')) {
234 /**
235 * Initialize the class and set its properties.
236 *
237 * @param int $id The id of the resultitem list.
238 * @return array
239 */
240 function wdk_resultitem_fields($id = 1)
241 {
242 static $fields_data = array();
243 $WMVC = &wdk_get_instance();
244
245 $WMVC->model('resultitem_m');
246 $fields = NULL;
247 if(isset($fields_data[$id])) {
248 return $fields_data[$id];
249 }
250
251 $db_data = $WMVC->resultitem_m->get($id, TRUE);
252 // generate/decode used fields
253
254 if(is_object($db_data))
255 $fields = json_decode($db_data->resultitem_json);
256
257 $fields_data[$id] = $fields;
258
259 return $fields;
260 }
261 }
262
263 if(!function_exists('wdk_resultitem_fields_section')) {
264 /**
265 * Initialize the class and set its properties.
266 *
267 * @param int $section_index The name of this plugin.
268 * @param int $id The id of the resultitem list.
269 * @return array
270 */
271 function wdk_resultitem_fields_section($section_index=1, $id = 1)
272 {
273 $fields = array();
274 $list = wdk_resultitem_fields($id);
275
276 if(isset($list[$section_index])) {
277 $fields = $list[$section_index];
278 }
279
280 return $fields;
281 }
282 }
283
284 if(!function_exists('wdk_resultitem_fields_section_value')) {
285 /**
286 * Initialize the class and set its properties.
287 *
288 * @param int $id The id of the resultitem list.
289 * @param int $section_index The id of section in resultitem_m
290 * @param int|object|array $listing The name of this plugin.
291 * @param string $default Default Value if empty
292
293 * @return array
294 */
295 function wdk_resultitem_fields_section_value($id = 1, $section_index=1, $listing='', $default='')
296 {
297 $output = [];
298 $list = wdk_resultitem_fields_section($section_index, $id);
299 $WMVC = &wdk_get_instance();
300 $WMVC->model('field_m');
301 $WMVC->model('category_m');
302 $WMVC->model('location_m');
303
304 static $category_static = array();
305 static $location_static = array();
306
307 foreach ($list as $key => $field) {
308 $row = array();
309 $row['value'] = wdk_field_value($field->field_id, $listing, $default);
310 if(empty($row['value'])) continue;
311
312 if(wmvc_show_data('field_id', $field) == 'category_id') {
313
314 if(!isset($category_static[$row['value']]))
315 {
316 $tree_data = $WMVC->category_m->get($row['value'], TRUE);
317
318 $category_static[$row['value']] = $tree_data;
319 }
320 else
321 {
322 $tree_data = $category_static[$row['value']];
323 }
324
325 $row['value'] = wmvc_show_data('category_title', $tree_data);
326 }
327
328 if(wmvc_show_data('field_id', $field) == 'location_id') {
329
330 if(!isset($location_static[$row['value']]))
331 {
332 $tree_data = $WMVC->location_m->get($row['value'], TRUE);
333
334 $location_static[$row['value']] = $tree_data;
335 }
336 else
337 {
338 $tree_data = $location_static[$row['value']];
339 }
340
341 $row['value'] = wmvc_show_data('location_title', $tree_data);
342 }
343
344 $field_data = $WMVC->field_m->get_fields_data($field->field_id);
345 $row += (array) $field;
346 $row += (array) $field_data;
347
348 $output [] = $row;
349 }
350 if(empty($output)) return NULL;
351 return $output;
352 }
353 }
354 if(!function_exists('wdk_generate_resultitem_fields_section_value')) {
355 /**
356 * Initialize the class and set its properties.
357 *
358 * @param int $id The id of the resultitem list.
359 * @param int $section_index The id of section in resultitem_m
360 * @param int|object|array $listing The name of this plugin.
361 * @param string $default Default Value if empty
362 * @param string $html Html for sprintf(), where
363 * %1$s - value
364 * %2$s - title
365 * %3$s - prefix
366 * %4$s - suffix
367 * @return array
368 */
369 function wdk_generate_resultitem_fields_section_value($id = 1, $section_index=1, $listing='', $default='', $html =' %3$s %1$s %4$s ')
370 {
371 $output = '';
372 $list = wdk_resultitem_fields_section($section_index, $id);
373 foreach ($list as $key => $field) {
374 $value = wdk_field_value($field->field_id, $listing, $default);
375 if(empty($value)) continue;
376 if(wdk_field_option($field->field_id,'field_type') == 'CHECKBOX') {
377 $html ='<span> %2$s </span>';
378 }
379 $output .= sprintf($html,
380 $value,
381 wdk_field_option($field->field_id,'field_label'),
382 wdk_field_option($field->field_id,'prefix'),
383 wdk_field_option($field->field_id,'suffix')
384 );
385 }
386
387 return trim($output);
388 }
389 }
390
391 if(!function_exists('wdk_listing_card')) {
392 /**
393 * Generate listing card html
394 *
395 * @param array $listing The listing data.
396 * @param array $settings The settings.
397 * @param bool $json_output Encode for json, default false
398 * @param string $html Html for sprintf(), where
399 * %1$s - content
400 * @return string
401 */
402
403 function wdk_listing_card($listing = array(), $settings = array(), $json_output = FALSE, $html_sprintf = '%1$s') {
404 $data = ['listing'=>$listing, 'settings'=>$settings];
405
406 $WMVC = &wdk_get_instance();
407
408 /* 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;
421 /* End Favorite module */
422
423 $output = $WMVC->view('frontend/result_item_card', $data, FALSE);
424
425 $output = sprintf($html_sprintf, $output);
426 if($json_output) {
427 $output = str_replace("'", "\'", $output);
428 $output = str_replace('"', '\"', $output);
429 $output = str_replace(array("\n", "\r"), '', $output);
430 }
431
432 return ($output);
433 }
434 }
435
436 if(!function_exists('wdk_image_alt')) {
437 /**
438 * Generate alt tag
439 *
440 * @param string|int $link|id The url or id of image.
441 * @return string alt or title
442 */
443
444 function wdk_image_alt($link_id = '') {
445 $alt = '';
446
447 if(is_intval($link_id)) {
448 $attached_id = $link_id;
449 } else {
450 $attached_id = attachment_url_to_postid($link_id);
451 }
452
453 $alt = get_post_meta($attached_id, '_wp_attachment_image_alt', true);
454 if($alt == '') {
455 $alt = get_the_title($attached_id);
456 }
457
458 return $alt;
459 }
460 }
461