mirror of
https://github.com/10h30/wp-strava.git
synced 2026-07-12 03:06:34 +09:00
Updated to the [ride] shortcode
This commit is contained in:
+2
-2
@@ -8,7 +8,7 @@
|
||||
background-position: -224px -160px;
|
||||
margin: 0 6px 2px 0;
|
||||
}
|
||||
.table {
|
||||
.wp-strava-ride-container {
|
||||
display: table;
|
||||
margin: 0 auto;
|
||||
}
|
||||
@@ -32,6 +32,6 @@
|
||||
.ride-details-table-units {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
.map img {
|
||||
.wp-strava-ride-container img {
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
@@ -100,25 +100,13 @@ class WPStrava_LatestMapWidget extends WP_Widget {
|
||||
endif;
|
||||
}
|
||||
|
||||
private function buildImage( $ride ) {
|
||||
$url = 'http://maps.google.com/maps/api/staticmap?maptype=terrain&size=390x260&sensor=false&path=color:0xFF0000BF|weight:2|enc:';
|
||||
$url_len = strlen( $url );
|
||||
$max_chars = 1865;
|
||||
|
||||
if ( $url_len + strlen( $ride->map->polyline ) < $max_chars )
|
||||
$url .= $ride->map->polyline;
|
||||
else
|
||||
$url .= $ride->map->summary_polyline;
|
||||
|
||||
return "<img src='{$url}' />";
|
||||
}
|
||||
|
||||
private function getStaticImage( $ride_id, $build_new ) {
|
||||
$img = get_option( 'strava_latest_map' );
|
||||
|
||||
if ( $build_new || ! $img ) {
|
||||
$ride = WPStrava::get_instance()->rides->getRide( $ride_id );
|
||||
$img = $this->buildImage( $ride );
|
||||
$img = WPStrava_StaticMap::get_image_tag( $ride );
|
||||
update_option( 'strava_latest_map', $img );
|
||||
}
|
||||
|
||||
|
||||
+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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,25 +34,6 @@ class WPStrava_Rides {
|
||||
return array();
|
||||
|
||||
} // getRides
|
||||
|
||||
public function getRideMap($rideId, $token, $efforts, $threshold) {
|
||||
if($rideId != 0 AND $token != "") {
|
||||
$url = preg_replace('/:id/', $rideId, $this->rideMapDetailsUrlV2);
|
||||
$json = file_get_contents($url . '?token=' . $token . '&threshold=' . $threshold);
|
||||
|
||||
if($json) {
|
||||
//$map_details = json_decode($json);
|
||||
//return $map_details;
|
||||
return $json;
|
||||
} else {
|
||||
$this->feedback .= _e("There was an error pulling data from strava.com.", "wp-strava");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->feedback .= _e("You need to provide both parameters to complete the call.", "wp-strava");
|
||||
return false;
|
||||
}
|
||||
} // getRideDetails
|
||||
|
||||
public function getRidesLongerThan( $rides, $dist ) {
|
||||
$som = WPStrava_SOM::get_som();
|
||||
|
||||
+4
-4
@@ -4,12 +4,12 @@ abstract class WPStrava_SOM {
|
||||
|
||||
public static function get_som( $som = NULL ) {
|
||||
$som = $som ? $som : WPStrava::get_instance()->settings->som;
|
||||
if ( $som == 'metric' ) {
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMMetric.class.php';
|
||||
return new WPStrava_SOMMetric();
|
||||
} else {
|
||||
if ( $som == 'english' ) {
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMEnglish.class.php';
|
||||
return new WPStrava_SOMEnglish();
|
||||
} else { //default to metric
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMMetric.class.php';
|
||||
return new WPStrava_SOMMetric();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class WPStrava_StaticMap {
|
||||
|
||||
public static function get_image_tag( $ride, $height = 320, $width = 480 ) {
|
||||
$url = "http://maps.google.com/maps/api/staticmap?maptype=terrain&size={$width}x{$height}&sensor=false&path=color:0xFF0000BF|weight:2|enc:";
|
||||
$url_len = strlen( $url );
|
||||
$max_chars = 1865;
|
||||
|
||||
if ( $url_len + strlen( $ride->map->polyline ) < $max_chars )
|
||||
$url .= $ride->map->polyline;
|
||||
else
|
||||
$url .= $ride->map->summary_polyline;
|
||||
|
||||
return "<img src='{$url}' />";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOM.class.php';
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/LatestRidesWidget.class.php';
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/LatestMapWidget.class.php';
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/RideShortcode.class.php';
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/StaticMap.class.php';
|
||||
|
||||
class WPStrava {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user