Added setting to hide elevation

This commit is contained in:
Justin Foell
2019-08-02 14:23:46 -05:00
parent 9bd5380043
commit 8444866558
5 changed files with 68 additions and 11 deletions
+15 -6
View File
@@ -107,11 +107,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 = '<th>' . __( 'Average Speed', 'wp-strava' ) . '</th>';
$max_title = '<th>' . __( 'Max Speed', 'wp-strava' ) . '</th>';
$elevation_title = '<th>' . __( 'Elevation Gain', 'wp-strava' ) . '</th>';
$avg_speed = '';
$max_speed = '';
$elevation = '<td>' . $strava_som->elevation( $activity_details->total_elevation_gain ) . '</td>';
$speed_label = '';
$elevation_label = '<td>' . $strava_som->get_elevation_label() . '</td>';
switch ( $strava_activitytype ) {
case WPStrava_ActivityType::TYPE_GROUP_PACE:
@@ -135,6 +138,12 @@ class WPStrava_ActivityShortcode {
break;
}
if ( WPStrava::get_instance()->settings->hide_elevation ) {
$elevation = '';
$elevation_title = '';
$elevation_label = '';
}
return '
<table id="activity-details-table">
<thead>
@@ -144,7 +153,7 @@ class WPStrava_ActivityShortcode {
<th>' . __( 'Distance', 'wp-strava' ) . '</th>
' . $avg_title . '
' . $max_title . '
<th>' . __( 'Elevation Gain', 'wp-strava' ) . '</th>
' . $elevation_title . '
</tr>
</thead>
<tbody>
@@ -154,7 +163,7 @@ class WPStrava_ActivityShortcode {
<td>' . $strava_som->distance( $activity_details->distance ) . '</td>
' . $avg_speed . '
' . $max_speed . '
<td>' . $strava_som->elevation( $activity_details->total_elevation_gain ) . '</td>
' . $elevation . '
</tr>
<tr class="activity-details-table-units">
<td>' . $strava_som->get_time_label() . '</td>
@@ -162,7 +171,7 @@ class WPStrava_ActivityShortcode {
<td>' . $strava_som->get_distance_label() . '</td>
' . $speed_label . '
' . $speed_label . '
<td>' . $strava_som->get_elevation_label() . '</td>
' . $elevation_label . '
</tr>
</tbody>
</table>
+6 -2
View File
@@ -50,8 +50,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 .= '</div></li>';
}
$response .= '</ul>';
+15 -3
View File
@@ -105,25 +105,37 @@ class WPStrava_RouteShortcode {
*/
private function get_table( $route_details, $som ) {
$strava_som = WPStrava_SOM::get_som( $som );
$elevation_title = '<th>' . __( 'Elevation Gain', 'wp-strava' ) . '</th>';
$elevation = '<td>' . $strava_som->elevation( $route_details->elevation_gain ) . '</td>';
$elevation_label = '<td>' . $strava_som->get_elevation_label() . '</td>';
if ( WPStrava::get_instance()->settings->hide_elevation ) {
$elevation = '';
$elevation_title = '';
$elevation_label = '';
}
return '
<table id="activity-details-table">
<thead>
<tr>
<th>' . __( 'Est. Moving Time', 'wp-strava' ) . '</th>
<th>' . __( 'Distance', 'wp-strava' ) . '</th>
<th>' . __( 'Elevation Gain', 'wp-strava' ) . '</th>
' . $elevation_title . '
</tr>
</thead>
<tbody>
<tr class="activity-details-table-info">
<td>' . $strava_som->time( $route_details->estimated_moving_time ) . '</td>
<td>' . $strava_som->distance( $route_details->distance ) . '</td>
<td>' . $strava_som->elevation( $route_details->elevation_gain ) . '</td>
' . $elevation . '
</tr>
<tr class="activity-details-table-units">
<td>' . $strava_som->get_time_label() . '</td>
<td>' . $strava_som->get_distance_label() . '</td>
<td>' . $strava_som->get_elevation_label() . '</td>
' . $elevation_label . '
</tr>
</tbody>
</table>
+27
View File
@@ -505,6 +505,33 @@ class WPStrava_Settings {
return null;
}
/**
* Display the Hide Elevation Checkbox.
*
* @author Justin Foell <justin@foell.org>
* @since 1.7.2
*/
public function print_hide_elevation_input() {
?>
<input type="checkbox" id="strava_hide_elevation" name="strava_hide_elevation" <?php checked( $this->hide_elevation, 'on' ); ?>/>
<?php
}
/**
* Sanitize the Hide Elevation Checkbox.
*
* @param string $checked 'on' or null.
* @return string 'on' if checked.
* @author Justin Foell <justin@foell.org>
* @since 1.7.2
*/
public function sanitize_hide_elevation( $checked ) {
if ( 'on' === $checked ) {
return $checked;
}
return null;
}
/**
* Print checkbox option to clear cache.
*
+5
View File
@@ -83,6 +83,11 @@ WP-Strava caches activity for one hour so your site doesn't hit the Strava API o
== Changelog ==
= 1.7.2 =
Added setting to hide elevation.
= 1.7.1 =
Added PHPUnit tests for all System of Measure calculations.