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 +532 -196 1.4.542.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.
@@ -287,9 +253,34 @@
287 253 return apply_filters( 'propertyhive_property_epc_attachment_ids', $epcs, $this );
288 254 }
289 255
290 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 + /**
291 281 * get_virtual_tour_urls function.
282 + * deprecated
292 283 *
293 284 * @access public
294 285 * @return array
295 286 */
@@ -312,9 +303,9 @@
312 303 *
313 304 * @access public
314 305 * @return string
315 306 */
316 - public function get_formatted_price( ) {
307 + public function get_formatted_price( $plain_text = false ) {
317 308
318 309 $return = '';
319 310
320 311 $currency = array();
@@ -320,50 +311,72 @@
320 311 $currency = array();
321 312 $prefix = '';
322 313 $suffix = '';
323 314
324 - 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' )
325 318 {
326 - $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();
327 331
328 - // Price Details
329 - $price .= $this->get_formatted_commercial_price();
332 + if ( $price != '' && !$plain_text )
333 + {
334 + $price = '<span class="commercial-price">' . $price . '</span>';
335 + }
330 336
331 - // Rent Details
332 - $rent = $this->get_formatted_commercial_rent();
333 - if ( $price != '' && $rent != '' )
334 - {
335 - $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;
336 349 }
337 - $price .= $rent;
338 -
339 - $return = $price;
340 350 }
341 351 else
342 352 {
343 - if ( ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) && $this->_poa == 'yes')
353 + if ( !$is_admin && $this->_poa == 'yes')
344 354 {
345 - $return = __( 'POA', 'propertyhive' );
355 + $return = esc_html__( 'POA', 'propertyhive' );
346 356 }
347 357 else
348 358 {
349 359 $ph_countries = new PH_Countries();
350 360
351 - if ( !is_admin() )
361 + if ( !$is_admin )
352 362 {
353 - 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'] ) )
354 365 {
355 - 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 != '' )
356 369 {
357 - $requested_currency = $ph_countries->get_currency( sanitize_text_field($_GET['currency']) );
370 + $requested_currency = $ph_countries->get_currency( $currency_code );
358 371 if ( $requested_currency !== FALSE )
359 372 {
360 373 $currency = $requested_currency;
361 374 $currency['exchange_rate'] = 1;
362 375 $exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
363 - if ( isset($exchange_rates[$_GET['currency']]) )
376 + if ( isset($exchange_rates[$currency_code]) )
364 377 {
365 - $currency['exchange_rate'] = $exchange_rates[sanitize_text_field($_GET['currency'])];
378 + $currency['exchange_rate'] = $exchange_rates[$currency_code];
366 379 }
367 380 }
368 381 }
369 382 else
@@ -384,11 +397,11 @@
384 397 }
385 398 }
386 399 }
387 400 }
388 - elseif ( isset($_COOKIE['propertyhive_currency']) && $_COOKIE['propertyhive_currency'] != '' )
401 + elseif ( false !== ( $cookie_currency = $ph_countries->get_currency_from_cookie() ) )
389 402 {
390 - $currency = unserialize(html_entity_decode($_COOKIE['propertyhive_currency']));
403 + $currency = $cookie_currency;
391 404 }
392 405 else
393 406 {
394 407 $default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
@@ -421,40 +434,54 @@
421 434 }
422 435 }
423 436 $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
424 437 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
425 - switch ($this->_department)
438 +
439 + $department = $this->_department;
440 + if ( ph_get_custom_department_based_on( $department ) !== false )
426 441 {
442 + $department = ph_get_custom_department_based_on( $department );
443 + }
444 + switch ($department)
445 + {
427 446 case "residential-sales":
428 447 {
429 448 $price = $this->_price;
430 - if ( isset($currency['exchange_rate']) && $price != '' )
449 +
450 + if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' )
431 451 {
432 - $price = $this->_price_actual * $currency['exchange_rate'];
452 + // Round this after calculation
453 + $price = round($this->_price_actual * $currency['exchange_rate'], 0);
433 454 }
434 - $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 : '-' );
435 457 break;
436 458 }
437 459 case "residential-lettings":
438 460 {
439 461 $price = $this->_rent;
440 - if ( isset($currency['exchange_rate']) && $price != '' )
462 + if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' )
441 463 {
442 - $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);
443 466 switch ( $this->_rent_frequency )
444 467 {
468 + case "pd": { $price = ($price * 365) / 52; break; }
445 469 case "pw": { $price = ($price * 12) / 52; break; }
446 470 case "pq": { $price = ($price * 12) / 4; break; }
447 471 case "pa": { $price = ($price * 12); break; }
448 472 }
449 473 }
450 - $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 ) ) : '-' );
451 476 break;
452 477 }
453 478 }
454 479 }
480 +
455 481 }
456 482
483 + // Stored price/frequency text is escaped above; currency and commercial HTML filters remain trusted.
457 484 return apply_filters( 'propertyhive_price_output', $return, $this, $currency, $prefix, $suffix );
458 485 }
459 486
460 487 /**
@@ -468,11 +495,13 @@
468 495 $price = '';
469 496
470 497 if ( $this->_for_sale == 'yes' )
471 498 {
472 - 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' )
473 502 {
474 - $price .= __( 'POA', 'propertyhive' );
503 + $price .= esc_html__( 'POA', 'propertyhive' );
475 504 }
476 505 else
477 506 {
478 507 $ph_countries = new PH_Countries();
@@ -488,17 +517,9 @@
488 517 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
489 518
490 519 if ( $this->_price_from != '' )
491 520 {
492 - $explode_price = explode(".", $this->_price_from);
493 - if ( count($explode_price) == 2 )
494 - {
495 - $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;
496 - }
497 - else
498 - {
499 - $price .= $prefix . number_format($this->_price_from, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
500 - }
521 + $price .= $prefix . esc_html( ph_display_price_field($this->_price_from, !$is_admin) ) . $suffix;
501 522 }
502 523 if ( $this->_price_to != '' && $this->_price_to != $this->_price_from )
503 524 {
504 525 if ( $price != '' )
@@ -504,27 +525,20 @@
504 525 if ( $price != '' )
505 526 {
506 527 $price .= ' - ';
507 528 }
508 - $explode_price = explode(".", $this->_price_to);
509 - if ( count($explode_price) == 2 )
510 - {
511 - $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;
512 - }
513 - else
514 - {
515 - $price .= $prefix . number_format($this->_price_to, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
516 - }
529 + $price .= $prefix . esc_html( ph_display_price_field($this->_price_to, !$is_admin) ) . $suffix;
517 530 }
518 531 if ( $price != '' )
519 532 {
520 533 $price_units = get_commercial_price_units( );
521 - $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] ) : '';
522 535 }
523 536 }
524 537 }
525 538
526 - 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 );
527 541 }
528 542
529 543 /**
530 544 * Get the formatted commercial rent. Show POA if on frontend and 'POA' ticked
@@ -537,11 +551,13 @@
537 551 $rent = '';
538 552
539 553 if ( $this->_to_rent == 'yes' )
540 554 {
541 - 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' )
542 558 {
543 - $rent .= __( 'POA', 'propertyhive' );
559 + $rent .= esc_html__( 'POA', 'propertyhive' );
544 560 }
545 561 else
546 562 {
547 563 $ph_countries = new PH_Countries();
@@ -557,17 +573,9 @@
557 573 $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
558 574
559 575 if ( $this->_rent_from != '' )
560 576 {
561 - $explode_rent = explode(".", $this->_rent_from);
562 - if ( count($explode_rent) == 2 )
563 - {
564 - $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;
565 - }
566 - else
567 - {
568 - $rent .= $prefix . number_format($this->_rent_from, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
569 - }
577 + $rent .= $prefix . esc_html( ph_display_price_field($this->_rent_from, !$is_admin) ) . $suffix;
570 578 }
571 579 if ( $this->_rent_to != '' && $this->_rent_to != $this->_rent_from )
572 580 {
573 581 if ( $rent != '' )
@@ -573,27 +581,20 @@
573 581 if ( $rent != '' )
574 582 {
575 583 $rent .= ' - ';
576 584 }
577 - $explode_rent = explode(".", $this->_rent_to);
578 - if ( count($explode_rent) == 2 )
579 - {
580 - $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;
581 - }
582 - else
583 - {
584 - $rent .= $prefix . number_format($this->_rent_to, 0, get_option('propertyhive_price_decimal_separator', '.'), get_option('propertyhive_price_thousand_separator', ',')) . $suffix;
585 - }
585 + $rent .= $prefix . esc_html( ph_display_price_field($this->_rent_to, !$is_admin) ) . $suffix;
586 586 }
587 587 if ( $rent != '' )
588 588 {
589 589 $price_units = get_commercial_price_units( );
590 - $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 );
591 591 }
592 592 }
593 593 }
594 594
595 - 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 );
596 597 }
597 598
598 599 public function get_formatted_floor_area( ) {
599 600
@@ -603,13 +604,13 @@
603 604 {
604 605 $explode_area = explode(".", $this->_floor_area_from);
605 606 if ( count($explode_area) == 2 )
606 607 {
607 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
608 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
608 609 }
609 610 else
610 611 {
611 - $area .= number_format($this->_floor_area_from, 0);
612 + $area .= number_format((float)$this->_floor_area_from, 0);
612 613 }
613 614 }
614 615 if ( $this->_floor_area_to != '' && $this->_floor_area_to != $this->_floor_area_from )
615 616 {
@@ -619,13 +620,13 @@
619 620 }
620 621 $explode_area = explode(".", $this->_floor_area_to);
621 622 if ( count($explode_area) == 2 )
622 623 {
623 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
624 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
624 625 }
625 626 else
626 627 {
627 - $area .= number_format($this->_floor_area_to, 0);
628 + $area .= number_format((float)$this->_floor_area_to, 0);
628 629 }
629 630 }
630 631
631 632 if ( $area != '' )
@@ -633,9 +634,9 @@
633 634 $area_units = get_area_units( );
634 635 $area .= ( isset($area_units[$this->_floor_area_units]) ) ? ' ' . $area_units[$this->_floor_area_units] : '';
635 636 }
636 637
637 - return $area;
638 + return apply_filters( 'propertyhive_floor_area_output', esc_html( $area ), $this );
638 639
639 640 }
640 641
641 642 public function get_formatted_site_area( ) {
@@ -646,13 +647,13 @@
646 647 {
647 648 $explode_area = explode(".", $this->_site_area_from);
648 649 if ( count($explode_area) == 2 )
649 650 {
650 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
651 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
651 652 }
652 653 else
653 654 {
654 - $area .= number_format($this->_site_area_from, 0);
655 + $area .= number_format((float)$this->_site_area_from, 0);
655 656 }
656 657 }
657 658 if ( $this->_site_area_to != '' && $this->_site_area_to != $this->_site_area_from )
658 659 {
@@ -662,13 +663,13 @@
662 663 }
663 664 $explode_area = explode(".", $this->_site_area_to);
664 665 if ( count($explode_area) == 2 )
665 666 {
666 - $area .= number_format($explode_area[0], 0) . '.' . $explode_area[1];
667 + $area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
667 668 }
668 669 else
669 670 {
670 - $area .= number_format($this->_site_area_to, 0);
671 + $area .= number_format((float)$this->_site_area_to, 0);
671 672 }
672 673 }
673 674
674 675 if ( $area != '' )
@@ -676,9 +677,9 @@
676 677 $area_units = get_area_units( );
677 678 $area .= ( isset($area_units[$this->_site_area_units]) ) ? ' ' . $area_units[$this->_site_area_units] : '';
678 679 }
679 680
680 - return $area;
681 + return apply_filters( 'propertyhive_site_area_output', esc_html( $area ), $this );
681 682
682 683 }
683 684
684 685 /**
@@ -696,12 +697,20 @@
696 697
697 698 $ph_countries = new PH_Countries();
698 699
699 700 $currency = $ph_countries->get_currency( $this->_currency );
700 - $prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
701 - $suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
702 701
703 - 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;
704 713 }
705 714
706 715 /**
707 716 * Get the available date, or 'Now' if date is in past
@@ -710,12 +719,17 @@
710 719 * @return string
711 720 */
712 721 public function get_available_date( )
713 722 {
714 - if (strtotime($this->_available_date))
723 + if ( $this->_available_date == '' )
715 724 {
716 - return date( get_option( 'date_format' ), strtotime($this->_available_date) );
725 + return '';
717 726 }
727 +
728 + if (strtotime($this->_available_date) > time())
729 + {
730 + return gmdate( get_option( 'date_format' ), strtotime($this->_available_date) );
731 + }
718 732 else
719 733 {
720 734 return __( 'Now', 'propertyhive' );
721 735 }
@@ -726,18 +740,25 @@
726 740 *
727 741 * @access public
728 742 * @return string
729 743 */
730 - public function get_formatted_description( ) {
744 + public function get_formatted_description( $plain_text = false ) {
731 745
732 - if ( $this->_department == 'commercial' )
746 + $department = $this->_department;
747 + if ( ph_get_custom_department_based_on( $department ) !== false )
733 748 {
734 - 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 );
735 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 + }
736 755 else
737 756 {
738 - return $this->get_formatted_rooms();
757 + $description = $this->get_formatted_rooms( $plain_text );
739 758 }
759 +
760 + return apply_filters( 'propertyhive_description_output', $description );
740 761 }
741 762
742 763 /**
743 764 * Get the full description by constructing the rooms
@@ -744,9 +765,9 @@
744 765 *
745 766 * @access public
746 767 * @return string
747 768 */
748 - public function get_formatted_rooms( ) {
769 + public function get_formatted_rooms( $plain_text = false ) {
749 770
750 771 $rooms = $this->_rooms;
751 772
752 773 $return = '';
@@ -754,25 +775,44 @@
754 775 if (isset($rooms) && $rooms != '' && $rooms > 0)
755 776 {
756 777 for ($i = 0; $i < $rooms; ++$i)
757 778 {
758 - $return .= '<p class="room">';
759 - if ($this->{'_room_name_' . $i} != '')
779 + if ( !$plain_text )
760 780 {
761 - $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>';
762 795 }
763 - if ($this->{'_room_dimensions_' . $i} != '')
764 - {
765 - $return .= ' <strong class="dimension">(' . $this->{'_room_dimensions_' . $i} . ')</strong>';
766 - }
767 - if ($this->{'_room_name_' . $i} != '' || $this->{'_room_dimensions_' . $i} != '')
796 + else
768 797 {
769 - $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";
770 811 }
771 - $return .= str_replace("\r\n", "", nl2br($this->{'_room_description_' . $i})) . '</p>';
772 812 }
773 813 }
774 -
814 +
775 815 return $return;
776 816 }
777 817
778 818 /**
@@ -780,9 +820,9 @@
780 820 *
781 821 * @access public
782 822 * @return string
783 823 */
784 - public function get_formatted_descriptions( ) {
824 + public function get_formatted_descriptions( $plain_text = false ) {
785 825
786 826 $descriptions = $this->_descriptions;
787 827
788 828 $return = '';
@@ -790,14 +830,30 @@
790 830 if (isset($descriptions) && $descriptions != '' && $descriptions > 0)
791 831 {
792 832 for ($i = 0; $i < $descriptions; ++$i)
793 833 {
794 - $return .= '<p class="description-section">';
795 - if ($this->{'_description_name_' . $i} != '')
834 + if ( !$plain_text )
796 835 {
797 - $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>';
798 847 }
799 - $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 + }
800 856 }
801 857 }
802 858
803 859 return $return;
@@ -810,9 +866,9 @@
810 866 * @return string
811 867 */
812 868 public function get_property_type()
813 869 {
814 - $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"));
815 871
816 872 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
817 873 {
818 874 return implode(", ", $term_list);
@@ -882,9 +938,9 @@
882 938 * @return string
883 939 */
884 940 public function get_tenure()
885 941 {
886 - $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"));
887 943
888 944 if ( !is_wp_error($term_list) && is_array($term_list) && !empty($term_list) )
889 945 {
890 946 return implode(", ", $term_list);
@@ -990,28 +1046,14 @@
990 1046 * @return string
991 1047 */
992 1048 public function get_imported_id()
993 1049 {
994 - global $wpdb;
995 -
996 - $row = $wpdb->get_row(
997 - "
998 - SELECT meta_value
999 - FROM {$wpdb->prefix}postmeta
1000 - WHERE
1001 - meta_key LIKE '_imported_ref_%'
1002 - AND
1003 - post_id = '" . $this->id . "'
1004 - LIMIT 1
1005 - ",
1006 - ARRAY_A
1007 - );
1008 -
1009 - if ( null !== $row )
1010 - {
1011 - 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 + }
1012 1055 }
1013 -
1014 1056 return '';
1015 1057 }
1016 1058
1017 1059 /**
@@ -1048,9 +1090,9 @@
1048 1090 }
1049 1091 }
1050 1092 }
1051 1093
1052 - return $features;
1094 + return apply_filters( 'propertyhive_property_features', $features );
1053 1095 }
1054 1096
1055 1097 /**
1056 1098 * Get the full formatted address
@@ -1161,8 +1203,214 @@
1161 1203
1162 1204 return $return;
1163 1205 }
1164 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 +
1165 1413 public function get_office_name()
1166 1414 {
1167 1415 return get_the_title( $this->_office_id );
1168 1416 }
@@ -1199,8 +1447,96 @@
1199 1447 {
1200 1448 return get_post_meta( $this->_office_id, '_office_email_address_' . ( str_replace("residential-", "", $this->_department) ), TRUE );
1201 1449 }
1202 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 +
1203 1539 /**
1204 1540 * Returns boolean whether the property is featured or not
1205 1541 *
1206 1542 * @access public
@@ -1207,9 +1543,9 @@
1207 1543 * @return string
1208 1544 */
1209 1545 public function is_featured() {
1210 1546
1211 - if (isset($the_property->_featured) && $the_property->_featured == 'yes')
1547 + if ( $this->_featured == 'yes' )
1212 1548 {
1213 1549 return true;
1214 1550 }
1215 1551