";
$unixtime = strtotime( $ride->start_date_local );
$response .= sprintf( __("On %s %s", "wp-strava"), date_i18n( get_option( 'date_format' ), $unixtime ), date_i18n( get_option( 'time_format' ), $unixtime ) );
diff --git a/lib/RideShortcode.class.php b/lib/RideShortcode.class.php
index 8113310..5353519 100644
--- a/lib/RideShortcode.class.php
+++ b/lib/RideShortcode.class.php
@@ -1,16 +1,17 @@
@@ -70,7 +71,7 @@ class WPStrava_RideShortcode {
}
} // handler
- static function printScripts() {
+ public static function printScripts() {
if (self::$add_script) {
wp_enqueue_style('wp-strava-style');
diff --git a/lib/SOM.class.php b/lib/SOM.class.php
index 4bd8ee0..1453a24 100644
--- a/lib/SOM.class.php
+++ b/lib/SOM.class.php
@@ -11,9 +11,9 @@ abstract class WPStrava_SOM {
require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMMetric.class.php';
return new WPStrava_SOMMetric();
}
-
+
}
-
+
abstract public function distance( $m );
abstract public function distance_inverse( $dist );
abstract public function get_distance_label();
@@ -29,4 +29,4 @@ abstract class WPStrava_SOM {
public function get_time_label() {
return __( 'hours', 'wp-strava' );
}
-}
\ No newline at end of file
+}
diff --git a/lib/Settings.class.php b/lib/Settings.class.php
index f1d7a42..2936ec8 100644
--- a/lib/Settings.class.php
+++ b/lib/Settings.class.php
@@ -2,7 +2,7 @@
/**
* v3 - http://strava.github.io/api/v3/oauth/
- *
+ *
* Set up an "API Application" at Strava
* Save the Client ID and Client Secret in WordPress - redirect to strava oauth/authorize URL for permission
* Get redirected back to this settings page with ?code= or ?error=
@@ -15,12 +15,12 @@ class WPStrava_Settings {
private $token;
private $page_name = 'wp-strava-options';
private $option_page = 'wp-strava-settings-group';
-
+
//register admin menus
public function hook() {
add_action( 'admin_init', array( $this, 'register_strava_settings' ) );
add_action( 'admin_menu', array( $this, 'add_strava_menu' ) );
- add_filter( 'pre_set_transient_settings_errors', array( $this, 'maybe_oauth' ), 10 );
+ add_filter( 'pre_set_transient_settings_errors', array( $this, 'maybe_oauth' ) );
add_filter( 'plugin_action_links_' . WPSTRAVA_PLUGIN_NAME, array( $this, 'settings_link' ) );
//for process debugging
//add_action( 'all', array( $this, 'hook_debug' ) );
@@ -35,27 +35,31 @@ class WPStrava_Settings {
* This runs after options are saved
*/
public function maybe_oauth( $value ) {
- //redirect only if all the right options are in place
- if ( isset( $value[0]['type'] ) && $value[0]['type'] == 'updated' ) { //make sure there were no settings errors
- if ( isset( $_POST['option_page'] ) && $_POST['option_page'] == $this->option_page ) { //make sure we're on our settings page
- //user is clearing to start-over, don't oauth
+ // Redirect only if all the right options are in place.
+ if ( isset( $value[0]['type'] ) && $value[0]['type'] == 'updated' ) { // Make sure there were no settings errors.
+ if ( isset( $_POST['option_page'] ) && $_POST['option_page'] == $this->option_page ) { // Make sure we're on our settings page.
+
+ // User is clearing to start-over, don't oauth.
if ( isset( $_POST['strava_token'] ) && empty( $_POST['strava_token'] ) )
return;
-
- $client_id = get_option( 'strava_client_id' );
- $client_secret = get_option( 'strava_client_secret' );
- if ( $client_id && $client_secret ) {
- $redirect = admin_url( "options-general.php?page={$this->page_name}" );
- $url = "https://www.strava.com/oauth/authorize?client_id={$client_id}&response_type=code&redirect_uri={$redirect}&approval_prompt=force";
- wp_redirect( $url );
- exit();
+ // Only re-auth if client ID and secret were shown.
+ if ( ! empty( $_POST['strava_client_id'] ) && ! empty( $_POST['strava_client_secret'] ) ) {
+ $client_id = get_option( 'strava_client_id' );
+ $client_secret = get_option( 'strava_client_secret' );
+
+ if ( $client_id && $client_secret ) {
+ $redirect = admin_url( "options-general.php?page={$this->page_name}" );
+ $url = "https://www.strava.com/oauth/authorize?client_id={$client_id}&response_type=code&redirect_uri={$redirect}&approval_prompt=force";
+ wp_redirect( $url );
+ exit();
+ }
}
}
}
return $value;
}
-
+
public function add_strava_menu() {
add_options_page( __( 'Strava Settings', 'wp-strava' ),
__( 'Strava', 'wp-strava' ),
@@ -79,14 +83,14 @@ class WPStrava_Settings {
add_settings_error( 'strava_token', 'strava_token', sprintf( __( 'Error authenticating at Strava: %s', 'wp-strava' ), str_replace( '_', ' ', $_GET['error'] ) ) );
}
}
-
- $this->token = get_option( 'strava_token' );
+
+ $this->token = get_option( 'strava_token' );
}
-
+
public function register_strava_settings() {
$this->init();
-
- add_settings_section( 'strava_api', __( 'Strava API', 'wp-strava' ), array( $this, 'print_api_instructions' ), 'wp-strava' ); //NULL / NULL no section label needed
+
+ add_settings_section( 'strava_api', __( 'Strava API', 'wp-strava' ), array( $this, 'print_api_instructions' ), 'wp-strava' );
if ( ! $this->token ) {
register_setting( $this->option_page, 'strava_client_id', array( $this, 'sanitize_client_id' ) );
@@ -98,41 +102,59 @@ class WPStrava_Settings {
register_setting( $this->option_page, 'strava_token', array( $this, 'sanitize_token' ) );
add_settings_field( 'strava_token', __( 'Strava Token', 'wp-strava' ), array( $this, 'print_token_input' ), 'wp-strava', 'strava_api' );
}
-
- register_setting( $this->option_page, 'strava_som', array( $this, 'sanitize_som' ) );
- add_settings_section( 'strava_options', __( 'Options', 'wp-strava' ), NULL, 'wp-strava' );
+ // Google Maps API.
+ register_setting( $this->option_page, 'strava_gmaps_key', array( $this, 'sanitize_gmaps_key' ) );
+ add_settings_section( 'strava_gmaps', __( 'Google Maps', 'wp-strava' ), array( $this, 'print_gmaps_instructions' ), 'wp-strava' );
+ add_settings_field( 'strava_gmaps_key', __( 'Static Maps Key', 'wp-strava' ), array( $this, 'print_gmaps_key_input' ), 'wp-strava', 'strava_gmaps' );
+ // System of Measurement.
+ register_setting( $this->option_page, 'strava_som', array( $this, 'sanitize_som' ) );
+ add_settings_section( 'strava_options', __( 'Options', 'wp-strava' ), null, 'wp-strava' );
add_settings_field( 'strava_som', __( 'System of Measurement', 'wp-strava' ), array( $this, 'print_som_input' ), 'wp-strava', 'strava_options' );
+
+ // Clear cache.
+ register_setting( $this->option_page, 'strava_cache_clear', array( $this, 'sanitize_cache_clear' ) );
+ add_settings_section( 'strava_cache', __( 'Cache', 'wp-strava' ), null, 'wp-strava' );
+ add_settings_field( 'strava_cache_clear', __( 'Clear cache (images & transient data)', 'wp-strava' ), array( $this, 'print_clear_input' ), 'wp-strava', 'strava_cache' );
}
public function print_api_instructions() {
$signup_url = 'http://www.strava.com/developers';
$settings_url = 'https://www.strava.com/settings/api';
$blog_name = get_bloginfo( 'name' );
- $app_name = $blog_name . ' Strava';
- $url_parts = parse_url( site_url() );
- $site_url = $url_parts['host']; //strip http/https for copying/pasting into strava
+ $app_name = sprintf( esc_html( '%s Strava', 'wp-strava' ), $blog_name );
+ $site_url = site_url();
$description = 'WP-Strava for ' . $blog_name;
printf( __( "
Steps:
- - Create your API Application here: %s using the following information:
+ - Create your free API Application/Connection here: %s using the following information:
- Application Name: %s
- Website: %s
- Application Description: %s
- Authorization Callback Domain: %s
- - Once you've created your API Application at strava.com, enter the Client ID and Client Secret below, which can be found at %s
+ - Once you've created your API Application at strava.com, enter the Client ID and Client Secret below, which can now be found on that same strava API Settings page.
- After saving your Client ID and Secret, you'll be redirected to strava to authorize your API Application. If successful, your Strava Token will display instead of Client ID and Client Secret.
- If you need to re-authorize your API Application, erase your Strava Token here and click 'Save Changes' to start over.
-
", 'wp-strava' ), $signup_url, $signup_url, $app_name, $site_url, $description, $site_url, $settings_url, $settings_url );
+ ", 'wp-strava' ), $settings_url, $settings_url, $app_name, $site_url, $description, $site_url );
}
-
+
+ public function print_gmaps_instructions() {
+ $maps_url = 'https://developers.google.com/maps/documentation/static-maps/';
+ printf( __( "
Steps:
+
+ - To use Google map images, you must create a Static Maps API Key. Create a free key by going here: %s and clicking Get a Key
+ - Once you've created your Google Static Maps API Key, enter the key below.
+
", 'wp-strava' ), $maps_url, $maps_url );
+
+ }
+
public function print_strava_options() {
?>