public static function filter_the_content($content)
 {
     // Ignore unless a search was posted for this page
     $ignore = true;
     // Older search forms did not include result page id, but always location text
     if (!isset($_POST['results_page_id']) and isset($_POST['location_text'])) {
         $ignore = false;
     }
     if (isset($_POST['results_page_id']) and $_POST['results_page_id'] == get_the_ID()) {
         $ignore = false;
     }
     if ($ignore) {
         return $content;
     }
     // Remove slashes added to form input
     $_POST = stripslashes_deep($_POST);
     // Remove this filter to prevent recursion
     remove_filter('the_content', array(__CLASS__, 'filter_the_content'));
     $geo_search = new GeoMashupSearch($_POST);
     // Buffer templated results and append to content
     ob_start();
     $geo_search->load_template('search-results');
     $content .= ob_get_clean();
     // Add the filter back - it's possbible that content preprocessors will cause it to be run again
     add_filter('the_content', array(__CLASS__, 'filter_the_content'));
     return $content;
 }
Пример #2
0
 /**
  * List nearby items.
  *
  * Returns an HTML list of objects near the current reference, the current post by default.
  *
  * @since 1.5
  * @link http://github.com/cyberhobo/wordpress-geo-mashup/wiki/Tag-Reference#nearby-list
  *
  * @param string|array $args Template tag arguments.
  * @return string List HTML.
  */
 public static function nearby_list($args = '')
 {
     if (!class_exists('GeoMashupSearch')) {
         return __('Enable the geo search widget in the Geo Mashup settings to power the nearby list!', 'GeoMashup');
     }
     $default_args = array('template' => 'nearby-list', 'object_name' => 'post', 'radius' => '50');
     $args = wp_parse_args($args, $default_args);
     $template = $args['template'];
     unset($args['template']);
     if (!isset($args['near_lat']) and !isset($args['location_text'])) {
         // Look near an object
         if (isset($args['object_id'])) {
             // We were given an ID
             $object_id = $args['object_id'];
             unset($args['object_id']);
         } else {
             // Use the current loop ID
             $object_id = get_the_ID();
         }
         // Use the reference object location
         $near_location = GeoMashupDB::get_object_location($args['object_name'], $object_id);
         if ($near_location) {
             $args['near_lat'] = $near_location->lat;
             $args['near_lng'] = $near_location->lng;
             if (empty($args['exclude_object_ids'])) {
                 $args['exclude_object_ids'] = $object_id;
             } else {
                 $args['exclude_object_ids'] .= ',' . $object_id;
             }
         }
     }
     $geo_search = new GeoMashupSearch($args);
     ob_start();
     $geo_search->load_template($template);
     return ob_get_clean();
 }
Пример #3
0
 function test_small_search()
 {
     require_once GEO_MASHUP_DIR_PATH . '/geo-mashup-search.php';
     $found_post = $this->factory->post->create_and_get();
     $location = GeoMashupDB::blank_location();
     $location->lat = 45.61806;
     $location->lng = 5.226046;
     GeoMashupDB::set_object_location('post', $found_post->ID, $location, false);
     $search_args = array('near_lat' => 45.6181, 'near_lng' => 5.226, 'object_name' => 'post', 'radius' => 0.5, 'units' => 'km', 'geo_mashup_search_submit' => 'Search');
     $search = new GeoMashupSearch($search_args);
     $this->assertTrue($search->have_posts(), 'Search did not find any posts.');
     $this->assertContains($found_post->ID, $search->get_the_IDs(), 'Search did not find the target post.');
 }