mirror of
https://github.com/10h30/wp-strava.git
synced 2026-07-11 18:56:18 +09:00
Updated to the [ride] shortcode
This commit is contained in:
+57
-90
@@ -15,109 +15,76 @@ class WPStrava_RideShortcode {
|
||||
function handler($atts) {
|
||||
self::$add_script = true;
|
||||
|
||||
$token = get_option('strava_token');
|
||||
$defaults = array(
|
||||
'id' => 0,
|
||||
'som' => WPStrava::get_instance()->settings->som,
|
||||
'map_width' => '480',
|
||||
'map_height' => '320',
|
||||
);
|
||||
|
||||
extract(shortcode_atts($defaults, $atts));
|
||||
|
||||
if($token) {
|
||||
$pairs = array(
|
||||
'id' => 0,
|
||||
'som' => "metric",
|
||||
'efforts' => false,
|
||||
'threshold' => 0,
|
||||
'map_width' => "100%",
|
||||
'map_height' => "400px"
|
||||
);
|
||||
|
||||
extract(shortcode_atts($pairs, $atts));
|
||||
$strava_som = WPStrava_SOM::get_som( $som );
|
||||
$strava_ride = WPStrava::get_instance()->rides;
|
||||
$rideDetails = $strava_ride->getRide( $id );
|
||||
|
||||
if (isset($som)) {
|
||||
$strava_som = $som;
|
||||
} else {
|
||||
$strava_som = get_option('strava_som_option', 'metric');
|
||||
}
|
||||
|
||||
$ride = WPStrava::get_instance()->rides;
|
||||
$rideDetails = $ride->getRide($id);
|
||||
$rideCoordinates = $ride->getRideMap($id, $token, $efforts, $threshold);
|
||||
|
||||
if ($strava_som == "metric") {
|
||||
$units = array(
|
||||
'elapsedTime' => __('hours','wp-strava'),
|
||||
'movingTime' => __('hours','wp-strava'),
|
||||
'distance' => __('km','wp-strava'),
|
||||
'averageSpeed' => __('km/h','wp-strava'),
|
||||
//'maximumSpeed' => __('km/h','wp-strava'),
|
||||
'elevationGain' => __('meters','wp-strava')
|
||||
);
|
||||
} elseif ($strava_som == "english") {
|
||||
$units = array(
|
||||
'elapsedTime' => __('hours','wp-strava'),
|
||||
'movingTime' => __('hours','wp-strava'),
|
||||
'distance' => __('miles','wp-strava'),
|
||||
'averageSpeed' => __('miles/h','wp-strava'),
|
||||
//'maximumSpeed' => __('miles/h','wp-strava'),
|
||||
'elevationGain' => __('feet','wp-strava')
|
||||
);
|
||||
}
|
||||
|
||||
if($rideCoordinates) {
|
||||
return "
|
||||
<div id='ride-header-{$id}' class='table'>
|
||||
<table id='ride-details-table'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Elapsed Time</th>
|
||||
<th>Moving Time</th>
|
||||
<th>Distance</th>
|
||||
<th>Average Speed</th>
|
||||
<th>Elevation Gain</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class='ride-details-table-info'>
|
||||
<td>{$rideDetails['elapsedTime']}</td>
|
||||
<td>{$rideDetails['movingTime']}</td>
|
||||
<td>{$rideDetails['distance']}</td>
|
||||
<td>{$rideDetails['averageSpeed']}</td>
|
||||
<td>{$rideDetails['elevationGain']}</td>
|
||||
</tr>
|
||||
<tr class='ride-details-table-units'>
|
||||
<td>{$units['elapsedTime']}</td>
|
||||
<td>{$units['movingTime']}</td>
|
||||
<td>{$units['distance']}</td>
|
||||
<td>{$units['averageSpeed']}</td>
|
||||
<td>{$units['elevationGain']}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div id='{$id}' class='map' style='width: {$map_width}; height: {$map_height}; border: 1px solid lightgrey;'></div>
|
||||
<script type='text/javascript'>
|
||||
if (window.coordinates === undefined) {
|
||||
window.coordinates = [];
|
||||
}
|
||||
window.coordinates[{$id}] = eval({$rideCoordinates});
|
||||
</script>
|
||||
";
|
||||
}
|
||||
} else {
|
||||
return __('Please first get your strava token using the settings wp strava page.', 'wp-strava');
|
||||
//sanitize width & height
|
||||
$map_width = str_replace( '%', '', $map_width );
|
||||
$map_height = str_replace( '%', '', $map_height );
|
||||
$map_width = str_replace( 'px', '', $map_width );
|
||||
$map_height = str_replace( 'px', '', $map_height );
|
||||
|
||||
if( $rideDetails ) {
|
||||
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">
|
||||
<td>' . $strava_som->time( $rideDetails->elapsed_time ) . '</td>
|
||||
<td>' . $strava_som->time( $rideDetails->moving_time ) . '</td>
|
||||
<td>' . $strava_som->distance( $rideDetails->distance ) . '</td>
|
||||
<td>' . $strava_som->speed( $rideDetails->average_speed ) . '</td>
|
||||
<td>' . $strava_som->speed( $rideDetails->max_speed ) . '</td>
|
||||
<td>' . $strava_som->elevation( $rideDetails->total_elevation_gain ) . '</td>
|
||||
</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>' .
|
||||
WPStrava_StaticMap::get_image_tag( $rideDetails, $map_height, $map_width ) .
|
||||
'</div>';
|
||||
}
|
||||
} // handler
|
||||
|
||||
static function registerScripts() {
|
||||
wp_register_style('wp-strava-style', plugins_url('css/wp-strava.css', __FILE__));
|
||||
wp_register_style('wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' );
|
||||
|
||||
wp_register_script('wp-strava-script', plugins_url('js/wp-strava.js', __FILE__), array('jquery'), '1.0', true);
|
||||
wp_register_script('google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
|
||||
//wp_register_script('wp-strava-script', WPSTRAVA_PLUGIN_URL . 'js/wp-strava.js', array( 'jquery' ), '1.0', true);
|
||||
//wp_register_script('google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
|
||||
}
|
||||
|
||||
static function printScripts() {
|
||||
if (self::$add_script) {
|
||||
wp_enqueue_style('wp-strava-style');
|
||||
wp_enqueue_script('jquery');
|
||||
|
||||
wp_print_scripts('google-maps');
|
||||
wp_print_scripts('wp-strava-script');
|
||||
//wp_print_scripts('google-maps');
|
||||
//wp_print_scripts('wp-strava-script');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user