Created
September 23, 2025 06:22
-
-
Save Junex123/7a8fd7709d8cb44356d484961619f0ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Property Filter | |
| * | |
| * @package wp-realestate | |
| * @author Habq | |
| * @license GNU General Public License, version 3 | |
| */ | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; | |
| } | |
| class WP_RealEstate_Property_Filter extends WP_RealEstate_Abstract_Filter { | |
| public static function init() { | |
| add_action( 'pre_get_posts', array( __CLASS__, 'archive' ) ); | |
| add_action( 'pre_get_posts', array( __CLASS__, 'taxonomy' ) ); | |
| add_filter( 'wp-realestate-property-filter-query', array( __CLASS__, 'filter_query_property' ), 10, 2 ); | |
| add_filter( 'wp-realestate-property-query-args', array( __CLASS__, 'filter_query_args_property' ), 10, 2 ); | |
| } | |
| public static function get_fields() { | |
| return apply_filters( 'wp-realestate-default-property-filter-fields', array( | |
| 'center-location' => array( | |
| 'name' => __( 'Location', 'wp-realestate' ), | |
| 'field_call_back' => array( 'WP_RealEstate_Abstract_Filter', 'filter_field_input_location'), | |
| 'placeholder' => __( 'All Location', 'wp-realestate' ), | |
| 'show_distance' => true, | |
| 'toggle' => true, | |
| 'for_post_type' => 'property', | |
| ), | |
| )); | |
| } | |
| public static function archive($query) { | |
| $suppress_filters = ! empty( $query->query_vars['suppress_filters'] ) ? $query->query_vars['suppress_filters'] : ''; | |
| if ( ! is_post_type_archive( 'property' ) || ! $query->is_main_query() || is_admin() || $query->query_vars['post_type'] != 'property' || $suppress_filters ) { | |
| return; | |
| } | |
| $limit = wp_realestate_get_option('number_properties_per_page', 10); | |
| $query_vars = &$query->query_vars; | |
| $query_vars['posts_per_page'] = $limit; | |
| $query->query_vars = $query_vars; | |
| return self::filter_query( $query ); | |
| } | |
| public static function taxonomy($query) { | |
| $is_correct_taxonomy = false; | |
| if ( is_tax( 'property_type' ) || is_tax( 'property_amenity' ) || is_tax( 'property_location' ) || is_tax( 'property_status' ) || is_tax( 'property_label' ) || is_tax( 'property_material' ) || apply_filters( 'wp-realestate-property-query-taxonomy', false ) ) { | |
| $is_correct_taxonomy = true; | |
| } | |
| if ( ! $is_correct_taxonomy || ! $query->is_main_query() || is_admin() ) { | |
| return; | |
| } | |
| $limit = wp_realestate_get_option('number_properties_per_page', 10); | |
| $query_vars = $query->query_vars; | |
| $query_vars['posts_per_page'] = $limit; | |
| $query->query_vars = $query_vars; | |
| return self::filter_query( $query ); | |
| } | |
| public static function filter_query( $query = null, $params = array() ) { | |
| global $wpdb, $wp_query; | |
| if ( empty( $query ) ) { | |
| $query = $wp_query; | |
| } | |
| if ( empty( $params ) ) { | |
| $params = $_GET; | |
| } | |
| // Filter params | |
| $params = apply_filters( 'wp_realestate_property_filter_params', $params ); | |
| // Initialize variables | |
| $query_vars = $query->query_vars; | |
| $query_vars = self::get_query_var_filter($query_vars, $params); | |
| $query->query_vars = $query_vars; | |
| // Meta query | |
| $meta_query = self::get_meta_filter($params); | |
| if ( $meta_query ) { | |
| $query->set( 'meta_query', $meta_query ); | |
| } | |
| // Tax query | |
| $tax_query = self::get_tax_filter($params); | |
| if ( $tax_query ) { | |
| $query->set( 'tax_query', $tax_query ); | |
| } | |
| return apply_filters('wp-realestate-property-filter-query', $query, $params); | |
| } | |
| public static function get_query_var_filter($query_vars, $params) { | |
| $ids = null; | |
| $query_vars = self::orderby($query_vars, $params); | |
| // Property title | |
| if ( ! empty( $params['filter-title'] ) ) { | |
| global $wp_realestate_property_keyword; | |
| $wp_realestate_property_keyword = sanitize_text_field( wp_unslash($params['filter-title']) ); | |
| $query_vars['s'] = sanitize_text_field( wp_unslash($params['filter-title']) ); | |
| add_filter( 'posts_search', array( __CLASS__, 'get_properties_keyword_search' ) ); | |
| } | |
| $distance_ids = self::filter_by_distance($params, 'property'); | |
| if ( !empty($distance_ids) ) { | |
| $ids = self::build_post_ids( $ids, $distance_ids ); | |
| } | |
| if ( ! empty( $params['filter-author'] ) ) { | |
| $query_vars['author'] = sanitize_text_field( wp_unslash($params['filter-author']) ); | |
| } | |
| // Post IDs | |
| if ( is_array( $ids ) && count( $ids ) > 0 ) { | |
| $query_vars['post__in'] = $ids; | |
| } | |
| return $query_vars; | |
| } | |
| public static function get_meta_filter($params) { | |
| $meta_query = array(); | |
| // price | |
| if ( isset($params['filter-price-from']) && intval($params['filter-price-from']) >= 0 && isset($params['filter-price-to']) && intval($params['filter-price-to']) > 0) { | |
| $price_from = WP_RealEstate_Price::convert_current_currency_to_default($params['filter-price-from']); | |
| $price_to = WP_RealEstate_Price::convert_current_currency_to_default($params['filter-price-to']); | |
| if ( $price_from == 0 ) { | |
| $meta_query[] = array( | |
| 'relation' => 'OR', | |
| array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'price', | |
| 'value' => array( intval($price_from), intval($price_to) ), | |
| 'compare' => 'BETWEEN', | |
| 'type' => 'NUMERIC', | |
| ), | |
| array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'price', | |
| 'value' => '', | |
| 'compare' => '==', | |
| ), | |
| ); | |
| } else { | |
| $meta_query[] = array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'price', | |
| 'value' => array( intval($price_from), intval($price_to) ), | |
| 'compare' => 'BETWEEN', | |
| 'type' => 'NUMERIC', | |
| ); | |
| } | |
| } | |
| if ( ! empty( $params['filter-featured'] ) ) { | |
| $meta_query[] = array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'featured', | |
| 'value' => 'on', | |
| 'compare' => '==', | |
| ); | |
| } | |
| // Rooms | |
| if ( ! empty( $params['filter-rooms'] ) ) { | |
| $value = sanitize_text_field( wp_unslash($params['filter-rooms']) ); | |
| if (strpos($value, '+') !== false) { | |
| $value = rtrim($value, '+'); | |
| $meta_query[] = array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'rooms', | |
| 'value' => $value, | |
| 'compare' => '>=', | |
| 'type' => 'NUMERIC', | |
| ); | |
| } else { | |
| $meta_query[] = array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'rooms', | |
| 'value' => $value, | |
| 'compare' => '=', | |
| 'type' => 'NUMERIC', | |
| ); | |
| } | |
| } | |
| // Beds | |
| if ( ! empty( $params['filter-beds'] ) ) { | |
| $value = sanitize_text_field( wp_unslash($params['filter-beds']) ); | |
| if (strpos($value, '+') !== false) { | |
| $value = rtrim($value, '+'); | |
| $meta_query[] = array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'beds', | |
| 'value' => $value, | |
| 'compare' => '>=', | |
| 'type' => 'NUMERIC', | |
| ); | |
| } else { | |
| $meta_query[] = array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'beds', | |
| 'value' => $value, | |
| 'compare' => '=', | |
| 'type' => 'NUMERIC', | |
| ); | |
| } | |
| } | |
| // Baths | |
| if ( ! empty( $params['filter-baths'] ) ) { | |
| $value = sanitize_text_field( wp_unslash($params['filter-baths']) ); | |
| if (strpos($value, '+') !== false) { | |
| $value = rtrim($value, '+'); | |
| $meta_query[] = array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'baths', | |
| 'value' => $value, | |
| 'compare' => '>=', | |
| 'type' => 'NUMERIC', | |
| ); | |
| } else { | |
| $meta_query[] = array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'baths', | |
| 'value' => $value, | |
| 'compare' => '=', | |
| 'type' => 'NUMERIC', | |
| ); | |
| } | |
| } | |
| // Garages | |
| if ( ! empty( $params['filter-garages'] ) ) { | |
| $value = sanitize_text_field( wp_unslash($params['filter-garages']) ); | |
| if (strpos($value, '+') !== false) { | |
| $value = rtrim($value, '+'); | |
| $meta_query[] = array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'garages', | |
| 'value' => $value, | |
| 'compare' => '>=', | |
| 'type' => 'NUMERIC', | |
| ); | |
| } else { | |
| $meta_query[] = array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'garages', | |
| 'value' => $value, | |
| 'compare' => '=', | |
| 'type' => 'NUMERIC', | |
| ); | |
| } | |
| } | |
| if ( isset($params['filter-home_area-from']) && intval($params['filter-home_area-from']) >= 0 && isset($params['filter-home_area-to']) && intval($params['filter-home_area-to']) > 0) { | |
| if ( $params['filter-home_area-from'] == 0 ) { | |
| $meta_query[] = array( | |
| 'relation' => 'OR', | |
| array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'home_area', | |
| 'value' => array( intval($params['filter-home_area-from']), intval($params['filter-home_area-to']) ), | |
| 'compare' => 'BETWEEN', | |
| 'type' => 'NUMERIC', | |
| ), | |
| array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'home_area', | |
| 'value' => '', | |
| 'compare' => '==', | |
| ), | |
| array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'home_area', | |
| 'compare' => 'NOT EXISTS', | |
| ), | |
| ); | |
| } else { | |
| $meta_query[] = array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'home_area', | |
| 'value' => array( intval($params['filter-home_area-from']), intval($params['filter-home_area-to']) ), | |
| 'compare' => 'BETWEEN', | |
| 'type' => 'NUMERIC', | |
| ); | |
| } | |
| } | |
| if ( isset($params['filter-lot_area-from']) && intval($params['filter-lot_area-from']) >= 0 && isset($params['filter-lot_area-to']) && intval($params['filter-lot_area-to']) > 0) { | |
| if ( $params['filter-lot_area-from'] == 0 ) { | |
| $meta_query[] = array( | |
| 'relation' => 'OR', | |
| array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'lot_area', | |
| 'value' => array( intval($params['filter-lot_area-from']), intval($params['filter-lot_area-to']) ), | |
| 'compare' => 'BETWEEN', | |
| 'type' => 'NUMERIC', | |
| ), | |
| array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'lot_area', | |
| 'value' => '', | |
| 'compare' => '==', | |
| ), | |
| array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'lot_area', | |
| 'compare' => 'NOT EXISTS', | |
| ), | |
| ); | |
| } else { | |
| $meta_query[] = array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'lot_area', | |
| 'value' => array( intval($params['filter-lot_area-from']), intval($params['filter-lot_area-to']) ), | |
| 'compare' => 'BETWEEN', | |
| 'type' => 'NUMERIC', | |
| ); | |
| } | |
| } | |
| // Year built | |
| if ( isset($params['filter-year_built-from']) && intval($params['filter-year_built-from']) >= 0 && isset($params['filter-year_built-to']) && intval($params['filter-year_built-to']) > 0) { | |
| if ( $params['filter-year_built-from'] == 0 ) { | |
| $meta_query[] = array( | |
| 'relation' => 'OR', | |
| array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'year_built', | |
| 'value' => array( intval($params['filter-year_built-from']), intval($params['filter-year_built-to']) ), | |
| 'compare' => 'BETWEEN', | |
| 'type' => 'NUMERIC', | |
| ), | |
| array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'year_built', | |
| 'value' => '', | |
| 'compare' => '==', | |
| ), | |
| array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'year_built', | |
| 'compare' => 'NOT EXISTS', | |
| ), | |
| ); | |
| } else { | |
| $meta_query[] = array( | |
| 'key' => WP_REALESTATE_PROPERTY_PREFIX . 'year_built', | |
| 'value' => array( intval($params['filter-year_built-from']), intval($params['filter-year_built-to']) ), | |
| 'compare' => 'BETWEEN', | |
| 'type' => 'NUMERIC', | |
| ); | |
| } | |
| } | |
| return $meta_query; | |
| } | |
| public static function get_tax_filter($params) { | |
| $tax_query = array(); | |
| if ( ! empty( $params['filter-status'] ) ) { | |
| if ( is_array($params['filter-status']) ) { | |
| $field = is_numeric( $params['filter-status'][0] ) ? 'term_id' : 'slug'; | |
| $values = array_filter( array_map( 'sanitize_title', wp_unslash( $params['filter-status'] ) ) ); | |
| if ( !empty($values) ) { | |
| $tax_query[] = array( | |
| 'taxonomy' => 'property_status', | |
| 'field' => $field, | |
| 'terms' => array_values($values), | |
| 'compare' => 'IN', | |
| ); | |
| } | |
| } else { | |
| $field = is_numeric( $params['filter-status'] ) ? 'term_id' : 'slug'; | |
| $tax_query[] = array( | |
| 'taxonomy' => 'property_status', | |
| 'field' => $field, | |
| 'terms' => sanitize_text_field( wp_unslash($params['filter-status']) ), | |
| 'compare' => '==', | |
| ); | |
| } | |
| } | |
| if ( ! empty( $params['filter-type'] ) ) { | |
| if ( is_array($params['filter-type']) ) { | |
| $field = is_numeric( $params['filter-type'][0] ) ? 'term_id' : 'slug'; | |
| $values = array_filter( array_map( 'sanitize_title', wp_unslash( $params['filter-type'] ) ) ); | |
| if ( !empty($values) ) { | |
| $tax_query[] = array( | |
| 'taxonomy' => 'property_type', | |
| 'field' => $field, | |
| 'terms' => array_values($values), | |
| 'compare' => 'IN', | |
| ); | |
| } | |
| } else { | |
| $field = is_numeric( $params['filter-type'] ) ? 'term_id' : 'slug'; | |
| $tax_query[] = array( | |
| 'taxonomy' => 'property_type', | |
| 'field' => $field, | |
| 'terms' => sanitize_text_field( wp_unslash($params['filter-type']) ), | |
| 'compare' => '==', | |
| ); | |
| } | |
| } | |
| if ( ! empty( $params['filter-location'] ) ) { | |
| if ( is_array($params['filter-location']) ) { | |
| $field = is_numeric( $params['filter-location'][0] ) ? 'term_id' : 'slug'; | |
| $values = array_filter( array_map( 'sanitize_title', wp_unslash( $params['filter-location'] ) ) ); | |
| // if ( !empty($values) ) { | |
| // $tax_query[] = array( | |
| // 'taxonomy' => 'property_location', | |
| // 'field' => $field, | |
| // 'terms' => array_values($values), | |
| // 'compare' => 'IN', | |
| // ); | |
| // } | |
| if ( !empty($values) ) { | |
| $location_tax_query = array('relation' => 'AND'); | |
| foreach ($values as $key => $value) { | |
| $location_tax_query[] = array( | |
| 'taxonomy' => 'property_location', | |
| 'field' => $field, | |
| 'terms' => $value, | |
| 'compare' => '==', | |
| ); | |
| } | |
| $tax_query[] = $location_tax_query; | |
| } | |
| } else { | |
| $field = is_numeric( $params['filter-location'] ) ? 'term_id' : 'slug'; | |
| $tax_query[] = array( | |
| 'taxonomy' => 'property_location', | |
| 'field' => $field, | |
| 'terms' => sanitize_text_field( wp_unslash($params['filter-location']) ), | |
| 'compare' => '==', | |
| ); | |
| } | |
| } | |
| if ( ! empty( $params['filter-amenity'] ) ) { | |
| if ( is_array($params['filter-amenity']) ) { | |
| $field = is_numeric( $params['filter-amenity'][0] ) ? 'term_id' : 'slug'; | |
| $values = array_filter( array_map( 'sanitize_title', wp_unslash( $params['filter-amenity'] ) ) ); | |
| if ( !empty($values) ) { | |
| $tax_query[] = array( | |
| 'taxonomy' => 'property_amenity', | |
| 'field' => $field, | |
| 'terms' => array_values($values), | |
| 'compare' => 'IN', | |
| ); | |
| } | |
| } else { | |
| $field = is_numeric( $params['filter-amenity'] ) ? 'term_id' : 'slug'; | |
| $tax_query[] = array( | |
| 'taxonomy' => 'property_amenity', | |
| 'field' => $field, | |
| 'terms' => sanitize_text_field( wp_unslash($params['filter-amenity']) ), | |
| 'compare' => '==', | |
| ); | |
| } | |
| } | |
| if ( ! empty( $params['filter-material'] ) ) { | |
| if ( is_array($params['filter-material']) ) { | |
| $field = is_numeric( $params['filter-material'][0] ) ? 'term_id' : 'slug'; | |
| $values = array_filter( array_map( 'sanitize_title', wp_unslash( $params['filter-material'] ) ) ); | |
| if ( !empty($values) ) { | |
| $tax_query[] = array( | |
| 'taxonomy' => 'property_material', | |
| 'field' => $field, | |
| 'terms' => array_values($values), | |
| 'compare' => 'IN', | |
| ); | |
| } | |
| } else { | |
| $field = is_numeric( $params['filter-material'] ) ? 'term_id' : 'slug'; | |
| $tax_query[] = array( | |
| 'taxonomy' => 'property_material', | |
| 'field' => $field, | |
| 'terms' => sanitize_text_field( wp_unslash($params['filter-material']) ), | |
| 'compare' => '==', | |
| ); | |
| } | |
| } | |
| if ( ! empty( $params['filter-label'] ) ) { | |
| if ( is_array($params['filter-label']) ) { | |
| $field = is_numeric( $params['filter-label'][0] ) ? 'term_id' : 'slug'; | |
| $values = array_filter( array_map( 'sanitize_title', wp_unslash( $params['filter-label'] ) ) ); | |
| if ( !empty($values) ) { | |
| $tax_query[] = array( | |
| 'taxonomy' => 'property_label', | |
| 'field' => $field, | |
| 'terms' => array_values($values), | |
| 'compare' => 'IN', | |
| ); | |
| } | |
| } else { | |
| $field = is_numeric( $params['filter-label'] ) ? 'term_id' : 'slug'; | |
| $tax_query[] = array( | |
| 'taxonomy' => 'property_label', | |
| 'field' => $field, | |
| 'terms' => sanitize_text_field( wp_unslash($params['filter-label']) ), | |
| 'compare' => '==', | |
| ); | |
| } | |
| } | |
| return $tax_query; | |
| } | |
| public static function get_properties_keyword_search( $search ) { | |
| global $wpdb, $wp_realestate_property_keyword; | |
| // Searchable Meta Keys: set to empty to search all meta keys. | |
| $searchable_meta_keys = array( | |
| WP_REALESTATE_PROPERTY_PREFIX.'address', | |
| WP_REALESTATE_PROPERTY_PREFIX.'property_id', | |
| ); | |
| $searchable_meta_keys = apply_filters( 'wp_realestate_searchable_meta_keys', $searchable_meta_keys ); | |
| // Set Search DB Conditions. | |
| $conditions = array(); | |
| // Search Post Meta. | |
| if ( apply_filters( 'wp_realestate_search_post_meta', true ) ) { | |
| // Only selected meta keys. | |
| if ( $searchable_meta_keys ) { | |
| $conditions[] = "{$wpdb->posts}.ID IN ( SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key IN ( '" . implode( "','", array_map( 'esc_sql', $searchable_meta_keys ) ) . "' ) AND meta_value LIKE '%" . esc_sql( $wp_realestate_property_keyword ) . "%' )"; | |
| } else { | |
| // No meta keys defined, search all post meta value. | |
| $conditions[] = "{$wpdb->posts}.ID IN ( SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value LIKE '%" . esc_sql( $wp_realestate_property_keyword ) . "%' )"; | |
| } | |
| } | |
| // Search taxonomy. | |
| $conditions[] = "{$wpdb->posts}.ID IN ( SELECT object_id FROM {$wpdb->term_relationships} AS tr LEFT JOIN {$wpdb->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id LEFT JOIN {$wpdb->terms} AS t ON tt.term_id = t.term_id WHERE t.name LIKE '%" . esc_sql( $wp_realestate_property_keyword ) . "%' )"; | |
| $conditions = apply_filters( 'wp_realestate_search_conditions', $conditions, $wp_realestate_property_keyword ); | |
| if ( empty( $conditions ) ) { | |
| return $search; | |
| } | |
| $conditions_str = implode( ' OR ', $conditions ); | |
| if ( ! empty( $search ) ) { | |
| $search = preg_replace( '/^ AND /', '', $search ); | |
| $search = " AND ( {$search} OR ( {$conditions_str} ) )"; | |
| } else { | |
| $search = " AND ( {$conditions_str} )"; | |
| } | |
| remove_filter( 'posts_search', array( __CLASS__, 'get_properties_keyword_search' ) ); | |
| return $search; | |
| } | |
| public static function filter_query_property($query, $params) { | |
| $query_vars = $query->query_vars; | |
| $meta_query = self::filter_meta($query_vars, $params); | |
| $query->set('meta_query', $meta_query); | |
| return $query; | |
| } | |
| public static function filter_query_args_property($query_vars, $params) { | |
| $meta_query = self::filter_meta($query_vars, $params); | |
| $query_vars['meta_query'] = $meta_query; | |
| return $query_vars; | |
| } | |
| public static function filter_meta($query_args, $params) { | |
| if ( isset($query_args['meta_query']) ) { | |
| $meta_query = $query_args['meta_query']; | |
| } else { | |
| $meta_query = array(); | |
| } | |
| if ( empty($params) || !is_array($params) ) { | |
| return $meta_query; | |
| } | |
| $filter_fields = WP_RealEstate_Custom_Fields::filter_custom_fields(array()); | |
| $cfielddate = []; | |
| foreach ( $params as $key => $value ) { | |
| if ( !empty($value) && strrpos( $key, 'filter-cfielddate-', -strlen( $key ) ) !== false ) { | |
| $cfielddate[$key] = $value; | |
| } | |
| if ( !empty($value) && strrpos( $key, 'filter-cfield-', -strlen( $key ) ) !== false ) { | |
| $custom_key = str_replace( 'filter-cfield-', '', $key ); | |
| if ( !empty($filter_fields[$custom_key]) ) { | |
| $fielddata = $filter_fields[$custom_key]; | |
| $field_type = $fielddata['type']; | |
| $meta_key = $custom_key; | |
| switch ($field_type) { | |
| case 'text': | |
| case 'textarea': | |
| case 'wysiwyg': | |
| case 'number': | |
| case 'url': | |
| case 'email': | |
| $meta_query[] = array( | |
| 'key' => $meta_key, | |
| 'value' => $value, | |
| 'compare' => 'LIKE', | |
| ); | |
| break; | |
| case 'radio': | |
| case 'select': | |
| case 'pw_select': | |
| $meta_query[] = array( | |
| 'key' => $meta_key, | |
| 'value' => $value, | |
| 'compare' => '=', | |
| ); | |
| break; | |
| case 'checkbox': | |
| $meta_query[] = array( | |
| 'key' => $meta_key, | |
| 'value' => 'on', | |
| 'compare' => '=', | |
| ); | |
| break; | |
| case 'pw_multiselect': | |
| case 'multiselect': | |
| case 'multicheck': | |
| if ( is_array($value) ) { | |
| $multi_meta = array( 'relation' => 'OR' ); | |
| foreach ($value as $val) { | |
| $multi_meta[] = array( | |
| 'key' => $meta_key, | |
| 'value' => '"'.$val.'"', | |
| 'compare' => 'LIKE', | |
| ); | |
| } | |
| $meta_query[] = $multi_meta; | |
| } else { | |
| $meta_query[] = array( | |
| 'key' => $meta_key, | |
| 'value' => '"'.$value.'"', | |
| 'compare' => 'LIKE', | |
| ); | |
| } | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| if ( !empty($cfielddate) ) { | |
| foreach ( $cfielddate as $key => $values ) { | |
| if ( !empty($values) && is_array($values) && count($values) == 2 ) { | |
| $custom_key = str_replace( 'filter-cfielddate-', '', $key ); | |
| if ( !empty($filter_fields[$custom_key]) ) { | |
| $fielddata = $filter_fields[$custom_key]; | |
| $field_type = $fielddata['type']; | |
| $meta_key = $custom_key; | |
| if ( !empty($values['from']) && !empty($values['to']) ) { | |
| $meta_query[] = array( | |
| 'key' => $meta_key, | |
| 'value' => array($values['from'], $values['to']), | |
| 'compare' => 'BETWEEN', | |
| 'type' => 'DATE', | |
| ); | |
| } elseif ( !empty($values['from']) && empty($values['to']) ) { | |
| $meta_query[] = array( | |
| 'key' => $meta_key, | |
| 'value' => $values['from'], | |
| 'compare' => '>', | |
| 'type' => 'DATE', | |
| ); | |
| } elseif (empty($values['from']) && !empty($values['to']) ) { | |
| $meta_query[] = array( | |
| 'key' => $meta_key, | |
| 'value' => $values['to'], | |
| 'compare' => '<', | |
| 'type' => 'DATE', | |
| ); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| if ( !empty($params['filter-counter']) ) { | |
| foreach ( $params['filter-counter'] as $key => $value ) { | |
| if ( !empty($value) && strrpos( $key, 'filter-cfield-', -strlen( $key ) ) !== false ) { | |
| $custom_key = str_replace( 'filter-cfield-', '', $key ); | |
| if ( !empty($filter_fields[$custom_key]) ) { | |
| $fielddata = $filter_fields[$custom_key]; | |
| $field_type = $fielddata['type']; | |
| $meta_key = $custom_key; | |
| switch ($field_type) { | |
| case 'text': | |
| case 'textarea': | |
| case 'wysiwyg': | |
| case 'number': | |
| case 'url': | |
| case 'email': | |
| $meta_query[] = array( | |
| 'key' => $meta_key, | |
| 'value' => $value, | |
| 'compare' => 'LIKE', | |
| ); | |
| break; | |
| case 'radio': | |
| case 'select': | |
| case 'pw_select': | |
| $meta_query[] = array( | |
| 'key' => $meta_key, | |
| 'value' => $value, | |
| 'compare' => '=', | |
| ); | |
| break; | |
| case 'checkbox': | |
| $meta_query[] = array( | |
| 'key' => $meta_key, | |
| 'value' => 'on', | |
| 'compare' => '=', | |
| ); | |
| break; | |
| case 'pw_multiselect': | |
| case 'multiselect': | |
| case 'multicheck': | |
| if ( is_array($value) ) { | |
| $multi_meta = array( 'relation' => 'OR' ); | |
| foreach ($value as $val) { | |
| $multi_meta[] = array( | |
| 'key' => $meta_key, | |
| 'value' => '"'.$val.'"', | |
| 'compare' => 'LIKE', | |
| ); | |
| } | |
| $meta_query[] = $multi_meta; | |
| } else { | |
| $meta_query[] = array( | |
| 'key' => $meta_key, | |
| 'value' => '"'.$value.'"', | |
| 'compare' => 'LIKE', | |
| ); | |
| } | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| return $meta_query; | |
| } | |
| public static function display_filter_value($key, $value, $filters) { | |
| $url = urldecode(WP_RealEstate_Mixes::get_full_current_url()); | |
| if ( is_array($value) ) { | |
| $value = array_filter( array_map( 'sanitize_title', wp_unslash( $value ) ) ); | |
| } else { | |
| $value = sanitize_text_field( wp_unslash($value) ); | |
| } | |
| switch ($key) { | |
| case 'filter-status': | |
| self::render_filter_tax($key, $value, 'property_status', $url); | |
| break; | |
| case 'filter-location': | |
| self::render_filter_tax($key, $value, 'property_location', $url); | |
| break; | |
| case 'filter-type': | |
| self::render_filter_tax($key, $value, 'property_type', $url); | |
| break; | |
| case 'filter-amenity': | |
| self::render_filter_tax($key, $value, 'property_amenity', $url); | |
| break; | |
| case 'filter-price': | |
| if ( isset($value[0]) && isset($value[1]) ) { | |
| $from = WP_RealEstate_Price::format_price($value[0], true); | |
| $to = WP_RealEstate_Price::format_price($value[1], true); | |
| $rm_url = self::remove_url_var($key . '-from=' . $value[0], $url); | |
| $rm_url = self::remove_url_var($key . '-to=' . $value[1], $rm_url); | |
| self::render_filter_result_item( $from.' - '.$to, $rm_url ); | |
| } | |
| break; | |
| case 'filter-distance': | |
| if ( !empty($filters['filter-center-location']) ) { | |
| $distance_type = apply_filters( 'wp_realestate_filter_distance_type', 'miles' ); | |
| $title = $value.' '.$distance_type; | |
| $rm_url = self::remove_url_var( $key . '=' . $value, $url); | |
| self::render_filter_result_item( $title, $rm_url ); | |
| } | |
| break; | |
| case 'filter-featured': | |
| $title = esc_html__('Featured', 'wp-realestate'); | |
| $rm_url = self::remove_url_var($key . $key . '=' . $value, $url); | |
| self::render_filter_result_item( $title, $rm_url ); | |
| break; | |
| case 'filter-author': | |
| $user_info = get_userdata($value); | |
| if ( is_object($user_info) ) { | |
| $title = $user_info->display_name; | |
| } else { | |
| $title = $value; | |
| } | |
| $rm_url = self::remove_url_var( $key . '=' . $value, $url); | |
| self::render_filter_result_item( $title, $rm_url ); | |
| break; | |
| case 'filter-orderby': | |
| $orderby_options = apply_filters( 'wp-realestate-properties-orderby', array( | |
| 'menu_order' => esc_html__('Default', 'wp-realestate'), | |
| 'newest' => esc_html__('Newest', 'wp-realestate'), | |
| 'oldest' => esc_html__('Oldest', 'wp-realestate'), | |
| 'random' => esc_html__('Random', 'wp-realestate'), | |
| )); | |
| $title = $value; | |
| if ( !empty($orderby_options[$value]) ) { | |
| $title = $orderby_options[$value]; | |
| } | |
| $rm_url = self::remove_url_var( $key . '=' . $value, $url); | |
| self::render_filter_result_item( $title, $rm_url ); | |
| break; | |
| default: | |
| if ( is_array($value) ) { | |
| foreach ($value as $val) { | |
| $rm_url = self::remove_url_var( $key . '[]=' . $val, $url); | |
| self::render_filter_result_item( $val, $rm_url); | |
| } | |
| } else { | |
| $rm_url = self::remove_url_var( $key . '=' . $value, $url); | |
| self::render_filter_result_item( $value, $rm_url); | |
| } | |
| break; | |
| } | |
| } | |
| public static function display_filter_value_simple($key, $value, $filters) { | |
| if ( is_array($value) ) { | |
| $value = array_filter( array_map( 'sanitize_title', wp_unslash( $value ) ) ); | |
| } else { | |
| $value = sanitize_text_field( wp_unslash($value) ); | |
| } | |
| switch ($key) { | |
| case 'filter-status': | |
| self::render_filter_tax_simple($key, $value, 'property_status', esc_html__('Status', 'wp-realestate')); | |
| break; | |
| case 'filter-location': | |
| self::render_filter_tax_simple($key, $value, 'property_location', esc_html__('Location', 'wp-realestate')); | |
| break; | |
| case 'filter-type': | |
| self::render_filter_tax_simple($key, $value, 'property_type', esc_html__('Type', 'wp-realestate')); | |
| break; | |
| case 'filter-amenity': | |
| self::render_filter_tax_simple($key, $value, 'property_amenity', esc_html__('Tag', 'wp-realestate')); | |
| break; | |
| case 'filter-price': | |
| if ( isset($value[0]) && isset($value[1]) ) { | |
| $from = WP_RealEstate_Price::format_price($value[0]); | |
| $to = WP_RealEstate_Price::format_price($value[1]); | |
| self::render_filter_result_item_simple( $from.' - '.$to, esc_html__('Price', 'wp-realestate') ); | |
| } | |
| break; | |
| case 'filter-distance': | |
| if ( !empty($filters['filter-center-location']) ) { | |
| $distance_type = apply_filters( 'wp_realestate_filter_distance_type', 'miles' ); | |
| $title = $value.' '.$distance_type; | |
| self::render_filter_result_item_simple( $title, esc_html__('Distance', 'wp-realestate') ); | |
| } | |
| break; | |
| case 'filter-featured': | |
| $title = esc_html__('Yes', 'wp-realestate'); | |
| self::render_filter_result_item_simple( $title, esc_html__('Featured', 'wp-realestate') ); | |
| break; | |
| case 'filter-author': | |
| $user_info = get_userdata($value); | |
| if ( is_object($user_info) ) { | |
| $title = $user_info->display_name; | |
| } else { | |
| $title = $value; | |
| } | |
| self::render_filter_result_item_simple( $title, esc_html__('Author', 'wp-realestate') ); | |
| break; | |
| case 'filter-orderby': | |
| $orderby_options = apply_filters( 'wp-realestate-properties-orderby', array( | |
| 'menu_order' => esc_html__('Default', 'wp-realestate'), | |
| 'newest' => esc_html__('Newest', 'wp-realestate'), | |
| 'oldest' => esc_html__('Oldest', 'wp-realestate'), | |
| 'random' => esc_html__('Random', 'wp-realestate'), | |
| )); | |
| $title = $value; | |
| if ( !empty($orderby_options[$value]) ) { | |
| $title = $orderby_options[$value]; | |
| } | |
| self::render_filter_result_item_simple( $title, esc_html__('Orderby', 'wp-realestate') ); | |
| break; | |
| default: | |
| $meta_obj = WP_RealEstate_Property_Meta::get_instance(0); | |
| $label_key = str_replace('filter-', '', $key); | |
| $label_key = str_replace('filter-', '', $label_key); | |
| $prefix = ''; | |
| if (preg_match("/-to/i", $key)) { | |
| $prefix = esc_html__('to', 'wp-realestate'); | |
| $label_key = str_replace('-to', '', $label_key); | |
| } elseif (preg_match("/-from/i", $key)) { | |
| $prefix = esc_html__('from', 'wp-realestate'); | |
| $label_key = str_replace('-from', '', $label_key); | |
| } | |
| $label = $meta_obj->get_post_meta_title($label_key); | |
| if ( empty($label) ) { | |
| $label = $label_key; | |
| } | |
| if ( $prefix ) { | |
| $label .= ' '.$prefix; | |
| } | |
| if ( is_array($value) ) { | |
| foreach ($value as $val) { | |
| self::render_filter_result_item_simple( $val, $label); | |
| } | |
| } else { | |
| self::render_filter_result_item_simple( $value, $label); | |
| } | |
| break; | |
| } | |
| } | |
| } | |
| WP_RealEstate_Property_Filter::init();<?php | |
| /** | |
| * Custom Fields | |
| * | |
| * @package wp-realestate | |
| * @author Habq | |
| * @license GNU General Public License, version 3 | |
| */ | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; // Exit if accessed directly | |
| } | |
| class WP_RealEstate_Custom_Fields { | |
| public static function init() { | |
| // submit admin | |
| add_filter( 'wp-realestate-property-fields-admin', array( __CLASS__, 'admin_custom_fields' ), 10 ); | |
| // submit frontend | |
| add_filter( 'wp-realestate-property-fields-front', array( __CLASS__, 'front_custom_fields' ), 100, 2 ); | |
| // filter fields | |
| add_filter( 'wp-realestate-default-property-filter-fields', array( __CLASS__, 'filter_custom_fields' ), 100 ); | |
| // compare fields | |
| add_filter( 'wp-realestate-default-property-compare-fields', array( __CLASS__, 'compare_custom_fields' ), 100 ); | |
| } | |
| public static function filter_custom_fields($old_fields) { | |
| $fields = self::get_search_custom_fields($old_fields, true); | |
| $fields['center-location'] = array( | |
| 'name' => __( 'Location', 'wp-realestate' ), | |
| 'field_call_back' => array( 'WP_RealEstate_Abstract_Filter', 'filter_field_input_location'), | |
| 'placeholder' => __( 'All Location', 'wp-realestate' ), | |
| 'show_distance' => true, | |
| 'toggle' => true, | |
| 'for_post_type' => 'property', | |
| ); | |
| $fields['distance'] = array( | |
| 'name' => __( 'Search Distance', 'wp-realestate' ), | |
| 'field_call_back' => array( 'WP_RealEstate_Abstract_Filter', 'filter_field_input_distance'), | |
| 'placeholder' => __( 'Distance', 'wp-realestate' ), | |
| 'toggle' => true, | |
| 'for_post_type' => 'property', | |
| ); | |
| return apply_filters( 'wp-realestate-types-add_custom_fields', $fields, $old_fields); | |
| } | |
| public static function compare_custom_fields($old_fields) { | |
| $fields = self::get_compare_custom_fields($old_fields, true); | |
| return apply_filters( 'wp-realestate-types-add_custom_fields', $fields, $old_fields); | |
| } | |
| public static function admin_custom_fields() { | |
| $init_fields = self::get_custom_fields(array(), true); | |
| $init_fields = apply_filters( 'wp-realestate-types-admin_custom_fields', $init_fields); | |
| $fields = array(); | |
| $key_tab = 'tab-heading-start'.rand(100,1000); | |
| $tab_data = array( | |
| 'id' => $key_tab, | |
| 'icon' => 'dashicons-admin-home', | |
| 'title' => esc_html__( 'General', 'wp-realestate' ), | |
| 'fields' => array(), | |
| ); | |
| $i = 0; | |
| foreach ($init_fields as $key => $field) { | |
| if ( $i == 0 && (empty($field['type']) || $field['type'] !== 'title') ) { | |
| $fields[$key_tab] = $tab_data; | |
| } elseif ( !empty($field['type']) && $field['type'] == 'title' ) { | |
| $key_tab = $field['id']; | |
| $fields[$key_tab] = array( | |
| 'id' => $key_tab, | |
| 'icon' => !empty($field['icon']) ? $field['icon'] : '', | |
| 'title' => !empty($field['name']) ? $field['name'] : '', | |
| 'fields' => array(), | |
| ); | |
| } | |
| $fields[$key_tab]['fields'][] = $field; | |
| $i++; | |
| } | |
| // author fields | |
| $post_author_id = ''; | |
| if ( !empty($_GET['post']) ) { | |
| $post_author_id = get_post_field( 'post_author', $_GET['post'] ); | |
| } | |
| $author_key = 'tab-heading-author'.rand(100,1000); | |
| $fields[$author_key] = array( | |
| 'id' => $author_key, | |
| 'icon' => 'dashicons-admin-users', | |
| 'title' => esc_html__( 'Author', 'wp-realestate' ), | |
| 'fields' => array( | |
| array( | |
| 'name' => __( 'Author', 'wp-realestate' ), | |
| 'id' => WP_REALESTATE_PROPERTY_PREFIX . 'posted_by', | |
| 'type' => 'user_ajax_search', | |
| 'default' => $post_author_id | |
| ) | |
| ), | |
| ); | |
| $box_options = array( | |
| 'id' => 'property_metabox', | |
| 'title' => esc_html__( 'Property Metabox', 'wp-realestate' ), | |
| 'object_types' => array( 'property' ), | |
| 'show_names' => true, | |
| ); | |
| // Setup meta box | |
| $cmb = new_cmb2_box( $box_options ); | |
| // Set tabs | |
| $cmb->add_field( [ | |
| 'id' => '__tabs', | |
| 'type' => 'tabs', | |
| 'tabs' => array( | |
| 'config' => $box_options, | |
| 'layout' => 'vertical', // Default : horizontal | |
| 'tabs' => apply_filters('wp-realestate-admin-custom-fields', $fields), | |
| ), | |
| ] ); | |
| return true; | |
| } | |
| public static function front_custom_fields($old_fields, $post_id) { | |
| $fields = self::get_custom_fields($old_fields, false, $post_id); | |
| return apply_filters( 'wp-realestate-types-submit_form_fields', $fields, $old_fields, $post_id); | |
| } | |
| public static function get_search_custom_fields($old_fields, $admin_field = true) { | |
| $prefix = WP_REALESTATE_PROPERTY_PREFIX; | |
| $fields = array(); | |
| $custom_all_fields = WP_RealEstate_Fields_Manager::get_custom_fields_data(); | |
| if (is_array($custom_all_fields) && sizeof($custom_all_fields) > 0) { | |
| $dtypes = WP_RealEstate_Fields_Manager::get_all_field_type_keys(); | |
| $available_types = WP_RealEstate_Fields_Manager::get_all_types_fields_available(); | |
| $required_types = WP_RealEstate_Fields_Manager::get_all_types_fields_required(); | |
| $i = 1; | |
| foreach ($custom_all_fields as $key => $custom_field) { | |
| $fieldkey = !empty($custom_field['type']) ? $custom_field['type'] : ''; | |
| if ( !empty($fieldkey) ) { | |
| $type = ''; | |
| $required_values = WP_RealEstate_Fields_Manager::get_field_id($fieldkey, $required_types); | |
| $available_values = WP_RealEstate_Fields_Manager::get_field_id($fieldkey, $available_types); | |
| if ( !empty($required_values) ) { | |
| $field_data = wp_parse_args( $custom_field, $required_values); | |
| $fieldtype = isset($required_values['type']) ? $required_values['type'] : ''; | |
| $fieldtype_type = 'required'; | |
| } elseif ( !empty($available_values) ) { | |
| $field_data = wp_parse_args( $custom_field, $available_values); | |
| $fieldtype = isset($available_values['type']) ? $available_values['type'] : ''; | |
| $fieldtype_type = 'available'; | |
| } elseif ( in_array($fieldkey, $dtypes) ) { | |
| $fieldkey = isset($custom_field['key']) ? $custom_field['key'] : ''; | |
| $fieldtype = isset($custom_field['type']) ? $custom_field['type'] : ''; | |
| $fieldtype_type = 'custom'; | |
| $field_data = $custom_field; | |
| if ( in_array($fieldtype, array('heading', 'file', 'url', 'email')) ) { | |
| continue; | |
| } | |
| } | |
| if ( !in_array($fieldkey, array( $prefix.'heading', $prefix.'featured_image', $prefix.'gallery', $prefix.'description', $prefix.'expiry_date', $prefix.'property_id', $prefix.'price_prefix', $prefix.'price_suffix', $prefix.'price_custom', $prefix.'lot_dimensions', $prefix.'video', $prefix.'virtual_tour', $prefix.'parent_property', $prefix.'floor_plans_group', $prefix.'valuation_group', $prefix.'public_facilities_group', $prefix.'map_location', $prefix.'featured_image', $prefix.'gallery', $prefix.'attachments', $prefix.'address', $prefix.'file' )) ) { | |
| $id = str_replace(WP_REALESTATE_PROPERTY_PREFIX, '', $field_data['id']); | |
| $fields[$id] = self::render_field($field_data, $fieldkey, $fieldtype, $i, $admin_field, $fieldtype_type); | |
| if ( !empty($field_data['field_call_back']) ) { | |
| $fields[$id]['field_call_back'] = $field_data['field_call_back']; | |
| } | |
| } | |
| } | |
| $i++; | |
| } | |
| // echo "<pre>".print_r($fields,1); die; | |
| } else { | |
| $fields = $old_fields; | |
| } | |
| return $fields; | |
| } | |
| public static function get_compare_custom_fields($old_fields, $admin_field = true) { | |
| $prefix = WP_REALESTATE_PROPERTY_PREFIX; | |
| $fields = array(); | |
| $custom_all_fields = WP_RealEstate_Fields_Manager::get_custom_fields_data(); | |
| if (is_array($custom_all_fields) && sizeof($custom_all_fields) > 0) { | |
| $dtypes = WP_RealEstate_Fields_Manager::get_all_field_type_keys(); | |
| $available_types = WP_RealEstate_Fields_Manager::get_all_types_fields_available(); | |
| $required_types = WP_RealEstate_Fields_Manager::get_all_types_fields_required(); | |
| $i = 1; | |
| foreach ($custom_all_fields as $key => $custom_field) { | |
| $fieldkey = !empty($custom_field['type']) ? $custom_field['type'] : ''; | |
| if ( !empty($fieldkey) ) { | |
| $type = ''; | |
| $required_values = WP_RealEstate_Fields_Manager::get_field_id($fieldkey, $required_types); | |
| $available_values = WP_RealEstate_Fields_Manager::get_field_id($fieldkey, $available_types); | |
| $custom_field_type = ''; | |
| if ( !empty($required_values) ) { | |
| $field_data = wp_parse_args( $custom_field, $required_values); | |
| $fieldtype = isset($required_values['type']) ? $required_values['type'] : ''; | |
| if ( empty($field_data['show_compare']) ) { | |
| continue; | |
| } | |
| $custom_field_type = 'required'; | |
| } elseif ( !empty($available_values) ) { | |
| $field_data = wp_parse_args( $custom_field, $available_values); | |
| $fieldtype = isset($available_values['type']) ? $available_values['type'] : ''; | |
| if ( empty($field_data['show_compare']) ) { | |
| continue; | |
| } | |
| $custom_field_type = 'available'; | |
| } elseif ( in_array($fieldkey, $dtypes) ) { | |
| $fieldkey = isset($custom_field['key']) ? $custom_field['key'] : ''; | |
| $fieldtype = isset($custom_field['type']) ? $custom_field['type'] : ''; | |
| $field_data = $custom_field; | |
| if ( in_array($fieldtype, array('heading', 'file', 'url', 'email')) ) { | |
| continue; | |
| } | |
| $custom_field_type = 'custom_field'; | |
| } | |
| $id = str_replace(WP_REALESTATE_PROPERTY_PREFIX, '', $field_data['id']); | |
| $field = self::render_field($field_data, $fieldkey, $fieldtype, $i, $admin_field); | |
| $field['custom_field_type'] = $custom_field_type; | |
| $fields[$id] = $field; | |
| } | |
| $i++; | |
| } | |
| } else { | |
| $fields = $old_fields; | |
| } | |
| //echo "<pre>".print_r($fields,1); die; | |
| return $fields; | |
| } | |
| public static function get_custom_fields($old_fields, $admin_field = true, $post_id = 0) { | |
| $prefix = WP_REALESTATE_PROPERTY_PREFIX; | |
| $fields = array(); | |
| $package_id = 0; | |
| if ( !$admin_field ) { | |
| $package_id = self::get_package_id($post_id); | |
| } | |
| $custom_all_fields = WP_RealEstate_Fields_Manager::get_custom_fields_data(); | |
| if (is_array($custom_all_fields) && sizeof($custom_all_fields) > 0) { | |
| $dtypes = WP_RealEstate_Fields_Manager::get_all_field_type_keys(); | |
| $available_types = WP_RealEstate_Fields_Manager::get_all_types_fields_available(); | |
| $required_types = WP_RealEstate_Fields_Manager::get_all_types_fields_required(); | |
| $i = 1; | |
| foreach ($custom_all_fields as $key => $custom_field) { | |
| $check_package_field = true; | |
| if ( !$admin_field ) { | |
| $check_package_field = self::check_package_field($custom_field, $package_id); | |
| } | |
| $fieldkey = !empty($custom_field['type']) ? $custom_field['type'] : ''; | |
| if ( !empty($fieldkey) && $check_package_field ) { | |
| $type = ''; | |
| $required_values = WP_RealEstate_Fields_Manager::get_field_id($fieldkey, $required_types); | |
| $available_values = WP_RealEstate_Fields_Manager::get_field_id($fieldkey, $available_types); | |
| if ( !empty($required_values) ) { | |
| $field_data = wp_parse_args( $custom_field, $required_values); | |
| $fieldtype = isset($required_values['type']) ? $required_values['type'] : ''; | |
| } elseif ( !empty($available_values) ) { | |
| $field_data = wp_parse_args( $custom_field, $available_values); | |
| $fieldtype = isset($available_values['type']) ? $available_values['type'] : ''; | |
| } elseif ( in_array($fieldkey, $dtypes) ) { | |
| $fieldkey = isset($custom_field['key']) ? $custom_field['key'] : ''; | |
| $fieldtype = isset($custom_field['type']) ? $custom_field['type'] : ''; | |
| $field_data = $custom_field; | |
| } | |
| if ( !$admin_field && (!empty($field_data['show_in_submit_form']) || $fieldtype == 'heading') && $fieldkey !== $prefix.'featured' ) { | |
| $fields[] = self::render_field($field_data, $fieldkey, $fieldtype, $i); | |
| } elseif( $admin_field && (!empty($field_data['show_in_admin_edit']) || $fieldtype == 'heading') && !in_array($fieldkey, array( $prefix.'title', $prefix.'description', $prefix.'status', $prefix.'type', $prefix.'material', $prefix.'amenity', $prefix.'location', $prefix.'label', $prefix.'featured_image' ))) { | |
| $fields[] = self::render_field($field_data, $fieldkey, $fieldtype, $i, $admin_field); | |
| } | |
| } | |
| $i++; | |
| } | |
| } else { | |
| $fields = $old_fields; | |
| } | |
| return $fields; | |
| } | |
| public static function get_package_id($post_id) { | |
| $package_id = apply_filters('wp-realestate-get-listing-package-id', 0, $post_id); | |
| return apply_filters( 'wp-realestate-types-get_package_id', $package_id); | |
| } | |
| public static function check_package_field($field, $package_id) { | |
| $return = false; | |
| if ( empty($package_id) ) { | |
| $return = true; | |
| } | |
| if ( empty($field['show_in_package']) ) { | |
| $return = true; | |
| } | |
| if ( !empty($field['show_in_package']) ) { | |
| $package_display = !empty($field['package_display']) ? $field['package_display'] : array(); | |
| if ( !empty($package_display) && is_array($package_display) && in_array($package_id, $package_display) ) { | |
| $return = true; | |
| } | |
| } | |
| return apply_filters( 'wp-realestate-types-check_package_field', $return, $field, $package_id); | |
| } | |
| public static function render_field($field_data, $fieldkey, $fieldtype, $priority, $admin_field = false, $fieldtype_type = '') { | |
| $name = stripslashes(isset($field_data['name']) ? $field_data['name'] : ''); | |
| $id = isset($field_data['id']) ? $field_data['id'] : ''; | |
| $placeholder = stripslashes(isset($field_data['placeholder']) ? $field_data['placeholder'] : ''); | |
| $description = stripslashes(isset($field_data['description']) ? $field_data['description'] : ''); | |
| $format = isset($field_data['format']) ? $field_data['format'] : ''; | |
| $required = isset($field_data['required']) ? $field_data['required'] : ''; | |
| $default = isset($field_data['default']) ? $field_data['default'] : ''; | |
| $field = array( | |
| 'name' => $name, | |
| 'id' => $id, | |
| 'type' => $fieldtype, | |
| 'priority' => $priority, | |
| 'description' => $description, | |
| 'default' => $default, | |
| 'attributes' => array() | |
| ); | |
| if ( !empty($field_data['attributes']) ) { | |
| $field['attributes'] = $field_data['attributes']; | |
| } | |
| if ( $placeholder ) { | |
| $field['attributes']['placeholder'] = $placeholder; | |
| $field['placeholder'] = $placeholder; | |
| } | |
| if ( $required ) { | |
| $field['attributes']['required'] = 'required'; | |
| $field['label_cb'] = array( 'WP_RealEstate_Mixes', 'required_add_label' ); | |
| } | |
| if ( $fieldtype_type == 'custom' ) { | |
| $field['filter-name-prefix'] = 'filter-cfield'; | |
| } | |
| switch ($fieldtype) { | |
| case 'wysiwyg': | |
| case 'textarea': | |
| if ( $fieldtype_type == 'custom' ) { | |
| $field['field_call_back'] = array( 'WP_RealEstate_Abstract_Filter', 'filter_field_input'); | |
| } | |
| break; | |
| case 'text': | |
| $field['type'] = 'text'; | |
| if ( $fieldtype_type == 'custom' ) { | |
| $field['field_call_back'] = array( 'WP_RealEstate_Abstract_Filter', 'filter_field_input'); | |
| } | |
| break; | |
| case 'number': | |
| $field['type'] = 'text'; | |
| $field['attributes']['type'] = 'number'; | |
| $field['attributes']['min'] = 0; | |
| $field['attributes']['pattern'] = '\d*'; | |
| if ( $fieldtype_type == 'custom' ) { | |
| $field['field_call_back'] = array( 'WP_RealEstate_Abstract_Filter', 'filter_field_input'); | |
| } | |
| break; | |
| case 'url': | |
| $field['type'] = 'text'; | |
| $field['attributes']['type'] = 'url'; | |
| $field['attributes']['pattern'] = 'https?://.+'; | |
| if ( $fieldtype_type == 'custom' ) { | |
| $field['field_call_back'] = array( 'WP_RealEstate_Abstract_Filter', 'filter_field_input'); | |
| } | |
| break; | |
| case 'email': | |
| $field['type'] = 'text'; | |
| $field['attributes']['type'] = 'email'; | |
| $field['attributes']['pattern'] = '[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2, 4}$'; | |
| if ( $fieldtype_type == 'custom' ) { | |
| $field['field_call_back'] = array( 'WP_RealEstate_Abstract_Filter', 'filter_field_input'); | |
| } | |
| break; | |
| case 'date': | |
| $field['type'] = 'text_date'; | |
| if ( $fieldtype_type == 'custom' ) { | |
| $field['field_call_back'] = array( 'WP_RealEstate_Abstract_Filter', 'filter_date_field_input'); | |
| $field['filter-name-prefix'] = 'filter-cfielddate'; | |
| } | |
| $field['date_format'] = 'Y-m-d'; | |
| break; | |
| case 'checkbox': | |
| if ( $fieldtype_type == 'custom' ) { | |
| $field['field_call_back'] = array( 'WP_RealEstate_Abstract_Filter', 'filter_field_checkbox'); | |
| } | |
| break; | |
| case 'radio': | |
| case 'select': | |
| $doptions = !empty($field_data['options']) ? $field_data['options'] : array(); | |
| $options = array(); | |
| if ( !empty($placeholder) ) { | |
| $options = array('' => $placeholder); | |
| } | |
| if ( is_array($doptions) ) { | |
| $options = $doptions; | |
| } elseif ( !empty($doptions) ) { | |
| $doptions = explode("\n", str_replace("\r", "", stripslashes($doptions))); | |
| foreach ($doptions as $val) { | |
| $options[$val] = $val; | |
| } | |
| } | |
| $field['options'] = $options; | |
| if ( $fieldtype == 'select' ) { | |
| $field['type'] = 'pw_select'; | |
| } | |
| if ( $fieldtype_type == 'custom' ) { | |
| $field['field_call_back'] = array( 'WP_RealEstate_Abstract_Filter', 'filter_field_select'); | |
| } | |
| break; | |
| case 'multiselect': | |
| $doptions = !empty($field_data['options']) ? $field_data['options'] : array(); | |
| $options = array(); | |
| if ( !empty($placeholder) ) { | |
| $options = array('' => $placeholder); | |
| } | |
| if ( is_array($doptions) ) { | |
| $options = $doptions; | |
| } elseif ( !empty($doptions) ) { | |
| $doptions = explode("\n", str_replace("\r", "", stripslashes($doptions))); | |
| foreach ($doptions as $val) { | |
| $options[$val] = $val; | |
| } | |
| } | |
| $field['options'] = $options; | |
| $field['type'] = 'pw_multiselect'; | |
| if ( $fieldtype_type == 'custom' ) { | |
| $field['field_call_back'] = array( 'WP_RealEstate_Abstract_Filter', 'filter_field_select'); | |
| } | |
| break; | |
| case 'file': | |
| $allow_types = !empty($field_data['allow_types']) ? $field_data['allow_types'] : array(); | |
| $multiples = !empty($field_data['multiple_files']) ? $field_data['multiple_files'] : false; | |
| $ajax = !empty($field_data['ajax']) ? $field_data['ajax'] : false; | |
| $field['ajax'] = $ajax ? true : (is_user_logged_in() ? true : false); | |
| if ( $multiples ) { | |
| $field['file_limit'] = !empty($field_data['file_limit']) ? $field_data['file_limit'] : 10; | |
| } | |
| if ( !$admin_field ) { | |
| $field['type'] = 'wp_realestate_file'; | |
| $field['file_multiple'] = $multiples ? true : false; | |
| if ( !empty($allow_types) ) { | |
| $allowed_mime_types = array(); | |
| $all_mime_types = get_allowed_mime_types(); | |
| $mime_types = array(); | |
| foreach ($allow_types as $mime_type) { | |
| $tmime = explode('|', $mime_type); | |
| $mime_types = array_merge($mime_types, $tmime); | |
| if ( isset($all_mime_types[$mime_type]) ) { | |
| $allowed_mime_types[] = $all_mime_types[$mime_type]; | |
| } | |
| } | |
| $field['mime_types'] = $mime_types; | |
| $field['allow_mime_types'] = $allowed_mime_types; | |
| } | |
| } else { | |
| if ( !$multiples ) { | |
| $field['type'] = 'file'; | |
| $field['preview_size'] = 'thumbnail'; | |
| } else { | |
| $field['type'] = 'file_list'; | |
| } | |
| if ( !empty($allow_types) ) { | |
| $allowed_mime_types = array(); | |
| $mime_types = get_allowed_mime_types(); | |
| foreach ($allow_types as $mime_type) { | |
| if ( isset($mime_types[$mime_type]) ) { | |
| $allowed_mime_types[$mime_type] = $mime_types[$mime_type]; | |
| } | |
| } | |
| $field['allow_mime_types'] = $allowed_mime_types; | |
| $field['query_args']['type'] = $allowed_mime_types; | |
| } | |
| } | |
| break; | |
| case 'wp_realestate_file': | |
| $allow_types = !empty($field_data['allow_types']) ? $field_data['allow_types'] : array(); | |
| $multiples = !empty($field_data['multiple_files']) ? $field_data['multiple_files'] : false; | |
| $ajax = !empty($field_data['ajax']) ? $field_data['ajax'] : false; | |
| $field['ajax'] = $ajax ? true : false; | |
| if ( $multiples ) { | |
| $field['file_limit'] = !empty($field_data['file_limit']) ? $field_data['file_limit'] : 10; | |
| } | |
| if ( !$admin_field ) { | |
| $field['file_multiple'] = $multiples ? true : false; | |
| if ( !empty($allow_types) ) { | |
| $allowed_mime_types = array(); | |
| $all_mime_types = get_allowed_mime_types(); | |
| $mime_types = array(); | |
| foreach ($allow_types as $mime_type) { | |
| $tmime = explode('|', $mime_type); | |
| $mime_types = array_merge($mime_types, $tmime); | |
| if ( isset($all_mime_types[$mime_type]) ) { | |
| $allowed_mime_types[] = $all_mime_types[$mime_type]; | |
| } | |
| } | |
| $field['mime_types'] = $mime_types; | |
| $field['allow_mime_types'] = $allowed_mime_types; | |
| } | |
| } else { | |
| if ( !$multiples ) { | |
| $field['type'] = 'file'; | |
| $field['preview_size'] = 'thumbnail'; | |
| } else { | |
| $field['type'] = 'file_list'; | |
| } | |
| if ( !empty($allow_types) ) { | |
| $allowed_mime_types = array(); | |
| $mime_types = get_allowed_mime_types(); | |
| foreach ($allow_types as $mime_type) { | |
| if ( isset($mime_types[$mime_type]) ) { | |
| $allowed_mime_types[$mime_type] = $mime_types[$mime_type]; | |
| } | |
| } | |
| $field['allow_mime_types'] = $allowed_mime_types; | |
| $field['query_args']['type'] = $allowed_mime_types; | |
| } | |
| } | |
| break; | |
| case 'heading': | |
| $field['type'] = 'title'; | |
| $field['icon'] = !empty($field_data['icon']) ? $field_data['icon'] : ''; | |
| $field['number_columns'] = !empty($field_data['number_columns']) ? $field_data['number_columns'] : ''; | |
| case 'pw_map': | |
| $field['split_values'] = isset($field_data['split_values']) ? $field_data['split_values'] : false; | |
| case 'repeater': | |
| case 'group': | |
| $subfields = array(); | |
| if ( !empty($field_data['fields']) ) { | |
| foreach ($field_data['fields'] as $subf) { | |
| $subfield = $subf; | |
| if ( !empty($subfield['type']) && $subfield['type'] == 'wp_realestate_file' ) { | |
| if ( $admin_field ) { | |
| $subfield['type'] = 'file'; | |
| $subfield['preview_size'] = 'thumbnail'; | |
| } | |
| $subfields[] = $subfield; | |
| } else { | |
| $subfields[] = $subfield; | |
| } | |
| } | |
| } | |
| $field['fields'] = $subfields; | |
| if ( !empty($field_data['options']) ) { | |
| $field['options'] = $field_data['options']; | |
| } | |
| break; | |
| } | |
| $prefix = WP_REALESTATE_PROPERTY_PREFIX; | |
| switch ($fieldkey) { | |
| case $prefix.'parent_property': | |
| $post__not_in = 0; | |
| if ( $admin_field ) { | |
| if ( !empty($_GET['post']) ) { | |
| $author = get_post_field( 'post_author', $_GET['post'] ); | |
| $post__not_in = $_GET['post']; | |
| } else { | |
| $author = get_current_user_id(); | |
| $post__not_in = 0; | |
| } | |
| } else { | |
| $author = get_current_user_id(); | |
| $post__not_in = !empty( $_REQUEST['property_id'] ) ? absint( $_REQUEST['property_id'] ) : 0; | |
| } | |
| $args = array( | |
| 'fields' => 'ids', | |
| 'author' => $author, | |
| 'post__not_in' => array($post__not_in) | |
| ); | |
| $posts = WP_RealEstate_Query::get_posts($args); | |
| if ( !empty($posts->posts) ) { | |
| $options = array(); | |
| foreach ($posts->posts as $post_id) { | |
| $options[$post_id] = get_post_field('post_title', $post_id); | |
| } | |
| $field['options'] = $options; | |
| } | |
| $field['attributes']['data-allowclear'] = true; | |
| break; | |
| case $prefix.'description': | |
| $field['type'] = !empty($field_data['select_type']) ? $field_data['select_type'] : 'wysiwyg'; | |
| if ( !empty($field_data['options']) ) { | |
| $field['options'] = $field_data['options']; | |
| } | |
| break; | |
| case $prefix.'location': | |
| $field['taxonomy'] = !empty($field_data['taxonomy']) ? $field_data['taxonomy'] : ''; | |
| $location_type = wp_realestate_get_option('location_multiple_fields', 'yes'); | |
| if ( $location_type === 'yes' ) { | |
| $field['type'] = 'wpre_taxonomy_location'; | |
| } else { | |
| $field['type'] = 'pw_taxonomy_select'; | |
| } | |
| // $field['type'] = !empty($field_data['type']) ? $field_data['type'] : 'pw_taxonomy_select'; | |
| break; | |
| case $prefix.'category': | |
| case $prefix.'amenity': | |
| case $prefix.'type': | |
| case $prefix.'status': | |
| case $prefix.'label': | |
| case $prefix.'material': | |
| $field['type'] = !empty($field_data['select_type']) ? $field_data['select_type'] : 'taxonomy_select'; | |
| $field['taxonomy'] = !empty($field_data['taxonomy']) ? $field_data['taxonomy'] : ''; | |
| break; | |
| case $prefix.'expiry_date': | |
| $field['date_format'] = !empty($field_data['date_format']) ? $field_data['date_format'] : 'Y-m-d'; | |
| break; | |
| } | |
| return apply_filters( 'wp-realestate-types-render_field', $field, $field_data, $fieldkey, $fieldtype, $priority); | |
| } | |
| } | |
| WP_RealEstate_Custom_Fields::init();<?php | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; | |
| } | |
| class Homeo_Elementor_RealEstate_Search_Form_Tabs extends Elementor\Widget_Base { | |
| public function get_name() { | |
| return 'apus_element_realestate_search_form_tabs'; | |
| } | |
| public function get_title() { | |
| return esc_html__( 'Apus Properties Search Form Tabs', 'homeo' ); | |
| } | |
| public function get_categories() { | |
| return [ 'homeo-elements' ]; | |
| } | |
| public function get_statues() { | |
| $args = [ | |
| 'taxonomy' => 'property_status', | |
| 'hide_empty' => false, | |
| 'meta_key' => 'menu_order', | |
| 'meta_compare' => 'NUMERIC', | |
| 'orderby' => 'meta_value_num', | |
| 'order' => 'ASC', | |
| ]; | |
| $statuses = get_terms( $args ); | |
| return $statuses; | |
| } | |
| protected function register_controls() { | |
| $columns = array(); | |
| for ($i=1; $i <= 12 ; $i++) { | |
| $columns[$i] = sprintf(esc_html__('%d Columns', 'homeo'), $i); | |
| } | |
| $this->start_controls_section( | |
| 'content_section', | |
| [ | |
| 'label' => esc_html__( 'Search Form: General', 'homeo' ), | |
| 'tab' => Elementor\Controls_Manager::TAB_CONTENT, | |
| ] | |
| ); | |
| $this->add_control( | |
| 'title', | |
| [ | |
| 'label' => esc_html__( 'Title', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'placeholder' => esc_html__( 'Enter your title here', 'homeo' ), | |
| ] | |
| ); | |
| $this->add_control( | |
| 'layout_type', | |
| [ | |
| 'label' => esc_html__( 'Layout Type', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => array( | |
| 'horizontal' => esc_html__('Horizontal', 'homeo'), | |
| 'vertical' => esc_html__('Vertical', 'homeo'), | |
| ), | |
| 'default' => 'horizontal' | |
| ] | |
| ); | |
| $this->add_control( | |
| 'style', | |
| [ | |
| 'label' => esc_html__( 'Style', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => array( | |
| '' => esc_html__('Default', 'homeo'), | |
| 'style1' => esc_html__('Style 1', 'homeo'), | |
| 'style2' => esc_html__('Style 2', 'homeo'), | |
| ), | |
| 'default' => '' | |
| ] | |
| ); | |
| $this->add_control( | |
| 'el_class', | |
| [ | |
| 'label' => esc_html__( 'Extra class name', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'placeholder' => esc_html__( 'If you wish to style particular content element differently, please add a class name to this field and refer to it in your custom CSS file.', 'homeo' ), | |
| ] | |
| ); | |
| $this->end_controls_section(); | |
| // tabs | |
| $fields = apply_filters( 'wp-realestate-default-property-filter-fields', array() ); | |
| $search_fields = array( '' => esc_html__('Choose a field', 'homeo') ); | |
| foreach ($fields as $key => $field) { | |
| if ( $key !== 'status' ) { | |
| $name = $field['name']; | |
| if ( empty($field['name']) ) { | |
| $name = $key; | |
| } | |
| $search_fields[$key] = $name; | |
| } | |
| } | |
| // repeater | |
| $repeater = new Elementor\Repeater(); | |
| $repeater->add_control( | |
| 'filter_field', | |
| [ | |
| 'label' => esc_html__( 'Filter field', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => $search_fields | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'placeholder', | |
| [ | |
| 'label' => esc_html__( 'Placeholder', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'enable_autocompleate_search', | |
| [ | |
| 'label' => esc_html__( 'Enable autocompleate search', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SWITCHER, | |
| 'default' => '', | |
| 'label_on' => esc_html__( 'Yes', 'homeo' ), | |
| 'label_off' => esc_html__( 'No', 'homeo' ), | |
| 'condition' => [ | |
| 'filter_field' => 'title', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'style', | |
| [ | |
| 'label' => esc_html__( 'Price Style', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => [ | |
| 'slider' => esc_html__('Price Slider', 'homeo'), | |
| 'text' => esc_html__('Pice Min/max Input Text', 'homeo'), | |
| 'list' => esc_html__('Price List', 'homeo'), | |
| ], | |
| 'default' => 'slider', | |
| 'condition' => [ | |
| 'filter_field' => 'price', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'price_range_size', | |
| [ | |
| 'label' => esc_html__( 'Price range size', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::NUMBER, | |
| 'input_type' => 'text', | |
| 'default' => 1000, | |
| 'condition' => [ | |
| 'filter_field' => 'price', | |
| 'style' => 'list', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'price_range_max', | |
| [ | |
| 'label' => esc_html__( 'Max price ranges', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::NUMBER, | |
| 'input_type' => 'text', | |
| 'default' => 10, | |
| 'condition' => [ | |
| 'filter_field' => 'price', | |
| 'style' => 'list', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'min_price_placeholder', | |
| [ | |
| 'label' => esc_html__( 'Min Price Placeholder', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'default' => 'Min Price', | |
| 'condition' => [ | |
| 'filter_field' => 'price', | |
| 'style' => 'text', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'max_price_placeholder', | |
| [ | |
| 'label' => esc_html__( 'Max Price Placeholder', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'default' => 'Max Price', | |
| 'condition' => [ | |
| 'filter_field' => 'price', | |
| 'style' => 'text', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'slider_style', | |
| [ | |
| 'label' => esc_html__( 'Layout Style', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => [ | |
| 'slider' => esc_html__('Slider', 'homeo'), | |
| 'text' => esc_html__('Input Text', 'homeo'), | |
| ], | |
| 'default' => 'slider', | |
| 'condition' => [ | |
| 'filter_field' => ['home_area', 'lot_area', 'year_built'], | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'min_placeholder', | |
| [ | |
| 'label' => esc_html__( 'Min Placeholder', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'default' => 'Min', | |
| 'condition' => [ | |
| 'filter_field' => ['home_area', 'lot_area', 'year_built'], | |
| 'slider_style' => 'text', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'max_placeholder', | |
| [ | |
| 'label' => esc_html__( 'Max Placeholder', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'default' => 'Max', | |
| 'condition' => [ | |
| 'filter_field' => ['home_area', 'lot_area', 'year_built'], | |
| 'slider_style' => 'text', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'number_style', | |
| [ | |
| 'label' => esc_html__( 'Layout', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => [ | |
| 'number-plus' => esc_html__('Number +', 'homeo'), | |
| 'number' => esc_html__('Number', 'homeo'), | |
| ], | |
| 'default' => 'number-plus', | |
| 'condition' => [ | |
| 'filter_field' => ['baths', 'beds', 'rooms', 'garages'], | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'min_number', | |
| [ | |
| 'label' => esc_html__( 'Min Number', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::NUMBER, | |
| 'input_type' => 'text', | |
| 'default' => 1, | |
| 'condition' => [ | |
| 'filter_field' => ['baths', 'beds', 'rooms', 'garages'], | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'max_number', | |
| [ | |
| 'label' => esc_html__( 'Max Number', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::NUMBER, | |
| 'input_type' => 'text', | |
| 'default' => 5, | |
| 'condition' => [ | |
| 'filter_field' => ['baths', 'beds', 'rooms', 'garages'], | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'columns', | |
| [ | |
| 'label' => esc_html__( 'Columns', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => $columns, | |
| 'default' => 1 | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'icon', | |
| [ | |
| 'label' => esc_html__( 'Icon', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::ICON | |
| ] | |
| ); | |
| // form fields | |
| $statuses = $this->get_statues(); | |
| if ( !empty($statuses) ) { | |
| $i = 0; | |
| foreach ($statuses as $term) { | |
| $this->start_controls_section( | |
| 'content_'.$i.'_section', | |
| [ | |
| 'label' => esc_html__( 'Tab: ', 'homeo' ).$term->name, | |
| 'tab' => Elementor\Controls_Manager::TAB_CONTENT, | |
| ] | |
| ); | |
| $this->add_control( | |
| 'show_this_tab_'.$i, | |
| [ | |
| 'label' => esc_html__( 'Show this tab', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SWITCHER, | |
| 'default' => 'yes', | |
| 'label_on' => esc_html__( 'Yes', 'homeo' ), | |
| 'label_off' => esc_html__( 'No', 'homeo' ), | |
| ] | |
| ); | |
| $this->add_control( | |
| 'title_'.$i, | |
| [ | |
| 'label' => esc_html__( 'Tab Title', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'placeholder' => esc_html__( 'Enter your title here', 'homeo' ), | |
| ] | |
| ); | |
| $this->add_control( | |
| 'main_search_fields_'.$i, | |
| [ | |
| 'label' => esc_html__( 'Main Search Fields', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::REPEATER, | |
| 'fields' => $repeater->get_controls(), | |
| ] | |
| ); | |
| $this->add_control( | |
| 'show_advance_search_'.$i, | |
| [ | |
| 'label' => esc_html__( 'Show Advanced Search', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SWITCHER, | |
| 'label_on' => esc_html__( 'Show', 'homeo' ), | |
| 'label_off' => esc_html__( 'Hide', 'homeo' ), | |
| 'return_value' => true, | |
| 'default' => true, | |
| ] | |
| ); | |
| $this->add_control( | |
| 'advance_search_fields_'.$i, | |
| [ | |
| 'label' => esc_html__( 'Advanced Search Fields', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::REPEATER, | |
| 'fields' => $repeater->get_controls(), | |
| ] | |
| ); | |
| $this->add_control( | |
| 'filter_btn_text_'.$i, | |
| [ | |
| 'label' => esc_html__( 'Button Text', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'default' => 'Find Property', | |
| ] | |
| ); | |
| $this->add_control( | |
| 'advanced_btn_text_'.$i, | |
| [ | |
| 'label' => esc_html__( 'Advanced Text', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'default' => 'Advanced', | |
| ] | |
| ); | |
| $this->add_control( | |
| 'btn_columns_'.$i, | |
| [ | |
| 'label' => esc_html__( 'Button Columns', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => $columns, | |
| 'default' => 1 | |
| ] | |
| ); | |
| $this->end_controls_section(); | |
| $i++; | |
| } | |
| } | |
| // star tab style | |
| $this->start_controls_section( | |
| 'section_tab_style', | |
| [ | |
| 'label' => esc_html__( 'Tab', 'homeo' ), | |
| 'tab' => Elementor\Controls_Manager::TAB_STYLE, | |
| ] | |
| ); | |
| $this->add_control( | |
| 'tab_active_color', | |
| [ | |
| 'label' => esc_html__( 'Tab Active BG Color', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::COLOR, | |
| 'selectors' => [ | |
| // Stronger selector to avoid section style from overwriting | |
| '{{WRAPPER}} .nav-tabs > li.active > a' => 'background-color: {{VALUE}};', | |
| '{{WRAPPER}} .nav-tabs > li.active > a:before' => 'border-color: {{VALUE}} transparent transparent;', | |
| ], | |
| ] | |
| ); | |
| $this->add_control( | |
| 'margin', | |
| [ | |
| 'label' => esc_html__( 'Margin', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::DIMENSIONS, | |
| 'size_units' => [ 'px', '%', 'em' ], | |
| 'selectors' => [ | |
| '{{WRAPPER}} .nav-tabs' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', | |
| ], | |
| ] | |
| ); | |
| $this->add_responsive_control( | |
| 'alignment', | |
| [ | |
| 'label' => esc_html__( 'Alignment', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::CHOOSE, | |
| 'options' => [ | |
| 'left' => [ | |
| 'title' => esc_html__( 'Left', 'homeo' ), | |
| 'icon' => 'fa fa-align-left', | |
| ], | |
| 'center' => [ | |
| 'title' => esc_html__( 'Center', 'homeo' ), | |
| 'icon' => 'fa fa-align-center', | |
| ], | |
| 'right' => [ | |
| 'title' => esc_html__( 'Right', 'homeo' ), | |
| 'icon' => 'fa fa-align-right', | |
| ], | |
| 'justify' => [ | |
| 'title' => esc_html__( 'Justified', 'homeo' ), | |
| 'icon' => 'fa fa-align-justify', | |
| ], | |
| ], | |
| 'default' => '', | |
| 'selectors' => [ | |
| '{{WRAPPER}} .nav-tabs' => 'text-align: {{VALUE}};', | |
| ], | |
| ] | |
| ); | |
| $this->end_controls_section(); | |
| // end tab style | |
| $this->start_controls_section( | |
| 'section_button_style', | |
| [ | |
| 'label' => esc_html__( 'Button', 'homeo' ), | |
| 'tab' => Elementor\Controls_Manager::TAB_STYLE, | |
| ] | |
| ); | |
| $this->start_controls_tabs( 'tabs_button_style' ); | |
| $this->start_controls_tab( | |
| 'tab_button_normal', | |
| [ | |
| 'label' => esc_html__( 'Normal', 'homeo' ), | |
| ] | |
| ); | |
| $this->add_control( | |
| 'button_color', | |
| [ | |
| 'label' => esc_html__( 'Button Color', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::COLOR, | |
| 'selectors' => [ | |
| '{{WRAPPER}} .btn-submit' => 'color: {{VALUE}};', | |
| ], | |
| ] | |
| ); | |
| $this->add_group_control( | |
| Elementor\Group_Control_Background::get_type(), | |
| [ | |
| 'name' => 'background_button', | |
| 'label' => esc_html__( 'Background', 'homeo' ), | |
| 'types' => [ 'classic', 'gradient', 'video' ], | |
| 'selector' => '{{WRAPPER}} .btn-submit', | |
| ] | |
| ); | |
| $this->add_group_control( | |
| Elementor\Group_Control_Border::get_type(), | |
| [ | |
| 'name' => 'border_button', | |
| 'label' => esc_html__( 'Border', 'homeo' ), | |
| 'selector' => '{{WRAPPER}} .btn-submit', | |
| ] | |
| ); | |
| $this->add_control( | |
| 'padding_button', | |
| [ | |
| 'label' => esc_html__( 'Padding', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::DIMENSIONS, | |
| 'size_units' => [ 'px', '%', 'em' ], | |
| 'selectors' => [ | |
| '{{WRAPPER}} .btn-submit' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', | |
| ], | |
| ] | |
| ); | |
| $this->end_controls_tab(); | |
| // tab hover | |
| $this->start_controls_tab( | |
| 'tab_button_hover', | |
| [ | |
| 'label' => esc_html__( 'Hover', 'homeo' ), | |
| ] | |
| ); | |
| $this->add_control( | |
| 'button_hover_color', | |
| [ | |
| 'label' => esc_html__( 'Button Color', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::COLOR, | |
| 'selectors' => [ | |
| '{{WRAPPER}} .btn-submit:hover, {{WRAPPER}} .btn-submit:focus' => 'color: {{VALUE}};', | |
| ], | |
| ] | |
| ); | |
| $this->add_group_control( | |
| Elementor\Group_Control_Background::get_type(), | |
| [ | |
| 'name' => 'background_button_hover', | |
| 'label' => esc_html__( 'Background', 'homeo' ), | |
| 'types' => [ 'classic', 'gradient', 'video' ], | |
| 'selector' => '{{WRAPPER}} .btn-submit:hover, {{WRAPPER}} .btn-submit:focus', | |
| ] | |
| ); | |
| $this->add_control( | |
| 'button_hover_border_color', | |
| [ | |
| 'label' => esc_html__( 'Border Color', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::COLOR, | |
| 'condition' => [ | |
| 'border_button_border!' => '', | |
| ], | |
| 'selectors' => [ | |
| '{{WRAPPER}} .btn-submit:hover, {{WRAPPER}} .btn-submit:focus' => 'border-color: {{VALUE}};', | |
| ], | |
| ] | |
| ); | |
| $this->add_control( | |
| 'padding_button_hover', | |
| [ | |
| 'label' => esc_html__( 'Padding', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::DIMENSIONS, | |
| 'size_units' => [ 'px', '%', 'em' ], | |
| 'selectors' => [ | |
| '{{WRAPPER}} .btn-submit:hover, {{WRAPPER}} .btn-submit:focus' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', | |
| ], | |
| ] | |
| ); | |
| $this->end_controls_tab(); | |
| $this->end_controls_tabs(); | |
| // end tab | |
| $this->end_controls_section(); | |
| $this->start_controls_section( | |
| 'section_border_style', | |
| [ | |
| 'label' => esc_html__( 'Border', 'homeo' ), | |
| 'tab' => Elementor\Controls_Manager::TAB_STYLE, | |
| ] | |
| ); | |
| $this->add_group_control( | |
| Elementor\Group_Control_Box_Shadow::get_type(), | |
| [ | |
| 'name' => 'box_shadow', | |
| 'label' => esc_html__( 'Box Shadow', 'homeo' ), | |
| 'selector' => '{{WRAPPER}} .content-main-inner', | |
| ] | |
| ); | |
| $this->end_controls_section(); | |
| $this->start_controls_section( | |
| 'section_typography_style', | |
| [ | |
| 'label' => esc_html__( 'Typography', 'homeo' ), | |
| 'tab' => Elementor\Controls_Manager::TAB_STYLE, | |
| ] | |
| ); | |
| $this->add_control( | |
| 'text_color', | |
| [ | |
| 'label' => esc_html__( 'Text Color', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::COLOR, | |
| 'selectors' => [ | |
| '{{WRAPPER}} .form-search' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .advance-search-btn' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .circle-check' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .form-control' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .form-control::-webkit-input-placeholder' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .form-control:-ms-input-placeholder ' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .form-control::placeholder ' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .select2-selection--single .select2-selection__rendered' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .select2-selection--single .select2-selection__placeholder' => 'color: {{VALUE}};', | |
| ], | |
| ] | |
| ); | |
| $this->end_controls_section(); | |
| } | |
| protected function render() { | |
| $settings = $this->get_settings(); | |
| extract( $settings ); | |
| $search_page_url = WP_RealEstate_Mixes::get_properties_page_url(); | |
| homeo_load_select2(); | |
| $_id = homeo_random_key(); | |
| ?> | |
| <div class="widget-property-search-form <?php echo esc_attr($el_class); ?> <?php echo esc_attr($layout_type.' '.$style); ?>"> | |
| <?php if ( $title ) { ?> | |
| <h2 class="title"><?php echo esc_html($title); ?></h2> | |
| <?php } ?> | |
| <?php | |
| $statuses = $this->get_statues(); | |
| if ( !empty($statuses) ) { | |
| ?> | |
| <ul role="tablist" class="nav nav-tabs"> | |
| <?php $i = $j = 0; foreach ($statuses as $term) : | |
| if ( empty($settings['show_this_tab_'.$i]) || !$settings['show_this_tab_'.$i] ) { | |
| $i++; | |
| continue; | |
| } | |
| ?> | |
| <li class="<?php echo esc_attr($j == 0 ? 'active' : '');?>"> | |
| <a href="#tab-<?php echo esc_attr($_id);?>-<?php echo esc_attr($j); ?>" data-toggle="tab"> | |
| <?php | |
| $tab_title = !empty($settings['title_'.$i]) ? $settings['title_'.$i] : $term->name; | |
| echo trim($tab_title); | |
| ?> | |
| </a> | |
| </li> | |
| <?php $i++; $j++; endforeach; ?> | |
| </ul> | |
| <div class="tab-content"> | |
| <?php | |
| $filter_fields = apply_filters( 'wp-realestate-default-property-filter-fields', array() ); | |
| $instance = array(); | |
| $i = $j = 0; | |
| foreach ($statuses as $term) { | |
| if ( empty($settings['show_this_tab_'.$i]) || !$settings['show_this_tab_'.$i] ) { | |
| $i++; | |
| continue; | |
| } | |
| $widget_id = homeo_random_key(); | |
| $args = array( 'widget_id' => $widget_id ); | |
| $main_search_fields = !empty($settings['main_search_fields_'.$i]) ? $settings['main_search_fields_'.$i] : ''; | |
| $advance_search_fields = !empty($settings['advance_search_fields_'.$i]) ? $settings['advance_search_fields_'.$i] : ''; | |
| $show_advance_search = !empty($settings['show_advance_search_'.$i]) ? $settings['show_advance_search_'.$i] : false; | |
| $btn_columns = !empty($settings['btn_columns_'.$i]) ? $settings['btn_columns_'.$i] : 1; | |
| $filter_btn_text = !empty($settings['filter_btn_text_'.$i]) ? $settings['filter_btn_text_'.$i] : ''; | |
| $advanced_btn_text = !empty($settings['advanced_btn_text_'.$i]) ? $settings['advanced_btn_text_'.$i] : ''; | |
| ?> | |
| <div id="tab-<?php echo esc_attr($_id);?>-<?php echo esc_attr($j); ?>" class="tab-pane fade <?php echo esc_attr($j == 0 ? 'active in' : ''); ?>"> | |
| <form action="<?php echo esc_url($search_page_url); ?>" class="form-search filter-listing-form <?php echo esc_attr($style); ?>" method="GET"> | |
| <?php if ( ! get_option('permalink_structure') ) { | |
| $properties_page_id = wp_realestate_get_option('properties_page_id'); | |
| $properties_page_id = WP_RealEstate_Mixes::get_lang_post_id( $properties_page_id, 'page'); | |
| if ( !empty($properties_page_id) ) { | |
| echo '<input type="hidden" name="p" value="' . $properties_page_id . '">'; | |
| } | |
| } ?> | |
| <input type="hidden" name="filter-status" value="<?php echo esc_attr($term->term_id); ?>"> | |
| <div class="search-form-inner"> | |
| <?php if ( $layout_type == 'horizontal' ) { ?> | |
| <div class="main-inner clearfix"> | |
| <div class="content-main-inner"> | |
| <div class="row row-20"> | |
| <?php | |
| if ( !empty($main_search_fields) ) { | |
| foreach ($main_search_fields as $item) { | |
| if ( empty($filter_fields[$item['filter_field']]['field_call_back']) ) { | |
| continue; | |
| } | |
| $filter_field = $filter_fields[$item['filter_field']]; | |
| if ( $item['filter_field'] == 'title' ) { | |
| if ($item['enable_autocompleate_search']) { | |
| wp_enqueue_script( 'handlebars', get_template_directory_uri() . '/js/handlebars.min.js', array(), null, true); | |
| wp_enqueue_script( 'typeahead-jquery', get_template_directory_uri() . '/js/typeahead.bundle.min.js', array('jquery', 'handlebars'), null, true); | |
| $filter_field['add_class'] = 'apus-autocompleate-input'; | |
| } | |
| } elseif ( $item['filter_field'] == 'price' ) { | |
| $filter_field['style'] = $item['style']; | |
| $filter_field['min_price_placeholder'] = $item['min_price_placeholder']; | |
| $filter_field['max_price_placeholder'] = $item['max_price_placeholder']; | |
| $filter_field['price_range_size'] = $item['price_range_size']; | |
| $filter_field['price_range_max'] = $item['price_range_max']; | |
| } elseif ( in_array($item['filter_field'], ['baths', 'beds', 'rooms', 'garages']) ) { | |
| $filter_field['number_style'] = $item['number_style']; | |
| $filter_field['min_number'] = $item['min_number']; | |
| $filter_field['max_number'] = $item['max_number']; | |
| } elseif ( in_array($item['filter_field'], ['home_area', 'lot_area', 'year_built']) ) { | |
| $filter_field['slider_style'] = $item['slider_style']; | |
| $filter_field['min_placeholder'] = $item['min_placeholder']; | |
| $filter_field['max_placeholder'] = $item['max_placeholder']; | |
| } | |
| if ( isset($item['icon']) ) { | |
| $filter_field['icon'] = $item['icon']; | |
| } | |
| if ( isset($item['placeholder']) ) { | |
| $filter_field['placeholder'] = $item['placeholder']; | |
| } | |
| $filter_field['show_title'] = false; | |
| $columns = !empty($item['columns']) ? $item['columns'] : '1'; | |
| ?> | |
| <div class="col-xs-12 col-md-<?php echo esc_attr($columns); ?>"> | |
| <?php call_user_func( $filter_field['field_call_back'], $instance, $args, $item['filter_field'], $filter_field ); ?> | |
| </div> | |
| <?php | |
| } | |
| } | |
| ?> | |
| <div class="col-xs-12 col-md-<?php echo esc_attr($btn_columns); ?> form-group form-group-search"> | |
| <div class="flex-middle justify-content-end-lg"> | |
| <?php if ( $show_advance_search && !empty($advance_search_fields) ) { ?> | |
| <div class="advance-link"> | |
| <a href="javascript:void(0);" class="advance-search-btn"> | |
| <?php | |
| if ( !empty($advanced_btn_text) ) { | |
| echo esc_html($advanced_btn_text); | |
| } else { | |
| esc_html_e('Advanced', 'homeo'); | |
| } | |
| ?> | |
| <i class="flaticon-more"></i> | |
| </a> | |
| </div> | |
| <?php } ?> | |
| <button class="btn-submit btn btn-theme btn-inverse" type="submit"> | |
| <?php echo trim($filter_btn_text); ?> | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <?php | |
| if ( $show_advance_search && !empty($advance_search_fields) ) { | |
| ?> | |
| <div class="advance-search-wrapper"> | |
| <div class="advance-search-wrapper-fields"> | |
| <div class="row row-20"> | |
| <?php | |
| $sub_class = ''; | |
| foreach ($advance_search_fields as $item) { | |
| if ( empty($filter_fields[$item['filter_field']]['field_call_back']) ) { | |
| continue; | |
| } | |
| $filter_field = $filter_fields[$item['filter_field']]; | |
| if ( isset($item['placeholder']) ) { | |
| $filter_field['placeholder'] = $item['placeholder']; | |
| } | |
| if ( isset($item['icon']) ) { | |
| $filter_field['icon'] = $item['icon']; | |
| } | |
| if($item['filter_field'] == 'amenity'){ | |
| $sub_class = 'wrapper-amenity'; | |
| $filter_field['show_title'] = true; | |
| }else{ | |
| $filter_field['show_title'] = false; | |
| $sub_class = ''; | |
| } | |
| if ( $item['filter_field'] == 'price' ) { | |
| $filter_field['style'] = $item['style']; | |
| $filter_field['min_price_placeholder'] = $item['min_price_placeholder']; | |
| $filter_field['max_price_placeholder'] = $item['max_price_placeholder']; | |
| $filter_field['price_range_size'] = $item['price_range_size']; | |
| $filter_field['price_range_max'] = $item['price_range_max']; | |
| } elseif ( in_array($item['filter_field'], ['baths', 'beds', 'rooms', 'garages']) ) { | |
| $filter_field['number_style'] = $item['number_style']; | |
| $filter_field['min_number'] = $item['min_number']; | |
| $filter_field['max_number'] = $item['max_number']; | |
| } elseif ( in_array($item['filter_field'], ['home_area', 'lot_area', 'year_built']) ) { | |
| $filter_field['slider_style'] = $item['slider_style']; | |
| $filter_field['min_placeholder'] = $item['min_placeholder']; | |
| $filter_field['max_placeholder'] = $item['max_placeholder']; | |
| } | |
| $columns = !empty($item['columns']) ? $item['columns'] : '1'; | |
| ?> | |
| <div class="col-xs-12 col-md-<?php echo esc_attr($columns.' '.$sub_class); ?>"> | |
| <?php call_user_func( $filter_field['field_call_back'], $instance, $args, $item['filter_field'], $filter_field ); ?> | |
| </div> | |
| <?php | |
| } | |
| ?> | |
| </div> | |
| </div> | |
| </div> | |
| <?php | |
| } | |
| ?> | |
| <?php } else { ?> | |
| <div class="main-inner clearfix"> | |
| <div class="content-main-inner"> | |
| <div class="row"> | |
| <?php | |
| if ( !empty($main_search_fields) ) { | |
| foreach ($main_search_fields as $item) { | |
| if ( empty($filter_fields[$item['filter_field']]['field_call_back']) ) { | |
| continue; | |
| } | |
| $filter_field = $filter_fields[$item['filter_field']]; | |
| if ( $item['filter_field'] == 'title' ) { | |
| if ($item['enable_autocompleate_search']) { | |
| wp_enqueue_script( 'handlebars', get_template_directory_uri() . '/js/handlebars.min.js', array(), null, true); | |
| wp_enqueue_script( 'typeahead-jquery', get_template_directory_uri() . '/js/typeahead.bundle.min.js', array('jquery', 'handlebars'), null, true); | |
| $filter_field['add_class'] = 'apus-autocompleate-input'; | |
| } | |
| } elseif ( $item['filter_field'] == 'price' ) { | |
| $filter_field['style'] = $item['style']; | |
| $filter_field['min_price_placeholder'] = $item['min_price_placeholder']; | |
| $filter_field['max_price_placeholder'] = $item['max_price_placeholder']; | |
| $filter_field['price_range_size'] = $item['price_range_size']; | |
| $filter_field['price_range_max'] = $item['price_range_max']; | |
| } elseif ( in_array($item['filter_field'], ['baths', 'beds', 'rooms', 'garages']) ) { | |
| $filter_field['number_style'] = $item['number_style']; | |
| $filter_field['min_number'] = $item['min_number']; | |
| $filter_field['max_number'] = $item['max_number']; | |
| } elseif ( in_array($item['filter_field'], ['home_area', 'lot_area', 'year_built']) ) { | |
| $filter_field['slider_style'] = $item['slider_style']; | |
| $filter_field['min_placeholder'] = $item['min_placeholder']; | |
| $filter_field['max_placeholder'] = $item['max_placeholder']; | |
| } | |
| if ( isset($item['icon']) ) { | |
| $filter_field['icon'] = $item['icon']; | |
| } | |
| if ( isset($item['placeholder']) ) { | |
| $filter_field['placeholder'] = $item['placeholder']; | |
| } | |
| $filter_field['show_title'] = false; | |
| $columns = !empty($item['columns']) ? $item['columns'] : '1'; | |
| ?> | |
| <div class="col-xs-12 col-md-<?php echo esc_attr($columns); ?>"> | |
| <?php call_user_func( $filter_field['field_call_back'], $instance, $args, $item['filter_field'], $filter_field ); ?> | |
| </div> | |
| <?php | |
| } | |
| } | |
| ?> | |
| <?php if ( $show_advance_search && !empty($advance_search_fields)) { ?> | |
| <div class="col-xs-12"> | |
| <div class="form-group"> | |
| <div class="advance-link"> | |
| <a href="javascript:void(0);" class="advance-search-btn"> | |
| <?php | |
| if ( !empty($advanced_btn_text) ) { | |
| echo esc_html($advanced_btn_text); | |
| } else { | |
| esc_html_e('Advanced', 'homeo'); | |
| } | |
| ?> | |
| <i class="flaticon-more"></i> | |
| </a> | |
| </div> | |
| </div> | |
| </div> | |
| <?php } ?> | |
| </div> | |
| <div class="row"> | |
| <div class="col-xs-12 col-md-<?php echo esc_attr($btn_columns); ?> form-group-search"> | |
| <button class="btn-submit btn-block btn btn-theme btn-inverse" type="submit"> | |
| <?php echo trim($filter_btn_text); ?> | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <?php | |
| if ( $show_advance_search && !empty($advance_search_fields) ) { | |
| ?> | |
| <div class="advance-search-wrapper"> | |
| <div class="advance-search-wrapper-fields"> | |
| <div class="row"> | |
| <?php | |
| foreach ($advance_search_fields as $item) { | |
| if ( empty($filter_fields[$item['filter_field']]['field_call_back']) ) { | |
| continue; | |
| } | |
| $filter_field = $filter_fields[$item['filter_field']]; | |
| if ( isset($item['placeholder']) ) { | |
| $filter_field['placeholder'] = $item['placeholder']; | |
| } | |
| if ( isset($item['icon']) ) { | |
| $filter_field['icon'] = $item['icon']; | |
| } | |
| $filter_field['show_title'] = false; | |
| $columns = !empty($item['columns']) ? $item['columns'] : '1'; | |
| if ( $item['filter_field'] == 'price' ) { | |
| $filter_field['style'] = $item['style']; | |
| $filter_field['min_price_placeholder'] = $item['min_price_placeholder']; | |
| $filter_field['max_price_placeholder'] = $item['max_price_placeholder']; | |
| $filter_field['price_range_size'] = $item['price_range_size']; | |
| $filter_field['price_range_max'] = $item['price_range_max']; | |
| } elseif ( in_array($item['filter_field'], ['baths', 'beds', 'rooms', 'garages']) ) { | |
| $filter_field['number_style'] = $item['number_style']; | |
| $filter_field['min_number'] = $item['min_number']; | |
| $filter_field['max_number'] = $item['max_number']; | |
| } elseif ( in_array($item['filter_field'], ['home_area', 'lot_area', 'year_built']) ) { | |
| $filter_field['slider_style'] = $item['slider_style']; | |
| $filter_field['min_placeholder'] = $item['min_placeholder']; | |
| $filter_field['max_placeholder'] = $item['max_placeholder']; | |
| } | |
| ?> | |
| <div class="col-xs-12 col-md-<?php echo esc_attr($columns); ?>"> | |
| <?php call_user_func( $filter_field['field_call_back'], $instance, $args, $item['filter_field'], $filter_field ); ?> | |
| </div> | |
| <?php | |
| } | |
| ?> | |
| </div> | |
| </div> | |
| </div> | |
| <?php | |
| } | |
| ?> | |
| <?php } ?> | |
| </div> | |
| </form> | |
| </div> | |
| <?php | |
| $j++; $i++; | |
| } | |
| ?> | |
| </div> | |
| <?php } ?> | |
| </div> | |
| <?php | |
| } | |
| } | |
| if ( version_compare(ELEMENTOR_VERSION, '3.5.0', '<') ) { | |
| Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Homeo_Elementor_RealEstate_Search_Form_Tabs ); | |
| } else { | |
| Elementor\Plugin::instance()->widgets_manager->register( new Homeo_Elementor_RealEstate_Search_Form_Tabs ); | |
| }<?php | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; | |
| } | |
| class Homeo_Elementor_RealEstate_Search_Form extends Elementor\Widget_Base { | |
| public function get_name() { | |
| return 'apus_element_realestate_search_form'; | |
| } | |
| public function get_title() { | |
| return esc_html__( 'Apus Properties Search Form', 'homeo' ); | |
| } | |
| public function get_categories() { | |
| return [ 'homeo-elements' ]; | |
| } | |
| protected function register_controls() { | |
| $this->start_controls_section( | |
| 'content_section', | |
| [ | |
| 'label' => esc_html__( 'Search Form', 'homeo' ), | |
| 'tab' => Elementor\Controls_Manager::TAB_CONTENT, | |
| ] | |
| ); | |
| $this->add_control( | |
| 'title', | |
| [ | |
| 'label' => esc_html__( 'Title', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'placeholder' => esc_html__( 'Enter your title here', 'homeo' ), | |
| ] | |
| ); | |
| $fields = apply_filters( 'wp-realestate-default-property-filter-fields', array() ); | |
| $search_fields = array( '' => esc_html__('Choose a field', 'homeo') ); | |
| foreach ($fields as $key => $field) { | |
| $name = $field['name']; | |
| if ( empty($field['name']) ) { | |
| $name = $key; | |
| } | |
| $search_fields[$key] = $name; | |
| } | |
| $repeater = new Elementor\Repeater(); | |
| $repeater->add_control( | |
| 'filter_field', | |
| [ | |
| 'label' => esc_html__( 'Filter field', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => $search_fields | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'placeholder', | |
| [ | |
| 'label' => esc_html__( 'Placeholder', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'enable_autocompleate_search', | |
| [ | |
| 'label' => esc_html__( 'Enable autocompleate search', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SWITCHER, | |
| 'default' => '', | |
| 'label_on' => esc_html__( 'Yes', 'homeo' ), | |
| 'label_off' => esc_html__( 'No', 'homeo' ), | |
| 'condition' => [ | |
| 'filter_field' => 'title', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'style', | |
| [ | |
| 'label' => esc_html__( 'Price Style', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => [ | |
| 'slider' => esc_html__('Price Slider', 'homeo'), | |
| 'text' => esc_html__('Pice Min/max Input Text', 'homeo'), | |
| 'list' => esc_html__('Price List', 'homeo'), | |
| ], | |
| 'default' => 'slider', | |
| 'condition' => [ | |
| 'filter_field' => 'price', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'price_range_size', | |
| [ | |
| 'label' => esc_html__( 'Price range size', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::NUMBER, | |
| 'input_type' => 'text', | |
| 'default' => 1000, | |
| 'condition' => [ | |
| 'filter_field' => 'price', | |
| 'style' => 'list', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'price_range_max', | |
| [ | |
| 'label' => esc_html__( 'Max price ranges', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::NUMBER, | |
| 'input_type' => 'text', | |
| 'default' => 10, | |
| 'condition' => [ | |
| 'filter_field' => 'price', | |
| 'style' => 'list', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'min_price_placeholder', | |
| [ | |
| 'label' => esc_html__( 'Min Price Placeholder', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'default' => 'Min Price', | |
| 'condition' => [ | |
| 'filter_field' => 'price', | |
| 'style' => 'text', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'max_price_placeholder', | |
| [ | |
| 'label' => esc_html__( 'Max Price Placeholder', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'default' => 'Max Price', | |
| 'condition' => [ | |
| 'filter_field' => 'price', | |
| 'style' => 'text', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'slider_style', | |
| [ | |
| 'label' => esc_html__( 'Layout Style', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => [ | |
| 'slider' => esc_html__('Slider', 'homeo'), | |
| 'text' => esc_html__('Input Text', 'homeo'), | |
| ], | |
| 'default' => 'slider', | |
| 'condition' => [ | |
| 'filter_field' => ['home_area', 'lot_area', 'year_built'], | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'min_placeholder', | |
| [ | |
| 'label' => esc_html__( 'Min Placeholder', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'default' => 'Min', | |
| 'condition' => [ | |
| 'filter_field' => ['home_area', 'lot_area', 'year_built'], | |
| 'slider_style' => 'text', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'max_placeholder', | |
| [ | |
| 'label' => esc_html__( 'Max Placeholder', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'default' => 'Max', | |
| 'condition' => [ | |
| 'filter_field' => ['home_area', 'lot_area', 'year_built'], | |
| 'slider_style' => 'text', | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'suffix', | |
| [ | |
| 'label' => esc_html__( 'Suffix', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'default' => 'Sqft', | |
| 'condition' => [ | |
| 'filter_field' => ['home_area', 'lot_area'], | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'number_style', | |
| [ | |
| 'label' => esc_html__( 'Layout Style', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => [ | |
| 'number-plus' => esc_html__('Number +', 'homeo'), | |
| 'number' => esc_html__('Number', 'homeo'), | |
| ], | |
| 'default' => 'number-plus', | |
| 'condition' => [ | |
| 'filter_field' => ['baths', 'beds', 'rooms', 'garages'], | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'min_number', | |
| [ | |
| 'label' => esc_html__( 'Min Number', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::NUMBER, | |
| 'input_type' => 'text', | |
| 'default' => 1, | |
| 'condition' => [ | |
| 'filter_field' => ['baths', 'beds', 'rooms', 'garages'], | |
| ], | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'max_number', | |
| [ | |
| 'label' => esc_html__( 'Max Number', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::NUMBER, | |
| 'input_type' => 'text', | |
| 'default' => 5, | |
| 'condition' => [ | |
| 'filter_field' => ['baths', 'beds', 'rooms', 'garages'], | |
| ], | |
| ] | |
| ); | |
| $columns = array(); | |
| for ($i=1; $i <= 12 ; $i++) { | |
| $columns[$i] = sprintf(esc_html__('%d Columns', 'homeo'), $i); | |
| } | |
| $repeater->add_control( | |
| 'columns', | |
| [ | |
| 'label' => esc_html__( 'Columns', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => $columns, | |
| 'default' => 1 | |
| ] | |
| ); | |
| $repeater->add_control( | |
| 'icon', | |
| [ | |
| 'label' => esc_html__( 'Icon', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::ICON | |
| ] | |
| ); | |
| $this->add_control( | |
| 'main_search_fields', | |
| [ | |
| 'label' => esc_html__( 'Main Search Fields', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::REPEATER, | |
| 'fields' => $repeater->get_controls(), | |
| ] | |
| ); | |
| $this->add_control( | |
| 'show_advance_search', | |
| [ | |
| 'label' => esc_html__( 'Show Advanced Search', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SWITCHER, | |
| 'label_on' => esc_html__( 'Show', 'homeo' ), | |
| 'label_off' => esc_html__( 'Hide', 'homeo' ), | |
| 'return_value' => true, | |
| 'default' => true, | |
| ] | |
| ); | |
| $this->add_control( | |
| 'advance_search_fields', | |
| [ | |
| 'label' => esc_html__( 'Advanced Search Fields', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::REPEATER, | |
| 'fields' => $repeater->get_controls(), | |
| ] | |
| ); | |
| $this->add_control( | |
| 'filter_btn_text', | |
| [ | |
| 'label' => esc_html__( 'Button Text', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'default' => 'Find Property', | |
| ] | |
| ); | |
| $this->add_control( | |
| 'advanced_btn_text', | |
| [ | |
| 'label' => esc_html__( 'Advanced Text', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'input_type' => 'text', | |
| 'default' => 'Advanced', | |
| ] | |
| ); | |
| $this->add_control( | |
| 'btn_columns', | |
| [ | |
| 'label' => esc_html__( 'Button Columns', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => $columns, | |
| 'default' => 1 | |
| ] | |
| ); | |
| $this->add_control( | |
| 'layout_type', | |
| [ | |
| 'label' => esc_html__( 'Layout Type', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => array( | |
| 'horizontal' => esc_html__('Horizontal', 'homeo'), | |
| 'vertical' => esc_html__('Vertical', 'homeo'), | |
| ), | |
| 'default' => 'horizontal' | |
| ] | |
| ); | |
| $this->add_control( | |
| 'style', | |
| [ | |
| 'label' => esc_html__( 'Style', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::SELECT, | |
| 'options' => array( | |
| '' => esc_html__('Default', 'homeo'), | |
| 'style1' => esc_html__('Style 1', 'homeo'), | |
| 'style2' => esc_html__('Style 2', 'homeo'), | |
| 'style3' => esc_html__('Style 3', 'homeo'), | |
| 'style4' => esc_html__('Style Icon', 'homeo'), | |
| ), | |
| 'default' => '' | |
| ] | |
| ); | |
| $this->add_control( | |
| 'el_class', | |
| [ | |
| 'label' => esc_html__( 'Extra class name', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::TEXT, | |
| 'placeholder' => esc_html__( 'If you wish to style particular content element differently, please add a class name to this field and refer to it in your custom CSS file.', 'homeo' ), | |
| ] | |
| ); | |
| $this->end_controls_section(); | |
| $this->start_controls_section( | |
| 'section_button_style', | |
| [ | |
| 'label' => esc_html__( 'Button', 'homeo' ), | |
| 'tab' => Elementor\Controls_Manager::TAB_STYLE, | |
| ] | |
| ); | |
| $this->start_controls_tabs( 'tabs_button_style' ); | |
| $this->start_controls_tab( | |
| 'tab_button_normal', | |
| [ | |
| 'label' => esc_html__( 'Normal', 'homeo' ), | |
| ] | |
| ); | |
| $this->add_control( | |
| 'button_color', | |
| [ | |
| 'label' => esc_html__( 'Button Color', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::COLOR, | |
| 'selectors' => [ | |
| '{{WRAPPER}} .btn-submit' => 'color: {{VALUE}};', | |
| ], | |
| ] | |
| ); | |
| $this->add_group_control( | |
| Elementor\Group_Control_Background::get_type(), | |
| [ | |
| 'name' => 'background_button', | |
| 'label' => esc_html__( 'Background', 'homeo' ), | |
| 'types' => [ 'classic', 'gradient', 'video' ], | |
| 'selector' => '{{WRAPPER}} .btn-submit', | |
| ] | |
| ); | |
| $this->add_group_control( | |
| Elementor\Group_Control_Border::get_type(), | |
| [ | |
| 'name' => 'border_button', | |
| 'label' => esc_html__( 'Border', 'homeo' ), | |
| 'selector' => '{{WRAPPER}} .btn-submit', | |
| ] | |
| ); | |
| $this->add_control( | |
| 'padding_button', | |
| [ | |
| 'label' => esc_html__( 'Padding', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::DIMENSIONS, | |
| 'size_units' => [ 'px', '%', 'em' ], | |
| 'selectors' => [ | |
| '{{WRAPPER}} .btn-submit' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', | |
| ], | |
| ] | |
| ); | |
| $this->end_controls_tab(); | |
| // tab hover | |
| $this->start_controls_tab( | |
| 'tab_button_hover', | |
| [ | |
| 'label' => esc_html__( 'Hover', 'homeo' ), | |
| ] | |
| ); | |
| $this->add_control( | |
| 'button_hover_color', | |
| [ | |
| 'label' => esc_html__( 'Button Color', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::COLOR, | |
| 'selectors' => [ | |
| '{{WRAPPER}} .btn-submit:hover, {{WRAPPER}} .btn-submit:focus' => 'color: {{VALUE}};', | |
| ], | |
| ] | |
| ); | |
| $this->add_group_control( | |
| Elementor\Group_Control_Background::get_type(), | |
| [ | |
| 'name' => 'background_button_hover', | |
| 'label' => esc_html__( 'Background', 'homeo' ), | |
| 'types' => [ 'classic', 'gradient', 'video' ], | |
| 'selector' => '{{WRAPPER}} .btn-submit:hover, {{WRAPPER}} .btn-submit:focus', | |
| ] | |
| ); | |
| $this->add_control( | |
| 'button_hover_border_color', | |
| [ | |
| 'label' => esc_html__( 'Border Color', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::COLOR, | |
| 'condition' => [ | |
| 'border_button_border!' => '', | |
| ], | |
| 'selectors' => [ | |
| '{{WRAPPER}} .btn-submit:hover, {{WRAPPER}} .btn-submit:focus' => 'border-color: {{VALUE}};', | |
| ], | |
| ] | |
| ); | |
| $this->add_control( | |
| 'padding_button_hover', | |
| [ | |
| 'label' => esc_html__( 'Padding', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::DIMENSIONS, | |
| 'size_units' => [ 'px', '%', 'em' ], | |
| 'selectors' => [ | |
| '{{WRAPPER}} .btn-submit:hover, {{WRAPPER}} .btn-submit:focus' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', | |
| ], | |
| ] | |
| ); | |
| $this->end_controls_tab(); | |
| $this->end_controls_tabs(); | |
| // end tab | |
| $this->end_controls_section(); | |
| $this->start_controls_section( | |
| 'section_border_style', | |
| [ | |
| 'label' => esc_html__( 'Border', 'homeo' ), | |
| 'tab' => Elementor\Controls_Manager::TAB_STYLE, | |
| ] | |
| ); | |
| $this->add_group_control( | |
| Elementor\Group_Control_Box_Shadow::get_type(), | |
| [ | |
| 'name' => 'box_shadow', | |
| 'label' => esc_html__( 'Box Shadow', 'homeo' ), | |
| 'selector' => '{{WRAPPER}} .content-main-inner', | |
| ] | |
| ); | |
| $this->end_controls_section(); | |
| $this->start_controls_section( | |
| 'section_typography_style', | |
| [ | |
| 'label' => esc_html__( 'Typography', 'homeo' ), | |
| 'tab' => Elementor\Controls_Manager::TAB_STYLE, | |
| ] | |
| ); | |
| $this->add_control( | |
| 'text_color', | |
| [ | |
| 'label' => esc_html__( 'Text Color', 'homeo' ), | |
| 'type' => Elementor\Controls_Manager::COLOR, | |
| 'selectors' => [ | |
| '{{WRAPPER}} .form-search' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .advance-search-btn' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .circle-check' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .form-control' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .form-control::-webkit-input-placeholder' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .form-control:-ms-input-placeholder ' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .form-control::placeholder ' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .select2-selection--single .select2-selection__rendered' => 'color: {{VALUE}};', | |
| '{{WRAPPER}} .select2-selection--single .select2-selection__placeholder' => 'color: {{VALUE}};', | |
| ], | |
| ] | |
| ); | |
| $this->end_controls_section(); | |
| } | |
| protected function render() { | |
| $settings = $this->get_settings(); | |
| extract( $settings ); | |
| $search_page_url = WP_RealEstate_Mixes::get_properties_page_url(); | |
| homeo_load_select2(); | |
| $filter_fields = apply_filters( 'wp-realestate-default-property-filter-fields', array() ); | |
| $instance = array(); | |
| $widget_id = homeo_random_key(); | |
| $args = array( 'widget_id' => $widget_id ); | |
| ?> | |
| <div class="widget-property-search-form <?php echo esc_attr($el_class.' '.$style.' '.$layout_type); ?>"> | |
| <?php if ( $title ) { ?> | |
| <h2 class="title"><?php echo esc_html($title); ?></h2> | |
| <?php } ?> | |
| <form action="<?php echo esc_url($search_page_url); ?>" class="form-search filter-listing-form <?php echo esc_attr($style); ?>" method="GET"> | |
| <?php if ( ! get_option('permalink_structure') ) { | |
| $properties_page_id = wp_realestate_get_option('properties_page_id'); | |
| $properties_page_id = WP_RealEstate_Mixes::get_lang_post_id( $properties_page_id, 'page'); | |
| if ( !empty($properties_page_id) ) { | |
| echo '<input type="hidden" name="p" value="' . $properties_page_id . '">'; | |
| } | |
| } ?> | |
| <div class="search-form-inner"> | |
| <?php if ( $layout_type == 'horizontal' ) { ?> | |
| <div class="main-inner clearfix"> | |
| <div class="content-main-inner"> | |
| <div class="row row-20"> | |
| <?php | |
| if ( !empty($main_search_fields) ) { | |
| foreach ($main_search_fields as $item) { | |
| if ( empty($filter_fields[$item['filter_field']]['field_call_back']) ) { | |
| continue; | |
| } | |
| $filter_field = $filter_fields[$item['filter_field']]; | |
| if ( $item['filter_field'] == 'title' ) { | |
| if ($item['enable_autocompleate_search']) { | |
| wp_enqueue_script( 'handlebars', get_template_directory_uri() . '/js/handlebars.min.js', array(), null, true); | |
| wp_enqueue_script( 'typeahead-jquery', get_template_directory_uri() . '/js/typeahead.bundle.min.js', array('jquery', 'handlebars'), null, true); | |
| $filter_field['add_class'] = 'apus-autocompleate-input'; | |
| } | |
| } elseif ( $item['filter_field'] == 'price' ) { | |
| $filter_field['style'] = $item['style']; | |
| $filter_field['min_price_placeholder'] = $item['min_price_placeholder']; | |
| $filter_field['max_price_placeholder'] = $item['max_price_placeholder']; | |
| $filter_field['price_range_size'] = $item['price_range_size']; | |
| $filter_field['price_range_max'] = $item['price_range_max']; | |
| } elseif ( in_array($item['filter_field'], ['baths', 'beds', 'rooms', 'garages']) ) { | |
| $filter_field['number_style'] = $item['number_style']; | |
| $filter_field['min_number'] = $item['min_number']; | |
| $filter_field['max_number'] = $item['max_number']; | |
| } elseif ( in_array($item['filter_field'], ['home_area', 'lot_area', 'year_built']) ) { | |
| $filter_field['slider_style'] = $item['slider_style']; | |
| $filter_field['min_placeholder'] = $item['min_placeholder']; | |
| $filter_field['max_placeholder'] = $item['max_placeholder']; | |
| } | |
| if ( in_array($item['filter_field'], ['home_area', 'lot_area']) ) { | |
| $filter_field['suffix'] = $item['suffix']; | |
| } | |
| if ( isset($item['icon']) ) { | |
| $filter_field['icon'] = $item['icon']; | |
| } | |
| if ( isset($item['placeholder']) ) { | |
| $filter_field['placeholder'] = $item['placeholder']; | |
| } | |
| $filter_field['show_title'] = false; | |
| $columns = !empty($item['columns']) ? $item['columns'] : '1'; | |
| ?> | |
| <div class="col-xs-12 col-md-<?php echo esc_attr($columns); ?>"> | |
| <?php call_user_func( $filter_field['field_call_back'], $instance, $args, $item['filter_field'], $filter_field ); ?> | |
| </div> | |
| <?php | |
| } | |
| } | |
| ?> | |
| <div class="col-xs-12 col-md-<?php echo esc_attr($btn_columns); ?> form-group form-group-search"> | |
| <div class="flex-middle justify-content-end-lg"> | |
| <?php if ( $show_advance_search && !empty($advance_search_fields) ) { ?> | |
| <div class="advance-link"> | |
| <a href="javascript:void(0);" class=" advance-search-btn"> | |
| <?php | |
| if ( !empty($advanced_btn_text) ) { | |
| echo esc_html($advanced_btn_text); | |
| } else { | |
| esc_html_e('Advanced', 'homeo'); | |
| } | |
| ?> | |
| <i class="flaticon-more"></i> | |
| </a> | |
| </div> | |
| <?php } ?> | |
| <?php if($style == 'style4') {?> | |
| <button class="btn-submit btn" type="submit"> | |
| <i class="flaticon-magnifying-glass"></i> | |
| </button> | |
| <?php }else{ ?> | |
| <button class="btn-submit btn btn-theme btn-inverse" type="submit"> | |
| <?php echo trim($filter_btn_text); ?> | |
| </button> | |
| <?php } ?> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <?php | |
| if ( $show_advance_search && !empty($advance_search_fields) ) { | |
| ?> | |
| <div class="advance-search-wrapper"> | |
| <div class="advance-search-wrapper-fields"> | |
| <div class="row row-20"> | |
| <?php | |
| $sub_class = ''; | |
| foreach ($advance_search_fields as $item) { | |
| if ( empty($filter_fields[$item['filter_field']]['field_call_back']) ) { | |
| continue; | |
| } | |
| $filter_field = $filter_fields[$item['filter_field']]; | |
| if ( isset($item['placeholder']) ) { | |
| $filter_field['placeholder'] = $item['placeholder']; | |
| } | |
| if ( isset($item['icon']) ) { | |
| $filter_field['icon'] = $item['icon']; | |
| } | |
| if($item['filter_field'] == 'amenity'){ | |
| $sub_class = 'wrapper-amenity'; | |
| $filter_field['show_title'] = true; | |
| }else{ | |
| $filter_field['show_title'] = false; | |
| $sub_class = ''; | |
| } | |
| if ( $item['filter_field'] == 'price' ) { | |
| $filter_field['style'] = $item['style']; | |
| $filter_field['min_price_placeholder'] = $item['min_price_placeholder']; | |
| $filter_field['max_price_placeholder'] = $item['max_price_placeholder']; | |
| $filter_field['price_range_size'] = $item['price_range_size']; | |
| $filter_field['price_range_max'] = $item['price_range_max']; | |
| } elseif ( in_array($item['filter_field'], ['baths', 'beds', 'rooms', 'garages']) ) { | |
| $filter_field['number_style'] = $item['number_style']; | |
| $filter_field['min_number'] = $item['min_number']; | |
| $filter_field['max_number'] = $item['max_number']; | |
| } elseif ( in_array($item['filter_field'], ['home_area', 'lot_area', 'year_built']) ) { | |
| $filter_field['slider_style'] = $item['slider_style']; | |
| $filter_field['min_placeholder'] = $item['min_placeholder']; | |
| $filter_field['max_placeholder'] = $item['max_placeholder']; | |
| } | |
| if ( in_array($item['filter_field'], ['home_area', 'lot_area']) ) { | |
| $filter_field['suffix'] = $item['suffix']; | |
| } | |
| $columns = !empty($item['columns']) ? $item['columns'] : '1'; | |
| ?> | |
| <div class="col-xs-12 col-md-<?php echo esc_attr($columns.' '.$sub_class); ?>"> | |
| <?php call_user_func( $filter_field['field_call_back'], $instance, $args, $item['filter_field'], $filter_field ); ?> | |
| </div> | |
| <?php | |
| } | |
| ?> | |
| </div> | |
| </div> | |
| </div> | |
| <?php | |
| } | |
| ?> | |
| <?php } else { ?> | |
| <div class="main-inner clearfix"> | |
| <div class="content-main-inner"> | |
| <div class="row"> | |
| <?php | |
| if ( !empty($main_search_fields) ) { | |
| foreach ($main_search_fields as $item) { | |
| if ( empty($filter_fields[$item['filter_field']]['field_call_back']) ) { | |
| continue; | |
| } | |
| $filter_field = $filter_fields[$item['filter_field']]; | |
| if ( $item['filter_field'] == 'title' ) { | |
| if ($item['enable_autocompleate_search']) { | |
| wp_enqueue_script( 'handlebars', get_template_directory_uri() . '/js/handlebars.min.js', array(), null, true); | |
| wp_enqueue_script( 'typeahead-jquery', get_template_directory_uri() . '/js/typeahead.bundle.min.js', array('jquery', 'handlebars'), null, true); | |
| $filter_field['add_class'] = 'apus-autocompleate-input'; | |
| } | |
| } elseif ( $item['filter_field'] == 'price' ) { | |
| $filter_field['style'] = $item['style']; | |
| $filter_field['min_price_placeholder'] = $item['min_price_placeholder']; | |
| $filter_field['max_price_placeholder'] = $item['max_price_placeholder']; | |
| $filter_field['price_range_size'] = $item['price_range_size']; | |
| $filter_field['price_range_max'] = $item['price_range_max']; | |
| } elseif ( in_array($item['filter_field'], ['baths', 'beds', 'rooms', 'garages']) ) { | |
| $filter_field['number_style'] = $item['number_style']; | |
| $filter_field['min_number'] = $item['min_number']; | |
| $filter_field['max_number'] = $item['max_number']; | |
| } elseif ( in_array($item['filter_field'], ['home_area', 'lot_area', 'year_built']) ) { | |
| $filter_field['slider_style'] = $item['slider_style']; | |
| $filter_field['min_placeholder'] = $item['min_placeholder']; | |
| $filter_field['max_placeholder'] = $item['max_placeholder']; | |
| } | |
| if ( in_array($item['filter_field'], ['home_area', 'lot_area']) ) { | |
| $filter_field['suffix'] = $item['suffix']; | |
| } | |
| if ( isset($item['icon']) ) { | |
| $filter_field['icon'] = $item['icon']; | |
| } | |
| if ( isset($item['placeholder']) ) { | |
| $filter_field['placeholder'] = $item['placeholder']; | |
| } | |
| $filter_field['show_title'] = false; | |
| $columns = !empty($item['columns']) ? $item['columns'] : '1'; | |
| ?> | |
| <div class="col-xs-12 col-md-<?php echo esc_attr($columns); ?>"> | |
| <?php call_user_func( $filter_field['field_call_back'], $instance, $args, $item['filter_field'], $filter_field ); ?> | |
| </div> | |
| <?php | |
| } | |
| } | |
| ?> | |
| <?php if( $show_advance_search && !empty($advance_search_fields)){ ?> | |
| <div class="col-xs-12"> | |
| <div class="form-group"> | |
| <div class="advance-link"> | |
| <a href="javascript:void(0);" class=" advance-search-btn"> | |
| <?php | |
| if ( !empty($advanced_btn_text) ) { | |
| echo esc_html($advanced_btn_text); | |
| } else { | |
| esc_html_e('Advanced', 'homeo'); | |
| } | |
| ?> | |
| <i class="flaticon-more"></i> | |
| </a> | |
| </div> | |
| </div> | |
| </div> | |
| <?php } ?> | |
| </div> | |
| <?php | |
| if ( $show_advance_search && !empty($advance_search_fields) ) { | |
| ?> | |
| <div class="advance-search-wrapper"> | |
| <div class="advance-search-wrapper-fields"> | |
| <div class="row"> | |
| <?php | |
| foreach ($advance_search_fields as $item) { | |
| if ( empty($filter_fields[$item['filter_field']]['field_call_back']) ) { | |
| continue; | |
| } | |
| $filter_field = $filter_fields[$item['filter_field']]; | |
| if ( isset($item['placeholder']) ) { | |
| $filter_field['placeholder'] = $item['placeholder']; | |
| } | |
| if ( isset($item['icon']) ) { | |
| $filter_field['icon'] = $item['icon']; | |
| } | |
| $filter_field['show_title'] = false; | |
| $columns = !empty($item['columns']) ? $item['columns'] : '1'; | |
| if ( $item['filter_field'] == 'price' ) { | |
| $filter_field['style'] = $item['style']; | |
| $filter_field['min_price_placeholder'] = $item['min_price_placeholder']; | |
| $filter_field['max_price_placeholder'] = $item['max_price_placeholder']; | |
| $filter_field['price_range_size'] = $item['price_range_size']; | |
| $filter_field['price_range_max'] = $item['price_range_max']; | |
| } elseif ( in_array($item['filter_field'], ['baths', 'beds', 'rooms', 'garages']) ) { | |
| $filter_field['number_style'] = $item['number_style']; | |
| $filter_field['min_number'] = $item['min_number']; | |
| $filter_field['max_number'] = $item['max_number']; | |
| } elseif ( in_array($item['filter_field'], ['home_area', 'lot_area', 'year_built']) ) { | |
| $filter_field['slider_style'] = $item['slider_style']; | |
| $filter_field['min_placeholder'] = $item['min_placeholder']; | |
| $filter_field['max_placeholder'] = $item['max_placeholder']; | |
| } | |
| if ( in_array($item['filter_field'], ['home_area', 'lot_area']) ) { | |
| $filter_field['suffix'] = $item['suffix']; | |
| } | |
| ?> | |
| <div class="col-xs-12 col-md-<?php echo esc_attr($columns); ?>"> | |
| <?php call_user_func( $filter_field['field_call_back'], $instance, $args, $item['filter_field'], $filter_field ); ?> | |
| </div> | |
| <?php | |
| } | |
| ?> | |
| </div> | |
| </div> | |
| </div> | |
| <?php | |
| } | |
| ?> | |
| <div class="row"> | |
| <div class="col-xs-12 col-md-<?php echo esc_attr($btn_columns); ?> form-group-search"> | |
| <?php if($style == 'style4') {?> | |
| <button class="btn-submit btn-block btn" type="submit"> | |
| <i class="flaticon-magnifying-glass"></i> | |
| </button> | |
| <?php }else{ ?> | |
| <button class="btn-submit btn-block btn btn-theme btn-inverse" type="submit"> | |
| <?php echo trim($filter_btn_text); ?> | |
| </button> | |
| <?php } ?> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <?php } ?> | |
| </div> | |
| </form> | |
| </div> | |
| <?php | |
| } | |
| } | |
| if ( version_compare(ELEMENTOR_VERSION, '3.5.0', '<') ) { | |
| Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Homeo_Elementor_RealEstate_Search_Form ); | |
| } else { | |
| Elementor\Plugin::instance()->widgets_manager->register( new Homeo_Elementor_RealEstate_Search_Form ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment