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 adding
define( \'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 adding
define( \'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 ' -
- +
+
@@ -50,15 +58,15 @@ class WPStrava_ActivityShortcode { - - - - - - - + + + + + + + - + @@ -67,11 +75,12 @@ class WPStrava_ActivityShortcode { -
' . __( 'Elapsed Time', 'wp-strava' ) . '
' . $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() . '' . $strava_som->get_elevation_label() . '
' . - WPStrava_StaticMap::get_image_tag( $ride_details, $map_height, $map_width, $markers ) . + + ' . + WPStrava_StaticMap::get_image_tag( $activity_details, $map_height, $map_width, $atts['markers'] ) . '
'; - } // End if( $ride_details ). - } // handler + } // End if( $activity_details ). + } public static function print_scripts() { if ( self::$add_script ) { diff --git a/lib/LatestActivities.class.php b/lib/LatestActivities.class.php index bb4d6a7..c3d4336 100644 --- a/lib/LatestActivities.class.php +++ b/lib/LatestActivities.class.php @@ -12,33 +12,33 @@ class WPStava_LatestActivities { $args = wp_parse_args( $args, $defaults ); - $som = WPStrava_SOM::get_som( $args['som'] ); - $strava_rides = WPStrava::get_instance()->rides; - $rides = $strava_rides->getRides( $args['athlete_token'], $args['strava_club_id'], $args['quantity'] ); + $som = WPStrava_SOM::get_som( $args['som'] ); + $strava_activity = WPStrava::get_instance()->activity; + $activities = $strava_activity->get_activities( $args['athlete_token'], $args['strava_club_id'], $args['quantity'] ); - if ( is_wp_error( $rides ) ) { - return $rides->get_error_message(); + if ( is_wp_error( $activities ) ) { + return $activities->get_error_message(); } - $response = "