diff --git a/css/wp-strava.css b/css/wp-strava.css
index fad25b8..4331325 100755
--- a/css/wp-strava.css
+++ b/css/wp-strava.css
@@ -1,5 +1,5 @@
@CHARSET "UTF-8";
-.ride-item:before {
+.activity-item:before {
content: "";
width: 16px;
height: 16px;
@@ -8,30 +8,30 @@
background-position: -224px -160px;
margin: 0 6px 2px 0;
}
-.wp-strava-ride-container {
+.wp-strava-activity-container {
display: table;
margin: 0 auto;
}
-#ride-details-table tr td {
+#activity-details-table tr td {
padding: 5px;
}
-#ride-details-table th {
+#activity-details-table th {
padding: 5px;
text-align: center;
font-size: 0.8em;
}
-#ride-details-table td {
+#activity-details-table td {
text-align: center;
border: 1px solid #e7e7e7;
}
-.ride-details-table-info {
+.activity-details-table-info {
font-size: 1.2em;
font-weight: bold;
text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.4);
}
-.ride-details-table-units {
+.activity-details-table-units {
font-size: 0.8em;
}
-.wp-strava-ride-container img {
+.wp-strava-activity-container img {
max-width: none;
}
diff --git a/js/wp-strava.js b/js/wp-strava.js
deleted file mode 100644
index 5b05e32..0000000
--- a/js/wp-strava.js
+++ /dev/null
@@ -1,39 +0,0 @@
-
-jQuery(document).ready(function($){
- $('.map').each(function(){
- var mapId = $(this).attr('id');
-
- var rideCoordinates = window.coordinates[mapId].latlng;
- var mapCenter = new google.maps.LatLng(23.091860, -102.839356);
- var mapOptions = {
- zoom: 5,
- center: mapCenter,
- //mapTypeControl: true,
- //mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
- zoomControl: true,
- zoomControlOptions: {style: google.maps.MapTypeControlStyle.SMALL},
- mapTypeId: google.maps.MapTypeId.TERRAIN
- };
- var mapObject = new google.maps.Map($('#' + mapId)[0], mapOptions);
- var mapBounds = new google.maps.LatLngBounds();
- var mapCoordinates = new google.maps.MVCArray();
- var size = rideCoordinates.length;
- for(i = 0; i < size; i++) {
- point = new google.maps.LatLng(parseFloat(rideCoordinates[i][0]), parseFloat(rideCoordinates[i][1]));
- mapBounds.extend(point);
- mapCoordinates.push(point);
- }
-
- var polylineOptions = {
- path: mapCoordinates,
- strokeColor: '#e0642e',
- strokeOpacity: 0.8,
- strokeWeight: 3
- };
-
- var polyline = new google.maps.Polyline(polylineOptions);
- polyline.setMap(mapObject);
- mapObject.fitBounds(mapBounds);
- //google.maps.event.trigger(mapObject, 'resize');
- });
-});
diff --git a/lib/API.class.php b/lib/API.class.php
index 56ce806..63fb753 100755
--- a/lib/API.class.php
+++ b/lib/API.class.php
@@ -1,12 +1,10 @@
error ) ) {
@@ -45,7 +44,7 @@ class WPStrava_API {
return new WP_Error(
'wp-strava_post',
// Translators: message shown when there's a problem with ab HTTP POST to the Strava API.
- sprintf( __( 'ERROR %1$s %2$s - See full error by adding define( \'WP_STRAVA_DEBUG\', true ); to wp-config.php', 'wp-strava' ), $response['response']['code'], $response['response']['message'] ),
+ sprintf( __( 'ERROR %1$s %2$s - See full error by addingdefine( \'WP_STRAVA_DEBUG\', true );
to wp-config.php', 'wp-strava' ), $response['response']['code'], $response['response']['message'] ),
$error
);
}
@@ -76,7 +75,8 @@ class WPStrava_API {
}
if ( 200 != $response['response']['code'] ) {
- //see if there's useful info in the body
+
+ // See if there's useful info in the body.
$body = json_decode( $response['body'] );
$error = '';
if ( ! empty( $body->error ) ) {
@@ -90,7 +90,7 @@ class WPStrava_API {
return new WP_Error(
'wp-strava_get',
// Translators: message shown when there's a problem with an HTTP GET to the Strava API.
- sprintf( __( 'ERROR %1$s %2$s - See full error by adding define( \'WP_STRAVA_DEBUG\', true ); to wp-config.php', 'wp-strava' ), $response['response']['code'], $response['response']['message'] ),
+ sprintf( __( 'ERROR %1$s %2$s - See full error by addingdefine( \'WP_STRAVA_DEBUG\', true );
to wp-config.php', 'wp-strava' ), $response['response']['code'], $response['response']['message'] ),
$error
);
}
diff --git a/lib/Rides.class.php b/lib/Activity.class.php
similarity index 50%
rename from lib/Rides.class.php
rename to lib/Activity.class.php
index 2f70de0..4377836 100755
--- a/lib/Rides.class.php
+++ b/lib/Activity.class.php
@@ -1,23 +1,23 @@
get_api( $athlete_token )->get( "activities/{$activity_id}" );
- } // getRideDetails
+ }
/**
* Get activity list from Strava API.
@@ -27,9 +27,9 @@ class WPStrava_Rides {
* @param string $athlete_token Token of athlete to retrieve for
* @param int $club_id Club ID of all club riders (optional).
* @param int|null $quantity Number of records to retrieve (optional).
- * @return array|WP_Error Array of rides or WP_Error.
+ * @return array|WP_Error Array of activities or WP_Error.
*/
- public function getRides( $athlete_token, $club_id = null, $quantity = null ) {
+ public function get_activities( $athlete_token, $club_id = null, $quantity = null ) {
$api = WPStrava::get_instance()->get_api( $athlete_token );
$data = null;
@@ -53,20 +53,28 @@ class WPStrava_Rides {
return array();
- } // getRides
+ }
- public function getRidesLongerThan( $rides, $dist ) {
+ /**
+ * Undocumented function
+ *
+ * @param array $activities
+ * @param float $dist Distance in default system of measure (km/mi).
+ * @return void
+ * @author Justin Foell
+ */
+ public function get_activities_longer_than( $activities, $dist ) {
$som = WPStrava_SOM::get_som();
$meters = $som->distance_inverse( $dist );
- $long_rides = array();
- foreach ( $rides as $ride_info ) {
- if ( $ride_info->distance > $meters ) {
- $long_rides[] = $ride_info;
+ $long_activities = array();
+ foreach ( $activities as $activity_info ) {
+ if ( $activity_info->distance > $meters ) {
+ $long_activities[] = $activity_info;
}
}
- return $long_rides;
+ return $long_activities;
}
-} // class Rides
+}
diff --git a/lib/ActivityShortcode.class.php b/lib/ActivityShortcode.class.php
index 44477ca..69d9c62 100644
--- a/lib/ActivityShortcode.class.php
+++ b/lib/ActivityShortcode.class.php
@@ -4,7 +4,7 @@ class WPStrava_ActivityShortcode {
private static $add_script;
public static function init() {
- add_shortcode( 'ride', array( __CLASS__, 'handler' ) );
+ add_shortcode( 'ride', array( __CLASS__, 'handler' ) ); // @deprecated 1.1
add_shortcode( 'activity', array( __CLASS__, 'handler' ) );
add_action( 'wp_footer', array( __CLASS__, 'print_scripts' ) );
}
@@ -23,22 +23,30 @@ class WPStrava_ActivityShortcode {
'markers' => false,
);
- extract( shortcode_atts( $defaults, $atts ) );
+ $atts = shortcode_atts( $defaults, $atts );
- $strava_som = WPStrava_SOM::get_som( $som );
- $activity = WPStrava::get_instance()->rides;
- $ride_details = $activity->getRide( $athlete_token, $id );
+ $strava_som = WPStrava_SOM::get_som( $atts['som'] );
+ $activity = WPStrava::get_instance()->activity;
+ $activity_details = $activity->get_activity( $atts['athlete_token'], $atts['id'] );
+
+ if ( is_wp_error( $activity_details ) ) {
+ if ( WPSTRAVA_DEBUG ) {
+ return '
' . print_r( $activity_details, true ) . ''; // @codingStandardsIgnoreLine + } else { + return $activity_details->get_error_message(); + } + } //sanitize width & height - $map_width = str_replace( '%', '', $map_width ); - $map_height = str_replace( '%', '', $map_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 ); - if ( $ride_details ) { + if ( $activity_details ) { return ' -
| ' . __( 'Elapsed Time', 'wp-strava' ) . ' | @@ -50,15 +58,15 @@ class WPStrava_ActivityShortcode {|||||
|---|---|---|---|---|---|
| ' . $strava_som->time( $ride_details->elapsed_time ) . ' | -' . $strava_som->time( $ride_details->moving_time ) . ' | -' . $strava_som->distance( $ride_details->distance ) . ' | -' . $strava_som->speed( $ride_details->average_speed ) . ' | -' . $strava_som->speed( $ride_details->max_speed ) . ' | -' . $strava_som->elevation( $ride_details->total_elevation_gain ) . ' | +
| ' . $strava_som->time( $activity_details->elapsed_time ) . ' | +' . $strava_som->time( $activity_details->moving_time ) . ' | +' . $strava_som->distance( $activity_details->distance ) . ' | +' . $strava_som->speed( $activity_details->average_speed ) . ' | +' . $strava_som->speed( $activity_details->max_speed ) . ' | +' . $strava_som->elevation( $activity_details->total_elevation_gain ) . ' |
| ' . $strava_som->get_time_label() . ' | ' . $strava_som->get_time_label() . ' | ' . $strava_som->get_distance_label() . ' | @@ -67,11 +75,12 @@ class WPStrava_ActivityShortcode {' . $strava_som->get_elevation_label() . ' |
'; - print_r( $rides ); // @codingStandardsIgnoreLine + print_r( $activities ); // @codingStandardsIgnoreLine echo ''; } else { - echo $rides->get_error_message(); + echo $activities->get_error_message(); } - echo $after_widget; + echo $args['$after_widget']; return; } - if ( ! empty( $rides ) ) { + if ( ! empty( $activities ) ) { if ( ! empty( $distance_min ) ) { - $rides = $strava_rides->getRidesLongerThan( $rides, $distance_min ); + $activities = $strava_activity->get_activities_longer_than( $activities, $distance_min ); } - $ride = current( $rides ); + $activity = current( $activities ); // Compare transient (temporary storage) to option (more permenant). // If the option isn't set or the transient is different, update the option. - if ( empty( $ride_option->id ) || $ride->id != $ride_option->id ) { + if ( empty( $activity_option->id ) || $activity->id != $activity_option->id ) { $build_new = true; - $this->update_activity( $athlete_token, $ride ); + $this->update_activity( $athlete_token, $activity ); } // Update the transient if it needs updating. - if ( empty( $ride_transient->id ) || $ride->id != $ride_transient->id ) { - $this->update_activity_transient( $athlete_token, $ride ); + if ( empty( $activity_transient->id ) || $activity->id != $activity_transient->id ) { + $this->update_activity_transient( $athlete_token, $activity ); } } } - if ( $ride ) { - echo $before_widget; + if ( $activity ) { + echo $args['$before_widget']; if ( $title ) { - echo $before_title . $title . $after_title; + echo $args['$before_title'] . $title . $args['$after_title']; } - echo ""; - echo $this->getStaticImage( $athlete_token, $ride, $build_new ); + echo ""; + echo $this->get_static_image( $athlete_token, $activity, $build_new ); echo ''; - echo $after_widget; + echo $args['$after_widget']; } } /** - * Get image for specific ride using Static Maps class. + * Get image for specific activity using Static Maps class. * * @author Justin Foell * * @param string $athlete_token Token for athelete. - * @param int $ride_id Club ID (optional). - * @param boolean $build_new Whether to refresh the image from cache. - * @return string Image tag. + * @param object $activity Activity to get image for. + * @param boolean $build_new Whether to refresh the image from cache. + * @return string Image tag. */ - private function getStaticImage( $athlete_token, $ride, $build_new ) { + private function get_static_image( $athlete_token, $activity, $build_new ) { $img = get_option( 'strava_latest_map_' . $athlete_token ); if ( $build_new || ! $img ) { - $img = WPStrava_StaticMap::get_image_tag( $ride ); + $img = WPStrava_StaticMap::get_image_tag( $activity ); $this->update_map( $athlete_token, $img ); } diff --git a/lib/RouteShortcode.class.php b/lib/RouteShortcode.class.php index 23cfc12..c7f848d 100644 --- a/lib/RouteShortcode.class.php +++ b/lib/RouteShortcode.class.php @@ -1,5 +1,11 @@ false, ); - extract( shortcode_atts( $defaults, $atts ) ); + $atts = shortcode_atts( $defaults, $atts ); - $strava_som = WPStrava_SOM::get_som( $som ); + $strava_som = WPStrava_SOM::get_som( $atts['som'] ); $route = WPStrava::get_instance()->routes; - $route_details = $route->get_route( $id ); + $route_details = $route->get_route( $atts['id'] ); + + if ( is_wp_error( $route_details ) ) { + if ( WPSTRAVA_DEBUG ) { + return '
' . print_r( $route_details, true ) . ''; // @codingStandardsIgnoreLine + } else { + return $route_details->get_error_message(); + } + } //sanitize width & height - $map_width = str_replace( '%', '', $map_width ); - $map_height = str_replace( '%', '', $map_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 ); if ( $route_details ) { return ' -
| ' . __( 'Est. Moving Time', 'wp-strava' ) . ' | @@ -46,22 +60,24 @@ class WPStrava_RouteShortcode {||
|---|---|---|
| ' . $strava_som->time( $route_details->estimated_moving_time ) . ' | ' . $strava_som->distance( $route_details->distance ) . ' | ' . $strava_som->elevation( $route_details->elevation_gain ) . ' |
| ' . $strava_som->get_time_label() . ' | ' . $strava_som->get_distance_label() . ' | ' . $strava_som->get_elevation_label() . ' |
Steps: