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 +507 -196 1.4.612.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,75 +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 ( '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 - }
115 +
116 + $value = apply_filters( 'propertyhive_get_detail', $value, $key, $this );
145 117
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 118 return $value;
153 119 }
154 120
155 121 /**
@@ -163,9 +129,9 @@
163 129 // Standard post data
164 130 $this->id = $result->ID;
165 131 $this->post_title = $result->post_title;
166 132 $this->post_status = $result->post_status;
167 - $this->post_excerpt = $result->post_excerpt;
133 + $this->post_excerpt = apply_filters( 'propertyhive_property_post_excerpt', $result->post_excerpt );
168 134 }
169 135
170 136 /**
171 137 * get_gallery_attachment_ids function.
@@ -337,9 +303,9 @@
337 303 *
338 304 * @access public
339 305 * @return string
340 306 */
341 - public function get_formatted_price( ) {
307 + public function get_formatted_price( $plain_text = false ) {
342 308
343 309 $return = '';
344 310
345 311 $currency = array();
@@ -345,50 +311,72 @@
345 311 $currency = array();
346 312 $prefix = '';
347 313 $suffix = '';
348 314
349 - if ( $this->_department == 'commercial' )
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' )
350 318 {
351 - $price = '';
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();
352 331
353 - // Price Details
354 - $price .= $this->get_formatted_commercial_price();
332 + if ( $price != '' && !$plain_text )
333 + {
334 + $price = '<span class="commercial-price">' . $price . '</span>';
335 + }
355 336
356 - // Rent Details
357 - $rent = $this->get_formatted_commercial_rent();
358 - if ( $price != '' && $rent != '' )
359 - {
360 - $price .= '<br>';
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;
361 349 }
362 - $price .= $rent;
363 -
364 - $return = $price;
365 350 }
366 351 else
367 352 {
368 - if ( ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) && $this->_poa == 'yes')
353 + if ( !$is_admin && $this->_poa == 'yes')
369 354 {
370 - $return = __( 'POA', 'propertyhive' );
355 + $return = esc_html__( 'POA', 'propertyhive' );
371 356 }
372 357 else
373 358 {
374 359 $ph_countries = new PH_Countries();
375 360
376 - if ( !is_admin() )
361 + if ( !$is_admin )
377 362 {
378 - 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'] ) )
379 365 {
380 - 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 != '' )
381 369 {
382 - $requested_currency = $ph_countries->get_currency( sanitize_text_field($_GET['currency']) );
370 + $requested_currency = $ph_countries->get_currency( $currency_code );
383 371 if ( $requested_currency !== FALSE )
384 372 {
385 373 $currency = $requested_currency;
386 374 $currency['exchange_rate'] = 1;
387 375 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
388 - if ( isset($exchange_rates[$_GET['currency']]) )
376 + if ( isset($exchange_rates[$currency_code]) )
389 377 {
390 - $currency['exchange_rate'] = $exchange_rates[sanitize_text_field($_GET['currency'])];
378 + $currency['exchange_rate'] = $exchange_rates[$currency_code];
391 379 }
392 380 }
393 381 }
394 382 else
@@ -409,11 +397,11 @@
409 397 }
410 398 }
411 399 }
412 400 }
413 - elseif ( isset($_COOKIE['propertyhive_currency']) && $_COOKIE['propertyhive_currency'] != '' )
401 + elseif ( false !== ( $cookie_currency = $ph_countries->get_currency_from_cookie() ) )
414 402 {
415 - $currency = unserialize(html_entity_decode($_COOKIE['propertyhive_currency']));
403 + $currency = $cookie_currency;
416 404 }
417 405 else
418 406 {
419 407 $default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
@@ -446,40 +434,54 @@
446 434 }
447 435 }
448 436 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
449 437 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
450 - switch ($this->_department)
438 +
439 + $department = $this->_department;
440 + if ( ph_get_custom_department_based_on( $department ) !== false )
451 441 {
442 + $department = ph_get_custom_department_based_on( $department );
443 + }
444 + switch ($department)
445 + {
452 446 case "residential-sales":
453 447 {
454 448 $price = $this->_price;
455 - if ( isset($currency['exchange_rate']) && $price != '' )
449 +
450 + if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' )
456 451 {
457 - $price = $this->_price_actual * $currency['exchange_rate'];
452 + // Round this after calculation
453 + $price = round($this->_price_actual * $currency['exchange_rate'], 0);
458 454 }
459 - $return = ( ( $price != '' ) ? $prefix . number_format($price, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix : '-' );
455 +
456 + $return = ( ( $price != '' ) ? $prefix . esc_html( ph_display_price_field($price, !$is_admin) ) . $suffix : '-' );
460 457 break;
461 458 }
462 459 case "residential-lettings":
463 460 {
464 461 $price = $this->_rent;
465 - if ( isset($currency['exchange_rate']) && $price != '' )
462 + if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' )
466 463 {
467 - $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);
468 466 switch ( $this->_rent_frequency )
469 467 {
468 + case "pd": { $price = ($price * 365) / 52; break; }
470 469 case "pw": { $price = ($price * 12) / 52; break; }
471 470 case "pq": { $price = ($price * 12) / 4; break; }
472 471 case "pa": { $price = ($price * 12); break; }
473 472 }
474 473 }
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' ) : '-' );
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 476 break;
477 477 }
478 478 }
479 479 }
480 +
480 481 }
481 482
483 + // Stored price/frequency text is escaped above; currency and commercial HTML filters remain trusted.
482 484 return apply_filters( 'propertyhive_price_output', $return, $this, $currency, $prefix, $suffix );
483 485 }
484 486
485 487 /**
@@ -493,11 +495,13 @@
493 495 $price = '';
494 496
495 497 if ( $this->_for_sale == 'yes' )
496 498 {
497 - 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' )
498 502 {
499 - $price .= __( 'POA', 'propertyhive' );
503 + $price .= esc_html__( 'POA', 'propertyhive' );
500 504 }
501 505 else
502 506 {
503 507 $ph_countries = new PH_Countries();
@@ -513,17 +517,9 @@
513 517 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
514 518
515 519 if ( $this->_price_from != '' )
516 520 {
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 - }
521 + $price .= $prefix . esc_html( ph_display_price_field($this->_price_from, !$is_admin) ) . $suffix;
526 522 }
527 523 if ( $this->_price_to != '' && $this->_price_to != $this->_price_from )
528 524 {
529 525 if ( $price != '' )
@@ -529,27 +525,20 @@
529 525 if ( $price != '' )
530 526 {
531 527 $price .= ' - ';
532 528 }
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 - }
529 + $price .= $prefix . esc_html( ph_display_price_field($this->_price_to, !$is_admin) ) . $suffix;
542 530 }
543 531 if ( $price != '' )
544 532 {
545 533 $price_units = get_commercial_price_units( );
546 - $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] ) : '';
547 535 }
548 536 }
549 537 }
550 538
551 - 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 );
552 541 }
553 542
554 543 /**
555 544 * Get the formatted commercial rent. Show POA if on frontend and 'POA' ticked
@@ -562,11 +551,13 @@
562 551 $rent = '';
563 552
564 553 if ( $this->_to_rent == 'yes' )
565 554 {
566 - 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' )
567 558 {
568 - $rent .= __( 'POA', 'propertyhive' );
559 + $rent .= esc_html__( 'POA', 'propertyhive' );
569 560 }
570 561 else
571 562 {
572 563 $ph_countries = new PH_Countries();
@@ -582,17 +573,9 @@
582 573 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
583 574
584 575 if ( $this->_rent_from != '' )
585 576 {
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 - }
577 + $rent .= $prefix . esc_html( ph_display_price_field($this->_rent_from, !$is_admin) ) . $suffix;
595 578 }
596 579 if ( $this->_rent_to != '' && $this->_rent_to != $this->_rent_from )
597 580 {
598 581 if ( $rent != '' )
@@ -598,27 +581,20 @@
598 581 if ( $rent != '' )
599 582 {
600 583 $rent .= ' - ';
601 584 }
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 - }
585 + $rent .= $prefix . esc_html( ph_display_price_field($this->_rent_to, !$is_admin) ) . $suffix;
611 586 }
612 587 if ( $rent != '' )
613 588 {
614 589 $price_units = get_commercial_price_units( );
615 - $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 );
616 591 }
617 592 }
618 593 }
619 594
620 - 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 );
621 597 }
622 598
623 599 public function get_formatted_floor_area( ) {
624 600
@@ -628,13 +604,13 @@
628 604 {
629 605 $explode_area = explode(".", $this->_floor_area_from);
630 606 if ( count($explode_area) == 2 )
631 607 {
632 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
608 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
633 609 }
634 610 else
635 611 {
636 - $area .= number_format($this->_floor_area_from, 0);
612 + $area .= number_format((float)$this->_floor_area_from, 0);
637 613 }
638 614 }
639 615 if ( $this->_floor_area_to != '' && $this->_floor_area_to != $this->_floor_area_from )
640 616 {
@@ -644,13 +620,13 @@
644 620 }
645 621 $explode_area = explode(".", $this->_floor_area_to);
646 622 if ( count($explode_area) == 2 )
647 623 {
648 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
624 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
649 625 }
650 626 else
651 627 {
652 - $area .= number_format($this->_floor_area_to, 0);
628 + $area .= number_format((float)$this->_floor_area_to, 0);
653 629 }
654 630 }
655 631
656 632 if ( $area != '' )
@@ -658,9 +634,9 @@
658 634 $area_units = get_area_units( );
659 635 $area .= ( isset($area_units[$this->_floor_area_units]) ) ? ' ' . $area_units[$this->_floor_area_units] : '';
660 636 }
661 637
662 - return $area;
638 + return apply_filters( 'propertyhive_floor_area_output', esc_html( $area ), $this );
663 639
664 640 }
665 641
666 642 public function get_formatted_site_area( ) {
@@ -671,13 +647,13 @@
671 647 {
672 648 $explode_area = explode(".", $this->_site_area_from);
673 649 if ( count($explode_area) == 2 )
674 650 {
675 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
651 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
676 652 }
677 653 else
678 654 {
679 - $area .= number_format($this->_site_area_from, 0);
655 + $area .= number_format((float)$this->_site_area_from, 0);
680 656 }
681 657 }
682 658 if ( $this->_site_area_to != '' && $this->_site_area_to != $this->_site_area_from )
683 659 {
@@ -687,13 +663,13 @@
687 663 }
688 664 $explode_area = explode(".", $this->_site_area_to);
689 665 if ( count($explode_area) == 2 )
690 666 {
691 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
667 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
692 668 }
693 669 else
694 670 {
695 - $area .= number_format($this->_site_area_to, 0);
671 + $area .= number_format((float)$this->_site_area_to, 0);
696 672 }
697 673 }
698 674
699 675 if ( $area != '' )
@@ -701,9 +677,9 @@
701 677 $area_units = get_area_units( );
702 678 $area .= ( isset($area_units[$this->_site_area_units]) ) ? ' ' . $area_units[$this->_site_area_units] : '';
703 679 }
704 680
705 - return $area;
681 + return apply_filters( 'propertyhive_site_area_output', esc_html( $area ), $this );
706 682
707 683 }
708 684
709 685 /**
@@ -721,12 +697,20 @@
721 697
722 698 $ph_countries = new PH_Countries();
723 699
724 700 $currency = $ph_countries->get_currency( $this->_currency );
725 - $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
726 - $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
727 701
728 - 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;
729 713 }
730 714
731 715 /**
732 716 * Get the available date, or 'Now' if date is in past
@@ -735,12 +719,17 @@
735 719 * @return string
736 720 */
737 721 public function get_available_date( )
738 722 {
739 - if (strtotime($this->_available_date))
723 + if ( $this->_available_date == '' )
740 724 {
741 - return date( get_option( 'date_format' ), strtotime($this->_available_date) );
725 + return '';
742 726 }
727 +
728 + if (strtotime($this->_available_date) > time())
729 + {
730 + return gmdate( get_option( 'date_format' ), strtotime($this->_available_date) );
731 + }
743 732 else
744 733 {
745 734 return __( 'Now', 'propertyhive' );
746 735 }
@@ -751,18 +740,25 @@
751 740 *
752 741 * @access public
753 742 * @return string
754 743 */
755 - public function get_formatted_description( ) {
744 + public function get_formatted_description( $plain_text = false ) {
756 745
757 - if ( $this->_department == 'commercial' )
746 + $department = $this->_department;
747 + if ( ph_get_custom_department_based_on( $department ) !== false )
758 748 {
759 - 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 );
760 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 + }
761 755 else
762 756 {
763 - return $this->get_formatted_rooms();
757 + $description = $this->get_formatted_rooms( $plain_text );
764 758 }
759 +
760 + return apply_filters( 'propertyhive_description_output', $description );
765 761 }
766 762
767 763 /**
768 764 * Get the full description by constructing the rooms
@@ -769,9 +765,9 @@
769 765 *
770 766 * @access public
771 767 * @return string
772 768 */
773 - public function get_formatted_rooms( ) {
769 + public function get_formatted_rooms( $plain_text = false ) {
774 770
775 771 $rooms = $this->_rooms;
776 772
777 773 $return = '';
@@ -779,25 +775,44 @@
779 775 if (isset($rooms) && $rooms != '' && $rooms > 0)
780 776 {
781 777 for ($i = 0; $i < $rooms; ++$i)
782 778 {
783 - $return .= '<p class="room">';
784 - if ($this->{'_room_name_' . $i} != '')
779 + if ( !$plain_text )
785 780 {
786 - $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>';
787 795 }
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} != '')
796 + else
793 797 {
794 - $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";
795 811 }
796 - $return .= str_replace("\r\n", "", nl2br($this->{'_room_description_' . $i})) . '</p>';
797 812 }
798 813 }
799 -
814 +
800 815 return $return;
801 816 }
802 817
803 818 /**
@@ -805,9 +820,9 @@
805 820 *
806 821 * @access public
807 822 * @return string
808 823 */
809 - public function get_formatted_descriptions( ) {
824 + public function get_formatted_descriptions( $plain_text = false ) {
810 825
811 826 $descriptions = $this->_descriptions;
812 827
813 828 $return = '';
@@ -815,14 +830,30 @@
815 830 if (isset($descriptions) && $descriptions != '' && $descriptions > 0)
816 831 {
817 832 for ($i = 0; $i < $descriptions; ++$i)
818 833 {
819 - $return .= '<p class="description-section">';
820 - if ($this->{'_description_name_' . $i} != '')
834 + if ( !$plain_text )
821 835 {
822 - $return .= '<strong class="description-title">' . $this->{'_description_name_' . $i} . '</strong><br>';
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>';
823 847 }
824 - $return .= str_replace("\r\n", "", nl2br($this->{'_description_' . $i})) . '</p>';
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 + }
825 856 }
826 857 }
827 858
828 859 return $return;
@@ -835,9 +866,9 @@
835 866 * @return string
836 867 */
837 868 public function get_property_type()
838 869 {
839 - $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"));
840 871
841 872 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
842 873 {
843 874 return implode(", ", $term_list);
@@ -907,9 +938,9 @@
907 938 * @return string
908 939 */
909 940 public function get_tenure()
910 941 {
911 - $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"));
912 943
913 944 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
914 945 {
915 946 return implode(", ", $term_list);
@@ -1015,28 +1046,14 @@
1015 1046 * @return string
1016 1047 */
1017 1048 public function get_imported_id()
1018 1049 {
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'];
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 + }
1037 1055 }
1038 -
1039 1056 return '';
1040 1057 }
1041 1058
1042 1059 /**
@@ -1073,9 +1090,9 @@
1073 1090 }
1074 1091 }
1075 1092 }
1076 1093
1077 - return $features;
1094 + return apply_filters( 'propertyhive_property_features', $features );
1078 1095 }
1079 1096
1080 1097 /**
1081 1098 * Get the full formatted address
@@ -1186,8 +1203,214 @@
1186 1203
1187 1204 return $return;
1188 1205 }
1189 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 +
1190 1413 public function get_office_name()
1191 1414 {
1192 1415 return get_the_title( $this->_office_id );
1193 1416 }
@@ -1224,8 +1447,96 @@
1224 1447 {
1225 1448 return get_post_meta( $this->_office_id, '_office_email_address_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1226 1449 }
1227 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 +
1228 1539 /**
1229 1540 * Returns boolean whether the property is featured or not
1230 1541 *
1231 1542 * @access public
@@ -1232,9 +1543,9 @@
1232 1543 * @return string
1233 1544 */
1234 1545 public function is_featured() {
1235 1546
1236 - if (isset($the_property->_featured) && $the_property->_featured == 'yes')
1547 + if ( $this->_featured == 'yes' )
1237 1548 {
1238 1549 return true;
1239 1550 }
1240 1551