function draw_property_search_form($args = false) { global $wp_properties; WPP_F::force_script_inclusion('wpp-jquery-number-format'); $args = wp_parse_args($args, array('search_attributes' => false, 'searchable_property_types' => false, 'use_pagination' => 'on', 'per_page' => '10', 'group_attributes' => false, 'strict_search' => false, 'instance_id' => false, 'sort_order' => false, 'cache' => true)); if (empty($args['search_attributes']) && isset($args['searchable_attributes'])) { $args['search_attributes'] = $args['searchable_attributes']; } extract($args, EXTR_SKIP); $search_values = array(); $property_type_flag = false; //** Bail if no search attributes passed */ if (!is_array($args['search_attributes'])) { return; } $property_stats = $wp_properties['property_stats']; if (!isset($property_stats['property_type'])) { $property_stats['property_type'] = sprintf(__('%s Type', ud_get_wp_property()->domain), WPP_F::property_label()); } //** Load search values for attributes (from cache, or generate) */ if (!empty($search_attributes) && !empty($searchable_property_types)) { $search_values = WPP_F::get_search_values($search_attributes, $searchable_property_types, $args['cache'], $args['instance_id']); } //** This looks clumsy - potanin@UD */ if (array_key_exists('property_type', array_fill_keys($search_attributes, 1)) && is_array($searchable_property_types) && count($searchable_property_types) > 1) { $spt = array_fill_keys($searchable_property_types, 1); if (!empty($wp_properties['property_types'])) { foreach ($wp_properties['property_types'] as $key => $value) { if (array_key_exists($key, $spt)) { $search_values['property_type'][$key] = $value; } } if (isset($search_values['property_type']) && count($search_values['property_type']) <= 1) { unset($search_values['property_type']); } } } ?> <form action="<?php echo WPP_F::base_url($wp_properties['configuration']['base_slug']); ?> " method="post" class="wpp_shortcode_search_form"> <?php do_action("draw_property_search_form", $args); ?> <?php if ($sort_order) { ?> <input type="hidden" name="wpp_search[sort_order]" value="<?php echo $sort_order; ?> "/> <?php } ?> <?php if (!empty($sort_by)) { ?> <input type="hidden" name="wpp_search[sort_by]" value="<?php echo $sort_by; ?> "/> <?php } ?> <?php if (!empty($use_pagination)) { ?> <input type="hidden" name="wpp_search[pagination]" value="<?php echo $use_pagination; ?> "/> <?php } ?> <?php if (!empty($per_page)) { ?> <input type="hidden" name="wpp_search[per_page]" value="<?php echo $per_page; ?> "/> <?php } ?> <?php if (!empty($strict_search)) { ?> <input type="hidden" name="wpp_search[strict_search]" value="<?php echo $strict_search; ?> "/> <?php } ?> <?php //** If no property_type passed in search_attributes, we get defaults */ if (is_array($searchable_property_types) && !array_key_exists('property_type', array_fill_keys($search_attributes, 1))) { echo '<input type="hidden" name="wpp_search[property_type]" value="' . implode(',', $searchable_property_types) . '" />'; } ?> <ul class="wpp_search_elements"> <?php if (isset($group_attributes) && $group_attributes) { //** Get group data */ $groups = $wp_properties['property_groups']; $_search_attributes = array(); foreach ($search_attributes as $attr) { $_search_attributes[$attr] = $attr; } $search_groups = sort_stats_by_groups($_search_attributes); unset($_search_attributes); } else { //** Create an ad-hoc group */ $search_groups['ungrouped'] = $search_attributes; } $main_stats_group = isset($wp_properties['configuration']['main_stats_group']) ? $wp_properties['configuration']['main_stats_group'] : false; $count = 0; foreach ($search_groups as $this_group => $search_attributes) { $count++; if ($this_group == 'ungrouped' || $this_group === 0 || $this_group == $main_stats_group) { $is_a_group = false; $this_group = 'not_a_group'; } else { $is_a_group = true; } ?> <li class="wpp_search_group wpp_group_<?php echo $this_group; ?> "> <?php if ($is_a_group) { ?> <span class="wpp_search_group_title wpp_group_<?php echo $this_group; ?> _title"><?php echo $groups[$this_group]['name']; ?> </span> <?php } elseif ($group_attributes && $count == count($search_groups)) { ?> <span class="wpp_search_group_title" style="height:1px;line-height:1px;"> </span> <?php } ?> <ul class="wpp_search_group wpp_group_<?php echo $this_group; ?> "> <?php //** Begin Group Attributes */ foreach ($search_attributes as $attrib) { //** Override search values if they are set in the developer tab */ if (!empty($wp_properties['predefined_search_values'][$attrib])) { $maybe_search_values = explode(',', $wp_properties['predefined_search_values'][$attrib]); if (is_array($maybe_search_values)) { $using_predefined_values = true; $search_values[$attrib] = $maybe_search_values; } else { $using_predefined_values = true; } } //** Don't display search attributes that have no values */ if (!apply_filters('wpp::show_search_field_with_no_values', isset($search_values[$attrib]), $attrib)) { continue; } $label = apply_filters('wpp::search_attribute::label', empty($property_stats[$attrib]) ? WPP_F::de_slug($attrib) : $property_stats[$attrib], $attrib); ?> <li class="wpp_search_form_element seach_attribute_<?php echo $attrib; ?> wpp_search_attribute_type_<?php echo isset($wp_properties['searchable_attr_fields'][$attrib]) ? $wp_properties['searchable_attr_fields'][$attrib] : $attrib; ?> <?php echo !empty($wp_properties['searchable_attr_fields'][$attrib]) && $wp_properties['searchable_attr_fields'][$attrib] == 'checkbox' ? 'wpp-checkbox-el' : ''; echo !empty($wp_properties['searchable_attr_fields'][$attrib]) && ($wp_properties['searchable_attr_fields'][$attrib] == 'multi_checkbox' && count($search_values[$attrib]) == 1) || isset($wp_properties['searchable_attr_fields'][$attrib]) && $wp_properties['searchable_attr_fields'][$attrib] == 'checkbox' ? ' single_checkbox' : ''; ?> "> <?php $random_element_id = 'wpp_search_element_' . rand(1000, 9999); ?> <label for="<?php echo $random_element_id; ?> " class="wpp_search_label wpp_search_label_<?php echo $attrib; ?> "><?php echo $label; ?> <span class="wpp_search_post_label_colon">:</span></label> <div class="wpp_search_attribute_wrap"> <?php $value = isset($_REQUEST['wpp_search'][$attrib]) ? $_REQUEST['wpp_search'][$attrib] : ''; ob_start(); wpp_render_search_input(array('attrib' => $attrib, 'random_element_id' => $random_element_id, 'search_values' => $search_values, 'value' => $value)); $this_field = ob_get_contents(); ob_end_clean(); echo apply_filters('wpp_search_form_field_' . $attrib, $this_field, $attrib, $label, $value, isset($wp_properties['searchable_attr_fields'][$attrib]) ? $wp_properties['searchable_attr_fields'][$attrib] : false, $random_element_id); ?> </div> <div class="clear"></div> </li> <?php } //** End Group Attributes */ ?> </ul> <div class="clear"></div> </li> <?php } ?> <li class="wpp_search_form_element submit"><input type="submit" class="wpp_search_button submit btn btn-large" value="<?php _e('Search', ud_get_wp_property()->domain); ?> "/></li> </ul> </form> <?php }
/** * Displays property overview * * Performs searching/filtering functions, provides template with $properties file * Retirms html content to be displayed after location attribute on property edit page * * @since 1.081 * * @param string $listing_id Listing ID must be passed * * @return string $result * * @uses WPP_F::get_properties() * */ public static function render($atts = "") { global $wp_properties, $wpp_query, $property, $post, $wp_query; $_property = $property; $wpp_query = array(); $atts = wp_parse_args($atts, array()); \WPP_F::force_script_inclusion('jquery-ui-widget'); \WPP_F::force_script_inclusion('jquery-ui-mouse'); \WPP_F::force_script_inclusion('jquery-ui-slider'); \WPP_F::force_script_inclusion('wpp-jquery-address'); \WPP_F::force_script_inclusion('wpp-jquery-scrollTo'); \WPP_F::force_script_inclusion('wpp-jquery-fancybox'); \WPP_F::force_script_inclusion('wp-property-frontend'); //** Load all queriable attributes **/ foreach (\WPP_F::get_queryable_keys() as $key) { //** This needs to be done because a key has to exist in the $deafult array for shortcode_atts() to load passed value */ $queryable_keys[$key] = false; } //** Allow the shorthand of "type" as long as there is not a custom attribute of "type". If "type" does exist as an attribute, then users need to use the full "property_type" query tag. **/ if (!array_key_exists('type', $queryable_keys) && (is_array($atts) && array_key_exists('type', $atts))) { $atts['property_type'] = $atts['type']; unset($atts['type']); } //** Get ALL allowed attributes that may be passed via shortcode (to include property attributes) */ $defaults['strict_search'] = false; $defaults['show_children'] = isset($wp_properties['configuration']['property_overview']['show_children']) ? $wp_properties['configuration']['property_overview']['show_children'] : 'true'; $defaults['child_properties_title'] = __('Floor plans at location:', ud_get_wp_property()->domain); $defaults['fancybox_preview'] = $wp_properties['configuration']['property_overview']['fancybox_preview']; $defaults['bottom_pagination_flag'] = isset($wp_properties['configuration']['bottom_insert_pagenation']) && $wp_properties['configuration']['bottom_insert_pagenation'] == 'true' ? true : false; $defaults['thumbnail_size'] = $wp_properties['configuration']['property_overview']['thumbnail_size']; $defaults['sort_by_text'] = __('Sort By:', ud_get_wp_property()->domain); $defaults['sort_by'] = 'post_date'; $defaults['sort_order'] = 'DESC'; $defaults['template'] = false; $defaults['ajax_call'] = false; $defaults['disable_wrapper'] = false; $defaults['sorter_type'] = 'buttons'; $defaults['sorter'] = 'on'; $defaults['pagination'] = 'on'; $defaults['pagination_type'] = ud_get_wp_property('configuration.property_overview.pagination_type') ? ud_get_wp_property('configuration.property_overview.pagination_type') : 'slider'; $defaults['hide_count'] = false; $defaults['per_page'] = 10; $defaults['starting_row'] = 0; $defaults['unique_hash'] = rand(10000, 99900); $defaults['detail_button'] = false; $defaults['stats'] = ''; $defaults['class'] = 'wpp_property_overview_shortcode'; $defaults['in_new_window'] = false; $defaults = apply_filters('shortcode_property_overview_allowed_args', $defaults, $atts); //* Determine if we should disable sorter */ if (isset($atts['sorter']) && in_array($atts['sorter'], array('off', 'false'))) { $atts['sorter'] = false; $atts['sorter_type'] = 'none'; } if (!empty($atts['ajax_call'])) { //** If AJAX call then the passed args have all the data we need */ $wpp_query = $atts; //* Fix ajax data. Boolean value false is returned as string 'false'. */ foreach ($wpp_query as $key => $value) { if ($value == 'false') { $wpp_query[$key] = false; } } $wpp_query['ajax_call'] = true; //** Everything stays the same except for sort order and page */ $wpp_query['starting_row'] = ($wpp_query['requested_page'] - 1) * $wpp_query['per_page']; //** Figure out current page */ $wpp_query['current_page'] = $wpp_query['requested_page']; } else { /** Determine if fancybox style is included */ \WPP_F::force_style_inclusion('wpp-jquery-fancybox-css'); //** Merge defaults with passed arguments */ $wpp_query = shortcode_atts($defaults, $atts); $wpp_query['query'] = shortcode_atts($queryable_keys, $atts); //** Handle search */ if (!empty($_REQUEST['wpp_search'])) { $wpp_query['query'] = shortcode_atts($wpp_query['query'], $_REQUEST['wpp_search']); $wpp_query['query'] = \WPP_F::prepare_search_attributes($wpp_query['query']); if (isset($_REQUEST['wpp_search']['sort_by'])) { $wpp_query['sort_by'] = $_REQUEST['wpp_search']['sort_by']; } if (isset($_REQUEST['wpp_search']['sort_order'])) { $wpp_query['sort_order'] = $_REQUEST['wpp_search']['sort_order']; } if (isset($_REQUEST['wpp_search']['pagination'])) { $wpp_query['pagination'] = $_REQUEST['wpp_search']['pagination']; } if (isset($_REQUEST['wpp_search']['per_page'])) { $wpp_query['per_page'] = $_REQUEST['wpp_search']['per_page']; } if (isset($_REQUEST['wpp_search']['strict_search'])) { $wpp_query['strict_search'] = $_REQUEST['wpp_search']['strict_search']; } } } //** Load certain settings into query for get_properties() to use */ $wpp_query['query']['sort_by'] = $wpp_query['sort_by']; $wpp_query['query']['sort_order'] = $wpp_query['sort_order']; $wpp_query['query']['pagi'] = $wpp_query['starting_row'] . '--' . $wpp_query['per_page']; if (!isset($wpp_query['current_page'])) { $wpp_query['current_page'] = $wpp_query['starting_row'] / $wpp_query['per_page'] + 1; } //** Load settings that are not passed via shortcode atts */ $wpp_query['sortable_attrs'] = \WPP_F::get_sortable_keys(); //** Replace dynamic field values */ //** Detect currently property for conditional in-shortcode usage that will be replaced from values */ if (isset($post) && is_object($post)) { $dynamic_fields['post_id'] = isset($post->ID) ? $post->ID : 0; $dynamic_fields['post_parent'] = isset($post->post_parent) ? $post->post_parent : 0; $dynamic_fields['property_type'] = isset($post->property_type) ? $post->property_type : false; $dynamic_fields = apply_filters('shortcode_property_overview_dynamic_fields', $dynamic_fields); if (is_array($dynamic_fields)) { foreach ($wpp_query['query'] as $query_key => $query_value) { if (!empty($dynamic_fields[$query_value])) { $wpp_query['query'][$query_key] = $dynamic_fields[$query_value]; } } } } //** Remove all blank values */ $wpp_query['query'] = array_filter($wpp_query['query']); //echo "<pre>"; print_r( $wpp_query ); echo "</pre>"; //** We add # to value which says that we don't want to use LIKE in SQL query for searching this value. */ $required_strict_search = apply_filters('wpp::required_strict_search', array('wpp_agents')); $ignored_strict_search_field_types = apply_filters('wpp:ignored_strict_search_field_types', array('range_dropdown', 'range_input')); foreach ($wpp_query['query'] as $key => $val) { if (!array_key_exists($key, $defaults) && $key != 'property_type') { //** Be sure that the attribute exists of parameter is required for strict search */ if (in_array($wpp_query['strict_search'], array('true', 'on')) && isset($wp_properties['property_stats'][$key]) || in_array($key, $required_strict_search)) { /** * Ignore specific search attribute fields for strict search. * For example, range values must not be included to strict search. * Also, be sure to ignore list of values */ if (isset($wp_properties['searchable_attr_fields'][$key]) && in_array($wp_properties['searchable_attr_fields'][$key], (array) $ignored_strict_search_field_types) || substr_count($val, ',') || substr_count($val, '–') || substr_count($val, '--')) { continue; } elseif (substr_count($val, '-')) { $_val = explode('-', $val); if (count($_val) == 2 && is_numeric($_val[0]) && is_numeric($_val[1])) { continue; } } $wpp_query['query'][$key] = '#' . trim($val, '#') . '#'; } } } //** Unset this because it gets passed with query (for back-button support) but not used by get_properties() */ unset($wpp_query['query']['per_page']); unset($wpp_query['query']['pagination']); unset($wpp_query['query']['requested_page']); //** Load the results */ $wpp_query['properties'] = \WPP_F::get_properties($wpp_query['query'], true); //** Calculate number of pages */ if ($wpp_query['pagination'] == 'on') { $wpp_query['pages'] = ceil($wpp_query['properties']['total'] / $wpp_query['per_page']); } $property_type = isset($wpp_query['query']['property_type']) ? $wpp_query['query']['property_type'] : false; if (!empty($property_type) && isset($wp_properties['hidden_attributes'][$property_type])) { foreach ((array) $wp_properties['hidden_attributes'][$property_type] as $attr_key) { unset($wpp_query['sortable_attrs'][$attr_key]); } } //** Legacy Support - include variables so old templates still work */ $properties = $wpp_query['properties']['results']; $thumbnail_sizes = \WPP_F::image_sizes($wpp_query['thumbnail_size']); $child_properties_title = $wpp_query['child_properties_title']; $unique = $wpp_query['unique_hash']; $thumbnail_size = $wpp_query['thumbnail_size']; //* Debugger */ if (isset($wp_properties['configuration']['developer_mode']) && $wp_properties['configuration']['developer_mode'] == 'true' && !$wpp_query['ajax_call']) { echo '<script type="text/javascript">console.log( ' . json_encode($wpp_query) . ' ); </script>'; } ob_start(); //** Make certain variables available to be used within the single listing page */ $wpp_overview_shortcode_vars = apply_filters('wpp_overview_shortcode_vars', array('wp_properties' => $wp_properties, 'wpp_query' => $wpp_query)); //** By merging our extra variables into $wp_query->query_vars they will be extracted in load_template() */ if (is_array($wpp_overview_shortcode_vars)) { $wp_query->query_vars = array_merge($wp_query->query_vars, $wpp_overview_shortcode_vars); } $template = $wpp_query['template']; $fancybox_preview = $wpp_query['fancybox_preview']; $show_children = $wpp_query['show_children']; $class = $wpp_query['class']; $stats = $wpp_query['stats']; $in_new_window = !empty($wpp_query['in_new_window']) ? " target=\"_blank\" " : ""; //** Make query_vars available to emulate WP template loading */ extract($wp_query->query_vars, EXTR_SKIP); //** Try find custom template */ $template_found = \WPP_F::get_template_part(array("property-overview-{$template}", "property-overview-" . sanitize_key($property_type), "property-overview"), array(ud_get_wp_property()->path('static/views', 'dir'))); if ($template_found) { include $template_found; } $ob_get_contents = ob_get_contents(); ob_end_clean(); $ob_get_contents = apply_filters('shortcode_property_overview_content', $ob_get_contents, $wpp_query); // Initialize result (content which will be shown) and open wrap (div) with unique id if ($wpp_query['disable_wrapper'] != 'true') { $result['top'] = '<div id="wpp_shortcode_' . $wpp_query['unique_hash'] . '" class="wpp_ui ' . $wpp_query['class'] . '">'; } $result['top_pagination'] = self::draw_pagination(array('type' => $wpp_query['pagination_type'], 'class' => 'wpp_top_pagination', 'sorter_type' => $wpp_query['sorter_type'], 'hide_count' => $wpp_query['hide_count'], 'sort_by_text' => $wpp_query['sort_by_text'])); $result['result'] = $ob_get_contents; if ($wpp_query['bottom_pagination_flag'] == 'true') { $result['bottom_pagination'] = self::draw_pagination(array('type' => $wpp_query['pagination_type'], 'class' => 'wpp_bottom_pagination', 'sorter_type' => $wpp_query['sorter_type'], 'hide_count' => $wpp_query['hide_count'], 'sort_by_text' => $wpp_query['sort_by_text'], 'javascript' => false)); } if ($wpp_query['disable_wrapper'] != 'true') { $result['bottom'] = '</div>'; } $result = apply_filters('wpp_property_overview_render', $result); /* Reset global property to default. */ $property = $_property; if ($wpp_query['ajax_call']) { return json_encode(array('wpp_query' => $wpp_query, 'display' => implode('', $result))); } else { return implode('', $result); } }