From d37286fce711cd0c12b017dcc8440929b461af72 Mon Sep 17 00:00:00 2001 From: Justin Foell Date: Fri, 26 Jan 2018 16:11:34 -0600 Subject: [PATCH] Better club ID support --- lib/LatestActivities.class.php | 2 +- lib/LatestMapWidget.class.php | 62 ++++++++++++++-------------------- lib/Settings.class.php | 14 +++----- readme.txt | 5 +++ wp-strava.php | 2 +- 5 files changed, 37 insertions(+), 48 deletions(-) diff --git a/lib/LatestActivities.class.php b/lib/LatestActivities.class.php index c3d4336..83972d1 100644 --- a/lib/LatestActivities.class.php +++ b/lib/LatestActivities.class.php @@ -30,7 +30,7 @@ class WPStava_LatestActivities { $response .= sprintf( __( 'On %1$s %2$s', 'wp-strava' ), date_i18n( get_option( 'date_format' ), $unixtime ), date_i18n( get_option( 'time_format' ), $unixtime ) ); if ( is_numeric( $args['strava_club_id'] ) ) { - $response .= " " . $activity->athlete_name . ''; + $response .= " " . $activity->athlete->firstname . ' ' . $activity->athlete->lastname . ''; } // Translators: "went 10 miles" diff --git a/lib/LatestMapWidget.class.php b/lib/LatestMapWidget.class.php index 48d8e1e..de29776 100644 --- a/lib/LatestMapWidget.class.php +++ b/lib/LatestMapWidget.class.php @@ -70,9 +70,11 @@ class WPStrava_LatestMapWidget extends WP_Widget { $strava_club_id = empty( $instance['strava_club_id'] ) ? null : $instance['strava_club_id']; $build_new = false; + $id = empty( $strava_club_id ) ? $athlete_token : $strava_club_id; + // Try our transient first. - $activity_transient = get_transient( 'strava_latest_map_activity_' . $athlete_token ); - $activity_option = get_option( 'strava_latest_map_activity_' . $athlete_token ); + $activity_transient = get_transient( 'strava_latest_map_activity_' . $id ); + $activity_option = get_option( 'strava_latest_map_activity_' . $id ); $activity = $activity_transient ? $activity_transient : null; @@ -109,12 +111,12 @@ class WPStrava_LatestMapWidget extends WP_Widget { // If the option isn't set or the transient is different, update the option. if ( empty( $activity_option->id ) || $activity->id != $activity_option->id ) { $build_new = true; - $this->update_activity( $athlete_token, $activity ); + $this->update_activity( $id, $activity ); } // Update the transient if it needs updating. if ( empty( $activity_transient->id ) || $activity->id != $activity_transient->id ) { - $this->update_activity_transient( $athlete_token, $activity ); + $this->update_activity_transient( $id, $activity ); } } } @@ -126,7 +128,7 @@ class WPStrava_LatestMapWidget extends WP_Widget { } echo ""; - echo $this->get_static_image( $athlete_token, $activity, $build_new ); + echo $this->get_static_image( $id, $activity, $build_new ); echo ''; echo $args['after_widget']; } @@ -137,17 +139,17 @@ class WPStrava_LatestMapWidget extends WP_Widget { * * @author Justin Foell * - * @param string $athlete_token Token for athelete. - * @param object $activity Activity to get image for. - * @param boolean $build_new Whether to refresh the image from cache. - * @return string Image tag. + * @param string $id Athlete Token or Club ID. + * @param object $activity Activity to get image for. + * @param boolean $build_new Whether to refresh the image from cache. + * @return string Image tag. */ - private function get_static_image( $athlete_token, $activity, $build_new ) { - $img = get_option( 'strava_latest_map_' . $athlete_token ); + private function get_static_image( $id, $activity, $build_new ) { + $img = get_option( 'strava_latest_map_' . $id ); if ( $build_new || ! $img ) { $img = WPStrava_StaticMap::get_image_tag( $activity ); - $this->update_map( $athlete_token, $img ); + $this->update_map( $id, $img ); } return $img; @@ -159,15 +161,11 @@ class WPStrava_LatestMapWidget extends WP_Widget { * @author Justin Foell * @since 1.2.0 * - * @param string $athlete_token Token for athelete. - * @param string $img Image tag. + * @param string $id Athlete Token or Club ID. + * @param string $img Image tag. */ - private function update_map( $athlete_token, $img ) { - // Remove old (pre 1.2.0) cached maps. - if ( get_option( 'strava_latest_map' ) ) { - delete_option( 'strava_latest_map' ); - } - update_option( 'strava_latest_map_' . $athlete_token, $img ); + private function update_map( $id, $img ) { + update_option( 'strava_latest_map_' . $id, $img ); } /** @@ -176,15 +174,11 @@ class WPStrava_LatestMapWidget extends WP_Widget { * @author Justin Foell * @since 1.2.0 * - * @param string $athlete_token Token for athelete. - * @param object $activity stdClass Strava activity object. + * @param string $id Athlete Token or Club ID. + * @param object $activity stdClass Strava activity object. */ - private function update_activity( $athlete_token, $activity ) { - // Remove old (pre 1.2.0) option. - if ( get_option( 'strava_latest_map_ride' ) ) { - delete_option( 'strava_latest_map_ride' ); - } - update_option( 'strava_latest_map_activity_' . $athlete_token, $activity ); + private function update_activity( $id, $activity ) { + update_option( 'strava_latest_map_activity_' . $id, $activity ); } /** @@ -193,14 +187,10 @@ class WPStrava_LatestMapWidget extends WP_Widget { * @author Justin Foell * @since 1.2.0 * - * @param string $athlete_token Token for athelete. - * @param object $activity stdClass Strava activity object. + * @param string $id Athlete Token or Club ID. + * @param object $activity stdClass Strava activity object. */ - private function update_activity_transient( $athlete_token, $activity ) { - // Remove old (pre 1.2.0) transient. - if ( get_transient( 'strava_latest_map_ride' ) ) { - delete_transient( 'strava_latest_map_ride' ); - } - set_transient( 'strava_latest_map_activity_' . $athlete_token, $activity, HOUR_IN_SECONDS ); + private function update_activity_transient( $id, $activity ) { + set_transient( 'strava_latest_map_activity_' . $id, $activity, HOUR_IN_SECONDS ); } } diff --git a/lib/Settings.class.php b/lib/Settings.class.php index 602141f..190e23a 100644 --- a/lib/Settings.class.php +++ b/lib/Settings.class.php @@ -349,17 +349,11 @@ class WPStrava_Settings { public function sanitize_cache_clear( $checked ) { if ( 'on' === $checked ) { - // Clear these (pre 1.2.0) values: - delete_transient( 'strava_latest_map_ride' ); - delete_option( 'strava_latest_map_ride' ); - delete_option( 'strava_latest_map' ); + global $wpdb; - // Remove activity transients and options. - foreach ( $this->get_tokens() as $token ) { - delete_transient( 'strava_latest_map_activity_' . $token ); - delete_option( 'strava_latest_map_activity_' . $token ); - delete_option( 'strava_latest_map_' . $token ); - } + $wpdb->query( "DELETE FROM {$wpdb->options} WHERE `option_name` LIKE '_transient_timeout_strava_latest_map_%'" ); + $wpdb->query( "DELETE FROM {$wpdb->options} WHERE `option_name` LIKE '_transient_strava_latest_map_%'" ); + $wpdb->query( "DELETE FROM {$wpdb->options} WHERE `option_name` LIKE 'strava_latest_map%'" ); } return null; } diff --git a/readme.txt b/readme.txt index 3cc546c..5038e10 100755 --- a/readme.txt +++ b/readme.txt @@ -74,6 +74,11 @@ If your key works with other Google Maps plugins but not WP Strava, you may need == Changelog == += 1.4.2 = + +Better Club ID support. +Refined cache clearing to include club IDs. + = 1.4.1 = Fix array indices on map widget diff --git a/wp-strava.php b/wp-strava.php index 4c94510..1e3dd9a 100755 --- a/wp-strava.php +++ b/wp-strava.php @@ -3,7 +3,7 @@ * Plugin Name: WP Strava * Plugin URI: https://wordpress.org/plugins/wp-strava/ * 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.4.1 + * Version: 1.4.2-rc1 * Author: Carlos Santa Cruz, Justin Foell, Lance Willet, Daniel Lintott * License: GPL2 * Text Domain: wp-strava