diff --git a/lang/create_messages.sh b/lang/create_messages.sh index 860dedd..2a1cf63 100755 --- a/lang/create_messages.sh +++ b/lang/create_messages.sh @@ -3,4 +3,4 @@ ../wp-strava.php \ ../readme.txt -msgfmt -o es_ES.mo messages.es_ES.po +msgfmt -o wp-strava-es_ES.mo wp-strava-es_ES.po diff --git a/lang/es_ES.mo b/lang/wp-strava-es_ES.mo similarity index 100% rename from lang/es_ES.mo rename to lang/wp-strava-es_ES.mo diff --git a/lang/messages.es_ES.po b/lang/wp-strava-es_ES.po similarity index 100% rename from lang/messages.es_ES.po rename to lang/wp-strava-es_ES.po diff --git a/lang/messages.po b/lang/wp-strava.po similarity index 100% rename from lang/messages.po rename to lang/wp-strava.po diff --git a/lib/API.class.php b/lib/API.class.php index 5d87f9f..7df3aa0 100755 --- a/lib/API.class.php +++ b/lib/API.class.php @@ -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 \ No newline at end of file + +} // Class API. diff --git a/lib/LatestMapWidget.class.php b/lib/LatestMapWidget.class.php index 3534807..65b7940 100644 --- a/lib/LatestMapWidget.class.php +++ b/lib/LatestMapWidget.class.php @@ -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'; ?>

- +

-

+

- -

+ +

- - + +

- '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 { strava_request_handler( $strava_club_id, $quantity ); ?> -

- +

- - + +

- - + +

- rides; - + $rides = $strava_rides->getRides( $strava_club_id, $quantity ); if ( is_wp_error( $rides ) ) return $rides->get_error_message(); - + $response = ""; return $response; } // Function strava_request_handler - + } // class LatestRidesWidget diff --git a/lib/RideShortcode.class.php b/lib/RideShortcode.class.php index 5353519..975e392 100644 --- a/lib/RideShortcode.class.php +++ b/lib/RideShortcode.class.php @@ -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 '
@@ -49,12 +49,12 @@ class WPStrava_RideShortcode { - - - - - - + + + + + + @@ -66,14 +66,14 @@ class WPStrava_RideShortcode {
' . $strava_som->time( $rideDetails->elapsed_time ) . '' . $strava_som->time( $rideDetails->moving_time ) . '' . $strava_som->distance( $rideDetails->distance ) . '' . $strava_som->speed( $rideDetails->average_speed ) . '' . $strava_som->speed( $rideDetails->max_speed ) . '' . $strava_som->elevation( $rideDetails->total_elevation_gain ) . '' . $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->get_time_label() . '
' . - WPStrava_StaticMap::get_image_tag( $rideDetails, $map_height, $map_width ) . - '
'; - } + WPStrava_StaticMap::get_image_tag( $ride_details, $map_height, $map_width ) . + ''; + } // 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'); diff --git a/lib/Rides.class.php b/lib/Rides.class.php index 925f24c..4b237ff 100755 --- a/lib/Rides.class.php +++ b/lib/Rides.class.php @@ -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 -?> diff --git a/lib/SOM.class.php b/lib/SOM.class.php index 1453a24..80c441c 100644 --- a/lib/SOM.class.php +++ b/lib/SOM.class.php @@ -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'; diff --git a/lib/SOMEnglish.class.php b/lib/SOMEnglish.class.php index 8cc6103..5b92367 100644 --- a/lib/SOMEnglish.class.php +++ b/lib/SOMEnglish.class.php @@ -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' ); } -} \ No newline at end of file +} diff --git a/lib/Settings.class.php b/lib/Settings.class.php index 2936ec8..b6a6476 100644 --- a/lib/Settings.class.php +++ b/lib/Settings.class.php @@ -170,15 +170,15 @@ class WPStrava_Settings { } public function print_client_input() { - ?> $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 = 'page_name}" ) . '">' . __( 'Settings' ) . ''; - $links[] = $settings_link; + $settings_link = 'page_name}" ) . '">' . __( 'Settings', 'wp-strava' ) . ''; + $links[] = $settings_link; return $links; } -} \ No newline at end of file +} diff --git a/readme.txt b/readme.txt index 8fcfe79..9e1301a 100755 --- a/readme.txt +++ b/readme.txt @@ -1,7 +1,7 @@ === Plugin Name === Contributors: cmanon, jrfoell, lancewillett Tags: strava, bicycle, cycling, biking, running, run, swimming, swim, gps, shortcode, widget, plugin -Requires at least: 4.0 +Requires at least: 4.6 Tested up to: 4.7 Stable tag: 1.1 License: GPLv2 or later @@ -32,6 +32,10 @@ latest map to activities of a certain minimum distance == Changelog == += 1.2 = +Changes to better support translations through https://translate.wordpress.org +Cleaned up formatting + = 1.1 = Added [activity] shortcode to deprecate [ride] in the future Fixed static method call error in shortcode diff --git a/wp-strava.php b/wp-strava.php index 7128fb7..9f7fd00 100755 --- a/wp-strava.php +++ b/wp-strava.php @@ -2,16 +2,18 @@ /* * Plugin Name: WP Strava * Plugin URI: http://cmanon.com - * Description: Plugin to show your strava.com information in your wordpress blog. Some Icons are Copyright © Yusuke Kamiyamane. All rights reserved. Licensed under a Creative Commons Attribution 3.0 license. - * Version: 1.1 - * Author: Carlos Santa Cruz, Justin Foell, Lance Willet + * Description: Plugin to show your strava.com information in your wordpress blog. Some Icons are Copyright © Yusuke Kamiyamane. All rights reserved. Licensed under a Creative Commons Attribution 3.0 license. + * Version: 1.2 + * Author: Carlos Santa Cruz, Justin Foell, Lance Willet * License: GPL2 + * Text Domain: wp-strava + * Domain Path: /lang */ -/* Copyright 2011 Carlos Santa Cruz (email : cmanon at gmail dot com) +/* Copyright 2017 Carlos Santa Cruz (email : cmanon at gmail dot com) This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2, as + it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, @@ -25,15 +27,16 @@ */ -define( 'WPSTRAVA_PLUGIN_DIR', trailingslashit( dirname( __FILE__) ) ); +define( 'WPSTRAVA_PLUGIN_DIR', trailingslashit( dirname( __FILE__ ) ) ); define( 'WPSTRAVA_PLUGIN_URL', plugins_url( '/', __FILE__ ) ); -define( 'WPSTRAVA_PLUGIN_NAME', plugin_basename(__FILE__) ); +define( 'WPSTRAVA_PLUGIN_NAME', plugin_basename( __FILE__ ) ); if ( ! defined( 'WPSTRAVA_DEBUG' ) ) define( 'WPSTRAVA_DEBUG', false ); // Load the multilingual support. -if( file_exists( WPSTRAVA_PLUGIN_DIR . 'lang/' . get_locale() . '.mo' ) ) { - load_textdomain( 'wp-strava', WPSTRAVA_PLUGIN_DIR . 'lang/' . get_locale() . '.mo' ); +function wp_strava_load_plugin_textdomain() { + load_plugin_textdomain( 'wp-strava', false, WPSTRAVA_PLUGIN_DIR . 'lang/' ); } +add_action( 'plugins_loaded', 'wp_strava_load_plugin_textdomain' ); require_once WPSTRAVA_PLUGIN_DIR . 'lib/Strava.class.php'; $wpstrava = WPStrava::get_instance();