diff --git a/includes/WPStrava/ActivityShortcode.php b/includes/WPStrava/ActivityShortcode.php
index 1bbb3bd..e6f8890 100644
--- a/includes/WPStrava/ActivityShortcode.php
+++ b/includes/WPStrava/ActivityShortcode.php
@@ -112,11 +112,14 @@ class WPStrava_ActivityShortcode {
private function get_table( $activity_details, $som ) {
$strava_som = WPStrava_SOM::get_som( $som );
$strava_activitytype = WPStrava_ActivityType::get_type_group( $activity_details->type );
- $avg_speed = '';
- $max_speed = '';
- $speed_label = '';
$avg_title = '
' . __( 'Average Speed', 'wp-strava' ) . ' | ';
$max_title = '' . __( 'Max Speed', 'wp-strava' ) . ' | ';
+ $elevation_title = '' . __( 'Elevation Gain', 'wp-strava' ) . ' | ';
+ $avg_speed = '';
+ $max_speed = '';
+ $elevation = '' . $strava_som->elevation( $activity_details->total_elevation_gain ) . ' | ';
+ $speed_label = '';
+ $elevation_label = '' . $strava_som->get_elevation_label() . ' | ';
switch ( $strava_activitytype ) {
case WPStrava_ActivityType::TYPE_GROUP_PACE:
@@ -140,6 +143,12 @@ class WPStrava_ActivityShortcode {
break;
}
+ if ( WPStrava::get_instance()->settings->hide_elevation ) {
+ $elevation = '';
+ $elevation_title = '';
+ $elevation_label = '';
+ }
+
return '
@@ -149,7 +158,7 @@ class WPStrava_ActivityShortcode {
| ' . __( 'Distance', 'wp-strava' ) . ' |
' . $avg_title . '
' . $max_title . '
- ' . __( 'Elevation Gain', 'wp-strava' ) . ' |
+ ' . $elevation_title . '
@@ -159,7 +168,7 @@ class WPStrava_ActivityShortcode {
' . $strava_som->distance( $activity_details->distance ) . ' |
' . $avg_speed . '
' . $max_speed . '
- ' . $strava_som->elevation( $activity_details->total_elevation_gain ) . ' |
+ ' . $elevation . '
| ' . $strava_som->get_time_label() . ' |
@@ -167,7 +176,7 @@ class WPStrava_ActivityShortcode {
' . $strava_som->get_distance_label() . ' |
' . $speed_label . '
' . $speed_label . '
- ' . $strava_som->get_elevation_label() . ' |
+ ' . $elevation_label . '
diff --git a/includes/WPStrava/LatestActivities.php b/includes/WPStrava/LatestActivities.php
index d8c9cbf..b28ec10 100644
--- a/includes/WPStrava/LatestActivities.php
+++ b/includes/WPStrava/LatestActivities.php
@@ -55,8 +55,12 @@ class WPStrava_LatestActivities {
$response .= sprintf( __( ' went %1$s %2$s', 'wp-strava' ), $som->distance( $activity->distance ), $som->get_distance_label() );
// Translators: "during 2 hours"
$response .= sprintf( __( ' during %1$s %2$s', 'wp-strava' ), $som->time( $activity->elapsed_time ), $som->get_time_label() );
- // Translators: "climbing 100 ft."
- $response .= sprintf( __( ' climbing %1$s %2$s', 'wp-strava' ), $som->elevation( $activity->total_elevation_gain ), $som->get_elevation_label() );
+
+ if ( ! WPStrava::get_instance()->settings->hide_elevation ) {
+ // Translators: "climbing 100 ft."
+ $response .= sprintf( __( ' climbing %1$s %2$s', 'wp-strava' ), $som->elevation( $activity->total_elevation_gain ), $som->get_elevation_label() );
+ }
+
$response .= '';
}
$response .= '';
diff --git a/includes/WPStrava/RouteShortcode.php b/includes/WPStrava/RouteShortcode.php
index a3a758e..a0b997a 100644
--- a/includes/WPStrava/RouteShortcode.php
+++ b/includes/WPStrava/RouteShortcode.php
@@ -110,25 +110,37 @@ class WPStrava_RouteShortcode {
*/
private function get_table( $route_details, $som ) {
$strava_som = WPStrava_SOM::get_som( $som );
+
+
+ $elevation_title = '' . __( 'Elevation Gain', 'wp-strava' ) . ' | ';
+ $elevation = '' . $strava_som->elevation( $route_details->elevation_gain ) . ' | ';
+ $elevation_label = '' . $strava_som->get_elevation_label() . ' | ';
+
+ if ( WPStrava::get_instance()->settings->hide_elevation ) {
+ $elevation = '';
+ $elevation_title = '';
+ $elevation_label = '';
+ }
+
return '
| ' . __( 'Est. Moving Time', 'wp-strava' ) . ' |
' . __( 'Distance', 'wp-strava' ) . ' |
- ' . __( 'Elevation Gain', 'wp-strava' ) . ' |
+ ' . $elevation_title . '
| ' . $strava_som->time( $route_details->estimated_moving_time ) . ' |
' . $strava_som->distance( $route_details->distance ) . ' |
- ' . $strava_som->elevation( $route_details->elevation_gain ) . ' |
+ ' . $elevation . '
| ' . $strava_som->get_time_label() . ' |
' . $strava_som->get_distance_label() . ' |
- ' . $strava_som->get_elevation_label() . ' |
+ ' . $elevation_label . '
diff --git a/includes/WPStrava/SOM.php b/includes/WPStrava/SOM.php
index 485bfb8..11c4edb 100644
--- a/includes/WPStrava/SOM.php
+++ b/includes/WPStrava/SOM.php
@@ -33,9 +33,13 @@ abstract class WPStrava_SOM {
* Create a time string of hours:minutes:seconds from just seconds.
*
* @return string Time formatted as 'H:i:s'.
+ * @see https://stackoverflow.com/a/20870843/2146022
*/
public function time( $seconds ) {
- return date( 'H:i:s', mktime( 0, 0, $seconds ) );
+ $zero = new DateTime( '@0' );
+ $offset = new DateTime( "@{$seconds}" );
+ $diff = $zero->diff( $offset );
+ return sprintf( '%02d:%02d:%02d', $diff->days * 24 + $diff->h, $diff->i, $diff->s );
}
/**
diff --git a/includes/WPStrava/Settings.php b/includes/WPStrava/Settings.php
index 6638284..582c21d 100644
--- a/includes/WPStrava/Settings.php
+++ b/includes/WPStrava/Settings.php
@@ -16,13 +16,24 @@ class WPStrava_Settings {
private $option_page = 'wp-strava-settings-group';
private $adding_athlete = true;
- //register admin menus
+ /**
+ * Register actions & filters for menus and authentication.
+ *
+ * @author Justin Foell
+ * @since 0.62
+ */
public function hook() {
add_action( 'admin_init', array( $this, 'register_strava_settings' ), 20 );
add_action( 'admin_menu', array( $this, 'add_strava_menu' ) );
add_filter( 'plugin_action_links_' . WPSTRAVA_PLUGIN_NAME, array( $this, 'settings_link' ) );
}
+ /**
+ * Add the strava settings menu.
+ *
+ * @author Justin Foell
+ * @since 0.62
+ */
public function add_strava_menu() {
add_options_page(
__( 'Strava Settings', 'wp-strava' ),
@@ -33,6 +44,12 @@ class WPStrava_Settings {
);
}
+ /**
+ * Register settings using the WP Settings API.
+ *
+ * @author Justin Foell
+ * @since 0.62
+ */
public function register_strava_settings() {
add_settings_section( 'strava_api', __( 'Strava API', 'wp-strava' ), array( $this, 'print_api_instructions' ), 'wp-strava' );
@@ -71,9 +88,11 @@ class WPStrava_Settings {
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' );
- // Hide Time Option.
+ // Hide Options.
register_setting( $this->option_page, 'strava_hide_time', array( $this, 'sanitize_hide_time' ) );
add_settings_field( 'strava_hide_time', __( 'Hide Activity Time', 'wp-strava' ), array( $this, 'print_hide_time_input' ), 'wp-strava', 'strava_options' );
+ register_setting( $this->option_page, 'strava_hide_elevation', array( $this, 'sanitize_hide_elevation' ) );
+ add_settings_field( 'strava_hide_elevation', __( 'Hide Activity Elevation', 'wp-strava' ), array( $this, 'print_hide_elevation_input' ), 'wp-strava', 'strava_options' );
// Clear cache.
register_setting( $this->option_page, 'strava_cache_clear', array( $this, 'sanitize_cache_clear' ) );
@@ -81,6 +100,12 @@ class WPStrava_Settings {
add_settings_field( 'strava_cache_clear', __( 'Clear cache (images & transient data)', 'wp-strava' ), array( $this, 'print_clear_input' ), 'wp-strava', 'strava_cache' );
}
+ /**
+ * Print the Strava setup instructions.
+ *
+ * @author Justin Foell
+ * @since 0.62
+ */
public function print_api_instructions() {
$settings_url = 'https://www.strava.com/settings/api';
$icon_url = 'https://plugins.svn.wordpress.org/wp-strava/assets/icon-128x128.png';
@@ -118,6 +143,12 @@ class WPStrava_Settings {
);
}
+ /**
+ * Print the google maps instructions.
+ *
+ * @author Justin Foell
+ * @since 1.1
+ */
public function print_gmaps_instructions() {
$maps_url = 'https://developers.google.com/maps/documentation/static-maps/';
printf( __( "Steps:
@@ -127,22 +158,46 @@ class WPStrava_Settings {
", 'wp-strava' ), $maps_url, $maps_url );
}
+ /**
+ * Print the settings page container.
+ *
+ * @author Justin Foell
+ * @since 0.62
+ */
public function print_strava_options() {
include WPSTRAVA_PLUGIN_DIR . 'templates/admin-settings.php';
}
+ /**
+ * Print the client ID input
+ *
+ * @author Justin Foell
+ * @since 1.2.0
+ */
public function print_client_input() {
?>
+ * @since 1.2.0
+ */
public function print_secret_input() {
?>
+ * @since 1.2.0
+ */
public function print_nickname_input() {
$nickname = $this->ids_empty( $this->ids ) ? __( 'Default', 'wp-strava' ) : '';
?>
@@ -150,6 +205,14 @@ class WPStrava_Settings {
+ * @since 2.0
+ */
public function print_id_input() {
foreach ( $this->get_all_ids() as $id => $nickname ) {
?>
@@ -160,6 +223,14 @@ class WPStrava_Settings {
}
}
+ /**
+ * Sanitize the client ID.
+ *
+ * @param string $client_id
+ * @return string
+ * @author Justin Foell
+ * @since 1.2.0
+ */
public function sanitize_client_id( $client_id ) {
// Return early if not trying to add an additional athlete.
if ( ! $this->adding_athlete ) {
@@ -172,6 +243,14 @@ class WPStrava_Settings {
return $client_id;
}
+ /**
+ * Sanitize the client secret.
+ *
+ * @param string $client_secret
+ * @return string
+ * @author Justin Foell
+ * @since 1.2.0
+ */
public function sanitize_client_secret( $client_secret ) {
// Return early if not trying to add an additional athlete.
if ( ! $this->adding_athlete ) {
@@ -184,6 +263,14 @@ class WPStrava_Settings {
return $client_secret;
}
+ /**
+ * Sanitize the nicknames - make sure we've got the same number of nicknames sa tokens.
+ *
+ * @param array $nicknames Nicknames for the athletes saved.
+ * @return array
+ * @author Justin Foell
+ * @since 1.2.0
+ */
public function sanitize_nickname( $nicknames ) {
if ( ! $this->adding_athlete ) {
@@ -211,20 +298,50 @@ class WPStrava_Settings {
return $nicknames;
}
+ /**
+ * Sanitize the ID.
+ *
+ * Renamed from sanitize_token().
+ *
+ * @param string $token
+ * @return string
+ * @author Justin Foell
+ * @since 2.0
+ */
public function sanitize_id( $id ) {
return $id;
}
+ /**
+ * Print the GMaps key input.
+ *
+ * @author Justin Foell
+ * @since 1.1
+ */
public function print_gmaps_key_input() {
?>
+ * @since 1.1
+ */
public function sanitize_gmaps_key( $key ) {
return $key;
}
+ /**
+ * Print System of Measure option.
+ *
+ * @author Justin Foell
+ * @since 0.62
+ */
public function print_som_input() {
?>