From dfc4ca81c17411475c514acfc81b16187eee7871 Mon Sep 17 00:00:00 2001
From: Justin Foell Steps: Use the following information:';
+ print_r($rides);
+ echo '
';
+ echo $after_widget;
+ return;
+ }
+
if ( ! empty( $rides ) ) {
if ( ! empty( $distance_min ) )
From fde59eab6dcfbf1427399fb8b347d4c5a4b7a4c4 Mon Sep 17 00:00:00 2001
From: Justin Foell
+
+
+
+
+
- - -
++ + +
athlete->id}"; - } - */ - - //$instance['athlete_hash'] = strip_tags( $new_instance['athlete_hash'] ); - return $instance; } public function widget( $args, $instance ) { extract( $args ); - $ride_index_params = $instance['ride_index_params']; $distance_min = $instance['distance_min']; + $strava_club_id = empty( $instance['strava_club_id'] ) ? NULL : $instance['strava_club_id']; $build_new = false; //try our transient first @@ -67,9 +57,7 @@ class WPStrava_LatestMapWidget extends WP_Widget { if ( ! $ride ) { $strava_rides = WPStrava::get_instance()->rides; - $ride_index_params = implode( '&', explode( "\n", $ride_index_params ) ); - parse_str( $ride_index_params, $params ); - $rides = $strava_rides->getRidesAdvanced( $params ); + $rides = $strava_rides->getRides( $strava_club_id ); if ( is_wp_error( $rides ) ) { echo $before_widget; @@ -101,47 +89,32 @@ class WPStrava_LatestMapWidget extends WP_Widget { if ( $ride ): echo $before_widget; ?>' . var_export( $wpstrava->api->get( 'athlete' ), true ) );
//@TODO only load these when needed using is_active_widget()
function load_styles() {
From 140c04fd24174ae4cd49b10019298af00d82305e Mon Sep 17 00:00:00 2001
From: Justin Foell
Date: Fri, 12 Sep 2014 10:37:34 -0500
Subject: [PATCH 06/15] Formatting
---
lib/RideShortcode.class.php | 2 +-
lib/Settings.class.php | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/RideShortcode.class.php b/lib/RideShortcode.class.php
index 7c0eba5..e908b9f 100644
--- a/lib/RideShortcode.class.php
+++ b/lib/RideShortcode.class.php
@@ -100,7 +100,7 @@ class WPStrava_RideShortcode {
";
}
} else {
- return _e('Please first get your strava token using the settings wp strava page.', 'wp-strava');
+ return __('Please first get your strava token using the settings wp strava page.', 'wp-strava');
}
} // handler
diff --git a/lib/Settings.class.php b/lib/Settings.class.php
index 6cee30b..74f958f 100644
--- a/lib/Settings.class.php
+++ b/lib/Settings.class.php
@@ -29,8 +29,8 @@ class WPStrava_Settings {
public function option_home() {
if ( isset( $_POST['option_page'] ) && $_POST['option_page'] == $this->option_page ) {
//redirect only if all the right options are in place
- $errors = get_settings_errors();
- if ( ! empty( $errors ) )
+ global $wp_settings_errors;
+ if ( ! empty( $wp_settings_errors ) )
return;
//clearing to start-over
From 5ae8a9bee1a14316692059bf7590c02d297519ae Mon Sep 17 00:00:00 2001
From: Justin Foell
Date: Fri, 12 Sep 2014 10:40:02 -0500
Subject: [PATCH 07/15] Renamed option_home hook function
---
lib/Settings.class.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/Settings.class.php b/lib/Settings.class.php
index 74f958f..9374e1c 100644
--- a/lib/Settings.class.php
+++ b/lib/Settings.class.php
@@ -20,13 +20,13 @@ class WPStrava_Settings {
public function hook() {
add_action( 'admin_init', array( $this, 'register_strava_settings' ) );
add_action( 'admin_menu', array( $this, 'add_strava_menu' ) );
- add_action( 'option_home', array( $this, 'option_home' ) );
+ add_action( 'option_home', array( $this, 'maybe_oauth' ) );
}
/**
* This runs after options are saved
*/
- public function option_home() {
+ public function maybe_oauth() {
if ( isset( $_POST['option_page'] ) && $_POST['option_page'] == $this->option_page ) {
//redirect only if all the right options are in place
global $wp_settings_errors;
From bc36c9c7cc83e95078b064b31bd016b571cf9b64 Mon Sep 17 00:00:00 2001
From: Justin Foell
Date: Fri, 12 Sep 2014 12:28:53 -0500
Subject: [PATCH 08/15] Updated settings workflow
---
lib/Settings.class.php | 80 ++++++++++++++++++++----------------------
1 file changed, 39 insertions(+), 41 deletions(-)
diff --git a/lib/Settings.class.php b/lib/Settings.class.php
index 9374e1c..d6e4b07 100644
--- a/lib/Settings.class.php
+++ b/lib/Settings.class.php
@@ -5,7 +5,7 @@
*
* Set up an "API Application" at Strava
* Save the Client ID and Client Secret in WordPress - redirect to strava oauth/authorize URL for permission
- * Get redirected back to this settings page with ?code=
+ * Get redirected back to this settings page with ?code= or ?error=
* Use code to retrieve auth token
*/
@@ -20,33 +20,39 @@ class WPStrava_Settings {
public function hook() {
add_action( 'admin_init', array( $this, 'register_strava_settings' ) );
add_action( 'admin_menu', array( $this, 'add_strava_menu' ) );
- add_action( 'option_home', array( $this, 'maybe_oauth' ) );
+ add_filter( 'pre_set_transient_settings_errors', array( $this, 'maybe_oauth' ), 10 );
+ //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() {
- if ( isset( $_POST['option_page'] ) && $_POST['option_page'] == $this->option_page ) {
- //redirect only if all the right options are in place
- global $wp_settings_errors;
- if ( ! empty( $wp_settings_errors ) )
- return;
-
- //clearing to start-over
- if ( isset( $_POST['strava_token'] ) && empty( $_POST['strava_token'] ) )
- return;
+ public function maybe_oauth( $value ) {
+ //redirect only if all the right options are in place
+ if ( isset( $value[0]['type'] ) && $value[0]['type'] == 'updated' ) { //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
+ //user is clearing to start-over, don't oauth
+ if ( isset( $_POST['strava_token'] ) && empty( $_POST['strava_token'] ) )
+ return;
- $client_id = get_option( 'strava_client_id' );
- $client_secret = get_option( 'strava_client_secret' );
+ $client_id = get_option( 'strava_client_id' );
+ $client_secret = get_option( 'strava_client_secret' );
- if ( $client_id && $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";
- wp_redirect( $url );
- exit();
- }
+ if ( $client_id && $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";
+ wp_redirect( $url );
+ exit();
+ }
+ }
}
+ return $value;
}
public function add_strava_menu() {
@@ -58,13 +64,18 @@ class WPStrava_Settings {
}
public function init() {
- if ( isset( $_GET['page'] ) && $_GET['page'] == $this->page_name && isset( $_GET['code'] ) ) {
- $token = $this->get_token( $_GET['code'] );
- if ( $token ) {
- add_settings_error( 'strava_token', 'strava_token', sprintf( __( 'New Strava Token Retrieved. %s', 'wp-strava' ), $this->feedback ) , 'updated' );
- update_option( 'strava_token', $token );
- } else {
- add_settings_error( 'strava_token', 'strava_token', $this->feedback );
+ //only update when redirected back from strava
+ if ( ! isset( $_GET['settings-updated'] ) && isset( $_GET['page'] ) && $_GET['page'] == $this->page_name ) {
+ if ( isset( $_GET['code'] ) ) {
+ $token = $this->get_token( $_GET['code'] );
+ if ( $token ) {
+ add_settings_error( 'strava_token', 'strava_token', sprintf( __( 'New Strava token retrieved. %s', 'wp-strava' ), $this->feedback ) , 'updated' );
+ update_option( 'strava_token', $token );
+ } else {
+ add_settings_error( 'strava_token', 'strava_token', $this->feedback );
+ }
+ } else if ( isset( $_GET['error'] ) ) {
+ add_settings_error( 'strava_token', 'strava_token', sprintf( __( 'Error authenticating at Strava: %s', 'wp-strava' ), str_replace( '_', ' ', $_GET['error'] ) ) );
}
}
@@ -158,23 +169,10 @@ class WPStrava_Settings {
if ( trim( $client_secret ) == '' ) {
add_settings_error( 'strava_client_secret', 'strava_client_secret', __( 'Client Secret is required.', 'wp-strava' ) );
}
- echo "WHEREAMI";
return $client_secret;
}
public function sanitize_token( $token ) {
- /*
- if ( isset( $_GET['code'] ) ) {
- $token = $this->get_token( $_GET['code'] );
- if ( $token ) {
- add_settings_error( 'strava_token', 'strava_token', sprintf( __( 'New Strava Token Retrieved: %s', 'wp-strava' ), $this->feedback ) , 'updated' );
- return $token;
- } else {
- add_settings_error( 'strava_token', 'strava_token', $this->feedback );
- return NULL;
- }
- }
- */
return $token;
}
@@ -195,7 +193,7 @@ class WPStrava_Settings {
return false;
}
} else {
- $this->feedback .= __( 'There was an error pulling data of strava.com.', 'wp-strava' );
+ $this->feedback .= __( sprintf( 'There was an error receiving data from Strava: %s', print_r( $strava_info, true ) ), 'wp-strava' );
return false;
}
} else {
From 7992db37f098dac352d0be0fff79a6688154a22f Mon Sep 17 00:00:00 2001
From: Justin Foell
Date: Tue, 23 Sep 2014 13:39:48 -0500
Subject: [PATCH 09/15] Updated version Addd handling of 503 service unavail
---
lib/API.class.php | 2 ++
lib/LatestMapWidget.class.php | 10 +++++++---
lib/Rides.class.php | 2 +-
lib/Settings.class.php | 7 +++++++
readme.txt | 17 +++++++++++------
wp-strava.php | 9 ++++-----
6 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/lib/API.class.php b/lib/API.class.php
index a547a1f..44dd657 100755
--- a/lib/API.class.php
+++ b/lib/API.class.php
@@ -68,6 +68,8 @@ class WPStrava_API {
$error = '';
if ( ! empty( $body->error ) )
$error = $body->error;
+ else if ( $response['response']['code'] == 503 )
+ $error = __( 'Strava Temporarily Unavailable', 'wp-strava' );
else
$error = print_r( $response, true );
diff --git a/lib/LatestMapWidget.class.php b/lib/LatestMapWidget.class.php
index 243acb2..ce86ff9 100644
--- a/lib/LatestMapWidget.class.php
+++ b/lib/LatestMapWidget.class.php
@@ -61,9 +61,13 @@ class WPStrava_LatestMapWidget extends WP_Widget {
if ( is_wp_error( $rides ) ) {
echo $before_widget;
- echo '';
- print_r($rides);
- echo '
';
+ if ( WPSTRAVA_DEBUG ) {
+ echo '';
+ print_r($rides);
+ echo '
';
+ } else {
+ echo $rides->get_error_message();
+ }
echo $after_widget;
return;
}
diff --git a/lib/Rides.class.php b/lib/Rides.class.php
index c00aef9..309de3a 100755
--- a/lib/Rides.class.php
+++ b/lib/Rides.class.php
@@ -45,7 +45,7 @@ class WPStrava_Rides {
//return $map_details;
return $json;
} else {
- $this->feedback .= _e("There was an error pulling data of strava.com.", "wp-strava");
+ $this->feedback .= _e("There was an error pulling data from strava.com.", "wp-strava");
return false;
}
} else {
diff --git a/lib/Settings.class.php b/lib/Settings.class.php
index 74f958f..698116c 100644
--- a/lib/Settings.class.php
+++ b/lib/Settings.class.php
@@ -21,6 +21,7 @@ class WPStrava_Settings {
add_action( 'admin_init', array( $this, 'register_strava_settings' ) );
add_action( 'admin_menu', array( $this, 'add_strava_menu' ) );
add_action( 'option_home', array( $this, 'option_home' ) );
+ add_filter( 'plugin_action_links_' . WPSTRAVA_PLUGIN_NAME, array( $this, 'settings_link' ) );
}
/**
@@ -225,5 +226,11 @@ class WPStrava_Settings {
public function __get( $name ) {
return get_option( "strava_{$name}" );
}
+
+ public function settings_link( $links ) {
+ $settings_link = 'page_name}" ) . '">' . __( 'Settings' ) . '';
+ $links[] = $settings_link;
+ return $links;
+ }
}
\ No newline at end of file
diff --git a/readme.txt b/readme.txt
index c2c68d8..c4bebca 100755
--- a/readme.txt
+++ b/readme.txt
@@ -1,20 +1,25 @@
=== Plugin Name ===
Contributors: cmanon, jrfoell
Donate link: http://cmanon.com/
-Tags: bicycle, cycling, strava
-Requires at least: 2.0
-Tested up to: 3.5.1
-Stable tag: 0.62
+Tags: strava, bicycle, cycling, biking, running, run, swimming, swim, gps, shortcode, widget, plugin
+Requires at least: 3.0
+Tested up to: 4.0
+Stable tag: 1.0
License: GPLv2 or later
-This plugin is intended to show your strava.com information in your WordPress site.
+Show your Strava activity on your WordPress site.
== Description ==
-This plugin uses the REST strava.com API to pull the data out and show the information in your WordPress site.
+This plugin uses the Strava V3 API to embed maps and activity for
+athletes and clubs on your WordPress site. Included are several
+widgets and shortcodes for showing maps and activity summaries.
== Changelog ==
+= 1.0 =
+Change to Strava API V3
+
= 0.70 =
Use WordPress HTTP API for all remote calls
Use WordPress Settings API for settings page
diff --git a/wp-strava.php b/wp-strava.php
index d8a659d..60927b0 100755
--- a/wp-strava.php
+++ b/wp-strava.php
@@ -27,6 +27,8 @@ License: GPL2
define( 'WPSTRAVA_PLUGIN_DIR', trailingslashit( dirname( __FILE__) ) );
define( 'WPSTRAVA_PLUGIN_URL', plugins_url( '/', __FILE__ ) );
+define( 'WPSTRAVA_PLUGIN_NAME', plugin_basename(__FILE__) );
+define( 'WPSTRAVA_DEBUG', false );
// Load the multilingual support.
if( file_exists( WPSTRAVA_PLUGIN_DIR . 'lang/' . get_locale() . '.mo' ) ) {
@@ -37,16 +39,13 @@ require_once WPSTRAVA_PLUGIN_DIR . 'lib/Strava.class.php';
$wpstrava = WPStrava::get_instance();
//@TODO only load these when needed using is_active_widget()
-function load_styles() {
+function wpstrava_load_scripts_and_styles() {
// Register a personalized stylesheet
wp_register_style('wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' );
wp_enqueue_style('wp-strava');
-}
-add_action('wp_enqueue_script', 'load_styles');
-function load_scripts() {
// Load required javascript libraries
wp_enqueue_script('jquery');
//wp_enqueue_script('google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
}
-add_action('wp-enqueue_script', 'load_scripts');
+add_action('wp_enqueue_script', 'wpstrava_load_scripts_and_styles');
From 4ac9a8aebfb242f5bdb0402e6ca50cadff3e3d95 Mon Sep 17 00:00:00 2001
From: Justin Foell
Date: Sat, 1 Nov 2014 22:53:32 -0500
Subject: [PATCH 10/15] Updated to the [ride] shortcode
---
css/wp-strava.css | 4 +-
lib/LatestMapWidget.class.php | 14 +---
lib/RideShortcode.class.php | 147 +++++++++++++---------------------
lib/Rides.class.php | 19 -----
lib/SOM.class.php | 8 +-
lib/StaticMap.class.php | 18 +++++
lib/Strava.class.php | 1 +
7 files changed, 83 insertions(+), 128 deletions(-)
create mode 100644 lib/StaticMap.class.php
diff --git a/css/wp-strava.css b/css/wp-strava.css
index 86cae73..fad25b8 100755
--- a/css/wp-strava.css
+++ b/css/wp-strava.css
@@ -8,7 +8,7 @@
background-position: -224px -160px;
margin: 0 6px 2px 0;
}
-.table {
+.wp-strava-ride-container {
display: table;
margin: 0 auto;
}
@@ -32,6 +32,6 @@
.ride-details-table-units {
font-size: 0.8em;
}
-.map img {
+.wp-strava-ride-container img {
max-width: none;
}
diff --git a/lib/LatestMapWidget.class.php b/lib/LatestMapWidget.class.php
index ce86ff9..ec40b16 100644
--- a/lib/LatestMapWidget.class.php
+++ b/lib/LatestMapWidget.class.php
@@ -100,25 +100,13 @@ class WPStrava_LatestMapWidget extends WP_Widget {
endif;
}
- private function buildImage( $ride ) {
- $url = 'http://maps.google.com/maps/api/staticmap?maptype=terrain&size=390x260&sensor=false&path=color:0xFF0000BF|weight:2|enc:';
- $url_len = strlen( $url );
- $max_chars = 1865;
-
- if ( $url_len + strlen( $ride->map->polyline ) < $max_chars )
- $url .= $ride->map->polyline;
- else
- $url .= $ride->map->summary_polyline;
-
- return "
";
- }
private function getStaticImage( $ride_id, $build_new ) {
$img = get_option( 'strava_latest_map' );
if ( $build_new || ! $img ) {
$ride = WPStrava::get_instance()->rides->getRide( $ride_id );
- $img = $this->buildImage( $ride );
+ $img = WPStrava_StaticMap::get_image_tag( $ride );
update_option( 'strava_latest_map', $img );
}
diff --git a/lib/RideShortcode.class.php b/lib/RideShortcode.class.php
index e908b9f..5c755da 100644
--- a/lib/RideShortcode.class.php
+++ b/lib/RideShortcode.class.php
@@ -15,109 +15,76 @@ class WPStrava_RideShortcode {
function handler($atts) {
self::$add_script = true;
- $token = get_option('strava_token');
+ $defaults = array(
+ 'id' => 0,
+ 'som' => WPStrava::get_instance()->settings->som,
+ 'map_width' => '480',
+ 'map_height' => '320',
+ );
+
+ extract(shortcode_atts($defaults, $atts));
- if($token) {
- $pairs = array(
- 'id' => 0,
- 'som' => "metric",
- 'efforts' => false,
- 'threshold' => 0,
- 'map_width' => "100%",
- 'map_height' => "400px"
- );
-
- extract(shortcode_atts($pairs, $atts));
+ $strava_som = WPStrava_SOM::get_som( $som );
+ $strava_ride = WPStrava::get_instance()->rides;
+ $rideDetails = $strava_ride->getRide( $id );
- if (isset($som)) {
- $strava_som = $som;
- } else {
- $strava_som = get_option('strava_som_option', 'metric');
- }
-
- $ride = WPStrava::get_instance()->rides;
- $rideDetails = $ride->getRide($id);
- $rideCoordinates = $ride->getRideMap($id, $token, $efforts, $threshold);
-
- if ($strava_som == "metric") {
- $units = array(
- 'elapsedTime' => __('hours','wp-strava'),
- 'movingTime' => __('hours','wp-strava'),
- 'distance' => __('km','wp-strava'),
- 'averageSpeed' => __('km/h','wp-strava'),
- //'maximumSpeed' => __('km/h','wp-strava'),
- 'elevationGain' => __('meters','wp-strava')
- );
- } elseif ($strava_som == "english") {
- $units = array(
- 'elapsedTime' => __('hours','wp-strava'),
- 'movingTime' => __('hours','wp-strava'),
- 'distance' => __('miles','wp-strava'),
- 'averageSpeed' => __('miles/h','wp-strava'),
- //'maximumSpeed' => __('miles/h','wp-strava'),
- 'elevationGain' => __('feet','wp-strava')
- );
- }
-
- if($rideCoordinates) {
- return "
-
-
-
-
- Elapsed Time
- Moving Time
- Distance
- Average Speed
- Elevation Gain
-
-
-
-
- {$rideDetails['elapsedTime']}
- {$rideDetails['movingTime']}
- {$rideDetails['distance']}
- {$rideDetails['averageSpeed']}
- {$rideDetails['elevationGain']}
-
-
- {$units['elapsedTime']}
- {$units['movingTime']}
- {$units['distance']}
- {$units['averageSpeed']}
- {$units['elevationGain']}
-
-
-
-
-
-
- ";
- }
- } else {
- return __('Please first get your strava token using the settings wp strava page.', 'wp-strava');
+ //sanitize width & height
+ $map_width = str_replace( '%', '', $map_width );
+ $map_height = str_replace( '%', '', $map_height );
+ $map_width = str_replace( 'px', '', $map_width );
+ $map_height = str_replace( 'px', '', $map_height );
+
+ if( $rideDetails ) {
+ return '
+
+
+
+
+ ' . __( 'Elapsed Time', 'wp-strava' ) . '
+ ' . __( 'Moving Time', 'wp-strava' ) . '
+ ' . __( 'Distance', 'wp-strava' ) . '
+ ' . __( 'Average Speed', 'wp-strava' ) . '
+ ' . __( 'Max Speed', 'wp-strava' ) . '
+ ' . __( 'Elevation Gain', 'wp-strava' ) . '
+
+
+
+
+ ' . $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->get_time_label() . '
+ ' . $strava_som->get_time_label() . '
+ ' . $strava_som->get_distance_label() . '
+ ' . $strava_som->get_speed_label() . '
+ ' . $strava_som->get_speed_label() . '
+ ' . $strava_som->get_elevation_label() . '
+
+
+
' .
+ WPStrava_StaticMap::get_image_tag( $rideDetails, $map_height, $map_width ) .
+ '';
}
} // handler
static function registerScripts() {
- wp_register_style('wp-strava-style', plugins_url('css/wp-strava.css', __FILE__));
+ wp_register_style('wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' );
- wp_register_script('wp-strava-script', plugins_url('js/wp-strava.js', __FILE__), array('jquery'), '1.0', true);
- wp_register_script('google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
+ //wp_register_script('wp-strava-script', WPSTRAVA_PLUGIN_URL . 'js/wp-strava.js', array( 'jquery' ), '1.0', true);
+ //wp_register_script('google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
}
static function printScripts() {
if (self::$add_script) {
wp_enqueue_style('wp-strava-style');
- wp_enqueue_script('jquery');
- wp_print_scripts('google-maps');
- wp_print_scripts('wp-strava-script');
+ //wp_print_scripts('google-maps');
+ //wp_print_scripts('wp-strava-script');
}
}
}
diff --git a/lib/Rides.class.php b/lib/Rides.class.php
index 309de3a..925f24c 100755
--- a/lib/Rides.class.php
+++ b/lib/Rides.class.php
@@ -34,25 +34,6 @@ class WPStrava_Rides {
return array();
} // getRides
-
- public function getRideMap($rideId, $token, $efforts, $threshold) {
- if($rideId != 0 AND $token != "") {
- $url = preg_replace('/:id/', $rideId, $this->rideMapDetailsUrlV2);
- $json = file_get_contents($url . '?token=' . $token . '&threshold=' . $threshold);
-
- if($json) {
- //$map_details = json_decode($json);
- //return $map_details;
- return $json;
- } else {
- $this->feedback .= _e("There was an error pulling data from strava.com.", "wp-strava");
- return false;
- }
- } else {
- $this->feedback .= _e("You need to provide both parameters to complete the call.", "wp-strava");
- return false;
- }
- } // getRideDetails
public function getRidesLongerThan( $rides, $dist ) {
$som = WPStrava_SOM::get_som();
diff --git a/lib/SOM.class.php b/lib/SOM.class.php
index 7340d76..4bd8ee0 100644
--- a/lib/SOM.class.php
+++ b/lib/SOM.class.php
@@ -4,12 +4,12 @@ abstract class WPStrava_SOM {
public static function get_som( $som = NULL ) {
$som = $som ? $som : WPStrava::get_instance()->settings->som;
- if ( $som == 'metric' ) {
- require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMMetric.class.php';
- return new WPStrava_SOMMetric();
- } else {
+ if ( $som == 'english' ) {
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();
}
}
diff --git a/lib/StaticMap.class.php b/lib/StaticMap.class.php
new file mode 100644
index 0000000..8a3be0b
--- /dev/null
+++ b/lib/StaticMap.class.php
@@ -0,0 +1,18 @@
+map->polyline ) < $max_chars )
+ $url .= $ride->map->polyline;
+ else
+ $url .= $ride->map->summary_polyline;
+
+ return "
";
+ }
+
+}
\ No newline at end of file
diff --git a/lib/Strava.class.php b/lib/Strava.class.php
index ffd1adc..86589be 100644
--- a/lib/Strava.class.php
+++ b/lib/Strava.class.php
@@ -5,6 +5,7 @@ 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/RideShortcode.class.php';
+require_once WPSTRAVA_PLUGIN_DIR . 'lib/StaticMap.class.php';
class WPStrava {
From 18d8897ee970f75f03071dcb7f8630aab599734f Mon Sep 17 00:00:00 2001
From: Justin Foell
Date: Sat, 1 Nov 2014 23:07:03 -0500
Subject: [PATCH 11/15] Updated documentation Set version to alpha
---
readme.txt | 17 +++++++++++++++++
wp-strava.php | 2 +-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/readme.txt b/readme.txt
index c4bebca..d42fe9e 100755
--- a/readme.txt
+++ b/readme.txt
@@ -15,10 +15,27 @@ This plugin uses the Strava V3 API to embed maps and activity for
athletes and clubs on your WordPress site. Included are several
widgets and shortcodes for showing maps and activity summaries.
+= Shortcodes =
+
+[ride id=NUMBER] - add to any page or post. Also takes the following
+optional parameters:
+
+* som - english/metric (system of measure - override from default setting)
+* map_width - width (width of image in pixels)
+* map_height - height (height of image in pixels)
+
+= Widgets =
+
+Strava Latest Rides - shows a list of the last few activities
+
+Strava Latest Map - shows map of latest activity with option to limit
+latest map to activities of a certain minimum distance
+
== Changelog ==
= 1.0 =
Change to Strava API V3
+Switch ride shortcode to use static map
= 0.70 =
Use WordPress HTTP API for all remote calls
diff --git a/wp-strava.php b/wp-strava.php
index 60927b0..954f67a 100755
--- a/wp-strava.php
+++ b/wp-strava.php
@@ -3,7 +3,7 @@
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.0
+Version: 1.0a
Author: Carlos Santa Cruz (cmanon), Justin Foell
Author URI: http://cmanon.com
License: GPL2
From 353ee5ecb0ea253bf39c467a07f4a9c3e13dcc20 Mon Sep 17 00:00:00 2001
From: Justin Foell
Date: Tue, 4 Nov 2014 21:09:12 -0600
Subject: [PATCH 12/15] Register styles in main plugin Enqueue styles only if
needed
---
lib/LatestRidesWidget.class.php | 8 +++++++-
lib/RideShortcode.class.php | 11 +----------
lib/Settings.class.php | 4 ----
lib/Strava.class.php | 7 +++++++
wp-strava.php | 12 ------------
5 files changed, 15 insertions(+), 27 deletions(-)
diff --git a/lib/LatestRidesWidget.class.php b/lib/LatestRidesWidget.class.php
index 40e8cdd..a4f50b7 100644
--- a/lib/LatestRidesWidget.class.php
+++ b/lib/LatestRidesWidget.class.php
@@ -8,7 +8,13 @@ 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 );
- wp_enqueue_style( 'wp-strava' ); //TODO only load this when wigit is loaded
+ add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue' ) );
+ }
+
+ public function maybe_enqueue() {
+ if ( is_active_widget( false, false, $this->id_base ) ) {
+ wp_enqueue_style( 'wp-strava-style' ); //only load this when wigit is loaded
+ }
}
/** @see WP_Widget::widget */
diff --git a/lib/RideShortcode.class.php b/lib/RideShortcode.class.php
index 5c755da..8113310 100644
--- a/lib/RideShortcode.class.php
+++ b/lib/RideShortcode.class.php
@@ -5,13 +5,11 @@ class WPStrava_RideShortcode {
static function init() {
add_shortcode('ride', array(__CLASS__, 'handler'));
-
- add_action('init', array(__CLASS__, 'registerScripts'));
add_action('wp_footer', array(__CLASS__, 'printScripts'));
}
// Shortcode handler function
- // [ride id=id som=metric efforts=false threshold=5 map-width="100%" map-height="400px"] tag
+ // [ride id=id som=metric map_width="100%" map_height="400px"]
function handler($atts) {
self::$add_script = true;
@@ -72,13 +70,6 @@ class WPStrava_RideShortcode {
}
} // handler
- static function registerScripts() {
- wp_register_style('wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' );
-
- //wp_register_script('wp-strava-script', WPSTRAVA_PLUGIN_URL . 'js/wp-strava.js', array( 'jquery' ), '1.0', true);
- //wp_register_script('google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
- }
-
static function printScripts() {
if (self::$add_script) {
wp_enqueue_style('wp-strava-style');
diff --git a/lib/Settings.class.php b/lib/Settings.class.php
index 5ff7f55..f1d7a42 100644
--- a/lib/Settings.class.php
+++ b/lib/Settings.class.php
@@ -203,10 +203,6 @@ class WPStrava_Settings {
}
}
- public function print_options_label() {
- ?>Options
diff --git a/lib/Strava.class.php b/lib/Strava.class.php
index 86589be..cc807f4 100644
--- a/lib/Strava.class.php
+++ b/lib/Strava.class.php
@@ -19,6 +19,8 @@ class WPStrava {
if ( is_admin() ) {
$this->settings->hook();
+ } else {
+ add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
}
// Register StravaLatestRidesWidget widget
@@ -66,4 +68,9 @@ class WPStrava {
return $this->rides;
}
+
+ public function register_scripts() {
+ // Register a personalized stylesheet
+ wp_register_style( 'wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' );
+ }
}
\ No newline at end of file
diff --git a/wp-strava.php b/wp-strava.php
index 954f67a..f0546d3 100755
--- a/wp-strava.php
+++ b/wp-strava.php
@@ -37,15 +37,3 @@ if( file_exists( WPSTRAVA_PLUGIN_DIR . 'lang/' . get_locale() . '.mo' ) ) {
require_once WPSTRAVA_PLUGIN_DIR . 'lib/Strava.class.php';
$wpstrava = WPStrava::get_instance();
-
-//@TODO only load these when needed using is_active_widget()
-function wpstrava_load_scripts_and_styles() {
- // Register a personalized stylesheet
- wp_register_style('wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' );
- wp_enqueue_style('wp-strava');
-
- // Load required javascript libraries
- wp_enqueue_script('jquery');
- //wp_enqueue_script('google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
-}
-add_action('wp_enqueue_script', 'wpstrava_load_scripts_and_styles');
From 3f2b1917c88057cc54035d76bb115c26d91eb1ab Mon Sep 17 00:00:00 2001
From: Justin Foell
Date: Tue, 25 Nov 2014 14:58:39 -0600
Subject: [PATCH 13/15] Replaced PHP 5.3 only wigits_init
---
lib/Strava.class.php | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/lib/Strava.class.php b/lib/Strava.class.php
index cc807f4..0cb1b2d 100644
--- a/lib/Strava.class.php
+++ b/lib/Strava.class.php
@@ -24,9 +24,8 @@ class WPStrava {
}
// Register StravaLatestRidesWidget widget
- add_action( 'widgets_init', function() { return register_widget( 'WPStrava_LatestRidesWidget' ); } );
- add_action( 'widgets_init', function() { return register_widget( 'WPStrava_LatestMapWidget' ); } );
-
+ add_action( 'widgets_init', create_function('', 'return register_widget( "WPStrava_LatestRidesWidget" );') );
+ add_action( 'widgets_init', create_function('', 'return register_widget( "WPStrava_LatestMapWidget" );' ) );
}
public static function get_instance() {
From b05c64ad954d1e016113c3fdbcc940bd0d29ba7a Mon Sep 17 00:00:00 2001
From: Justin Foell
Date: Mon, 1 Dec 2014 15:17:13 -0600
Subject: [PATCH 14/15] Ignore svn dir
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index b25c15b..e0c38e3 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
*~
+.svn
From 6f6ed94329e3b59f2695f2edf617abea949d11cf Mon Sep 17 00:00:00 2001
From: Justin Foell
Date: Tue, 9 Dec 2014 21:49:47 -0600
Subject: [PATCH 15/15] Updated version to 1.0
---
wp-strava.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/wp-strava.php b/wp-strava.php
index f0546d3..372f8cb 100755
--- a/wp-strava.php
+++ b/wp-strava.php
@@ -3,7 +3,7 @@
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.0a
+Version: 1.0
Author: Carlos Santa Cruz (cmanon), Justin Foell
Author URI: http://cmanon.com
License: GPL2