(.*),(.*),0", true); define('yahoo_regexp', "(.*)<\/Latitude>.*(.*)<\/Longitude>", true); define('yahoo_geocoder', 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=geocodewordpress&location=', true); define('yahoo_annotatedmaps', 'http://api.maps.yahoo.com/Maps/V1/AnnotatedMaps?appid=geocodewordpress&xmlsrc=', true); define('yahoo_embedpngmapurl', 'http://api.local.yahoo.com/MapsService/V1/mapImage?appid=geocodewordpress&', true); define('GEOPRESS_USE_ZIP', true); define('GEOPRESS_FETCH_TIMEOUT', 2); define('GEOPRESS_USER_AGENT', 'GeoPress2.0', false); define('GEOPRESS_LOCATION', 'geopress/', false); define('GEOPRESS_VERSION', '2.4.3', false); if ( !function_exists('Snoopy') ) { require_once(ABSPATH.WPINC.'/class-snoopy.php'); error_reporting(E_ERROR); } function geocode($location, $geocoder) { if($geocoder == null) { $geocoder = "yahoo"; } if( !preg_match('/\[(.+),[ ]?(.+)\]/', $location, $matches) ) { $client = new Snoopy(); $client->agent = GEOPRESS_USER_AGENT; $client->read_timeout = GEOPRESS_FETCH_TIMEOUT; $client->use_gzip = GEOPRESS_USE_GZIP; if($geocoder == 'google') { $url = google_geocode . urlencode($location); $regexp = google_regexp; } elseif($geocoder == 'yahoo') { $url = yahoo_geocoder . urlencode($location); $regexp = yahoo_regexp; } @$client->fetch($url); $xml = $client->results; $lat = ""; $lon = ""; $latlong = ""; if ($geocoder == 'google' && preg_match("/$regexp/", $xml, $latlong)) { $lat = trim($latlong[1]); $lon = trim($latlong[2]); } elseif ($geocoder == 'yahoo' && preg_match("/$regexp/", $xml, $latlong)) { $lat = trim($latlong[1]); $lon = trim($latlong[2]); } } else { $lat = trim($matches[1]); $lon = trim($matches[2]); } return array($lat, $lon); } function yahoo_geocode($location) { if( !preg_match('/\[(.+),[ ]?(.+)\]/', $location, $matches) ) { $client = new Snoopy(); $client->agent = GEOPRESS_USER_AGENT; $client->read_timeout = GEOPRESS_FETCH_TIMEOUT; $client->use_gzip = GEOPRESS_USE_GZIP; $url = yahoo_geocoder . urlencode($location); @$client->fetch($url); $xml = $client->results; $lat = ""; $lon = ""; $latlong = ""; if (preg_match("/(.*)<\/Latitude>.*(.*)<\/Longitude>/", $xml, $latlong)) { $lat = $latlong[1]; $lon = $latlong[2]; } } else { $lat = $matches[1]; $lon = $matches[2]; } return array($lat, $lon); } // Converts a zoom from 1 (world) to 18 (closest) to Yahoo coords: 1 (close) 12(country) function yahoo_zoom($zoom) { return ceil(12 / $zoom); } function yahoo_mapurl($location) { $client = new Snoopy(); $client->agent = GEOPRESS_USER_AGENT; $client->read_timeout = GEOPRESS_FETCH_TIMEOUT; $client->use_gzip = GEOPRESS_USE_GZIP; $mapwidth = get_settings('_geopress_mapwidth', true); $mapheight= get_settings('_geopress_mapheight', true); $url = yahoo_embedpngmapurl . "image_width=" . $mapwidth . "&image_height=" . $mapheight; $url .= "&zoom=" . (yahoo_zoom( GeoPress::mapstraction_map_zoom())); // TODO: put in an appropriate conversion function // Get the image for a location, or just lat/lon if( !preg_match('/\[(.+),[ ]?(.+)\]/', $location, $matches) ) { $url .= "&location=" . urlencode($location); } else { $url .= "&latitude=" . $matches[1] . "&longitude=" . $matches[2]; } @$client->fetch($url); $xml = $client->results; $mapinfo = ""; if (preg_match("/(.*)<\/Result>/", $xml, $mapinfo)) { $warn = $mapinfo[1]; $mapurl = $mapinfo[2]; } return array($warn, $mapurl); } class GeoPress { function install() { global $table_prefix, $wpdb; // Do a dbDelta to make any necessary updates to the database depending on previous GeoPress version $table_name = $table_prefix . "geopress"; $sql = "CREATE TABLE $table_name ( id int(11) NOT NULL AUTO_INCREMENT, name tinytext NOT NULL, loc tinytext, warn tinytext, mapurl tinytext, coord text NOT NULL, geom varchar(16) NOT NULL, relationshiptag tinytext, featuretypetag tinytext, elev float, floor float, radius float, visible tinyint(4) DEFAULT 1, map_format tinytext DEFAULT '', map_zoom tinyint(4) DEFAULT 0, map_type tinytext DEFAULT '', UNIQUE KEY id (id) );"; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); // One time change necessary to convert from id to geopress_id $update_to_geopress_id = 0; $sql = "DESCRIBE $table_name;"; $tablefields = $wpdb->get_results( $sql ); foreach($tablefields as $tablefield) { if(strtolower($tablefield->Field) == "id") { $update_to_geopress_id = 1; break; } } if($update_to_geopress_id) { $sql = "ALTER TABLE $table_name CHANGE id geopress_id int(11) NOT NULL auto_increment;"; $result = $wpdb->get_results( $sql ); } // default options add_option('_geopress_mapwidth', "400"); add_option('_geopress_mapheight', "200"); add_option('_geopress_rss_enable', "true"); add_option('_geopress_rss_format', "simple"); add_option('_geopress_map_format', "google"); add_option('_geopress_map_type', 'hybrid'); add_option('_geopress_controls_pan', true); add_option('_geopress_controls_map_type', true); add_option('_geopress_controls_zoom', "small"); add_option('_geopress_controls_overview', false); add_option('_geopress_controls_scale', true); add_option('_geopress_default_add_map', 0); add_option('_geopress_default_zoom_level', "11"); $ping_sites = get_option("ping_sites"); if( !preg_match('/mapufacture/', $ping_sites, $matches) ) { update_option("ping_sites", $ping_sites . "\n" . "http://mapufacture.com/georss/ping/api"); } } // Returns an array of locations, each key containing the array of posts at the at location function get_location_posts ($number = -1) { global $table_prefix, $wpdb; $geopress_table = $table_prefix . "geopress"; $sql = "SELECT * FROM $geopress_table, $wpdb->postmeta"; $sql .= " INNER JOIN $wpdb->posts ON $wpdb->posts.id = $wpdb->postmeta.post_id"; $sql .= " WHERE $wpdb->postmeta.meta_key = '_geopress_id'"; $sql .= " AND $wpdb->postmeta.meta_value = $geopress_table.geopress_id"; $sql .= " AND coord != ''"; if($number >= 0) { $sql .= " LIMIT ".$number; } $result = $wpdb->get_results( $sql ); // Build a hash of Location => Posts @ location $locations = array(); foreach ($result as $loc) { if($locations[$loc->name] == null) { $locations[$loc->name] = array(); } array_push($locations[$loc->name], $loc); } return $locations; } function get_locations ($number = -1) { global $table_prefix, $wpdb; $geopress_table = $table_prefix . "geopress"; $sql = "SELECT * FROM $geopress_table"; $sql .= " INNER JOIN $wpdb->postmeta ON $wpdb->postmeta.meta_key = '_geopress_id'"; $sql .= " AND $wpdb->postmeta.meta_value = $geopress_table.geopress_id"; $sql .= " WHERE coord != '' GROUP BY 'name'"; if($number >= 0) { $sql .= " LIMIT ".$number; } $result = $wpdb->get_results( $sql ); // echo $sql; // debug return $result; } // dfraga - Getting loop locations function get_loop_locations ($locations = -1) { $result = ""; $i = 0; while (have_posts()) { the_post(); // echo "get_loop_locations: -> ".get_the_ID()." -> ".get_the_title()."
"; $geo = GeoPress::get_geo(get_the_ID()); if ($geo != "") { $result[] = $geo; $i++; if ($i == $locations) { break; } } } // Build a hash of Location => Posts @ location $locations = array(); foreach ($result as $loc) { if($locations[$loc->name] == null) { $locations[$loc->name] = array(); } array_push($locations[$loc->name], $loc); } return $locations; } // function get_bounds($locations) { // // lat = 0; // // lon = 0; // // zoom = 1; // latbounds = [MAXINT, -MAXINT]; // lonbounds = [MAXINT, -MAXINT]; // if(count($locations) > 0) { // foreach($locations as $loc) { // $coords = split(" ",$loc->coord); // lat += $loc->coords[0]; // lon += $loc->coords[0]; // if(lat > latbounds[1]) latbounds[1] = lat; // if(lat < latbounds[0]) latbounds[0] = lat; // if(lon > lonbounds[1]) lonbounds[1] = lon; // if(lon < lonbounds[0]) lonbounds[0] = lon; // // } // // lat = lat / count($locations); // // lon = lon / count($locations); // } // return [latbounds[0],lonbounds[0],latbounds[1],lonbounds[1]]; // } function get_geo ($id) { global $table_prefix, $wpdb; // // $sql = "SELECT * FROM $geopress_table"; // $sql .= " INNER JOIN $wpdb->postmeta ON $wpdb->postmeta.meta_key = '_geopress_id'"; // $sql .= " AND $wpdb->postmeta.meta_value = $geopress_table.geopress_id"; // $sql .= " WHERE AND coord != '' GROUP BY 'name'"; // if($number >= 0) { // $sql .= " LIMIT ".$number; // } $geopress_table = $table_prefix . "geopress"; $geo_id = get_post_meta($id,'_geopress_id',true); if ($geo_id) { $sql = "SELECT * FROM $geopress_table, $wpdb->postmeta"; $sql .= " INNER JOIN $wpdb->posts ON $wpdb->posts.id = $wpdb->postmeta.post_id"; $sql .= " WHERE $wpdb->postmeta.meta_key = '_geopress_id'"; $sql .= " AND $wpdb->postmeta.meta_value = $geopress_table.geopress_id"; $sql .= " AND $wpdb->postmeta.post_id = $id AND $geopress_table.geopress_id = $geo_id"; $row = $wpdb->get_results( $sql ); return $row[0]; } } function get_location ($loc_id) { if ($loc_id) { global $table_prefix, $wpdb; $table_name = $table_prefix . "geopress"; $sql = "SELECT * FROM ".$table_name." WHERE geopress_id = ".$loc_id; $row = $wpdb->get_row( $sql ); return $row; } } // Store the location and map parameters to the database function save_geo ($id, $name,$loc,$coord,$geom,$warn,$mapurl,$visible = 1,$map_format = '', $map_zoom = 0, $map_type = '') { global $table_prefix, $wpdb; if($name == "") { $visible = 0; } $table_name = $table_prefix . "geopress"; if($id && $id != -1) { $sql = "SELECT * FROM $table_name WHERE geopress_id = $id"; } else { $sql = "SELECT * FROM $table_name WHERE (name = '$name' AND coord = '$coord') OR loc = '$loc'"; } $row = $wpdb->get_row( $sql ); //TODO SQL INJECTION POSSIBLE? if ($row) { $geo_id = $row->geopress_id; $sql = "UPDATE ".$table_name." SET name = '$name', loc = '$loc', coord = '$coord', geom = '$geom', warn = '$warn', mapurl = '$mapurl', visible = '$visible', map_format = '$map_format', map_zoom = '$map_zoom', map_type = '$map_type' WHERE geopress_id = '$geo_id'"; $wpdb->query( $sql ); } else { $sql = "INSERT INTO ".$table_name." VALUES (NULL,'$name','$loc','$warn','$mapurl','$coord','$geom',NULL,NULL,NULL,NULL,NULL,'$visible','$map_format','$map_zoom','$map_type')"; $wpdb->query( $sql ); $geo_id = mysql_insert_id(); } return $geo_id; } function default_loc() { global $table_prefix, $wpdb; $table_name = $table_prefix . "geopress"; $sql = "SELECT * FROM ".$table_name." LIMIT 1"; $result = $wpdb->get_results( $sql ); foreach ($result as $row) { return $row->loc; } } function select_saved_geo () { global $table_prefix, $wpdb; $table_name = $table_prefix . "geopress"; $sql = "SELECT * FROM ".$table_name." WHERE visible = 1"; $result = $wpdb->get_results( $sql ); foreach ($result as $row) { echo "\n"; } } function map_saved_locations ($locations) { global $table_prefix, $wpdb; $output = geopress_map_select(); $output .= ""; echo $output; } function location_edit_form () { global $post_ID; $geo = GeoPress::get_geo($post_ID); ?>

