PluginProbe
Property Hive / 1.4.62
Property Hive v1.4.62
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / class-ph-property.php

class-ph-property.php in Property Hive 1.4.62, at includes/class-ph-property.php

1,293 lines 39.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' ) ) exit; // Exit if accessed directly
4
5 /**
6 * Property
7 *
8 * The PropertyHive property class handles property data.
9 *
10 * @class PH_Property
11 * @version 1.0.0
12 * @package PropertyHive/Classes
13 * @category Class
14 * @author PropertyHive
15 */
16 class PH_Property {
17
18 /** @public int Property (post) ID */
19 public $id;
20
21 /**
22 * Get the property if ID is passed, otherwise the property is new and empty.
23 *
24 * @access public
25 * @param string|object $id (default: '')
26 * @return void
27 */
28 public function __construct( $id = '' ) {
29 if ( $id != '' )
30 {
31 if ( is_int($id) && $id > 0 )
32 {
33
34 }
35 else
36 {
37 // Must be post object
38 $id = $id->ID;
39 }
40 $this->get_property( $id );
41 }
42 }
43
44 /**
45 * Gets a property from the database.
46 *
47 * @access public
48 * @param int $id (default: 0)
49 * @return bool
50 */
51 public function get_property( $id = 0 ) {
52 if ( ! $id ) {
53 return false;
54 }
55 if ( $result = get_post( $id ) ) {
56 $this->populate( $result );
57 return true;
58 }
59 return false;
60 }
61
62 /**
63 * __isset function.
64 *
65 * @access public
66 * @param mixed $key
67 * @return bool
68 */
69 public function __isset( $key ) {
70 if ( ! $this->id ) {
71 return false;
72 }
73 return metadata_exists( 'post', $this->id, $key );
74 }
75
76 /**
77 * __get function.
78 *
79 * @access public
80 * @param mixed $key
81 * @return mixed
82 */
83 public function __get( $key ) {
84
85 if ( 'property_type' == $key )
86 {
87 return $this->get_property_type();
88 }
89 if ( 'availability' == $key )
90 {
91 return $this->get_availability();
92 }
93 if ( 'location' == $key )
94 {
95 return $this->get_location();
96 }
97 if ( 'price_qualifier' == $key )
98 {
99 return $this->get_price_qualifier();
100 }
101 if ( 'tenure' == $key )
102 {
103 return $this->get_tenure();
104 }
105 if ( 'sale_by' == $key )
106 {
107 return $this->get_sale_by();
108 }
109 if ( 'furnished' == $key )
110 {
111 return $this->get_furnished();
112 }
113 if ( 'parking' == $key )
114 {
115 return $this->get_parking();
116 }
117 if ( 'outside_space' == $key )
118 {
119 return $this->get_outside_space();
120 }
121 if ( 'marketing_flag' == $key )
122 {
123 return $this->get_marketing_flag();
124 }
125 if ( 'imported_id' == $key )
126 {
127 return $this->get_imported_id();
128 }
129 if ( 'office_name' == $key )
130 {
131 return $this->get_office_name();
132 }
133 if ( 'office_address' == $key )
134 {
135 return $this->get_office_address();
136 }
137 if ( 'office_telephone_number' == $key )
138 {
139 return $this->get_office_telephone_number();
140 }
141 if ( 'office_email_address' == $key )
142 {
143 return $this->get_office_email_address();
144 }
145
146 // Get values or default if not set
147 $value = get_post_meta( $this->id, $key, true );
148 if ($value == '')
149 {
150 $value = get_post_meta( $this->id, '_' . $key, true );
151 }
152 return $value;
153 }
154
155 /**
156 * Populates a property from the loaded post data.
157 *
158 * @access public
159 * @param mixed $result
160 * @return void
161 */
162 public function populate( $result ) {
163 // Standard post data
164 $this->id = $result->ID;
165 $this->post_title = $result->post_title;
166 $this->post_status = $result->post_status;
167 $this->post_excerpt = $result->post_excerpt;
168 }
169
170 /**
171 * get_gallery_attachment_ids function.
172 *
173 * @access public
174 * @return array
175 */
176 public function get_gallery_attachment_ids()
177 {
178 $photos = $this->photos;
179 if ( is_array($photos) )
180 {
181 $photos = array_filter( $photos );
182 }
183 else
184 {
185 $photos = array();
186 }
187 return apply_filters( 'propertyhive_property_gallery_attachment_ids', $photos, $this );
188 }
189
190 /**
191 * Gets the first photo
192 *
193 * @access public
194 * @param string $size
195 * @return string
196 */
197 public function get_main_photo_src( $size = 'thumbnail' ) {
198
199 $return = false;
200
201 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
202 {
203 $photos = $this->_photo_urls;
204
205 if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]) && isset($photos[0]['url']))
206 {
207 $return = $photos[0]['url'];
208 }
209 }
210 else
211 {
212 $photos = $this->_photos;
213
214
215
216 if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]))
217 {
218 $image_attributes = wp_get_attachment_image_src( $photos[0], $size );
219 if( $image_attributes )
220 {
221 $return = $image_attributes[0];
222 }
223 }
224 }
225
226
227 return $return;
228 }
229
230 /**
231 * get_floorplan_attachment_ids function.
232 *
233 * @access public
234 * @return array
235 */
236 public function get_floorplan_attachment_ids()
237 {
238 $floorplans = $this->_floorplans;
239 if ( is_array($floorplans) )
240 {
241 $floorplans = array_filter( $floorplans );
242 }
243 else
244 {
245 $floorplans = array();
246 }
247 return apply_filters( 'propertyhive_property_floorplan_attachment_ids', $floorplans, $this );
248 }
249
250 /**
251 * get_brochure_attachment_ids function.
252 *
253 * @access public
254 * @return array
255 */
256 public function get_brochure_attachment_ids()
257 {
258 $brochures = $this->_brochures;
259 if ( is_array($brochures) )
260 {
261 $brochures = array_filter( $brochures );
262 }
263 else
264 {
265 $brochures = array();
266 }
267 return apply_filters( 'propertyhive_property_brochure_attachment_ids', $brochures, $this );
268 }
269
270 /**
271 * get_epc_attachment_ids function.
272 *
273 * @access public
274 * @return array
275 */
276 public function get_epc_attachment_ids()
277 {
278 $epcs = $this->_epcs;
279 if ( is_array($epcs) )
280 {
281 $epcs = array_filter( $epcs );
282 }
283 else
284 {
285 $epcs = array();
286 }
287 return apply_filters( 'propertyhive_property_epc_attachment_ids', $epcs, $this );
288 }
289
290 /**
291 * get_virtual_tours function.
292 *
293 * @access public
294 * @return array
295 */
296 public function get_virtual_tours()
297 {
298 $num_property_virtual_tours = get_post_meta($this->id, '_virtual_tours', TRUE);
299 if ($num_property_virtual_tours == '') { $num_property_virtual_tours = 0; }
300
301 $virtual_tours = array();
302 for ($i = 0; $i < $num_property_virtual_tours; ++$i)
303 {
304 $label = get_post_meta($this->id, '_virtual_tour_label_' . $i, TRUE);
305 $virtual_tours[] = array(
306 'url' => get_post_meta($this->id, '_virtual_tour_' . $i, TRUE),
307 'label' => ( $label != '' ? $label : __( 'Virtual Tour', 'propertyhive' ) ),
308 );
309 }
310
311 return apply_filters( 'propertyhive_property_virtual_tours', array_filter( $virtual_tours ), $this );
312 }
313
314 /**
315 * get_virtual_tour_urls function.
316 * deprecated
317 *
318 * @access public
319 * @return array
320 */
321 public function get_virtual_tour_urls()
322 {
323 $num_property_virtual_tours = get_post_meta($this->id, '_virtual_tours', TRUE);
324 if ($num_property_virtual_tours == '') { $num_property_virtual_tours = 0; }
325
326 $virtual_tour_urls = array();
327 for ($i = 0; $i < $num_property_virtual_tours; ++$i)
328 {
329 $virtual_tour_urls[] = get_post_meta($this->id, '_virtual_tour_' . $i, TRUE);
330 }
331
332 return apply_filters( 'propertyhive_property_virtual_tour_urls', array_filter( $virtual_tour_urls ), $this );
333 }
334
335 /**
336 * Get the formatted price based on department. Show POA if on frontend and 'POA' ticked
337 *
338 * @access public
339 * @return string
340 */
341 public function get_formatted_price( ) {
342
343 $return = '';
344
345 $currency = array();
346 $prefix = '';
347 $suffix = '';
348
349 if ( $this->_department == 'commercial' )
350 {
351 if (
352 !is_admin() &&
353 $this->_for_sale == 'yes' && $this->_price_poa == 'yes' &&
354 $this->_to_rent == 'yes' && $this->_rent_poa == 'yes'
355 )
356 {
357 $return = __( 'POA', 'propertyhive' );
358 }
359 else
360 {
361 $price = '';
362
363 // Price Details
364 $price .= $this->get_formatted_commercial_price();
365
366 // Rent Details
367 $rent = $this->get_formatted_commercial_rent();
368 if ( $price != '' && $rent != '' )
369 {
370 $price .= '<br>';
371 }
372 $price .= $rent;
373
374 $return = $price;
375 }
376 }
377 else
378 {
379 if ( ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) && $this->_poa == 'yes')
380 {
381 $return = __( 'POA', 'propertyhive' );
382 }
383 else
384 {
385 $ph_countries = new PH_Countries();
386
387 if ( !is_admin() )
388 {
389 if ( isset($_GET['currency']) )
390 {
391 if ( $_GET['currency'] != '' )
392 {
393 $requested_currency = $ph_countries->get_currency( sanitize_text_field($_GET['currency']) );
394 if ( $requested_currency !== FALSE )
395 {
396 $currency = $requested_currency;
397 $currency['exchange_rate'] = 1;
398 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
399 if ( isset($exchange_rates[$_GET['currency']]) )
400 {
401 $currency['exchange_rate'] = $exchange_rates[sanitize_text_field($_GET['currency'])];
402 }
403 }
404 }
405 else
406 {
407 $default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
408 if ( $default_currency != '' )
409 {
410 $requested_currency = $ph_countries->get_currency( $default_currency );
411 if ( $requested_currency !== FALSE )
412 {
413 $currency = $requested_currency;
414 $currency['exchange_rate'] = 1;
415 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
416 if ( isset($exchange_rates[$default_currency]) )
417 {
418 $currency['exchange_rate'] = $exchange_rates[$default_currency];
419 }
420 }
421 }
422 }
423 }
424 elseif ( isset($_COOKIE['propertyhive_currency']) && $_COOKIE['propertyhive_currency'] != '' )
425 {
426 $currency = unserialize(html_entity_decode($_COOKIE['propertyhive_currency']));
427 }
428 else
429 {
430 $default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
431 if ( $default_currency != '' )
432 {
433 $requested_currency = $ph_countries->get_currency( $default_currency );
434 if ( $requested_currency !== FALSE )
435 {
436 $currency = $requested_currency;
437 $currency['exchange_rate'] = 1;
438 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
439 if ( isset($exchange_rates[$default_currency]) )
440 {
441 $currency['exchange_rate'] = $exchange_rates[$default_currency];
442 }
443 }
444 }
445 }
446 }
447
448 if ( empty($currency) )
449 {
450 if ($this->_currency != '')
451 {
452 $currency = $ph_countries->get_currency( $this->_currency );
453 }
454 else
455 {
456 $currency = $ph_countries->get_currency( 'GBP' );
457 }
458 }
459 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
460 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
461 switch ($this->_department)
462 {
463 case "residential-sales":
464 {
465 $price = $this->_price;
466 if ( isset($currency['exchange_rate']) && $price != '' )
467 {
468 $price = $this->_price_actual * $currency['exchange_rate'];
469 }
470 $return = ( ( $price != '' ) ? $prefix . number_format($price, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix : '-' );
471 break;
472 }
473 case "residential-lettings":
474 {
475 $price = $this->_rent;
476 if ( isset($currency['exchange_rate']) && $price != '' )
477 {
478 $price = $this->_price_actual * $currency['exchange_rate'];
479 switch ( $this->_rent_frequency )
480 {
481 case "pw": { $price = ($price * 12) / 52; break; }
482 case "pq": { $price = ($price * 12) / 4; break; }
483 case "pa": { $price = ($price * 12); break; }
484 }
485 }
486 $return = ( ( $price != '' ) ? $prefix . number_format($price, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix . ' ' . __( $this->_rent_frequency, 'propertyhive' ) : '-' );
487 break;
488 }
489 }
490 }
491 }
492
493 return apply_filters( 'propertyhive_price_output', $return, $this, $currency, $prefix, $suffix );
494 }
495
496 /**
497 * Get the formatted commercial price. Show POA if on frontend and 'POA' ticked
498 *
499 * @access public
500 * @return string
501 */
502 public function get_formatted_commercial_price( ) {
503
504 $price = '';
505
506 if ( $this->_for_sale == 'yes' )
507 {
508 if ( !is_admin() && $this->_price_poa == 'yes' )
509 {
510 $price .= __( 'POA', 'propertyhive' );
511 }
512 else
513 {
514 $ph_countries = new PH_Countries();
515 if ( $this->_commercial_price_currency != '' )
516 {
517 $currency = $ph_countries->get_currency( $this->_commercial_price_currency );
518 }
519 else
520 {
521 $currency = $ph_countries->get_currency( 'GBP' );
522 }
523 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
524 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
525
526 if ( $this->_price_from != '' )
527 {
528 $explode_price = explode(".", $this->_price_from);
529 if ( count($explode_price) == 2 )
530 {
531 $price .= $prefix . number_format($explode_price[0], 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . get_option('propertyhive_price_decimal_separator', '.') . $explode_price[1] . $suffix;
532 }
533 else
534 {
535 $price .= $prefix . number_format($this->_price_from, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
536 }
537 }
538 if ( $this->_price_to != '' && $this->_price_to != $this->_price_from )
539 {
540 if ( $price != '' )
541 {
542 $price .= ' - ';
543 }
544 $explode_price = explode(".", $this->_price_to);
545 if ( count($explode_price) == 2 )
546 {
547 $price .= $prefix . number_format($explode_price[0], 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . get_option('propertyhive_price_decimal_separator', '.') . $explode_price[1] . $suffix;
548 }
549 else
550 {
551 $price .= $prefix . number_format($this->_price_to, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
552 }
553 }
554 if ( $price != '' )
555 {
556 $price_units = get_commercial_price_units( );
557 $price .= ( isset($price_units[$this->_price_units]) ) ? ' ' . $price_units[$this->_price_units] : '';
558 }
559 }
560 }
561
562 return $price;
563 }
564
565 /**
566 * Get the formatted commercial rent. Show POA if on frontend and 'POA' ticked
567 *
568 * @access public
569 * @return string
570 */
571 public function get_formatted_commercial_rent( ) {
572
573 $rent = '';
574
575 if ( $this->_to_rent == 'yes' )
576 {
577 if ( !is_admin() && $this->_rent_poa == 'yes' )
578 {
579 $rent .= __( 'POA', 'propertyhive' );
580 }
581 else
582 {
583 $ph_countries = new PH_Countries();
584 if ( $this->_commercial_rent_currency != '' )
585 {
586 $currency = $ph_countries->get_currency( $this->_commercial_rent_currency );
587 }
588 else
589 {
590 $currency = $ph_countries->get_currency( 'GBP' );
591 }
592 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
593 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
594
595 if ( $this->_rent_from != '' )
596 {
597 $explode_rent = explode(".", $this->_rent_from);
598 if ( count($explode_rent) == 2 )
599 {
600 $rent .= $prefix . number_format($explode_rent[0], 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . get_option('propertyhive_price_decimal_separator', '.') . $explode_rent[1] . $suffix;
601 }
602 else
603 {
604 $rent .= $prefix . number_format($this->_rent_from, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
605 }
606 }
607 if ( $this->_rent_to != '' && $this->_rent_to != $this->_rent_from )
608 {
609 if ( $rent != '' )
610 {
611 $rent .= ' - ';
612 }
613 $explode_rent = explode(".", $this->_rent_to);
614 if ( count($explode_rent) == 2 )
615 {
616 $rent .= $prefix . number_format($explode_rent[0], 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . get_option('propertyhive_price_decimal_separator', '.') . $explode_rent[1] . $suffix;
617 }
618 else
619 {
620 $rent .= $prefix . number_format($this->_rent_to, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
621 }
622 }
623 if ( $rent != '' )
624 {
625 $price_units = get_commercial_price_units( );
626 $rent .= ' ' . ( isset($price_units[$this->_rent_units]) ? $price_units[$this->_rent_units] : $this->_rent_units );
627 }
628 }
629 }
630
631 return $rent;
632 }
633
634 public function get_formatted_floor_area( ) {
635
636 $area = '';
637
638 if ( $this->_floor_area_from != '' )
639 {
640 $explode_area = explode(".", $this->_floor_area_from);
641 if ( count($explode_area) == 2 )
642 {
643 $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
644 }
645 else
646 {
647 $area .= number_format($this->_floor_area_from, 0);
648 }
649 }
650 if ( $this->_floor_area_to != '' && $this->_floor_area_to != $this->_floor_area_from )
651 {
652 if ( $area != '' )
653 {
654 $area .= ' - ';
655 }
656 $explode_area = explode(".", $this->_floor_area_to);
657 if ( count($explode_area) == 2 )
658 {
659 $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
660 }
661 else
662 {
663 $area .= number_format($this->_floor_area_to, 0);
664 }
665 }
666
667 if ( $area != '' )
668 {
669 $area_units = get_area_units( );
670 $area .= ( isset($area_units[$this->_floor_area_units]) ) ? ' ' . $area_units[$this->_floor_area_units] : '';
671 }
672
673 return $area;
674
675 }
676
677 public function get_formatted_site_area( ) {
678
679 $area = '';
680
681 if ( $this->_site_area_from != '' )
682 {
683 $explode_area = explode(".", $this->_site_area_from);
684 if ( count($explode_area) == 2 )
685 {
686 $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
687 }
688 else
689 {
690 $area .= number_format($this->_site_area_from, 0);
691 }
692 }
693 if ( $this->_site_area_to != '' && $this->_site_area_to != $this->_site_area_from )
694 {
695 if ( $area != '' )
696 {
697 $area .= ' - ';
698 }
699 $explode_area = explode(".", $this->_site_area_to);
700 if ( count($explode_area) == 2 )
701 {
702 $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
703 }
704 else
705 {
706 $area .= number_format($this->_site_area_to, 0);
707 }
708 }
709
710 if ( $area != '' )
711 {
712 $area_units = get_area_units( );
713 $area .= ( isset($area_units[$this->_site_area_units]) ) ? ' ' . $area_units[$this->_site_area_units] : '';
714 }
715
716 return $area;
717
718 }
719
720 /**
721 * Get the formatted deposit
722 *
723 * @access public
724 * @return string
725 */
726 public function get_formatted_deposit( )
727 {
728 if ( $this->_deposit == '' )
729 {
730 return '';
731 }
732
733 $ph_countries = new PH_Countries();
734
735 $currency = $ph_countries->get_currency( $this->_currency );
736 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
737 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
738
739 return $prefix . number_format($this->_deposit, 0) . $suffix;
740 }
741
742 /**
743 * Get the available date, or 'Now' if date is in past
744 *
745 * @access public
746 * @return string
747 */
748 public function get_available_date( )
749 {
750 if (strtotime($this->_available_date))
751 {
752 return date( get_option( 'date_format' ), strtotime($this->_available_date) );
753 }
754 else
755 {
756 return __( 'Now', 'propertyhive' );
757 }
758 }
759
760 /**
761 * Get the full description by constructing the rooms or commercial description (dependant on department)
762 *
763 * @access public
764 * @return string
765 */
766 public function get_formatted_description( ) {
767
768 if ( $this->_department == 'commercial' )
769 {
770 return $this->get_formatted_descriptions(); // Haven't called this commercial_descriptions as we might use generic descriptions for other area going forward
771 }
772 else
773 {
774 return $this->get_formatted_rooms();
775 }
776 }
777
778 /**
779 * Get the full description by constructing the rooms
780 *
781 * @access public
782 * @return string
783 */
784 public function get_formatted_rooms( ) {
785
786 $rooms = $this->_rooms;
787
788 $return = '';
789
790 if (isset($rooms) && $rooms != '' && $rooms > 0)
791 {
792 for ($i = 0; $i < $rooms; ++$i)
793 {
794 $return .= '<p class="room">';
795 if ($this->{'_room_name_' . $i} != '')
796 {
797 $return .= '<strong class="name">' . $this->{'_room_name_' . $i} . '</strong>';
798 }
799 if ($this->{'_room_dimensions_' . $i} != '')
800 {
801 $return .= ' <strong class="dimension">(' . $this->{'_room_dimensions_' . $i} . ')</strong>';
802 }
803 if ($this->{'_room_name_' . $i} != '' || $this->{'_room_dimensions_' . $i} != '')
804 {
805 $return .= '<br>';
806 }
807 $return .= str_replace("\r\n", "", nl2br($this->{'_room_description_' . $i})) . '</p>';
808 }
809 }
810
811 return $return;
812 }
813
814 /**
815 * Get the full description by constructing the descriptions
816 *
817 * @access public
818 * @return string
819 */
820 public function get_formatted_descriptions( ) {
821
822 $descriptions = $this->_descriptions;
823
824 $return = '';
825
826 if (isset($descriptions) && $descriptions != '' && $descriptions > 0)
827 {
828 for ($i = 0; $i < $descriptions; ++$i)
829 {
830 $return .= '<p class="description-section">';
831 if ($this->{'_description_name_' . $i} != '')
832 {
833 $return .= '<strong class="description-title">' . $this->{'_description_name_' . $i} . '</strong><br>';
834 }
835 $return .= str_replace("\r\n", "", nl2br($this->{'_description_' . $i})) . '</p>';
836 }
837 }
838
839 return $return;
840 }
841
842 /**
843 * Get the property type taxononmy
844 *
845 * @access public
846 * @return string
847 */
848 public function get_property_type()
849 {
850 $term_list = wp_get_post_terms($this->id, ( ( $this->_department == 'commercial' ) ? 'commercial_' : '' ) . 'property_type', array("fields" => "names"));
851
852 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
853 {
854 return implode(", ", $term_list);
855 }
856
857 return '';
858 }
859
860 /**
861 * Get the availability taxononmy
862 *
863 * @access public
864 * @return string
865 */
866 public function get_availability()
867 {
868 $term_list = wp_get_post_terms($this->id, 'availability', array("fields" => "names"));
869
870 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
871 {
872 return implode(", ", $term_list);
873 }
874
875 return '';
876 }
877
878 /**
879 * Get the location taxononmy
880 *
881 * @access public
882 * @return string
883 */
884 public function get_location()
885 {
886 $term_list = wp_get_post_terms($this->id, 'location', array("fields" => "names"));
887
888 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
889 {
890 return implode(", ", $term_list);
891 }
892
893 return '';
894 }
895
896 /**
897 * Get the price qualifier taxononmy
898 *
899 * @access public
900 * @return string
901 */
902 public function get_price_qualifier()
903 {
904 $term_list = wp_get_post_terms($this->id, 'price_qualifier', array("fields" => "names"));
905
906 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
907 {
908 return implode(", ", $term_list);
909 }
910
911 return '';
912 }
913
914 /**
915 * Get the tenure taxononmy
916 *
917 * @access public
918 * @return string
919 */
920 public function get_tenure()
921 {
922 $term_list = wp_get_post_terms($this->id, 'tenure', array("fields" => "names"));
923
924 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
925 {
926 return implode(", ", $term_list);
927 }
928
929 return '';
930 }
931
932 /**
933 * Get the sale by taxononmy
934 *
935 * @access public
936 * @return string
937 */
938 public function get_sale_by()
939 {
940 $term_list = wp_get_post_terms($this->id, 'sale_by', array("fields" => "names"));
941
942 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
943 {
944 return implode(", ", $term_list);
945 }
946
947 return '';
948 }
949
950 /**
951 * Get the furnished taxononmy
952 *
953 * @access public
954 * @return string
955 */
956 public function get_furnished()
957 {
958 $term_list = wp_get_post_terms($this->id, 'furnished', array("fields" => "names"));
959
960 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
961 {
962 return implode(", ", $term_list);
963 }
964
965 return '';
966 }
967
968 /**
969 * Get the parking taxononmy
970 *
971 * @access public
972 * @return string
973 */
974 public function get_parking()
975 {
976 $term_list = wp_get_post_terms($this->id, 'parking', array("fields" => "names"));
977
978 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
979 {
980 return implode(", ", $term_list);
981 }
982
983 return '';
984 }
985
986 /**
987 * Get the outside space taxononmy
988 *
989 * @access public
990 * @return string
991 */
992 public function get_outside_space()
993 {
994 $term_list = wp_get_post_terms($this->id, 'outside_space', array("fields" => "names"));
995
996 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
997 {
998 return implode(", ", $term_list);
999 }
1000
1001 return '';
1002 }
1003
1004 /**
1005 * Get the marketing flag taxononmy
1006 *
1007 * @access public
1008 * @return string
1009 */
1010 public function get_marketing_flag()
1011 {
1012 $term_list = wp_get_post_terms($this->id, 'marketing_flag', array("fields" => "names"));
1013
1014 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
1015 {
1016 return implode(", ", $term_list);
1017 }
1018
1019 return '';
1020 }
1021
1022 /**
1023 * Get the ID of property from third party system
1024 *
1025 * @access public
1026 * @return string
1027 */
1028 public function get_imported_id()
1029 {
1030 global $wpdb;
1031
1032 $row = $wpdb->get_row(
1033 "
1034 SELECT meta_value
1035 FROM {$wpdb->prefix}postmeta
1036 WHERE
1037 meta_key LIKE '_imported_ref_%'
1038 AND
1039 post_id = '" . $this->id . "'
1040 LIMIT 1
1041 ",
1042 ARRAY_A
1043 );
1044
1045 if ( null !== $row )
1046 {
1047 return $row['meta_value'];
1048 }
1049
1050 return '';
1051 }
1052
1053 /**
1054 * Get an array of property features
1055 *
1056 * @access public
1057 * @return array
1058 */
1059 public function get_features( )
1060 {
1061 $features = array();
1062
1063 if ( get_option('propertyhive_features_type') == 'checkbox' )
1064 {
1065 $term_list = wp_get_post_terms($this->id, 'property_feature', array("fields" => "names"));
1066 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
1067 {
1068 foreach ( $term_list as $term_name )
1069 {
1070 $features[] = trim($term_name);
1071 }
1072 }
1073 }
1074 else
1075 {
1076 $num_property_features = $this->_features;
1077 if ($num_property_features == '') { $num_property_features = 0; }
1078
1079 for ($i = 0; $i < $num_property_features; ++$i)
1080 {
1081 if ( trim($this->{'_feature_' . $i}) != '' )
1082 {
1083 $features[] = trim($this->{'_feature_' . $i});
1084 }
1085 }
1086 }
1087
1088 return $features;
1089 }
1090
1091 /**
1092 * Get the full formatted address
1093 *
1094 * @access public
1095 * @return string
1096 */
1097 public function get_formatted_full_address( $separator = ', ' ) {
1098 // Standard post data
1099
1100 $return = '';
1101
1102 $address_name_number = $this->_address_name_number;
1103 if ($address_name_number != '')
1104 {
1105 $return .= $address_name_number;
1106 }
1107 $address_street = $this->_address_street;
1108 if ($address_street != '')
1109 {
1110 if ($return != '') { $return .= ' '; }
1111 $return .= $address_street;
1112 }
1113 $address_two = $this->_address_two;
1114 if ($address_two != '')
1115 {
1116 if ($return != '') { $return .= $separator; }
1117 $return .= $address_two;
1118 }
1119 $address_three = $this->_address_three;
1120 if ($address_three != '')
1121 {
1122 if ($return != '') { $return .= $separator; }
1123 $return .= $address_three;
1124 }
1125 $address_four = $this->_address_four;
1126 if ($address_four != '')
1127 {
1128 if ($return != '') { $return .= $separator; }
1129 $return .= $address_four;
1130 }
1131 $address_postcode = $this->_address_postcode;
1132 if ($address_postcode != '')
1133 {
1134 if ($return != '') { $return .= $separator; }
1135 $return .= $address_postcode;
1136 }
1137
1138 if ( $return == '' )
1139 {
1140 $return = $this->post_title;
1141 }
1142
1143 return $return;
1144 }
1145
1146 /**
1147 * Get the summary formatted address
1148 *
1149 * @access public
1150 * @return string
1151 */
1152 public function get_formatted_summary_address( $separator = ', ' ) {
1153 // Standard post data
1154
1155 $return = '';
1156
1157 $address_name_number = $this->_address_name_number;
1158 if ($address_name_number != '')
1159 {
1160 $return .= $address_name_number;
1161 }
1162 $address_street = $this->_address_street;
1163 if ($address_street != '')
1164 {
1165 if ($return != '') { $return .= ' '; }
1166 $return .= $address_street;
1167 }
1168 $address_two = $this->_address_two;
1169 $address_three = $this->_address_three;
1170 $address_four = $this->_address_four;
1171 if ($address_two != '')
1172 {
1173 if ($return != '') { $return .= $separator; }
1174 $return .= $address_two;
1175 }
1176 elseif ($address_three != '')
1177 {
1178 if ($return != '') { $return .= $separator; }
1179 $return .= $address_three;
1180 }
1181 elseif ($address_four != '')
1182 {
1183 if ($return != '') { $return .= $separator; }
1184 $return .= $address_four;
1185 }
1186 $address_postcode = $this->_address_postcode;
1187 if ($address_postcode != '')
1188 {
1189 if ($return != '') { $return .= $separator; }
1190 $return .= $address_postcode;
1191 }
1192
1193 if ( $return == '' )
1194 {
1195 $return = $this->post_title;
1196 }
1197
1198 return $return;
1199 }
1200
1201 public function get_office_name()
1202 {
1203 return get_the_title( $this->_office_id );
1204 }
1205
1206 public function get_office_address( $separator = ', ' )
1207 {
1208 $return = '';
1209
1210 for ( $i = 1; $i <= 4; ++$i )
1211 {
1212 $address = get_post_meta( $this->_office_id, '_office_address_' . $i, TRUE );
1213 if ($address != '')
1214 {
1215 if ($return != '') { $return .= $separator; }
1216 $return .= $address;
1217 }
1218 }
1219 $address = get_post_meta( $this->_office_id, '_office_address_postcode', TRUE );
1220 if ($address != '')
1221 {
1222 if ($return != '') { $return .= $separator; }
1223 $return .= $address;
1224 }
1225
1226 return $return;
1227 }
1228
1229 public function get_office_telephone_number()
1230 {
1231 return get_post_meta( $this->_office_id, '_office_telephone_number_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1232 }
1233
1234 public function get_office_email_address()
1235 {
1236 return get_post_meta( $this->_office_id, '_office_email_address_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1237 }
1238
1239 /**
1240 * Returns boolean whether the property is featured or not
1241 *
1242 * @access public
1243 * @return string
1244 */
1245 public function is_featured() {
1246
1247 if (isset($the_property->_featured) && $the_property->_featured == 'yes')
1248 {
1249 return true;
1250 }
1251
1252 return false;
1253
1254 }
1255
1256 /**
1257 * Adds a note (comment) to the property
1258 *
1259 * @access public
1260 * @param string $note Note to add
1261 * @return id Comment ID
1262 */
1263 public function add_note( $note ) {
1264
1265 if ( is_user_logged_in() )
1266 {
1267 $user = get_user_by( 'id', get_current_user_id() );
1268
1269 $commentdata = array(
1270 'comment_post_ID' => $this->id,
1271 'comment_author' => $user->display_name,
1272 'comment_author_email' => $user->user_email,
1273 'comment_author_url' => '',
1274 'comment_content' => $note,
1275 'comment_type' => 'propertyhive_note',
1276 'comment_parent' => 0,
1277 'user_id' => $user->ID,
1278 'comment_agent' => 'PropertyHive',
1279 'comment_date' => current_time('mysql'),
1280 'comment_approved' => 1,
1281 );
1282
1283 $comment_id = wp_insert_comment( $commentdata );
1284
1285 return $comment_id;
1286 }
1287 }
1288
1289
1290
1291
1292 }
1293