diff --git a/css/wp-strava.css b/css/wp-strava.css index 03574ac..67bdb35 100755 --- a/css/wp-strava.css +++ b/css/wp-strava.css @@ -12,15 +12,15 @@ display: table; margin: 0 auto; } -#activity-details-table tr td { +.activity-details-table tr td { padding: 5px; } -#activity-details-table th { +.activity-details-table th { padding: 5px; text-align: center; font-size: 0.8em; } -#activity-details-table td { +.activity-details-table td { text-align: center; border: 1px solid #e7e7e7; } @@ -32,3 +32,45 @@ .activity-details-table-units { font-size: 0.8em; } + +/* Responsive Tables */ +@media +only screen and (max-width: 760px), +(min-device-width: 768px) and (max-device-width: 1024px) { + + /* Force table to not be like tables anymore */ + table, thead, tbody, th, td, tr { + display: block; + } + + /* Hide table headers (but not display: none;, for accessibility) */ + thead tr { + position: absolute; + top: -9999px; + left: -9999px; + } + + td { + /* Behave like a "row" */ + border: none; + border-bottom: 1px solid #e7e7e7; + position: relative; + padding-left: 50%; + } + + td:before { + /* Now like a table header */ + position: absolute; + /* Top/left values mimic padding */ + top: 5px; + left: 5px; + width: 45%; + padding-right: 10px; + white-space: nowrap; + content: attr(data-label); + } + + .activity-details-table-info, .activity-details-table-units { + display: inline; + } +} diff --git a/readme.txt b/readme.txt index 0bd2efe..abb9bdf 100755 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: cmanon, jrfoell, lancewillett, dlintott, sebastianerb Tags: strava, activity, bicycle, cycling, biking, running, run, swimming, swim, paddle, kayak, gps, shortcode, widget, plugin Requires at least: 4.6 -Tested up to: 5.4 +Tested up to: 5.5 Stable tag: 2.3.2 Requires PHP: 5.3 License: GPLv2 or later @@ -116,6 +116,10 @@ On the WP-Strava settings page you cannot currently remove and add another athle == Changelog == += 2.4.0 = +Made activity table responsive https://wordpress.org/support/topic/responsive-strava-activity-table/ +Improve output escaping, documentation, and other coding standards + = 2.3.2 = Added support to not link to activities https://wordpress.org/support/topic/feature-request-make-link-to-activity-optional diff --git a/src/WPStrava.php b/src/WPStrava.php index 5b8c18b..68cc27e 100644 --- a/src/WPStrava.php +++ b/src/WPStrava.php @@ -78,7 +78,7 @@ class WPStrava { if ( is_admin() ) { $this->settings->hook(); - } else { + } else { // Front-end. add_action( 'init', array( $this, 'register_shortcodes' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) ); } diff --git a/src/WPStrava/ActivityRenderer.php b/src/WPStrava/ActivityRenderer.php index a286606..3ee825c 100644 --- a/src/WPStrava/ActivityRenderer.php +++ b/src/WPStrava/ActivityRenderer.php @@ -67,7 +67,7 @@ class WPStrava_ActivityRenderer { /** * The the activity details in in HTML table. * - * @param string $activity_details Activity details from the activity class. + * @param stdClass $activity_details Activity details from the activity class. * @param string $som System of measure (english/metric). * @return string HTML Table of activity details. * @author Justin Foell @@ -80,27 +80,42 @@ class WPStrava_ActivityRenderer { $avg_title = '' . __( 'Average Speed', 'wp-strava' ) . ''; $max_title = '' . __( 'Max Speed', 'wp-strava' ) . ''; $elevation_title = '' . __( 'Elevation Gain', 'wp-strava' ) . ''; + $elevation = ' +
' . $strava_som->elevation( $activity_details->total_elevation_gain ) . '
+
' . $strava_som->get_elevation_label() . '
+ '; $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: - $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() . ''; + $avg_speed = ' +
' . $strava_som->pace( $activity_details->average_speed ) . '
+
' . $strava_som->get_pace_label() . '
+ '; + $max_speed = ' +
' . $strava_som->pace( $activity_details->max_speed ) . '
+ '; 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() . ''; + $avg_speed = ' +
' . $strava_som->speed( $activity_details->average_speed ) . '
+
' . $strava_som->get_speed_label() . '
+ '; + $max_speed = ' +
' . $strava_som->speed( $activity_details->max_speed ) . '
+
' . $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() . ''; + $avg_speed = ' +
' . $strava_som->swimpace( $activity_details->average_speed ) . '
+
' . $strava_som->get_swimpace_label() . '
+ '; + $max_speed = ' +
' . $strava_som->swimpace( $activity_details->max_speed ) . '
+
' . $strava_som->get_swimpace_label() . '
+ '; break; default: $avg_title = ''; @@ -109,13 +124,12 @@ class WPStrava_ActivityRenderer { } if ( WPStrava::get_instance()->settings->hide_elevation ) { - $elevation = ''; $elevation_title = ''; - $elevation_label = ''; + $elevation = ''; } return ' - +
@@ -127,22 +141,23 @@ class WPStrava_ActivityRenderer { - - - - + + + + ' . $avg_speed . ' ' . $max_speed . ' ' . $elevation . ' - - - - - ' . $speed_label . ' - ' . $speed_label . ' - ' . $elevation_label . ' -
' . __( 'Elapsed Time', 'wp-strava' ) . '
' . $strava_som->time( $activity_details->elapsed_time ) . '' . $strava_som->time( $activity_details->moving_time ) . '' . $strava_som->distance( $activity_details->distance ) . '
+
' . $strava_som->time( $activity_details->elapsed_time ) . '
+
' . $strava_som->get_time_label() . '
+
+
' . $strava_som->time( $activity_details->moving_time ) . '
+
' . $strava_som->get_time_label() . '
+
+
' . $strava_som->distance( $activity_details->distance ) . '
+
' . $strava_som->get_distance_label() . '
+
' . $strava_som->get_time_label() . '' . $strava_som->get_time_label() . '' . $strava_som->get_distance_label() . '
'; diff --git a/src/WPStrava/AuthRefresh.php b/src/WPStrava/AuthRefresh.php index 3079eb3..1bdd6e3 100644 --- a/src/WPStrava/AuthRefresh.php +++ b/src/WPStrava/AuthRefresh.php @@ -107,7 +107,7 @@ class WPStrava_AuthRefresh extends WPStrava_Auth { // Translators: Token refresh success message. $this->feedback .= __( 'ID %s successfully re-authenticated.', 'wp-strava' ); - if ( $strava_info->access_token != $info->access_token ) { + if ( $strava_info->access_token !== $info->access_token ) { // Translators: New token created message. $this->feedback .= __( 'ID %s access extended.', 'wp-strava' ); diff --git a/src/WPStrava/Blocks/Activity.php b/src/WPStrava/Blocks/Activity.php index 3baa5e3..ceff6b0 100644 --- a/src/WPStrava/Blocks/Activity.php +++ b/src/WPStrava/Blocks/Activity.php @@ -38,7 +38,7 @@ class WPStrava_Blocks_Activity implements WPStrava_Blocks_Interface { } $matches = []; - preg_match( "/\/activities\/([0-9].*)$/", $attributes['url'], $matches ); + preg_match( '/\/activities\/([0-9].*)$/', $attributes['url'], $matches ); if ( $matches[1] ) { // Transform from block attributes to shortcode standard. $attributes = array( diff --git a/src/WPStrava/RouteShortcode.php b/src/WPStrava/RouteShortcode.php index 65ee859..f56f6d3 100644 --- a/src/WPStrava/RouteShortcode.php +++ b/src/WPStrava/RouteShortcode.php @@ -102,7 +102,7 @@ class WPStrava_RouteShortcode { /** * The the route details in in HTML table. * - * @param string $route_details route details from the route class. + * @param stdClass $route_details route details from the route class. * @param string $som System of measure (english/metric). * @return string HTML Table of route details. * @author Justin Foell @@ -122,7 +122,7 @@ class WPStrava_RouteShortcode { } return ' - +
diff --git a/src/WPStrava/SOM.php b/src/WPStrava/SOM.php index 11c4edb..0fc6e81 100644 --- a/src/WPStrava/SOM.php +++ b/src/WPStrava/SOM.php @@ -36,9 +36,9 @@ abstract class WPStrava_SOM { * @see https://stackoverflow.com/a/20870843/2146022 */ public function time( $seconds ) { - $zero = new DateTime( '@0' ); - $offset = new DateTime( "@{$seconds}" ); - $diff = $zero->diff( $offset ); + $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/src/WPStrava/Settings.php b/src/WPStrava/Settings.php index 4b5483f..54a6db0 100644 --- a/src/WPStrava/Settings.php +++ b/src/WPStrava/Settings.php @@ -236,10 +236,19 @@ class WPStrava_Settings { * @since 2.0.0 */ public function print_id_input() { + $first = true; foreach ( $this->get_all_ids() as $id => $nickname ) { ?> + + +
+ + + -

+ +

* @since 2.0.0 */ @@ -644,7 +653,8 @@ class WPStrava_Settings { * @since 2.0.0 */ public function save_info( $id, $secret, $info ) { - $infos = get_option( 'strava_info', array() ); + $infos = get_option( 'strava_info' ); + $infos = empty( $infos ) ? array() : $infos; $infos = array_filter( $infos, array( $this, 'filter_by_id' ), ARRAY_FILTER_USE_KEY ); // Remove old IDs. $info->client_secret = $secret; @@ -661,7 +671,7 @@ class WPStrava_Settings { * @since 2.0.0 */ public function filter_by_id( $key ) { - if ( in_array( $key, $this->ids ) ) { + if ( in_array( $key, $this->ids ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- Loose comparison OK. return true; } return false;
' . __( 'Est. Moving Time', 'wp-strava' ) . '