' . __('Location','GeoPress') . '

'; $loc = $geo->loc; $geometry = $geo->coord; $locname = $geo->name; echo '
'; echo ' '; echo ' '; echo ""; echo '
'.__('Saved Name', 'GeoPress').' '.__('Location Name, Address, or [Latitude, Longitude]', 'GeoPress').'
Map Location
'; echo ''; echo '

'; echo '
'.__('Saved Locations', 'GeoPress').' '; echo geopress_map_select(); echo '
Reset Map

'; // echo ' // // // // '; // If there is already a geo location - map it if($geo) { ?> '; } function geopress_admin_page() { echo "

Locations

"; } function geopress_documentation_page() { echo '

GeoPress Documentation

'; ?>

About GeoPress

GeoPress is a tool to help you embed geographic locations into your blog posts, and also include this information in your RSS/Atom syndicated feeds using the GeoRSS standard.

To begin using GeoPress, write a new article and enter a location name a geographic address in the appropriate fields. Press enter, or click the Geocode button to verify on the map that this is the appropriate location. Additionally, you can click on the map to set a location. Once you save your post, the geographic location is stored with the post entry. If you want to just enter latitude and longitude, then enter [latitude, longitude] into the address field.

Notice to users of WordPress 2.1+: there are now default privacy settings that prevent your blog from pinging Blog aggregators like Technorati or Mapufacture, or being searched by Google. To change your privacy settings, go to "Options" -> "Privacy" and allow your blog to be visible by anyone. This will let aggregators and search engines allow users and readers to find your blog.

