From 4f66886832f6b20ef0fc5feca3588dac1f649e51 Mon Sep 17 00:00:00 2001 From: Justin Foell Date: Fri, 1 Feb 2019 11:59:00 -0600 Subject: [PATCH] Added image_only flag to [activity] shortcode --- css/wp-strava.css | 3 -- lib/WPStrava/ActivityShortcode.php | 85 +++++++++++++++++------------- lib/WPStrava/RouteShortcode.php | 7 ++- readme.txt | 8 ++- wp-strava.php | 2 +- 5 files changed, 62 insertions(+), 43 deletions(-) diff --git a/css/wp-strava.css b/css/wp-strava.css index 4331325..03574ac 100755 --- a/css/wp-strava.css +++ b/css/wp-strava.css @@ -32,6 +32,3 @@ .activity-details-table-units { font-size: 0.8em; } -.wp-strava-activity-container img { - max-width: none; -} diff --git a/lib/WPStrava/ActivityShortcode.php b/lib/WPStrava/ActivityShortcode.php index 7044b15..3b694de 100644 --- a/lib/WPStrava/ActivityShortcode.php +++ b/lib/WPStrava/ActivityShortcode.php @@ -53,9 +53,16 @@ class WPStrava_ActivityShortcode { 'map_height' => '320', 'athlete_token' => WPStrava::get_instance()->settings->get_default_token(), 'markers' => false, + 'image_only' => false, ); - $atts = shortcode_atts( $defaults, $atts ); + $atts = shortcode_atts( $defaults, $atts, 'activity' ); + + /* Make sure boolean values are actually boolean + * @see https://wordpress.stackexchange.com/a/119299 + */ + $atts['markers'] = filter_var( $atts['markers'], FILTER_VALIDATE_BOOLEAN ); + $atts['image_only'] = filter_var( $atts['image_only'], FILTER_VALIDATE_BOOLEAN ); $strava_som = WPStrava_SOM::get_som( $atts['som'] ); $activity = WPStrava::get_instance()->activity; @@ -74,42 +81,46 @@ class WPStrava_ActivityShortcode { $map_height = str_replace( 'px', '', $map_height ); if ( $activity_details ) { - return ' -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' . __( 'Elapsed Time', 'wp-strava' ) . '' . __( 'Moving Time', 'wp-strava' ) . '' . __( 'Distance', 'wp-strava' ) . '' . __( 'Average Speed', 'wp-strava' ) . '' . __( 'Max Speed', 'wp-strava' ) . '' . __( 'Elevation Gain', 'wp-strava' ) . '
' . $strava_som->time( $activity_details->elapsed_time ) . '' . $strava_som->time( $activity_details->moving_time ) . '' . $strava_som->distance( $activity_details->distance ) . '' . $strava_som->speed( $activity_details->average_speed ) . '' . $strava_som->speed( $activity_details->max_speed ) . '' . $strava_som->elevation( $activity_details->total_elevation_gain ) . '
' . $strava_som->get_time_label() . '' . $strava_som->get_time_label() . '' . $strava_som->get_distance_label() . '' . $strava_som->get_speed_label() . '' . $strava_som->get_speed_label() . '' . $strava_som->get_elevation_label() . '
- ' . - WPStrava_StaticMap::get_image_tag( $activity_details, $map_height, $map_width, $atts['markers'] ) . - ' -
'; + $activity_output = '
'; + if ( ! $atts['image_only'] ) { + $activity_output .= ' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
' . __( 'Elapsed Time', 'wp-strava' ) . '' . __( 'Moving Time', 'wp-strava' ) . '' . __( 'Distance', 'wp-strava' ) . '' . __( 'Average Speed', 'wp-strava' ) . '' . __( 'Max Speed', 'wp-strava' ) . '' . __( 'Elevation Gain', 'wp-strava' ) . '
' . $strava_som->time( $activity_details->elapsed_time ) . '' . $strava_som->time( $activity_details->moving_time ) . '' . $strava_som->distance( $activity_details->distance ) . '' . $strava_som->speed( $activity_details->average_speed ) . '' . $strava_som->speed( $activity_details->max_speed ) . '' . $strava_som->elevation( $activity_details->total_elevation_gain ) . '
' . $strava_som->get_time_label() . '' . $strava_som->get_time_label() . '' . $strava_som->get_distance_label() . '' . $strava_som->get_speed_label() . '' . $strava_som->get_speed_label() . '' . $strava_som->get_elevation_label() . '
+ '; + } + $activity_output .= '' . + WPStrava_StaticMap::get_image_tag( $activity_details, $map_height, $map_width, $atts['markers'] ) . + ' +
'; + return $activity_output; } // End if( $activity_details ). } diff --git a/lib/WPStrava/RouteShortcode.php b/lib/WPStrava/RouteShortcode.php index d30be37..99a7981 100644 --- a/lib/WPStrava/RouteShortcode.php +++ b/lib/WPStrava/RouteShortcode.php @@ -55,7 +55,12 @@ class WPStrava_RouteShortcode { 'markers' => false, ); - $atts = shortcode_atts( $defaults, $atts ); + $atts = shortcode_atts( $defaults, $atts, 'route' ); + + /* Make sure boolean values are actually boolean + * @see https://wordpress.stackexchange.com/a/119299 + */ + $atts['markers'] = filter_var( $atts['markers'], FILTER_VALIDATE_BOOLEAN ); $strava_som = WPStrava_SOM::get_som( $atts['som'] ); $route = WPStrava::get_instance()->routes; diff --git a/readme.txt b/readme.txt index 8297f50..6567157 100755 --- a/readme.txt +++ b/readme.txt @@ -72,12 +72,18 @@ WP-Strava caches activity for one hour so your site doesn't hit the Strava API o 6. Activity Shortcode - Shows a map of activity with some statistics. 7. Activity Shortcode Settings - An example activity shortcode. The athlete_token parameter is only needed if your site is connected to multiple athlete accounts. 8. Route Shortcode - Shows a map of a route. -9. Route Shortcode Settings - An example route shortcode. Add markers=true to show green/red start stop points. +9. Route Shortcode Settings - An example route shortcode. Add markers=true to show green/red start/stop points. 10. Activities Shortcode - Shows latest athlete activity in a page or post. 11. Activities Shortcode Settings - An example activities shortcode. The athlete_token parameter is only needed if your site is connected to multiple athlete accounts. == Changelog == += 1.6.1 = + +Added 'image_only' attribute to [activity] shortcode to optionally remove data table. +Added boolean filtering to shortcodes to prevent false-positive "truthiness" to a shortcode attribute like markers="false". +Removed 'max-width: none' from activity image to make it responsive. + = 1.6.0 = Added class autoloader (removed composer autoloader). diff --git a/wp-strava.php b/wp-strava.php index 2cae3e8..e2e4aed 100755 --- a/wp-strava.php +++ b/wp-strava.php @@ -3,7 +3,7 @@ * Plugin Name: WP Strava * 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 + * Version: 1.6.1 * Author: Carlos Santa Cruz, Justin Foell, Lance Willett, Daniel Lintott * License: GPL2 * Text Domain: wp-strava