Origin commit
This commit is contained in:
690
inc/property/class-metabox-property-admin.php
Executable file
690
inc/property/class-metabox-property-admin.php
Executable file
@@ -0,0 +1,690 @@
|
||||
<?php
|
||||
/**
|
||||
* $Desc$
|
||||
*
|
||||
* @version $Id$
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @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_MetaBox {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function register_admin_fields() {
|
||||
$prefix = OPALESTATE_PROPERTY_PREFIX;
|
||||
$box_options = [
|
||||
'id' => 'property_metabox',
|
||||
'title' => esc_html__( 'Property Metabox', 'opalestate-pro' ),
|
||||
'object_types' => [ 'opalestate_property' ],
|
||||
'show_names' => true,
|
||||
];
|
||||
|
||||
// Setup meta box
|
||||
$cmb = new_cmb2_box( $box_options );
|
||||
|
||||
// Setting tabs
|
||||
$tabs_setting = [
|
||||
'config' => $box_options,
|
||||
'layout' => 'vertical', // Default : horizontal
|
||||
'tabs' => [],
|
||||
];
|
||||
|
||||
|
||||
$tabs_setting['tabs'][] = [
|
||||
'id' => 'p-general',
|
||||
'icon' => 'dashicons-admin-home',
|
||||
'title' => esc_html__( 'General', 'opalestate-pro' ),
|
||||
'fields' => $this->metaboxes_management_fields(),
|
||||
];
|
||||
|
||||
$tabs_setting['tabs'][] = [
|
||||
'id' => 'p-prices',
|
||||
'icon' => 'dashicons-admin-tools',
|
||||
'title' => esc_html__( 'Prices', 'opalestate-pro' ),
|
||||
'fields' => $this->metaboxes_price_fields(),
|
||||
];
|
||||
|
||||
$tabs_setting['tabs'][] = [
|
||||
'id' => 'p-information',
|
||||
'icon' => 'dashicons-admin-post',
|
||||
'title' => esc_html__( 'Information', 'opalestate-pro' ),
|
||||
'fields' => $this->metaboxes_info_fields(),
|
||||
];
|
||||
|
||||
$tabs_setting['tabs'][] = [
|
||||
'id' => 'p-facilities',
|
||||
'icon' => 'dashicons-grid-view',
|
||||
'title' => esc_html__( 'Facility', 'opalestate-pro' ),
|
||||
'fields' => $this->metaboxes_public_facilities_fields(),
|
||||
];
|
||||
|
||||
|
||||
$tabs_setting['tabs'][] = [
|
||||
'id' => 'p-floor-plans',
|
||||
'icon' => 'dashicons-grid-view',
|
||||
'title' => esc_html__( 'Floor Plan', 'opalestate-pro' ),
|
||||
'fields' => $this->metaboxes_floor_plans(),
|
||||
];
|
||||
|
||||
$tabs_setting['tabs'][] = [
|
||||
'id' => 'p-apartments',
|
||||
'icon' => 'dashicons-admin-multisite',
|
||||
'title' => esc_html__( 'Apartments', 'opalestate-pro' ),
|
||||
'fields' => $this->metaboxes_apartments(),
|
||||
];
|
||||
|
||||
////
|
||||
$tabs_setting['tabs'][] = [
|
||||
'id' => 'p-gallery',
|
||||
'icon' => 'dashicons-format-gallery',
|
||||
'title' => esc_html__( 'Gallery', 'opalestate-pro' ),
|
||||
'fields' => [
|
||||
[
|
||||
'id' => "{$prefix}gallery",
|
||||
'name' => esc_html__( 'Images Gallery', 'opalestate-pro' ),
|
||||
'type' => 'file_list',
|
||||
'description' => esc_html__( 'Select one or more images to show as gallery', 'opalestate-pro' ),
|
||||
],
|
||||
],
|
||||
];
|
||||
///
|
||||
$tabs_setting['tabs'][] = [
|
||||
'id' => 'p-vt_gallery',
|
||||
'title' => esc_html__( 'Virtual Tour 360', 'opalestate-pro' ),
|
||||
'icon' => 'dashicons-format-image',
|
||||
'fields' => [
|
||||
[
|
||||
'id' => "{$prefix}vt_gallery",
|
||||
'name' => esc_html__( 'Manual Images 360 ', 'opalestate-pro' ),
|
||||
'type' => 'opal_upload',
|
||||
'description' => esc_html__( 'Select one or more images to show as gallery', 'opalestate-pro' ),
|
||||
],
|
||||
[
|
||||
'id' => "{$prefix}virtual",
|
||||
'name' => esc_html__( 'Or 360° Virtual Tour', 'opalestate-pro' ),
|
||||
'type' => 'textarea_code',
|
||||
'description' => esc_html__( 'Input iframe to show 360° Virtual Tour.', 'opalestate-pro' ),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
///
|
||||
$tabs_setting['tabs'][] = [
|
||||
'id' => 'p-attachments',
|
||||
'icon' => 'dashicons-media-default',
|
||||
'title' => esc_html__( 'Attachments', 'opalestate-pro' ),
|
||||
'fields' => [
|
||||
[
|
||||
'id' => "{$prefix}attachments",
|
||||
'name' => esc_html__( 'Attachments', 'opalestate-pro' ),
|
||||
'type' => 'file_list',
|
||||
'options' => [
|
||||
'url' => false, // Hide the text input for the url
|
||||
],
|
||||
'description' => esc_html__( 'Select one or more files to allow download', 'opalestate-pro' ),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$tabs_setting['tabs'][] = [
|
||||
'id' => 'p-agents',
|
||||
'icon' => 'dashicons-admin-users',
|
||||
'title' => esc_html__( 'Contact Member', 'opalestate-pro' ),
|
||||
'fields' => $this->metaboxes_members_fields(),
|
||||
];
|
||||
|
||||
$tabs_setting['tabs'][] = [
|
||||
'id' => 'p-assignment',
|
||||
'icon' => 'dashicons-admin-users',
|
||||
'title' => esc_html__( 'User Assignment', 'opalestate-pro' ),
|
||||
'fields' => $this->metaboxes_assignment_fields(),
|
||||
];
|
||||
|
||||
$tabs_setting['tabs'][] = [
|
||||
'id' => 'p-layout',
|
||||
'title' => esc_html__( 'Layout', 'opalestate-pro' ),
|
||||
'fields' => $this->metaboxes_layout_fields(),
|
||||
];
|
||||
|
||||
// Set tabs
|
||||
$cmb->add_field( [
|
||||
'id' => '__tabs',
|
||||
'type' => 'tabs',
|
||||
'tabs' => $tabs_setting,
|
||||
] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function metaboxes_management_fields() {
|
||||
$prefix = OPALESTATE_PROPERTY_PREFIX;
|
||||
$fields = [
|
||||
[
|
||||
'name' => esc_html__( 'Featured', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'featured',
|
||||
'type' => 'switch',
|
||||
'options' => [
|
||||
0 => esc_html__( 'No', 'opalestate-pro' ),
|
||||
1 => esc_html__( 'Yes', 'opalestate-pro' ),
|
||||
],
|
||||
'default' => 0,
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Property SKU', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'sku',
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Please Enter Your Property SKU', 'opalestate-pro' ),
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'map',
|
||||
'name' => esc_html__( 'Location', 'opalestate-pro' ),
|
||||
'type' => 'opal_map',
|
||||
'sanitization_cb' => 'opal_map_sanitise',
|
||||
'split_values' => true,
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Postal Code / Zip', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'zipcode',
|
||||
'type' => 'text',
|
||||
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Google Map View', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'enablemapview',
|
||||
'type' => 'switch',
|
||||
'options' => [
|
||||
1 => esc_html__( 'Yes', 'opalestate-pro' ),
|
||||
0 => esc_html__( 'No', 'opalestate-pro' ),
|
||||
],
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Address', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'address',
|
||||
'type' => 'textarea_small',
|
||||
'attributes' => [
|
||||
'required' => 'required',
|
||||
],
|
||||
],
|
||||
|
||||
|
||||
[
|
||||
'id' => "{$prefix}video",
|
||||
'name' => esc_html__( 'Video', 'opalestate-pro' ),
|
||||
'type' => 'text_url',
|
||||
'description' => esc_html__( 'Input for videos, audios from Youtube, Vimeo and all supported sites by WordPress. It has preview feature.', 'opalestate-pro' ),
|
||||
],
|
||||
];
|
||||
|
||||
return apply_filters( 'opalestate_postype_property_metaboxes_fields_management', $fields );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function metaboxes_price_fields() {
|
||||
$prefix = OPALESTATE_PROPERTY_PREFIX;
|
||||
|
||||
$currency = opalestate_currency_symbol() ? ' (' . opalestate_currency_symbol() . ')' : ' ($)';
|
||||
|
||||
$fields = [
|
||||
[
|
||||
'id' => $prefix . 'price',
|
||||
'name' => esc_html__( 'Regular Price', 'opalestate-pro' ) . $currency,
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Enter amount without currency', 'opalestate-pro' ),
|
||||
'attributes' => opalestate_get_option( 'require_input_price' ) ? [ 'required' => 'required' ] : '',
|
||||
'before_row' => '<div class="row-group-features group-has-three group-price clearfix"><h3>' . ( is_admin() ? "" : esc_html__( 'Price', 'opalestate-pro' ) ) . '</h3>', // callback
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'saleprice',
|
||||
'name' => esc_html__( 'Sale Price', 'opalestate-pro' ) . $currency,
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Enter amount without currency', 'opalestate-pro' ),
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'before_pricelabel',
|
||||
'name' => esc_html__( 'Before Price Label (optional)', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Before Price Label (e.g. "from")', 'opalestate-pro' ),
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'pricelabel',
|
||||
'name' => esc_html__( 'After Price Label (optional)', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'After Price Label (e.g. "per month")', 'opalestate-pro' ),
|
||||
'after_row' => '</div>', // callback
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Is Price On Call', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'price_oncall',
|
||||
'type' => 'switch',
|
||||
'options' => [
|
||||
0 => esc_html__( 'No', 'opalestate-pro' ),
|
||||
1 => esc_html__( 'Yes', 'opalestate-pro' ),
|
||||
],
|
||||
'default' => 0,
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
return apply_filters( 'opalestate_postype_property_metaboxes_fields_price', $fields );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function metaboxes_info_fields() {
|
||||
$prefix = OPALESTATE_PROPERTY_PREFIX;
|
||||
|
||||
$fields = [
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Built year', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'builtyear',
|
||||
'type' => 'text_date',
|
||||
'description' => esc_html__( 'Enter built year', 'opalestate-pro' ),
|
||||
|
||||
'before_row' => '<div class="row-group-features group-has-three group-property-info clearfix"><h3>' . ( is_admin() ? "" : esc_html__( 'Property Information', 'opalestate-pro' ) ) . '</h3>',
|
||||
// callback
|
||||
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Parking', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'parking',
|
||||
'type' => 'text',
|
||||
'attributes' => [
|
||||
'type' => 'number',
|
||||
'min' => 0,
|
||||
],
|
||||
'description' => esc_html__( 'Enter number of Parking', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Bedrooms', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'bedrooms',
|
||||
'type' => 'text',
|
||||
'attributes' => [
|
||||
'type' => 'number',
|
||||
'min' => 0,
|
||||
],
|
||||
'description' => esc_html__( 'Enter number of bedrooms', 'opalestate-pro' ),
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Bathrooms', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'bathrooms',
|
||||
'type' => 'text',
|
||||
'attributes' => [
|
||||
'type' => 'number',
|
||||
'min' => 0,
|
||||
],
|
||||
'description' => esc_html__( 'Enter number of bathrooms', 'opalestate-pro' ),
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Plot Size', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'plotsize',
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Enter size of Plot as 20x30, 20x30x40, 20x30x40x50', 'opalestate-pro' ),
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Area Size', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'areasize',
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Enter size of area in sqft', 'opalestate-pro' ),
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Orientation', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}orientation",
|
||||
'type' => 'text',
|
||||
'description' => esc_html__( 'Enter Orientation of property', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Living Rooms', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}livingrooms",
|
||||
'type' => 'text',
|
||||
'attributes' => [
|
||||
'type' => 'number',
|
||||
'min' => 0,
|
||||
],
|
||||
'description' => esc_html__( 'Enter Number of Living Rooms', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Kitchens', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}kitchens",
|
||||
'type' => 'text',
|
||||
'attributes' => [
|
||||
'type' => 'number',
|
||||
'min' => 0,
|
||||
],
|
||||
'description' => esc_html__( 'Enter Number of Kitchens', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Rooms', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}amountrooms",
|
||||
'type' => 'text',
|
||||
'attributes' => [
|
||||
'type' => 'number',
|
||||
'min' => 0,
|
||||
],
|
||||
'description' => esc_html__( 'Enter Number of Amount Rooms', 'opalestate-pro' ),
|
||||
|
||||
'after_row' => '</div>',
|
||||
|
||||
],
|
||||
];
|
||||
|
||||
return apply_filters( 'opalestate_postype_property_metaboxes_fields_info', $fields );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function metaboxes_public_facilities_fields() {
|
||||
$prefix = OPALESTATE_PROPERTY_PREFIX;
|
||||
$fields = [
|
||||
[
|
||||
'id' => $prefix . 'public_facilities_group',
|
||||
'type' => 'group',
|
||||
'fields' => [
|
||||
[
|
||||
'id' => $prefix . 'public_facilities_key',
|
||||
'name' => esc_html__( 'Label', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'public_facilities_value',
|
||||
'name' => esc_html__( 'Content', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
],
|
||||
],
|
||||
'options' => [
|
||||
'group_title' => esc_html__( 'Facility {#}', 'opalestate-pro' ),
|
||||
'add_button' => esc_html__( 'Add more', 'opalestate-pro' ),
|
||||
'remove_button' => esc_html__( 'Remove', 'opalestate-pro' ),
|
||||
'sortable' => true,
|
||||
'closed' => false,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return apply_filters( 'opalestate_postype_property_metaboxes_fields_public_facilities', $fields );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function metaboxes_members_fields() {
|
||||
$prefix = OPALESTATE_PROPERTY_PREFIX;
|
||||
global $post;
|
||||
|
||||
$types = [
|
||||
'hide' => esc_html__( 'Hide Author Information', 'opalestate-pro' ),
|
||||
'user' => esc_html__( 'User Author Information', 'opalestate-pro' ),
|
||||
'agent' => esc_html__( 'Agent Information', 'opalestate-pro' ),
|
||||
'agency' => esc_html__( 'Agency Information', 'opalestate-pro' ),
|
||||
];
|
||||
|
||||
// agent
|
||||
$agents = [
|
||||
0 => esc_html__( 'No', 'opalestate-pro' ),
|
||||
];
|
||||
if ( isset( $_GET['post'] ) && $_GET['post'] ) {
|
||||
$id = get_post_meta( (int) $_GET['post'], OPALESTATE_PROPERTY_PREFIX . 'agent', true );
|
||||
if ( $id ) {
|
||||
$agents[ $id ] = get_the_title( $id );
|
||||
}
|
||||
}
|
||||
// agency
|
||||
$agency = [
|
||||
0 => esc_html__( 'No', 'opalestate-pro' ),
|
||||
];
|
||||
if ( isset( $_GET['post'] ) && $_GET['post'] ) {
|
||||
$id = get_post_meta( (int) $_GET['post'], OPALESTATE_PROPERTY_PREFIX . 'agency', true );
|
||||
if ( $id ) {
|
||||
$agency[ $id ] = get_the_title( $id );
|
||||
}
|
||||
}
|
||||
|
||||
$fields = [
|
||||
[
|
||||
'name' => esc_html__( 'Author Information', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}author_type",
|
||||
'type' => 'select',
|
||||
'options' => $types,
|
||||
'default' => 'user',
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Agent', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}agent",
|
||||
'type' => 'select',
|
||||
'options' => $agents,
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Agency', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}agency",
|
||||
'type' => 'select',
|
||||
'options' => $agency,
|
||||
],
|
||||
];
|
||||
|
||||
return apply_filters( 'opalestate_postype_property_metaboxes_fields_agent', $fields );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function metaboxes_assignment_fields() {
|
||||
$prefix = OPALESTATE_PROPERTY_PREFIX;
|
||||
global $post;
|
||||
|
||||
// users
|
||||
$users = [
|
||||
0 => esc_html__( 'Default User', 'opalestate-pro' ),
|
||||
];
|
||||
|
||||
$all_users = get_users();
|
||||
|
||||
foreach ( $all_users as $user ) {
|
||||
$users[ $user->ID ] = $user->display_name;
|
||||
}
|
||||
|
||||
$fields = [
|
||||
[
|
||||
'name' => esc_html__( 'User', 'opalestate-pro' ),
|
||||
'id' => "post_author_override",
|
||||
'type' => 'select',
|
||||
"description" => esc_html__( 'Change to new owner of this property, which be listed in That user dashboard', 'opalestate-pro' ),
|
||||
'options' => $users,
|
||||
],
|
||||
];
|
||||
|
||||
return apply_filters( 'opalestate_postype_property_metaboxes_fields_assignment', $fields );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function metaboxes_layout_fields() {
|
||||
$prefix = OPALESTATE_PROPERTY_PREFIX;
|
||||
|
||||
$templates = opalestate_single_layout_prieview();
|
||||
|
||||
$fields = [
|
||||
[
|
||||
'name' => esc_html__( 'Layout Display', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}layout",
|
||||
'type' => 'select',
|
||||
'options' => apply_filters( 'opalestate_single_layout_templates', [ '' => esc_html__( 'Inherit', 'opalestate-pro' ) ] ),
|
||||
'description' => esc_html__( 'Select a layout to display full information of this property', 'opalestate-pro' ),
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Preview Display', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}preview",
|
||||
'type' => 'select',
|
||||
'options' => $templates,
|
||||
'description' => esc_html__( 'Select a layout to display full information of this property', 'opalestate-pro' ),
|
||||
],
|
||||
];
|
||||
|
||||
return apply_filters( 'opalestate_postype_property_metaboxes_fields_layout', $fields );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function metaboxes_floor_plans() {
|
||||
$prefix = OPALESTATE_PROPERTY_PREFIX;
|
||||
$fields = [
|
||||
[
|
||||
'id' => $prefix . 'public_floor_group',
|
||||
'type' => 'group',
|
||||
'fields' => [
|
||||
[
|
||||
'id' => $prefix . 'floor_name',
|
||||
'name' => esc_html__( 'Name', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'floor_price',
|
||||
'name' => esc_html__( 'Price', 'opalestate-pro' ),
|
||||
'before_row' => '<div class="field-row-2">',
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'floor_size',
|
||||
'name' => esc_html__( 'Size', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'floor_room',
|
||||
'name' => esc_html__( 'Rooms', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'floor_bath',
|
||||
'name' => esc_html__( 'Baths', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'after_row' => '</div>',
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'floor_content',
|
||||
'name' => esc_html__( 'Content', 'opalestate-pro' ),
|
||||
'type' => 'textarea_small',
|
||||
],
|
||||
[
|
||||
'id' => "{$prefix}floor_image",
|
||||
'name' => esc_html__( 'Image Preview', 'opalestate-pro' ),
|
||||
'type' => 'file',
|
||||
'query_args' => [
|
||||
'type' => [
|
||||
'image/gif',
|
||||
'image/jpeg',
|
||||
'image/png',
|
||||
],
|
||||
],
|
||||
'description' => esc_html__( 'Input iframe to show 360° Virtual Tour.', 'opalestate-pro' ),
|
||||
],
|
||||
],
|
||||
'options' => [
|
||||
'group_title' => esc_html__( 'Floor {#}', 'opalestate-pro' ),
|
||||
'add_button' => esc_html__( 'Add more', 'opalestate-pro' ),
|
||||
'remove_button' => esc_html__( 'Remove', 'opalestate-pro' ),
|
||||
'sortable' => true,
|
||||
'closed' => false,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return apply_filters( 'opalestate_postype_property_metaboxes_fields_floor_plans', $fields );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function metaboxes_apartments() {
|
||||
$prefix = OPALESTATE_PROPERTY_PREFIX;
|
||||
$fields = [
|
||||
[
|
||||
'id' => $prefix . 'apartments',
|
||||
'type' => 'group',
|
||||
'fields' => [
|
||||
[
|
||||
'id' => $prefix . 'apartment_plot',
|
||||
'name' => esc_html__( 'Plot', 'opalestate-pro' ),
|
||||
'before_row' => '<div class="field-row-2">',
|
||||
'type' => 'text',
|
||||
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'apartment_beds',
|
||||
'name' => esc_html__( 'Beds', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'apartment_price_from',
|
||||
'name' => esc_html__( 'Price from', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'apartment_floor',
|
||||
'name' => esc_html__( 'Floor', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'after_row' => '</div>',
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'apartment_building_address',
|
||||
'name' => esc_html__( 'Building / Address', 'opalestate-pro' ),
|
||||
'type' => 'textarea_small',
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'apartment_status',
|
||||
'name' => esc_html__( 'Status', 'opalestate-pro' ),
|
||||
'type' => 'select',
|
||||
'options' => apply_filters( 'opalestate_property_apartment_statuses', [
|
||||
'' => esc_html__( 'None', 'opalestate-pro' ),
|
||||
'available' => esc_html__( 'Available', 'opalestate-pro' ),
|
||||
'unavailable' => esc_html__( 'Unavailable', 'opalestate-pro' ),
|
||||
] ),
|
||||
'before_row' => '<div class="field-row-2">',
|
||||
],
|
||||
[
|
||||
'id' => $prefix . 'apartment_link',
|
||||
'name' => esc_html__( 'Link', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'after_row' => '</div>',
|
||||
],
|
||||
],
|
||||
'options' => [
|
||||
'group_title' => esc_html__( 'Apartment {#}', 'opalestate-pro' ),
|
||||
'add_button' => esc_html__( 'Add more', 'opalestate-pro' ),
|
||||
'remove_button' => esc_html__( 'Remove', 'opalestate-pro' ),
|
||||
'sortable' => true,
|
||||
'closed' => false,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return apply_filters( 'opalestate_postype_property_metaboxes_fields_apartments', $fields );
|
||||
}
|
||||
}
|
||||
150
inc/property/class-opalestate-favorite.php
Executable file
150
inc/property/class-opalestate-favorite.php
Executable file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* $Desc$
|
||||
*
|
||||
* @version $Id$
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @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_Favorite_Property: work as wishlist function
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
class Opalestate_Favorite_Property{
|
||||
|
||||
/**
|
||||
* @var integer $userId
|
||||
*/
|
||||
protected $userId ;
|
||||
|
||||
/**
|
||||
* Get instance of this object
|
||||
*/
|
||||
public static function get_instance(){
|
||||
static $_instance;
|
||||
if( !$_instance ){
|
||||
$_instance = new Opalestate_Favorite_Property();
|
||||
}
|
||||
return $_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(){
|
||||
|
||||
add_shortcode( 'opalestate_favorite_button' , array( $this, 'favorite_button' ) );
|
||||
add_shortcode( 'opalestate_user_favious_properties' , array( $this, 'favorite_properties' ) );
|
||||
|
||||
/**
|
||||
* Ajax action
|
||||
*/
|
||||
add_action( 'wp_ajax_opalestate_toggle_status', array($this,'toggle_status') );
|
||||
add_action( 'wp_ajax_nopriv_opalestate_toggle_status', array($this,'toggle_status') );
|
||||
add_action( 'init', array($this,'init') );
|
||||
|
||||
|
||||
// show content page in user dashboard
|
||||
add_filter( 'opalestate_user_content_favorite_page' , array( $this, 'favorite_properties' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set values when user logined in system
|
||||
*/
|
||||
public function init(){
|
||||
|
||||
global $current_user;
|
||||
wp_get_current_user();
|
||||
$this->userId = $current_user->ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow set or remove favorite
|
||||
*/
|
||||
public function toggle_status(){
|
||||
|
||||
if( isset($_POST['property_id']) ){
|
||||
|
||||
$property_id = absint( $_POST['property_id'] );
|
||||
|
||||
$items = (array)get_user_meta( $this->userId, 'opalestate_user_favorite', true );
|
||||
|
||||
$key = array_search( $property_id, $items);
|
||||
if( $key != false || $key != '' ){
|
||||
unset($items[$key]);
|
||||
}else {
|
||||
$items[] = $property_id;
|
||||
}
|
||||
// remove items emty
|
||||
foreach( $items as $key => $value ) {
|
||||
if( empty($value) ) {
|
||||
unset( $items[$key] );
|
||||
}
|
||||
}
|
||||
update_user_meta( $this->userId, 'opalestate_user_favorite', $items );
|
||||
}
|
||||
|
||||
echo $this->favorite_button( array('property_id' => $property_id ) );
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* render favorite button in loop
|
||||
*/
|
||||
public function favorite_button( $atts ){
|
||||
$atts['userId'] = $this->userId;
|
||||
if( !isset($atts['property_id']) ){
|
||||
$atts['property_id'] = get_the_ID();
|
||||
}
|
||||
|
||||
$items = (array)get_user_meta( $this->userId, 'opalestate_user_favorite', true );
|
||||
|
||||
$key = array_search( $atts['property_id'], $items);
|
||||
$atts['existed'] = $key;
|
||||
|
||||
ob_start();
|
||||
echo opalestate_load_template_path( 'user/favorite-button' , $atts );
|
||||
$ouput = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $ouput;
|
||||
}
|
||||
|
||||
/**
|
||||
* show all favorited properties with pagination.
|
||||
*/
|
||||
public function favorite_properties(){
|
||||
|
||||
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
|
||||
$per_page = 9;
|
||||
$items = (array)get_user_meta( $this->userId, 'opalestate_user_favorite', true );
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'opalestate_property',
|
||||
'paged' => $paged,
|
||||
'posts_per_page' => $per_page,
|
||||
'post__in' => !empty($items) ? $items : array( 9999999 )
|
||||
);
|
||||
|
||||
$loop = new WP_Query( $args );
|
||||
|
||||
|
||||
return opalestate_load_template_path( 'user/favorite-properties' , array('loop' => $loop) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Opalestate_Favorite_Property::get_instance();
|
||||
79
inc/property/class-opalestate-posttype.php
Executable file
79
inc/property/class-opalestate-posttype.php
Executable file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Opalestate_PostType_Property
|
||||
*
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @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_PostType_Agency
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
class Opalestate_PostType_Property {
|
||||
|
||||
/**
|
||||
* Opalestate_PostType_Property constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'init', [ __CLASS__, 'definition' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Post type and taxonomies
|
||||
*/
|
||||
public static function definition() {
|
||||
if ( ! is_blog_installed() || post_type_exists( 'opalestate_property' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$labels = [
|
||||
'name' => esc_html__( 'Properties', 'opalestate-pro' ),
|
||||
'singular_name' => esc_html__( 'Property', 'opalestate-pro' ),
|
||||
'add_new' => esc_html__( 'Add New Property', 'opalestate-pro' ),
|
||||
'add_new_item' => esc_html__( 'Add New Property', 'opalestate-pro' ),
|
||||
'edit_item' => esc_html__( 'Edit Property', 'opalestate-pro' ),
|
||||
'new_item' => esc_html__( 'New Property', 'opalestate-pro' ),
|
||||
'all_items' => esc_html__( 'All Properties', 'opalestate-pro' ),
|
||||
'view_item' => esc_html__( 'View Property', 'opalestate-pro' ),
|
||||
'search_items' => esc_html__( 'Search Property', 'opalestate-pro' ),
|
||||
'not_found' => esc_html__( 'No Properties found', 'opalestate-pro' ),
|
||||
'not_found_in_trash' => esc_html__( 'No Properties found in Trash', 'opalestate-pro' ),
|
||||
'parent_item_colon' => '',
|
||||
'menu_name' => esc_html__( 'Properties', 'opalestate-pro' ),
|
||||
];
|
||||
|
||||
$labels = apply_filters( 'opalestate_postype_property_labels', $labels );
|
||||
|
||||
register_post_type( 'opalestate_property',
|
||||
apply_filters( 'opalestate_property_post_type_parameters', [
|
||||
'labels' => $labels,
|
||||
'supports' => [ 'title', 'editor', 'thumbnail', 'comments', 'author' ],
|
||||
'public' => true,
|
||||
'has_archive' => true,
|
||||
'menu_position' => 51,
|
||||
'categories' => [],
|
||||
'menu_icon' => 'dashicons-admin-home',
|
||||
'map_meta_cap' => true,
|
||||
'publicly_queryable' => true,
|
||||
'exclude_from_search' => false,
|
||||
'query_var' => true,
|
||||
'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
|
||||
'show_in_nav_menus' => true,
|
||||
'rewrite' => [ 'slug' => esc_html_x( 'property', 'property slug', 'opalestate-pro' ) ],
|
||||
] )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
new Opalestate_PostType_Property();
|
||||
71
inc/property/class-opalestate-property-query.php
Executable file
71
inc/property/class-opalestate-property-query.php
Executable file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* $Desc$
|
||||
*
|
||||
* @version $Id$
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @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_Query {
|
||||
/**
|
||||
* The args to pass to the give_get_donors() query
|
||||
*
|
||||
* @since 1.8.14
|
||||
* @access public
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $args = array();
|
||||
|
||||
/**
|
||||
* The collection found based on the criteria set
|
||||
*
|
||||
* @since 1.8.14
|
||||
* @access public
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
public $count = 0;
|
||||
|
||||
public $collection = array();
|
||||
|
||||
|
||||
public function insert( ) {
|
||||
|
||||
}
|
||||
|
||||
public function update() {
|
||||
|
||||
}
|
||||
|
||||
public function mapping_query(){
|
||||
|
||||
}
|
||||
|
||||
public function query( $args ){
|
||||
$this->count = '';
|
||||
$this->collection = '';
|
||||
$data = '';
|
||||
}
|
||||
|
||||
public function get_list ( $args ){
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function count() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
727
inc/property/class-opalestate-property.php
Executable file
727
inc/property/class-opalestate-property.php
Executable file
@@ -0,0 +1,727 @@
|
||||
<?php
|
||||
/**
|
||||
* $Desc$
|
||||
*
|
||||
* @version $Id$
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @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',
|
||||
'map',
|
||||
'nearby',
|
||||
'walkscores',
|
||||
'apartments',
|
||||
'floor_plans',
|
||||
'views_statistics',
|
||||
];
|
||||
|
||||
foreach ( $keys as $key ) {
|
||||
$this->property_settings[ $key ] = opalestate_get_option( 'enable_single_' . $key, 'on' );
|
||||
}
|
||||
}
|
||||
|
||||
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'] ) ? $value . ' ' . $field['unit'] : $value;
|
||||
|
||||
$this->metabox_info[ $id ] = [ 'label' => $field['name'], 'value' => $value ];
|
||||
}
|
||||
}
|
||||
|
||||
return $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->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 = '<span class="property-locations">';
|
||||
foreach ( $terms as $key => $term ) {
|
||||
$output .= '<a href="' . get_term_link( $term->term_id ) . '" class="location-name">' . $term->name . '</a>';
|
||||
if ( $key < ( count( $terms ) - 1 ) ) {
|
||||
$output .= ", ";
|
||||
}
|
||||
}
|
||||
$output .= '</span>';
|
||||
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 = '<ul class="property-labels">';
|
||||
foreach ( $labels as $key => $value ) {
|
||||
$output .= '<li class="property-labels-item property-label-' . trim( $value->slug ) . '"><span class="label-status label">' . esc_html( $value->name ) . '</span></li>';
|
||||
}
|
||||
$output .= '</ul>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets statuses
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function get_status() {
|
||||
$terms = wp_get_post_terms( $this->post_id, 'opalestate_status' );
|
||||
|
||||
return $terms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render statuses.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function render_statuses() {
|
||||
$statuses = $this->get_status();
|
||||
|
||||
if ( empty( $statuses ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$output = '<ul class="property-status">';
|
||||
foreach ( $statuses as $key => $value ) {
|
||||
$output .= '<li class="property-status-item property-status-' . esc_attr( $value->slug ) . '"><span class="label-status label">' . esc_html( $value->name ) . '</span></li>';
|
||||
}
|
||||
$output .= '</ul>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function getAuthor() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function get_author_type() {
|
||||
return $this->get_metabox_value( 'author_type' );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function render_author_link() {
|
||||
switch ( $this->get_author_type() ) {
|
||||
|
||||
case 'hide':
|
||||
|
||||
return;
|
||||
break;
|
||||
|
||||
case 'agent':
|
||||
$agent_id = $this->get_metabox_value( 'agent' );
|
||||
$data = OpalEstate_Agent::get_link( $agent_id );
|
||||
break;
|
||||
|
||||
case 'agency':
|
||||
$agency_id = $this->get_metabox_value( 'agency' );
|
||||
$data = OpalEstate_Agency::get_link( $agency_id );
|
||||
break;
|
||||
default:
|
||||
$data = $this->get_author_link();
|
||||
break;
|
||||
}
|
||||
|
||||
$avatar = $data['avatar'] ? $data['avatar'] : opalestate_get_image_avatar_placehold();
|
||||
$avatar = '<img class="avatar" src="' . esc_url( $avatar ) . '" alt="' . $data['name'] . '" />';
|
||||
|
||||
return '<a href="' . $data['link'] . '" aria-label="' . $data['name'] . '" class="author-link"><span aria-label="' . $data['name'] . '" class="author-avatar hint--top">' . $avatar . '</span><span class="author-name">' . $data['name'] . '</span></a>';
|
||||
}
|
||||
|
||||
private function get_author_link() {
|
||||
|
||||
$image_id = get_user_meta( get_the_author_meta( 'ID' ), OPALESTATE_USER_PROFILE_PREFIX . 'avatar_id', true );
|
||||
$related_id = get_user_meta( get_the_author_meta( 'ID' ), OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
|
||||
|
||||
if ( $image_id ) {
|
||||
$url = wp_get_attachment_url( $image_id );
|
||||
} else {
|
||||
$url = get_avatar_url( get_the_author_meta( 'email' ) );
|
||||
}
|
||||
|
||||
if ( $related_id ) {
|
||||
$authorlink = get_permalink( $related_id );
|
||||
$author = get_the_title( $related_id );
|
||||
} else {
|
||||
$authorlink = get_author_posts_url( get_the_author_meta( 'ID' ) );
|
||||
$author = get_the_author();
|
||||
}
|
||||
|
||||
return [
|
||||
'name' => $author,
|
||||
'avatar' => $url,
|
||||
'link' => $authorlink,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets status
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function get_category_tax() {
|
||||
$terms = wp_get_post_terms( $this->post_id, 'property_category' );
|
||||
|
||||
return $terms;
|
||||
}
|
||||
|
||||
public function get_types_tax() {
|
||||
$terms = wp_get_post_terms( $this->post_id, 'opalestate_types' );
|
||||
|
||||
return $terms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets meta box value
|
||||
*
|
||||
* @access public
|
||||
* @param $key
|
||||
* @param $single
|
||||
* @return string
|
||||
*/
|
||||
public function get_metabox_value( $key, $single = true ) {
|
||||
return get_post_meta( $this->post_id, OPALESTATE_PROPERTY_PREFIX . $key, $single );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets map value
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_map() {
|
||||
return $this->map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets address value
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_address() {
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets sku value
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_sku() {
|
||||
return $this->sku;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets video url value
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
|
||||
public function get_video_url() {
|
||||
return $this->get_metabox_value( 'video' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets 360 virtual tour value
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_virtual_tour() {
|
||||
return $this->get_metabox_value( 'virtual' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets gallery ids value
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function get_gallery() {
|
||||
return $this->get_metabox_value( 'gallery', true );
|
||||
}
|
||||
|
||||
|
||||
public function get_gallery_count() {
|
||||
$count = $this->get_gallery();
|
||||
|
||||
return count( $count );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets price value
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_price() {
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets sale price value
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_sale_price() {
|
||||
return $this->saleprice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets price value
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_before_price_label() {
|
||||
return $this->before_pricelabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets price value
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_price_label() {
|
||||
return $this->pricelabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets price format value
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_format_price() {
|
||||
return $this->get_metabox_value( 'formatprice' );
|
||||
}
|
||||
|
||||
public function enable_google_mapview() {
|
||||
return $this->get_metabox_value( 'enablemapview' );
|
||||
}
|
||||
|
||||
public function get_google_map_link() {
|
||||
$url = 'https://maps.google.com/maps?q=' . $this->address . '&ll=' . $this->latitude . ',' . $this->longitude . '&z=17';
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public static function is_allowed_remove( $user_id, $item_id ) {
|
||||
$item = get_post( $item_id );
|
||||
|
||||
if ( ! empty( $item->post_author ) ) {
|
||||
if ( $item->post_author == $user_id ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_price_oncall() {
|
||||
return $this->get_metabox_value( 'price_oncall' );
|
||||
}
|
||||
|
||||
public function get_facilities() {
|
||||
return $this->get_metabox_value( 'public_facilities_group' );
|
||||
}
|
||||
|
||||
public function get_attachments() {
|
||||
return $this->get_metabox_value( 'attachments' );
|
||||
}
|
||||
|
||||
|
||||
public function get_content_single_layout() {
|
||||
return $this->get_metabox_value( 'layout' );
|
||||
}
|
||||
|
||||
public function get_preview_template() {
|
||||
return $this->get_metabox_value( 'preview' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rating count.
|
||||
*
|
||||
* @param string $context What the value is for. Valid values are view and edit.
|
||||
* @return int
|
||||
*/
|
||||
public function get_rating_counts() {
|
||||
return $this->get_metabox_value( 'rating_count' ) ? $this->get_metabox_value( 'rating_count' ) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get average rating.
|
||||
*
|
||||
* @param string $context What the value is for. Valid values are view and edit.
|
||||
* @return float
|
||||
*/
|
||||
public function get_average_rating() {
|
||||
return $this->get_metabox_value( 'average_rating' ) ? $this->get_metabox_value( 'average_rating' ) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get review count.
|
||||
*
|
||||
* @param string $context What the value is for. Valid values are view and edit.
|
||||
* @return int
|
||||
*/
|
||||
public function get_review_count() {
|
||||
return $this->get_metabox_value( 'review_count' ) ? $this->get_metabox_value( 'review_count' ) : 0;
|
||||
}
|
||||
|
||||
public function get_rating_count_stats() {
|
||||
return $this->get_metabox_value( 'rating_count_stats' ) ? $this->get_metabox_value( 'rating_count_stats' ) : [
|
||||
5 => 0,
|
||||
4 => 0,
|
||||
3 => 0,
|
||||
2 => 0,
|
||||
1 => 0,
|
||||
];
|
||||
}
|
||||
|
||||
public function get_rating_average_stats() {
|
||||
return $this->get_metabox_value( 'rating_average_stats' );
|
||||
}
|
||||
|
||||
public function get_apartments() {
|
||||
return $this->get_metabox_value( 'apartments' );
|
||||
}
|
||||
|
||||
public function get_floor_plans() {
|
||||
return $this->get_metabox_value( 'public_floor_group' );
|
||||
}
|
||||
|
||||
public function get_posted() {
|
||||
return human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . ' ' . esc_html__( 'ago' );
|
||||
}
|
||||
}
|
||||
402
inc/property/class-opalestate-query.php
Executable file
402
inc/property/class-opalestate-query.php
Executable file
@@ -0,0 +1,402 @@
|
||||
<?php
|
||||
/**
|
||||
* Opalestate_Query
|
||||
*
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Opalestate_Query {
|
||||
|
||||
/**
|
||||
* Set active location
|
||||
*/
|
||||
public static $LOCATION;
|
||||
|
||||
/**
|
||||
* Get Query Object to display list of agents
|
||||
*/
|
||||
public static function get_agents( $args = [], $featured = false ) {
|
||||
$default = [
|
||||
'post_type' => 'opalestate_agent',
|
||||
'posts_per_page' => 10,
|
||||
];
|
||||
|
||||
$args = array_merge( $default, $args );
|
||||
if ( $featured ) {
|
||||
$args['meta_key'] = OPALESTATE_AGENT_PREFIX . 'featured';
|
||||
$args['meta_value'] = 1;
|
||||
$args['meta_compare'] = '=';
|
||||
}
|
||||
|
||||
return new WP_Query( $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Query Object to display list of agents
|
||||
*/
|
||||
public static function get_agencies( $args = [], $featured = false ) {
|
||||
$default = [
|
||||
'post_type' => 'opalestate_agency',
|
||||
'posts_per_page' => 10,
|
||||
];
|
||||
$args = array_merge( $default, $args );
|
||||
if ( $featured ) {
|
||||
$args['meta_key'] = OPALESTATE_AGENCY_PREFIX . 'featured';
|
||||
$args['meta_value'] = 1;
|
||||
$args['meta_compare'] = '=';
|
||||
}
|
||||
|
||||
return new WP_Query( $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Query Object By post and agent with setting items per page.
|
||||
*/
|
||||
public static function get_agency_property( $agency_id = null, $user_id = null, $per_page = 10, $page = null ) {
|
||||
if ( null == $agency_id ) {
|
||||
$agency_id = get_the_ID();
|
||||
}
|
||||
|
||||
$paged = $page ? $page : ( ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' ) );
|
||||
|
||||
// if this has not any relationship with any user
|
||||
if ( $user_id ) {
|
||||
|
||||
$author = [ $user_id ]; //echo '<pre>'.print_r( $post_id, 1 );die;
|
||||
$team = get_post_meta( $agency_id, OPALESTATE_AGENCY_PREFIX . 'team', true );
|
||||
|
||||
if ( is_array( $team ) ) {
|
||||
$author = array_merge( $author, $team );
|
||||
}
|
||||
|
||||
$args = [
|
||||
'post_type' => 'opalestate_property',
|
||||
'author__in' => $author,
|
||||
'posts_per_page' => $per_page,
|
||||
'paged' => $paged,
|
||||
];
|
||||
} else {
|
||||
$agents = get_post_meta( $agency_id, OPALESTATE_AGENCY_PREFIX . 'team', true );
|
||||
$args = [
|
||||
'post_type' => 'opalestate_property',
|
||||
'posts_per_page' => $per_page,
|
||||
'paged' => $paged,
|
||||
];
|
||||
$args['meta_query'] = [ 'relation' => 'OR' ];
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'agency',
|
||||
'value' => $agency_id,
|
||||
'compare' => '=',
|
||||
] );
|
||||
|
||||
if ( $agents ) {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'agent',
|
||||
'value' => $agents,
|
||||
] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$query = new WP_Query( $args );
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Query Object By post and agent with setting items per page.
|
||||
*/
|
||||
public static function get_agent_property( $post_id = null, $agent_id = null, $per_page = 10, $isfeatured = false ) {
|
||||
if ( null == $post_id ) {
|
||||
$post_id = get_the_ID();
|
||||
}
|
||||
|
||||
$user_id = get_post_meta( $post_id, OPALESTATE_AGENT_PREFIX . 'user_id', true );
|
||||
|
||||
$paged = ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' );
|
||||
|
||||
$args = [
|
||||
'post_type' => 'opalestate_property',
|
||||
'posts_per_page' => $per_page,
|
||||
'post__not_in' => [ $post_id ],
|
||||
'paged' => $paged,
|
||||
];
|
||||
|
||||
$args['meta_query'] = [ 'relation' => 'AND' ];
|
||||
|
||||
if ( $user_id ) {
|
||||
$args['author'] = $user_id;
|
||||
} else {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'agent',
|
||||
'value' => $agent_id,
|
||||
'compare' => '=',
|
||||
] );
|
||||
}
|
||||
|
||||
if ( $isfeatured ) {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
|
||||
'value' => 'on',
|
||||
'compare' => '=',
|
||||
] );
|
||||
}
|
||||
$query = new WP_Query( $args );
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Query Object to show featured properties with custom setting via Arguments passing.
|
||||
*/
|
||||
public static function get_featured_properties_query( $args = [] ) {
|
||||
$default = [
|
||||
'post_type' => 'opalestate_property',
|
||||
'posts_per_page' => 10,
|
||||
'meta_key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
|
||||
'meta_value' => 1,
|
||||
'meta_compare' => '=',
|
||||
|
||||
];
|
||||
|
||||
$args = array_merge( $default, $args );
|
||||
|
||||
return new WP_Query( $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set filter location to query when user set his location as global filterable.
|
||||
*/
|
||||
public static function set_location( $args ) {
|
||||
if ( $args && self::$LOCATION ) {
|
||||
$tax_query = [
|
||||
[
|
||||
'taxonomy' => 'opalestate_location',
|
||||
'field' => 'slug',
|
||||
'terms' => self::$LOCATION,
|
||||
],
|
||||
];
|
||||
$args['tax_query'] = [ 'relation' => 'AND' ];
|
||||
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get WP Query Object with custom passing arguments and User request as get data.
|
||||
*/
|
||||
public static function get_property_query( $args = [] ) {
|
||||
$condition = [
|
||||
'post_type' => 'opalestate_property',
|
||||
'posts_per_page' => isset( $args['posts_per_page'] ) ? $args['posts_per_page'] : 5,
|
||||
'paged' => isset( $args['paged'] ) ? $args['paged'] : 1,
|
||||
];
|
||||
|
||||
$condition = array_merge( $condition, $args );
|
||||
$relation = "AND";
|
||||
|
||||
$condition['meta_query'] = [];
|
||||
|
||||
$condition['tax_query'] = [
|
||||
'relation' => $relation,
|
||||
];
|
||||
|
||||
if ( ! empty( $args['categories'] ) ) {
|
||||
array_push( $condition['tax_query'], [
|
||||
'taxonomy' => 'property_category',
|
||||
'terms' => implode( ',', $args['categories'] ),
|
||||
'field' => 'slug',
|
||||
'operator' => 'IN',
|
||||
] );
|
||||
}
|
||||
|
||||
if ( ! empty( $args['types'] ) ) {
|
||||
array_push( $condition['tax_query'], [
|
||||
'taxonomy' => 'opalestate_types',
|
||||
'terms' => $args['types'],
|
||||
'field' => 'slug',
|
||||
'operator' => 'IN',
|
||||
] );
|
||||
}
|
||||
|
||||
|
||||
if ( ! empty( $args['statuses'] ) ) {
|
||||
array_push( $condition['tax_query'], [
|
||||
'taxonomy' => 'opalestate_status',
|
||||
'terms' => $args['statuses'],
|
||||
'field' => 'slug',
|
||||
'operator' => 'IN',
|
||||
] );
|
||||
}
|
||||
|
||||
|
||||
if ( ! empty( $args['labels'] ) ) {
|
||||
array_push( $condition['tax_query'], [
|
||||
'taxonomy' => 'opalestate_label',
|
||||
'terms' => $args['labels'],
|
||||
'field' => 'slug',
|
||||
] );
|
||||
}
|
||||
|
||||
if ( ! empty( $args['cities'] ) ) {
|
||||
array_push( $condition['tax_query'], [
|
||||
'taxonomy' => 'opalestate_city',
|
||||
'terms' => $args['cities'],
|
||||
'field' => 'slug',
|
||||
'operator' => 'IN',
|
||||
] );
|
||||
}
|
||||
|
||||
if ( ! empty( $args['showmode'] ) ) {
|
||||
if ( $args['showmode'] == 'featured' ) {
|
||||
array_push( $condition['meta_query'], [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
|
||||
'value' => 'on',
|
||||
'compare' => '=',
|
||||
] );
|
||||
} elseif ( $args['showmode'] == 'normal' ) {
|
||||
array_push( $condition['meta_query'], [
|
||||
'relation' => 'OR',
|
||||
[
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
|
||||
'compare' => 'NOT EXISTS',
|
||||
'value' => '' // This is ignored, but is necessary...
|
||||
],
|
||||
[
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
|
||||
'value' => 'on',
|
||||
'compare' => '!=',
|
||||
],
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
$query = new WP_Query( $condition );
|
||||
|
||||
wp_reset_postdata();
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Agent id by property id
|
||||
*/
|
||||
public static function get_agent_by_property( $post_id = null ) {
|
||||
if ( null == $post_id ) {
|
||||
$post_id = get_the_ID();
|
||||
}
|
||||
$agent_id = get_post_meta( $post_id, OPALESTATE_PROPERTY_PREFIX . 'agent', true );
|
||||
|
||||
return $agent_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get List of properties by user
|
||||
*/
|
||||
public static function get_properties_by_user( $oargs = [], $user_id = null ) {
|
||||
|
||||
$paged = ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' );
|
||||
$per_page = 9;
|
||||
|
||||
$args = [
|
||||
'post_type' => 'opalestate_property',
|
||||
'paged' => $paged,
|
||||
'post_status' => 'any',
|
||||
'author' => $user_id,
|
||||
'posts_per_page' => $per_page,
|
||||
|
||||
];
|
||||
if ( ! empty( $oargs ) || is_array( $oargs ) ) {
|
||||
$args = array_merge( $args, $oargs );
|
||||
}
|
||||
|
||||
if ( isset( $args['featured'] ) && $args['featured'] ) {
|
||||
$args = array_merge( $args,
|
||||
[
|
||||
'meta_key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
|
||||
'meta_value' => 'on',
|
||||
'meta_compare' => '=',
|
||||
] );
|
||||
unset( $args['featured'] );
|
||||
|
||||
}
|
||||
$query = new WP_Query( $args );
|
||||
wp_reset_postdata();
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function get_amenities() {
|
||||
return get_terms( 'opalestate_amenities', [ 'hide_empty' => false ] );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function filter_by_location( $geo_lat, $geo_long, $radius, $prefix = OPALESTATE_PROPERTY_PREFIX ) {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$radius_measure = '';
|
||||
$earth = 3959;
|
||||
|
||||
if ( $radius_measure == 'km' ) {
|
||||
$earth = 6371;
|
||||
}
|
||||
|
||||
$latitude = $prefix . 'map_latitude';
|
||||
$longitude = $prefix . 'map_longitude';
|
||||
|
||||
$sql = "SELECT $wpdb->posts.ID,
|
||||
( %s * acos(
|
||||
cos( radians(%s) ) *
|
||||
cos( radians( latitude.meta_value ) ) *
|
||||
cos( radians( longitude.meta_value ) - radians(%s) ) +
|
||||
sin( radians(%s) ) *
|
||||
sin( radians( latitude.meta_value ) )
|
||||
) )
|
||||
AS distance, latitude.meta_value AS latitude, longitude.meta_value AS longitude
|
||||
FROM $wpdb->posts
|
||||
INNER JOIN $wpdb->postmeta
|
||||
AS latitude
|
||||
ON $wpdb->posts.ID = latitude.post_id
|
||||
INNER JOIN $wpdb->postmeta
|
||||
AS longitude
|
||||
ON $wpdb->posts.ID = longitude.post_id
|
||||
WHERE 1=1
|
||||
|
||||
AND latitude.meta_key = '" . $latitude . "'
|
||||
AND longitude.meta_key= '" . $longitude . "'
|
||||
HAVING distance < %s
|
||||
ORDER BY $wpdb->posts.menu_order ASC, distance ASC";
|
||||
|
||||
$query = $wpdb->prepare( $sql,
|
||||
|
||||
$earth,
|
||||
$geo_lat,
|
||||
$geo_long,
|
||||
$geo_lat,
|
||||
$radius
|
||||
);
|
||||
|
||||
$post_ids = $wpdb->get_results( $query, OBJECT_K );
|
||||
if ( $post_ids ) {
|
||||
$post_ids = array_keys( $post_ids );
|
||||
|
||||
return $post_ids;
|
||||
}
|
||||
|
||||
return [ 0 ];
|
||||
}
|
||||
}
|
||||
484
inc/property/class-opalestate-search.php
Executable file
484
inc/property/class-opalestate-search.php
Executable file
@@ -0,0 +1,484 @@
|
||||
<?php
|
||||
/**
|
||||
* $Desc$
|
||||
*
|
||||
* @version $Id$
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @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_Search {
|
||||
/**
|
||||
* Add action to ajax search to display query data results with json format.
|
||||
*/
|
||||
public static function init() {
|
||||
add_action( 'wp_ajax_opalestate_ajx_get_properties', [ __CLASS__, 'get_search_json' ] );
|
||||
add_action( 'wp_ajax_nopriv_opalestate_ajx_get_properties', [ __CLASS__, 'get_search_json' ] );
|
||||
|
||||
add_action( 'wp_ajax_opalestate_render_get_properties', [ __CLASS__, 'render_get_properties' ] );
|
||||
add_action( 'wp_ajax_nopriv_opalestate_render_get_properties', [ __CLASS__, 'render_get_properties' ] );
|
||||
// add_filter( "pre_get_posts", array( __CLASS__, 'change_archive_query' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Query Object to display collection of property with user request which submited via search form
|
||||
*/
|
||||
public static function get_search_results_query( $limit = 9 ) {
|
||||
// global $paged;
|
||||
global $wp_query;
|
||||
|
||||
$show_featured_first = opalestate_options( 'show_featured_first', 1 );
|
||||
$search_min_price = isset( $_GET['min_price'] ) ? sanitize_text_field( $_GET['min_price'] ) : '';
|
||||
$search_max_price = isset( $_GET['max_price'] ) ? sanitize_text_field( $_GET['max_price'] ) : '';
|
||||
|
||||
$search_min_area = isset( $_GET['min_area'] ) ? sanitize_text_field( $_GET['min_area'] ) : '';
|
||||
$search_max_area = isset( $_GET['max_area'] ) ? sanitize_text_field( $_GET['max_area'] ) : '';
|
||||
$s = isset( $_GET['search_text'] ) ? sanitize_text_field( $_GET['search_text'] ) : null;
|
||||
$location_text = isset( $_GET['location_text'] ) ? sanitize_text_field( $_GET['location_text'] ) : null;
|
||||
|
||||
$posts_per_page = apply_filters( 'opalestate_search_property_per_page', opalestate_options( 'search_property_per_page', $limit ) );
|
||||
|
||||
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
|
||||
$paged = isset( $wp_query->query['paged'] ) ? $wp_query->query['paged'] : $paged;
|
||||
$paged = ! empty( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : $paged;
|
||||
|
||||
if ( isset( $_GET['paged'] ) && intval( $_GET['paged'] ) > 0 ) {
|
||||
$paged = intval( $_GET['paged'] );
|
||||
}
|
||||
|
||||
$infos = [];
|
||||
|
||||
$args = [
|
||||
'posts_per_page' => $posts_per_page,
|
||||
'paged' => $paged,
|
||||
'post_type' => 'opalestate_property',
|
||||
'post_status' => 'publish',
|
||||
's' => $s,
|
||||
];
|
||||
|
||||
|
||||
$tax_query = [];
|
||||
|
||||
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
|
||||
$tax_query[] =
|
||||
[
|
||||
'taxonomy' => 'opalestate_location',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $_GET['location'] ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( isset( $_GET['state'] ) && $_GET['state'] != -1 ) {
|
||||
$tax_query[] =
|
||||
[
|
||||
'taxonomy' => 'opalestate_state',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $_GET['state'] ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( isset( $_GET['city'] ) && $_GET['city'] != -1 ) {
|
||||
$tax_query[] =
|
||||
[
|
||||
'taxonomy' => 'opalestate_city',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $_GET['city'] ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( isset( $_GET['types'] ) && $_GET['types'] != -1 ) {
|
||||
$tax_query[] =
|
||||
[
|
||||
'taxonomy' => 'opalestate_types',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $_GET['types'] ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( isset( $_GET['status'] ) && $_GET['status'] != -1 ) {
|
||||
$tax_query[] =
|
||||
[
|
||||
'taxonomy' => 'opalestate_status',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $_GET['status'] ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( isset( $_GET['amenities'] ) && is_array( $_GET['amenities'] ) ) {
|
||||
$tax_query[] =
|
||||
[
|
||||
'taxonomy' => 'opalestate_amenities',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $_GET['amenities'] ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( $tax_query ) {
|
||||
$args['tax_query'] = [ 'relation' => 'AND' ];
|
||||
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );
|
||||
}
|
||||
|
||||
$args['meta_query'] = [ 'relation' => 'AND' ];
|
||||
if ( isset( $_GET['info'] ) && is_array( $_GET['info'] ) ) {
|
||||
$metaquery = [];
|
||||
foreach ( $_GET['info'] as $key => $value ) {
|
||||
if ( trim( $value ) ) {
|
||||
if ( is_numeric( trim( $value ) ) ) {
|
||||
$fieldquery = [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . $key,
|
||||
'value' => sanitize_text_field( trim( $value ) ),
|
||||
'compare' => '>=',
|
||||
'type' => 'NUMERIC',
|
||||
];
|
||||
} else {
|
||||
$fieldquery = [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . $key,
|
||||
'value' => sanitize_text_field( trim( $value ) ),
|
||||
'compare' => 'LIKE',
|
||||
];
|
||||
}
|
||||
$sarg = apply_filters( 'opalestate_search_field_query_' . $key, $fieldquery );
|
||||
$metaquery[] = $sarg;
|
||||
|
||||
}
|
||||
}
|
||||
$args['meta_query'] = array_merge( $args['meta_query'], $metaquery );
|
||||
}
|
||||
|
||||
if ( $search_min_price != '' && $search_min_price != '' && is_numeric( $search_min_price ) && is_numeric( $search_max_price ) ) {
|
||||
if ( $search_min_price ) {
|
||||
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'price',
|
||||
'value' => [ $search_min_price, $search_max_price ],
|
||||
'compare' => 'BETWEEN',
|
||||
'type' => 'NUMERIC',
|
||||
] );
|
||||
} else {
|
||||
array_push( $args['meta_query'], [
|
||||
[
|
||||
[
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'price',
|
||||
'compare' => 'NOT EXISTS',
|
||||
],
|
||||
'relation' => 'OR',
|
||||
[
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'price',
|
||||
'value' => $search_max_price,
|
||||
'compare' => '<=',
|
||||
'type' => 'NUMERIC',
|
||||
],
|
||||
],
|
||||
] );
|
||||
}
|
||||
|
||||
} elseif ( $search_min_price != '' && is_numeric( $search_min_price ) ) {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'price',
|
||||
'value' => $search_min_price,
|
||||
'compare' => '>=',
|
||||
'type' => 'NUMERIC',
|
||||
] );
|
||||
} elseif ( $search_max_price != '' && is_numeric( $search_max_price ) ) {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'price',
|
||||
'value' => $search_max_price,
|
||||
'compare' => '<=',
|
||||
'type' => 'NUMERIC',
|
||||
] );
|
||||
}
|
||||
|
||||
if ( $search_min_area != '' && $search_min_area != '' && is_numeric( $search_min_area ) && is_numeric( $search_max_area ) ) {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'areasize',
|
||||
'value' => [ $search_min_area, $search_max_area ],
|
||||
'compare' => 'BETWEEN',
|
||||
'type' => 'NUMERIC',
|
||||
] );
|
||||
} elseif ( $search_min_area != '' && is_numeric( $search_min_area ) ) {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'areasize',
|
||||
'value' => $search_min_area,
|
||||
'compare' => '>=',
|
||||
'type' => 'NUMERIC',
|
||||
] );
|
||||
} elseif ( $search_max_area != '' && is_numeric( $search_max_area ) ) {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'areasize',
|
||||
'value' => $search_max_area,
|
||||
'compare' => '<=',
|
||||
'type' => 'NUMERIC',
|
||||
] );
|
||||
}
|
||||
|
||||
///// search by address and geo location ///
|
||||
if ( isset( $_GET['geo_long'] ) && isset( $_GET['geo_lat'] ) ) {
|
||||
|
||||
if ( $_GET['location_text'] && ( empty( $_GET['geo_long'] ) || empty( $_GET['geo_lat'] ) ) ) {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_PROPERTY_PREFIX . 'map_address',
|
||||
'value' => sanitize_text_field( trim( $_GET['location_text'] ) ),
|
||||
'compare' => 'LIKE',
|
||||
'operator' => 'OR',
|
||||
] );
|
||||
|
||||
} elseif ( $_GET['geo_lat'] && $_GET['geo_long'] ) {
|
||||
$radius = isset( $_GET['geo_radius'] ) ? $_GET['geo_radius'] : 5;
|
||||
$post_ids = Opalestate_Query::filter_by_location( $_GET['geo_lat'], $_GET['geo_long'], $radius );
|
||||
$args['post__in'] = $post_ids;
|
||||
}
|
||||
}
|
||||
|
||||
/// ///
|
||||
$ksearchs = [];
|
||||
|
||||
if ( isset( $_REQUEST['opalsortable'] ) && ! empty( $_REQUEST['opalsortable'] ) ) {
|
||||
$ksearchs = explode( "_", $_REQUEST['opalsortable'] );
|
||||
} elseif ( isset( $_SESSION['opalsortable'] ) && ! empty( $_SESSION['opalsortable'] ) ) {
|
||||
$ksearchs = explode( "_", $_SESSION['opalsortable'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $ksearchs ) && count( $ksearchs ) == 2 ) {
|
||||
$args['meta_key'] = OPALESTATE_PROPERTY_PREFIX . $ksearchs[0];
|
||||
$args['orderby'] = 'meta_value_num';
|
||||
$args['order'] = $ksearchs[1];
|
||||
}
|
||||
|
||||
$args = apply_filters( 'opalestate_get_search_results_query_args', $args );
|
||||
|
||||
$query = new WP_Query( $args );
|
||||
|
||||
wp_reset_postdata();
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get search query base on user request to filter collection of Agents
|
||||
*/
|
||||
public static function get_search_agents_query( $args = [] ) {
|
||||
$min = opalestate_options( 'search_agent_min_price', 0 );
|
||||
$max = opalestate_options( 'search_agent_max_price', 10000000 );
|
||||
|
||||
$search_min_price = isset( $_GET['min_price'] ) ? sanitize_text_field( $_GET['min_price'] ) : '';
|
||||
$search_max_price = isset( $_GET['max_price'] ) ? sanitize_text_field( $_GET['max_price'] ) : '';
|
||||
|
||||
$search_min_area = isset( $_GET['min_area'] ) ? sanitize_text_field( $_GET['min_area'] ) : '';
|
||||
$search_max_area = isset( $_GET['max_area'] ) ? sanitize_text_field( $_GET['max_area'] ) : '';
|
||||
$s = isset( $_GET['search_text'] ) ? sanitize_text_field( $_GET['search_text'] ) : null;
|
||||
|
||||
$paged = ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' );
|
||||
$default = [
|
||||
'post_type' => 'opalestate_agent',
|
||||
'posts_per_page' => apply_filters( 'opalestate_agent_per_page', 12 ),
|
||||
'paged' => $paged,
|
||||
];
|
||||
$args = array_merge( $default, $args );
|
||||
|
||||
$tax_query = [];
|
||||
|
||||
|
||||
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
|
||||
$tax_query[] =
|
||||
[
|
||||
'taxonomy' => 'opalestate_location',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $_GET['location'] ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( isset( $_GET['types'] ) && $_GET['types'] != -1 ) {
|
||||
$tax_query[] =
|
||||
[
|
||||
'taxonomy' => 'opalestate_types',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $_GET['types'] ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( $tax_query ) {
|
||||
$args['tax_query'] = [ 'relation' => 'AND' ];
|
||||
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );
|
||||
}
|
||||
|
||||
$args['meta_query'] = [ 'relation' => 'AND' ];
|
||||
|
||||
if ( $search_min_price != $min && is_numeric( $search_min_price ) ) {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_AGENT_PREFIX . 'target_min_price',
|
||||
'value' => $search_min_price,
|
||||
'compare' => '>=',
|
||||
// 'type' => 'NUMERIC'
|
||||
] );
|
||||
}
|
||||
if ( is_numeric( $search_max_price ) && $search_max_price != $max ) {
|
||||
array_push( $args['meta_query'], [
|
||||
'key' => OPALESTATE_AGENT_PREFIX . 'target_max_price',
|
||||
'value' => $search_max_price,
|
||||
'compare' => '<=',
|
||||
// 'type' => 'NUMERIC'
|
||||
] );
|
||||
}
|
||||
|
||||
return new WP_Query( $args );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get search query base on user request to filter collection of Agents
|
||||
*/
|
||||
public static function get_search_agencies_query( $args = [] ) {
|
||||
$s = isset( $_GET['search_text'] ) ? sanitize_text_field( $_GET['search_text'] ) : null;
|
||||
|
||||
$paged = ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' );
|
||||
$default = [
|
||||
'post_type' => 'opalestate_agency',
|
||||
'posts_per_page' => apply_filters( 'opalestate_agency_per_page', 12 ),
|
||||
'paged' => $paged,
|
||||
];
|
||||
$args = array_merge( $default, $args );
|
||||
|
||||
$tax_query = [];
|
||||
|
||||
|
||||
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
|
||||
$tax_query[] =
|
||||
[
|
||||
'taxonomy' => 'opalestate_location',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $_GET['location'] ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( isset( $_GET['types'] ) && $_GET['types'] != -1 ) {
|
||||
$tax_query[] =
|
||||
[
|
||||
'taxonomy' => 'opalestate_types',
|
||||
'field' => 'slug',
|
||||
'terms' => sanitize_text_field( $_GET['types'] ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( $tax_query ) {
|
||||
$args['tax_query'] = [ 'relation' => 'AND' ];
|
||||
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );
|
||||
}
|
||||
|
||||
$args['meta_query'] = [ 'relation' => 'AND' ];
|
||||
|
||||
|
||||
return new WP_Query( $args );
|
||||
}
|
||||
|
||||
|
||||
public function filter_by_geolocations() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function get_setting_search_fields( $option = '' ) {
|
||||
$options = [
|
||||
OPALESTATE_PROPERTY_PREFIX . 'bedrooms' => esc_html__( 'Bed Rooms', 'opalestate-pro' ),
|
||||
OPALESTATE_PROPERTY_PREFIX . 'parking' => esc_html__( 'Parking', 'opalestate-pro' ),
|
||||
OPALESTATE_PROPERTY_PREFIX . 'bathrooms' => esc_html__( 'Bath Rooms', 'opalestate-pro' ),
|
||||
];
|
||||
|
||||
$default = apply_filters( 'opalestate_default_fields_setting', $options );
|
||||
|
||||
$metas = Opalestate_Property_MetaBox::metaboxes_info_fields();
|
||||
$esettings = [];
|
||||
$found = false;
|
||||
foreach ( $metas as $key => $meta ) {
|
||||
$value = opalestate_options( $meta['id'] . '_opt' . $option );
|
||||
|
||||
if ( preg_match( "#areasize#", $meta['id'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $value ) {
|
||||
$id = str_replace( OPALESTATE_PROPERTY_PREFIX, "", $meta['id'] );
|
||||
$esettings[ $id ] = $meta['name'];
|
||||
}
|
||||
if ( $value == 0 ) {
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $esettings ) ) {
|
||||
return $esettings;
|
||||
} elseif ( $found ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Json data by action ajax filter
|
||||
*/
|
||||
public static function get_search_json() {
|
||||
|
||||
$query = self::get_search_results_query();
|
||||
|
||||
$output = [];
|
||||
|
||||
while ( $query->have_posts() ) {
|
||||
|
||||
$query->the_post();
|
||||
$property = opalesetate_property( get_the_ID() );
|
||||
$output[] = $property->get_meta_search_objects();
|
||||
}
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
echo json_encode( $output );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function render_get_properties() {
|
||||
// $_GET = $_POST;
|
||||
echo opalestate_load_template_path( 'shortcodes/ajax-map-search-result' );
|
||||
die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render search property form in horizontal
|
||||
*/
|
||||
public static function render_horizontal_form( $atts = [] ) {
|
||||
echo opalestate_load_template_path( 'search-box/search-form-h', $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render search property form in vertical
|
||||
*/
|
||||
public static function render_vertical_form( $atts = [] ) {
|
||||
echo opalestate_load_template_path( 'search-box/search-form-v', $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function render_field_price() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function render_field_area() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
OpalEstate_Search::init();
|
||||
125
inc/property/class-opalestate-shortcodes.php
Executable file
125
inc/property/class-opalestate-shortcodes.php
Executable file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* $Desc$
|
||||
*
|
||||
* @version $Id$
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @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_Shortcodes
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
class OpalEstate_Shortcodes{
|
||||
|
||||
/**
|
||||
* Static $shortcodes
|
||||
*/
|
||||
public $shortcodes;
|
||||
|
||||
/**
|
||||
* defined list of shortcode and functions of this for each.
|
||||
*/
|
||||
public function __construct(){
|
||||
|
||||
$this->shortcodes = array(
|
||||
|
||||
'search_properties_result' => array( 'code' => 'search_properties_result', 'label' => esc_html__( 'Search Properties Result', 'opalestate-pro' ) ),
|
||||
'search_properties' => array( 'code' => 'search_properties', 'label' => esc_html__( 'Search Properties', 'opalestate-pro' ) ),
|
||||
'search_properties_v' => array( 'code' => 'search_properties_v', 'label' => esc_html__( 'Search Properties Vertical', 'opalestate-pro' ) ),
|
||||
|
||||
'search_map_properties' => array( 'code' => 'search_map_properties', 'label' => esc_html__( 'Search Map Properties', 'opalestate-pro' ) ),
|
||||
'ajax_map_search' => array( 'code' => 'ajax_map_search', 'label' => esc_html__( 'Ajax Search Map Properties', 'opalestate-pro' ) ),
|
||||
'ajax_map_quick_search' => array( 'code' => 'ajax_map_quick_search', 'label' => esc_html__( 'Ajax Search Map Properties', 'opalestate-pro' ) ),
|
||||
'register_form' => array( 'code' => 'register_form', 'label' => esc_html__( 'Register User Form', 'opalestate-pro' ) ),
|
||||
'login_form' => array( 'code' => 'login_form', 'label' => esc_html__( 'Login Form', 'opalestate-pro' ) ),
|
||||
);
|
||||
|
||||
foreach( $this->shortcodes as $shortcode ){
|
||||
add_shortcode( 'opalestate_'.$shortcode['code'] , array( $this, $shortcode['code'] ) );
|
||||
}
|
||||
|
||||
if( is_admin() ){
|
||||
add_action( 'media_buttons', array( $this, 'shortcode_button' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function shortcode_button(){
|
||||
|
||||
}
|
||||
|
||||
public function search_properties_result(){
|
||||
return opalestate_load_template_path( 'shortcodes/search-properties-result' );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Display all properties follow user when logined
|
||||
*/
|
||||
public function agent_property(){
|
||||
return opalestate_load_template_path( 'shortcodes/agent-property-listing' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render search property page with horizontal form and map
|
||||
*/
|
||||
public function search_properties(){
|
||||
return opalestate_load_template_path( 'shortcodes/search-properties', array( 'loop' => '') );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render search property page with vertical form and map
|
||||
*/
|
||||
public function search_properties_v(){
|
||||
return opalestate_load_template_path( 'shortcodes/search-properties-v', array( 'loop' => '') );
|
||||
}
|
||||
|
||||
public function search_map_properties(){
|
||||
return opalestate_load_template_path( 'shortcodes/search-map-properties', array( 'loop' => '') );
|
||||
}
|
||||
|
||||
public function ajax_map_search(){
|
||||
wp_enqueue_script( 'sticky-kit', OPALESTATE_PLUGIN_URL . 'assets/js/jquery.sticky-kit.min.js' );
|
||||
return opalestate_load_template_path( 'shortcodes/ajax-map-search', array( 'loop' => '') );
|
||||
}
|
||||
|
||||
public function ajax_map_quick_search(){
|
||||
return opalestate_load_template_path( 'shortcodes/ajax-map-quick-search', array( 'loop' => '') );
|
||||
}
|
||||
|
||||
/* register form show up */
|
||||
public function register_form( $atts = array() ) {
|
||||
$atts = shortcode_atts( array(
|
||||
'message' => '',
|
||||
'redirect' => '',
|
||||
'hide_title' => false
|
||||
), $atts );
|
||||
return opalestate_load_template_path( 'user/register-form', $atts );
|
||||
}
|
||||
|
||||
/* sign in show up */
|
||||
public function login_form( $atts = array() ) {
|
||||
$atts = shortcode_atts( array(
|
||||
'message' => '',
|
||||
'redirect' => '',
|
||||
'hide_title' => false
|
||||
), $atts );
|
||||
return opalestate_load_template_path( 'user/login-form', $atts );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new OpalEstate_Shortcodes();
|
||||
155
inc/property/class-opalestate-view-stats.php
Executable file
155
inc/property/class-opalestate-view-stats.php
Executable file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
/**
|
||||
* Property view stats.
|
||||
*
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @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_View_Stats {
|
||||
protected $id;
|
||||
|
||||
protected $record;
|
||||
|
||||
public function __construct( $id, $record = 8 ) {
|
||||
|
||||
$this->id = $id;
|
||||
|
||||
$this->record = $record;
|
||||
|
||||
$this->count_page_stats();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_real_ip_addr() {
|
||||
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { //check ip from share internet
|
||||
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
||||
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { //to check ip is pass from proxy
|
||||
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
} elseif ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
} else {
|
||||
$ip = '';
|
||||
}
|
||||
|
||||
return $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count page views.
|
||||
*/
|
||||
public function count_page_stats() {
|
||||
// Get IPs.
|
||||
$ips = $this->get_ips_viewed();
|
||||
|
||||
$current_ip = static::get_real_ip_addr();
|
||||
|
||||
if ( ! in_array( $current_ip, $ips ) ) {
|
||||
// Update IPS.
|
||||
array_push( $ips, $current_ip );
|
||||
update_post_meta( $this->id, 'opalestate_ips_viewed', $ips );
|
||||
|
||||
// Count and update total views.
|
||||
$total_views = intval( get_post_meta( $this->id, 'opalestate_total_views', true ) );
|
||||
if ( $total_views == '' ) {
|
||||
$total_views = 1;
|
||||
} else {
|
||||
$total_views++;
|
||||
}
|
||||
|
||||
update_post_meta( $this->id, 'opalestate_total_views', $total_views );
|
||||
|
||||
// Update detailed views.
|
||||
$today = date( 'm-d-Y', time() );
|
||||
$detailed_views = get_post_meta( $this->id, 'opalestate_detailed_views', true );
|
||||
|
||||
if ( $detailed_views == '' || ! is_array( $detailed_views ) ) {
|
||||
$detailed_views = [];
|
||||
$detailed_views[ $today ] = 1;
|
||||
} else {
|
||||
if ( ! isset( $detailed_views[ $today ] ) ) {
|
||||
if ( count( $detailed_views ) > 15 ) {
|
||||
array_shift( $detailed_views );
|
||||
}
|
||||
|
||||
$detailed_views[ $today ] = 1;
|
||||
} else {
|
||||
$detailed_views[ $today ] = intval( $detailed_views[ $today ] ) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
$detailed_views = update_post_meta( $this->id, 'opalestate_detailed_views', $detailed_views );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function get_traffic_labels() {
|
||||
$detailed_views = get_post_meta( $this->id, 'opalestate_detailed_views', true );
|
||||
|
||||
if ( ! is_array( $detailed_views ) ) {
|
||||
$detailed_views = [];
|
||||
}
|
||||
|
||||
$array_label = array_keys( $detailed_views );
|
||||
$array_label = array_slice( $array_label, -1 * $this->record, $this->record, false );
|
||||
|
||||
return $array_label;
|
||||
}
|
||||
|
||||
|
||||
public function get_traffic_data() {
|
||||
$detailed_views = get_post_meta( $this->id, 'opalestate_detailed_views', true );
|
||||
if ( ! is_array( $detailed_views ) ) {
|
||||
$detailed_views = [];
|
||||
}
|
||||
$array_values = array_values( $detailed_views );
|
||||
$array_values = array_slice( $array_values, -1 * $this->record, $this->record, false );
|
||||
|
||||
return $array_values;
|
||||
}
|
||||
|
||||
|
||||
public function get_traffic_data_accordion() {
|
||||
$detailed_views = get_post_meta( $this->id, 'opalestate_detailed_views', true );
|
||||
if ( ! is_array( $detailed_views ) ) {
|
||||
$detailed_views = [];
|
||||
}
|
||||
|
||||
// since this runs before we increment the visits - on acc page style
|
||||
$today = date( 'm-d-Y', time() );
|
||||
|
||||
if ( isset( $detailed_views[ $today ] ) ) {
|
||||
$detailed_views[ $today ] = intval( $detailed_views[ $today ] ) + 1;
|
||||
}
|
||||
|
||||
$array_values = array_values( $detailed_views );
|
||||
$array_values = array_slice( $array_values, -1 * $this->record, $this->record, false );
|
||||
|
||||
return $array_values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get IPs viewed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_ips_viewed() {
|
||||
$ips = get_post_meta( $this->id, 'opalestate_ips_viewed', true );
|
||||
if ( ! $ips ) {
|
||||
$ips = [];
|
||||
}
|
||||
|
||||
return $ips;
|
||||
}
|
||||
}
|
||||
0
inc/property/functions.php
Executable file
0
inc/property/functions.php
Executable file
Reference in New Issue
Block a user