PluginProbe
Property Hive / 2.3.0
Property Hive v2.3.0
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 1.4.62 All 260 releases
propertyhive / includes / class-ph-property.php

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

1,593 lines 49.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 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Property; preserving the existing PH_* class name is required for plugin and extension compatibility.
17 class PH_Property {
18
19 /** @public int Property (post) ID */
20 public $id;
21
22 /** @public string Property (post) Title */
23 public $post_title;
24
25 /** @public string Property (post) Status */
26 public $post_status;
27
28 /** @public string Property (post) Excerpt */
29 public $post_excerpt;
30
31 /**
32 * Get the property if ID is passed, otherwise the property is new and empty.
33 *
34 * @access public
35 * @param string|object $id (default: '')
36 * @return void
37 */
38 public function __construct( $id = '' ) {
39 if ( $id != '' )
40 {
41 if ( is_int($id) && $id > 0 )
42 {
43
44 }
45 else
46 {
47 // Must be post object
48 $id = $id->ID;
49 }
50 $this->get_property( $id );
51 }
52 }
53
54 /**
55 * Gets a property from the database.
56 *
57 * @access public
58 * @param int $id (default: 0)
59 * @return bool
60 */
61 public function get_property( $id = 0 ) {
62 if ( ! $id ) {
63 return false;
64 }
65 if ( $result = get_post( $id ) ) {
66 $this->populate( $result );
67 return true;
68 }
69 return false;
70 }
71
72 /**
73 * __isset function.
74 *
75 * @access public
76 * @param mixed $key
77 * @return bool
78 */
79 public function __isset( $key ) {
80 if ( ! $this->id ) {
81 return false;
82 }
83 return metadata_exists( 'post', $this->id, $key );
84 }
85
86 /**
87 * __get function.
88 *
89 * @access public
90 * @param mixed $key
91 * @return mixed
92 */
93 public function __get( $key ) {
94
95 $value = '';
96
97 if ( method_exists($this, 'get_' . $key) && 'available_date' != $key )
98 {
99 $value = $this->{'get_' . $key}();
100 }
101 else
102 {
103 $value = get_post_meta( $this->id, $key, true );
104 if ($value == '')
105 {
106 $value = get_post_meta( $this->id, '_' . $key, true );
107 }
108 // Sanitize stored description HTML before trusted extension callbacks run.
109 // This also protects descriptions saved before the write-boundary checks.
110 if ( preg_match( '/^_?(?:room_(?:name|dimensions|description)|description(?:_name)?)_[0-9]+$/', $key ) ) {
111 $value = is_scalar( $value ) ? (string) $value : '';
112 $value = preg_match( '/^_?(?:room_description|description)_[0-9]+$/', $key ) ? propertyhive_sanitize_description( $value ) : wp_kses_post( $value );
113 }
114 }
115
116 $value = apply_filters( 'propertyhive_get_detail', $value, $key, $this );
117
118 return $value;
119 }
120
121 /**
122 * Populates a property from the loaded post data.
123 *
124 * @access public
125 * @param mixed $result
126 * @return void
127 */
128 public function populate( $result ) {
129 // Standard post data
130 $this->id = $result->ID;
131 $this->post_title = $result->post_title;
132 $this->post_status = $result->post_status;
133 $this->post_excerpt = apply_filters( 'propertyhive_property_post_excerpt', $result->post_excerpt );
134 }
135
136 /**
137 * get_gallery_attachment_ids function.
138 *
139 * @access public
140 * @return array
141 */
142 public function get_gallery_attachment_ids()
143 {
144 $photos = $this->photos;
145 if ( is_array($photos) )
146 {
147 $photos = array_filter( $photos );
148 }
149 else
150 {
151 $photos = array();
152 }
153 return apply_filters( 'propertyhive_property_gallery_attachment_ids', $photos, $this );
154 }
155
156 /**
157 * Gets the first photo
158 *
159 * @access public
160 * @param string $size
161 * @return string
162 */
163 public function get_main_photo_src( $size = 'thumbnail' ) {
164
165 $return = false;
166
167 if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
168 {
169 $photos = $this->_photo_urls;
170
171 if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]) && isset($photos[0]['url']))
172 {
173 $return = $photos[0]['url'];
174 }
175 }
176 else
177 {
178 $photos = $this->_photos;
179
180
181
182 if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]))
183 {
184 $image_attributes = wp_get_attachment_image_src( $photos[0], $size );
185 if( $image_attributes )
186 {
187 $return = $image_attributes[0];
188 }
189 }
190 }
191
192
193 return $return;
194 }
195
196 /**
197 * get_floorplan_attachment_ids function.
198 *
199 * @access public
200 * @return array
201 */
202 public function get_floorplan_attachment_ids()
203 {
204 $floorplans = $this->_floorplans;
205 if ( is_array($floorplans) )
206 {
207 $floorplans = array_filter( $floorplans );
208 }
209 else
210 {
211 $floorplans = array();
212 }
213 return apply_filters( 'propertyhive_property_floorplan_attachment_ids', $floorplans, $this );
214 }
215
216 /**
217 * get_brochure_attachment_ids function.
218 *
219 * @access public
220 * @return array
221 */
222 public function get_brochure_attachment_ids()
223 {
224 $brochures = $this->_brochures;
225 if ( is_array($brochures) )
226 {
227 $brochures = array_filter( $brochures );
228 }
229 else
230 {
231 $brochures = array();
232 }
233 return apply_filters( 'propertyhive_property_brochure_attachment_ids', $brochures, $this );
234 }
235
236 /**
237 * get_epc_attachment_ids function.
238 *
239 * @access public
240 * @return array
241 */
242 public function get_epc_attachment_ids()
243 {
244 $epcs = $this->_epcs;
245 if ( is_array($epcs) )
246 {
247 $epcs = array_filter( $epcs );
248 }
249 else
250 {
251 $epcs = array();
252 }
253 return apply_filters( 'propertyhive_property_epc_attachment_ids', $epcs, $this );
254 }
255
256 /**
257 * get_virtual_tours function.
258 *
259 * @access public
260 * @return array
261 */
262 public function get_virtual_tours()
263 {
264 $num_property_virtual_tours = get_post_meta($this->id, '_virtual_tours', TRUE);
265 if ($num_property_virtual_tours == '') { $num_property_virtual_tours = 0; }
266
267 $virtual_tours = array();
268 for ($i = 0; $i < $num_property_virtual_tours; ++$i)
269 {
270 $label = get_post_meta($this->id, '_virtual_tour_label_' . $i, TRUE);
271 $virtual_tours[] = array(
272 'url' => get_post_meta($this->id, '_virtual_tour_' . $i, TRUE),
273 'label' => ( $label != '' ? $label : __( 'Virtual Tour', 'propertyhive' ) ),
274 );
275 }
276
277 return apply_filters( 'propertyhive_property_virtual_tours', array_filter( $virtual_tours ), $this );
278 }
279
280 /**
281 * get_virtual_tour_urls function.
282 * deprecated
283 *
284 * @access public
285 * @return array
286 */
287 public function get_virtual_tour_urls()
288 {
289 $num_property_virtual_tours = get_post_meta($this->id, '_virtual_tours', TRUE);
290 if ($num_property_virtual_tours == '') { $num_property_virtual_tours = 0; }
291
292 $virtual_tour_urls = array();
293 for ($i = 0; $i < $num_property_virtual_tours; ++$i)
294 {
295 $virtual_tour_urls[] = get_post_meta($this->id, '_virtual_tour_' . $i, TRUE);
296 }
297
298 return apply_filters( 'propertyhive_property_virtual_tour_urls', array_filter( $virtual_tour_urls ), $this );
299 }
300
301 /**
302 * Get the formatted price based on department. Show POA if on frontend and 'POA' ticked
303 *
304 * @access public
305 * @return string
306 */
307 public function get_formatted_price( $plain_text = false ) {
308
309 $return = '';
310
311 $currency = array();
312 $prefix = '';
313 $suffix = '';
314
315 $is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true;
316
317 if ( $this->_department == 'commercial' || ph_get_custom_department_based_on( $this->_department ) == 'commercial' )
318 {
319 if (
320 !$is_admin &&
321 $this->_for_sale == 'yes' && $this->_price_poa == 'yes' &&
322 $this->_to_rent == 'yes' && $this->_rent_poa == 'yes'
323 )
324 {
325 $return = esc_html__( 'POA', 'propertyhive' );
326 }
327 else
328 {
329 // Price Details
330 $price = $this->get_formatted_commercial_price();
331
332 if ( $price != '' && !$plain_text )
333 {
334 $price = '<span class="commercial-price">' . $price . '</span>';
335 }
336
337 // Rent Details
338 $rent = $this->get_formatted_commercial_rent();
339
340 if ( $rent != '' && !$plain_text ) { $rent = '<span class="commercial-rent">' . $rent . '</span>'; }
341
342 if ( $price != '' && $rent != '' )
343 {
344 $price .= !$plain_text ? '<br>' : "\n";
345 }
346 $price .= $rent;
347
348 $return = $price;
349 }
350 }
351 else
352 {
353 if ( !$is_admin && $this->_poa == 'yes')
354 {
355 $return = esc_html__( 'POA', 'propertyhive' );
356 }
357 else
358 {
359 $ph_countries = new PH_Countries();
360
361 if ( !$is_admin )
362 {
363 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Public currency choice only affects displayed prices.
364 if ( isset($_GET['currency']) && is_string( $_GET['currency'] ) )
365 {
366 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Public currency choice only affects displayed prices.
367 $currency_code = sanitize_text_field( wp_unslash( $_GET['currency'] ) );
368 if ( $currency_code != '' )
369 {
370 $requested_currency = $ph_countries->get_currency( $currency_code );
371 if ( $requested_currency !== FALSE )
372 {
373 $currency = $requested_currency;
374 $currency['exchange_rate'] = 1;
375 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
376 if ( isset($exchange_rates[$currency_code]) )
377 {
378 $currency['exchange_rate'] = $exchange_rates[$currency_code];
379 }
380 }
381 }
382 else
383 {
384 $default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
385 if ( $default_currency != '' )
386 {
387 $requested_currency = $ph_countries->get_currency( $default_currency );
388 if ( $requested_currency !== FALSE )
389 {
390 $currency = $requested_currency;
391 $currency['exchange_rate'] = 1;
392 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
393 if ( isset($exchange_rates[$default_currency]) )
394 {
395 $currency['exchange_rate'] = $exchange_rates[$default_currency];
396 }
397 }
398 }
399 }
400 }
401 elseif ( false !== ( $cookie_currency = $ph_countries->get_currency_from_cookie() ) )
402 {
403 $currency = $cookie_currency;
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
425 if ( empty($currency) )
426 {
427 if ($this->_currency != '')
428 {
429 $currency = $ph_countries->get_currency( $this->_currency );
430 }
431 else
432 {
433 $currency = $ph_countries->get_currency( 'GBP' );
434 }
435 }
436 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
437 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
438
439 $department = $this->_department;
440 if ( ph_get_custom_department_based_on( $department ) !== false )
441 {
442 $department = ph_get_custom_department_based_on( $department );
443 }
444 switch ($department)
445 {
446 case "residential-sales":
447 {
448 $price = $this->_price;
449
450 if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' )
451 {
452 // Round this after calculation
453 $price = round($this->_price_actual * $currency['exchange_rate'], 0);
454 }
455
456 $return = ( ( $price != '' ) ? $prefix . esc_html( ph_display_price_field($price, !$is_admin) ) . $suffix : '-' );
457 break;
458 }
459 case "residential-lettings":
460 {
461 $price = $this->_rent;
462 if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' )
463 {
464 // Round this after calculation as we only want to check the first two decimal places
465 $price = round($this->_price_actual * $currency['exchange_rate'], 2);
466 switch ( $this->_rent_frequency )
467 {
468 case "pd": { $price = ($price * 365) / 52; break; }
469 case "pw": { $price = ($price * 12) / 52; break; }
470 case "pq": { $price = ($price * 12) / 4; break; }
471 case "pa": { $price = ($price * 12); break; }
472 }
473 }
474
475 $return = ( ( $price != '' ) ? $prefix . esc_html( ph_display_price_field($price, !$is_admin) ) . $suffix . ' ' . esc_html( propertyhive_get_rent_frequency_label( $this->_rent_frequency ) ) : '-' );
476 break;
477 }
478 }
479 }
480
481 }
482
483 // Stored price/frequency text is escaped above; currency and commercial HTML filters remain trusted.
484 return apply_filters( 'propertyhive_price_output', $return, $this, $currency, $prefix, $suffix );
485 }
486
487 /**
488 * Get the formatted commercial price. Show POA if on frontend and 'POA' ticked
489 *
490 * @access public
491 * @return string
492 */
493 public function get_formatted_commercial_price( ) {
494
495 $price = '';
496
497 if ( $this->_for_sale == 'yes' )
498 {
499 $is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true;
500
501 if ( !$is_admin && $this->_price_poa == 'yes' )
502 {
503 $price .= esc_html__( 'POA', 'propertyhive' );
504 }
505 else
506 {
507 $ph_countries = new PH_Countries();
508 if ( $this->_commercial_price_currency != '' )
509 {
510 $currency = $ph_countries->get_currency( $this->_commercial_price_currency );
511 }
512 else
513 {
514 $currency = $ph_countries->get_currency( 'GBP' );
515 }
516 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
517 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
518
519 if ( $this->_price_from != '' )
520 {
521 $price .= $prefix . esc_html( ph_display_price_field($this->_price_from, !$is_admin) ) . $suffix;
522 }
523 if ( $this->_price_to != '' && $this->_price_to != $this->_price_from )
524 {
525 if ( $price != '' )
526 {
527 $price .= ' - ';
528 }
529 $price .= $prefix . esc_html( ph_display_price_field($this->_price_to, !$is_admin) ) . $suffix;
530 }
531 if ( $price != '' )
532 {
533 $price_units = get_commercial_price_units( );
534 $price .= ( isset($price_units[$this->_price_units]) ) ? ' ' . esc_html( $price_units[$this->_price_units] ) : '';
535 }
536 }
537 }
538
539 // Stored price/unit text is escaped above; preserve trusted currency and price filter HTML.
540 return apply_filters( 'propertyhive_commercial_price_output', $price, $this );
541 }
542
543 /**
544 * Get the formatted commercial rent. Show POA if on frontend and 'POA' ticked
545 *
546 * @access public
547 * @return string
548 */
549 public function get_formatted_commercial_rent( ) {
550
551 $rent = '';
552
553 if ( $this->_to_rent == 'yes' )
554 {
555 $is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true;
556
557 if ( !$is_admin && $this->_rent_poa == 'yes' )
558 {
559 $rent .= esc_html__( 'POA', 'propertyhive' );
560 }
561 else
562 {
563 $ph_countries = new PH_Countries();
564 if ( $this->_commercial_rent_currency != '' )
565 {
566 $currency = $ph_countries->get_currency( $this->_commercial_rent_currency );
567 }
568 else
569 {
570 $currency = $ph_countries->get_currency( 'GBP' );
571 }
572 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
573 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
574
575 if ( $this->_rent_from != '' )
576 {
577 $rent .= $prefix . esc_html( ph_display_price_field($this->_rent_from, !$is_admin) ) . $suffix;
578 }
579 if ( $this->_rent_to != '' && $this->_rent_to != $this->_rent_from )
580 {
581 if ( $rent != '' )
582 {
583 $rent .= ' - ';
584 }
585 $rent .= $prefix . esc_html( ph_display_price_field($this->_rent_to, !$is_admin) ) . $suffix;
586 }
587 if ( $rent != '' )
588 {
589 $price_units = get_commercial_price_units( );
590 $rent .= ' ' . esc_html( isset( $price_units[$this->_rent_units] ) ? $price_units[$this->_rent_units] : $this->_rent_units );
591 }
592 }
593 }
594
595 // Stored rent/unit text is escaped above; preserve trusted currency and rent filter HTML.
596 return apply_filters( 'propertyhive_commercial_rent_output', $rent, $this );
597 }
598
599 public function get_formatted_floor_area( ) {
600
601 $area = '';
602
603 if ( $this->_floor_area_from != '' )
604 {
605 $explode_area = explode(".", $this->_floor_area_from);
606 if ( count($explode_area) == 2 )
607 {
608 $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
609 }
610 else
611 {
612 $area .= number_format((float)$this->_floor_area_from, 0);
613 }
614 }
615 if ( $this->_floor_area_to != '' && $this->_floor_area_to != $this->_floor_area_from )
616 {
617 if ( $area != '' )
618 {
619 $area .= ' - ';
620 }
621 $explode_area = explode(".", $this->_floor_area_to);
622 if ( count($explode_area) == 2 )
623 {
624 $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
625 }
626 else
627 {
628 $area .= number_format((float)$this->_floor_area_to, 0);
629 }
630 }
631
632 if ( $area != '' )
633 {
634 $area_units = get_area_units( );
635 $area .= ( isset($area_units[$this->_floor_area_units]) ) ? ' ' . $area_units[$this->_floor_area_units] : '';
636 }
637
638 return apply_filters( 'propertyhive_floor_area_output', esc_html( $area ), $this );
639
640 }
641
642 public function get_formatted_site_area( ) {
643
644 $area = '';
645
646 if ( $this->_site_area_from != '' )
647 {
648 $explode_area = explode(".", $this->_site_area_from);
649 if ( count($explode_area) == 2 )
650 {
651 $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
652 }
653 else
654 {
655 $area .= number_format((float)$this->_site_area_from, 0);
656 }
657 }
658 if ( $this->_site_area_to != '' && $this->_site_area_to != $this->_site_area_from )
659 {
660 if ( $area != '' )
661 {
662 $area .= ' - ';
663 }
664 $explode_area = explode(".", $this->_site_area_to);
665 if ( count($explode_area) == 2 )
666 {
667 $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
668 }
669 else
670 {
671 $area .= number_format((float)$this->_site_area_to, 0);
672 }
673 }
674
675 if ( $area != '' )
676 {
677 $area_units = get_area_units( );
678 $area .= ( isset($area_units[$this->_site_area_units]) ) ? ' ' . $area_units[$this->_site_area_units] : '';
679 }
680
681 return apply_filters( 'propertyhive_site_area_output', esc_html( $area ), $this );
682
683 }
684
685 /**
686 * Get the formatted deposit
687 *
688 * @access public
689 * @return string
690 */
691 public function get_formatted_deposit( )
692 {
693 if ( $this->_deposit == '' )
694 {
695 return '';
696 }
697
698 $ph_countries = new PH_Countries();
699
700 $currency = $ph_countries->get_currency( $this->_currency );
701
702 $is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true;
703
704 if ( $currency === false )
705 {
706 return ph_display_price_field($this->_deposit, !$is_admin);
707 }
708
709 $prefix = ( !isset($currency['currency_prefix']) || ( isset($currency['currency_prefix']) && $currency['currency_prefix'] ) ) ? $currency['currency_symbol'] : '';
710 $suffix = ( isset($currency['currency_prefix']) && !$currency['currency_prefix'] ) ? $currency['currency_symbol'] : '';
711
712 return $prefix . ph_display_price_field($this->_deposit, !$is_admin) . $suffix;
713 }
714
715 /**
716 * Get the available date, or 'Now' if date is in past
717 *
718 * @access public
719 * @return string
720 */
721 public function get_available_date( )
722 {
723 if ( $this->_available_date == '' )
724 {
725 return '';
726 }
727
728 if (strtotime($this->_available_date) > time())
729 {
730 return gmdate( get_option( 'date_format' ), strtotime($this->_available_date) );
731 }
732 else
733 {
734 return __( 'Now', 'propertyhive' );
735 }
736 }
737
738 /**
739 * Get the full description by constructing the rooms or commercial description (dependant on department)
740 *
741 * @access public
742 * @return string
743 */
744 public function get_formatted_description( $plain_text = false ) {
745
746 $department = $this->_department;
747 if ( ph_get_custom_department_based_on( $department ) !== false )
748 {
749 $department = ph_get_custom_department_based_on( $department );
750 }
751 if ( $department == 'commercial' )
752 {
753 $description = $this->get_formatted_descriptions( $plain_text ); // Haven't called this commercial_descriptions as we might use generic descriptions for other areas going forward
754 }
755 else
756 {
757 $description = $this->get_formatted_rooms( $plain_text );
758 }
759
760 return apply_filters( 'propertyhive_description_output', $description );
761 }
762
763 /**
764 * Get the full description by constructing the rooms
765 *
766 * @access public
767 * @return string
768 */
769 public function get_formatted_rooms( $plain_text = false ) {
770
771 $rooms = $this->_rooms;
772
773 $return = '';
774
775 if (isset($rooms) && $rooms != '' && $rooms > 0)
776 {
777 for ($i = 0; $i < $rooms; ++$i)
778 {
779 if ( !$plain_text )
780 {
781 $return .= '<p class="room">';
782 if ($this->{'_room_name_' . $i} != '')
783 {
784 $return .= '<strong class="name">' . $this->{'_room_name_' . $i} . '</strong>';
785 }
786 if ($this->{'_room_dimensions_' . $i} != '')
787 {
788 $return .= '&nbsp;<span class="dimension">' . $this->{'_room_dimensions_' . $i} . '</span>';
789 }
790 if ($this->{'_room_name_' . $i} != '' || $this->{'_room_dimensions_' . $i} != '')
791 {
792 $return .= '<br>';
793 }
794 $return .= str_replace("\r\n", "", nl2br($this->{'_room_description_' . $i})) . '</p>';
795 }
796 else
797 {
798 if ($this->{'_room_name_' . $i} != '')
799 {
800 $return .= $this->{'_room_name_' . $i};
801 }
802 if ($this->{'_room_dimensions_' . $i} != '')
803 {
804 $return .= ' ' . $this->{'_room_dimensions_' . $i};
805 }
806 if ($this->{'_room_name_' . $i} != '' || $this->{'_room_dimensions_' . $i} != '')
807 {
808 $return .= "\n";
809 }
810 $return .= wp_strip_all_tags($this->{'_room_description_' . $i}) . "\n\n";
811 }
812 }
813 }
814
815 return $return;
816 }
817
818 /**
819 * Get the full description by constructing the descriptions
820 *
821 * @access public
822 * @return string
823 */
824 public function get_formatted_descriptions( $plain_text = false ) {
825
826 $descriptions = $this->_descriptions;
827
828 $return = '';
829
830 if (isset($descriptions) && $descriptions != '' && $descriptions > 0)
831 {
832 for ($i = 0; $i < $descriptions; ++$i)
833 {
834 if ( !$plain_text )
835 {
836 $return .= '<p class="description-section';
837 if ($this->{'_description_name_' . $i} != '')
838 {
839 $return .= ' description-section-' . esc_attr(sanitize_title($this->{'_description_name_' . $i}));
840 }
841 $return .= '">';
842 if ($this->{'_description_name_' . $i} != '')
843 {
844 $return .= '<strong class="description-title">' . $this->{'_description_name_' . $i} . '</strong><br>';
845 }
846 $return .= str_replace("\r\n", "", nl2br($this->{'_description_' . $i})) . '</p>';
847 }
848 else
849 {
850 if ($this->{'_description_name_' . $i} != '')
851 {
852 $return .= $this->{'_description_name_' . $i} . "\n";
853 }
854 $return .= wp_strip_all_tags($this->{'_description_' . $i}) . "\n\n";
855 }
856 }
857 }
858
859 return $return;
860 }
861
862 /**
863 * Get the property type taxononmy
864 *
865 * @access public
866 * @return string
867 */
868 public function get_property_type()
869 {
870 $term_list = wp_get_post_terms($this->id, ( ( $this->_department == 'commercial' || ph_get_custom_department_based_on( $this->_department ) == 'commercial' ) ? 'commercial_' : '' ) . 'property_type', array("fields" => "names"));
871
872 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
873 {
874 return implode(", ", $term_list);
875 }
876
877 return '';
878 }
879
880 /**
881 * Get the availability taxononmy
882 *
883 * @access public
884 * @return string
885 */
886 public function get_availability()
887 {
888 $term_list = wp_get_post_terms($this->id, 'availability', array("fields" => "names"));
889
890 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
891 {
892 return implode(", ", $term_list);
893 }
894
895 return '';
896 }
897
898 /**
899 * Get the location taxononmy
900 *
901 * @access public
902 * @return string
903 */
904 public function get_location()
905 {
906 $term_list = wp_get_post_terms($this->id, 'location', array("fields" => "names"));
907
908 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
909 {
910 return implode(", ", $term_list);
911 }
912
913 return '';
914 }
915
916 /**
917 * Get the price qualifier taxononmy
918 *
919 * @access public
920 * @return string
921 */
922 public function get_price_qualifier()
923 {
924 $term_list = wp_get_post_terms($this->id, 'price_qualifier', array("fields" => "names"));
925
926 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
927 {
928 return implode(", ", $term_list);
929 }
930
931 return '';
932 }
933
934 /**
935 * Get the tenure taxononmy
936 *
937 * @access public
938 * @return string
939 */
940 public function get_tenure()
941 {
942 $term_list = wp_get_post_terms($this->id, ( ( $this->_department == 'commercial' || ph_get_custom_department_based_on( $this->_department ) == 'commercial' ) ? 'commercial_' : '' ) . 'tenure', array("fields" => "names"));
943
944 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
945 {
946 return implode(", ", $term_list);
947 }
948
949 return '';
950 }
951
952 /**
953 * Get the sale by taxononmy
954 *
955 * @access public
956 * @return string
957 */
958 public function get_sale_by()
959 {
960 $term_list = wp_get_post_terms($this->id, 'sale_by', array("fields" => "names"));
961
962 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
963 {
964 return implode(", ", $term_list);
965 }
966
967 return '';
968 }
969
970 /**
971 * Get the furnished taxononmy
972 *
973 * @access public
974 * @return string
975 */
976 public function get_furnished()
977 {
978 $term_list = wp_get_post_terms($this->id, 'furnished', array("fields" => "names"));
979
980 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
981 {
982 return implode(", ", $term_list);
983 }
984
985 return '';
986 }
987
988 /**
989 * Get the parking taxononmy
990 *
991 * @access public
992 * @return string
993 */
994 public function get_parking()
995 {
996 $term_list = wp_get_post_terms($this->id, 'parking', array("fields" => "names"));
997
998 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
999 {
1000 return implode(", ", $term_list);
1001 }
1002
1003 return '';
1004 }
1005
1006 /**
1007 * Get the outside space taxononmy
1008 *
1009 * @access public
1010 * @return string
1011 */
1012 public function get_outside_space()
1013 {
1014 $term_list = wp_get_post_terms($this->id, 'outside_space', array("fields" => "names"));
1015
1016 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
1017 {
1018 return implode(", ", $term_list);
1019 }
1020
1021 return '';
1022 }
1023
1024 /**
1025 * Get the marketing flag taxononmy
1026 *
1027 * @access public
1028 * @return string
1029 */
1030 public function get_marketing_flag()
1031 {
1032 $term_list = wp_get_post_terms($this->id, 'marketing_flag', array("fields" => "names"));
1033
1034 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
1035 {
1036 return implode(", ", $term_list);
1037 }
1038
1039 return '';
1040 }
1041
1042 /**
1043 * Get the ID of property from third party system
1044 *
1045 * @access public
1046 * @return string
1047 */
1048 public function get_imported_id()
1049 {
1050 // Use WordPress's metadata cache and match the literal importer-key prefix.
1051 foreach ( get_post_meta( $this->id ) as $key => $values ) {
1052 if ( 0 === strpos( $key, '_imported_ref_' ) && isset( $values[0] ) ) {
1053 return $values[0];
1054 }
1055 }
1056 return '';
1057 }
1058
1059 /**
1060 * Get an array of property features
1061 *
1062 * @access public
1063 * @return array
1064 */
1065 public function get_features( )
1066 {
1067 $features = array();
1068
1069 if ( get_option('propertyhive_features_type') == 'checkbox' )
1070 {
1071 $term_list = wp_get_post_terms($this->id, 'property_feature', array("fields" => "names"));
1072 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
1073 {
1074 foreach ( $term_list as $term_name )
1075 {
1076 $features[] = trim($term_name);
1077 }
1078 }
1079 }
1080 else
1081 {
1082 $num_property_features = $this->_features;
1083 if ($num_property_features == '') { $num_property_features = 0; }
1084
1085 for ($i = 0; $i < $num_property_features; ++$i)
1086 {
1087 if ( trim($this->{'_feature_' . $i}) != '' )
1088 {
1089 $features[] = trim($this->{'_feature_' . $i});
1090 }
1091 }
1092 }
1093
1094 return apply_filters( 'propertyhive_property_features', $features );
1095 }
1096
1097 /**
1098 * Get the full formatted address
1099 *
1100 * @access public
1101 * @return string
1102 */
1103 public function get_formatted_full_address( $separator = ', ' ) {
1104 // Standard post data
1105
1106 $return = '';
1107
1108 $address_name_number = $this->_address_name_number;
1109 if ($address_name_number != '')
1110 {
1111 $return .= $address_name_number;
1112 }
1113 $address_street = $this->_address_street;
1114 if ($address_street != '')
1115 {
1116 if ($return != '') { $return .= ' '; }
1117 $return .= $address_street;
1118 }
1119 $address_two = $this->_address_two;
1120 if ($address_two != '')
1121 {
1122 if ($return != '') { $return .= $separator; }
1123 $return .= $address_two;
1124 }
1125 $address_three = $this->_address_three;
1126 if ($address_three != '')
1127 {
1128 if ($return != '') { $return .= $separator; }
1129 $return .= $address_three;
1130 }
1131 $address_four = $this->_address_four;
1132 if ($address_four != '')
1133 {
1134 if ($return != '') { $return .= $separator; }
1135 $return .= $address_four;
1136 }
1137 $address_postcode = $this->_address_postcode;
1138 if ($address_postcode != '')
1139 {
1140 if ($return != '') { $return .= $separator; }
1141 $return .= $address_postcode;
1142 }
1143
1144 if ( $return == '' )
1145 {
1146 $return = $this->post_title;
1147 }
1148
1149 return $return;
1150 }
1151
1152 /**
1153 * Get the summary formatted address
1154 *
1155 * @access public
1156 * @return string
1157 */
1158 public function get_formatted_summary_address( $separator = ', ' ) {
1159 // Standard post data
1160
1161 $return = '';
1162
1163 $address_name_number = $this->_address_name_number;
1164 if ($address_name_number != '')
1165 {
1166 $return .= $address_name_number;
1167 }
1168 $address_street = $this->_address_street;
1169 if ($address_street != '')
1170 {
1171 if ($return != '') { $return .= ' '; }
1172 $return .= $address_street;
1173 }
1174 $address_two = $this->_address_two;
1175 $address_three = $this->_address_three;
1176 $address_four = $this->_address_four;
1177 if ($address_two != '')
1178 {
1179 if ($return != '') { $return .= $separator; }
1180 $return .= $address_two;
1181 }
1182 elseif ($address_three != '')
1183 {
1184 if ($return != '') { $return .= $separator; }
1185 $return .= $address_three;
1186 }
1187 elseif ($address_four != '')
1188 {
1189 if ($return != '') { $return .= $separator; }
1190 $return .= $address_four;
1191 }
1192 $address_postcode = $this->_address_postcode;
1193 if ($address_postcode != '')
1194 {
1195 if ($return != '') { $return .= $separator; }
1196 $return .= $address_postcode;
1197 }
1198
1199 if ( $return == '' )
1200 {
1201 $return = $this->post_title;
1202 }
1203
1204 return $return;
1205 }
1206
1207 public function get_material_information()
1208 {
1209 $return = array();
1210
1211 $utilities = array();
1212
1213 // Utilities
1214 $utility_types = array(
1215 'electricity' => __( 'Electricity Type', 'propertyhive' ),
1216 'water' => __( 'Water Type', 'propertyhive' ),
1217 'heating' => __( 'Heating Type', 'propertyhive' ),
1218 'broadband' => __( 'Broadband Type', 'propertyhive' ),
1219 'sewerage' => __( 'Sewerage Type', 'propertyhive' ),
1220 );
1221 foreach ( $utility_types as $utility_key => $utility_label )
1222 {
1223 $property_utility_types = $this->{'_' . $utility_key . '_type'};
1224 if ( is_array($property_utility_types) && !empty($property_utility_types) )
1225 {
1226 $types = array();
1227 foreach ( $property_utility_types as $type )
1228 {
1229 if ( $type == 'other' )
1230 {
1231 $types[] = $this->{'_' . $utility_key . '_type_other'};
1232 }
1233 else
1234 {
1235 $function_name = "get_{$utility_key}_type";
1236
1237 if ( function_exists($function_name) )
1238 {
1239 $types[] = $function_name($type);
1240 }
1241 else
1242 {
1243 $types[] = $type;
1244 }
1245 }
1246 }
1247 if ( !isset($utilities[$utility_key]) ) { $utilities[$utility_key] = array(); }
1248 $utilities[$utility_key] = implode(", ", $types);
1249 }
1250 }
1251
1252 if ( !empty($utilities) )
1253 {
1254 $return['utilities'] = $utilities;
1255 }
1256
1257 // Accessibility
1258 $accessibility = array();
1259
1260 $property_accessibility = $this->_accessibility;
1261 if ( is_array($property_accessibility) && !empty($property_accessibility) )
1262 {
1263 foreach ( $property_accessibility as $type )
1264 {
1265 if ( $type == 'other' )
1266 {
1267 $accessibility[] = $this->_accessibility_other;
1268 }
1269 else
1270 {
1271 $function_name = "get_accessibility_type";
1272
1273 if ( function_exists($function_name) )
1274 {
1275 $accessibility[] = $function_name($type);
1276 }
1277 else
1278 {
1279 $accessibility[] = $type;
1280 }
1281 }
1282 }
1283 }
1284
1285 if ( !empty($accessibility) )
1286 {
1287 $return['accessibility'] = implode(", ", $accessibility);
1288 }
1289
1290 // Restrictions
1291 $restrictions = array();
1292
1293 $property_restriction = $this->_restriction;
1294 if ( is_array($property_restriction) && !empty($property_restriction) )
1295 {
1296 foreach ( $property_restriction as $type )
1297 {
1298 if ( $type == 'other' )
1299 {
1300 $restrictions[] = $this->_restriction_other;
1301 }
1302 else
1303 {
1304 $function_name = "get_restriction";
1305
1306 if ( function_exists($function_name) )
1307 {
1308 $restrictions[] = $function_name($type);
1309 }
1310 else
1311 {
1312 $restrictions[] = $type;
1313 }
1314 }
1315 }
1316 }
1317
1318 if ( !empty($restrictions) )
1319 {
1320 $return['restrictions'] = implode(", ", $restrictions);
1321 }
1322
1323 // Rights & Easements
1324 $rights = array();
1325
1326 $property_right = $this->_right;
1327 if ( is_array($property_right) && !empty($property_right) )
1328 {
1329 foreach ( $property_right as $type )
1330 {
1331 if ( $type == 'other' )
1332 {
1333 $rights[] = $this->_right_other;
1334 }
1335 else
1336 {
1337 $function_name = "get_right";
1338
1339 if ( function_exists($function_name) )
1340 {
1341 $rights[] = $function_name($type);
1342 }
1343 else
1344 {
1345 $rights[] = $type;
1346 }
1347 }
1348 }
1349 }
1350
1351 if ( !empty($rights) )
1352 {
1353 $return['rights'] = implode(", ", $rights);
1354 }
1355
1356 // Flood Risk
1357 $flood_data = array();
1358
1359 $property_flood_data = $this->_flooded_in_last_five_years;
1360 if ( !empty($property_flood_data) )
1361 {
1362 $flood_data['flooded_in_last_five_years'] = ucfirst($property_flood_data);
1363 }
1364
1365 $flood_sources = array();
1366
1367 $property_flood_source_type = $this->_flood_source_type;
1368 if ( is_array($property_flood_source_type) && !empty($property_flood_source_type) )
1369 {
1370 foreach ( $property_flood_source_type as $type )
1371 {
1372 if ( $type == 'other' )
1373 {
1374 $flood_sources[] = $this->_flood_source_type_other;
1375 }
1376 else
1377 {
1378 $function_name = "get_flooding_source_type";
1379
1380 if ( function_exists($function_name) )
1381 {
1382 $flood_sources[] = $function_name($type);
1383 }
1384 else
1385 {
1386 $flood_sources[] = $type;
1387 }
1388 }
1389 }
1390 }
1391
1392 if ( !empty($flood_sources) )
1393 {
1394 $flood_data['flood_source'] = implode(", ", $flood_sources);
1395 }
1396
1397 $property_flood_data = $this->_flood_defences;
1398 if ( !empty($property_flood_data) )
1399 {
1400 $flood_data['flood_defences'] = ucfirst($property_flood_data);
1401 }
1402
1403 if ( !empty($flood_data) )
1404 {
1405 $return['flood_risk'] = $flood_data;
1406 }
1407
1408 $return = apply_filters( 'propertyhive_property_material_information', $return, $this );
1409
1410 return $return;
1411 }
1412
1413 public function get_office_name()
1414 {
1415 return get_the_title( $this->_office_id );
1416 }
1417
1418 public function get_office_address( $separator = ', ' )
1419 {
1420 $return = '';
1421
1422 for ( $i = 1; $i <= 4; ++$i )
1423 {
1424 $address = get_post_meta( $this->_office_id, '_office_address_' . $i, TRUE );
1425 if ($address != '')
1426 {
1427 if ($return != '') { $return .= $separator; }
1428 $return .= $address;
1429 }
1430 }
1431 $address = get_post_meta( $this->_office_id, '_office_address_postcode', TRUE );
1432 if ($address != '')
1433 {
1434 if ($return != '') { $return .= $separator; }
1435 $return .= $address;
1436 }
1437
1438 return $return;
1439 }
1440
1441 public function get_office_telephone_number()
1442 {
1443 return get_post_meta( $this->_office_id, '_office_telephone_number_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1444 }
1445
1446 public function get_office_email_address()
1447 {
1448 return get_post_meta( $this->_office_id, '_office_email_address_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1449 }
1450
1451 public function get_negotiator_name()
1452 {
1453 if ( empty($this->_negotiator_id) )
1454 {
1455 return '';
1456 }
1457
1458 $user = get_userdata( $this->_negotiator_id );
1459
1460 if ( $user === false )
1461 {
1462 return '';
1463 }
1464
1465 return $user->display_name;
1466 }
1467
1468 public function get_negotiator_telephone_number( $fallback_to_office = true )
1469 {
1470 if ( empty($this->_negotiator_id) )
1471 {
1472 return '';
1473 }
1474
1475 $user = get_userdata( $this->_negotiator_id );
1476
1477 if ( $user === false )
1478 {
1479 return '';
1480 }
1481
1482 $telephone_number = get_user_meta( $this->_negotiator_id, 'telephone_number', true );
1483
1484 if ( empty($telephone_number) && $fallback_to_office )
1485 {
1486 // need to fallback
1487 $telephone_number = $this->get_office_telephone_number();
1488 }
1489
1490 return $telephone_number;
1491 }
1492
1493 public function get_negotiator_email_address( $fallback_to_office = true )
1494 {
1495 if ( empty($this->_negotiator_id) )
1496 {
1497 return '';
1498 }
1499
1500 $user = get_userdata( $this->_negotiator_id );
1501
1502 if ( $user === false )
1503 {
1504 return '';
1505 }
1506
1507 $email_address = $user->user_email;
1508
1509 if ( empty($email_address) && $fallback_to_office )
1510 {
1511 // need to fallback
1512 $email_address = $this->get_office_email_address();
1513 }
1514
1515 return $email_address;
1516 }
1517
1518 public function get_negotiator_photo()
1519 {
1520 if ( empty($this->_negotiator_id) )
1521 {
1522 return '';
1523 }
1524
1525 $user = get_userdata( $this->_negotiator_id );
1526
1527 if ( $user === false )
1528 {
1529 return '';
1530 }
1531
1532 $photo_attachment_id = get_user_meta( $this->_negotiator_id, 'photo_attachment_id', true );
1533
1534 $photo = wp_get_attachment_image( $photo_attachment_id, 'large' );
1535
1536 return $photo;
1537 }
1538
1539 /**
1540 * Returns boolean whether the property is featured or not
1541 *
1542 * @access public
1543 * @return string
1544 */
1545 public function is_featured() {
1546
1547 if ( $this->_featured == 'yes' )
1548 {
1549 return true;
1550 }
1551
1552 return false;
1553
1554 }
1555
1556 /**
1557 * Adds a note (comment) to the property
1558 *
1559 * @access public
1560 * @param string $note Note to add
1561 * @return id Comment ID
1562 */
1563 public function add_note( $note ) {
1564
1565 if ( is_user_logged_in() )
1566 {
1567 $user = get_user_by( 'id', get_current_user_id() );
1568
1569 $commentdata = array(
1570 'comment_post_ID' => $this->id,
1571 'comment_author' => $user->display_name,
1572 'comment_author_email' => $user->user_email,
1573 'comment_author_url' => '',
1574 'comment_content' => $note,
1575 'comment_type' => 'propertyhive_note',
1576 'comment_parent' => 0,
1577 'user_id' => $user->ID,
1578 'comment_agent' => 'PropertyHive',
1579 'comment_date' => current_time('mysql'),
1580 'comment_approved' => 1,
1581 );
1582
1583 $comment_id = wp_insert_comment( $commentdata );
1584
1585 return $comment_id;
1586 }
1587 }
1588
1589
1590
1591
1592 }
1593