From bbd2cc9e5874a5c040fd38b1349308672325ea3e Mon Sep 17 00:00:00 2001 From: Daniel Lintott Date: Sat, 16 Dec 2017 12:52:52 +0000 Subject: [PATCH] Add routes shortcode functionality --- lib/RouteShortcode.class.php | 76 ++++++++++++++++++++++++++++++++++++ lib/Routes.class.php | 20 ++++++++++ lib/Strava.class.php | 14 ++++++- readme.txt | 4 ++ 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 lib/RouteShortcode.class.php create mode 100644 lib/Routes.class.php diff --git a/lib/RouteShortcode.class.php b/lib/RouteShortcode.class.php new file mode 100644 index 0000000..b8a3399 --- /dev/null +++ b/lib/RouteShortcode.class.php @@ -0,0 +1,76 @@ + 0, + 'som' => WPStrava::get_instance()->settings->som, + 'map_width' => '480', + 'map_height' => '320', + 'athlete_token' => WPStrava::get_instance()->settings->get_default_token(), + ); + + extract( shortcode_atts( $defaults, $atts ) ); + + $strava_som = WPStrava_SOM::get_som( $som ); + $route = WPStrava::get_instance()->routes; + $route_details = $route->getRoute( $id ); + + //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 ( $route_details ) { + return ' +
+ + + + + + + + + + + + + + + + + + + + +
' . __( 'Est. Moving Time', 'wp-strava' ) . '' . __( 'Distance', 'wp-strava' ) . '' . __( 'Elevation Gain', 'wp-strava' ) . '
' . $strava_som->time( $route_details->estimated_moving_time ) . '' . $strava_som->distance( $route_details->distance ) . '' . $strava_som->elevation( $route_details->elevation_gain ) . '
' . $strava_som->get_time_label() . '' . $strava_som->get_distance_label() . '' . $strava_som->get_elevation_label() . '
' . + WPStrava_StaticMap::get_image_tag( $route_details, $map_height, $map_width ) . + '
'; + } // End if( $route_details ). + } // handler + + 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'); + } + } +} + +// Initialize short code +WPStrava_RouteShortcode::init(); diff --git a/lib/Routes.class.php b/lib/Routes.class.php new file mode 100644 index 0000000..fd2f664 --- /dev/null +++ b/lib/Routes.class.php @@ -0,0 +1,20 @@ +get_api()->get( "routes/{$route_id}" ); + } // getRouteDetails +} \ No newline at end of file diff --git a/lib/Strava.class.php b/lib/Strava.class.php index 375f751..79b1ff2 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/ActivityShortcode.class.php'; +require_once WPSTRAVA_PLUGIN_DIR . 'lib/RouteShortcode.class.php'; require_once WPSTRAVA_PLUGIN_DIR . 'lib/StaticMap.class.php'; class WPStrava { @@ -13,6 +14,7 @@ class WPStrava { 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(); @@ -40,7 +42,9 @@ class WPStrava { // On-demand classes. if ( $name == 'rides' ) { return $this->get_rides(); - } + } elseif ( $name == 'routes' ) { + return $this->get_routes(); + } if ( isset( $this->{$name} ) ) { return $this->{$name}; @@ -71,6 +75,14 @@ class WPStrava { 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 register_scripts() { // Register a personalized stylesheet wp_register_style( 'wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' ); diff --git a/readme.txt b/readme.txt index 9b553a5..72dfbf7 100755 --- a/readme.txt +++ b/readme.txt @@ -25,6 +25,10 @@ Also takes the following optional parameters: [ride] is an alias for [activity] and will accept the same parameters (kept for backwards compatibility). +[route id=NUMBER] - add to any page or post. Shows a summary of the activity plus a map if a google maps key has been added. + +This also takes the same optional parameters as the activity shortcode above. + = Widgets = Strava Latest Activity List - shows a list of the last few activities.