diff --git a/.gitignore b/.gitignore
index b25c15b..e0c38e3 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
*~
+.svn
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/API.class.php b/lib/API.class.php
index 33631e7..44dd657 100755
--- a/lib/API.class.php
+++ b/lib/API.class.php
@@ -4,29 +4,26 @@
*/
class WPStrava_API {
- 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
+ //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/';
- /*
- private $rideUrl = "http://www.strava.com/api/v1/rides/:id";
- private $rideUrlV2 = "http://www.strava.com/api/v2/rides/:id";
- private $ridesUrl = "http://www.strava.com/api/v1/rides";
- private $authenticationUrl = "https://www.strava.com/api/v1/authentication/login";
- private $authenticationUrlV2 = "https://www.strava.com/api/v2/authentication/login";
- private $rideMapDetailsUrl = "http://www.strava.com/api/v1/rides/:id/map_details";
- private $rideMapDetailsUrlV2 = "http://www.strava.com/api/v2/rides/:id/map_details";
- */
+ public function __construct( $access_token ) {
+ $this->access_token = $access_token;
+ }
- public function post( $uri, $data = NULL, $version = 2 ) {
- $url = ( $version == 2 ) ? self::STRAVA_V2_API : self::STRAVA_V1_API;
+ public function post( $uri, $data = NULL ) {
+ $url = self::STRAVA_V3_API;
$args = array(
'body' => http_build_query( $data ),
+ 'sslverify' => false,
+ 'headers' => array(
+ 'Authorization' => 'Bearer ' . $this->access_token,
+ )
);
- if ( $version == 2 )
- $args['sslverify'] = false;
-
$response = wp_remote_post( $url . $uri, $args );
if ( $response['response']['code'] != 200 ) {
@@ -46,26 +43,33 @@ class WPStrava_API {
return json_decode( $response['body'] );
}
- public function get( $uri, $args = NULL, $version = 2 ) {
- $url = ( $version == 2 ) ? self::STRAVA_V2_API : self::STRAVA_V1_API;
+ public function get( $uri, $args = NULL ) {
+ $url = self::STRAVA_V3_API;
$url .= $uri;
if ( ! empty( $args ) )
$url = add_query_arg( $args, $url );
- $response = wp_remote_get( $url );
+ $get_args = array(
+ 'headers' => array(
+ 'Authorization' => 'Bearer ' . $this->access_token,
+ )
+ );
+
+ $response = wp_remote_get( $url, $get_args );
if ( is_wp_error( $response ) )
return $response;
if ( $response['response']['code'] != 200 ) {
- die($url);
//see if there's useful info in the body
$body = json_decode( $response['body'] );
$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 a77ab73..ec40b16 100644
--- a/lib/LatestMapWidget.class.php
+++ b/lib/LatestMapWidget.class.php
@@ -17,7 +17,7 @@ class WPStrava_LatestMapWidget extends WP_Widget {
public function form( $instance ) {
// outputs the options form on admin
$distance_min = isset( $instance['distance_min'] ) ? esc_attr( $instance['distance_min'] ) : '';
- $ride_index_params = isset( $instance['ride_index_params'] ) ? esc_attr( $instance['ride_index_params'] ) : '';
+ $strava_club_id = isset( $instance['strava_club_id'] ) ? esc_attr( $instance['strava_club_id'] ) : '';
//provide some defaults
//$ride_index_params = $ride_index_params ? $ride_index_params : 'athleteId=21';
@@ -27,35 +27,25 @@ class WPStrava_LatestMapWidget extends WP_Widget {
som->get_distance_label() ); ?>
-
-
-
-
-
+
+
+
+
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
@@ -64,12 +54,23 @@ class WPStrava_LatestMapWidget extends WP_Widget {
if ( $ride_transient )
$ride = $ride_transient;
-
+
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;
+ if ( WPSTRAVA_DEBUG ) {
+ echo '';
+ print_r($rides);
+ echo ' ';
+ } else {
+ echo $rides->get_error_message();
+ }
+ echo $after_widget;
+ return;
+ }
if ( ! empty( $rides ) ) {
@@ -92,47 +93,20 @@ class WPStrava_LatestMapWidget extends WP_Widget {
if ( $ride ):
echo $before_widget;
?>
- name ?>" href="http://app.strava.com/activities/id ?>">getStaticImage( $ride->id, $build_new );
?> latlng );
- $full_url = '';
- $max_chars = 1865;
-
- //get the longest usable URL
- while ( $url_len + $point_len < $max_chars ) {
- $mod = (int) ( $count / $num );
- $points = array();
- for ( $i = 0; $i < $count; $i += $mod ) {
- $point = $map_details->latlng[$i];
- $points[] = number_format( $point[0], 4 ) . ',' . number_format( $point[1], 4 );
- }
-
- $url_points = join( '|', $points );
- $point_len = strlen( $url_points );
- if ( $url_len + $point_len < $max_chars )
- $full_url = $url . $url_points;
- $num++;
- }
-
- return " ";
- }
private function getStaticImage( $ride_id, $build_new ) {
$img = get_option( 'strava_latest_map' );
if ( $build_new || ! $img ) {
- $map_details = WPStrava::get_instance()->rides->getMapDetails( $ride_id );
- $img = $this->buildImage( $map_details );
+ $ride = WPStrava::get_instance()->rides->getRide( $ride_id );
+ $img = WPStrava_StaticMap::get_image_tag( $ride );
update_option( 'strava_latest_map', $img );
}
diff --git a/lib/LatestRidesWidget.class.php b/lib/LatestRidesWidget.class.php
index e84a4bb..a4f50b7 100644
--- a/lib/LatestRidesWidget.class.php
+++ b/lib/LatestRidesWidget.class.php
@@ -6,73 +6,64 @@
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
+ $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 );
+ 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 */
public function widget( $args, $instance ) {
- extract($args);
+ extract( $args );
//$widget_id = $args['widget_id'];
- $title = apply_filters('widget_title', empty($instance['title']) ? _e('Rides', 'wp-strava') : $instance['title']);
- $strava_search_option = empty($instance['strava_search_option']) ? 'athlete' : $instance['strava_search_option'];
- $strava_search_id = empty($instance['strava_search_id']) ? '' : $instance['strava_search_id'];
- $quantity = empty($instance['quantity']) ? '5' : $instance['quantity'];
+ $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'];
+ $quantity = empty( $instance['quantity'] ) ? '5' : $instance['quantity'];
$this->som = WPStrava_SOM::get_som();
?>
- strava_request_handler($strava_search_option, $strava_search_id, $strava_som_option, $quantity); ?>
+ strava_request_handler( $strava_club_id, $strava_som_option, $quantity ); ?>
-
-
-
-
-
-
-
- >
- >
-
+
+
-
-
+
+
@@ -83,41 +74,29 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
// 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_search_option, $strava_search_id, $strava_som_option, $quantity ) {
+ private function strava_request_handler( $strava_club_id, $strava_som_option, $quantity ) {
- //Check if the username is empty.
- if ( empty( $strava_search_id ) )
- return __("Please configure the Strava search id on the widget options.", "wp-strava");
- //else
$strava_rides = WPStrava::get_instance()->rides;
- $rides = $strava_rides->getRidesSimple( $strava_search_option, $strava_search_id );
+ $rides = $strava_rides->getRides( $strava_club_id, $quantity );
if ( is_wp_error( $rides ) )
return $rides->get_error_message();
-
- //adjust quantity
- $rides = array_slice( $rides, 0, $quantity );
- $rides_details = $strava_rides->getRidesDetails( $rides );
- if ( is_wp_error( $rides_details ) )
- return $rides_details->get_error_message();
-
$response = "
";
- foreach($rides_details as $ride_obj) {
- $ride = $ride_obj->ride;
+ foreach( $rides as $ride ) {
$response .= "";
$response .= "" . $ride->name . " ";
$response .= "";
$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 ) );
- if ($strava_search_option == "club") {
+ if ( is_numeric( $strava_club_id ) ) {
$response .= "
" . $ride->athlete_name . " ";
}
$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->elevation_gain ), $this->som->get_elevation_label() );
+ $response .= sprintf( __( " climbing %s %s", "wp-strava" ), $this->som->elevation( $ride->total_elevation_gain ), $this->som->get_elevation_label() );
$response .= "
";
$response .= " ";
}
diff --git a/lib/RideShortcode.class.php b/lib/RideShortcode.class.php
index db36f77..8113310 100644
--- a/lib/RideShortcode.class.php
+++ b/lib/RideShortcode.class.php
@@ -5,122 +5,80 @@ 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;
- $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 = new Rides();
- $rideDetails = $ride->getRideDetails($id, $strava_som);
- $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 "
-
-
-
- ";
- }
- } else {
- return _e('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 '
+ ';
}
} // handler
- static function registerScripts() {
- wp_register_style('wp-strava-style', plugins_url('css/wp-strava.css', __FILE__));
-
- 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');
- }
-
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');
}
}
}
// Initialize short code
-RideShortcode::init();
+WPStrava_RideShortcode::init();
diff --git a/lib/Rides.class.php b/lib/Rides.class.php
index d3e145b..925f24c 100755
--- a/lib/Rides.class.php
+++ b/lib/Rides.class.php
@@ -7,101 +7,47 @@ class WPStrava_Rides {
const RIDES_URL = "http://app.strava.com/rides/";
const ATHLETES_URL = "http://app.strava.com/athletes/";
- public function getRideDetails( $rideId ) {
- return WPStrava::get_instance()->api->get( "rides/{$rideId}" );
+ public function getRide( $rideId ) {
+ return WPStrava::get_instance()->api->get( "activities/{$rideId}" );
} // getRideDetails
-
- public function getRidesDetails( $rides ) {
- $rides_details = array();
- foreach ( $rides as $stravaRide ) {
- $detail = $this->getRideDetails( $stravaRide->id );
-
- if ( is_wp_error( $detail ) )
- return $detail;
-
- $rides_details[] = $detail;
- }
- return $rides_details;
- } // getRidesDetails
- public function getRidesSimple( $searchOption, $searchId ) {
+ public function getRides( $club_id = NULL, $quantity = NULL ) {
$api = WPStrava::get_instance()->api;
$data = NULL;
+
+ $args = $quantity ? array( 'per_page' => $quantity ) : NULL;
+
//Get the json results using the constructor specified values.
- if ( $searchOption == 'athlete' ) {
- if ( is_numeric( $searchId ) ) {
- $data = $api->get( 'rides', array( 'athleteId' => $searchId ), 1 );
- } else {
- $data = $api->get( 'rides', array( 'athleteName' => $searchId ), 1 );
- }
- } elseif ($searchOption == 'club' && is_numeric($searchId)) {
- $data = $api->get( 'rides', array( 'clubId' => $searchId ), 1 );
+ if ( is_numeric( $club_id ) ) {
+ $data = $api->get( "clubs/{$club_id}/activities", $args );
} else {
- return new WP_Error( 'wp-strava_options', __("There's an error in your simple options.", 'wp-strava') );
+ $data = $api->get( 'athlete/activities', $args );
}
if ( is_wp_error( $data ) )
return $data;
- if ( isset( $data->rides ) )
- return $data->rides;
-
- return array();
-
- } // getRidesSimple
-
- public function getRidesAdvanced( $params ) {
- $data = WPStrava::get_instance()->api->get( 'rides', $params, 1 ); //version 1
-
- if ( is_wp_error( $data ) )
+ if ( is_array( $data ) )
return $data;
- if ( isset( $data->rides ) )
- return $data->rides;
-
return array();
- }
-
- 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 of 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
+
+ } // getRides
public function getRidesLongerThan( $rides, $dist ) {
$som = WPStrava_SOM::get_som();
$meters = $som->distance_inverse( $dist );
$long_rides = array();
- foreach ( $rides as $ride ) {
- $ride_info = $this->getRideDetails( $ride->id );
- if ( $ride_info->ride->distance > $meters ) {
+ foreach ( $rides as $ride_info ) {
+ if ( $ride_info->distance > $meters ) {
$long_rides[] = $ride_info;
}
}
return $long_rides;
}
-
- public function getMapDetails( $ride_id ) {
- $token = WPStrava::get_instance()->settings->token;
- return WPStrava::get_instance()->api->get( "rides/{$ride_id}/map_details", array( 'token' => $token ) );
- }
-
} // class Rides
?>
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/Settings.class.php b/lib/Settings.class.php
index 9eee604..f1d7a42 100644
--- a/lib/Settings.class.php
+++ b/lib/Settings.class.php
@@ -1,35 +1,105 @@
\n";
+ }
+
+ /**
+ * This runs after options are saved
+ */
+ 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' );
+
+ 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() {
add_options_page( __( 'Strava Settings', 'wp-strava' ),
__( 'Strava', 'wp-strava' ),
'manage_options',
- 'wp-strava-options',
+ $this->page_name,
array( $this, 'print_strava_options' ) );
}
+ public function init() {
+ //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'] ) ) );
+ }
+ }
+
+ $this->token = get_option( 'strava_token' );
+ }
+
public function register_strava_settings() {
- register_setting('wp-strava-settings-group','strava_email', array( $this, 'sanitize_email' ) );
- register_setting('wp-strava-settings-group','strava_password', NULL );
- register_setting('wp-strava-settings-group','strava_token', array( $this, 'sanitize_token' ) );
-
+ $this->init();
+
add_settings_section( 'strava_api', __( 'Strava API', 'wp-strava' ), array( $this, 'print_api_instructions' ), 'wp-strava' ); //NULL / NULL no section label needed
- add_settings_field( 'strava_email', __( 'Strava Email', 'wp-strava' ), array( $this, 'print_email_input' ), 'wp-strava', 'strava_api' );
- add_settings_field( 'strava_password', __( 'Strava Password', 'wp-strava' ), array( $this, 'print_password_input' ), 'wp-strava', 'strava_api' );
- add_settings_field( 'strava_token', __( 'Strava Token', 'wp-strava' ), array( $this, 'print_token_input' ), 'wp-strava', 'strava_api' );
+ if ( ! $this->token ) {
+ register_setting( $this->option_page, 'strava_client_id', array( $this, 'sanitize_client_id' ) );
+ register_setting( $this->option_page, 'strava_client_secret', array( $this, 'sanitize_client_secret' ) );
- register_setting('wp-strava-settings-group','strava_som', array( $this, 'sanitize_som' ) );
+ add_settings_field( 'strava_client_id', __( 'Strava Client ID', 'wp-strava' ), array( $this, 'print_client_input' ), 'wp-strava', 'strava_api' );
+ add_settings_field( 'strava_client_secret', __( 'Strava Client Secret', 'wp-strava' ), array( $this, 'print_secret_input' ), 'wp-strava', 'strava_api' );
+ } else {
+ 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' );
+ }
+
+ register_setting( $this->option_page, 'strava_som', array( $this, 'sanitize_som' ) );
add_settings_section( 'strava_options', __( 'Options', 'wp-strava' ), NULL, 'wp-strava' );
@@ -37,7 +107,26 @@ class WPStrava_Settings {
}
public function print_api_instructions() {
- ?>
Steps:
+
+ Create your API Application here: %s using the following information:
+
+ Application Name: %s
+ Website: %s
+ Application Description: %s
+ Authorization Callback Domain: %s
+
+ Once you've created your API Application at strava.com, enter the Client ID and Client Secret below, which can be found at %s
+ After saving your Client ID and Secret, you'll be redirected to strava to authorize your API Application. If successful, your Strava Token will display instead of Client ID and Client Secret.
+ If you need to re-authorize your API Application, erase your Strava Token here and click 'Save Changes' to start over.
+ ", 'wp-strava' ), $signup_url, $signup_url, $app_name, $site_url, $description, $site_url, $settings_url, $settings_url );
}
public function print_strava_options() {
@@ -47,7 +136,7 @@ class WPStrava_Settings {