PluginProbe
Property Hive / 2.3.1
Property Hive v2.3.1
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
← All changes | includes/class-ph-property.php +573 -191 1.4.62.3.1 View file →
@@ -12,13 +12,23 @@
12 12 * @package PropertyHive/Classes
13 13 * @category Class
14 14 * @author PropertyHive
15 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.
16 17 class PH_Property {
17 18
18 19 /** @public int Property (post) ID */
19 20 public $id;
20 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 +
21 31 /**
22 32 * Get the property if ID is passed, otherwise the property is new and empty.
23 33 *
24 34 * @access public
@@ -81,71 +91,31 @@
81 91 * @return mixed
82 92 */
83 93 public function __get( $key ) {
84 94
85 - if ( 'property_type' == $key )
95 + $value = '';
96 +
97 + if ( method_exists($this, 'get_' . $key) && 'available_date' != $key )
86 98 {
87 - return $this->get_property_type();
99 + $value = $this->{'get_' . $key}();
88 100 }
89 - if ( 'availability' == $key )
101 + else
90 102 {
91 - return $this->get_availability();
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 + }
92 114 }
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 ( 'office_name' == $key )
126 - {
127 - return $this->get_office_name();
128 - }
129 - if ( 'office_address' == $key )
130 - {
131 - return $this->get_office_address();
132 - }
133 - if ( 'office_telephone_number' == $key )
134 - {
135 - return $this->get_office_telephone_number();
136 - }
137 - if ( 'office_email_address' == $key )
138 - {
139 - return $this->get_office_email_address();
140 - }
115 +
116 + $value = apply_filters( 'propertyhive_get_detail', $value, $key, $this );
141 117
142 - // Get values or default if not set
143 - $value = get_post_meta( $this->id, $key, true );
144 - if ($value == '')
145 - {
146 - $value = get_post_meta( $this->id, '_' . $key, true );
147 - }
148 118 return $value;
149 119 }
150 120
151 121 /**
@@ -159,9 +129,9 @@
159 129 // Standard post data
160 130 $this->id = $result->ID;
161 131 $this->post_title = $result->post_title;
162 132 $this->post_status = $result->post_status;
163 - $this->post_excerpt = $result->post_excerpt;
133 + $this->post_excerpt = apply_filters( 'propertyhive_property_post_excerpt', $result->post_excerpt );
164 134 }
165 135
166 136 /**
167 137 * get_gallery_attachment_ids function.
@@ -190,22 +160,37 @@
190 160 * @param string $size
191 161 * @return string
192 162 */
193 163 public function get_main_photo_src( $size = 'thumbnail' ) {
194 -
195 - $photos = $this->_photos;
196 164
197 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;
198 179
199 - if (isset($photos) && is_array($photos) && !empty($photos))
200 - {
201 - $image_attributes = wp_get_attachment_image_src( $photos[0], $size );
202 - if( $image_attributes )
180 +
181 +
182 + if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]))
203 183 {
204 - $return = $image_attributes[0];
184 + $image_attributes = wp_get_attachment_image_src( $photos[0], $size );
185 + if( $image_attributes )
186 + {
187 + $return = $image_attributes[0];
188 + }
205 189 }
206 190 }
207 191
192 +
208 193 return $return;
209 194 }
210 195
211 196 /**
@@ -268,9 +253,34 @@
268 253 return apply_filters( 'propertyhive_property_epc_attachment_ids', $epcs, $this );
269 254 }
270 255
271 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 + /**
272 281 * get_virtual_tour_urls function.
282 + * deprecated
273 283 *
274 284 * @access public
275 285 * @return array
276 286 */
@@ -293,54 +303,80 @@
293 303 *
294 304 * @access public
295 305 * @return string
296 306 */
297 - public function get_formatted_price( ) {
307 + public function get_formatted_price( $plain_text = false ) {
298 308
299 - if ( $this->_department == 'commercial' )
300 - {
301 - $price = '';
309 + $return = '';
302 310
303 - // Price Details
304 - $price .= $this->get_formatted_commercial_price();
311 + $currency = array();
312 + $prefix = '';
313 + $suffix = '';
305 314
306 - // Rent Details
307 - $rent = $this->get_formatted_commercial_rent();
308 - if ( $price != '' && $rent != '' )
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 + )
309 324 {
310 - $price .= '<br>';
325 + $return = esc_html__( 'POA', 'propertyhive' );
311 326 }
312 - $price .= $rent;
327 + else
328 + {
329 + // Price Details
330 + $price = $this->get_formatted_commercial_price();
313 331
314 - return $price;
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 + }
315 350 }
316 351 else
317 352 {
318 - if (!is_admin() && $this->_poa == 'yes')
353 + if ( !$is_admin && $this->_poa == 'yes')
319 354 {
320 - return __( 'POA', 'propertyhive' );
355 + $return = esc_html__( 'POA', 'propertyhive' );
321 356 }
322 357 else
323 358 {
324 359 $ph_countries = new PH_Countries();
325 360
326 - $currency = array();
327 -
328 - if ( !is_admin() )
361 + if ( !$is_admin )
329 362 {
330 - if ( isset($_GET['currency']) )
363 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Public currency choice only affects displayed prices.
364 + if ( isset($_GET['currency']) && is_string( $_GET['currency'] ) )
331 365 {
332 - if ( $_GET['currency'] != '' )
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 != '' )
333 369 {
334 - $requested_currency = $ph_countries->get_currency( $_GET['currency'] );
370 + $requested_currency = $ph_countries->get_currency( $currency_code );
335 371 if ( $requested_currency !== FALSE )
336 372 {
337 373 $currency = $requested_currency;
338 374 $currency['exchange_rate'] = 1;
339 375 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
340 - if ( isset($exchange_rates[$_GET['currency']]) )
376 + if ( isset($exchange_rates[$currency_code]) )
341 377 {
342 - $currency['exchange_rate'] = $exchange_rates[$_GET['currency']];
378 + $currency['exchange_rate'] = $exchange_rates[$currency_code];
343 379 }
344 380 }
345 381 }
346 382 else
@@ -361,11 +397,11 @@
361 397 }
362 398 }
363 399 }
364 400 }
365 - elseif ( isset($_COOKIE['propertyhive_currency']) && $_COOKIE['propertyhive_currency'] != '' )
401 + elseif ( false !== ( $cookie_currency = $ph_countries->get_currency_from_cookie() ) )
366 402 {
367 - $currency = unserialize(html_entity_decode($_COOKIE['propertyhive_currency']));
403 + $currency = $cookie_currency;
368 404 }
369 405 else
370 406 {
371 407 $default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
@@ -398,41 +434,55 @@
398 434 }
399 435 }
400 436 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
401 437 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
402 - switch ($this->_department)
438 +
439 + $department = $this->_department;
440 + if ( ph_get_custom_department_based_on( $department ) !== false )
403 441 {
442 + $department = ph_get_custom_department_based_on( $department );
443 + }
444 + switch ($department)
445 + {
404 446 case "residential-sales":
405 447 {
406 448 $price = $this->_price;
407 - if ( isset($currency['exchange_rate']) && $price != '' )
449 +
450 + if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' )
408 451 {
409 - $price = $this->_price_actual * $currency['exchange_rate'];
452 + // Round this after calculation
453 + $price = round($this->_price_actual * $currency['exchange_rate'], 0);
410 454 }
411 - return ( ( $price != '' ) ? $prefix . number_format($price , 0) . $suffix : '-' );
455 +
456 + $return = ( ( $price != '' ) ? $prefix . esc_html( ph_display_price_field($price, !$is_admin) ) . $suffix : '-' );
412 457 break;
413 458 }
414 459 case "residential-lettings":
415 460 {
416 461 $price = $this->_rent;
417 - if ( isset($currency['exchange_rate']) && $price != '' )
462 + if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' )
418 463 {
419 - $price = $this->_price_actual * $currency['exchange_rate'];
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);
420 466 switch ( $this->_rent_frequency )
421 467 {
468 + case "pd": { $price = ($price * 365) / 52; break; }
422 469 case "pw": { $price = ($price * 12) / 52; break; }
423 470 case "pq": { $price = ($price * 12) / 4; break; }
424 471 case "pa": { $price = ($price * 12); break; }
425 472 }
426 473 }
427 - return ( ( $price != '' ) ? $prefix . number_format($price, 0) . $suffix . ' ' . __( $this->_rent_frequency, 'propertyhive' ) : '-' );
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 ) ) : '-' );
428 476 break;
429 477 }
430 478 }
431 479 }
480 +
432 481 }
433 482
434 - return '';
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 );
435 485 }
436 486
437 487 /**
438 488 * Get the formatted commercial price. Show POA if on frontend and 'POA' ticked
@@ -445,11 +495,13 @@
445 495 $price = '';
446 496
447 497 if ( $this->_for_sale == 'yes' )
448 498 {
449 - if ( !is_admin() && $this->_price_poa == 'yes' )
499 + $is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true;
500 +
501 + if ( !$is_admin && $this->_price_poa == 'yes' )
450 502 {
451 - $price .= __( 'POA', 'propertyhive' );
503 + $price .= esc_html__( 'POA', 'propertyhive' );
452 504 }
453 505 else
454 506 {
455 507 $ph_countries = new PH_Countries();
@@ -465,17 +517,9 @@
465 517 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
466 518
467 519 if ( $this->_price_from != '' )
468 520 {
469 - $explode_price = explode(".", $this->_price_from);
470 - if ( count($explode_price) == 2 )
471 - {
472 - $price .= $prefix . number_format($explode_price[0], 0) . '.' . $explode_price[1] . $suffix;
473 - }
474 - else
475 - {
476 - $price .= $prefix . number_format($this->_price_from, 0) . $suffix;
477 - }
521 + $price .= $prefix . esc_html( ph_display_price_field($this->_price_from, !$is_admin) ) . $suffix;
478 522 }
479 523 if ( $this->_price_to != '' && $this->_price_to != $this->_price_from )
480 524 {
481 525 if ( $price != '' )
@@ -481,27 +525,20 @@
481 525 if ( $price != '' )
482 526 {
483 527 $price .= ' - ';
484 528 }
485 - $explode_price = explode(".", $this->_price_to);
486 - if ( count($explode_price) == 2 )
487 - {
488 - $price .= $prefix . number_format($explode_price[0], 0) . '.' . $explode_price[1] . $suffix;
489 - }
490 - else
491 - {
492 - $price .= $prefix . number_format($this->_price_to, 0) . $suffix;
493 - }
529 + $price .= $prefix . esc_html( ph_display_price_field($this->_price_to, !$is_admin) ) . $suffix;
494 530 }
495 531 if ( $price != '' )
496 532 {
497 533 $price_units = get_commercial_price_units( );
498 - $price .= ( isset($price_units[$this->_price_units]) ) ? ' ' . $price_units[$this->_price_units] : '';
534 + $price .= ( isset($price_units[$this->_price_units]) ) ? ' ' . esc_html( $price_units[$this->_price_units] ) : '';
499 535 }
500 536 }
501 537 }
502 538
503 - return $price;
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 );
504 541 }
505 542
506 543 /**
507 544 * Get the formatted commercial rent. Show POA if on frontend and 'POA' ticked
@@ -514,11 +551,13 @@
514 551 $rent = '';
515 552
516 553 if ( $this->_to_rent == 'yes' )
517 554 {
518 - if ( !is_admin() && $this->_rent_poa == 'yes' )
555 + $is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true;
556 +
557 + if ( !$is_admin && $this->_rent_poa == 'yes' )
519 558 {
520 - $rent .= __( 'POA', 'propertyhive' );
559 + $rent .= esc_html__( 'POA', 'propertyhive' );
521 560 }
522 561 else
523 562 {
524 563 $ph_countries = new PH_Countries();
@@ -534,17 +573,9 @@
534 573 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
535 574
536 575 if ( $this->_rent_from != '' )
537 576 {
538 - $explode_rent = explode(".", $this->_rent_from);
539 - if ( count($explode_rent) == 2 )
540 - {
541 - $rent .= $prefix . number_format($explode_rent[0], 0) . '.' . $explode_rent[1] . $suffix;
542 - }
543 - else
544 - {
545 - $rent .= $prefix . number_format($this->_rent_from, 0) . $suffix;
546 - }
577 + $rent .= $prefix . esc_html( ph_display_price_field($this->_rent_from, !$is_admin) ) . $suffix;
547 578 }
548 579 if ( $this->_rent_to != '' && $this->_rent_to != $this->_rent_from )
549 580 {
550 581 if ( $rent != '' )
@@ -550,27 +581,20 @@
550 581 if ( $rent != '' )
551 582 {
552 583 $rent .= ' - ';
553 584 }
554 - $explode_rent = explode(".", $this->_rent_to);
555 - if ( count($explode_rent) == 2 )
556 - {
557 - $rent .= $prefix . number_format($explode_rent[0], 0) . '.' . $explode_rent[1] . $suffix;
558 - }
559 - else
560 - {
561 - $rent .= $prefix . number_format($this->_rent_to, 0) . $suffix;
562 - }
585 + $rent .= $prefix . esc_html( ph_display_price_field($this->_rent_to, !$is_admin) ) . $suffix;
563 586 }
564 587 if ( $rent != '' )
565 588 {
566 589 $price_units = get_commercial_price_units( );
567 - $rent .= ' ' . ( isset($price_units[$this->_rent_units]) ? $price_units[$this->_rent_units] : $this->_rent_units );
590 + $rent .= ' ' . esc_html( isset( $price_units[$this->_rent_units] ) ? $price_units[$this->_rent_units] : $this->_rent_units );
568 591 }
569 592 }
570 593 }
571 594
572 - return $rent;
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 );
573 597 }
574 598
575 599 public function get_formatted_floor_area( ) {
576 600
@@ -580,13 +604,13 @@
580 604 {
581 605 $explode_area = explode(".", $this->_floor_area_from);
582 606 if ( count($explode_area) == 2 )
583 607 {
584 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
608 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
585 609 }
586 610 else
587 611 {
588 - $area .= number_format($this->_floor_area_from, 0);
612 + $area .= number_format((float)$this->_floor_area_from, 0);
589 613 }
590 614 }
591 615 if ( $this->_floor_area_to != '' && $this->_floor_area_to != $this->_floor_area_from )
592 616 {
@@ -596,13 +620,13 @@
596 620 }
597 621 $explode_area = explode(".", $this->_floor_area_to);
598 622 if ( count($explode_area) == 2 )
599 623 {
600 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
624 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
601 625 }
602 626 else
603 627 {
604 - $area .= number_format($this->_floor_area_to, 0);
628 + $area .= number_format((float)$this->_floor_area_to, 0);
605 629 }
606 630 }
607 631
608 632 if ( $area != '' )
@@ -610,9 +634,9 @@
610 634 $area_units = get_area_units( );
611 635 $area .= ( isset($area_units[$this->_floor_area_units]) ) ? ' ' . $area_units[$this->_floor_area_units] : '';
612 636 }
613 637
614 - return $area;
638 + return apply_filters( 'propertyhive_floor_area_output', esc_html( $area ), $this );
615 639
616 640 }
617 641
618 642 public function get_formatted_site_area( ) {
@@ -623,13 +647,13 @@
623 647 {
624 648 $explode_area = explode(".", $this->_site_area_from);
625 649 if ( count($explode_area) == 2 )
626 650 {
627 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
651 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
628 652 }
629 653 else
630 654 {
631 - $area .= number_format($this->_site_area_from, 0);
655 + $area .= number_format((float)$this->_site_area_from, 0);
632 656 }
633 657 }
634 658 if ( $this->_site_area_to != '' && $this->_site_area_to != $this->_site_area_from )
635 659 {
@@ -639,13 +663,13 @@
639 663 }
640 664 $explode_area = explode(".", $this->_site_area_to);
641 665 if ( count($explode_area) == 2 )
642 666 {
643 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
667 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
644 668 }
645 669 else
646 670 {
647 - $area .= number_format($this->_site_area_to, 0);
671 + $area .= number_format((float)$this->_site_area_to, 0);
648 672 }
649 673 }
650 674
651 675 if ( $area != '' )
@@ -653,9 +677,9 @@
653 677 $area_units = get_area_units( );
654 678 $area .= ( isset($area_units[$this->_site_area_units]) ) ? ' ' . $area_units[$this->_site_area_units] : '';
655 679 }
656 680
657 - return $area;
681 + return apply_filters( 'propertyhive_site_area_output', esc_html( $area ), $this );
658 682
659 683 }
660 684
661 685 /**
@@ -673,12 +697,20 @@
673 697
674 698 $ph_countries = new PH_Countries();
675 699
676 700 $currency = $ph_countries->get_currency( $this->_currency );
677 - $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
678 - $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
679 701
680 - return $prefix . number_format($this->_deposit, 0) . $suffix;
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;
681 713 }
682 714
683 715 /**
684 716 * Get the available date, or 'Now' if date is in past
@@ -687,12 +719,17 @@
687 719 * @return string
688 720 */
689 721 public function get_available_date( )
690 722 {
691 - if (strtotime($this->_available_date))
723 + if ( $this->_available_date == '' )
692 724 {
693 - return date( get_option( 'date_format' ), strtotime($this->_available_date) );
725 + return '';
694 726 }
727 +
728 + if (strtotime($this->_available_date) > time())
729 + {
730 + return gmdate( get_option( 'date_format' ), strtotime($this->_available_date) );
731 + }
695 732 else
696 733 {
697 734 return __( 'Now', 'propertyhive' );
698 735 }
@@ -703,18 +740,25 @@
703 740 *
704 741 * @access public
705 742 * @return string
706 743 */
707 - public function get_formatted_description( ) {
744 + public function get_formatted_description( $plain_text = false ) {
708 745
709 - if ( $this->_department == 'commercial' )
746 + $department = $this->_department;
747 + if ( ph_get_custom_department_based_on( $department ) !== false )
710 748 {
711 - return $this->get_formatted_descriptions(); // Haven't called this commercial_descriptions as we might use generic descriptions for other area going forward
749 + $department = ph_get_custom_department_based_on( $department );
712 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 + }
713 755 else
714 756 {
715 - return $this->get_formatted_rooms();
757 + $description = $this->get_formatted_rooms( $plain_text );
716 758 }
759 +
760 + return apply_filters( 'propertyhive_description_output', $description );
717 761 }
718 762
719 763 /**
720 764 * Get the full description by constructing the rooms
@@ -721,9 +765,9 @@
721 765 *
722 766 * @access public
723 767 * @return string
724 768 */
725 - public function get_formatted_rooms( ) {
769 + public function get_formatted_rooms( $plain_text = false ) {
726 770
727 771 $rooms = $this->_rooms;
728 772
729 773 $return = '';
@@ -731,27 +775,44 @@
731 775 if (isset($rooms) && $rooms != '' && $rooms > 0)
732 776 {
733 777 for ($i = 0; $i < $rooms; ++$i)
734 778 {
735 - $return .= '<p class="room">';
736 - if ($this->{'_room_name_' . $i} != '')
779 + if ( !$plain_text )
737 780 {
738 - $return .= '<strong class="name">' . $this->{'_room_name_' . $i} . '</strong>';
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>';
739 795 }
740 - if ($this->{'_room_dimensions_' . $i} != '')
741 - {
742 - $return .= ' <strong class="dimension">(' . $this->{'_room_dimensions_' . $i} . ')</strong>';
743 - }
744 - if ($this->{'_room_name_' . $i} != '' || $this->{'_room_dimensions_' . $i} != '')
796 + else
745 797 {
746 - $return .= '<br>';
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";
747 811 }
748 - $return .= nl2br($this->{'_room_description_' . $i}) . '
749 - </p>
750 - ';
751 812 }
752 813 }
753 -
814 +
754 815 return $return;
755 816 }
756 817
757 818 /**
@@ -759,9 +820,9 @@
759 820 *
760 821 * @access public
761 822 * @return string
762 823 */
763 - public function get_formatted_descriptions( ) {
824 + public function get_formatted_descriptions( $plain_text = false ) {
764 825
765 826 $descriptions = $this->_descriptions;
766 827
767 828 $return = '';
@@ -769,20 +830,30 @@
769 830 if (isset($descriptions) && $descriptions != '' && $descriptions > 0)
770 831 {
771 832 for ($i = 0; $i < $descriptions; ++$i)
772 833 {
773 - $return .= '<p class="description-section">';
774 - if ($this->{'_description_name_' . $i} != '')
834 + if ( !$plain_text )
775 835 {
776 - $return .= '<strong class="description-title">' . $this->{'_description_name_' . $i} . '</strong>';
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>';
777 847 }
778 - if ($this->{'_description_' . $i} != '')
848 + else
779 849 {
780 - $return .= '<br>';
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";
781 855 }
782 - $return .= nl2br($this->{'_description_' . $i}) . '
783 - </p>
784 - ';
785 856 }
786 857 }
787 858
788 859 return $return;
@@ -795,9 +866,9 @@
795 866 * @return string
796 867 */
797 868 public function get_property_type()
798 869 {
799 - $term_list = wp_get_post_terms($this->id, ( ( $this->_department == 'commercial' ) ? 'commercial_' : '' ) . 'property_type', array("fields" => "names"));
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"));
800 871
801 872 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
802 873 {
803 874 return implode(", ", $term_list);
@@ -867,9 +938,9 @@
867 938 * @return string
868 939 */
869 940 public function get_tenure()
870 941 {
871 - $term_list = wp_get_post_terms($this->id, 'tenure', array("fields" => "names"));
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"));
872 943
873 944 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
874 945 {
875 946 return implode(", ", $term_list);
@@ -968,8 +1039,25 @@
968 1039 return '';
969 1040 }
970 1041
971 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 + /**
972 1060 * Get an array of property features
973 1061 *
974 1062 * @access public
975 1063 * @return array
@@ -984,9 +1072,9 @@
984 1072 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
985 1073 {
986 1074 foreach ( $term_list as $term_name )
987 1075 {
988 - $features[] = $term_name;
1076 + $features[] = trim($term_name);
989 1077 }
990 1078 }
991 1079 }
992 1080 else
@@ -995,16 +1083,16 @@
995 1083 if ($num_property_features == '') { $num_property_features = 0; }
996 1084
997 1085 for ($i = 0; $i < $num_property_features; ++$i)
998 1086 {
999 - if ( $this->{'_feature_' . $i} != '' )
1087 + if ( trim($this->{'_feature_' . $i}) != '' )
1000 1088 {
1001 - $features[] = $this->{'_feature_' . $i};
1089 + $features[] = trim($this->{'_feature_' . $i});
1002 1090 }
1003 1091 }
1004 1092 }
1005 1093
1006 - return $features;
1094 + return apply_filters( 'propertyhive_property_features', $features );
1007 1095 }
1008 1096
1009 1097 /**
1010 1098 * Get the full formatted address
@@ -1115,8 +1203,214 @@
1115 1203
1116 1204 return $return;
1117 1205 }
1118 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 +
1119 1413 public function get_office_name()
1120 1414 {
1121 1415 return get_the_title( $this->_office_id );
1122 1416 }
@@ -1153,8 +1447,96 @@
1153 1447 {
1154 1448 return get_post_meta( $this->_office_id, '_office_email_address_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1155 1449 }
1156 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 +
1157 1539 /**
1158 1540 * Returns boolean whether the property is featured or not
1159 1541 *
1160 1542 * @access public
@@ -1161,9 +1543,9 @@
1161 1543 * @return string
1162 1544 */
1163 1545 public function is_featured() {
1164 1546
1165 - if (isset($the_property->_featured) && $the_property->_featured == 'yes')
1547 + if ( $this->_featured == 'yes' )
1166 1548 {
1167 1549 return true;
1168 1550 }
1169 1551