mirror of
https://github.com/10h30/wp-strava.git
synced 2026-06-05 15:10:01 +09:00
Merge pull request #6 from jrfoell/master
This is currently what's v1.1 on wp.org :)
This commit is contained in:
@@ -26,6 +26,9 @@ class WPStrava_API {
|
||||
|
||||
$response = wp_remote_post( $url . $uri, $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'] );
|
||||
|
||||
@@ -3,26 +3,31 @@
|
||||
class WPStrava_LatestMapWidget extends WP_Widget {
|
||||
|
||||
private $som;
|
||||
|
||||
|
||||
public function __construct() {
|
||||
$this->som = WPStrava_SOM::get_som();
|
||||
|
||||
|
||||
parent::__construct(
|
||||
false,
|
||||
'Strava Latest Map', // 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'] ) : '';
|
||||
$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';
|
||||
//$ride_index_params = $ride_index_params ?: 'athleteId=21';
|
||||
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id( 'distance_min' ); ?>"><?php echo sprintf( __( 'Min. Distance (%s):', 'wp-strava' ), $this->som->get_distance_label() ); ?></label>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id( 'distance_min' ); ?>" name="<?php echo $this->get_field_name( 'distance_min' ); ?>" type="text" value="<?php echo $distance_min; ?>" />
|
||||
@@ -31,12 +36,13 @@ class WPStrava_LatestMapWidget extends WP_Widget {
|
||||
<label for="<?php echo $this->get_field_id('strava_club_id'); ?>"><?php _e('Club ID (leave blank to show Athlete):'); ?></label>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id('strava_club_id'); ?>" name="<?php echo $this->get_field_name('strava_club_id'); ?>" type="text" value="<?php echo $strava_club_id; ?>" />
|
||||
</p>
|
||||
<?php
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
public function update( $new_instance, $old_instance ) {
|
||||
// processes widget options to be saved from the admin
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = strip_tags( $new_instance['title'] );
|
||||
$instance['strava_club_id'] = strip_tags( $new_instance['strava_club_id'] );
|
||||
$instance['distance_min'] = strip_tags( $new_instance['distance_min'] );
|
||||
return $instance;
|
||||
@@ -44,16 +50,17 @@ class WPStrava_LatestMapWidget extends WP_Widget {
|
||||
|
||||
public function widget( $args, $instance ) {
|
||||
extract( $args );
|
||||
|
||||
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Latest Activity', 'wp-strava' ) : $instance['title'] );
|
||||
$distance_min = $instance['distance_min'];
|
||||
$strava_club_id = empty( $instance['strava_club_id'] ) ? NULL : $instance['strava_club_id'];
|
||||
$build_new = false;
|
||||
|
||||
//try our transient first
|
||||
|
||||
// Try our transient first.
|
||||
$ride_transient = get_transient( 'strava_latest_map_ride' );
|
||||
$ride_option = get_option( 'strava_latest_map_ride' );
|
||||
|
||||
if ( $ride_transient )
|
||||
$ride = $ride_transient;
|
||||
$ride = $ride_transient ?: null;
|
||||
|
||||
if ( ! $ride ) {
|
||||
$strava_rides = WPStrava::get_instance()->rides;
|
||||
@@ -73,37 +80,38 @@ class WPStrava_LatestMapWidget extends WP_Widget {
|
||||
}
|
||||
|
||||
if ( ! empty( $rides ) ) {
|
||||
|
||||
|
||||
if ( ! empty( $distance_min ) )
|
||||
$rides = $strava_rides->getRidesLongerThan( $rides, $distance_min );
|
||||
|
||||
$ride = current( $rides );
|
||||
|
||||
//update transients & options
|
||||
if ( $ride->id != $ride_option->id ) {
|
||||
if ( empty( $ride_option->id ) || $ride->id != $ride_option->id ) {
|
||||
$build_new = true;
|
||||
update_option( 'strava_latest_map_ride', $ride );
|
||||
}
|
||||
|
||||
if ( $ride->id != $ride_transient->id )
|
||||
set_transient( 'strava_latest_map_ride', $ride, 60 * 60 ); //one hour
|
||||
if ( empty( $ride_transient->id ) || $ride->id != $ride_transient->id ) {
|
||||
set_transient( 'strava_latest_map_ride', $ride, HOUR_IN_SECONDS );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $ride ):
|
||||
if ( $ride ) {
|
||||
echo $before_widget;
|
||||
?><h3 class="widget-title">Latest Ride</h3>
|
||||
<a title="<?php echo $ride->name ?>" href="http://app.strava.com/activities/<?php echo $ride->id ?>"><?php
|
||||
if ( $title ) echo $before_title . $title . $after_title;
|
||||
?><a title="<?php echo $ride->name ?>" target="_blank" href="http://app.strava.com/activities/<?php echo $ride->id ?>"><?php
|
||||
echo $this->getStaticImage( $ride->id, $build_new );
|
||||
?></a><?php
|
||||
echo $after_widget;
|
||||
endif;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 = WPStrava_StaticMap::get_image_tag( $ride );
|
||||
@@ -112,5 +120,4 @@ class WPStrava_LatestMapWidget extends WP_Widget {
|
||||
|
||||
return $img;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
|
||||
?>
|
||||
<?php echo $before_widget; ?>
|
||||
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
|
||||
<?php echo $this->strava_request_handler( $strava_club_id, $strava_som_option, $quantity ); ?>
|
||||
<?php echo $this->strava_request_handler( $strava_club_id, $quantity ); ?>
|
||||
<?php echo $after_widget; ?>
|
||||
<?php
|
||||
}
|
||||
@@ -39,11 +39,6 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
|
||||
public function update( $new_instance, $old_instance ) {
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = strip_tags( $new_instance['title'] );
|
||||
if( in_array( $new_instance['strava_som_option'], array( 'metric', 'english' ) ) ) {
|
||||
$instance['strava_som_option'] = $new_instance['strava_som_option'];
|
||||
} else {
|
||||
$instance['strava_som_option'] = 'metric';
|
||||
}
|
||||
$instance['strava_club_id'] = strip_tags( $new_instance['strava_club_id'] );
|
||||
$instance['quantity'] = $new_instance['quantity'];
|
||||
|
||||
@@ -74,7 +69,7 @@ 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_club_id, $strava_som_option, $quantity ) {
|
||||
private function strava_request_handler( $strava_club_id, $quantity ) {
|
||||
|
||||
$strava_rides = WPStrava::get_instance()->rides;
|
||||
|
||||
@@ -85,7 +80,7 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
|
||||
$response = "<ul id='rides'>";
|
||||
foreach( $rides as $ride ) {
|
||||
$response .= "<li class='ride'>";
|
||||
$response .= "<a href='" . WPStrava_Rides::RIDES_URL . $ride->id . "' >" . $ride->name . "</a>";
|
||||
$response .= "<a href='" . WPStrava_Rides::RIDES_URL . $ride->id . "' target='_blank'>" . $ride->name . "</a>";
|
||||
$response .= "<div class='ride-item'>";
|
||||
$unixtime = strtotime( $ride->start_date_local );
|
||||
$response .= sprintf( __("On %s %s", "wp-strava"), date_i18n( get_option( 'date_format' ), $unixtime ), date_i18n( get_option( 'time_format' ), $unixtime ) );
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
<?php
|
||||
|
||||
class WPStrava_RideShortcode {
|
||||
static $add_script;
|
||||
private static $add_script;
|
||||
|
||||
static function init() {
|
||||
add_shortcode('ride', array(__CLASS__, 'handler'));
|
||||
add_action('wp_footer', array(__CLASS__, 'printScripts'));
|
||||
public static function init() {
|
||||
add_shortcode( 'ride', array( __CLASS__, 'handler' ) );
|
||||
add_shortcode( 'activity', array( __CLASS__, 'handler' ) );
|
||||
add_action( 'wp_footer', array( __CLASS__, 'printScripts' ) );
|
||||
}
|
||||
|
||||
// Shortcode handler function
|
||||
// [ride id=id som=metric map_width="100%" map_height="400px"]
|
||||
function handler($atts) {
|
||||
public static function handler($atts) {
|
||||
self::$add_script = true;
|
||||
|
||||
$defaults = array(
|
||||
@@ -31,7 +32,7 @@ class WPStrava_RideShortcode {
|
||||
$map_height = str_replace( '%', '', $map_height );
|
||||
$map_width = str_replace( 'px', '', $map_width );
|
||||
$map_height = str_replace( 'px', '', $map_height );
|
||||
|
||||
|
||||
if( $rideDetails ) {
|
||||
return '
|
||||
<div id="ride-header-' . $id . '" class="wp-strava-ride-container">
|
||||
@@ -70,7 +71,7 @@ class WPStrava_RideShortcode {
|
||||
}
|
||||
} // handler
|
||||
|
||||
static function printScripts() {
|
||||
public static function printScripts() {
|
||||
if (self::$add_script) {
|
||||
wp_enqueue_style('wp-strava-style');
|
||||
|
||||
|
||||
+3
-3
@@ -11,9 +11,9 @@ abstract class WPStrava_SOM {
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMMetric.class.php';
|
||||
return new WPStrava_SOMMetric();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
abstract public function distance( $m );
|
||||
abstract public function distance_inverse( $dist );
|
||||
abstract public function get_distance_label();
|
||||
@@ -29,4 +29,4 @@ abstract class WPStrava_SOM {
|
||||
public function get_time_label() {
|
||||
return __( 'hours', 'wp-strava' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+82
-38
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* v3 - http://strava.github.io/api/v3/oauth/
|
||||
*
|
||||
*
|
||||
* 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= or ?error=
|
||||
@@ -15,12 +15,12 @@ class WPStrava_Settings {
|
||||
private $token;
|
||||
private $page_name = 'wp-strava-options';
|
||||
private $option_page = 'wp-strava-settings-group';
|
||||
|
||||
|
||||
//register admin menus
|
||||
public function hook() {
|
||||
add_action( 'admin_init', array( $this, 'register_strava_settings' ) );
|
||||
add_action( 'admin_menu', array( $this, 'add_strava_menu' ) );
|
||||
add_filter( 'pre_set_transient_settings_errors', array( $this, 'maybe_oauth' ), 10 );
|
||||
add_filter( 'pre_set_transient_settings_errors', array( $this, 'maybe_oauth' ) );
|
||||
add_filter( 'plugin_action_links_' . WPSTRAVA_PLUGIN_NAME, array( $this, 'settings_link' ) );
|
||||
//for process debugging
|
||||
//add_action( 'all', array( $this, 'hook_debug' ) );
|
||||
@@ -35,27 +35,31 @@ class WPStrava_Settings {
|
||||
* 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
|
||||
// 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();
|
||||
// Only re-auth if client ID and secret were shown.
|
||||
if ( ! empty( $_POST['strava_client_id'] ) && ! empty( $_POST['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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
public function add_strava_menu() {
|
||||
add_options_page( __( 'Strava Settings', 'wp-strava' ),
|
||||
__( 'Strava', 'wp-strava' ),
|
||||
@@ -79,14 +83,14 @@ class WPStrava_Settings {
|
||||
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' );
|
||||
|
||||
$this->token = get_option( 'strava_token' );
|
||||
}
|
||||
|
||||
|
||||
public function register_strava_settings() {
|
||||
$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_section( 'strava_api', __( 'Strava API', 'wp-strava' ), array( $this, 'print_api_instructions' ), 'wp-strava' );
|
||||
|
||||
if ( ! $this->token ) {
|
||||
register_setting( $this->option_page, 'strava_client_id', array( $this, 'sanitize_client_id' ) );
|
||||
@@ -98,41 +102,59 @@ class WPStrava_Settings {
|
||||
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' );
|
||||
// Google Maps API.
|
||||
register_setting( $this->option_page, 'strava_gmaps_key', array( $this, 'sanitize_gmaps_key' ) );
|
||||
add_settings_section( 'strava_gmaps', __( 'Google Maps', 'wp-strava' ), array( $this, 'print_gmaps_instructions' ), 'wp-strava' );
|
||||
add_settings_field( 'strava_gmaps_key', __( 'Static Maps Key', 'wp-strava' ), array( $this, 'print_gmaps_key_input' ), 'wp-strava', 'strava_gmaps' );
|
||||
|
||||
// System of Measurement.
|
||||
register_setting( $this->option_page, 'strava_som', array( $this, 'sanitize_som' ) );
|
||||
add_settings_section( 'strava_options', __( 'Options', 'wp-strava' ), null, 'wp-strava' );
|
||||
add_settings_field( 'strava_som', __( 'System of Measurement', 'wp-strava' ), array( $this, 'print_som_input' ), 'wp-strava', 'strava_options' );
|
||||
|
||||
// Clear cache.
|
||||
register_setting( $this->option_page, 'strava_cache_clear', array( $this, 'sanitize_cache_clear' ) );
|
||||
add_settings_section( 'strava_cache', __( 'Cache', 'wp-strava' ), null, 'wp-strava' );
|
||||
add_settings_field( 'strava_cache_clear', __( 'Clear cache (images & transient data)', 'wp-strava' ), array( $this, 'print_clear_input' ), 'wp-strava', 'strava_cache' );
|
||||
}
|
||||
|
||||
public function print_api_instructions() {
|
||||
$signup_url = 'http://www.strava.com/developers';
|
||||
$settings_url = 'https://www.strava.com/settings/api';
|
||||
$blog_name = get_bloginfo( 'name' );
|
||||
$app_name = $blog_name . ' Strava';
|
||||
$url_parts = parse_url( site_url() );
|
||||
$site_url = $url_parts['host']; //strip http/https for copying/pasting into strava
|
||||
$app_name = sprintf( esc_html( '%s Strava', 'wp-strava' ), $blog_name );
|
||||
$site_url = site_url();
|
||||
$description = 'WP-Strava for ' . $blog_name;
|
||||
printf( __( "<p>Steps:</p>
|
||||
<ol>
|
||||
<li>Create your API Application here: <a href='%s' target='_blank'>%s</a> using the following information:</li>
|
||||
<li>Create your free API Application/Connection here: <a href='%s' target='_blank'>%s</a> using the following information:</li>
|
||||
<ul>
|
||||
<li>Application Name: <strong>%s</strong></li>
|
||||
<li>Website: <strong>%s</strong></li>
|
||||
<li>Application Description: <strong>%s</strong></li>
|
||||
<li>Authorization Callback Domain: <strong>%s</strong></li>
|
||||
</ul>
|
||||
<li>Once you've created your API Application at strava.com, enter the Client ID and Client Secret below, which can be found at <a href='%s' target='_blank'>%s</a></li>
|
||||
<li>Once you've created your API Application at strava.com, enter the <strong>Client ID</strong> and <strong>Client Secret</strong> below, which can now be found on that same strava API Settings page.
|
||||
<li>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.</li>
|
||||
<li>If you need to re-authorize your API Application, erase your Strava Token here and click 'Save Changes' to start over.</li>
|
||||
</ol>", 'wp-strava' ), $signup_url, $signup_url, $app_name, $site_url, $description, $site_url, $settings_url, $settings_url );
|
||||
</ol>", 'wp-strava' ), $settings_url, $settings_url, $app_name, $site_url, $description, $site_url );
|
||||
}
|
||||
|
||||
|
||||
public function print_gmaps_instructions() {
|
||||
$maps_url = 'https://developers.google.com/maps/documentation/static-maps/';
|
||||
printf( __( "<p>Steps:</p>
|
||||
<ol>
|
||||
<li>To use Google map images, you must create a Static Maps API Key. Create a free key by going here: <a href='%s' target='_blank'>%s</a> and clicking <strong>Get a Key</strong></li>
|
||||
<li>Once you've created your Google Static Maps API Key, enter the key below.
|
||||
</ol>", 'wp-strava' ), $maps_url, $maps_url );
|
||||
|
||||
}
|
||||
|
||||
public function print_strava_options() {
|
||||
?>
|
||||
<div class="wrap">
|
||||
<div id="icon-options-general" class="icon32"><br/></div>
|
||||
<div id="icon-options-general" class="icon32"><br/></div>
|
||||
<h2><?php _e( 'Strava Settings', 'wp-strava' ); ?></h2>
|
||||
|
||||
<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
|
||||
@@ -200,9 +222,17 @@ class WPStrava_Settings {
|
||||
} else {
|
||||
$this->feedback .= __( 'Missing Client ID or Client Secret.', 'wp-strava' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function print_gmaps_key_input() {
|
||||
?><input type="text" id="strava_gmaps_key" name="strava_gmaps_key" value="<?php echo get_option( 'strava_gmaps_key' ); ?>" /><?php
|
||||
}
|
||||
|
||||
public function sanitize_gmaps_key( $key ) {
|
||||
return $key;
|
||||
}
|
||||
|
||||
public function print_som_input() {
|
||||
$strava_som = get_option( 'strava_som' );
|
||||
?>
|
||||
@@ -217,13 +247,27 @@ class WPStrava_Settings {
|
||||
return $som;
|
||||
}
|
||||
|
||||
public function print_clear_input() {
|
||||
?><input type="checkbox" id="strava_cache_clear" name="strava_cache_clear" /><?php
|
||||
}
|
||||
|
||||
public function sanitize_cache_clear( $checked ) {
|
||||
if ( 'on' === $checked ) {
|
||||
// Clear these values:
|
||||
delete_transient( 'strava_latest_map_ride' );
|
||||
delete_option( 'strava_latest_map_ride' );
|
||||
delete_option( 'strava_latest_map' );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function __get( $name ) {
|
||||
return get_option( "strava_{$name}" );
|
||||
}
|
||||
|
||||
public function settings_link( $links ) {
|
||||
$settings_link = '<a href="' . admin_url( "options-general.php?page={$this->page_name}" ) . '">' . __( 'Settings' ) . '</a>';
|
||||
$links[] = $settings_link;
|
||||
|
||||
public function settings_link( $links ) {
|
||||
$settings_link = '<a href="' . admin_url( "options-general.php?page={$this->page_name}" ) . '">' . __( 'Settings' ) . '</a>';
|
||||
$links[] = $settings_link;
|
||||
return $links;
|
||||
}
|
||||
|
||||
|
||||
+26
-7
@@ -1,18 +1,37 @@
|
||||
<?php
|
||||
|
||||
class WPStrava_StaticMap {
|
||||
|
||||
|
||||
/**
|
||||
* Get an image tag to a static google map. Will render with
|
||||
* detailed polyline if not greater than 1865 chars, otherwise
|
||||
* rendering will use summary polyline.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param object $ride Ride object from strava.
|
||||
* @param int $height Height of map in pixels.
|
||||
* @param int $width Width of map in pixels.
|
||||
*/
|
||||
public static function get_image_tag( $ride, $height = 320, $width = 480 ) {
|
||||
$url = "http://maps.google.com/maps/api/staticmap?maptype=terrain&size={$width}x{$height}&sensor=false&path=color:0xFF0000BF|weight:2|enc:";
|
||||
$key = WPStrava::get_instance()->settings->gmaps_key;
|
||||
|
||||
// Short circuit if missing key or ride object doesn't have the data we need.
|
||||
if ( empty( $key ) || empty( $ride->map ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$url = "https://maps.googleapis.com/maps/api/staticmap?maptype=terrain&size={$width}x{$height}&sensor=false&key={$key}&path=color:0xFF0000BF|weight:2|enc:";
|
||||
$url_len = strlen( $url );
|
||||
$max_chars = 1865;
|
||||
|
||||
if ( $url_len + strlen( $ride->map->polyline ) < $max_chars )
|
||||
if ( ! empty( $ride->map->polyline ) && ( $url_len + strlen( $ride->map->polyline ) < $max_chars ) ) {
|
||||
$url .= $ride->map->polyline;
|
||||
else
|
||||
} else {
|
||||
$url .= $ride->map->summary_polyline;
|
||||
|
||||
return "<img src='{$url}' />";
|
||||
}
|
||||
|
||||
return "<img class='wp-strava-img' src='{$url}' />";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+17
-14
@@ -9,11 +9,11 @@ require_once WPSTRAVA_PLUGIN_DIR . 'lib/StaticMap.class.php';
|
||||
|
||||
class WPStrava {
|
||||
|
||||
private static $instance = NULL;
|
||||
private $settings = NULL;
|
||||
private $api = NULL;
|
||||
private $rides = NULL;
|
||||
|
||||
private static $instance = null;
|
||||
private $settings = null;
|
||||
private $api = null;
|
||||
private $rides = null;
|
||||
|
||||
private function __construct() {
|
||||
$this->settings = new WPStrava_Settings();
|
||||
|
||||
@@ -24,8 +24,8 @@ class WPStrava {
|
||||
}
|
||||
|
||||
// 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" );' ) );
|
||||
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() {
|
||||
@@ -37,28 +37,31 @@ class WPStrava {
|
||||
}
|
||||
|
||||
public function __get( $name ) {
|
||||
//on-demand classes
|
||||
if ( $name == 'api' )
|
||||
// On-demand classes.
|
||||
if ( $name == 'api' ) {
|
||||
return $this->get_api();
|
||||
}
|
||||
|
||||
if ( $name == 'rides' )
|
||||
if ( $name == 'rides' ) {
|
||||
return $this->get_rides();
|
||||
}
|
||||
|
||||
if ( isset( $this->{$name} ) )
|
||||
if ( isset( $this->{$name} ) ) {
|
||||
return $this->{$name};
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_api() {
|
||||
if ( ! $this->api ) {
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/API.class.php';
|
||||
$this->api = new WPStrava_API( get_option('strava_token') );
|
||||
$this->api = new WPStrava_API( get_option( 'strava_token' ) );
|
||||
}
|
||||
|
||||
return $this->api;
|
||||
}
|
||||
|
||||
|
||||
public function get_rides() {
|
||||
if ( ! $this->rides ) {
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/Rides.class.php';
|
||||
|
||||
+15
-6
@@ -1,10 +1,9 @@
|
||||
=== Plugin Name ===
|
||||
Contributors: cmanon, jrfoell
|
||||
Donate link: http://cmanon.com/
|
||||
Contributors: cmanon, jrfoell, lancewillett
|
||||
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
|
||||
Requires at least: 4.0
|
||||
Tested up to: 4.7
|
||||
Stable tag: 1.1
|
||||
License: GPLv2 or later
|
||||
|
||||
Show your Strava activity on your WordPress site.
|
||||
@@ -17,7 +16,7 @@ widgets and shortcodes for showing maps and activity summaries.
|
||||
|
||||
= Shortcodes =
|
||||
|
||||
[ride id=NUMBER] - add to any page or post. Also takes the following
|
||||
[activity id=NUMBER] - add to any page or post. Also takes the following
|
||||
optional parameters:
|
||||
|
||||
* som - english/metric (system of measure - override from default setting)
|
||||
@@ -33,6 +32,16 @@ latest map to activities of a certain minimum distance
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.1 =
|
||||
Added [activity] shortcode to deprecate [ride] in the future
|
||||
Fixed static method call error in shortcode
|
||||
Added title to Strava Latest Map Widget
|
||||
Added Lance Willett to contributors
|
||||
Added target="_blank" to widget hrefs
|
||||
Added Google Maps Key to settings (required for map images)
|
||||
Added cache clear option to remove transient & image data
|
||||
Cleaned up formatting
|
||||
|
||||
= 1.0 =
|
||||
Change to Strava API V3
|
||||
Switch ride shortcode to use static map
|
||||
|
||||
+9
-9
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
/*
|
||||
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
|
||||
Author: Carlos Santa Cruz (cmanon), Justin Foell <justin@foell.org>
|
||||
Author URI: http://cmanon.com
|
||||
License: GPL2
|
||||
*/
|
||||
* 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
|
||||
* License: GPL2
|
||||
*/
|
||||
|
||||
/* Copyright 2011 Carlos Santa Cruz (email : cmanon at gmail dot com)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
@@ -28,7 +28,7 @@ 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 );
|
||||
if ( ! defined( 'WPSTRAVA_DEBUG' ) ) define( 'WPSTRAVA_DEBUG', false );
|
||||
|
||||
// Load the multilingual support.
|
||||
if( file_exists( WPSTRAVA_PLUGIN_DIR . 'lang/' . get_locale() . '.mo' ) ) {
|
||||
|
||||
Reference in New Issue
Block a user