2013-02-03 20:38:55 -06:00
|
|
|
<?php
|
|
|
|
|
|
2017-09-29 10:52:57 -05:00
|
|
|
class WPStrava_ActivityShortcode {
|
2015-05-11 22:28:33 -05:00
|
|
|
private static $add_script;
|
2013-02-03 20:38:55 -06:00
|
|
|
|
2015-05-11 22:28:33 -05:00
|
|
|
public static function init() {
|
|
|
|
|
add_shortcode( 'ride', array( __CLASS__, 'handler' ) );
|
|
|
|
|
add_shortcode( 'activity', array( __CLASS__, 'handler' ) );
|
2017-05-26 10:53:24 -05:00
|
|
|
add_action( 'wp_footer', array( __CLASS__, 'print_scripts' ) );
|
2013-02-03 20:38:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Shortcode handler function
|
2017-12-26 14:18:13 -06:00
|
|
|
// [activity id=id som=metric map_width="100%" map_height="400px" markers=false]
|
2017-05-26 10:53:24 -05:00
|
|
|
public static function handler( $atts ) {
|
2013-02-03 20:38:55 -06:00
|
|
|
self::$add_script = true;
|
|
|
|
|
|
2014-11-01 22:53:32 -05:00
|
|
|
$defaults = array(
|
2017-09-29 10:52:57 -05:00
|
|
|
'id' => 0,
|
|
|
|
|
'som' => WPStrava::get_instance()->settings->som,
|
|
|
|
|
'map_width' => '480',
|
|
|
|
|
'map_height' => '320',
|
|
|
|
|
'athlete_token' => WPStrava::get_instance()->settings->get_default_token(),
|
2017-12-26 14:18:13 -06:00
|
|
|
'markers' => false,
|
2014-11-01 22:53:32 -05:00
|
|
|
);
|
2017-05-26 10:53:24 -05:00
|
|
|
|
|
|
|
|
extract( shortcode_atts( $defaults, $atts ) );
|
|
|
|
|
|
2017-12-26 14:18:13 -06:00
|
|
|
$strava_som = WPStrava_SOM::get_som( $som );
|
|
|
|
|
$activity = WPStrava::get_instance()->rides;
|
2017-09-29 10:52:57 -05:00
|
|
|
$ride_details = $activity->getRide( $athlete_token, $id );
|
2013-02-03 20:38:55 -06:00
|
|
|
|
2014-11-01 22:53:32 -05:00
|
|
|
//sanitize width & height
|
2017-09-29 10:52:57 -05:00
|
|
|
$map_width = str_replace( '%', '', $map_width );
|
2014-11-01 22:53:32 -05:00
|
|
|
$map_height = str_replace( '%', '', $map_height );
|
2017-09-29 10:52:57 -05:00
|
|
|
$map_width = str_replace( 'px', '', $map_width );
|
2014-11-01 22:53:32 -05:00
|
|
|
$map_height = str_replace( 'px', '', $map_height );
|
2015-05-11 22:28:33 -05:00
|
|
|
|
2017-05-26 10:53:24 -05:00
|
|
|
if ( $ride_details ) {
|
2014-11-01 22:53:32 -05:00
|
|
|
return '
|
|
|
|
|
<div id="ride-header-' . $id . '" class="wp-strava-ride-container">
|
|
|
|
|
<table id="ride-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="ride-details-table-info">
|
2017-05-26 10:53:24 -05:00
|
|
|
<td>' . $strava_som->time( $ride_details->elapsed_time ) . '</td>
|
|
|
|
|
<td>' . $strava_som->time( $ride_details->moving_time ) . '</td>
|
|
|
|
|
<td>' . $strava_som->distance( $ride_details->distance ) . '</td>
|
|
|
|
|
<td>' . $strava_som->speed( $ride_details->average_speed ) . '</td>
|
|
|
|
|
<td>' . $strava_som->speed( $ride_details->max_speed ) . '</td>
|
|
|
|
|
<td>' . $strava_som->elevation( $ride_details->total_elevation_gain ) . '</td>
|
2014-11-01 22:53:32 -05:00
|
|
|
</tr>
|
|
|
|
|
<tr class="ride-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>' .
|
2017-12-16 13:05:16 +00:00
|
|
|
WPStrava_StaticMap::get_image_tag( $ride_details, $map_height, $map_width, $markers ) .
|
2017-05-26 10:53:24 -05:00
|
|
|
'</div>';
|
|
|
|
|
} // End if( $ride_details ).
|
2013-02-03 20:38:55 -06:00
|
|
|
} // handler
|
|
|
|
|
|
2017-05-26 10:53:24 -05:00
|
|
|
public static function print_scripts() {
|
|
|
|
|
if ( self::$add_script ) {
|
|
|
|
|
wp_enqueue_style( 'wp-strava-style' );
|
2013-02-03 20:38:55 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize short code
|
2017-09-29 10:52:57 -05:00
|
|
|
WPStrava_ActivityShortcode::init();
|