Removed all instances of 'ride' in favor of 'activity'

Removed all extract()
Updated code standards and documentation
Update readme
This commit is contained in:
Justin Foell
2018-01-26 13:27:57 -06:00
parent 49f82ca890
commit ffe977cbf3
18 changed files with 319 additions and 216 deletions
+8 -8
View File
@@ -1,12 +1,10 @@
<?php
/*
* Util is a class with all the utility methods.
* API class for all remote calls.
*/
class WPStrava_API {
//deactivated
//const STRAVA_V1_API = 'http://www.strava.com/api/v1/'; //rides?athleteId=134698
//const STRAVA_V2_API = 'http://www.strava.com/api/v2/'; //rides/:ride_id/map_details
const STRAVA_V3_API = 'https://www.strava.com/api/v3/';
public function __construct( $access_token = null ) {
@@ -33,7 +31,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 ) ) {
@@ -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 <code>define( \'WP_STRAVA_DEBUG\', true );</code> to wp-config.php', 'wp-strava' ), $response['response']['code'], $response['response']['message'] ),
sprintf( __( 'ERROR %1$s %2$s - See full error by adding<br/><code>define( \'WP_STRAVA_DEBUG\', true );</code><br/>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 <code>define( \'WP_STRAVA_DEBUG\', true );</code> to wp-config.php', 'wp-strava' ), $response['response']['code'], $response['response']['message'] ),
sprintf( __( 'ERROR %1$s %2$s - See full error by adding<br/><code>define( \'WP_STRAVA_DEBUG\', true );</code><br/>to wp-config.php', 'wp-strava' ), $response['response']['code'], $response['response']['message'] ),
$error
);
}
+27 -19
View File
@@ -1,23 +1,23 @@
<?php
/*
* Rides is a class wrapper for the Strava REST API functions.
* Activity is a class wrapper for the Strava REST API functions.
*/
class WPStrava_Rides {
class WPStrava_Activity {
const ACTIVITIES_URL = 'http://app.strava.com/activities/';
const ATHLETES_URL = 'http://app.strava.com/athletes/';
const ACTIVITIES_URL = 'http://strava.com/activities/';
const ATHLETES_URL = 'http://strava.com/athletes/';
/**
* Get single activity by ID.
*
* @param string $athlete_token Token of athlete to retrieve for
* @param int $activity_id ID of activity to retrieve.
* @return object stdClass representing this activty.
* @param string $athlete_token Token of athlete to retrieve for
* @param int $activity_id ID of activity to retrieve.
* @return object stdClass representing this activity.
* @author Justin Foell
*/
public function getRide( $athlete_token, $activity_id ) {
public function get_activity( $athlete_token, $activity_id ) {
return WPStrava::get_instance()->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
}
+31 -22
View File
@@ -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 '<pre>' . print_r( $activity_details, true ) . '</pre>'; // @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 '
<div id="ride-header-' . $id . '" class="wp-strava-ride-container">
<table id="ride-details-table">
<div id="activity-header-' . $atts['id'] . '" class="wp-strava-activity-container">
<table id="activity-details-table">
<thead>
<tr>
<th>' . __( 'Elapsed Time', 'wp-strava' ) . '</th>
@@ -50,15 +58,15 @@ class WPStrava_ActivityShortcode {
</tr>
</thead>
<tbody>
<tr class="ride-details-table-info">
<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>
<tr class="activity-details-table-info">
<td>' . $strava_som->time( $activity_details->elapsed_time ) . '</td>
<td>' . $strava_som->time( $activity_details->moving_time ) . '</td>
<td>' . $strava_som->distance( $activity_details->distance ) . '</td>
<td>' . $strava_som->speed( $activity_details->average_speed ) . '</td>
<td>' . $strava_som->speed( $activity_details->max_speed ) . '</td>
<td>' . $strava_som->elevation( $activity_details->total_elevation_gain ) . '</td>
</tr>
<tr class="ride-details-table-units">
<tr class="activity-details-table-units">
<td>' . $strava_som->get_time_label() . '</td>
<td>' . $strava_som->get_time_label() . '</td>
<td>' . $strava_som->get_distance_label() . '</td>
@@ -67,11 +75,12 @@ class WPStrava_ActivityShortcode {
<td>' . $strava_som->get_elevation_label() . '</td>
</tr>
</tbody>
</table>' .
WPStrava_StaticMap::get_image_tag( $ride_details, $map_height, $map_width, $markers ) .
</table>
<a title="' . $activity_details->name . '" href="' . WPStrava_Activity::ACTIVITIES_URL . $activity_details->id . '">' .
WPStrava_StaticMap::get_image_tag( $activity_details, $map_height, $map_width, $atts['markers'] ) .
'</div>';
} // End if( $ride_details ).
} // handler
} // End if( $activity_details ).
}
public static function print_scripts() {
if ( self::$add_script ) {
+15 -15
View File
@@ -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 = "<ul id='rides'>";
foreach ( $rides as $ride ) {
$response .= "<li class='ride'>";
$response .= "<a href='" . WPStrava_Rides::ACTIVITIES_URL . $ride->id . "' target='_blank'>" . $ride->name . '</a>';
$response .= "<div class='ride-item'>";
$unixtime = strtotime( $ride->start_date_local );
$response = "<ul id='activities'>";
foreach ( $activities as $activity ) {
$response .= "<li class='activity'>";
$response .= "<a href='" . WPStrava_Activity::ACTIVITIES_URL . $activity->id . "'>" . $activity->name . '</a>';
$response .= "<div class='activity-item'>";
$unixtime = strtotime( $activity->start_date_local );
// Translators: Shows something like "On <date> <[went 10 miles] [during 2 hours] [climbing 100 feet]>."
$response .= sprintf( __( 'On %1$s %2$s', 'wp-strava' ), date_i18n( get_option( 'date_format' ), $unixtime ), date_i18n( get_option( 'time_format' ), $unixtime ) );
if ( is_numeric( $args['strava_club_id'] ) ) {
$response .= " <a href='" . WPStrava_Rides::ATHLETES_URL . $ride->athlete_id . "'>" . $ride->athlete_name . '</a>';
$response .= " <a href='" . WPStrava_Activity::ATHLETES_URL . $activity->athlete_id . "'>" . $activity->athlete_name . '</a>';
}
// Translators: "went 10 miles"
$response .= sprintf( __( ' went %1$s %2$s', 'wp-strava' ), $som->distance( $ride->distance ), $som->get_distance_label() );
$response .= sprintf( __( ' went %1$s %2$s', 'wp-strava' ), $som->distance( $activity->distance ), $som->get_distance_label() );
// Translators: "during 2 hours"
$response .= sprintf( __( ' during %1$s %2$s', 'wp-strava' ), $som->time( $ride->elapsed_time ), $som->get_time_label() );
$response .= sprintf( __( ' during %1$s %2$s', 'wp-strava' ), $som->time( $activity->elapsed_time ), $som->get_time_label() );
// Translators: "climbing 100 ft."
$response .= sprintf( __( ' climbing %1$s %2$s', 'wp-strava' ), $som->elevation( $ride->total_elevation_gain ), $som->get_elevation_label() );
$response .= sprintf( __( ' climbing %1$s %2$s', 'wp-strava' ), $som->elevation( $activity->total_elevation_gain ), $som->get_elevation_label() );
$response .= '</div></li>';
}
$response .= '</ul>';
+1 -1
View File
@@ -10,7 +10,7 @@ class WPStrava_LatestActivitiesWidget extends WP_Widget {
public function __construct() {
$widget_ops = array(
'classname' => 'LatestActivitiesWidget',
'description' => __( 'Will publish your latest activities from strava.com.', 'wp-strava' ),
'description' => __( 'Will show your latest activities from strava.com.', 'wp-strava' ),
);
parent::__construct( 'wp-strava', __( 'Strava Latest Activities List', 'wp-strava' ), $widget_ops );
add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue' ) );
+37 -32
View File
@@ -56,8 +56,13 @@ class WPStrava_LatestMapWidget extends WP_Widget {
return $instance;
}
/**
* Method to render the widget on the front end.
*
* @param array $args Arguments from the widget settings.
* @param array $instance Settings for this particular widget.
*/
public function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Latest Activity Map', 'wp-strava' ) : $instance['title'] );
$athlete_token = isset( $instance['athlete_token'] ) ? $instance['athlete_token'] : WPStrava::get_instance()->settings->get_default_token();
@@ -66,82 +71,82 @@ class WPStrava_LatestMapWidget extends WP_Widget {
$build_new = false;
// Try our transient first.
$ride_transient = get_transient( 'strava_latest_map_activity_' . $athlete_token );
$ride_option = get_option( 'strava_latest_map_activity_' . $athlete_token );
$activity_transient = get_transient( 'strava_latest_map_activity_' . $athlete_token );
$activity_option = get_option( 'strava_latest_map_activity_' . $athlete_token );
$ride = $ride_transient ? $ride_transient : null;
$activity = $activity_transient ? $activity_transient : null;
if ( ! $ride ) {
$strava_rides = WPStrava::get_instance()->rides;
$rides = $strava_rides->getRides( $athlete_token, $strava_club_id );
if ( ! $activity ) {
$strava_activity = WPStrava::get_instance()->activity;
$activities = $strava_activity->get_activities( $athlete_token, $strava_club_id );
if ( is_wp_error( $rides ) ) {
echo $before_widget;
if ( is_wp_error( $activities ) ) {
echo $args['before_widget'];
if ( $title ) {
echo $before_title . $title . $after_title;
echo $args['$before_title'] . $title . $args['$after_title'];
}
if ( WPSTRAVA_DEBUG ) {
echo '<pre>';
print_r( $rides ); // @codingStandardsIgnoreLine
print_r( $activities ); // @codingStandardsIgnoreLine
echo '</pre>';
} 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 "<a title='{$ride->name}' target='_blank' href='http://app.strava.com/activities/{$ride->id}'>";
echo $this->getStaticImage( $athlete_token, $ride, $build_new );
echo "<a title='{$activity->name}' href='http://app.strava.com/activities/{$activity->id}'>";
echo $this->get_static_image( $athlete_token, $activity, $build_new );
echo '</a>';
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 );
}
+29 -13
View File
@@ -1,5 +1,11 @@
<?php
/**
* Route Shortcode.
*
* @author Daniel Lintott
* @since 1.3.0
*/
class WPStrava_RouteShortcode {
private static $add_script;
@@ -22,22 +28,30 @@ class WPStrava_RouteShortcode {
'markers' => 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 '<pre>' . print_r( $route_details, true ) . '</pre>'; // @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 '
<div id="ride-header-' . $id . '" class="wp-strava-ride-container">
<table id="ride-details-table">
<div id="activity-header-' . $atts['id'] . '" class="wp-strava-activity-container">
<table id="activity-details-table">
<thead>
<tr>
<th>' . __( 'Est. Moving Time', 'wp-strava' ) . '</th>
@@ -46,22 +60,24 @@ class WPStrava_RouteShortcode {
</tr>
</thead>
<tbody>
<tr class="ride-details-table-info">
<tr class="activity-details-table-info">
<td>' . $strava_som->time( $route_details->estimated_moving_time ) . '</td>
<td>' . $strava_som->distance( $route_details->distance ) . '</td>
<td>' . $strava_som->elevation( $route_details->elevation_gain ) . '</td>
</tr>
<tr class="ride-details-table-units">
<tr class="activity-details-table-units">
<td>' . $strava_som->get_time_label() . '</td>
<td>' . $strava_som->get_distance_label() . '</td>
<td>' . $strava_som->get_elevation_label() . '</td>
</tr>
</tbody>
</table>' .
WPStrava_StaticMap::get_image_tag( $route_details, $map_height, $map_width, $markers ) .
'</div>';
</table>
<a title="' . $route_details->name . '" href="' . WPStrava_Routes::ROUTES_URL . $route_details->id . '">' .
WPStrava_StaticMap::get_image_tag( $route_details, $map_height, $map_width, $atts['markers'] ) .
'</a>
</div>';
} // End if( $route_details ).
} // handler
}
public static function print_scripts() {
if ( self::$add_script ) {
+7 -4
View File
@@ -1,10 +1,13 @@
<?php
/*
* Routes is a class wrapper for the Strava REST API functions.
*/
/**
* Routes is a class wrapper for the Strava REST API functions.
*
* @author Daniel Lintott
* @since 1.3.0
*/
class WPStrava_Routes {
const ROUTES_URL = 'http://app.strava.com/routes/';
const ROUTES_URL = 'http://strava.com/routes/';
/**
* Get single route by ID.
+11 -4
View File
@@ -2,16 +2,23 @@
abstract class WPStrava_SOM {
/**
* Factory method to get the correct SOM class based on specified units
* or by the options setting.
*
* @param string $som 'english' or 'metric'
* @return WPStrava_SOM Instance of SOM
* @author Justin Foell
*/
public static function get_som( $som = null ) {
$som = $som ? $som : WPStrava::get_instance()->settings->som;
if ( 'english' === $som ) {
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();
}
// Default to metric.
require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMMetric.class.php';
return new WPStrava_SOMMetric();
}
abstract public function distance( $m );
+36 -8
View File
@@ -1,47 +1,75 @@
<?php
/**
* SOM English class.
*
* All conversions are limited to 2 decimal places.
*/
class WPStrava_SOMEnglish extends WPStrava_SOM {
/**
* @param string $m meters
* @return string mi
* Change meters to miles.
*
* @param float $m Distance in meters.
* @return float Distance in miles.
*/
public function distance( $m ) {
return number_format( $m / 1609.344, 2 );
}
/**
* @param string $dist miles
* @return float meters
* Change miles to meters.
*
* @param float $dist Distance in miles.
* @return float Distance in meters.
*/
public function distance_inverse( $dist ) {
return $dist * 1609.344;
}
/**
* Abbreviated label for this system of measure's distance - Miles: mi.
*
* @return string 'mi.'
*/
public function get_distance_label() {
return __( 'mi.', 'wp-strava' );
}
/**
* @param string $mps
* @return string mph
* Change meters per second to miles per hour.
*
* @param float $mps Meters per second.
* @return float Miles per hour.
*/
public function speed( $mps ) {
return number_format( $mps * 2.2369, 2 );
}
/**
* Abbreviated label for this system of measure's speed - Miles Per Hour: mph
*
* @return string 'mph'
*/
public function get_speed_label() {
return __( 'mph', 'wp-strava' );
}
/**
* @param string $m meters
* @return string feet
* Change meters to feet.
*
* @param float $m Elevation in meters.
* @return float Elevation in feet.
*/
public function elevation( $m ) {
return number_format( $m / 0.3048, 2 );
}
/**
* Abbreviated label for this system of measure's elevation - Feet: ft.
*
* @return string 'ft.'
*/
public function get_elevation_label() {
return __( 'ft.', 'wp-strava' );
}
+37 -8
View File
@@ -1,46 +1,75 @@
<?php
/**
* SOM Metric class.
*
* All conversions are limited to 2 decimal places.
*/
class WPStrava_SOMMetric extends WPStrava_SOM {
/**
* @param $m meters
* @return string km
* Change meters to kilometers.
*
* @param float $m Distance in meters.
* @return float Distance in kilometers.
*/
public function distance( $m ) {
return number_format( $m / 1000, 2 );
}
/**
* @param string $dist km
* @return string meters
* Change kilometers to meters.
*
* @param float $dist Distance in kilometers.
* @return float Distance in meters.
*/
public function distance_inverse( $dist ) {
return $dist * 1000;
}
/**
* Abbreviated label for this system of measure's distance - Kilometers: km
*
* @return string 'km'
*/
public function get_distance_label() {
return __( 'km', 'wp-strava' );
}
/**
* @param $mps
* @return string km/h
* Change meters per second to kilometers per hour.
*
* @param float $mps Meters per second.
* @return float Kilometers per hour.
*/
public function speed( $mps ) {
return number_format( $mps * 3.6, 2 );
}
/**
* Abbreviated label for this system of measure's speed - Kilometers Per Hour: km/h
*
* @return string 'km/h'
*/
public function get_speed_label() {
return __( 'km/h', 'wp-strava' );
}
/**
* @param $m meters
* @return string meters
* Change meters to meters };^)
*
* @param $m Elevation in meters.
* @return string Elevation in meters.
*/
public function elevation( $m ) {
return number_format( $m, 2 );
}
/**
* Abbreviated label for this system of measure's elevation - Meters: meters
*
* @return string 'meters'
*/
public function get_elevation_label() {
return __( 'meters', 'wp-strava' );
}
+4 -12
View File
@@ -23,7 +23,6 @@ class WPStrava_Settings {
add_action( 'admin_menu', array( $this, 'add_strava_menu' ) );
add_filter( 'pre_set_transient_settings_errors', array( $this, 'maybe_oauth' ) );
add_filter( 'plugin_action_links_' . WPSTRAVA_PLUGIN_NAME, array( $this, 'settings_link' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'settings_scripts' ) );
}
/**
@@ -146,9 +145,9 @@ class WPStrava_Settings {
$description = sprintf( __( 'WP-Strava for %s', 'wp-strava' ), $blog_name );
printf( __( "<p>Steps:</p>
<ol>
<li>Create your free API Application/Connection here: <a href='%1\$s' target='_blank'>%2\$s</a> using the following information:</li>
<li>Create your free API Application/Connection here: <a href='%1\$s'>%2\$s</a> using the following information:</li>
<ul>
<li>App Icon: <strong>upload <a href='%3\$s' target='_blank'>this image</a></strong></li>
<li>App Icon: <strong>upload <a href='%3\$s'>this image</a></strong></li>
<li>Application Name: <strong>%4\$s</strong></li>
<li>Category: OK to leave at default 'other'</li>
<li>Club: OK to leave blank</li>
@@ -174,7 +173,7 @@ class WPStrava_Settings {
$maps_url = 'https://developers.google.com/maps/documentation/static-maps/';
printf( __( "<p>Steps:</p>
<ol>
<li>To use Google map images, you must create a Static Maps API Key. Create a free key by going here: <a href='%1\$s' target='_blank'>%2\$s</a> and clicking <strong>Get a Key</strong></li>
<li>To use Google map images, you must create a Static Maps API Key. Create a free key by going here: <a href='%1\$s'>%2\$s</a> and clicking <strong>Get a Key</strong></li>
<li>Once you've created your Google Static Maps API Key, enter the key below.
</ol>", 'wp-strava' ), $maps_url, $maps_url );
@@ -432,7 +431,7 @@ class WPStrava_Settings {
* @return string
*/
private function get_default_nickname( $number = 1 ) {
// Translators: Athelete number if no nickname present.
// Translators: Athlete number if no nickname present.
return ( 1 === $number ) ? __( 'Default', 'wp-strava' ) : sprintf( __( 'Athlete %s', 'wp-strava' ), $number );
}
@@ -488,11 +487,4 @@ class WPStrava_Settings {
$links[] = $settings_link;
return $links;
}
public function settings_scripts() {
$screen = get_current_screen();
if ( "settings_page_{$this->page_name}" === $screen->id ) {
wp_enqueue_script( 'wp-strava-settings', WPSTRAVA_PLUGIN_URL . 'js/wp-strava-settings.js', array( 'jquery' ) );
}
}
}
+23 -13
View File
@@ -9,17 +9,17 @@ class WPStrava_StaticMap {
*
* @static
* @access public
* @param object $ride Ride object from strava.
* @param int $height Height of map in pixels.
* @param int $width Width of map in pixels.
* @param bool $markers Display start and finish markers.
* @return string HTML img tag with static map image.
* @param object $activity Activity object to get image tag for.
* @param int $height Height of map in pixels.
* @param int $width Width of map in pixels.
* @param bool $markers Display start and finish markers.
* @return string HTML img tag with static map image.
*/
public static function get_image_tag( $ride, $height = 320, $width = 480, $markers = false ) {
public static function get_image_tag( $activity, $height = 320, $width = 480, $markers = false, $link = true ) {
$key = WPStrava::get_instance()->settings->gmaps_key;
// Short circuit if missing key or ride object doesn't have the data we need.
if ( empty( $key ) || empty( $ride->map ) ) {
// Short circuit if missing key or activity object doesn't have the data we need.
if ( empty( $key ) || empty( $activity->map ) ) {
return '';
}
@@ -28,10 +28,10 @@ class WPStrava_StaticMap {
$max_chars = 1865;
$polyline = '';
if ( ! empty( $ride->map->polyline ) && ( $url_len + strlen( $ride->map->polyline ) < $max_chars ) ) {
$polyline = $ride->map->polyline;
} elseif ( ! empty( $ride->map->summary_polyline ) ) {
$polyline = $ride->map->summary_polyline;
if ( ! empty( $activity->map->polyline ) && ( $url_len + strlen( $activity->map->polyline ) < $max_chars ) ) {
$polyline = $activity->map->polyline;
} elseif ( ! empty( $activity->map->summary_polyline ) ) {
$polyline = $activity->map->summary_polyline;
}
$url .= $polyline;
@@ -53,7 +53,17 @@ class WPStrava_StaticMap {
* @see https://developers.google.com/maps/documentation/utilities/polylinealgorithm
* @access private
* @param string $enc Encoded polyline.
* @return array with indexes of start & finish containing lat/lon for each.
* @return array {
* Indexes of start & finish containing lat/lon for each.
* @type array $start {
* @type float $0 Latitude
* @type float $1 Longitude
* }
* @type array $finish {
* @type float $0 Latitude
* @type float $1 Longitude
* }
* }
*/
private static function decode_start_finish( $enc ) {
require_once WPSTRAVA_PLUGIN_DIR . 'lib/Polyline.php';
+8 -8
View File
@@ -12,7 +12,7 @@ class WPStrava {
private static $instance = null;
private $settings = null;
private $api = array(); // Holds an array of APIs.
private $rides = null;
private $activity = null;
private $routes = null;
private function __construct() {
@@ -38,8 +38,8 @@ class WPStrava {
public function __get( $name ) {
// On-demand classes.
if ( 'rides' === $name ) {
return $this->get_rides();
if ( 'activity' === $name ) {
return $this->get_activity();
}
if ( 'routes' === $name ) {
@@ -66,13 +66,13 @@ class WPStrava {
return $this->api[ $token ];
}
public function get_rides() {
if ( ! $this->rides ) {
require_once WPSTRAVA_PLUGIN_DIR . 'lib/Rides.class.php';
$this->rides = new WPStrava_Rides();
public function get_activity() {
if ( ! $this->activity ) {
require_once WPSTRAVA_PLUGIN_DIR . 'lib/Activity.class.php';
$this->activity = new WPStrava_Activity();
}
return $this->rides;
return $this->activity;
}
public function get_routes() {