diff --git a/readme.txt b/readme.txt index 6c859de..6829fc0 100755 --- a/readme.txt +++ b/readme.txt @@ -122,7 +122,7 @@ On the WP-Strava settings page you cannot currently remove and add another athle = 2.9.0 = Switched Activities List to display moving time instead of elapsed time https://wordpress.org/support/topic/moving-time-instead-of-elapsed-time/ - +Added calories burned (when available) to Activity and Activities List https://wordpress.org/support/topic/calorie/ = 2.8.0 = diff --git a/src/WPStrava/ActivitiesListRenderer.php b/src/WPStrava/ActivitiesListRenderer.php index 2416edb..c80d530 100644 --- a/src/WPStrava/ActivitiesListRenderer.php +++ b/src/WPStrava/ActivitiesListRenderer.php @@ -48,7 +48,9 @@ class WPStrava_ActivitiesListRenderer { } $response = "'; diff --git a/src/WPStrava/ActivityRenderer.php b/src/WPStrava/ActivityRenderer.php index 59e2656..26ecef6 100644 --- a/src/WPStrava/ActivityRenderer.php +++ b/src/WPStrava/ActivityRenderer.php @@ -90,6 +90,8 @@ class WPStrava_ActivityRenderer { '; $avg_speed = ''; $max_speed = ''; + $calories_title = ''; + $calories = ''; switch ( $strava_activitytype ) { case WPStrava_ActivityType::TYPE_GROUP_PACE: @@ -130,6 +132,14 @@ class WPStrava_ActivityRenderer { $elevation = ''; } + if ( $activity_details->calories ) { + $calories_title = '' . __( 'Calories Burned', 'wp-strava' ) . ''; + $calories = ' +
' . $strava_som->calories( $activity_details->calories ) . '
+
' . $strava_som->get_calories_label() . '
+ '; + } + return ' @@ -140,6 +150,7 @@ class WPStrava_ActivityRenderer { ' . $avg_title . ' ' . $max_title . ' ' . $elevation_title . ' + ' . $calories_title . ' @@ -159,6 +170,7 @@ class WPStrava_ActivityRenderer { ' . $avg_speed . ' ' . $max_speed . ' ' . $elevation . ' + ' . $calories . '
diff --git a/src/WPStrava/AuthRefresh.php b/src/WPStrava/AuthRefresh.php index 1bdd6e3..ba9bbbf 100644 --- a/src/WPStrava/AuthRefresh.php +++ b/src/WPStrava/AuthRefresh.php @@ -65,7 +65,7 @@ class WPStrava_AuthRefresh extends WPStrava_Auth { 'client_id' => $client_id, 'redirect_uri' => $this->get_redirect_param(), 'approval_prompt' => 'auto', - 'scope' => 'activity:read,read', + 'scope' => 'read,activity:read', ), $this->auth_url ); diff --git a/src/WPStrava/SOM.php b/src/WPStrava/SOM.php index 0fc6e81..907d27b 100644 --- a/src/WPStrava/SOM.php +++ b/src/WPStrava/SOM.php @@ -77,4 +77,26 @@ abstract class WPStrava_SOM { return "{$min}:{$sec}"; } + + /** + * Format calories to add appropriate comma. + * + * @param string|int $kcal Kilocalories + * @author Justin Foell + * @since 2.9.0 + */ + public function calories( $kcal ) { + return number_format_i18n( $kcal, 0 ); + } + + /** + * Abbreviated label for kilocalories. + * + * @return string + * @author Justin Foell + * @since 2.9.0 + */ + public function get_calories_label() { + return __( 'kcal', 'wp-strava' ); + } } diff --git a/tests/WPStrava/SOMEnglishTest.php b/tests/WPStrava/SOMEnglishTest.php index 9124fb3..26e3d63 100644 --- a/tests/WPStrava/SOMEnglishTest.php +++ b/tests/WPStrava/SOMEnglishTest.php @@ -96,4 +96,15 @@ class WPStrava_SOMEnglishTest extends TestCase { $this->assertEquals( '61:24:31', $this->som->time( 221071 ) ); } + /** + * Test that 1304 calories is 1,304 using both string and int inputs. + * + * @author Justin Foell + * @since 2.9.0 + */ + public function test_calories() { + $this->assertEquals( '1,304', $this->som->calories( '1304' ) ); + $this->assertEquals( '1,304', $this->som->calories( 1304 ) ); + } + }