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 TimeMoving TimeDistanceAverage SpeedElevation 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 {