* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved. * @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html * * @website http://www.wpopal.com * @support http://www.wpopal.com/support/forum.html */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } /** * @class Opalestate_Property * * @version 1.0 */ class Opalestate_Property { /** * @var Integer $post_id * * @access protected */ public $post_id; /** * @var array $metabox_info * * @access protected */ protected $metabox_info; /** * @var float $price * * @access protected */ protected $price; /** * @var float $saleprice * * @access protected */ protected $saleprice; /** * @var String $map * * @access protected */ protected $map; /** * @var Integer $address * * @access protected */ public $address; /** * @var String $sku * * @access protected */ public $sku; /** * @var String $latitude * * @access protected */ public $latitude; /** * @var String $longitude * * @access protected */ public $longitude; /** * @var Integer $featured 1 or 0 * * @access protected */ public $featured; /** * @var array Property page settings $property_settings * * @access public */ public $property_settings; /** * Constructor */ public function __construct( $post_id ) { $this->post_id = $post_id; $this->map = $this->get_metabox_value( 'map' ); $this->address = $this->get_metabox_value( 'address' ); $this->price = $this->get_metabox_value( 'price' ); $this->saleprice = $this->get_metabox_value( 'saleprice' ); $this->before_pricelabel = $this->get_metabox_value( 'before_pricelabel' ); $this->pricelabel = $this->get_metabox_value( 'pricelabel' ); $this->featured = $this->get_metabox_value( 'featured' ); $this->sku = $this->get_metabox_value( 'sku' ); $this->latitude = isset( $this->map['latitude'] ) ? $this->map['latitude'] : ''; $this->longitude = isset( $this->map['longitude'] ) ? $this->map['longitude'] : ''; } /** * Get A Instance Of Opalestate_Property */ public static function get_instance( $post_id ) { static $_instance; if ( ! $_instance ) { $_instance = new Opalestate_Property( $post_id ); } return $_instance; } public function get_block_setting( $key ) { if ( ! $this->property_settings ) { $keys = [ 'amenities', 'attachments', 'facilities', 'video', 'virtual_tour', 'map', 'nearby', 'walkscores', 'apartments', 'floor_plans', 'views_statistics', 'author_box', 'enquire_form', 'mortgage', ]; foreach ( $keys as $key ) { $this->property_settings[ $key ] = opalestate_get_option( 'enable_single_' . $key ); } } return $this->property_settings[ $key ]; } /** * Gets Amenities * * @access public * @param string $all * @return array */ public function get_meta_fullinfo() { if ( empty( $this->metabox_info ) ) { $fields = Opalestate_Property_MetaBox::metaboxes_info_fields(); foreach ( $fields as $a => $field ) { $id = str_replace( OPALESTATE_PROPERTY_PREFIX, '', $field['id'] ); if ( $field['type'] == 'multicheck' || $field['type'] == 'select' ) { $opt_values = (array) get_post_meta( $this->post_id, $field['id'] ); if ( ! empty( $opt_values ) && isset( $field['options'] ) ) { $tmp = []; foreach ( $opt_values as $key => $val ) { if ( isset( $field['options'][ $val ] ) ) { $tmp[ $val ] = $field['options'][ $val ]; } } $opt_values = $tmp; } $value = implode( ", ", $opt_values ); } else { $value = get_post_meta( $this->post_id, $field['id'], true ); } $value = isset( $field['unit'] ) && $field['unit'] ? $value . ' ' . $field['unit'] : $value; $this->metabox_info[ $id ] = [ 'label' => $field['name'], 'value' => $value ]; } } return apply_filters( 'opalestate_property_metabox_info', $this->metabox_info ); } public function get_id() { return $this->post_id; } /** * */ public function is_featured() { return $this->featured; } /** * */ public function get_meta_search_objects() { $prop = new stdClass(); $map = $this->get_metabox_value( 'map' ); $image_id = get_post_thumbnail_id( $this->post_id ); if ( $image_id ) { $url = wp_get_attachment_url( $image_id, opalestate_options( 'loop_image_size', 'large' ), true ); } else { $url = opalestate_get_image_placeholder( apply_filters( 'opalestate_loop_property_thumbnail', 'large' ), true ); } $prop->id = $this->post_id; $prop->title = get_the_title(); $prop->url = get_permalink( $this->post_id ); $prop->lat = $map['latitude']; $prop->lng = $map['longitude']; $prop->address = $this->address; $prop->pricehtml = opalestate_price_format( $this->get_price() ); $prop->pricelabel = $this->get_price_label(); $prop->thumb = $url; if ( file_exists( get_template_directory() . '/images/map/market_icon.png' ) ) { $prop->icon = get_template_directory_uri() . '/images/map/market_icon.png'; } else { $prop->icon = OPALESTATE_PLUGIN_URL . '/assets/map/market_icon.png'; } $prop->icon = apply_filters( 'opalestate_prop_icon', $prop->icon ); $prop->featured = $this->featured; $metas = Opalestate_Property_MetaBox::metaboxes_info_fields(); foreach ( $metas as $key => $field ) { $id = str_replace( OPALESTATE_PROPERTY_PREFIX, "", $field['id'] ); $prop->$id = get_post_meta( $this->post_id, $field['id'], true ); } $metas = $this->get_meta_shortinfo(); $prop->metas = $metas; $prop->status = $this->render_statuses(); $terms = wp_get_post_terms( $this->post_id, 'opalestate_types' ); if ( $terms ) { $term = reset( $terms ); $icon = get_term_meta( $term->term_id, 'opalestate_type_iconmarker', true ); if ( $icon ) { $prop->icon = $icon; } } return $prop; } /** * Gets Amenities * * @access public * @param string $all * @return array */ public function get_meta_shortinfo() { $output = []; $meta = opalestate_options( 'show_property_meta' ); $meta = apply_filters( 'opalestate_property_meta_shortinfo_fields', $meta ); if ( ! empty( $meta ) ) { $fields = $this->get_meta_fullinfo(); foreach ( $meta as $key => $value ) { if ( isset( $fields[ $value ] ) ) { $output[ $value ] = $fields[ $value ]; } } } return $output; } /** * Gets Amenities * * @access public * @param string $all * @return array */ public function get_amenities( $all = true ) { if ( $all ) { $terms = Opalestate_Query::get_amenities(); } else { $terms = wp_get_post_terms( $this->post_id, 'opalestate_amenities' ); } return $terms; } /** * */ public function get_locations() { $terms = wp_get_post_terms( $this->post_id, 'opalestate_location' ); if ( $terms ) { return $terms; } return []; } /** * Gets locations * * @access public * @return array */ public function render_locations() { $terms = wp_get_post_terms( $this->post_id, 'opalestate_location' ); if ( $terms ) { $output = ''; foreach ( $terms as $key => $term ) { $output .= '' . $term->name . ''; if ( $key < ( count( $terms ) - 1 ) ) { $output .= ", "; } } $output .= ''; echo $output; } } /** * Gets labels * * @access public * @return array */ public function get_labels() { return wp_get_post_terms( $this->post_id, 'opalestate_label' ); } /** * Render labels. * * @access public * @return string */ public function render_labels() { $labels = $this->get_labels(); if ( empty( $labels ) ) { return; } $output = '