Adding to your post

You can insert a dynamic map into your post automatically by selecting "Automatically add a map after any post" in the GeoPress options tab. This map will be inserted at the end of any post that has a location set for it.

Alternatively, you can manually insert a map by putting INSERT_MAP anywhere in your post text. The map will use the default map size as sent in your GeoPress options. You can override this size by passing in INSERT_MAP(height,width), where height and width are the size of the map, in pixels.

You can also insert the geographic coordinates, or address of the post by using INSERT_COORDS, and INSERT_ADDRESS, respectively. These will be output using Microformat styling.

INSERT_LOCATION will put in the stored name of the location into a post.

A map of all your geotagged posts can be inserted by using INSERT_GEOPRESS_MAP(height,width).

You can set the location of a post within the body of the post itself by using GEOPRESS_LOCATION(Location String), where Location String can be any text that normally works in the GeoPress location box. For example address, city, region, country, etc. You can also post coordinates by doing GEOPRESS_LOCATION([latitude,longitude]). An alternative is to use machine-tags in the Post, like tags: geo:long=24.9419260025024 geo:lat=60.1587851399795, for example. These two mechanisms make it easy to add GeoPress locations when using an offline blog client, or when posting by email or SMS.

Limitations

Currently, GeoPress only supports a single geographic coordinate. In the future it will support lines, polygons, and multiple points.

