PluginProbe
Property Hive / 1.4.59
Property Hive v1.4.59
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.59, at includes/class-ph-property.php

1,282 lines 38.7 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 $price = '';
352
353 // Price Details
354 $price .= $this->get_formatted_commercial_price();
355
356 // Rent Details
357 $rent = $this->get_formatted_commercial_rent();
358 if ( $price != '' && $rent != '' )
359 {
360 $price .= '<br>';
361 }
362 $price .= $rent;
363
364 $return = $price;
365 }
366 else
367 {
368 if ( ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) && $this->_poa == 'yes')
369 {
370 $return = __( 'POA', 'propertyhive' );
371 }
372 else
373 {
374 $ph_countries = new PH_Countries();
375
376 if ( !is_admin() )
377 {
378 if ( isset($_GET['currency']) )
379 {
380 if ( $_GET['currency'] != '' )
381 {
382 $requested_currency = $ph_countries->get_currency( sanitize_text_field($_GET['currency']) );
383 if ( $requested_currency !== FALSE )
384 {
385 $currency = $requested_currency;
386 $currency['exchange_rate'] = 1;
387 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
388 if ( isset($exchange_rates[$_GET['currency']]) )
389 {
390 $currency['exchange_rate'] = $exchange_rates[sanitize_text_field($_GET['currency'])];
391 }
392 }
393 }
394 else
395 {
396 $default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
397 if ( $default_currency != '' )
398 {
399 $requested_currency = $ph_countries->get_currency( $default_currency );
400 if ( $requested_currency !== FALSE )
401 {
402 $currency = $requested_currency;
403 $currency['exchange_rate'] = 1;
404 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
405 if ( isset($exchange_rates[$default_currency]) )
406 {
407 $currency['exchange_rate'] = $exchange_rates[$default_currency];
408 }
409 }
410 }
411 }
412 }
413 elseif ( isset($_COOKIE['propertyhive_currency']) && $_COOKIE['propertyhive_currency'] != '' )
414 {
415 $currency = unserialize(html_entity_decode($_COOKIE['propertyhive_currency']));
416 }
417 else
418 {
419 $default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
420 if ( $default_currency != '' )
421 {
422 $requested_currency = $ph_countries->get_currency( $default_currency );
423 if ( $requested_currency !== FALSE )
424 {
425 $currency = $requested_currency;
426 $currency['exchange_rate'] = 1;
427 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
428 if ( isset($exchange_rates[$default_currency]) )
429 {
430 $currency['exchange_rate'] = $exchange_rates[$default_currency];
431 }
432 }
433 }
434 }
435 }
436
437 if ( empty($currency) )
438 {
439 if ($this->_currency != '')
440 {
441 $currency = $ph_countries->get_currency( $this->_currency );
442 }
443 else
444 {
445 $currency = $ph_countries->get_currency( 'GBP' );
446 }
447 }
448 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
449 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
450 switch ($this->_department)
451 {
452 case "residential-sales":
453 {
454 $price = $this->_price;
455 if ( isset($currency['exchange_rate']) && $price != '' )
456 {
457 $price = $this->_price_actual * $currency['exchange_rate'];
458 }
459 $return = ( ( $price != '' ) ? $prefix . number_format($price, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix : '-' );
460 break;
461 }
462 case "residential-lettings":
463 {
464 $price = $this->_rent;
465 if ( isset($currency['exchange_rate']) && $price != '' )
466 {
467 $price = $this->_price_actual * $currency['exchange_rate'];
468 switch ( $this->_rent_frequency )
469 {
470 case "pw": { $price = ($price * 12) / 52; break; }
471 case "pq": { $price = ($price * 12) / 4; break; }
472 case "pa": { $price = ($price * 12); break; }
473 }
474 }
475 $return = ( ( $price != '' ) ? $prefix . number_format($price, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix . ' ' . __( $this->_rent_frequency, 'propertyhive' ) : '-' );
476 break;
477 }
478 }
479 }
480 }
481
482 return apply_filters( 'propertyhive_price_output', $return, $this, $currency, $prefix, $suffix );
483 }
484
485 /**
486 * Get the formatted commercial price. Show POA if on frontend and 'POA' ticked
487 *
488 * @access public
489 * @return string
490 */
491 public function get_formatted_commercial_price( ) {
492
493 $price = '';
494
495 if ( $this->_for_sale == 'yes' )
496 {
497 if ( !is_admin() && $this->_price_poa == 'yes' )
498 {
499 $price .= __( 'POA', 'propertyhive' );
500 }
501 else
502 {
503 $ph_countries = new PH_Countries();
504 if ( $this->_commercial_price_currency != '' )
505 {
506 $currency = $ph_countries->get_currency( $this->_commercial_price_currency );
507 }
508 else
509 {
510 $currency = $ph_countries->get_currency( 'GBP' );
511 }
512 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
513 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
514
515 if ( $this->_price_from != '' )
516 {
517 $explode_price = explode(".", $this->_price_from);
518 if ( count($explode_price) == 2 )
519 {
520 $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;
521 }
522 else
523 {
524 $price .= $prefix . number_format($this->_price_from, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
525 }
526 }
527 if ( $this->_price_to != '' && $this->_price_to != $this->_price_from )
528 {
529 if ( $price != '' )
530 {
531 $price .= ' - ';
532 }
533 $explode_price = explode(".", $this->_price_to);
534 if ( count($explode_price) == 2 )
535 {
536 $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;
537 }
538 else
539 {
540 $price .= $prefix . number_format($this->_price_to, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
541 }
542 }
543 if ( $price != '' )
544 {
545 $price_units = get_commercial_price_units( );
546 $price .= ( isset($price_units[$this->_price_units]) ) ? ' ' . $price_units[$this->_price_units] : '';
547 }
548 }
549 }
550
551 return $price;
552 }
553
554 /**
555 * Get the formatted commercial rent. Show POA if on frontend and 'POA' ticked
556 *
557 * @access public
558 * @return string
559 */
560 public function get_formatted_commercial_rent( ) {
561
562 $rent = '';
563
564 if ( $this->_to_rent == 'yes' )
565 {
566 if ( !is_admin() && $this->_rent_poa == 'yes' )
567 {
568 $rent .= __( 'POA', 'propertyhive' );
569 }
570 else
571 {
572 $ph_countries = new PH_Countries();
573 if ( $this->_commercial_rent_currency != '' )
574 {
575 $currency = $ph_countries->get_currency( $this->_commercial_rent_currency );
576 }
577 else
578 {
579 $currency = $ph_countries->get_currency( 'GBP' );
580 }
581 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
582 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
583
584 if ( $this->_rent_from != '' )
585 {
586 $explode_rent = explode(".", $this->_rent_from);
587 if ( count($explode_rent) == 2 )
588 {
589 $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;
590 }
591 else
592 {
593 $rent .= $prefix . number_format($this->_rent_from, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
594 }
595 }
596 if ( $this->_rent_to != '' && $this->_rent_to != $this->_rent_from )
597 {
598 if ( $rent != '' )
599 {
600 $rent .= ' - ';
601 }
602 $explode_rent = explode(".", $this->_rent_to);
603 if ( count($explode_rent) == 2 )
604 {
605 $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;
606 }
607 else
608 {
609 $rent .= $prefix . number_format($this->_rent_to, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
610 }
611 }
612 if ( $rent != '' )
613 {
614 $price_units = get_commercial_price_units( );
615 $rent .= ' ' . ( isset($price_units[$this->_rent_units]) ? $price_units[$this->_rent_units] : $this->_rent_units );
616 }
617 }
618 }
619
620 return $rent;
621 }
622
623 public function get_formatted_floor_area( ) {
624
625 $area = '';
626
627 if ( $this->_floor_area_from != '' )
628 {
629 $explode_area = explode(".", $this->_floor_area_from);
630 if ( count($explode_area) == 2 )
631 {
632 $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
633 }
634 else
635 {
636 $area .= number_format($this->_floor_area_from, 0);
637 }
638 }
639 if ( $this->_floor_area_to != '' && $this->_floor_area_to != $this->_floor_area_from )
640 {
641 if ( $area != '' )
642 {
643 $area .= ' - ';
644 }
645 $explode_area = explode(".", $this->_floor_area_to);
646 if ( count($explode_area) == 2 )
647 {
648 $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
649 }
650 else
651 {
652 $area .= number_format($this->_floor_area_to, 0);
653 }
654 }
655
656 if ( $area != '' )
657 {
658 $area_units = get_area_units( );
659 $area .= ( isset($area_units[$this->_floor_area_units]) ) ? ' ' . $area_units[$this->_floor_area_units] : '';
660 }
661
662 return $area;
663
664 }
665
666 public function get_formatted_site_area( ) {
667
668 $area = '';
669
670 if ( $this->_site_area_from != '' )
671 {
672 $explode_area = explode(".", $this->_site_area_from);
673 if ( count($explode_area) == 2 )
674 {
675 $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
676 }
677 else
678 {
679 $area .= number_format($this->_site_area_from, 0);
680 }
681 }
682 if ( $this->_site_area_to != '' && $this->_site_area_to != $this->_site_area_from )
683 {
684 if ( $area != '' )
685 {
686 $area .= ' - ';
687 }
688 $explode_area = explode(".", $this->_site_area_to);
689 if ( count($explode_area) == 2 )
690 {
691 $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
692 }
693 else
694 {
695 $area .= number_format($this->_site_area_to, 0);
696 }
697 }
698
699 if ( $area != '' )
700 {
701 $area_units = get_area_units( );
702 $area .= ( isset($area_units[$this->_site_area_units]) ) ? ' ' . $area_units[$this->_site_area_units] : '';
703 }
704
705 return $area;
706
707 }
708
709 /**
710 * Get the formatted deposit
711 *
712 * @access public
713 * @return string
714 */
715 public function get_formatted_deposit( )
716 {
717 if ( $this->_deposit == '' )
718 {
719 return '';
720 }
721
722 $ph_countries = new PH_Countries();
723
724 $currency = $ph_countries->get_currency( $this->_currency );
725 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
726 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
727
728 return $prefix . number_format($this->_deposit, 0) . $suffix;
729 }
730
731 /**
732 * Get the available date, or 'Now' if date is in past
733 *
734 * @access public
735 * @return string
736 */
737 public function get_available_date( )
738 {
739 if (strtotime($this->_available_date))
740 {
741 return date( get_option( 'date_format' ), strtotime($this->_available_date) );
742 }
743 else
744 {
745 return __( 'Now', 'propertyhive' );
746 }
747 }
748
749 /**
750 * Get the full description by constructing the rooms or commercial description (dependant on department)
751 *
752 * @access public
753 * @return string
754 */
755 public function get_formatted_description( ) {
756
757 if ( $this->_department == 'commercial' )
758 {
759 return $this->get_formatted_descriptions(); // Haven't called this commercial_descriptions as we might use generic descriptions for other area going forward
760 }
761 else
762 {
763 return $this->get_formatted_rooms();
764 }
765 }
766
767 /**
768 * Get the full description by constructing the rooms
769 *
770 * @access public
771 * @return string
772 */
773 public function get_formatted_rooms( ) {
774
775 $rooms = $this->_rooms;
776
777 $return = '';
778
779 if (isset($rooms) && $rooms != '' && $rooms > 0)
780 {
781 for ($i = 0; $i < $rooms; ++$i)
782 {
783 $return .= '<p class="room">';
784 if ($this->{'_room_name_' . $i} != '')
785 {
786 $return .= '<strong class="name">' . $this->{'_room_name_' . $i} . '</strong>';
787 }
788 if ($this->{'_room_dimensions_' . $i} != '')
789 {
790 $return .= ' <strong class="dimension">(' . $this->{'_room_dimensions_' . $i} . ')</strong>';
791 }
792 if ($this->{'_room_name_' . $i} != '' || $this->{'_room_dimensions_' . $i} != '')
793 {
794 $return .= '<br>';
795 }
796 $return .= str_replace("\r\n", "", nl2br($this->{'_room_description_' . $i})) . '</p>';
797 }
798 }
799
800 return $return;
801 }
802
803 /**
804 * Get the full description by constructing the descriptions
805 *
806 * @access public
807 * @return string
808 */
809 public function get_formatted_descriptions( ) {
810
811 $descriptions = $this->_descriptions;
812
813 $return = '';
814
815 if (isset($descriptions) && $descriptions != '' && $descriptions > 0)
816 {
817 for ($i = 0; $i < $descriptions; ++$i)
818 {
819 $return .= '<p class="description-section">';
820 if ($this->{'_description_name_' . $i} != '')
821 {
822 $return .= '<strong class="description-title">' . $this->{'_description_name_' . $i} . '</strong><br>';
823 }
824 $return .= str_replace("\r\n", "", nl2br($this->{'_description_' . $i})) . '</p>';
825 }
826 }
827
828 return $return;
829 }
830
831 /**
832 * Get the property type taxononmy
833 *
834 * @access public
835 * @return string
836 */
837 public function get_property_type()
838 {
839 $term_list = wp_get_post_terms($this->id, ( ( $this->_department == 'commercial' ) ? 'commercial_' : '' ) . 'property_type', array("fields" => "names"));
840
841 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
842 {
843 return implode(", ", $term_list);
844 }
845
846 return '';
847 }
848
849 /**
850 * Get the availability taxononmy
851 *
852 * @access public
853 * @return string
854 */
855 public function get_availability()
856 {
857 $term_list = wp_get_post_terms($this->id, 'availability', array("fields" => "names"));
858
859 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
860 {
861 return implode(", ", $term_list);
862 }
863
864 return '';
865 }
866
867 /**
868 * Get the location taxononmy
869 *
870 * @access public
871 * @return string
872 */
873 public function get_location()
874 {
875 $term_list = wp_get_post_terms($this->id, 'location', array("fields" => "names"));
876
877 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
878 {
879 return implode(", ", $term_list);
880 }
881
882 return '';
883 }
884
885 /**
886 * Get the price qualifier taxononmy
887 *
888 * @access public
889 * @return string
890 */
891 public function get_price_qualifier()
892 {
893 $term_list = wp_get_post_terms($this->id, 'price_qualifier', array("fields" => "names"));
894
895 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
896 {
897 return implode(", ", $term_list);
898 }
899
900 return '';
901 }
902
903 /**
904 * Get the tenure taxononmy
905 *
906 * @access public
907 * @return string
908 */
909 public function get_tenure()
910 {
911 $term_list = wp_get_post_terms($this->id, 'tenure', array("fields" => "names"));
912
913 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
914 {
915 return implode(", ", $term_list);
916 }
917
918 return '';
919 }
920
921 /**
922 * Get the sale by taxononmy
923 *
924 * @access public
925 * @return string
926 */
927 public function get_sale_by()
928 {
929 $term_list = wp_get_post_terms($this->id, 'sale_by', array("fields" => "names"));
930
931 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
932 {
933 return implode(", ", $term_list);
934 }
935
936 return '';
937 }
938
939 /**
940 * Get the furnished taxononmy
941 *
942 * @access public
943 * @return string
944 */
945 public function get_furnished()
946 {
947 $term_list = wp_get_post_terms($this->id, 'furnished', array("fields" => "names"));
948
949 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
950 {
951 return implode(", ", $term_list);
952 }
953
954 return '';
955 }
956
957 /**
958 * Get the parking taxononmy
959 *
960 * @access public
961 * @return string
962 */
963 public function get_parking()
964 {
965 $term_list = wp_get_post_terms($this->id, 'parking', array("fields" => "names"));
966
967 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
968 {
969 return implode(", ", $term_list);
970 }
971
972 return '';
973 }
974
975 /**
976 * Get the outside space taxononmy
977 *
978 * @access public
979 * @return string
980 */
981 public function get_outside_space()
982 {
983 $term_list = wp_get_post_terms($this->id, 'outside_space', array("fields" => "names"));
984
985 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
986 {
987 return implode(", ", $term_list);
988 }
989
990 return '';
991 }
992
993 /**
994 * Get the marketing flag taxononmy
995 *
996 * @access public
997 * @return string
998 */
999 public function get_marketing_flag()
1000 {
1001 $term_list = wp_get_post_terms($this->id, 'marketing_flag', array("fields" => "names"));
1002
1003 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
1004 {
1005 return implode(", ", $term_list);
1006 }
1007
1008 return '';
1009 }
1010
1011 /**
1012 * Get the ID of property from third party system
1013 *
1014 * @access public
1015 * @return string
1016 */
1017 public function get_imported_id()
1018 {
1019 global $wpdb;
1020
1021 $row = $wpdb->get_row(
1022 "
1023 SELECT meta_value
1024 FROM {$wpdb->prefix}postmeta
1025 WHERE
1026 meta_key LIKE '_imported_ref_%'
1027 AND
1028 post_id = '" . $this->id . "'
1029 LIMIT 1
1030 ",
1031 ARRAY_A
1032 );
1033
1034 if ( null !== $row )
1035 {
1036 return $row['meta_value'];
1037 }
1038
1039 return '';
1040 }
1041
1042 /**
1043 * Get an array of property features
1044 *
1045 * @access public
1046 * @return array
1047 */
1048 public function get_features( )
1049 {
1050 $features = array();
1051
1052 if ( get_option('propertyhive_features_type') == 'checkbox' )
1053 {
1054 $term_list = wp_get_post_terms($this->id, 'property_feature', array("fields" => "names"));
1055 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
1056 {
1057 foreach ( $term_list as $term_name )
1058 {
1059 $features[] = trim($term_name);
1060 }
1061 }
1062 }
1063 else
1064 {
1065 $num_property_features = $this->_features;
1066 if ($num_property_features == '') { $num_property_features = 0; }
1067
1068 for ($i = 0; $i < $num_property_features; ++$i)
1069 {
1070 if ( trim($this->{'_feature_' . $i}) != '' )
1071 {
1072 $features[] = trim($this->{'_feature_' . $i});
1073 }
1074 }
1075 }
1076
1077 return $features;
1078 }
1079
1080 /**
1081 * Get the full formatted address
1082 *
1083 * @access public
1084 * @return string
1085 */
1086 public function get_formatted_full_address( $separator = ', ' ) {
1087 // Standard post data
1088
1089 $return = '';
1090
1091 $address_name_number = $this->_address_name_number;
1092 if ($address_name_number != '')
1093 {
1094 $return .= $address_name_number;
1095 }
1096 $address_street = $this->_address_street;
1097 if ($address_street != '')
1098 {
1099 if ($return != '') { $return .= ' '; }
1100 $return .= $address_street;
1101 }
1102 $address_two = $this->_address_two;
1103 if ($address_two != '')
1104 {
1105 if ($return != '') { $return .= $separator; }
1106 $return .= $address_two;
1107 }
1108 $address_three = $this->_address_three;
1109 if ($address_three != '')
1110 {
1111 if ($return != '') { $return .= $separator; }
1112 $return .= $address_three;
1113 }
1114 $address_four = $this->_address_four;
1115 if ($address_four != '')
1116 {
1117 if ($return != '') { $return .= $separator; }
1118 $return .= $address_four;
1119 }
1120 $address_postcode = $this->_address_postcode;
1121 if ($address_postcode != '')
1122 {
1123 if ($return != '') { $return .= $separator; }
1124 $return .= $address_postcode;
1125 }
1126
1127 if ( $return == '' )
1128 {
1129 $return = $this->post_title;
1130 }
1131
1132 return $return;
1133 }
1134
1135 /**
1136 * Get the summary formatted address
1137 *
1138 * @access public
1139 * @return string
1140 */
1141 public function get_formatted_summary_address( $separator = ', ' ) {
1142 // Standard post data
1143
1144 $return = '';
1145
1146 $address_name_number = $this->_address_name_number;
1147 if ($address_name_number != '')
1148 {
1149 $return .= $address_name_number;
1150 }
1151 $address_street = $this->_address_street;
1152 if ($address_street != '')
1153 {
1154 if ($return != '') { $return .= ' '; }
1155 $return .= $address_street;
1156 }
1157 $address_two = $this->_address_two;
1158 $address_three = $this->_address_three;
1159 $address_four = $this->_address_four;
1160 if ($address_two != '')
1161 {
1162 if ($return != '') { $return .= $separator; }
1163 $return .= $address_two;
1164 }
1165 elseif ($address_three != '')
1166 {
1167 if ($return != '') { $return .= $separator; }
1168 $return .= $address_three;
1169 }
1170 elseif ($address_four != '')
1171 {
1172 if ($return != '') { $return .= $separator; }
1173 $return .= $address_four;
1174 }
1175 $address_postcode = $this->_address_postcode;
1176 if ($address_postcode != '')
1177 {
1178 if ($return != '') { $return .= $separator; }
1179 $return .= $address_postcode;
1180 }
1181
1182 if ( $return == '' )
1183 {
1184 $return = $this->post_title;
1185 }
1186
1187 return $return;
1188 }
1189
1190 public function get_office_name()
1191 {
1192 return get_the_title( $this->_office_id );
1193 }
1194
1195 public function get_office_address( $separator = ', ' )
1196 {
1197 $return = '';
1198
1199 for ( $i = 1; $i <= 4; ++$i )
1200 {
1201 $address = get_post_meta( $this->_office_id, '_office_address_' . $i, TRUE );
1202 if ($address != '')
1203 {
1204 if ($return != '') { $return .= $separator; }
1205 $return .= $address;
1206 }
1207 }
1208 $address = get_post_meta( $this->_office_id, '_office_address_postcode', TRUE );
1209 if ($address != '')
1210 {
1211 if ($return != '') { $return .= $separator; }
1212 $return .= $address;
1213 }
1214
1215 return $return;
1216 }
1217
1218 public function get_office_telephone_number()
1219 {
1220 return get_post_meta( $this->_office_id, '_office_telephone_number_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1221 }
1222
1223 public function get_office_email_address()
1224 {
1225 return get_post_meta( $this->_office_id, '_office_email_address_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1226 }
1227
1228 /**
1229 * Returns boolean whether the property is featured or not
1230 *
1231 * @access public
1232 * @return string
1233 */
1234 public function is_featured() {
1235
1236 if (isset($the_property->_featured) && $the_property->_featured == 'yes')
1237 {
1238 return true;
1239 }
1240
1241 return false;
1242
1243 }
1244
1245 /**
1246 * Adds a note (comment) to the property
1247 *
1248 * @access public
1249 * @param string $note Note to add
1250 * @return id Comment ID
1251 */
1252 public function add_note( $note ) {
1253
1254 if ( is_user_logged_in() )
1255 {
1256 $user = get_user_by( 'id', get_current_user_id() );
1257
1258 $commentdata = array(
1259 'comment_post_ID' => $this->id,
1260 'comment_author' => $user->display_name,
1261 'comment_author_email' => $user->user_email,
1262 'comment_author_url' => '',
1263 'comment_content' => $note,
1264 'comment_type' => 'propertyhive_note',
1265 'comment_parent' => 0,
1266 'user_id' => $user->ID,
1267 'comment_agent' => 'PropertyHive',
1268 'comment_date' => current_time('mysql'),
1269 'comment_approved' => 1,
1270 );
1271
1272 $comment_id = wp_insert_comment( $commentdata );
1273
1274 return $comment_id;
1275 }
1276 }
1277
1278
1279
1280
1281 }
1282