mirror of
https://github.com/10h30/wp-strava.git
synced 2026-06-05 15:10:01 +09:00
Add image_only flag to [route] shortcode;
Refine table addition
This commit is contained in:
@@ -73,23 +73,25 @@ class WPStrava_ActivityShortcode {
|
||||
return $e->to_html();
|
||||
}
|
||||
|
||||
//sanitize width & height
|
||||
$map_width = str_replace( '%', '', $atts['map_width'] );
|
||||
$map_height = str_replace( '%', '', $atts['map_height'] );
|
||||
$map_width = str_replace( 'px', '', $map_width );
|
||||
$map_height = str_replace( 'px', '', $map_height );
|
||||
|
||||
$activity_output = '';
|
||||
if ( $activity_details ) {
|
||||
$activity_output = '<div id="activity-header-' . $atts['id'] . '" class="wp-strava-activity-container">';
|
||||
$activity_output .= '<div id="activity-header-' . $atts['id'] . '" class="wp-strava-activity-container">';
|
||||
if ( ! $atts['image_only'] ) {
|
||||
$activity_output .= $this->get_table( $activity_details, $atts['som'] );
|
||||
}
|
||||
|
||||
// Sanitize width & height.
|
||||
$map_width = str_replace( '%', '', $atts['map_width'] );
|
||||
$map_height = str_replace( '%', '', $atts['map_height'] );
|
||||
$map_width = str_replace( 'px', '', $map_width );
|
||||
$map_height = str_replace( 'px', '', $map_height );
|
||||
|
||||
$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 ).
|
||||
return $activity_output;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,6 +53,7 @@ class WPStrava_RouteShortcode {
|
||||
'map_height' => '320',
|
||||
'athlete_token' => WPStrava::get_instance()->settings->get_default_token(),
|
||||
'markers' => false,
|
||||
'image_only' => false,
|
||||
);
|
||||
|
||||
$atts = shortcode_atts( $defaults, $atts, 'route' );
|
||||
@@ -60,9 +61,9 @@ class WPStrava_RouteShortcode {
|
||||
/* Make sure boolean values are actually boolean
|
||||
* @see https://wordpress.stackexchange.com/a/119299
|
||||
*/
|
||||
$atts['markers'] = filter_var( $atts['markers'], FILTER_VALIDATE_BOOLEAN );
|
||||
$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'] );
|
||||
$route = WPStrava::get_instance()->routes;
|
||||
$route_details = null;
|
||||
|
||||
@@ -72,41 +73,61 @@ class WPStrava_RouteShortcode {
|
||||
return $e->to_html();
|
||||
}
|
||||
|
||||
// Sanitize width & height.
|
||||
$map_width = str_replace( '%', '', $atts['map_width'] );
|
||||
$map_height = str_replace( '%', '', $atts['map_height'] );
|
||||
$map_width = str_replace( 'px', '', $map_width );
|
||||
$map_height = str_replace( 'px', '', $map_height );
|
||||
|
||||
$route_output = '';
|
||||
if ( $route_details ) {
|
||||
return '
|
||||
<div id="activity-header-' . $atts['id'] . '" class="wp-strava-activity-container">
|
||||
<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>
|
||||
</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>
|
||||
</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>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<a title="' . $route_details->name . '" href="' . WPStrava_Routes::ROUTES_URL . $route_details->id . '">' .
|
||||
$route_output = '<div id="activity-header-' . $atts['id'] . '" class="wp-strava-activity-container">';
|
||||
if ( ! $atts['image_only'] ) {
|
||||
$route_output .= $this->get_table( $route_details, $atts['som'] );
|
||||
}
|
||||
|
||||
// Sanitize width & height.
|
||||
$map_width = str_replace( '%', '', $atts['map_width'] );
|
||||
$map_height = str_replace( '%', '', $atts['map_height'] );
|
||||
$map_width = str_replace( 'px', '', $map_width );
|
||||
$map_height = str_replace( 'px', '', $map_height );
|
||||
|
||||
$route_output .= '<a title="' . $route_details->name . '" href="' . WPStrava_Routes::ROUTES_URL . $route_details->id . '">' .
|
||||
WPStrava_StaticMap::get_image_tag( $route_details, $map_height, $map_width, $atts['markers'] ) .
|
||||
'</a>
|
||||
</div>';
|
||||
} // End if( $route_details ).
|
||||
return $route_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* The the route details in in HTML table.
|
||||
*
|
||||
* @param string $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 <justin@foell.org>
|
||||
* @since NEXT
|
||||
*/
|
||||
private function get_table( $route_details, $som ) {
|
||||
$strava_som = WPStrava_SOM::get_som( $som );
|
||||
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>
|
||||
</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>
|
||||
</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>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user