Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dshanske committed Feb 5, 2017
1 parent 817929f commit e72fbb7
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 28 deletions.
5 changes: 4 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ module.exports = function(grunt) {
domainPath: '/languages',
potFilename: 'simple-location.pot',
type: 'wp-plugin',
exclude: [
'build/.*'
],
updateTimestamp: true
}
}
Expand All @@ -68,5 +71,5 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-copy');

// Default task(s).
grunt.registerTask('default', ['wp_readme_to_markdown', 'makepot']);
grunt.registerTask('default', ['wp_readme_to_markdown', 'makepot', 'sass']);
};
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**Tags:** geolocation, geo, maps, location, indieweb
**Stable tag:** 3.0.2
**Requires at least:** 4.7
**Tested up to:** 4.7
**Tested up to:** 4.7.2
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -20,12 +20,15 @@ Offers the opportunity to change the displayed timezone on a per-post basis for

## Other Notes ##

API Keys are required to use [Google Static Maps](https://developers.google.com/maps/documentation/javascript/get-api-key) or [Mapbox Static Maps](https://www.mapbox.com/help/create-api-access-token/).
* API Keys are required to use [Google Static Maps](https://developers.google.com/maps/documentation/javascript/get-api-key) or [Mapbox Static Maps](https://www.mapbox.com/help/create-api-access-token/).
If not provided there will be no map displayed regardless of setting. The appropriate API keys should be entered in Settings>>Media or within the admin interface at /wp-admin/options-media.php.

You can filter any query or archive by adding ?geo={all|public|text} to it to show only posts with location. Adding /geo/all to the homepage or archive pages should also work
* You can filter any query or archive by adding `?geo={all|public|text}` to it to show only public posts with location. Adding /geo/all to the homepage or archive pages should also work

The Development Version as well as support can be found on [Github](https://github.com/dshanske/simple-location).
* Chrome Users: The button that retrieves the location using the HTML5 geolocation API will not work on Chrome if your website is secure(https). This is a Chrome decision to ensure safe control of personal
data.

* The Development Version as well as support can be found on [Github](https://github.com/dshanske/simple-location).

## Venues ##

Expand All @@ -46,6 +49,12 @@ will now be required to show maps for services that require API keys.

## Changelog ##

### Version 3.0.3 ###
* Add support for queries and permalinks to show location enabled posts
* Use built-in WP timezone list generation code
* Fix error with private setting
* Put in check for improperly timezone setting to avoid exception error

### Version 3.0.2 ###
* Continuing to iterate based on initial feedback to 3.0.0
* Timezone box now hidden until checked
Expand Down
2 changes: 1 addition & 1 deletion includes/class-geo-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function init() {
}

public static function rewrite() {
add_rewrite_endpoint( 'geo', EP_ALL_ARCHIVES | EP_ROOT );
add_rewrite_endpoint( 'geo', EP_ALL_ARCHIVES | EP_ROOT );
}

public static function query_var( $vars ) {
Expand Down
14 changes: 7 additions & 7 deletions includes/class-loc-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,53 +81,53 @@ public static function admin_init() {
add_settings_section(
'sloc',
'Simple Location Map Settings',
array( 'loc_config', 'sloc_settings' ),
array( 'Loc_Config', 'sloc_settings' ),
'media'
);
add_settings_field(
'sloc_default_map_provider', // id
'Default Map Provider', // setting title
array( 'loc_config', 'map_provider_callback' ), // display callback
array( 'Loc_Config', 'map_provider_callback' ), // display callback
'media', // settings page
'sloc', // settings section
array( 'name' => 'sloc_default_map_provider' )
);
add_settings_field(
'googleapi', // id
'Google Maps API Key', // setting title
array( 'loc_config', 'string_callback' ), // display callback
array( 'Loc_Config', 'string_callback' ), // display callback
'media', // settings page
'sloc', // settings section
array( 'name' => 'sloc_google_api' )
);
add_settings_field(
'mapboxapi', // id
'Mapbox API Key', // setting title
array( 'loc_config', 'string_callback' ), // display callback
array( 'Loc_Config', 'string_callback' ), // display callback
'media', // settings page
'sloc', // settings section
array( 'name' => 'sloc_mapbox_api' )
);
add_settings_field(
'height', // id
'Map Height', // setting title
array( 'loc_config', 'number_callback' ), // display callback
array( 'Loc_Config', 'number_callback' ), // display callback
'media', // settings page
'sloc', // settings section
array( 'name' => 'sloc_height' )
);
add_settings_field(
'width', // id
'Map Width', // setting title
array( 'loc_config', 'number_callback' ), // display callback
array( 'Loc_Config', 'number_callback' ), // display callback
'media', // settings page
'sloc', // settings section
array( 'name' => 'sloc_width' )
);
add_settings_field(
'zoom', // id
'Map Zoom', // setting title
array( 'loc_config', 'number_callback' ), // display callback
array( 'Loc_Config', 'number_callback' ), // display callback
'media', // settings page
'sloc', // settings section
array( 'name' => 'sloc_zoom' )
Expand Down
3 changes: 3 additions & 0 deletions includes/class-loc-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public static function get_location($id = false) {
$loc = WP_Geo_Data::get_geodata( $id );
// 0 is private
if ( isset( $loc ) ) {
if ( '0' === $loc['public'] ) {
return '';
}
$map = Loc_Config::default_map_provider();
$map->set( $loc['latitude'], $loc['longitude'] );
$c = '';
Expand Down
149 changes: 149 additions & 0 deletions includes/class-location-controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php
/**
* Location API
*
*
*
* @package Simple Location
*/

class Location_Controller {
public static function register_routes() {
register_rest_route( 'simple_location/v1', '/reverse-address', array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( 'Location_Controller', 'reverse' ),
'args' => array(
'longitude' => array(
'required' => 'true',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
'latitude' => array(
'required' => 'true',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
),
'permissions_callback' => 'is_user_logged_in',
) )
);
register_rest_route( 'simple_location/v1', '/venue', array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( 'Location_Controller', 'get_venues' ),
'args' => array(
'longitude' => array(
'required' => 'true',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
'latitude' => array(
'required' => 'true',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
),
'permissions_callback' => 'is_user_logged_in',
),
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( 'Location_Controller', 'save_venue' ),
'args' => array(
'longitude' => array(
'required' => 'true',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
'latitude' => array(
'required' => 'true',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
),
'permissions_callback' => 'is_user_logged_in',
) )
);
register_rest_route( 'simple_location/v1', '/venue' . '/(?P<id>[\d]+)', array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( 'Location_Controller', 'get_venue_by_id' ),
'args' => array(
'longitude' => array(
'required' => 'true',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
'latitude' => array(
'required' => 'true',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
),
'permissions_callback' => 'is_user_logged_in',
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( 'Location_Controller', 'edit_venue' ),
'args' => array(
'longitude' => array(
'required' => 'true',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
'latitude' => array(
'required' => 'true',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
),
'permissions_callback' => 'is_user_logged_in',
),
array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array( 'Location_Controller', 'delete_venue' ),
'args' => array(
'longitude' => array(
'required' => 'true',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
'latitude' => array(
'required' => 'true',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function($param, $request, $key) {
return is_numeric( $param );
}
),
),
'permissions_callback' => 'is_user_logged_in',
) )
);


}

}

30 changes: 25 additions & 5 deletions includes/class-post-timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static function init() {
add_filter( 'get_the_date', array( 'Post_Timezone', 'get_the_date' ), 12, 2 );
add_filter( 'get_the_time', array( 'Post_Timezone', 'get_the_time' ), 12, 2 );
add_filter( 'get_the_modified_date' , array( 'Post_Timezone', 'get_the_date' ), 12, 2 );
add_filter( 'get_the_modified_time' , array( 'Post_Timezone', 'get_the_time'), 12, 2);
add_filter( 'get_the_modified_time' , array( 'Post_Timezone', 'get_the_time' ), 12, 2 );
add_action( 'post_submitbox_misc_actions', array( 'Post_Timezone', 'post_submitbox' ) );
add_action( 'save_post', array( 'Post_Timezone', 'postbox_save_post_meta' ) );
}
Expand All @@ -17,7 +17,6 @@ public static function post_submitbox() {
if ( 'post' === get_post_type( $post ) ) {
echo '<div class="misc-pub-section misc-pub-section-last">';
wp_nonce_field( 'timezone_override_metabox', 'timezone_override_nonce' );
$tzlist = DateTimeZone::listIdentifiers();
$timezone = get_post_meta( $post->ID, 'geo_timezone', true );
if ( ! $timezone ) {
$timezone = get_post_meta( $post->ID, '_timezone', true );
Expand All @@ -33,9 +32,13 @@ public static function post_submitbox() {
<br />
<select name="timezone" id="timezone" width="90%" <?php if ( ! $timezone ) { echo 'hidden'; }?>>
<?php
if ( ! $timezone ) {
$timezone = get_option( 'timezone_string' );
if ( ! $timezone ) {
if ( ! $timezone = get_option( 'timezone_string' ) ) {
if ( 0 === get_option( 'gmt_offset', 0 ) ) {
$timezone = UTC;
}
}
}

echo wp_timezone_choice( $timezone );
echo '</select>';
Expand Down Expand Up @@ -72,7 +75,13 @@ public static function postbox_save_post_meta( $post_id ) {
}
}
if ( isset( $_POST['override_timezone'] ) ) {
update_post_meta( $post_id, 'geo_timezone', $_POST['timezone'] );
$tzlist = DateTimeZone::listIdentifiers();
// For now protect against non-standard timezones
if ( in_array( $_POST['timezone' ], $tzlist ) ) {
update_post_meta( $post_id, 'geo_timezone', $_POST['timezone'] );
} else {
error_log( 'SLOC Timezone Set Error: ' . $_POST['timezone'] . ' not supported' );
}
} else {
delete_post_meta( $post_id, 'geo_timezone' );
}
Expand All @@ -90,6 +99,12 @@ public static function get_the_date($the_date, $d = '' , $post = null) {
return $the_date;
}
}
if ( 1 === strlen( $timezone ) ) {
// Something Got Set Wrong
delete_post_meta( $post->ID, 'geo_timezone' );
return $the_time;
}

if ( '' === $d ) {
$d = get_option( 'date_format' );
}
Expand All @@ -109,6 +124,11 @@ public static function get_the_time($the_time, $d = '' , $post = null) {
return $the_time;
}
}
if ( 1 === strlen( $timezone ) ) {
// Something Got Set Wrong
delete_post_meta( $post->ID, 'geo_timezone' );
return $the_time;
}
if ( '' === $d ) {
$d = get_option( 'time_format' );
}
Expand Down
8 changes: 4 additions & 4 deletions languages/simple-location.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# This file is distributed under the same license as the Simple Location package.
msgid ""
msgstr ""
"Project-Id-Version: Simple Location 3.0.2\n"
"Project-Id-Version: Simple Location 3.0.3\n"
"Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/simple-location\n"
"POT-Creation-Date: 2017-01-03 01:38:41+00:00\n"
"POT-Creation-Date: 2017-02-05 03:03:14+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -173,11 +173,11 @@ msgstr ""
msgid "Clear"
msgstr ""

#: includes/class-post-timezone.php:31
#: includes/class-post-timezone.php:30
msgid "Change Displayed Timezone"
msgstr ""

#: simple-location.php:69
#: simple-location.php:84
msgid "Map Settings"
msgstr ""

Expand Down
Loading

0 comments on commit e72fbb7

Please sign in to comment.