From bd40fe402188d0cac0660b70d215959e2b3f3a5d Mon Sep 17 00:00:00 2001 From: Justin Foell Date: Tue, 26 Dec 2017 14:18:13 -0600 Subject: [PATCH] Fixed activities URL https://wordpress.org/support/topic/problem-with-link-4/ Lots of formatting (code standards) Bumped version # --- lib/API.class.php | 34 ++++++----- lib/ActivityShortcode.class.php | 11 ++-- lib/LatestMapWidget.class.php | 60 +++++++++--------- lib/LatestRidesWidget.class.php | 79 ++++++++++++------------ lib/Rides.class.php | 6 +- lib/SOM.class.php | 4 +- lib/SOMMetric.class.php | 2 +- lib/Settings.class.php | 104 ++++++++++++++++++-------------- lib/Strava.class.php | 54 +++++++++-------- wp-strava.php | 8 ++- 10 files changed, 197 insertions(+), 165 deletions(-) diff --git a/lib/API.class.php b/lib/API.class.php index 043582a..5f1fc3d 100755 --- a/lib/API.class.php +++ b/lib/API.class.php @@ -17,9 +17,9 @@ public function post( $uri, $data = null ) { $url = self::STRAVA_V3_API; $args = array( - 'body' => http_build_query( $data ), + 'body' => http_build_query( $data ), 'sslverify' => false, - 'headers' => array(), + 'headers' => array(), ); if ( $this->access_token ) { @@ -28,17 +28,19 @@ public function post( $uri, $data = null ) { $response = wp_remote_post( $url . $uri, $args ); - if ( is_wp_error( $response ) ) + if ( is_wp_error( $response ) ) { return $response; + } - if ( $response['response']['code'] != 200 ) { + if ( 200 != $response['response']['code'] ) { //see if there's useful info in the body - $body = json_decode( $response['body'] ); + $body = json_decode( $response['body'] ); $error = ''; - if ( ! empty( $body->error ) ) + if ( ! empty( $body->error ) ) { $error = $body->error; - else - $error = print_r( $response, true ); + } else { + $error = print_r( $response, true ); // @codingStandardsIgnoreLine + } return new WP_Error( 'wp-strava_post', @@ -69,19 +71,21 @@ public function get( $uri, $args = null ) { $response = wp_remote_get( $url, $get_args ); - if ( is_wp_error( $response ) ) + if ( is_wp_error( $response ) ) { return $response; + } - if ( $response['response']['code'] != 200 ) { + if ( 200 != $response['response']['code'] ) { //see if there's useful info in the body - $body = json_decode( $response['body'] ); + $body = json_decode( $response['body'] ); $error = ''; - if ( ! empty( $body->error ) ) + if ( ! empty( $body->error ) ) { $error = $body->error; - else if ( $response['response']['code'] == 503 ) + } elseif ( 503 == $response['response']['code'] ) { $error = __( 'Strava Temporarily Unavailable', 'wp-strava' ); - else - $error = print_r( $response, true ); + } else { + $error = print_r( $response, true ); // @codingStandardsIgnoreLine + } return new WP_Error( 'wp-strava_get', diff --git a/lib/ActivityShortcode.class.php b/lib/ActivityShortcode.class.php index a43382d..44477ca 100644 --- a/lib/ActivityShortcode.class.php +++ b/lib/ActivityShortcode.class.php @@ -10,7 +10,7 @@ public static function init() { } // Shortcode handler function - // [ride id=id som=metric map_width="100%" map_height="400px" markers=false] + // [activity id=id som=metric map_width="100%" map_height="400px" markers=false] public static function handler( $atts ) { self::$add_script = true; @@ -20,13 +20,13 @@ public static function handler( $atts ) { 'map_width' => '480', 'map_height' => '320', 'athlete_token' => WPStrava::get_instance()->settings->get_default_token(), - 'markers' => false, + 'markers' => false, ); extract( shortcode_atts( $defaults, $atts ) ); - $strava_som = WPStrava_SOM::get_som( $som ); - $activity = WPStrava::get_instance()->rides; + $strava_som = WPStrava_SOM::get_som( $som ); + $activity = WPStrava::get_instance()->rides; $ride_details = $activity->getRide( $athlete_token, $id ); //sanitize width & height @@ -76,9 +76,6 @@ public static function handler( $atts ) { 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/LatestMapWidget.class.php b/lib/LatestMapWidget.class.php index 89d925a..49be244 100644 --- a/lib/LatestMapWidget.class.php +++ b/lib/LatestMapWidget.class.php @@ -8,7 +8,7 @@ public function __construct() { $this->som = WPStrava_SOM::get_som(); parent::__construct( - false, + false, __( 'Strava Latest Map', 'wp-strava' ), // Name array( 'description' => __( 'Strava latest activity using static google map image', 'wp-strava' ) ) // Args. ); @@ -16,15 +16,12 @@ public function __construct() { public function form( $instance ) { // outputs the options form on admin - $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : __( 'Latest Activity Map', 'wp-strava' ); - $all_tokens = WPStrava::get_instance()->settings->get_all_tokens(); - $athlete_token = isset( $instance['athlete_token'] ) ? esc_attr( $instance['athlete_token'] ) : WPStrava::get_instance()->settings->get_default_token(); - $distance_min = isset( $instance['distance_min'] ) ? esc_attr( $instance['distance_min'] ) : ''; + $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : __( 'Latest Activity Map', 'wp-strava' ); + $all_tokens = WPStrava::get_instance()->settings->get_all_tokens(); + $athlete_token = isset( $instance['athlete_token'] ) ? esc_attr( $instance['athlete_token'] ) : WPStrava::get_instance()->settings->get_default_token(); + $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'; - ?>

