From e72fbb77bf5910bcaade7779b4f3c7a089d3b209 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Sat, 4 Feb 2017 21:04:00 -0600 Subject: [PATCH] Fixes --- Gruntfile.js | 5 +- README.md | 17 ++- includes/class-geo-meta.php | 2 +- includes/class-loc-config.php | 14 +-- includes/class-loc-view.php | 3 + includes/class-location-controller.php | 149 +++++++++++++++++++++++++ includes/class-post-timezone.php | 30 ++++- languages/simple-location.pot | 8 +- phpcs.ruleset.xml | 17 +++ readme.txt | 17 ++- simple-location.php | 19 +++- 11 files changed, 253 insertions(+), 28 deletions(-) create mode 100644 includes/class-location-controller.php create mode 100644 phpcs.ruleset.xml diff --git a/Gruntfile.js b/Gruntfile.js index 22c39b7..eecc5b8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -55,6 +55,9 @@ module.exports = function(grunt) { domainPath: '/languages', potFilename: 'simple-location.pot', type: 'wp-plugin', + exclude: [ + 'build/.*' + ], updateTimestamp: true } } @@ -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']); }; diff --git a/README.md b/README.md index c21e6d7..ce5f4dc 100755 --- a/README.md +++ b/README.md @@ -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 @@ -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 ## @@ -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 diff --git a/includes/class-geo-meta.php b/includes/class-geo-meta.php index b10cfa3..ba4648a 100644 --- a/includes/class-geo-meta.php +++ b/includes/class-geo-meta.php @@ -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 ) { diff --git a/includes/class-loc-config.php b/includes/class-loc-config.php index e05fff3..216154a 100644 --- a/includes/class-loc-config.php +++ b/includes/class-loc-config.php @@ -81,13 +81,13 @@ 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' ) @@ -95,7 +95,7 @@ public static function admin_init() { 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' ) @@ -103,7 +103,7 @@ public static function admin_init() { 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' ) @@ -111,7 +111,7 @@ public static function admin_init() { 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' ) @@ -119,7 +119,7 @@ public static function admin_init() { 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' ) @@ -127,7 +127,7 @@ public static function admin_init() { 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' ) diff --git a/includes/class-loc-view.php b/includes/class-loc-view.php index 9411d10..ec3fcd1 100755 --- a/includes/class-loc-view.php +++ b/includes/class-loc-view.php @@ -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 = ''; diff --git a/includes/class-location-controller.php b/includes/class-location-controller.php new file mode 100644 index 0000000..6437547 --- /dev/null +++ b/includes/class-location-controller.php @@ -0,0 +1,149 @@ + 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[\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', + ) ) + ); + + + } + +} + diff --git a/includes/class-post-timezone.php b/includes/class-post-timezone.php index 741c578..b130a48 100644 --- a/includes/class-post-timezone.php +++ b/includes/class-post-timezone.php @@ -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' ) ); } @@ -17,7 +17,6 @@ public static function post_submitbox() { if ( 'post' === get_post_type( $post ) ) { echo '
'; 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 ); @@ -33,9 +32,13 @@ public static function post_submitbox() {