Esempio n. 1
0
 function handle_search_redirect()
 {
     global $wpdb;
     $this->property = new property_model($wpdb, false);
     // Check the search criteria and see if any meta information has been added - if so then
     // we need to resort to straight searching and bypass the quick find stuff.
     switch (addslashes($_REQUEST['searchmadeby'])) {
         case 'quicksearchwidget':
             $search = $_REQUEST['sp_quicksearchfor'];
             break;
         case 'advsearchwidget':
             $search = $_REQUEST['sp_advsearchfor'];
             break;
         case 'shortcodesearch':
             $search = $_REQUEST['sp_shortcodesearchfor'];
             break;
         case 'advshortcodesearch':
             $search = $_REQUEST['sp_advshortcodesearchfor'];
             break;
     }
     $metasearch = array();
     if (!empty($_GET['meta'])) {
         foreach ((array) $_GET['meta'] as $metakey => $metadata) {
             if (!empty($metadata)) {
                 $metasearch[$metakey] = $metadata;
             }
         }
     }
     $tagsearch = apply_filters('staypress_advsearch_extendshortcode_tags', array());
     if (__($this->propertyoptions['propertysearchtext'], 'property') == $search) {
         // no text put into the search box, so blank out the standard placeholder text
         $search = '';
     }
     // Check criteria for property ID or reference - overrides meta information serch
     $property = $this->property->public_quickfind_propertyreforid($search, 'publish');
     if ($property !== false && !empty($property)) {
         // if it exists - redirect to correct permalink
         $url = sp_get_permalink('property', $property);
         $url = apply_filters('staypress_search_redirect_url', $url);
         wp_safe_redirect($url);
         exit;
     }
     if (empty($metasearch) && empty($tagsearch)) {
         // Check criteria for nearby locations
         $dest = $this->property->public_quickfind_location($search);
         if ($dest !== false && !empty($dest)) {
             // if it exists - redirect to correct permalink
             $page_prefix = SPPCommon::get_option('property_rewrite_prefix', '');
             if (!empty($page_prefix)) {
                 $page_prefix = trailingslashit($page_prefix);
             }
             if (!empty($dest->town)) {
                 $url = $page_prefix . __('in', 'property') . '/' . $this->make_url($dest->country);
                 $url .= '/' . $this->make_url($dest->region);
                 $url .= '/' . $this->make_url($dest->town);
             } elseif (!empty($dest->region)) {
                 $url = $page_prefix . __('in', 'property') . '/' . $this->make_url($dest->country);
                 $url .= '/' . $this->make_url($dest->region);
             } elseif (!empty($dest->country)) {
                 $url = $page_prefix . __('in', 'property') . '/' . $this->make_url($dest->country);
             } else {
                 return false;
             }
             $url = apply_filters('staypress_search_redirect_url', $url);
             wp_safe_redirect(trailingslashit(get_option('home')) . $url);
             exit;
         }
         // Check criteria for keyword
         $searchingfor = array_map(array(&$this, 'make_url'), array_map('trim', explode(',', $search)));
         $keyworded = $this->property->get_properties_with_tags((array) $searchingfor);
         if (empty($keyworded) || count($keyworded) == 1 && $keyworded[0] == '0') {
         } else {
             // There are properties with those keywords to redirect
             $url = sp_get_permalink('with', false, implode('/', $searchingfor));
             $url = apply_filters('staypress_search_redirect_url', $url);
             wp_safe_redirect($url);
             exit;
         }
         // Add in final keyword bit
         $extend = 'keyword:' . urlencode($search) . "/searchfor:" . urlencode($search);
         $url = sp_get_permalink('search', false, $extend);
         $url = apply_filters('staypress_search_redirect_url', $url);
         wp_safe_redirect($url);
         exit;
     } else {
         $urlextend = array();
         // More advanced serching - need to build a meta information url and then process later
         // Check criteria for nearby locations
         $dest = $this->property->public_quickfind_location($search);
         if ($dest !== false && !empty($dest)) {
             // if it exists - redirect to correct permalink
             if (!empty($dest->town)) {
                 $urlextend[] = 'intown:' . $this->make_url($dest->town);
                 $urlextend[] = 'inregion:' . $this->make_url($dest->region);
                 $urlextend[] = 'incountry:' . $this->make_url($dest->country);
             } elseif (!empty($dest->region)) {
                 $urlextend[] = 'inregion:' . $this->make_url($dest->region);
                 $urlextend[] = 'incountry:' . $this->make_url($dest->country);
             } elseif (!empty($dest->country)) {
                 $urlextend[] = 'incountry:' . $this->make_url($dest->country);
             }
         }
         // Check criteria for keyword
         if (empty($urlextend)) {
             $searchingfor = array_map(array(&$this, 'make_url'), array_map('trim', explode(',', $search)));
             $keyworded = $this->property->get_properties_with_tags((array) $searchingfor);
             if (empty($keyworded) || count($keyworded) == 1 && $keyworded[0] == '0') {
             } else {
                 // There are properties with those keywords to redirect
                 foreach ($searchingfor as $sf) {
                     $urlextend[] = 'tag:' . $sf;
                 }
             }
         }
         if (!empty($tagsearch)) {
             foreach ($tagsearch as $tag) {
                 $urlextend[] = 'tag:' . $tag;
             }
         }
         if (empty($urlextend)) {
             $urlextend[] = 'keyword:' . urlencode($search);
         }
         if (!empty($metasearch)) {
             foreach ((array) $metasearch as $key => $value) {
                 $fac = $this->property->get_metaforfac($key);
                 if (!empty($fac)) {
                     $urlextend[] = $this->make_url($fac->metaname) . ':' . urlencode($value);
                 }
             }
         }
         $urlextend[] = "searchfor:" . urlencode($search);
         $url = sp_get_permalink('search', false, implode('/', $urlextend));
         $url = apply_filters('staypress_search_redirect_url', $url);
         wp_safe_redirect($url);
         exit;
     }
 }
 function widget($args, $instance)
 {
     global $wpdb;
     extract($args);
     $defaults = array('title' => '', 'ownertype' => 'define', 'owner' => '', 'shownumber' => '25');
     foreach ($defaults as $key => $value) {
         if (isset($instance[$key])) {
             $defaults[$key] = $instance[$key];
         }
     }
     extract($defaults);
     $this->property =& new property_model($wpdb, false);
     switch ($ownertype) {
         case 'define':
             if (defined('STAYPRESS_ON_PROPERTY_PAGE')) {
                 $property_id = (int) STAYPRESS_ON_PROPERTY_PAGE;
             }
             $properties = $this->get_properties_owned_by($property_id, $shownumber);
             break;
         case 'ownerid':
             $owner_id = (int) $owner;
             $properties = $this->get_properties_with_owner_id($owner_id, $shownumber);
             break;
         case 'ownername':
             $ownername = $owner;
             $properties = $this->get_properties_with_owner_name($ownername, $shownumber);
             break;
     }
     if (!empty($properties)) {
         echo $before_widget;
         $title = apply_filters('widget_title', $title);
         if (!empty($title)) {
             echo $before_title . $title . $after_title;
         }
         $count = 1;
         echo "<ul class='propertythumbnaillist'>";
         foreach ((array) $properties as $key => $property) {
             if ($property_id !== false && $property_id == $property->ID) {
                 unset($properties[$key]);
                 continue;
             }
             if (has_post_thumbnail($property->ID)) {
                 echo "<li class='propertythumbnail'>";
                 echo "<div class='nearcount'>" . $count . "</div>";
                 echo "<a href='" . sp_get_permalink('property', $property) . "'>";
                 // The excerpt
                 echo "<div class='theexcerpt'>";
                 echo esc_html($property->post_excerpt);
                 echo "</div>";
                 // The image
                 echo get_the_post_thumbnail($property->ID);
                 echo "<h4>" . esc_html($property->post_title) . "</h4>";
                 echo "</a>";
                 echo "</li>";
                 $count++;
             } else {
                 unset($properties[$key]);
             }
         }
         echo "</ul> <!-- propertythumbnaillist -->";
         echo $after_widget;
         $this->enqueue_propertynear_data($properties);
     }
 }