diff --git a/lib/WPStrava/ActivityShortcode.php b/lib/WPStrava/ActivityShortcode.php
index 7044b15..0cd8baf 100644
--- a/lib/WPStrava/ActivityShortcode.php
+++ b/lib/WPStrava/ActivityShortcode.php
@@ -63,7 +63,7 @@ class WPStrava_ActivityShortcode {
try {
$activity_details = $activity->get_activity( $atts['athlete_token'], $atts['id'] );
- } catch( WPStrava_Exception $e ) {
+ } catch ( WPStrava_Exception $e ) {
return $e->to_html();
}
@@ -74,6 +74,37 @@ class WPStrava_ActivityShortcode {
$map_height = str_replace( 'px', '', $map_height );
if ( $activity_details ) {
+
+ $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' ) . ' | ';
+
+ switch ( $strava_activitytype ) {
+ case WPStrava_ActivityType::TYPE_GROUP_PACE:
+ $avg_speed = '' . $strava_som->pace( $activity_details->average_speed ) . ' | ';
+ $max_speed = '' . $strava_som->pace( $activity_details->max_speed ) . ' | ';
+ $speed_label = '' . $strava_som->get_pace_label() . ' | ';
+ break;
+ case WPStrava_ActivityType::TYPE_GROUP_SPEED:
+ $avg_speed = '' . $strava_som->speed( $activity_details->average_speed ) . ' | ';
+ $max_speed = '' . $strava_som->speed( $activity_details->max_speed ) . ' | ';
+ $speed_label = '' . $strava_som->get_speed_label() . ' | ';
+ break;
+ case WPStrava_ActivityType::TYPE_GROUP_PACE:
+ $avg_speed = '' . $strava_som->swimpace( $activity_details->average_speed ) . ' | ';
+ $max_speed = '' . $strava_som->swimpace( $activity_details->max_speed ) . ' | ';
+ $speed_label = '' . $strava_som->get_swimpace_label() . ' | ';
+ break;
+ default:
+ $avg_title = '';
+ $max_title = '';
+ break;
+
+ }
+
return '
';
} // End if( $activity_details ).
}
diff --git a/lib/WPStrava/ActivityType.php b/lib/WPStrava/ActivityType.php
new file mode 100644
index 0000000..c404b15
--- /dev/null
+++ b/lib/WPStrava/ActivityType.php
@@ -0,0 +1,84 @@
+
+ * @since NEXT
+ */
+class WPStrava_ActivityType {
+
+ const TYPE_ALPINESKI = 'AlpineSki';
+ const TYPE_BACKCOUNTRYSKI = 'BackcountrySki';
+ const TYPE_CANOEING = 'Canoeing';
+ const TYPE_CROSSFIT = 'Crossfit';
+ const TYPE_EBIKERIDE = 'EBikeRide';
+ const TYPE_ELLIPTICAL = 'Elliptical';
+ const TYPE_HANDCYCLE = 'Hike';
+ const TYPE_HIKE = 'IceSkate';
+ const TYPE_ICESKATE = 'InlineSkate';
+ const TYPE_INLINESKATE = 'AlpineSki';
+ const TYPE_KAYAKING = 'Kayaking';
+ const TYPE_KITESURF = 'Kitesurf';
+ const TYPE_NORDICSKI = 'NordicSki';
+ const TYPE_RIDE = 'Ride';
+ const TYPE_ROCKCLIMBING = 'RockClimbing';
+ const TYPE_ROLLERSKI = 'RollerSki';
+ const TYPE_ROWING = 'Rowing';
+ const TYPE_RUN = 'Run';
+ const TYPE_SNOWBOARD = 'Snowboard';
+ const TYPE_SNOWSHOE = 'Snowshoe';
+ const TYPE_STAIRSTEPPER = 'StairStepper';
+ const TYPE_STANDUPPADDLING = 'StandUpPaddling';
+ const TYPE_SURFING = 'Surfing';
+ const TYPE_SWIM = 'Swim';
+ const TYPE_VIRTUALRIDE = 'VirtualRide';
+ const TYPE_VIRTUALRUN = 'VirtualRun';
+ const TYPE_WALK = 'Walk';
+ const TYPE_WEIGHTTRAINING = 'WeightTraining';
+ const TYPE_WHEELCHAIR = 'Wheelchair';
+ const TYPE_WINDSURF = 'Windsurf';
+ const TYPE_WORKOUT = 'Workout';
+ const TYPE_YOGA = 'Yoga';
+
+ const TYPE_DEFAULT = self::TYPE_RIDE;
+
+ private static $water_types = array( self::TYPE_SWIM );
+ private static $pace_types = array( self::TYPE_CANOEING, self::TYPE_HIKE, self::TYPE_RUN, self::TYPE_SNOWSHOE, self::TYPE_VIRTUALRUN, self::TYPE_WALK );
+ private static $speed_types = array( self::TYPE_ALPINESKI, self::TYPE_BACKCOUNTRYSKI, self::TYPE_EBIKERIDE, self::TYPE_ELLIPTICAL, self::TYPE_HANDCYCLE, self::TYPE_ICESKATE, self::TYPE_INLINESKATE, self::TYPE_KAYAKING, self::TYPE_KITESURF, self::TYPE_NORDICSKI, self::TYPE_RIDE, self::TYPE_ROCKCLIMBING, self::TYPE_ROLLERSKI, self::TYPE_ROWING, self::TYPE_SNOWBOARD, self::TYPE_STAIRSTEPPER, self::TYPE_STANDUPPADDLING, self::TYPE_SURFING, self::TYPE_VIRTUALRIDE, self::TYPE_WHEELCHAIR, self::TYPE_WINDSURF );
+
+ const TYPE_GROUP_WATER = 'water';
+ const TYPE_GROUP_PACE = 'pace';
+ const TYPE_GROUP_SPEED = 'speed';
+ const TYPE_GROUP_OTHER = 'other';
+
+ /**
+ * Get the type of activity.
+ *
+ * @param string $type Type provided by Strava.
+ * @return string Type group (water/pace/speed/other).
+ * @author @author Sebastian Erb
+ * @since NEXT
+ */
+ public static function get_type_group( $type ) {
+
+ if ( in_array( $type, self::$pace_types, true ) ) {
+ return self::TYPE_GROUP_PACE;
+ }
+
+ if ( in_array( $type, self::$speed_types, true ) ) {
+ return self::TYPE_GROUP_SPEED;
+ }
+
+ if ( in_array( $type, self::$water_types, true ) ) {
+ return self::TYPE_GROUP_WATER;
+ }
+
+ return self::TYPE_GROUP_OTHER;
+ }
+
+}
diff --git a/lib/WPStrava/RouteShortcode.php b/lib/WPStrava/RouteShortcode.php
index d30be37..a14ab49 100644
--- a/lib/WPStrava/RouteShortcode.php
+++ b/lib/WPStrava/RouteShortcode.php
@@ -63,7 +63,7 @@ class WPStrava_RouteShortcode {
try {
$route_details = $route->get_route( $atts['id'] );
- } catch( WPStrava_Exception $e ) {
+ } catch ( WPStrava_Exception $e ) {
return $e->to_html();
}
diff --git a/lib/WPStrava/SOM.php b/lib/WPStrava/SOM.php
index 9b9890d..e47a605 100644
--- a/lib/WPStrava/SOM.php
+++ b/lib/WPStrava/SOM.php
@@ -26,6 +26,8 @@ abstract class WPStrava_SOM {
abstract public function get_speed_label();
abstract public function elevation( $m );
abstract public function get_elevation_label();
+ abstract public function pace( $mps );
+ abstract public function get_pace_label();
public function time( $seconds ) {
return date( 'H:i:s', mktime( 0, 0, $seconds ) );
@@ -34,4 +36,27 @@ abstract class WPStrava_SOM {
public function get_time_label() {
return __( 'hours', 'wp-strava' );
}
+
+ /**
+ * Abbreviated label for this system of measure's pace - Minutes Per 100 Meters: min/100m. Same for English/metric.
+ *
+ * @return string 'min/100m'
+ */
+ public function get_swimpace_label() {
+ return __( 'min/100m', 'wp-strava' );
+ }
+
+ /**
+ * Change meters per second to Minutes Per 100 Meters. Same for English/metric.
+ *
+ * @param float $mps Meters per second.
+ * @return float Minutes Per 100 Meters.
+ */
+ public function swimpace( $mps ) {
+
+ $kmh = $mps * 3.6;
+ $min100m = 60 / $kmh / 10;
+
+ return number_format( $min100m, 2 );
+ }
}
diff --git a/lib/WPStrava/SOMEnglish.php b/lib/WPStrava/SOMEnglish.php
index 33c48e1..abf6ca1 100644
--- a/lib/WPStrava/SOMEnglish.php
+++ b/lib/WPStrava/SOMEnglish.php
@@ -55,6 +55,37 @@ class WPStrava_SOMEnglish extends WPStrava_SOM {
return __( 'mph', 'wp-strava' );
}
+ /**
+ * Change meters per second to minutes per mile.
+ *
+ * @param float $mps Meters per second.
+ * @return float Minutes Per Mile.
+ */
+ public function pace( $mps ) {
+
+ if ( ! $mps ) {
+ return __( 'N/A', 'wp-strava' );
+ }
+
+ $mph = $mps * 2.2369;
+ $s = 3600 / $mph;
+ $ss = $s / 60;
+ $ms = floor( $ss ) * 60;
+ $sec = round( $s - $ms );
+ $min = floor( $ss );
+
+ return "{$min}:{$sec}";
+ }
+
+ /**
+ * Abbreviated label for this system of measure's pace - Minutes Per Mile: min/mile
+ *
+ * @return string 'min/mile'
+ */
+ public function get_pace_label() {
+ return __( 'min/mile', 'wp-strava' );
+ }
+
/**
* Change meters to feet.
*
diff --git a/lib/WPStrava/SOMMetric.php b/lib/WPStrava/SOMMetric.php
index c357c9e..7c969df 100644
--- a/lib/WPStrava/SOMMetric.php
+++ b/lib/WPStrava/SOMMetric.php
@@ -55,6 +55,38 @@ class WPStrava_SOMMetric extends WPStrava_SOM {
return __( 'km/h', 'wp-strava' );
}
+ /**
+ * Change meters per second to minutes per kilometer.
+ *
+ * @param float $mps Meters per second.
+ * @return float Kilometers per hour.
+ */
+ public function pace( $mps ) {
+
+ if ( ! $mps ) {
+ return __( 'N/A', 'wp-strava' );
+ }
+
+ // 4 m/s => 14,4 km/h => 4:10 min/km
+ $kmh = $mps * 3.6;
+ $s = 3600 / $kmh;
+ $ss = $s / 60;
+ $ms = floor( $ss ) * 60;
+ $sec = round( $s - $ms );
+ $min = floor( $ss );
+
+ return "{$min}:{$sec}";
+ }
+
+ /**
+ * Abbreviated label for this system of measure's speed - Minutes Per Kilometers: min/km
+ *
+ * @return string 'min/km'
+ */
+ public function get_pace_label() {
+ return __( 'min/km', 'wp-strava' );
+ }
+
/**
* Change meters to meters };^)
*
diff --git a/readme.txt b/readme.txt
old mode 100755
new mode 100644
index 8297f50..c8c0348
--- a/readme.txt
+++ b/readme.txt
@@ -1,9 +1,9 @@
=== WP-Strava ===
-Contributors: cmanon, jrfoell, lancewillett, dlintott
+Contributors: cmanon, jrfoell, lancewillett, dlintott, sebastianerb
Tags: strava, activity, bicycle, cycling, biking, running, run, swimming, swim, gps, shortcode, widget, plugin
Requires at least: 4.6
-Tested up to: 4.9
+Tested up to: 5.0
Stable tag: 1.6.0
Requires PHP: 5.2
License: GPLv2 or later
@@ -78,6 +78,12 @@ WP-Strava caches activity for one hour so your site doesn't hit the Strava API o
== Changelog ==
+= NEXT =
+
+Added Sebastian Erb to contributors.
+Added Pace support (min/km) and (min/mile) for Activity Shortcode
+Added Swimpace support (min/100m) for Activity Shortcode
+
= 1.6.0 =
Added class autoloader (removed composer autoloader).
@@ -121,7 +127,7 @@ Fix array indices on map widget
= 1.4.0 =
-Added dlintott to contributors.
+Added Daniel Lintott to contributors.
Fixed non-existent settings js from being enqueued.
Changed all 'ride' styles and functions to 'activity'.
Added inline documentation.
diff --git a/wp-strava.php b/wp-strava.php
index 2cae3e8..103a06c 100755
--- a/wp-strava.php
+++ b/wp-strava.php
@@ -4,7 +4,7 @@
* Plugin URI: https://wordpress.org/plugins/wp-strava/
* Description: Show your strava.com activity on your WordPress site. Some Icons are Copyright © Yusuke Kamiyamane. All rights reserved. Licensed under a Creative Commons Attribution 3.0 license.
* Version: 1.6.0
- * Author: Carlos Santa Cruz, Justin Foell, Lance Willett, Daniel Lintott
+ * Author: Carlos Santa Cruz, Justin Foell, Lance Willett, Daniel Lintott, Sebastian Erb
* License: GPL2
* Text Domain: wp-strava
* Domain Path: /lang