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 }
/** @see WP_Widget::update */ function update($new_instance, $old_instance) { //Recache searchable values for search widget form $searchable_attributes = $new_instance['searchable_attributes']; $grouped_searchable_attributes = $new_instance['grouped_searchable_attributes']; $searchable_property_types = $new_instance['searchable_property_types']; $group_attributes = !empty($new_instance['group_attributes']) ? $new_instance['group_attributes'] : 'false'; if ($group_attributes == 'true') { WPP_F::get_search_values($grouped_searchable_attributes, $searchable_property_types, false, $this->id); } else { WPP_F::get_search_values($searchable_attributes, $searchable_property_types, false, $this->id); } return $new_instance; }