Skip to content

Commit

Permalink
Finer Control of Textual Display and Improved Meta UI
Browse files Browse the repository at this point in the history
  • Loading branch information
dshanske committed Jul 11, 2015
1 parent db1eaf3 commit eacdc9c
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 135 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Simple Location #
**Contributors:** dshanske
**Tags:** location, indieweb
**Stable tag:** 2.0.3
**Stable tag:** 2.1.0
**Requires at least:** 4.0
**Tested up to:** 4.2
**License:** GPLv2 or later
Expand Down Expand Up @@ -38,6 +38,10 @@ used to store geodata about a post.

## Changelog ##

### Version 2.1.0 ###
* Revamp in Text Display Parameters, now offering three levels of Detail
* Coordinates will now display and Location will link to map if set for full address

### Version 2.0.3 ###
* Google Static Maps now link to Google Maps
* Nominatim now defaultly tries to retrieve in the language of the blog
Expand Down
13 changes: 8 additions & 5 deletions includes/class-google-map-static.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
// Google Map Provider
class google_map_static implements map_provider {
public function reverse_lookup($lat, $lon, $zoom=18, $alt = NULL) {
public static function reverse_lookup($lat, $lon, $zoom=18, $alt = NULL) {
$response = wp_remote_get('https://maps.googleapis.com/maps/api/geocode/json?latlng=' . $lat . ',' . $lon);
$json = json_decode($response['body'], true);
$address = $json['results'][0]['address_components'];
Expand All @@ -16,21 +16,24 @@ public function reverse_lookup($lat, $lon, $zoom=18, $alt = NULL) {
}

// Return code for map
public function get_the_map_url($lat, $lon, $height=300, $width=300, $zoom=14) {
public static function get_the_map_url($lat, $lon, $height=300, $width=300, $zoom=14) {
$map = 'https://maps.googleapis.com/maps/api/staticmap?markers=color:red%7Clabel:P%7C' . $lat . ',' . $lon . '&size=' . $height . 'x' . $width;
return $map;
}

public static function get_the_map_link($lat, $lon) {
return 'http://maps.google.com/maps?q=loc:' . $lat . ',' . $lon;
}

// Return code for map
public function get_the_map($lat, $lon, $height=300, $width=300, $zoom=14) {
$link = 'http://maps.google.com/maps?q=loc:' . $lat . ',' . $lon;
public static function get_the_map($lat, $lon, $height=300, $width=300, $zoom=14) {
$link = self::get_the_map_link($lat, $lon);
$map = self::get_the_map_url($lat, $lon, $height, $width, $zoom);
$c = '<a href="' . $link . '"><img src="' . $map . '" /></a>';
return $c;
}

public function the_map($lat, $lon, $height=300, $width=300, $zoom=14) {
public static function the_map($lat, $lon, $height=300, $width=300, $zoom=14) {
echo self::get_the_map($lat, $lon, $height, $width, $zoom);
}
}
58 changes: 20 additions & 38 deletions includes/class-loc-postmeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ public static function location_metabox( $object, $box ) {
?>
<p>
<label for="geo_public"><?php _e( "Display Text Location", 'simple-location' ); ?></label>
<input type="checkbox" name="geo_public" id="geo_public" <?php checked(get_post_meta( $object->ID, 'geo_public', true ), "1" ); ?>" />
<?php $public = get_post_meta( $object->ID, 'geo_public', true ); ?>
<select name="geo_public">
<option value="0" <?php selected($public, 0 ); ?>>Don't Display</option>
<option value="1" <?php selected($public, 1 ); ?>>Show Region</option>
<option value="2" <?php selected($public, 2 ); ?>>Show Locality</option>
<option value="3" <?php selected($public, 3 ); ?>>Show Address</option>
</select>

<label for="geo_full"><?php _e( "Full Address", 'simple-location' ); ?></label>
<input type="checkbox" name="geo_full" id="geo_full" <?php checked(get_post_meta( $object->ID, 'geo_full', true ), "1" ); ?>" />

<label for="geo_map"><?php _e( "Display Map and Coordinates", 'simple-location' ); ?></label>
<label for="geo_map"><?php _e( "Display Map if Showing Address", 'simple-location' ); ?></label>
<input type="checkbox" name="geo_map" id="geo_map" <?php checked(get_post_meta( $object->ID, 'geo_map', true ), "1" ); ?>" />
<br />
<br />
Expand Down Expand Up @@ -121,35 +124,22 @@ public static function address_metabox( $object, $box ) {
<label for="geo_lookup"><?php _e("Address Lookup", 'simple-location' ); ?></label>
<input type="checkbox" name="geo_lookup" id="geo_lookup" <?php checked(get_post_meta( $object->ID, 'geo_lookup', true ), "1" ); ?>" />
<br />
<label for="geo_address"><?php _e( "Display Name", 'simple-location' ); ?></label>
<br />
<input type="text" name="geo_address" id="geo_address" value="<?php echo get_post_meta( $object->ID, 'geo_address', true); ?>" size="70" />
<label for="name"><?php _e( "Location Name", 'simple-location' ); ?></label>
<input type="text" name="name" id="name" value="<?php echo ifset($address['name'], ""); ?>" size="30" />
<label for="street-address"><?php _e( "Address", 'simple-location' ); ?></label>
<input type="text" name="street-address" id="street-address" value="<?php echo ifset($address['street-address'], ""); ?>" size="30" />
</p>

<p>
<label for="street-address"><?php _e( "Street Address", 'simple-location' ); ?></label>
<br />
<input type="text" name="street-address" id="street-address" value="<?php echo ifset($address['street-address'], ""); ?>" size="70" />
</p>
<p>
<label for="extended-address"><?php _e( "Extended Address", 'simple-location' ); ?></label>
<br />
<input type="text" name="extended-address" id="extended-address" value="<?php echo ifset($address['extended-address'], ""); ?>" size="70" />
</p>
<p>
<label for="extended-address"><?php _e( "Neighborhood/Suburb", 'simple-location' ); ?></label>
<input type="text" name="extended-address" id="extended-address" value="<?php echo ifset($address['extended-address'], ""); ?>" size="30" />
<label for="locality"><?php _e( "City/Town/Village", 'simple-location' ); ?></label>
<br />
<input type="text" name="locality" id="locality" value="<?php echo ifset($address['locality'], ""); ?>" size="70" />
<input type="text" name="locality" id="locality" value="<?php echo ifset($address['locality'], ""); ?>" size="30" />
</p>
<p>
<label for="region"><?php _e( "State/County/Province", 'simple-location' ); ?></label>
<br />
<input type="text" name="region" id="region" value="<?php echo ifset($address['region'], ""); ?>" size="70" />
</p>
<p>
<input type="text" name="region" id="region" value="<?php echo ifset($address['region'], ""); ?>" size="30" />
<label for="country-name"><?php _e( "Country", 'simple-location' ); ?></label>
<br />
<input type="text" name="country-name" id="country-name" value="<?php echo ifset($address['country-name'], ""); ?>" size="70" />
<input type="text" name="country-name" id="country-name" value="<?php echo ifset($address['country-name'], ""); ?>" size="30" />
</p>
<?php
}
Expand Down Expand Up @@ -194,16 +184,7 @@ public static function locationbox_save_post_meta( $post_id ) {
else {
delete_post_meta( $post_id, 'geo_longitude');
}
$public= $_POST[ 'geo_public' ];
if($public)
update_post_meta($post_id, 'geo_public', 1);
else
update_post_meta($post_id, 'geo_public', 0);
$full= $_POST[ 'geo_full' ];
if($full)
update_post_meta($post_id, 'geo_full', 1);
else
update_post_meta($post_id, 'geo_full', 0);
update_post_meta($post_id, 'geo_public', $_POST[ 'geo_public' ]);
$map= $_POST[ 'geo_map' ];
if($map)
update_post_meta($post_id, 'geo_map', 1);
Expand All @@ -223,6 +204,7 @@ public static function addressbox_save_post_meta( $post_id ) {
* because the save_post action can be triggered at other times.
*/
// Check if our nonce is set.
$reverse = new osm_static();
if ( ! isset( $_POST['address_metabox_nonce'] ) ) {
return;
}
Expand All @@ -248,7 +230,7 @@ public static function addressbox_save_post_meta( $post_id ) {
$adr = array();
if($lookup) {
if ( !empty( $_POST[ 'geo_latitude' ] ) && !empty( $_POST[ 'geo_longitude' ] ) ) {
$reverse_adr = osm_static::reverse_lookup($_POST['geo_latitude'], $_POST['geo_longitude']);
$reverse_adr = $reverse->reverse_lookup($_POST['geo_latitude'], $_POST['geo_longitude']);
update_post_meta( $post_id, 'mf2_adr', $reverse_adr );
}
update_post_meta($post_id, 'geo_lookup', 0);
Expand Down
94 changes: 44 additions & 50 deletions includes/class-loc-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,59 @@ public static function get_the_geodata($id = false) {
$loc['public'] = get_post_meta( $id, 'geo_public', true );
$loc['address'] = get_post_meta( $id, 'geo_address', true );
$loc['map'] = get_post_meta( $id, 'geo_map', true );
$loc['full'] = get_post_meta( $id, 'geo_full', true );
if ($address!=false) {
$loc['adr'] = array_pop($address);
}
return $loc;
}
public static function get_location($id = false) {
$loc = self::get_the_geodata($id);
if($loc['public']!='1') {
$map = new google_map_static();
if( isset ($loc['adr']) ) {
$adr = $loc['adr'];
}
else {
$adr = array();
}
$final = array();
if($loc['public']==0) {
return "";
}
if($loc['full']!='1') {
return self::get_the_adr($loc['adr']);
$c = '<span class="h-adr adr">';
if( isset($adr['name']) ) {
$final[] = '<span class="p-name name">' . $adr['name'] . '</span>';
}
if ($loc['public']==3) {
if( isset($adr['street-address']) ) {
$final[] = '<span class="p-street-address street-address">' . $adr['street-address'] . '</span>';
}
if( isset($adr['extended-address']) ) {
$final[] = '<span class="p-extended-address extended-address">' . $adr['extended-address'] . '</span>';
}
}
if ($loc['public']>=2) {
if( isset($adr['locality']) ) {
$final[] = '<span class="p-locality locality">'. $adr['locality'] . '</span>';
}
}
if( isset($adr['region']) ) {
$final[] = '<span class="p-region region">' . $adr['region'] . '</span>';
}
if( isset($adr['country-name']) ) {
$final[] = '<span class="p-country-name country-name">' . $adr['country-name'] . '</span>';
}
$c .= implode(", ", $final);
if ($loc['public']==3) {
$c .= self::get_the_geo($loc['latitude'], $loc['longitude']);
$c = '<a href="' . $map->get_the_map_link($loc['latitude'], $loc['longitude']) . '">' . $c . '</span></a>';
}
else{
return self::get_the_full_adr($loc['adr']);
else {
$c .= '</span>';
}
return $c;



}

public static function get_map($id = false) {
Expand All @@ -46,10 +82,10 @@ public static function get_map($id = false) {
'zoom' => '14'
);
}
if(($loc['map']!='1')||($loc['public']!='1')) {
if(($loc['map']!='1')||($loc['public']!=3)) {
return "";
}
return self::get_the_geo($loc['latitude'], $loc['longitude']) . google_map_static::get_the_map($loc['latitude'], $loc['longitude'], $config['height'], $config['width'], $config['zoom']);
return google_map_static::get_the_map($loc['latitude'], $loc['longitude'], $config['height'], $config['width'], $config['zoom']);
}

// Return marked up coordinates
Expand All @@ -61,48 +97,6 @@ public static function get_the_geo($lat, $lon) {
return $c;
}

public static function get_the_full_adr($loc) {
$c = '<span class="h-adr adr">';
if( isset($loc['name']) ) {
$c .= '<span class="p-name name">' . $loc['name'] . '</span>, ';
}
if( isset($loc['street-address']) ) {
$c .= '<span class="p-street-address street-address">' . $loc['street-address'] . '</span>, ';
}
if( isset($loc['extended-address']) ) {
$c .= '<span class="p-extended-address extended-address">' . $loc['extended-address'] . '</span>, ';
}
if( isset($loc['locality']) ) {
$c .= '<span class="p-locality locality">'. $loc['locality'] . '</span>, ';
}
if( isset($loc['region']) ) {
$c .= '<span class="p-region region">' . $loc['region'] . '</span>, ';
}
if( isset($loc['country-name']) ) {
$c .= '<span class="p-country-name country-name">' . $loc['country-name'] . '</span>';
}
$c .= '</span>';
return $c;
}

public static function get_the_adr($loc) {
$c = '<span class="h-adr adr">';
if( isset($loc['name']) ) {
$c .= '<span class="p-name name">' . $loc['name'] . '</span>, ';
}
if( isset($loc['locality']) ) {
$c .= '<span class="p-locality locality">'. $loc['locality'] . '</span>, ';
}
if( isset($loc['region']) ) {
$c .= '<span class="p-region region">' . $loc['region'] . '</span>, ';
}
if( isset($loc['country-name']) ) {
$c .= '<span class="p-country-name country-name">' . $loc['country-name'] . '</span>';
}
$c .= '</span>';
return $c;
}

public static function location_content($content) {
$loc = self::get_location();
if(!empty($loc)) {
Expand Down
18 changes: 13 additions & 5 deletions includes/class-osm-static.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
// OSM Static Map Provider
class osm_static implements map_provider {
public function reverse_lookup($lat, $lon, $zoom=18, $alt = NULL) {
public static function reverse_lookup($lat, $lon, $zoom=18, $alt = NULL) {
$response = wp_remote_get('http://nominatim.openstreetmap.org/reverse?format=json&lat=' . $lat . '&lon=' . $lon . '&zoom=' . $zoom . '&accept-language=' . get_bloginfo('language') );
$json = json_decode($response['body'], true);
$address = $json['address'];
Expand All @@ -20,27 +20,35 @@ public function reverse_lookup($lat, $lon, $zoom=18, $alt = NULL) {
'region' => $region,
'country-name' => $address['country'] ?: null,
'postal-code' => $address['postcode'] ?: null,
'country-code' => $address['country_code'] ?: null,
'country-code' => strtoupper($address['country_code']) ?: null,
'latitude' => $lat,
'longitude' => $lon,
'altitude' => $alt,
'raw' => $address
);
if (is_null($addr['country-name']) ) {
$codes = json_decode(wp_remote_retrieve_body(wp_remote_get('http://country.io/names.json')), true);
$addr['country-name'] = $codes[$addr['country-code']];
}
return array_filter($addr);
}

public function get_the_map_url($lat, $lon, $height=300, $width=300, $zoom=14) {
public static function get_the_map_url($lat, $lon, $height=300, $width=300, $zoom=14) {
$map = plugin_dir_url( __FILE__ ) . 'staticmap.php?center=' . $lat . ',' . $lon . '&zoom=' . $zoom . '&size=' . $width . 'x' . $height . '&markers=' . $lat . ',' . $lon . '&maptype=mapnik';
return $map;
}

public static function get_the_map_link($lat, $lon) {
return 'http://www.openstreetmap.org/#map=14/' . $lat . '/' . $lon;
}

// Return code for map linked to OSM
public function get_the_map($lat, $lon, $height=300, $width=300, $zoom=14) {
public static function get_the_map($lat, $lon, $height=300, $width=300, $zoom=14) {
$c = '<img src="' . self::get_the_map_url($lat, $long, $height, $width, $zoom) . '" />';
return $c;
}

public function the_map($lat, $lon, $height=300, $width=300, $zoom=14) {
public static function the_map($lat, $lon, $height=300, $width=300, $zoom=14) {
echo get_the_map($lat, $lon, $height, $width, $zoom);
}
}
6 changes: 6 additions & 0 deletions includes/class-post-timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public static function init() {

public static function get_the_date($the_date, $d = '' , $post = null) {
$post = get_post( $post );
if (!$post) {
return $the_date;
}
$timezone = get_post_meta( $post->ID, '_timezone', true );
if ( !$timezone ) {
return $the_date;
Expand All @@ -29,6 +32,9 @@ public static function get_the_date($the_date, $d = '' , $post = null) {

public static function get_the_time($the_time, $d = '' , $post = null) {
$post = get_post( $post );
if (!$post) {
return $the_time;
}
$timezone = get_post_meta( $post->ID, '_timezone', true );
if ( !$timezone ) {
return $the_time;
Expand Down
Loading

0 comments on commit eacdc9c

Please sign in to comment.