Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Hide Time option; #27

Merged
merged 1 commit into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/WPStrava/LatestActivities.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public static function get_activities_html( $args ) {
if ( ! empty( $activity->start_date_local ) ) {
$unixtime = strtotime( $activity->start_date_local );
// Translators: Shows something like "On <date> <[went 10 miles] [during 2 hours] [climbing 100 feet]>."
$response .= sprintf( __( 'On %1$s %2$s', 'wp-strava' ), date_i18n( get_option( 'date_format' ), $unixtime ), date_i18n( get_option( 'time_format' ), $unixtime ) );
$response .= sprintf( __( 'On %1$s %2$s', 'wp-strava' ),
date_i18n( get_option( 'date_format' ), $unixtime ),
self::get_activity_time( $unixtime )
);
}

if ( is_numeric( $args['strava_club_id'] ) ) {
Expand All @@ -54,4 +57,20 @@ public static function get_activities_html( $args ) {
$response .= '</ul>';
return $response;
}

/**
* Get the activity time, possibly hiding it.
*
* @param int $unixtime
* @return string Formatted time, or empty string depending on hide_time option.
* @author Justin Foell <[email protected]>
* @since 1.7.1
*/
public static function get_activity_time( $unixtime ) {
if ( WPStrava::get_instance()->settings->hide_time ) {
return '';
}

return date_i18n( get_option( 'time_format' ), $unixtime );
}
}
31 changes: 31 additions & 0 deletions lib/WPStrava/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public function register_strava_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.
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' );

// 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' );
Expand Down Expand Up @@ -336,6 +340,33 @@ public function sanitize_som( $som ) {
return $som;
}

/**
* Display the Hide Time Checkbox.
*
* @author Justin Foell <[email protected]>
* @since 1.7.1
*/
public function print_hide_time_input() {
?>
<input type="checkbox" id="strava_hide_time" name="strava_hide_time" <?php checked( $this->hide_time, 'on' ); ?>/>
<?php
}

/**
* Sanitize the Hide Time Checkbox.
*
* @param string $checked 'on' or null.
* @return string 'on' if checked.
* @author Justin Foell <[email protected]>
* @since 1.7.1
*/
public function sanitize_hide_time( $checked ) {
if ( 'on' === $checked ) {
return $checked;
}
return null;
}

public function print_clear_input() {
?>
<input type="checkbox" id="strava_cache_clear" name="strava_cache_clear" />
Expand Down
12 changes: 10 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ This plugin uses the Strava API to embed maps and activity for athletes and club
Also takes the following optional parameters:

* som - english/metric (system of measure - override from default setting).
* map_width - width (width of image in pixels).
* map_height - height (height of image in pixels).
* map_width - width (width of image in pixels). Note both width and height parameters are limited to 640px except on premium API plans: https://developers.google.com/maps/documentation/maps-static/dev-guide#Imagesizes
* map_height - height (height of image in pixels). See note above on max height.
* athlete_token - specify a different athlete (you can copy this value from https://www.strava.com/settings/api or the wp-strava settings page at /wp-admin/options-general.php?page=wp-strava-options).
* markers - Display markers at the start/finish point (true/false, defaults to false).
* image_only - Display only the map image and not the table (true/false, defaults to false).
Expand Down Expand Up @@ -79,6 +79,13 @@ WP-Strava caches activity for one hour so your site doesn't hit the Strava API o

== Changelog ==

= 1.7.1 =

Added PHPUnit tests for all System of Measure calculations.
Fixed swimpace calculation.
Fixed seconds display on pace.
Added Hide Activity Time option to hide time display from Latest Activities List.

= 1.7.0 =

Added Sebastian Erb to contributors.
Expand All @@ -88,6 +95,7 @@ Added 'image_only' attribute to [activity] and [route] shortcode to optionally r
Added boolean filtering to shortcodes to prevent false-positive "truthiness" to a shortcode attribute like image_only="false".
Removed 'max-width: none' from activity image to make it responsive.


= 1.6.0 =

Added class autoloader (removed composer autoloader).
Expand Down
12 changes: 6 additions & 6 deletions tests/WPStrava/SOMEnglishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function test_object() {
/**
* Test that 10,000 meters is 6.21 miles using both string and float inputs.
*
* @author Justin Foell <justin[email protected]>
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_distance() {
Expand All @@ -28,7 +28,7 @@ public function test_distance() {
/**
* Test that 6.213712 miles is 10,000.00 meters using both string and float inputs.
*
* @author Justin Foell <justin[email protected]>
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_distance_inverse() {
Expand All @@ -39,7 +39,7 @@ public function test_distance_inverse() {
/**
* Test that 6.705 meters per second is 15.00 mph using both string and float inputs.
*
* @author Justin Foell <justin[email protected]>
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_speed() {
Expand All @@ -50,7 +50,7 @@ public function test_speed() {
/**
* Test that 2.68224 meters per second is a 10:00 minute/mile pace using both string and float inputs.
*
* @author Justin Foell <justin[email protected]>
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_pace() {
Expand All @@ -61,7 +61,7 @@ public function test_pace() {
/**
* Test that 60.96 meters is 200.00 feet using both string and float inputs.
*
* @author Justin Foell <justin[email protected]>
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_elevation() {
Expand All @@ -72,7 +72,7 @@ public function test_elevation() {
/**
* Test that 4805 seconds is 01:20:05 time (H:i:s) using both string and float inputs.
*
* @author Justin Foell <justin[email protected]>
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_time() {
Expand Down
12 changes: 6 additions & 6 deletions tests/WPStrava/SOMMetricTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function test_object() {
/**
* Test that 10,000 meters is 10.00 kilometers using both string and float inputs.
*
* @author Justin Foell <justin[email protected]>
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_distance() {
Expand All @@ -28,7 +28,7 @@ public function test_distance() {
/**
* Test that 42.195 km is 42,195.00 meters using both string and float inputs.
*
* @author Justin Foell <justin[email protected]>
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_distance_inverse() {
Expand All @@ -39,7 +39,7 @@ public function test_distance_inverse() {
/**
* Test that 4.47 meters per second is 16.09 kmh using both string and float inputs.
*
* @author Justin Foell <justin[email protected]>
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_speed() {
Expand All @@ -50,7 +50,7 @@ public function test_speed() {
/**
* Test that 2.2352 meters per second is a 7:27 minute/kilometer pace using both string and float inputs.
*
* @author Justin Foell <justin[email protected]>
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_pace() {
Expand All @@ -61,7 +61,7 @@ public function test_pace() {
/**
* Test that 70 meters is 70.00 meters using both string and float inputs.
*
* @author Justin Foell <justin[email protected]>
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_elevation() {
Expand All @@ -72,7 +72,7 @@ public function test_elevation() {
/**
* Test that 1.66 meters per second is a 1:00 minute/100m pace using both string and float inputs.
*
* @author Justin Foell <justin[email protected]>
* @author Justin Foell <justin@foell.org>
* @since 1.7.1
*/
public function test_swimpace() {
Expand Down
5 changes: 4 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

if ( ! defined( 'WPSTRAVA_PLUGIN_DIR' ) ) define( 'WPSTRAVA_PLUGIN_DIR', dirname( __FILE__ ) . '/../' );
if ( ! defined( 'WPSTRAVA_PLUGIN_DIR' ) ) {
define( 'WPSTRAVA_PLUGIN_DIR', dirname( __FILE__ ) . '/../' );
}

require_once dirname( __FILE__ ) . '/../lib/autoload.php';
require_once dirname( __FILE__ ) . '/../vendor/autoload.php';

Expand Down