PluginProbe
Property Hive / 2.3.0
Property Hive v2.3.0
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 +491 -191 1.4.622.3.0 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,30 +311,38 @@
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 319 if (
352 - !is_admin() &&
320 + !$is_admin &&
353 321 $this->_for_sale == 'yes' && $this->_price_poa == 'yes' &&
354 322 $this->_to_rent == 'yes' && $this->_rent_poa == 'yes'
355 323 )
356 324 {
357 - $return = __( 'POA', 'propertyhive' );
325 + $return = esc_html__( 'POA', 'propertyhive' );
358 326 }
359 327 else
360 328 {
361 - $price = '';
329 + // Price Details
330 + $price = $this->get_formatted_commercial_price();
362 331
363 - // Price Details
364 - $price .= $this->get_formatted_commercial_price();
332 + if ( $price != '' && !$plain_text )
333 + {
334 + $price = '<span class="commercial-price">' . $price . '</span>';
335 + }
365 336
366 337 // Rent Details
367 338 $rent = $this->get_formatted_commercial_rent();
339 +
340 + if ( $rent != '' && !$plain_text ) { $rent = '<span class="commercial-rent">' . $rent . '</span>'; }
341 +
368 342 if ( $price != '' && $rent != '' )
369 343 {
370 - $price .= '<br>';
344 + $price .= !$plain_text ? '<br>' : "\n";
371 345 }
372 346 $price .= $rent;
373 347
374 348 $return = $price;
@@ -375,31 +349,34 @@
375 349 }
376 350 }
377 351 else
378 352 {
379 - if ( ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) && $this->_poa == 'yes')
353 + if ( !$is_admin && $this->_poa == 'yes')
380 354 {
381 - $return = __( 'POA', 'propertyhive' );
355 + $return = esc_html__( 'POA', 'propertyhive' );
382 356 }
383 357 else
384 358 {
385 359 $ph_countries = new PH_Countries();
386 360
387 - if ( !is_admin() )
361 + if ( !$is_admin )
388 362 {
389 - 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'] ) )
390 365 {
391 - 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 != '' )
392 369 {
393 - $requested_currency = $ph_countries->get_currency( sanitize_text_field($_GET['currency']) );
370 + $requested_currency = $ph_countries->get_currency( $currency_code );
394 371 if ( $requested_currency !== FALSE )
395 372 {
396 373 $currency = $requested_currency;
397 374 $currency['exchange_rate'] = 1;
398 375 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
399 - if ( isset($exchange_rates[$_GET['currency']]) )
376 + if ( isset($exchange_rates[$currency_code]) )
400 377 {
401 - $currency['exchange_rate'] = $exchange_rates[sanitize_text_field($_GET['currency'])];
378 + $currency['exchange_rate'] = $exchange_rates[$currency_code];
402 379 }
403 380 }
404 381 }
405 382 else
@@ -420,11 +397,11 @@
420 397 }
421 398 }
422 399 }
423 400 }
424 - elseif ( isset($_COOKIE['propertyhive_currency']) && $_COOKIE['propertyhive_currency'] != '' )
401 + elseif ( false !== ( $cookie_currency = $ph_countries->get_currency_from_cookie() ) )
425 402 {
426 - $currency = unserialize(html_entity_decode($_COOKIE['propertyhive_currency']));
403 + $currency = $cookie_currency;
427 404 }
428 405 else
429 406 {
430 407 $default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
@@ -457,40 +434,54 @@
457 434 }
458 435 }
459 436 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
460 437 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
461 - switch ($this->_department)
438 +
439 + $department = $this->_department;
440 + if ( ph_get_custom_department_based_on( $department ) !== false )
462 441 {
442 + $department = ph_get_custom_department_based_on( $department );
443 + }
444 + switch ($department)
445 + {
463 446 case "residential-sales":
464 447 {
465 448 $price = $this->_price;
466 - if ( isset($currency['exchange_rate']) && $price != '' )
449 +
450 + if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' )
467 451 {
468 - $price = $this->_price_actual * $currency['exchange_rate'];
452 + // Round this after calculation
453 + $price = round($this->_price_actual * $currency['exchange_rate'], 0);
469 454 }
470 - $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 : '-' );
471 457 break;
472 458 }
473 459 case "residential-lettings":
474 460 {
475 461 $price = $this->_rent;
476 - if ( isset($currency['exchange_rate']) && $price != '' )
462 + if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' )
477 463 {
478 - $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);
479 466 switch ( $this->_rent_frequency )
480 467 {
468 + case "pd": { $price = ($price * 365) / 52; break; }
481 469 case "pw": { $price = ($price * 12) / 52; break; }
482 470 case "pq": { $price = ($price * 12) / 4; break; }
483 471 case "pa": { $price = ($price * 12); break; }
484 472 }
485 473 }
486 - $return = ( ( $price != '' ) ? $prefix . number_format($price, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix . ' ' . __( $this->_rent_frequency, 'propertyhive' ) : '-' );
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 ) ) : '-' );
487 476 break;
488 477 }
489 478 }
490 479 }
480 +
491 481 }
492 482
483 + // Stored price/frequency text is escaped above; currency and commercial HTML filters remain trusted.
493 484 return apply_filters( 'propertyhive_price_output', $return, $this, $currency, $prefix, $suffix );
494 485 }
495 486
496 487 /**
@@ -504,11 +495,13 @@
504 495 $price = '';
505 496
506 497 if ( $this->_for_sale == 'yes' )
507 498 {
508 - 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' )
509 502 {
510 - $price .= __( 'POA', 'propertyhive' );
503 + $price .= esc_html__( 'POA', 'propertyhive' );
511 504 }
512 505 else
513 506 {
514 507 $ph_countries = new PH_Countries();
@@ -524,17 +517,9 @@
524 517 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
525 518
526 519 if ( $this->_price_from != '' )
527 520 {
528 - $explode_price = explode(".", $this->_price_from);
529 - if ( count($explode_price) == 2 )
530 - {
531 - $price .= $prefix . number_format($explode_price[0], 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . get_option('propertyhive_price_decimal_separator', '.') . $explode_price[1] . $suffix;
532 - }
533 - else
534 - {
535 - $price .= $prefix . number_format($this->_price_from, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
536 - }
521 + $price .= $prefix . esc_html( ph_display_price_field($this->_price_from, !$is_admin) ) . $suffix;
537 522 }
538 523 if ( $this->_price_to != '' && $this->_price_to != $this->_price_from )
539 524 {
540 525 if ( $price != '' )
@@ -540,27 +525,20 @@
540 525 if ( $price != '' )
541 526 {
542 527 $price .= ' - ';
543 528 }
544 - $explode_price = explode(".", $this->_price_to);
545 - if ( count($explode_price) == 2 )
546 - {
547 - $price .= $prefix . number_format($explode_price[0], 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . get_option('propertyhive_price_decimal_separator', '.') . $explode_price[1] . $suffix;
548 - }
549 - else
550 - {
551 - $price .= $prefix . number_format($this->_price_to, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
552 - }
529 + $price .= $prefix . esc_html( ph_display_price_field($this->_price_to, !$is_admin) ) . $suffix;
553 530 }
554 531 if ( $price != '' )
555 532 {
556 533 $price_units = get_commercial_price_units( );
557 - $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] ) : '';
558 535 }
559 536 }
560 537 }
561 538
562 - 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 );
563 541 }
564 542
565 543 /**
566 544 * Get the formatted commercial rent. Show POA if on frontend and 'POA' ticked
@@ -573,11 +551,13 @@
573 551 $rent = '';
574 552
575 553 if ( $this->_to_rent == 'yes' )
576 554 {
577 - 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' )
578 558 {
579 - $rent .= __( 'POA', 'propertyhive' );
559 + $rent .= esc_html__( 'POA', 'propertyhive' );
580 560 }
581 561 else
582 562 {
583 563 $ph_countries = new PH_Countries();
@@ -593,17 +573,9 @@
593 573 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
594 574
595 575 if ( $this->_rent_from != '' )
596 576 {
597 - $explode_rent = explode(".", $this->_rent_from);
598 - if ( count($explode_rent) == 2 )
599 - {
600 - $rent .= $prefix . number_format($explode_rent[0], 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . get_option('propertyhive_price_decimal_separator', '.') . $explode_rent[1] . $suffix;
601 - }
602 - else
603 - {
604 - $rent .= $prefix . number_format($this->_rent_from, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
605 - }
577 + $rent .= $prefix . esc_html( ph_display_price_field($this->_rent_from, !$is_admin) ) . $suffix;
606 578 }
607 579 if ( $this->_rent_to != '' && $this->_rent_to != $this->_rent_from )
608 580 {
609 581 if ( $rent != '' )
@@ -609,27 +581,20 @@
609 581 if ( $rent != '' )
610 582 {
611 583 $rent .= ' - ';
612 584 }
613 - $explode_rent = explode(".", $this->_rent_to);
614 - if ( count($explode_rent) == 2 )
615 - {
616 - $rent .= $prefix . number_format($explode_rent[0], 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . get_option('propertyhive_price_decimal_separator', '.') . $explode_rent[1] . $suffix;
617 - }
618 - else
619 - {
620 - $rent .= $prefix . number_format($this->_rent_to, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
621 - }
585 + $rent .= $prefix . esc_html( ph_display_price_field($this->_rent_to, !$is_admin) ) . $suffix;
622 586 }
623 587 if ( $rent != '' )
624 588 {
625 589 $price_units = get_commercial_price_units( );
626 - $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 );
627 591 }
628 592 }
629 593 }
630 594
631 - 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 );
632 597 }
633 598
634 599 public function get_formatted_floor_area( ) {
635 600
@@ -639,13 +604,13 @@
639 604 {
640 605 $explode_area = explode(".", $this->_floor_area_from);
641 606 if ( count($explode_area) == 2 )
642 607 {
643 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
608 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
644 609 }
645 610 else
646 611 {
647 - $area .= number_format($this->_floor_area_from, 0);
612 + $area .= number_format((float)$this->_floor_area_from, 0);
648 613 }
649 614 }
650 615 if ( $this->_floor_area_to != '' && $this->_floor_area_to != $this->_floor_area_from )
651 616 {
@@ -655,13 +620,13 @@
655 620 }
656 621 $explode_area = explode(".", $this->_floor_area_to);
657 622 if ( count($explode_area) == 2 )
658 623 {
659 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
624 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
660 625 }
661 626 else
662 627 {
663 - $area .= number_format($this->_floor_area_to, 0);
628 + $area .= number_format((float)$this->_floor_area_to, 0);
664 629 }
665 630 }
666 631
667 632 if ( $area != '' )
@@ -669,9 +634,9 @@
669 634 $area_units = get_area_units( );
670 635 $area .= ( isset($area_units[$this->_floor_area_units]) ) ? ' ' . $area_units[$this->_floor_area_units] : '';
671 636 }
672 637
673 - return $area;
638 + return apply_filters( 'propertyhive_floor_area_output', esc_html( $area ), $this );
674 639
675 640 }
676 641
677 642 public function get_formatted_site_area( ) {
@@ -682,13 +647,13 @@
682 647 {
683 648 $explode_area = explode(".", $this->_site_area_from);
684 649 if ( count($explode_area) == 2 )
685 650 {
686 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
651 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
687 652 }
688 653 else
689 654 {
690 - $area .= number_format($this->_site_area_from, 0);
655 + $area .= number_format((float)$this->_site_area_from, 0);
691 656 }
692 657 }
693 658 if ( $this->_site_area_to != '' && $this->_site_area_to != $this->_site_area_from )
694 659 {
@@ -698,13 +663,13 @@
698 663 }
699 664 $explode_area = explode(".", $this->_site_area_to);
700 665 if ( count($explode_area) == 2 )
701 666 {
702 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
667 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
703 668 }
704 669 else
705 670 {
706 - $area .= number_format($this->_site_area_to, 0);
671 + $area .= number_format((float)$this->_site_area_to, 0);
707 672 }
708 673 }
709 674
710 675 if ( $area != '' )
@@ -712,9 +677,9 @@
712 677 $area_units = get_area_units( );
713 678 $area .= ( isset($area_units[$this->_site_area_units]) ) ? ' ' . $area_units[$this->_site_area_units] : '';
714 679 }
715 680
716 - return $area;
681 + return apply_filters( 'propertyhive_site_area_output', esc_html( $area ), $this );
717 682
718 683 }
719 684
720 685 /**
@@ -732,12 +697,20 @@
732 697
733 698 $ph_countries = new PH_Countries();
734 699
735 700 $currency = $ph_countries->get_currency( $this->_currency );
736 - $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
737 - $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
738 701
739 - 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;
740 713 }
741 714
742 715 /**
743 716 * Get the available date, or 'Now' if date is in past
@@ -746,12 +719,17 @@
746 719 * @return string
747 720 */
748 721 public function get_available_date( )
749 722 {
750 - if (strtotime($this->_available_date))
723 + if ( $this->_available_date == '' )
751 724 {
752 - return date( get_option( 'date_format' ), strtotime($this->_available_date) );
725 + return '';
753 726 }
727 +
728 + if (strtotime($this->_available_date) > time())
729 + {
730 + return gmdate( get_option( 'date_format' ), strtotime($this->_available_date) );
731 + }
754 732 else
755 733 {
756 734 return __( 'Now', 'propertyhive' );
757 735 }
@@ -762,18 +740,25 @@
762 740 *
763 741 * @access public
764 742 * @return string
765 743 */
766 - public function get_formatted_description( ) {
744 + public function get_formatted_description( $plain_text = false ) {
767 745
768 - if ( $this->_department == 'commercial' )
746 + $department = $this->_department;
747 + if ( ph_get_custom_department_based_on( $department ) !== false )
769 748 {
770 - 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 );
771 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 + }
772 755 else
773 756 {
774 - return $this->get_formatted_rooms();
757 + $description = $this->get_formatted_rooms( $plain_text );
775 758 }
759 +
760 + return apply_filters( 'propertyhive_description_output', $description );
776 761 }
777 762
778 763 /**
779 764 * Get the full description by constructing the rooms
@@ -780,9 +765,9 @@
780 765 *
781 766 * @access public
782 767 * @return string
783 768 */
784 - public function get_formatted_rooms( ) {
769 + public function get_formatted_rooms( $plain_text = false ) {
785 770
786 771 $rooms = $this->_rooms;
787 772
788 773 $return = '';
@@ -790,25 +775,44 @@
790 775 if (isset($rooms) && $rooms != '' && $rooms > 0)
791 776 {
792 777 for ($i = 0; $i < $rooms; ++$i)
793 778 {
794 - $return .= '<p class="room">';
795 - if ($this->{'_room_name_' . $i} != '')
779 + if ( !$plain_text )
796 780 {
797 - $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>';
798 795 }
799 - if ($this->{'_room_dimensions_' . $i} != '')
800 - {
801 - $return .= ' <strong class="dimension">(' . $this->{'_room_dimensions_' . $i} . ')</strong>';
802 - }
803 - if ($this->{'_room_name_' . $i} != '' || $this->{'_room_dimensions_' . $i} != '')
796 + else
804 797 {
805 - $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";
806 811 }
807 - $return .= str_replace("\r\n", "", nl2br($this->{'_room_description_' . $i})) . '</p>';
808 812 }
809 813 }
810 -
814 +
811 815 return $return;
812 816 }
813 817
814 818 /**
@@ -816,9 +820,9 @@
816 820 *
817 821 * @access public
818 822 * @return string
819 823 */
820 - public function get_formatted_descriptions( ) {
824 + public function get_formatted_descriptions( $plain_text = false ) {
821 825
822 826 $descriptions = $this->_descriptions;
823 827
824 828 $return = '';
@@ -826,14 +830,30 @@
826 830 if (isset($descriptions) && $descriptions != '' && $descriptions > 0)
827 831 {
828 832 for ($i = 0; $i < $descriptions; ++$i)
829 833 {
830 - $return .= '<p class="description-section">';
831 - if ($this->{'_description_name_' . $i} != '')
834 + if ( !$plain_text )
832 835 {
833 - $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>';
834 847 }
835 - $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 + }
836 856 }
837 857 }
838 858
839 859 return $return;
@@ -846,9 +866,9 @@
846 866 * @return string
847 867 */
848 868 public function get_property_type()
849 869 {
850 - $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"));
851 871
852 872 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
853 873 {
854 874 return implode(", ", $term_list);
@@ -918,9 +938,9 @@
918 938 * @return string
919 939 */
920 940 public function get_tenure()
921 941 {
922 - $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"));
923 943
924 944 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
925 945 {
926 946 return implode(", ", $term_list);
@@ -1026,28 +1046,14 @@
1026 1046 * @return string
1027 1047 */
1028 1048 public function get_imported_id()
1029 1049 {
1030 - global $wpdb;
1031 -
1032 - $row = $wpdb->get_row(
1033 - "
1034 - SELECT meta_value
1035 - FROM {$wpdb->prefix}postmeta
1036 - WHERE
1037 - meta_key LIKE '_imported_ref_%'
1038 - AND
1039 - post_id = '" . $this->id . "'
1040 - LIMIT 1
1041 - ",
1042 - ARRAY_A
1043 - );
1044 -
1045 - if ( null !== $row )
1046 - {
1047 - return $row['meta_value'];
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 + }
1048 1055 }
1049 -
1050 1056 return '';
1051 1057 }
1052 1058
1053 1059 /**
@@ -1084,9 +1090,9 @@
1084 1090 }
1085 1091 }
1086 1092 }
1087 1093
1088 - return $features;
1094 + return apply_filters( 'propertyhive_property_features', $features );
1089 1095 }
1090 1096
1091 1097 /**
1092 1098 * Get the full formatted address
@@ -1197,8 +1203,214 @@
1197 1203
1198 1204 return $return;
1199 1205 }
1200 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 +
1201 1413 public function get_office_name()
1202 1414 {
1203 1415 return get_the_title( $this->_office_id );
1204 1416 }
@@ -1235,8 +1447,96 @@
1235 1447 {
1236 1448 return get_post_meta( $this->_office_id, '_office_email_address_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1237 1449 }
1238 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 +
1239 1539 /**
1240 1540 * Returns boolean whether the property is featured or not
1241 1541 *
1242 1542 * @access public
@@ -1243,9 +1543,9 @@
1243 1543 * @return string
1244 1544 */
1245 1545 public function is_featured() {
1246 1546
1247 - if (isset($the_property->_featured) && $the_property->_featured == 'yes')
1547 + if ( $this->_featured == 'yes' )
1248 1548 {
1249 1549 return true;
1250 1550 }
1251 1551