Template Functions

These functions are available from GeoPress to further customize embedding geographic information into your blog. The Post functions return information about a specific post, or entry, and should be placed within the the_post() section of your templates. General functions can be used anywhere in your blog template and will return information pertaining to all of your geographic locations (such as maps, lists, links to locations)

General Functions

The following functions return the output. This allows you to perform any processing on the return text that you may want. To finally place the result in your template, use echo. For example, to output the stored address: <?php echo the_address(); ?>

  • geopress_map(height, width, num_locs): returns a GeoPress map of the last num_locs number of locations. If no value is set for num_locs, then all locations are plotted. caution: plotting all locations could slow down/prevent people viewing your blog.

Post Functions

  • has_location(): returns 'true' if the post has a location, 'false' if no location was set
  • geopress_post_map(height, width, controls): returns a GeoPress map of the current post's location. height, width sets the map size in pixels. controls is boolean if you want controls or no controls
  • the_coord(): returns the coordinates for the post as an array, latitude, longitude
  • the_address(): returns the address for the post
  • the_location_name(): returns the saved name for the post's location
  • the_geo_mf(): returns the coordinates of the post in Microformat geo format
  • the_adr_mf(): returns the address of the post in Microformat adr format
  • the_loc_mf(): returns the location name of the post in Microformat hCard format

Template Functions

GeoPress provides the ability to view all the posts at a specific location by putting "location=#" in the url, where # is the id number of the location, or "location=savedname", where savedname is the the name of the location (e.g. Home or Trafalgar Square)

  • geopress_location_name(): prints out the name of the location if it is passed in by the url..
  • geopress_locations_list(): prints out an unordered list of locations and links to display posts at that location.
'; } function geopress_locations_page() { if(isset($_POST['Options'])) { for($i = 0; $i < count($_POST['locname']);$i++) { // If the user set the locations via the web interface, don't change it here. if( !preg_match('/\[(.+),[ ]?(.+)\]/', $_POST['geometry'], $matches) ) { list($lat, $lon) = geocode($_POST['locaddr'][$i]); } else { $lat = $matches[1]; $lon = $matches[2]; } list($warn, $mapurl) = yahoo_mapurl($_POST['locaddr'][$i]); $geo_id = GeoPress::save_geo($_POST['locid'][$i], $_POST['locname'][$i], $_POST['locaddr'][$i], "$lat $lon", "point", $warn, $mapurl, $_POST['locvisible'][$i]); } echo '

' . __('Locations updated.', 'GeoPress') . '

'; } echo '

Configure Locations

'; echo '
'; global $table_prefix, $wpdb; $table_name = $table_prefix . "geopress"; $sql = "SELECT * FROM ".$table_name; $result = $wpdb->get_results( $sql ); echo ' '; $i = -1; foreach ($result as $loc) { $i++; if($loc->visible) { $checked = "checked='checked'";} else {$checked = "";} ?> \n"; } echo '
'.__('Show', 'GeoPress').' '.__('Name', 'GeoPress').' '.__('Address', 'GeoPress').' '.__('Geometry', 'GeoPress').'
/>
'; GeoPress::map_saved_locations($result); echo '
'; } function geopress_maps_page() { if(isset($_POST['Options'])) { $default_mapwidth = $_POST['default_mapwidth']; $default_mapheight = $_POST['default_mapheight']; $default_zoom_level = $_POST['default_zoom_level']; $map_controls_type = $_POST['map_controls_type']; $map_view_type = $_POST['map_view_type']; $map_controls_pan = $_POST['map_controls_pan']; $map_controls_map_type = $_POST['map_controls_map_type']; $map_controls_zoom = $_POST['map_controls_zoom']; $map_controls_overview = $_POST['map_controls_overview']; $map_controls_scale = $_POST['map_controls_scale']; $map_format = $_POST['map_format']; update_option('_geopress_map_format', $map_format); update_option('_geopress_mapwidth', $default_mapwidth); update_option('_geopress_mapheight', $default_mapheight); update_option('_geopress_map_type', $map_view_type); update_option('_geopress_controls_pan', $map_controls_pan); update_option('_geopress_controls_map_type', $map_controls_map_type); update_option('_geopress_controls_zoom', $map_controls_zoom); update_option('_geopress_controls_overview', $map_controls_overview); update_option('_geopress_controls_scale', $map_controls_scale); update_option('_geopress_default_zoom_level', $default_zoom_level); echo '

