예제 #1
0
 /**
  * Renders shortcode
  *
  * @since 1.04
  */
 public function render($atts = "")
 {
     global $post, $wp_properties;
     $group_attributes = '';
     $per_page = '';
     $pagination = '';
     extract(shortcode_atts(array('searchable_attributes' => '', 'searchable_property_types' => '', 'pagination' => 'on', 'group_attributes' => 'off', 'per_page' => '10', 'strict_search' => 'false'), $atts));
     if (empty($searchable_attributes)) {
         //** get first 3 attributes to prevent people from accidentally loading them all (long query) */
         $searchable_attributes = array_slice($wp_properties['searchable_attributes'], 0, 5);
     } else {
         $searchable_attributes = explode(",", $searchable_attributes);
     }
     $searchable_attributes = array_unique($searchable_attributes);
     if (empty($searchable_property_types)) {
         $searchable_property_types = $wp_properties['searchable_property_types'];
     } else {
         $searchable_property_types = explode(",", $searchable_property_types);
     }
     $widget_id = $post->ID . "_search";
     ob_start();
     echo '<div class="wpp_shortcode_search">';
     $search_args['searchable_attributes'] = $searchable_attributes;
     $search_args['searchable_property_types'] = $searchable_property_types;
     $search_args['group_attributes'] = $group_attributes == 'on' || $group_attributes == 'true' ? true : false;
     $search_args['per_page'] = $per_page;
     $search_args['pagination'] = $pagination;
     $search_args['instance_id'] = $widget_id;
     $search_args['strict_search'] = $strict_search;
     draw_property_search_form($search_args);
     echo "</div>";
     $content = ob_get_contents();
     ob_end_clean();
     return $content;
 }
예제 #2
0
 /**
  * Widget body
  * @param array $args
  * @param array $instance
  */
 function widget($args, $instance)
 {
     global $wp_properties;
     $before_widget = '';
     $before_title = '';
     $after_title = '';
     $after_widget = '';
     $widget_id = '';
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     $instance = apply_filters('SearchPropertiesWidget', $instance);
     $search_attributes = isset($instance['searchable_attributes']) ? $instance['searchable_attributes'] : false;
     $sort_by = isset($instance['sort_by']) ? $instance['sort_by'] : false;
     $sort_order = isset($instance['sort_order']) ? $instance['sort_order'] : false;
     $searchable_property_types = isset($instance['searchable_property_types']) ? $instance['searchable_property_types'] : array();
     $grouped_searchable_attributes = isset($instance['grouped_searchable_attributes']) ? $instance['grouped_searchable_attributes'] : array();
     if (!is_array($search_attributes)) {
         return;
     }
     if (!function_exists('draw_property_search_form')) {
         return;
     }
     //** The current widget can be used on the page twice. So ID of the current DOM element (widget) has to be unique */
     /*
       Removed since this will cause problems with jQuery Tabs in Denali.
       $before_widget = preg_replace('/id="([^\s]*)"/', 'id="$1_'.rand().'"', $before_widget);
     */
     echo $before_widget;
     echo '<div class="wpp_search_properties_widget">';
     if ($title) {
         echo $before_title . $title . $after_title;
     } else {
         echo '<span class="wpp_widget_no_title"></span>';
     }
     //** Load different attribute list depending on group selection */
     if (isset($instance['group_attributes']) && $instance['group_attributes'] == 'true') {
         $search_args['group_attributes'] = true;
         $search_args['search_attributes'] = $grouped_searchable_attributes;
     } else {
         $search_args['search_attributes'] = $search_attributes;
     }
     //* Clean searchable attributes: remove unavailable ones */
     $all_searchable_attributes = array_unique($wp_properties['searchable_attributes']);
     foreach ($search_args['search_attributes'] as $k => $v) {
         if (!in_array($v, $all_searchable_attributes)) {
             //* Don't remove hardcoded attributes (property_type,city) */
             if ($v != 'property_type' && $v != 'city') {
                 unset($search_args['search_attributes'][$k]);
             }
         }
     }
     $search_args['searchable_property_types'] = $searchable_property_types;
     if (isset($instance['use_pagi']) && $instance['use_pagi'] == 'on') {
         if (empty($instance['per_page'])) {
             $instance['per_page'] = 10;
         }
         $search_args['per_page'] = $instance['per_page'];
         $search_args['use_pagination'] = 'on';
     } else {
         $search_args['use_pagination'] = 'off';
         $search_args['per_page'] = isset($instance['per_page']) ? $instance['per_page'] : false;
     }
     $search_args['instance_id'] = $widget_id;
     $search_args['sort_by'] = $sort_by;
     $search_args['sort_order'] = $sort_order;
     $search_args['strict_search'] = !empty($instance['strict_search']) && $instance['strict_search'] == 'on' ? 'true' : 'false';
     draw_property_search_form($search_args);
     echo "<div class='cboth'></div></div>";
     echo $after_widget;
 }