0 )
{
}
else
{
// Must be post object
$id = $id->ID;
}
$this->get_property( $id );
}
}
/**
* Gets a property from the database.
*
* @access public
* @param int $id (default: 0)
* @return bool
*/
public function get_property( $id = 0 ) {
if ( ! $id ) {
return false;
}
if ( $result = get_post( $id ) ) {
$this->populate( $result );
return true;
}
return false;
}
/**
* __isset function.
*
* @access public
* @param mixed $key
* @return bool
*/
public function __isset( $key ) {
if ( ! $this->id ) {
return false;
}
return metadata_exists( 'post', $this->id, $key );
}
/**
* __get function.
*
* @access public
* @param mixed $key
* @return mixed
*/
public function __get( $key ) {
$value = '';
if ( method_exists($this, 'get_' . $key) && 'available_date' != $key )
{
$value = $this->{'get_' . $key}();
}
else
{
$value = get_post_meta( $this->id, $key, true );
if ($value == '')
{
$value = get_post_meta( $this->id, '_' . $key, true );
}
}
$value = apply_filters( 'propertyhive_get_detail', $value, $key, $this );
return $value;
}
/**
* Populates a property from the loaded post data.
*
* @access public
* @param mixed $result
* @return void
*/
public function populate( $result ) {
// Standard post data
$this->id = $result->ID;
$this->post_title = $result->post_title;
$this->post_status = $result->post_status;
$this->post_excerpt = apply_filters( 'propertyhive_property_post_excerpt', $result->post_excerpt );
}
/**
* get_gallery_attachment_ids function.
*
* @access public
* @return array
*/
public function get_gallery_attachment_ids()
{
$photos = $this->photos;
if ( is_array($photos) )
{
$photos = array_filter( $photos );
}
else
{
$photos = array();
}
return apply_filters( 'propertyhive_property_gallery_attachment_ids', $photos, $this );
}
/**
* Gets the first photo
*
* @access public
* @param string $size
* @return string
*/
public function get_main_photo_src( $size = 'thumbnail' ) {
$return = false;
if ( get_option('propertyhive_images_stored_as', '') == 'urls' )
{
$photos = $this->_photo_urls;
if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]) && isset($photos[0]['url']))
{
$return = $photos[0]['url'];
}
}
else
{
$photos = $this->_photos;
if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]))
{
$image_attributes = wp_get_attachment_image_src( $photos[0], $size );
if( $image_attributes )
{
$return = $image_attributes[0];
}
}
}
return $return;
}
/**
* get_floorplan_attachment_ids function.
*
* @access public
* @return array
*/
public function get_floorplan_attachment_ids()
{
$floorplans = $this->_floorplans;
if ( is_array($floorplans) )
{
$floorplans = array_filter( $floorplans );
}
else
{
$floorplans = array();
}
return apply_filters( 'propertyhive_property_floorplan_attachment_ids', $floorplans, $this );
}
/**
* get_brochure_attachment_ids function.
*
* @access public
* @return array
*/
public function get_brochure_attachment_ids()
{
$brochures = $this->_brochures;
if ( is_array($brochures) )
{
$brochures = array_filter( $brochures );
}
else
{
$brochures = array();
}
return apply_filters( 'propertyhive_property_brochure_attachment_ids', $brochures, $this );
}
/**
* get_epc_attachment_ids function.
*
* @access public
* @return array
*/
public function get_epc_attachment_ids()
{
$epcs = $this->_epcs;
if ( is_array($epcs) )
{
$epcs = array_filter( $epcs );
}
else
{
$epcs = array();
}
return apply_filters( 'propertyhive_property_epc_attachment_ids', $epcs, $this );
}
/**
* get_virtual_tours function.
*
* @access public
* @return array
*/
public function get_virtual_tours()
{
$num_property_virtual_tours = get_post_meta($this->id, '_virtual_tours', TRUE);
if ($num_property_virtual_tours == '') { $num_property_virtual_tours = 0; }
$virtual_tours = array();
for ($i = 0; $i < $num_property_virtual_tours; ++$i)
{
$label = get_post_meta($this->id, '_virtual_tour_label_' . $i, TRUE);
$virtual_tours[] = array(
'url' => get_post_meta($this->id, '_virtual_tour_' . $i, TRUE),
'label' => ( $label != '' ? $label : __( 'Virtual Tour', 'propertyhive' ) ),
);
}
return apply_filters( 'propertyhive_property_virtual_tours', array_filter( $virtual_tours ), $this );
}
/**
* get_virtual_tour_urls function.
* deprecated
*
* @access public
* @return array
*/
public function get_virtual_tour_urls()
{
$num_property_virtual_tours = get_post_meta($this->id, '_virtual_tours', TRUE);
if ($num_property_virtual_tours == '') { $num_property_virtual_tours = 0; }
$virtual_tour_urls = array();
for ($i = 0; $i < $num_property_virtual_tours; ++$i)
{
$virtual_tour_urls[] = get_post_meta($this->id, '_virtual_tour_' . $i, TRUE);
}
return apply_filters( 'propertyhive_property_virtual_tour_urls', array_filter( $virtual_tour_urls ), $this );
}
/**
* Get the formatted price based on department. Show POA if on frontend and 'POA' ticked
*
* @access public
* @return string
*/
public function get_formatted_price( $plain_text = false ) {
$return = '';
$currency = array();
$prefix = '';
$suffix = '';
$is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true;
if ( $this->_department == 'commercial' || ph_get_custom_department_based_on( $this->_department ) == 'commercial' )
{
if (
!$is_admin &&
$this->_for_sale == 'yes' && $this->_price_poa == 'yes' &&
$this->_to_rent == 'yes' && $this->_rent_poa == 'yes'
)
{
$return = __( 'POA', 'propertyhive' );
}
else
{
// Price Details
$price = $this->get_formatted_commercial_price();
if ( $price != '' && !$plain_text )
{
$price = '' . $price . '';
}
// Rent Details
$rent = $this->get_formatted_commercial_rent();
if ( $rent != '' && !$plain_text ) { $rent = '' . $rent . ''; }
if ( $price != '' && $rent != '' )
{
$price .= !$plain_text ? '
' : "\n";
}
$price .= $rent;
$return = $price;
}
}
else
{
if ( !$is_admin && $this->_poa == 'yes')
{
$return = __( 'POA', 'propertyhive' );
}
else
{
$ph_countries = new PH_Countries();
if ( !$is_admin )
{
if ( isset($_GET['currency']) )
{
if ( $_GET['currency'] != '' )
{
$requested_currency = $ph_countries->get_currency( sanitize_text_field($_GET['currency']) );
if ( $requested_currency !== FALSE )
{
$currency = $requested_currency;
$currency['exchange_rate'] = 1;
$exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
if ( isset($exchange_rates[$_GET['currency']]) )
{
$currency['exchange_rate'] = $exchange_rates[sanitize_text_field($_GET['currency'])];
}
}
}
else
{
$default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
if ( $default_currency != '' )
{
$requested_currency = $ph_countries->get_currency( $default_currency );
if ( $requested_currency !== FALSE )
{
$currency = $requested_currency;
$currency['exchange_rate'] = 1;
$exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
if ( isset($exchange_rates[$default_currency]) )
{
$currency['exchange_rate'] = $exchange_rates[$default_currency];
}
}
}
}
}
elseif ( isset($_COOKIE['propertyhive_currency']) && $_COOKIE['propertyhive_currency'] != '' )
{
$currency = @json_decode(html_entity_decode($_COOKIE['propertyhive_currency']), true);
}
else
{
$default_currency = apply_filters( 'propertyhive_default_display_currency', '' );
if ( $default_currency != '' )
{
$requested_currency = $ph_countries->get_currency( $default_currency );
if ( $requested_currency !== FALSE )
{
$currency = $requested_currency;
$currency['exchange_rate'] = 1;
$exchange_rates = get_option( 'propertyhive_currency_exchange_rates', array() );
if ( isset($exchange_rates[$default_currency]) )
{
$currency['exchange_rate'] = $exchange_rates[$default_currency];
}
}
}
}
}
if ( empty($currency) )
{
if ($this->_currency != '')
{
$currency = $ph_countries->get_currency( $this->_currency );
}
else
{
$currency = $ph_countries->get_currency( 'GBP' );
}
}
$prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
$suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
$department = $this->_department;
if ( ph_get_custom_department_based_on( $department ) !== false )
{
$department = ph_get_custom_department_based_on( $department );
}
switch ($department)
{
case "residential-sales":
{
$price = $this->_price;
if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' )
{
// Round this after calculation
$price = round($this->_price_actual * $currency['exchange_rate'], 0);
}
$return = ( ( $price != '' ) ? $prefix . ph_display_price_field($price, !$is_admin) . $suffix : '-' );
break;
}
case "residential-lettings":
{
$price = $this->_rent;
if ( $currency['currency_code'] != $this->currency && isset($currency['exchange_rate']) && $price != '' )
{
// Round this after calculation as we only want to check the first two decimal places
$price = round($this->_price_actual * $currency['exchange_rate'], 2);
switch ( $this->_rent_frequency )
{
case "pd": { $price = ($price * 365) / 52; break; }
case "pw": { $price = ($price * 12) / 52; break; }
case "pq": { $price = ($price * 12) / 4; break; }
case "pa": { $price = ($price * 12); break; }
}
}
$return = ( ( $price != '' ) ? $prefix . ph_display_price_field($price, !$is_admin) . $suffix . ' ' . __( $this->_rent_frequency, 'propertyhive' ) : '-' );
break;
}
}
}
}
return apply_filters( 'propertyhive_price_output', $return, $this, $currency, $prefix, $suffix );
}
/**
* Get the formatted commercial price. Show POA if on frontend and 'POA' ticked
*
* @access public
* @return string
*/
public function get_formatted_commercial_price( ) {
$price = '';
if ( $this->_for_sale == 'yes' )
{
$is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true;
if ( !$is_admin && $this->_price_poa == 'yes' )
{
$price .= __( 'POA', 'propertyhive' );
}
else
{
$ph_countries = new PH_Countries();
if ( $this->_commercial_price_currency != '' )
{
$currency = $ph_countries->get_currency( $this->_commercial_price_currency );
}
else
{
$currency = $ph_countries->get_currency( 'GBP' );
}
$prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
$suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
if ( $this->_price_from != '' )
{
$price .= $prefix . ph_display_price_field($this->_price_from, !$is_admin) . $suffix;
}
if ( $this->_price_to != '' && $this->_price_to != $this->_price_from )
{
if ( $price != '' )
{
$price .= ' - ';
}
$price .= $prefix . ph_display_price_field($this->_price_to, !$is_admin) . $suffix;
}
if ( $price != '' )
{
$price_units = get_commercial_price_units( );
$price .= ( isset($price_units[$this->_price_units]) ) ? ' ' . $price_units[$this->_price_units] : '';
}
}
}
return apply_filters( 'propertyhive_commercial_price_output', $price, $this );
}
/**
* Get the formatted commercial rent. Show POA if on frontend and 'POA' ticked
*
* @access public
* @return string
*/
public function get_formatted_commercial_rent( ) {
$rent = '';
if ( $this->_to_rent == 'yes' )
{
$is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true;
if ( !$is_admin && $this->_rent_poa == 'yes' )
{
$rent .= __( 'POA', 'propertyhive' );
}
else
{
$ph_countries = new PH_Countries();
if ( $this->_commercial_rent_currency != '' )
{
$currency = $ph_countries->get_currency( $this->_commercial_rent_currency );
}
else
{
$currency = $ph_countries->get_currency( 'GBP' );
}
$prefix = ( ($currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
$suffix = ( (!$currency['currency_prefix']) ? $currency['currency_symbol'] : '' );
if ( $this->_rent_from != '' )
{
$rent .= $prefix . ph_display_price_field($this->_rent_from, !$is_admin) . $suffix;
}
if ( $this->_rent_to != '' && $this->_rent_to != $this->_rent_from )
{
if ( $rent != '' )
{
$rent .= ' - ';
}
$rent .= $prefix . ph_display_price_field($this->_rent_to, !$is_admin) . $suffix;
}
if ( $rent != '' )
{
$price_units = get_commercial_price_units( );
$rent .= ' ' . __( ( isset($price_units[$this->_rent_units]) ? $price_units[$this->_rent_units] : $this->_rent_units ), 'propertyhive' );
}
}
}
return apply_filters( 'propertyhive_commercial_rent_output', $rent, $this );
}
public function get_formatted_floor_area( ) {
$area = '';
if ( $this->_floor_area_from != '' )
{
$explode_area = explode(".", $this->_floor_area_from);
if ( count($explode_area) == 2 )
{
$area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
}
else
{
$area .= number_format((float)$this->_floor_area_from, 0);
}
}
if ( $this->_floor_area_to != '' && $this->_floor_area_to != $this->_floor_area_from )
{
if ( $area != '' )
{
$area .= ' - ';
}
$explode_area = explode(".", $this->_floor_area_to);
if ( count($explode_area) == 2 )
{
$area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
}
else
{
$area .= number_format((float)$this->_floor_area_to, 0);
}
}
if ( $area != '' )
{
$area_units = get_area_units( );
$area .= ( isset($area_units[$this->_floor_area_units]) ) ? ' ' . $area_units[$this->_floor_area_units] : '';
}
return apply_filters( 'propertyhive_floor_area_output', $area, $this );
}
public function get_formatted_site_area( ) {
$area = '';
if ( $this->_site_area_from != '' )
{
$explode_area = explode(".", $this->_site_area_from);
if ( count($explode_area) == 2 )
{
$area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
}
else
{
$area .= number_format((float)$this->_site_area_from, 0);
}
}
if ( $this->_site_area_to != '' && $this->_site_area_to != $this->_site_area_from )
{
if ( $area != '' )
{
$area .= ' - ';
}
$explode_area = explode(".", $this->_site_area_to);
if ( count($explode_area) == 2 )
{
$area .= number_format((float)$explode_area[0], 0) . '.' . $explode_area[1];
}
else
{
$area .= number_format((float)$this->_site_area_to, 0);
}
}
if ( $area != '' )
{
$area_units = get_area_units( );
$area .= ( isset($area_units[$this->_site_area_units]) ) ? ' ' . $area_units[$this->_site_area_units] : '';
}
return apply_filters( 'propertyhive_site_area_output', $area, $this );
}
/**
* Get the formatted deposit
*
* @access public
* @return string
*/
public function get_formatted_deposit( )
{
if ( $this->_deposit == '' )
{
return '';
}
$ph_countries = new PH_Countries();
$currency = $ph_countries->get_currency( $this->_currency );
$is_admin = ( !is_admin() || ( is_admin() && defined('DOING_AJAX') && DOING_AJAX ) ) ? false : true;
if ( $currency === false )
{
return ph_display_price_field($this->_deposit, !$is_admin);
}
$prefix = ( !isset($currency['currency_prefix']) || ( isset($currency['currency_prefix']) && $currency['currency_prefix'] ) ) ? $currency['currency_symbol'] : '';
$suffix = ( isset($currency['currency_prefix']) && !$currency['currency_prefix'] ) ? $currency['currency_symbol'] : '';
return $prefix . ph_display_price_field($this->_deposit, !$is_admin) . $suffix;
}
/**
* Get the available date, or 'Now' if date is in past
*
* @access public
* @return string
*/
public function get_available_date( )
{
if ( $this->_available_date == '' )
{
return '';
}
if (strtotime($this->_available_date) > time())
{
return date( get_option( 'date_format' ), strtotime($this->_available_date) );
}
else
{
return __( 'Now', 'propertyhive' );
}
}
/**
* Get the full description by constructing the rooms or commercial description (dependant on department)
*
* @access public
* @return string
*/
public function get_formatted_description( $plain_text = false ) {
$department = $this->_department;
if ( ph_get_custom_department_based_on( $department ) !== false )
{
$department = ph_get_custom_department_based_on( $department );
}
if ( $department == 'commercial' )
{
$description = $this->get_formatted_descriptions( $plain_text ); // Haven't called this commercial_descriptions as we might use generic descriptions for other areas going forward
}
else
{
$description = $this->get_formatted_rooms( $plain_text );
}
return apply_filters( 'propertyhive_description_output', $description );
}
/**
* Get the full description by constructing the rooms
*
* @access public
* @return string
*/
public function get_formatted_rooms( $plain_text = false ) {
$rooms = $this->_rooms;
$return = '';
if (isset($rooms) && $rooms != '' && $rooms > 0)
{
for ($i = 0; $i < $rooms; ++$i)
{
if ( !$plain_text )
{
$return .= '
';
if ($this->{'_room_name_' . $i} != '')
{
$return .= '' . $this->{'_room_name_' . $i} . '';
}
if ($this->{'_room_dimensions_' . $i} != '')
{
$return .= ' ' . $this->{'_room_dimensions_' . $i} . '';
}
if ($this->{'_room_name_' . $i} != '' || $this->{'_room_dimensions_' . $i} != '')
{
$return .= '
';
}
$return .= str_replace("\r\n", "", nl2br($this->{'_room_description_' . $i})) . '
';
if ($this->{'_description_name_' . $i} != '')
{
$return .= '' . $this->{'_description_name_' . $i} . '
';
}
$return .= str_replace("\r\n", "", nl2br($this->{'_description_' . $i})) . '