' . __('Map layout updated.', 'GeoPress') . '

'; } $map_format = get_settings('_geopress_map_format', true); $default_mapwidth = get_settings('_geopress_mapwidth', true); $default_mapheight = get_settings('_geopress_mapheight', true); $default_zoom_level = get_settings('_geopress_default_zoom_level', true); $map_view_type = get_settings('_geopress_map_type', true); $map_controls_zoom = get_settings('_geopress_controls_zoom', true); $map_controls_pan = get_settings('_geopress_controls_pan ', true) ? 'checked="checked"' : ''; $map_controls_overview = get_settings('_geopress_controls_overview', true) ? 'checked="checked"' : ''; $map_controls_scale = get_settings('_geopress_controls_scale', true) ? 'checked="checked"' : ''; $map_controls_map_type = get_settings('_geopress_controls_map_type', true) ? 'checked="checked"' : ''; echo '

Configure Map Layout

'; ?>

About

This page configures the default map that will appear with posts and when you use INSERT_MAP. By setting the map size, default zoom level, and various controls that appear, you can customize how the maps on your site look.

Unfortunately, not all mapping providers (Google, Yahoo, or Microsoft) support turning on or off some of the controls to the right. Therefore, some of your settings may not appear correct when displayed on certain mapping providers. For example, Yahoo maps doesn't currently allow for removing the zoom control.

Default Map

'; echo "
".geopress_map('','',1,false)."
\n"; ?>
:
px
px
"; echo str_replace("value='$default_zoom_level'>","value='$default_zoom_level' selected='selected'>", $select); ?>
: "; echo str_replace("value='$map_format'>","value='$map_format' selected='selected'>", $select); ?> Changing to Microsoft Maps requires saving your options
: "; echo str_replace("value='$map_view_type'>","value='$map_view_type' selected='selected'>", $select); ?>
: "; echo str_replace("value='$map_controls_zoom'>","value='$map_controls_zoom' selected='selected'>", $select); ?>
/> (Yahoo)
/> (Google)
/> (Google)
/> (Google)
'; } function geopress_options_page() { if(isset($_POST['Options'])) { $default_rss_enable = $_POST['georss_enable']; $default_add_map = $_POST['default_add_map']; $rss_format = $_POST['georss_format']; $google_apikey = $_POST['google_apikey']; $yahoo_appid = $_POST['yahoo_appid']; update_option('_geopress_rss_enable', $default_rss_enable); update_option('_geopress_rss_format', $rss_format); update_option('_geopress_default_add_map', $default_add_map); update_option('_geopress_google_apikey', $google_apikey); update_option('_geopress_yahoo_appid', $yahoo_appid); echo '

' . __('Map options updated.', 'GeoPress') . '

'; } $default_rss_enable = get_settings('_geopress_rss_enable', true) ? 'checked="checked"' : ''; $default_add_map = get_settings('_geopress_default_add_map', true); $rss_format = get_settings('_geopress_rss_format', true); $google_apikey = get_settings('_geopress_google_apikey', true); $yahoo_appid = get_settings('_geopress_yahoo_appid', true); ?>

Welcome to GeoPress. To begin using GeoPress, please obtain and enter a GoogleMaps and Yahoo AppID as shown below. You can customize your default map view using the "Maps" tab above. Or just go and start writing your posts!