@@ -33,8 +30,8 @@ public function form( $instance ) {

@@ -43,47 +40,50 @@ public function form( $instance ) {

- +

settings->get_default_token(); - $distance_min = empty( $instance['distance_min'] ) ? 0 : absint( $instance['distance_min'] ); + $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(); + $distance_min = empty( $instance['distance_min'] ) ? 0 : absint( $instance['distance_min'] ); $strava_club_id = empty( $instance['strava_club_id'] ) ? null : $instance['strava_club_id']; - $build_new = false; + $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 ); + $ride_option = get_option( 'strava_latest_map_activity_' . $athlete_token ); $ride = $ride_transient ? $ride_transient : null; if ( ! $ride ) { $strava_rides = WPStrava::get_instance()->rides; - $rides = $strava_rides->getRides( $athlete_token, $strava_club_id ); + $rides = $strava_rides->getRides( $athlete_token, $strava_club_id ); if ( is_wp_error( $rides ) ) { echo $before_widget; - if ( $title ) echo $before_title . $title . $after_title; + if ( $title ) { + echo $before_title . $title . $after_title; + } + if ( WPSTRAVA_DEBUG ) { echo '
';
-					print_r($rides);
+					print_r( $rides ); // @codingStandardsIgnoreLine
 					echo '
'; } else { echo $rides->get_error_message(); @@ -94,8 +94,9 @@ public function widget( $args, $instance ) { if ( ! empty( $rides ) ) { - if ( ! empty( $distance_min ) ) + if ( ! empty( $distance_min ) ) { $rides = $strava_rides->getRidesLongerThan( $rides, $distance_min ); + } $ride = current( $rides ); @@ -115,10 +116,13 @@ public function widget( $args, $instance ) { if ( $ride ) { echo $before_widget; - if ( $title ) echo $before_title . $title . $after_title; - ?>name}' target='_blank' href='http://app.strava.com/activities/{$ride->id}'>"; echo $this->getStaticImage( $athlete_token, $ride, $build_new ); - ?>'; echo $after_widget; } } diff --git a/lib/LatestRidesWidget.class.php b/lib/LatestRidesWidget.class.php index 2a3174f..8171179 100644 --- a/lib/LatestRidesWidget.class.php +++ b/lib/LatestRidesWidget.class.php @@ -6,8 +6,11 @@ class WPStrava_LatestRidesWidget extends WP_Widget { public function __construct() { - $widget_ops = array( 'classname' => 'LatestRidesWidget', 'description' => __( 'Will publish your latest rides activity from strava.com.', 'wp-strava' ) ); - parent::__construct( 'wp-strava', $name = __( 'Strava Latest Activity List', 'wp-strava' ), $widget_ops ); + $widget_ops = array( + 'classname' => 'LatestRidesWidget', + 'description' => __( 'Will publish your latest rides activity from strava.com.', 'wp-strava' ), + ); + parent::__construct( 'wp-strava', __( 'Strava Latest Activity List', 'wp-strava' ), $widget_ops ); add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue' ) ); } @@ -21,38 +24,37 @@ public function maybe_enqueue() { public function widget( $args, $instance ) { extract( $args ); - //$widget_id = $args['widget_id']; - $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Activity', 'wp-strava' ) : $instance['title'] ); - $athlete_token = isset( $instance['athlete_token'] ) ? $instance['athlete_token'] : WPStrava::get_instance()->settings->get_default_token(); + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Activity', 'wp-strava' ) : $instance['title'] ); + $athlete_token = isset( $instance['athlete_token'] ) ? $instance['athlete_token'] : WPStrava::get_instance()->settings->get_default_token(); $strava_club_id = empty( $instance['strava_club_id'] ) ? '' : $instance['strava_club_id']; - $quantity = empty( $instance['quantity'] ) ? '5' : $instance['quantity']; + $quantity = empty( $instance['quantity'] ) ? '5' : $instance['quantity']; - ?> - - - strava_request_handler( $athlete_token, $strava_club_id, $quantity ); ?> - - strava_request_handler( $athlete_token, $strava_club_id, $quantity ); + echo $after_widget; } /** @see WP_Widget::update */ public function update( $new_instance, $old_instance ) { - $instance = $old_instance; - $instance['title'] = strip_tags( $new_instance['title'] ); - $instance['athlete_token'] = strip_tags( $new_instance['athlete_token'] ); + $instance = $old_instance; + $instance['title'] = strip_tags( $new_instance['title'] ); + $instance['athlete_token'] = strip_tags( $new_instance['athlete_token'] ); $instance['strava_club_id'] = strip_tags( $new_instance['strava_club_id'] ); - $instance['quantity'] = $new_instance['quantity']; + $instance['quantity'] = $new_instance['quantity']; return $instance; } /** @see WP_Widget::form */ public function form( $instance ) { - $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : __( 'Activity', 'wp-strava' ); - $all_tokens = WPStrava::get_instance()->settings->get_all_tokens(); - $athlete_token = isset( $instance['athlete_token'] ) ? esc_attr( $instance['athlete_token'] ) : WPStrava::get_instance()->settings->get_default_token(); + $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : __( 'Activity', 'wp-strava' ); + $all_tokens = WPStrava::get_instance()->settings->get_all_tokens(); + $athlete_token = isset( $instance['athlete_token'] ) ? esc_attr( $instance['athlete_token'] ) : WPStrava::get_instance()->settings->get_default_token(); $strava_club_id = isset( $instance['strava_club_id'] ) ? esc_attr( $instance['strava_club_id'] ) : ''; - $quantity = isset( $instance['quantity'] ) ? absint( $instance['quantity'] ) : 5; + $quantity = isset( $instance['quantity'] ) ? absint( $instance['quantity'] ) : 5; ?>

@@ -62,17 +64,17 @@ public function form( $instance ) {

- - + +

- +

rides; $rides = $strava_rides->getRides( $athlete_token, $strava_club_id, $quantity ); - if ( is_wp_error( $rides ) ) + if ( is_wp_error( $rides ) ) { return $rides->get_error_message(); + } $response = ""; + $response .= ''; return $response; } // Function strava_request_handler } // class LatestRidesWidget - diff --git a/lib/Rides.class.php b/lib/Rides.class.php index 0fb5bd1..2f70de0 100755 --- a/lib/Rides.class.php +++ b/lib/Rides.class.php @@ -4,8 +4,8 @@ */ class WPStrava_Rides { - const RIDES_URL = 'http://app.strava.com/rides/'; - const ATHLETES_URL = 'http://app.strava.com/athletes/'; + const ACTIVITIES_URL = 'http://app.strava.com/activities/'; + const ATHLETES_URL = 'http://app.strava.com/athletes/'; /** * Get single activity by ID. @@ -56,7 +56,7 @@ public function getRides( $athlete_token, $club_id = null, $quantity = null ) { } // getRides public function getRidesLongerThan( $rides, $dist ) { - $som = WPStrava_SOM::get_som(); + $som = WPStrava_SOM::get_som(); $meters = $som->distance_inverse( $dist ); $long_rides = array(); diff --git a/lib/SOM.class.php b/lib/SOM.class.php index 80c441c..0211243 100644 --- a/lib/SOM.class.php +++ b/lib/SOM.class.php @@ -4,10 +4,10 @@ abstract class WPStrava_SOM { public static function get_som( $som = null ) { $som = $som ? $som : WPStrava::get_instance()->settings->som; - if ( $som == 'english' ) { + if ( 'english' === $som ) { require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMEnglish.class.php'; return new WPStrava_SOMEnglish(); - } else { //default to metric + } else { // Default to metric. require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMMetric.class.php'; return new WPStrava_SOMMetric(); } diff --git a/lib/SOMMetric.class.php b/lib/SOMMetric.class.php index 0828c67..8eb4af5 100644 --- a/lib/SOMMetric.class.php +++ b/lib/SOMMetric.class.php @@ -44,4 +44,4 @@ public function elevation( $m ) { public function get_elevation_label() { return __( 'meters', 'wp-strava' ); } -} \ No newline at end of file +} diff --git a/lib/Settings.class.php b/lib/Settings.class.php index 368f94e..9ba42df 100644 --- a/lib/Settings.class.php +++ b/lib/Settings.class.php @@ -12,9 +12,9 @@ class WPStrava_Settings { private $feedback; - private $tokens = array(); - private $page_name = 'wp-strava-options'; - private $option_page = 'wp-strava-settings-group'; + private $tokens = array(); + private $page_name = 'wp-strava-options'; + private $option_page = 'wp-strava-settings-group'; private $adding_athlete = true; //register admin menus @@ -24,34 +24,28 @@ public function hook() { 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' ) ); - //for process debugging - //add_action( 'all', array( $this, 'hook_debug' ) ); - //add_filter( 'all', array( $this, 'hook_debug' ) ); - } - - public function hook_debug( $name ) { - echo "\n"; } /** * This runs after options are saved */ - public function maybe_oauth( $value ) { + public function maybe_oauth( $value ) { // User is clearing to start-over, don't oauth, ignore other errors. - if ( isset( $_POST['strava_token'] ) && $this->tokens_empty( $_POST['strava_token'] ) ) - return array(); + if ( isset( $_POST['strava_token'] ) && $this->tokens_empty( $_POST['strava_token'] ) ) { + return array(); + } // Redirect only if all the right options are in place. - if ( isset( $value[0]['type'] ) && 'updated' == $value[0]['type'] ) { // Make sure there were no settings errors. - if ( isset( $_POST['option_page'] ) && $_POST['option_page'] == $this->option_page ) { // Make sure we're on our settings page. + if ( isset( $value[0]['type'] ) && 'updated' === $value[0]['type'] ) { // Make sure there were no settings errors. + if ( isset( $_POST['option_page'] ) && $_POST['option_page'] === $this->option_page ) { // Make sure we're on our settings page. // Only re-auth if client ID and secret were saved. if ( ! empty( $_POST['strava_client_id'] ) && ! empty( $_POST['strava_client_secret'] ) ) { - $client_id = $_POST['strava_client_id']; + $client_id = $_POST['strava_client_id']; $client_secret = $_POST['strava_client_secret']; $redirect = admin_url( "options-general.php?page={$this->page_name}" ); - $url = "https://www.strava.com/oauth/authorize?client_id={$client_id}&response_type=code&redirect_uri={$redirect}&approval_prompt=force"; + $url = "https://www.strava.com/oauth/authorize?client_id={$client_id}&response_type=code&redirect_uri={$redirect}&approval_prompt=force"; wp_redirect( $url ); exit(); } @@ -77,11 +71,12 @@ public function init() { $this->adding_athlete = ! ( empty( $_POST['strava_client_id'] ) && empty( $_POST['strava_client_secret'] ) ); //only update when redirected back from strava - if ( ! isset( $_GET['settings-updated'] ) && isset( $_GET['page'] ) && $_GET['page'] == $this->page_name ) { + if ( ! isset( $_GET['settings-updated'] ) && isset( $_GET['page'] ) && $_GET['page'] === $this->page_name ) { if ( isset( $_GET['code'] ) ) { $token = $this->fetch_token( $_GET['code'] ); if ( $token ) { - add_settings_error( 'strava_token', 'strava_token', sprintf( __( 'New Strava token retrieved. %s', 'wp-strava' ), $this->feedback ) , 'updated' ); + // Translators: strava token + add_settings_error( 'strava_token', 'strava_token', sprintf( __( 'New Strava token retrieved. %s', 'wp-strava' ), $this->feedback ), 'updated' ); $this->add_token( $token ); update_option( 'strava_token', $this->tokens ); } else { @@ -108,7 +103,7 @@ public function register_strava_settings() { add_settings_field( 'strava_client_secret', __( 'Strava Client Secret', 'wp-strava' ), array( $this, 'print_secret_input' ), 'wp-strava', 'strava_api' ); add_settings_field( 'strava_nickname', __( 'Strava Nickname', 'wp-strava' ), array( $this, 'print_nickname_input' ), 'wp-strava', 'strava_api' ); } else { - register_setting( $this->option_page, 'strava_token', array( $this, 'sanitize_token' ) ); + register_setting( $this->option_page, 'strava_token', array( $this, 'sanitize_token' ) ); add_settings_field( 'strava_token', __( 'Strava Token', 'wp-strava' ), array( $this, 'print_token_input' ), 'wp-strava', 'strava_api' ); // Add additional fields @@ -138,13 +133,17 @@ public function register_strava_settings() { } public function print_api_instructions() { - $signup_url = 'http://www.strava.com/developers'; + $signup_url = 'http://www.strava.com/developers'; $settings_url = 'https://www.strava.com/settings/api'; - $icon_url = 'https://plugins.svn.wordpress.org/wp-strava/assets/icon-128x128.png'; - $blog_name = get_bloginfo( 'name' ); - $app_name = sprintf( esc_html( '%s Strava', 'wp-strava' ), $blog_name ); + $icon_url = 'https://plugins.svn.wordpress.org/wp-strava/assets/icon-128x128.png'; + $blog_name = get_bloginfo( 'name' ); + + // Translators: Strava "app" name + $app_name = sprintf( __( '%s Strava', 'wp-strava' ), $blog_name ); $site_url = site_url(); - $description = 'WP-Strava for ' . $blog_name; + + // Translators: Strava "app" description + $description = sprintf( __( 'WP-Strava for %s', 'wp-strava' ), $blog_name ); printf( __( "

Steps:

  1. Create your free API Application/Connection here: %2\$s using the following information:
  2. @@ -200,16 +199,22 @@ public function print_strava_options() { } public function print_client_input() { - ?> + + + + tokens_empty( $this->tokens ) ? __( 'Default', 'wp-strava' ) : ''; - ?> + + $token ) { + foreach ( $_POST['strava_token'] as $index => $token ) { $token = trim( $token ); if ( empty( $token ) ) { unset( $nicknames[ $index ] ); @@ -265,7 +270,7 @@ public function sanitize_nickname( $nicknames ) { } foreach ( $nicknames as $index => $nickname ) { - if ( '' == trim( $nickname ) ) { + if ( '' === trim( $nickname ) ) { add_settings_error( 'strava_nickname', 'strava_nickname', __( 'Nickname is required.', 'wp-strava' ) ); return $nicknames; } @@ -278,7 +283,7 @@ public function sanitize_token( $token ) { } private function fetch_token( $code ) { - $client_id = $this->client_id; + $client_id = $this->client_id; $client_secret = $this->client_secret; delete_option( 'strava_client_id' ); @@ -286,8 +291,12 @@ private function fetch_token( $code ) { if ( $client_id && $client_secret ) { require_once WPSTRAVA_PLUGIN_DIR . 'lib/API.class.php'; - $api = new WPStrava_API(); - $data = array( 'client_id' => $client_id, 'client_secret' => $client_secret, 'code' => $code ); + $api = new WPStrava_API(); + $data = array( + 'client_id' => $client_id, + 'client_secret' => $client_secret, + 'code' => $code, + ); $strava_info = $api->post( 'oauth/token', $data ); @@ -300,7 +309,8 @@ private function fetch_token( $code ) { return false; } } else { - $this->feedback .= __( sprintf( 'There was an error receiving data from Strava: %s', print_r( $strava_info, true ) ), 'wp-strava' ); + // Translators: error message from Strava + $this->feedback .= sprintf( __( 'There was an error receiving data from Strava: %s', 'wp-strava' ), print_r( $strava_info, true ) ); // @codingStandardsIgnoreLine return false; } } else { @@ -310,7 +320,9 @@ private function fetch_token( $code ) { } public function print_gmaps_key_input() { - ?> + + + + get_tokens(); + $tokens = $this->get_tokens(); $nicknames = $this->nickname; - $all = array(); - $number = 1; + $all = array(); + $number = 1; foreach ( $tokens as $index => $token ) { if ( ! empty( $nicknames[ $index ] ) ) { $all[ $token ] = $nicknames[ $index ]; @@ -419,7 +433,7 @@ public function get_all_tokens() { */ private function get_default_nickname( $number = 1 ) { // Translators: Athelete number if no nickname present. - return ( 1 == $number ) ? __( 'Default', 'wp-strava' ) : sprintf( __( 'Athlete %s', 'wp-strava' ), $number ); + return ( 1 === $number ) ? __( 'Default', 'wp-strava' ) : sprintf( __( 'Athlete %s', 'wp-strava' ), $number ); } /** @@ -437,7 +451,7 @@ public function tokens_empty( $tokens ) { } if ( is_array( $tokens ) ) { - foreach( $tokens as $token ) { + foreach ( $tokens as $token ) { if ( ! empty( $token ) ) { return false; } @@ -471,7 +485,7 @@ public function __get( $name ) { public function settings_link( $links ) { $settings_link = 'page_name}" ) . '">' . __( 'Settings', 'wp-strava' ) . ''; - $links[] = $settings_link; + $links[] = $settings_link; return $links; } diff --git a/lib/Strava.class.php b/lib/Strava.class.php index 79b1ff2..2a1fa3e 100644 --- a/lib/Strava.class.php +++ b/lib/Strava.class.php @@ -2,8 +2,6 @@ require_once WPSTRAVA_PLUGIN_DIR . 'lib/Settings.class.php'; require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOM.class.php'; -require_once WPSTRAVA_PLUGIN_DIR . 'lib/LatestRidesWidget.class.php'; -require_once WPSTRAVA_PLUGIN_DIR . 'lib/LatestMapWidget.class.php'; require_once WPSTRAVA_PLUGIN_DIR . 'lib/ActivityShortcode.class.php'; require_once WPSTRAVA_PLUGIN_DIR . 'lib/RouteShortcode.class.php'; require_once WPSTRAVA_PLUGIN_DIR . 'lib/StaticMap.class.php'; @@ -11,10 +9,10 @@ class WPStrava { private static $instance = null; - private $settings = null; - private $api = array(); // Holds an array of APIs. - private $rides = null; - private $routes = null; + private $settings = null; + private $api = array(); // Holds an array of APIs. + private $rides = null; + private $routes = null; private function __construct() { $this->settings = new WPStrava_Settings(); @@ -25,14 +23,13 @@ private function __construct() { add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) ); } - // Register StravaLatestRidesWidget widget - add_action( 'widgets_init', create_function( '', 'return register_widget( "WPStrava_LatestRidesWidget" );' ) ); - add_action( 'widgets_init', create_function( '', 'return register_widget( "WPStrava_LatestMapWidget" );' ) ); + // Register widgets. + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); } public static function get_instance() { if ( ! self::$instance ) { - $class = __CLASS__; + $class = __CLASS__; self::$instance = new $class(); } return self::$instance; @@ -40,11 +37,13 @@ public static function get_instance() { public function __get( $name ) { // On-demand classes. - if ( $name == 'rides' ) { + if ( 'rides' === $name ) { return $this->get_rides(); - } elseif ( $name == 'routes' ) { - return $this->get_routes(); - } + } + + if ( 'routes' === $name ) { + return $this->get_routes(); + } if ( isset( $this->{$name} ) ) { return $this->{$name}; @@ -60,10 +59,10 @@ public function get_api( $token = null ) { if ( empty( $this->api[ $token ] ) ) { require_once WPSTRAVA_PLUGIN_DIR . 'lib/API.class.php'; - $this->api[$token] = new WPStrava_API( $token ); + $this->api[ $token ] = new WPStrava_API( $token ); } - return $this->api[$token]; + return $this->api[ $token ]; } public function get_rides() { @@ -75,16 +74,23 @@ public function get_rides() { return $this->rides; } - public function get_routes() { - if ( ! $this->routes ) { - require_once WPSTRAVA_PLUGIN_DIR . 'lib/Routes.class.php'; - $this->routes = new WPStrava_Routes(); - } - return $this->routes; - } + public function get_routes() { + if ( ! $this->routes ) { + require_once WPSTRAVA_PLUGIN_DIR . 'lib/Routes.class.php'; + $this->routes = new WPStrava_Routes(); + } + return $this->routes; + } public function register_scripts() { - // Register a personalized stylesheet + // Register a personalized stylesheet. wp_register_style( 'wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' ); } + + public function register_widgets() { + require_once WPSTRAVA_PLUGIN_DIR . 'lib/LatestRidesWidget.class.php'; + require_once WPSTRAVA_PLUGIN_DIR . 'lib/LatestMapWidget.class.php'; + register_widget( 'WPStrava_LatestRidesWidget' ); + register_widget( 'WPStrava_LatestMapWidget' ); + } } diff --git a/wp-strava.php b/wp-strava.php index f78bfa5..3c98d7d 100755 --- a/wp-strava.php +++ b/wp-strava.php @@ -2,8 +2,8 @@ /* * Plugin Name: WP Strava * Plugin URI: https://wordpress.org/plugins/wp-strava/ - * 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.0 + * 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.3.0 * Author: Carlos Santa Cruz, Justin Foell, Lance Willet * License: GPL2 * Text Domain: wp-strava @@ -30,7 +30,9 @@ define( 'WPSTRAVA_PLUGIN_DIR', trailingslashit( dirname( __FILE__ ) ) ); define( 'WPSTRAVA_PLUGIN_URL', plugins_url( '/', __FILE__ ) ); define( 'WPSTRAVA_PLUGIN_NAME', plugin_basename( __FILE__ ) ); -if ( ! defined( 'WPSTRAVA_DEBUG' ) ) define( 'WPSTRAVA_DEBUG', false ); +if ( ! defined( 'WPSTRAVA_DEBUG' ) ) { + define( 'WPSTRAVA_DEBUG', false ); +} // Load the multilingual support. function wp_strava_load_plugin_textdomain() {