Added image_only flag to [activity] shortcode

This commit is contained in:
Justin Foell
2019-02-01 11:59:00 -06:00
parent 947b26faeb
commit 4f66886832
5 changed files with 62 additions and 43 deletions
-3
View File
@@ -32,6 +32,3 @@
.activity-details-table-units {
font-size: 0.8em;
}
.wp-strava-activity-container img {
max-width: none;
}
+48 -37
View File
@@ -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 '
<div id="activity-header-' . $atts['id'] . '" class="wp-strava-activity-container">
<table id="activity-details-table">
<thead>
<tr>
<th>' . __( 'Elapsed Time', 'wp-strava' ) . '</th>
<th>' . __( 'Moving Time', 'wp-strava' ) . '</th>
<th>' . __( 'Distance', 'wp-strava' ) . '</th>
<th>' . __( 'Average Speed', 'wp-strava' ) . '</th>
<th>' . __( 'Max Speed', 'wp-strava' ) . '</th>
<th>' . __( 'Elevation Gain', 'wp-strava' ) . '</th>
</tr>
</thead>
<tbody>
<tr class="activity-details-table-info">
<td>' . $strava_som->time( $activity_details->elapsed_time ) . '</td>
<td>' . $strava_som->time( $activity_details->moving_time ) . '</td>
<td>' . $strava_som->distance( $activity_details->distance ) . '</td>
<td>' . $strava_som->speed( $activity_details->average_speed ) . '</td>
<td>' . $strava_som->speed( $activity_details->max_speed ) . '</td>
<td>' . $strava_som->elevation( $activity_details->total_elevation_gain ) . '</td>
</tr>
<tr class="activity-details-table-units">
<td>' . $strava_som->get_time_label() . '</td>
<td>' . $strava_som->get_time_label() . '</td>
<td>' . $strava_som->get_distance_label() . '</td>
<td>' . $strava_som->get_speed_label() . '</td>
<td>' . $strava_som->get_speed_label() . '</td>
<td>' . $strava_som->get_elevation_label() . '</td>
</tr>
</tbody>
</table>
<a title="' . $activity_details->name . '" href="' . WPStrava_Activity::ACTIVITIES_URL . $activity_details->id . '">' .
WPStrava_StaticMap::get_image_tag( $activity_details, $map_height, $map_width, $atts['markers'] ) .
'</a>
</div>';
$activity_output = '<div id="activity-header-' . $atts['id'] . '" class="wp-strava-activity-container">';
if ( ! $atts['image_only'] ) {
$activity_output .= '
<table id="activity-details-table">
<thead>
<tr>
<th>' . __( 'Elapsed Time', 'wp-strava' ) . '</th>
<th>' . __( 'Moving Time', 'wp-strava' ) . '</th>
<th>' . __( 'Distance', 'wp-strava' ) . '</th>
<th>' . __( 'Average Speed', 'wp-strava' ) . '</th>
<th>' . __( 'Max Speed', 'wp-strava' ) . '</th>
<th>' . __( 'Elevation Gain', 'wp-strava' ) . '</th>
</tr>
</thead>
<tbody>
<tr class="activity-details-table-info">
<td>' . $strava_som->time( $activity_details->elapsed_time ) . '</td>
<td>' . $strava_som->time( $activity_details->moving_time ) . '</td>
<td>' . $strava_som->distance( $activity_details->distance ) . '</td>
<td>' . $strava_som->speed( $activity_details->average_speed ) . '</td>
<td>' . $strava_som->speed( $activity_details->max_speed ) . '</td>
<td>' . $strava_som->elevation( $activity_details->total_elevation_gain ) . '</td>
</tr>
<tr class="activity-details-table-units">
<td>' . $strava_som->get_time_label() . '</td>
<td>' . $strava_som->get_time_label() . '</td>
<td>' . $strava_som->get_distance_label() . '</td>
<td>' . $strava_som->get_speed_label() . '</td>
<td>' . $strava_som->get_speed_label() . '</td>
<td>' . $strava_som->get_elevation_label() . '</td>
</tr>
</tbody>
</table>
';
}
$activity_output .= '<a title="' . $activity_details->name . '" href="' . WPStrava_Activity::ACTIVITIES_URL . $activity_details->id . '">' .
WPStrava_StaticMap::get_image_tag( $activity_details, $map_height, $map_width, $atts['markers'] ) .
'</a>
</div>';
return $activity_output;
} // End if( $activity_details ).
}
+6 -1
View File
@@ -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;
+7 -1
View File
@@ -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).
+1 -1
View File
@@ -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