GoogleMaps Key:
GoogleMaps API Registration -
Yahoo AppID:
Yahoo! Developer Registration
:
:
:
get_row("SELECT * FROM $wpdb->posts WHERE ID = '$id'"); $addr = $_POST['addr']; $geometry = $_POST['geometry']; $locname = $_POST['locname']; // Allow the location to be set within the post body if ((preg_match_all('/GEOPRESS_LOCATION\((.+)\)/', $postdata->post_content, $matches) > 0) ) { // $locname = $matches[1]; $addr = $matches[1][0]; } // tags: geo:long=24.9419260025024 geo:lat=60.1587851399795 elseif ((preg_match_all('/geo:lat=([-\d\.]+)(.*)?geo:lon[g]?=([-\d\.]+)/', $postdata->post_content, $matches) > 0) ) { // $locname = $matches[1]; $addr = "[".$matches[1][0].",".$matches[3][0]."]"; } else { } // $map_format = $_POST['geopress_map_format']; // $map_zoom = $_POST['geopress_map_zoom']; // $map_type = $_POST['geopress_map_type']; if ( $addr ) { // if just lat/lon coordinates were given, don't geocode if( !preg_match('/\[(.+),[ ]?(.+)\]/', $addr, $matches) ) { // If the user set the coordinates via the web interface (using the geocoder), don't change it here. if( preg_match('/(.+),[ ]?(.+)/', $geometry, $matches) ) { $lat = $matches[1]; $lon = $matches[2]; } else { list($lat, $lon) = geocode($addr); } } else { $lat = $matches[1]; $lon = $matches[2]; } list($warn, $mapurl) = yahoo_mapurl($addr); $coords = "$lat $lon"; $coord_type = "point"; // Create a new loc - therefore -1 $geo_id = GeoPress::save_geo(-1, $locname, $addr, $coords, $coord_type, $warn, $mapurl, 1, $map_format, $map_zoom, $map_type); $updated = update_post_meta($id, '_geopress_id', $geo_id); if(!$updated) { add_post_meta($id, '_geopress_id', $geo_id); } } } // Replaces INSERT_MAP with a geopress map function embed_map_inpost($content) { $default_add_map = get_settings('_geopress_default_add_map', true); // If the user explicitly wants to insert a map if(preg_match_all('/INSERT_MAP/', $content, $matches) > 0) { $content = preg_replace("/INSERT_MAP\((\d+),[ ]?(\d+)\)/", geopress_post_map('\1','\2'), $content); $content = preg_replace("/INSERT_MAP/", geopress_post_map(), $content); // This can probably be made into a single preg_replace with ? optionals - ajturner // } elseif (preg_match_all('/INSERT_GEOPRESS_MAP/', $content, $matches) > 0) { $content = preg_replace("/INSERT_GEOPRESS_MAP\((\d+),[ ]?(\d+)\)/", geopress_map('\1','\2'), $content); $content = preg_replace("/INSERT_GEOPRESS_MAP/", geopress_map(), $content); // This can probably be made into a single preg_replace with ? optionals - ajturner // } elseif (($default_add_map == 2) || ( is_single() && ($default_add_map == 1))) { // Add a map to the end of the post if "automatically add map" is enabled $content .= geopress_post_map(); } $content = preg_replace("/GEOPRESS_LOCATION\((.+)\)/", "", $content); return $content; } // Replaces INSERT_COORDS or INSERT_ADDRESS with the geopress information function embed_data_inpost($content) { $content = preg_replace("/INSERT_COORDS/", the_geo_mf(), $content); $content = preg_replace("/INSERT_ADDRESS/", the_adr_mf(), $content); $content = preg_replace("/INSERT_LOCATION/", the_loc_mf(), $content); return $content; } /// /// Syndication Functions /// function atom_entry($post_ID) { if(get_settings('_geopress_rss_enable', true)) { $coord = the_coord(); if($coord != "") { the_coord_rss(); } } } function rss2_item($post_ID) { if(get_settings('_geopress_rss_enable', true)) { the_coord_rss(); } } function geopress_namespace() { if(get_settings('_geopress_rss_enable', true)) { switch(get_settings('_geopress_rss_format', true)) { case "w3c": echo 'xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"'."\n"; break; case "gml": case "simple": default: echo 'xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"'."\n"; } } } function wp_head() { echo geopress_header(); } // If the location is queried, JOIN with the postmeta table function join_clause($join) { if (((isset($_GET['location']) || $wp->query_vars['location'] != null) && $_GET['location'] != "") OR ((isset($_GET['loc']) || $wp->query_vars['loc'] != null) && $_GET['loc'] != "")) { global $wpdb, $id, $post, $posts; global $table_prefix; $geo_table_name = $table_prefix . "geopress"; $join .= " , $wpdb->postmeta, $geo_table_name "; } return $join; } // If the location is queried, add to the WHERE clause function where_clause($where) { if ((isset($_GET['location']) || $wp->query_vars['location'] != null) && $_GET['location'] != "") { global $wpdb, $id, $post, $posts; global $table_prefix; $geo_table_name = $table_prefix . "geopress"; $post_table_name = $table_prefix . "posts"; $postmeta_table_name = $table_prefix . "postmeta"; $location = $_GET['location']; $where.= " AND $geo_table_name.geopress_id = $wpdb->postmeta.meta_value AND $wpdb->posts.id = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '_geopress_id'"; // If the location= is a number, assume they're referring to the location id if( preg_match('/[0-9]+/', $location, $matches )) { $where .= " AND $wpdb->postmeta.meta_value=".mysql_real_escape_string($location); } // otherwise, look for the name else { $where .= " AND $geo_table_name.name='".mysql_real_escape_string($location)."'"; } } return $where; } // If the location is requested, and there exists a "location.php" template in // the theme, then use it function location_redirect() { if ((isset($_GET['location']) || $wp->query_vars['location'] != null) && $_GET['location'] != "") { global $posts; // $location = $wp->query_vars['loc']; $location = $_GET['location']; if($template = get_query_template('location')) { include($template); exit; } } return; } // TODO: ajturner - I'm not sure if these work properly // function register_query_var($vars) { // $vars[] = 'loc'; // return $vars; // } // function add_rewrite_tag() { // global $wp_rewrite; // $wp_rewrite->add_rewrite_tag('%loc%', '([0-9]{2})', "loc="); // } // function filter_query_string($query_string) { // return preg_replace_callback("#loc=([0-9]{2})#", array('GeoPress', 'query_string_callback'), $query_string); // } // Returns the map format (google, yahoo, microsoft, osm, etc) set in the defaults, or passed by the optional parameter function mapstraction_map_format($map_format_type = "") { if($map_format_type == "") return get_settings('_geopress_map_format', true); else return $map_format_type; } // Returns the map type (road, satellite, hybrid) set in the defaults, or passed by the optional parameter function mapstraction_map_type($map_view_type = "") { if($map_view_type == "") $map_view_type = get_settings('_geopress_map_type', true); switch($map_view_type) { case "hybrid": return 'Mapstraction.HYBRID'; break; case "road": return 'Mapstraction.ROAD'; break; case "satellite": return 'Mapstraction.SATELLITE'; break; default : return 'Mapstraction.HYBRID'; break; } } // Returns the map controls set in the defaults, or passed by the optional parameter /* pan: true, * zoom: 'large' || 'small', * overview: true, * scale: true, * map_type: true, */ function mapstraction_map_controls($pan = "", $zoom = "", $overview = "", $scale = "", $map_type = "") { if($pan == "") $map_controls_pan = get_settings('_geopress_controls_pan', true) ? 'true' : 'false'; else $map_controls_pan = $pan; if($zoom == "") $map_controls_zoom = get_settings('_geopress_controls_zoom', true); else $map_controls_zoom = $zoom; if($overview == "") $map_controls_overview = get_settings('_geopress_controls_overview', true) ? 'true' : 'false'; else $map_controls_overview = $overview; if($scale == "") $map_controls_scale = get_settings('_geopress_controls_scale', true) ? 'true' : 'false'; else $map_controls_scale = $scale; if($map_type == "") $map_controls_map_type = get_settings('_geopress_controls_map_type', true) ? 'true' : 'false'; else $map_controls_map_type = $map_type; $controls = "{\n"; $controls .= "\tpan: $map_controls_pan,\n"; $controls .= "\tzoom: '$map_controls_zoom',\n"; $controls .= "\toverview: $map_controls_overview,\n"; $controls .= "\tscale: $map_controls_scale,\n"; $controls .= "\tmap_type: $map_controls_map_type\n"; $controls .= "\t}"; return $controls; } // Returns the map zoom level set in the defaults, or passed by the optional parameter function mapstraction_map_zoom($map_zoom = 0) { if($map_zoom == 0) return get_settings('_geopress_default_zoom_level', true); else return $map_zoom; } } /// /// Wordpress Plugin Hooks /// add_action('activate_geopress/geopress.php', array('GeoPress', 'install')); // Add form to post editing add_action('edit_form_advanced', array('GeoPress', 'location_edit_form')); add_action('simple_edit_form', array('GeoPress', 'location_edit_form')); // Add form to page editing add_action('edit_page_form', array('GeoPress', 'location_edit_form')); // Handles querying for a specific location add_action('template_redirect', array('GeoPress', 'location_redirect')); add_filter('posts_join', array('GeoPress','join_clause') ); add_filter('posts_where', array('GeoPress','where_clause') ); // add_filter('query_vars', array('GeoPress','register_query_var') ); // add_filter( 'init', array('GeoPress', 'add_rewrite_tag') ); add_action('admin_head', array('GeoPress', 'admin_head')); add_action('save_post', array('GeoPress', 'update_post')); add_action('edit_post', array('GeoPress', 'update_post')); add_action('publish_post', array('GeoPress', 'update_post')); add_filter('the_content', array('GeoPress', 'embed_map_inpost')); add_action('admin_menu', array('GeoPress', 'admin_menu')); add_action('option_menu', array('GeoPress', 'geopress_options_page')); add_action('wp_head', array('GeoPress', 'wp_head')); add_action('admin_head', array('GeoPress', 'wp_head')); // XML Feed hooks // add_action('atom_ns', array('GeoPress', 'geopress_namespace')); add_action('atom_entry', array('GeoPress', 'atom_entry')); add_action('rss2_ns', array('GeoPress', 'geopress_namespace')); //add_action('rss2_head', array('GeoPress', 'rss2_head')); add_action('rss2_item', array('GeoPress', 'rss2_item')); add_action('rdf_ns', array('GeoPress', 'geopress_namespace')); //add_action('rdf_head', array('GeoPress', 'rss2_head')); add_action('rdf_item', array('GeoPress', 'rss2_item')); add_action('rss_ns', array('GeoPress', 'geopress_namespace')); //add_action('rss_head', array('GeoPress', 'rss2_head')); add_action('rss_item', array('GeoPress', 'rss2_item')); function geopress_header() { $map_format = get_settings('_geopress_map_format', true); $scripts = ""; $scripts .= ""; // if($map_format == "yahoo" ) // { $yahoo_appid = get_settings('_geopress_yahoo_appid', true); if($yahoo_appid != "") { $scripts .= "\n".''; } // } if($map_format == "microsoft") { $scripts .= "\n".' '; } $google_apikey = get_settings('_geopress_google_apikey', true); if($google_apikey != "") { $scripts .= "\n".''; } $plugindir = get_bloginfo('wpurl') . "/wp-content/plugins/geopress"; $scripts .= "\n".''; $scripts .= "\n".''; return $scripts; } /// /// User/Template Functions /// function geopress_locations_list() { $locations = GeoPress::get_locations(); foreach ($locations as $loc) { echo '
  • '.$loc->name.'
  • '; } return; } // dfraga - Debugging function added function dump_locations ($locations, $msg = "") { $string = "+ Dumping: ".$msg."
    \n"; if ($locations == "") { $string .= "- Void locations
    \n"; } foreach ($locations as $loc) { $string .= "- Location name: ".$loc->name."
    \n"; } $string .= "+ End of locations
    \n"; return $string; } // dfraga - Loop mapping added // Creates a dynamic map with the posts in "the_loop". Useful for category/search/single visualization. // $height, $width are the h/w in pixels of the map // $locations is the last N locations to put on the map, be default puts *all* locations // $unique_id is a true/false if a unique_id is required function geopress_map_loop($height = "", $width = "", $locations = -1, $zoom_level = -1) { return geopress_map ($height, $width, $locations, false, true, $zoom_level); } // Creates a dynamic map // $height, $width are the h/w in pixels of the map // $locations is the last N locations to put on the map, be default puts *all* locations // $unique_id is a true/false if a unique_id is required // $loop_locations set this to true if you're running this in a Post loop and want a map of the currently visible posts function geopress_map($height = "", $width = "", $locations = -1, $unique_id, $loop_locations = false, $zoom_level = -1) { $map_format = get_settings('_geopress_map_format', true); if ($height == "" || $width == "" ) { $height = get_settings('_geopress_mapheight', true); $width = get_settings('_geopress_mapwidth', true); } // sometimes we don't want to deal with a unique ID b/c we know there will // only be 1 map, like the select map if($unique_id) $map_id = geopress_rand_id(); else $map_id = ""; // dfraga - Getting specific locations if ($loop_locations == true) { $locs = GeoPress::get_loop_locations($locations); } else { $locs = GeoPress::get_location_posts($locations); } $output = '
    '; $output .= ' "; return $output; } $geopress_map_index = 1; function geopress_post_map($height = "", $width = "", $controls = true) { global $post, $geopress_map_index; $geo = GeoPress::get_geo($post->ID); if($geo) { if(!is_feed()) { if ($height == "" || $width == "" ) { $height = get_settings('_geopress_mapheight', true); $width = get_settings('_geopress_mapwidth', true); } $map_id = $post->ID . $geopress_map_index; $coords = split(" ",$geo->coord); $map_controls = $controls ? GeoPress::mapstraction_map_controls() : "false"; $output = '
    '; $output .= '"; } else { $output = ''; } $geopress_map_index++; } return $output; } function geopress_map_select($height=250, $width=400) { $map_format = get_settings('_geopress_map_format', true); $map_view_type = get_settings('_geopress_map_type', true); $output = '
    '; $output .= '\n"; return $output; } // Does the post have a location? function has_location() { global $post; $geo = GeoPress::get_geo($post->ID); if($geo) return true; else return false; } // Get the coordinates for a post function the_coord() { global $post; $geo = GeoPress::get_geo($post->ID); return $geo->coord; } // The Geographic coordinates in microformats // see http://microformats.org/wiki/geo function the_geo_mf() { $coord = the_coord(); $coord = split(" ", $coord); $coord_tag = "\n\t
    $coord[0], $coord[1]
    "; return $coord_tag; } // Gets the name for a location when passed in via the URL query function geopress_location_name() { if(isset($_GET['loc']) && $_GET['loc'] != "") { $loc_id = $_GET['loc']; $location = GeoPress::get_location($loc_id); return $location->name; } } // Get the address (name) for a post function the_location_name() { global $post; $geo = GeoPress::get_geo($post->ID); $addr = $geo->name; return $addr; } // Get the address (name) for a post function the_address() { global $post; $geo = GeoPress::get_geo($post->ID); $addr = $geo->loc; return $addr; } // The Address in microformats // see http://microformats.org/wiki/adr function the_adr_mf() { $addr = the_address(); $addr_tag = "\n\t
    $addr
    "; return $addr_tag; } // The Location in microformats // see http://microformats.org/wiki/adr function the_loc_mf() { $loc_name = the_location_name(); $loc_tag = "\n\t
    $loc_name
    "; return $loc_tag; } function ymap_post_url() { global $post; $coord = the_coord(); list($lat, $lon) = split(" ", $coord); return "http://maps.yahoo.com/int/index.php#lat=$lat&lon=$lon&mag=5&trf=0"; } function ymap_blog_url($type ='rss2_url') { // Note this url won't produce a valid, plottable map if you haven't // modified your wp-rss file for the type of feed you want (wp-rss.php or wp-rss2.php) $url = yahoo_annotatedmaps . bloginfo($type); return "$url"; } // Get the Coordinates in RSS format // this doesn't need to be called directly, it is added by the Plugin hooks function the_coord_rss() { $coord = the_coord(); $featurename = the_address(); $rss_format = get_settings('_geopress_rss_format', true); if($coord != "") { switch($rss_format) { case "w3c": $coord = split(" ", $coord); $coord_tag = "\t$coord[0]\n\t\t$coord[1]\n"; break; case "gml": $coord_tag = "\t\n\t\t\n\t\t\t$coord\n\t\t\n\t"; break; case "simple": // cascade to default default: $coord_tag = "\t