Changes for better language support

Cleaned up more formatting
This commit is contained in:
Justin Foell
2017-05-26 10:53:24 -05:00
parent 2e99255fa5
commit 0d797b90ad
14 changed files with 115 additions and 109 deletions
+8 -8
View File
@@ -12,8 +12,8 @@ class WPStrava_API {
public function __construct( $access_token ) {
$this->access_token = $access_token;
}
public function post( $uri, $data = NULL ) {
public function post( $uri, $data = null ) {
$url = self::STRAVA_V3_API;
$args = array(
@@ -46,7 +46,7 @@ class WPStrava_API {
return json_decode( $response['body'] );
}
public function get( $uri, $args = NULL ) {
public function get( $uri, $args = null ) {
$url = self::STRAVA_V3_API;
$url .= $uri;
@@ -59,12 +59,12 @@ class WPStrava_API {
'Authorization' => 'Bearer ' . $this->access_token,
)
);
$response = wp_remote_get( $url, $get_args );
if ( is_wp_error( $response ) )
return $response;
if ( $response['response']['code'] != 200 ) {
//see if there's useful info in the body
$body = json_decode( $response['body'] );
@@ -77,11 +77,11 @@ class WPStrava_API {
$error = print_r( $response, true );
return new WP_Error( 'wp-strava_get',
sprintf( __( 'ERROR %s %s - %s', 'wp-strava'), $response['response']['code'], $response['response']['message'], $error ),
sprintf( __( 'ERROR %s %s - %s', 'wp-strava' ), $response['response']['code'], $response['response']['message'], $error ),
$response );
}
return json_decode( $response['body'] );
}
} // class API
} // Class API.
+14 -14
View File
@@ -9,34 +9,34 @@ class WPStrava_LatestMapWidget extends WP_Widget {
parent::__construct(
false,
'Strava Latest Map', // Name
array( 'description' => __( 'Strava latest ride using static google map image', 'wp-strava' ), ) // Args
__( 'Strava Latest Map', 'wp-strava' ), // Name
array( 'description' => __( 'Strava latest ride using static google map image', 'wp-strava' ) ) // Args.
);
}
public function form( $instance ) {
// outputs the options form on admin
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : __( 'Latest Activity', 'wp-strava' );
$distance_min = isset( $instance['distance_min'] ) ? esc_attr( $instance['distance_min'] ) : '';
$distance_min = isset( $instance['distance_min'] ) ? esc_attr( $instance['distance_min'] ) : '';
$strava_club_id = isset( $instance['strava_club_id'] ) ? esc_attr( $instance['strava_club_id'] ) : '';
//provide some defaults
//$ride_index_params = $ride_index_params ?: 'athleteId=21';
//$ride_index_params = $ride_index_params ?: 'athleteId=21';
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'wp-strava' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<p>
<label for="<?php echo $this->get_field_id( 'distance_min' ); ?>"><?php echo sprintf( __( 'Min. Distance (%s):', 'wp-strava' ), $this->som->get_distance_label() ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'distance_min' ); ?>" name="<?php echo $this->get_field_name( 'distance_min' ); ?>" type="text" value="<?php echo $distance_min; ?>" />
</p>
<input class="widefat" id="<?php echo $this->get_field_id( 'distance_min' ); ?>" name="<?php echo $this->get_field_name( 'distance_min' ); ?>" type="text" value="<?php echo $distance_min; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('strava_club_id'); ?>"><?php _e('Club ID (leave blank to show Athlete):'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('strava_club_id'); ?>" name="<?php echo $this->get_field_name('strava_club_id'); ?>" type="text" value="<?php echo $strava_club_id; ?>" />
<label for="<?php echo $this->get_field_id( 'strava_club_id' ); ?>"><?php _e( 'Club ID (leave blank to show Athlete):', 'wp-strava' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'strava_club_id' ); ?>" name="<?php echo $this->get_field_name( 'strava_club_id' ); ?>" type="text" value="<?php echo $strava_club_id; ?>" />
</p>
<?php
<?php
}
public function update( $new_instance, $old_instance ) {
@@ -45,7 +45,7 @@ class WPStrava_LatestMapWidget extends WP_Widget {
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['strava_club_id'] = strip_tags( $new_instance['strava_club_id'] );
$instance['distance_min'] = strip_tags( $new_instance['distance_min'] );
return $instance;
return $instance;
}
public function widget( $args, $instance ) {
@@ -53,7 +53,7 @@ class WPStrava_LatestMapWidget extends WP_Widget {
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Latest Activity', 'wp-strava' ) : $instance['title'] );
$distance_min = $instance['distance_min'];
$strava_club_id = empty( $instance['strava_club_id'] ) ? NULL : $instance['strava_club_id'];
$strava_club_id = empty( $instance['strava_club_id'] ) ? null : $instance['strava_club_id'];
$build_new = false;
// Try our transient first.
@@ -120,4 +120,4 @@ class WPStrava_LatestMapWidget extends WP_Widget {
return $img;
}
}
}
+30 -30
View File
@@ -4,10 +4,10 @@
* WP Strava Latest Rides Widget Class
*/
class WPStrava_LatestRidesWidget extends WP_Widget {
public function __construct() {
$widget_ops = array( 'classname' => 'LatestRidesWidget', 'description' => __( 'Will publish your latest rides activity from strava.com.' ) );
parent::__construct( 'wp-strava', $name = 'Strava Latest Rides', $widget_ops );
$widget_ops = array( 'classname' => 'LatestRidesWidget', 'description' => __( 'Will publish your latest rides activity from strava.com.', 'wp-strava' ) );
parent::__construct( 'wp-strava', $name = __( 'Strava Latest Rides', 'wp-strava' ), $widget_ops );
add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue' ) );
}
@@ -16,11 +16,11 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
wp_enqueue_style( 'wp-strava-style' ); //only load this when wigit is loaded
}
}
/** @see WP_Widget::widget */
public function widget( $args, $instance ) {
extract( $args );
//$widget_id = $args['widget_id'];
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Rides', 'wp-strava' ) : $instance['title'] );
$strava_club_id = empty( $instance['strava_club_id'] ) ? '' : $instance['strava_club_id'];
@@ -32,72 +32,72 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
<?php echo $this->strava_request_handler( $strava_club_id, $quantity ); ?>
<?php echo $after_widget; ?>
<?php
<?php
}
/** @see WP_Widget::update */
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['strava_club_id'] = strip_tags( $new_instance['strava_club_id'] );
$instance['quantity'] = $new_instance['quantity'];
return $instance;
}
/** @see WP_Widget::form */
public function form( $instance ) {
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : __( 'Rides', 'wp-strava' );
$strava_club_id = isset( $instance['strava_club_id'] ) ? esc_attr( $instance['strava_club_id'] ) : '';
$quantity = isset( $instance['quantity'] ) ? absint( $instance['quantity'] ) : 5;
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'wp-strava' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('strava_club_id'); ?>"><?php _e('Club ID (leave blank to show Athlete):'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('strava_club_id'); ?>" name="<?php echo $this->get_field_name('strava_club_id'); ?>" type="text" value="<?php echo $strava_club_id; ?>" />
<label for="<?php echo $this->get_field_id( 'strava_club_id' ); ?>"><?php _e( 'Club ID (leave blank to show Athlete):', 'wp-strava' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('strava_club_id'); ?>" name="<?php echo $this->get_field_name( 'strava_club_id' ); ?>" type="text" value="<?php echo $strava_club_id; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('quantity'); ?>"><?php _e('Quantity:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('quantity'); ?>" name="<?php echo $this->get_field_name('quantity'); ?>" type="text" value="<?php echo $quantity; ?>" />
<label for="<?php echo $this->get_field_id( 'quantity' ); ?>"><?php _e( 'Quantity:', 'wp-strava' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'quantity' ); ?>" name="<?php echo $this->get_field_name( 'quantity' ); ?>" type="text" value="<?php echo $quantity; ?>" />
</p>
<?php
}
<?php
}
// The handler to the ajax call, we will avoid this if Strava support jsonp request and we can do it
// the parsing directly on the jQuery ajax call, the returned text will be enclosed in the $response variable.
private function strava_request_handler( $strava_club_id, $quantity ) {
$strava_rides = WPStrava::get_instance()->rides;
$rides = $strava_rides->getRides( $strava_club_id, $quantity );
if ( is_wp_error( $rides ) )
return $rides->get_error_message();
$response = "<ul id='rides'>";
foreach( $rides as $ride ) {
foreach ( $rides as $ride ) {
$response .= "<li class='ride'>";
$response .= "<a href='" . WPStrava_Rides::RIDES_URL . $ride->id . "' target='_blank'>" . $ride->name . "</a>";
$response .= "<a href='" . WPStrava_Rides::RIDES_URL . $ride->id . "' target='_blank'>" . $ride->name . '</a>';
$response .= "<div class='ride-item'>";
$unixtime = strtotime( $ride->start_date_local );
$response .= sprintf( __("On %s %s", "wp-strava"), date_i18n( get_option( 'date_format' ), $unixtime ), date_i18n( get_option( 'time_format' ), $unixtime ) );
$response .= sprintf( __( 'On %s %s', 'wp-strava' ), date_i18n( get_option( 'date_format' ), $unixtime ), date_i18n( get_option( 'time_format' ), $unixtime ) );
if ( is_numeric( $strava_club_id ) ) {
$response .= " <a href='" . WPStrava_Rides::ATHLETES_URL . $ride->athlete_id . "'>" . $ride->athlete_name . "</a>";
$response .= " <a href='" . WPStrava_Rides::ATHLETES_URL . $ride->athlete_id . "'>" . $ride->athlete_name . '</a>';
}
$response .= sprintf( __(" rode %s %s", "wp-strava"), $this->som->distance( $ride->distance ), $this->som->get_distance_label() );
$response .= sprintf( __( " during %s %s", "wp-strava" ), $this->som->time( $ride->elapsed_time ), $this->som->get_time_label() );
$response .= sprintf( __( " climbing %s %s", "wp-strava" ), $this->som->elevation( $ride->total_elevation_gain ), $this->som->get_elevation_label() );
$response .= sprintf( __( ' rode %s %s', 'wp-strava' ), $this->som->distance( $ride->distance ), $this->som->get_distance_label() );
$response .= sprintf( __( ' during %s %s', 'wp-strava' ), $this->som->time( $ride->elapsed_time ), $this->som->get_time_label() );
$response .= sprintf( __( ' climbing %s %s', 'wp-strava' ), $this->som->elevation( $ride->total_elevation_gain ), $this->som->get_elevation_label() );
$response .= "</div>";
$response .= "</li>";
}
$response .= "</ul>";
return $response;
} // Function strava_request_handler
} // class LatestRidesWidget
+19 -19
View File
@@ -6,12 +6,12 @@ class WPStrava_RideShortcode {
public static function init() {
add_shortcode( 'ride', array( __CLASS__, 'handler' ) );
add_shortcode( 'activity', array( __CLASS__, 'handler' ) );
add_action( 'wp_footer', array( __CLASS__, 'printScripts' ) );
add_action( 'wp_footer', array( __CLASS__, 'print_scripts' ) );
}
// Shortcode handler function
// [ride id=id som=metric map_width="100%" map_height="400px"]
public static function handler($atts) {
public static function handler( $atts ) {
self::$add_script = true;
$defaults = array(
@@ -20,12 +20,12 @@ class WPStrava_RideShortcode {
'map_width' => '480',
'map_height' => '320',
);
extract(shortcode_atts($defaults, $atts));
extract( shortcode_atts( $defaults, $atts ) );
$strava_som = WPStrava_SOM::get_som( $som );
$strava_ride = WPStrava::get_instance()->rides;
$rideDetails = $strava_ride->getRide( $id );
$ride_details = $strava_ride->getRide( $id );
//sanitize width & height
$map_width = str_replace( '%', '', $map_width );
@@ -33,7 +33,7 @@ class WPStrava_RideShortcode {
$map_width = str_replace( 'px', '', $map_width );
$map_height = str_replace( 'px', '', $map_height );
if( $rideDetails ) {
if ( $ride_details ) {
return '
<div id="ride-header-' . $id . '" class="wp-strava-ride-container">
<table id="ride-details-table">
@@ -49,12 +49,12 @@ class WPStrava_RideShortcode {
</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>
<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>
<tr class="ride-details-table-units">
<td>' . $strava_som->get_time_label() . '</td>
@@ -66,14 +66,14 @@ class WPStrava_RideShortcode {
</tr>
</tbody>
</table>' .
WPStrava_StaticMap::get_image_tag( $rideDetails, $map_height, $map_width ) .
'</div>';
}
WPStrava_StaticMap::get_image_tag( $ride_details, $map_height, $map_width ) .
'</div>';
} // End if( $ride_details ).
} // handler
public static function printScripts() {
if (self::$add_script) {
wp_enqueue_style('wp-strava-style');
public static function print_scripts() {
if ( self::$add_script ) {
wp_enqueue_style( 'wp-strava-style' );
//wp_print_scripts('google-maps');
//wp_print_scripts('wp-strava-script');
+15 -16
View File
@@ -4,20 +4,20 @@
*/
class WPStrava_Rides {
const RIDES_URL = "http://app.strava.com/rides/";
const ATHLETES_URL = "http://app.strava.com/athletes/";
const RIDES_URL = 'http://app.strava.com/rides/';
const ATHLETES_URL = 'http://app.strava.com/athletes/';
public function getRide( $rideId ) {
return WPStrava::get_instance()->api->get( "activities/{$rideId}" );
} // getRideDetails
public function getRides( $club_id = NULL, $quantity = NULL ) {
public function getRides( $club_id = null, $quantity = null ) {
$api = WPStrava::get_instance()->api;
$data = NULL;
$data = null;
$args = $quantity ? array( 'per_page' => $quantity ) : null;
$args = $quantity ? array( 'per_page' => $quantity ) : NULL;
//Get the json results using the constructor specified values.
if ( is_numeric( $club_id ) ) {
$data = $api->get( "clubs/{$club_id}/activities", $args );
@@ -27,16 +27,16 @@ class WPStrava_Rides {
if ( is_wp_error( $data ) )
return $data;
if ( is_array( $data ) )
return $data;
return array();
return array();
} // getRides
public function getRidesLongerThan( $rides, $dist ) {
$som = WPStrava_SOM::get_som();
$som = WPStrava_SOM::get_som();
$meters = $som->distance_inverse( $dist );
$long_rides = array();
@@ -45,9 +45,8 @@ class WPStrava_Rides {
$long_rides[] = $ride_info;
}
}
return $long_rides;
}
} // class Rides
?>
+1 -1
View File
@@ -2,7 +2,7 @@
abstract class WPStrava_SOM {
public static function get_som( $som = NULL ) {
public static function get_som( $som = null ) {
$som = $som ? $som : WPStrava::get_instance()->settings->som;
if ( $som == 'english' ) {
require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMEnglish.class.php';
+2 -2
View File
@@ -23,7 +23,7 @@ class WPStrava_SOMEnglish extends WPStrava_SOM {
}
/**
* @param string $mps
* @param string $mps
* @return string mph
*/
public function speed( $mps ) {
@@ -45,4 +45,4 @@ class WPStrava_SOMEnglish extends WPStrava_SOM {
public function get_elevation_label() {
return __( 'ft.', 'wp-strava' );
}
}
}
+8 -8
View File
@@ -170,15 +170,15 @@ class WPStrava_Settings {
}
public function print_client_input() {
?><input type="text" id="strava_client_id" name="strava_client_id" value="<?php echo get_option('strava_client_id'); ?>" /><?php
?><input type="text" id="strava_client_id" name="strava_client_id" value="<?php echo get_option( 'strava_client_id' ); ?>" /><?php
}
public function print_secret_input() {
?><input type="text" id="strava_client_secret" name="strava_client_secret" value="<?php echo get_option('strava_client_secret'); ?>" /><?php
?><input type="text" id="strava_client_secret" name="strava_client_secret" value="<?php echo get_option( 'strava_client_secret' ); ?>" /><?php
}
public function print_token_input() {
?><input type="text" id="strava_token" name="strava_token" value="<?php echo get_option('strava_token'); ?>" /><?php
?><input type="text" id="strava_token" name="strava_token" value="<?php echo get_option( 'strava_token' ); ?>" /><?php
}
public function sanitize_client_id( $client_id ) {
@@ -207,8 +207,8 @@ class WPStrava_Settings {
$data = array( 'client_id' => $client_id, 'client_secret' => $client_secret, 'code' => $code );
$strava_info = WPStrava::get_instance()->api->post( 'oauth/token', $data );
if( $strava_info ) {
if( isset( $strava_info->access_token ) ) {
if ( $strava_info ) {
if ( isset( $strava_info->access_token ) ) {
$this->feedback .= __( 'Successfully authenticated.', 'wp-strava' );
return $strava_info->access_token;
} else {
@@ -266,9 +266,9 @@ class WPStrava_Settings {
}
public function settings_link( $links ) {
$settings_link = '<a href="' . admin_url( "options-general.php?page={$this->page_name}" ) . '">' . __( 'Settings' ) . '</a>';
$links[] = $settings_link;
$settings_link = '<a href="' . admin_url( "options-general.php?page={$this->page_name}" ) . '">' . __( 'Settings', 'wp-strava' ) . '</a>';
$links[] = $settings_link;
return $links;
}
}
}