From 7fc803ccacb0cc9796120829976dd0b0dc8732fc Mon Sep 17 00:00:00 2001 From: Justin Foell <630830+jrfoell@users.noreply.github.com> Date: Fri, 26 Jun 2020 14:17:54 -0500 Subject: [PATCH 1/7] Add no_link setting --- src/WPStrava/Settings.php | 48 ++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/WPStrava/Settings.php b/src/WPStrava/Settings.php index fcb0eb1..247650f 100644 --- a/src/WPStrava/Settings.php +++ b/src/WPStrava/Settings.php @@ -93,14 +93,18 @@ class WPStrava_Settings { // Hide Options. register_setting( $this->option_page, 'strava_hide_time', array( $this, 'sanitize_hide_time' ) ); - add_settings_field( 'strava_hide_time', __( 'Hide Activity Time', 'wp-strava' ), array( $this, 'print_hide_time_input' ), 'wp-strava', 'strava_options' ); + add_settings_field( 'strava_hide_time', __( 'Time', 'wp-strava' ), array( $this, 'print_hide_time_input' ), 'wp-strava', 'strava_options' ); register_setting( $this->option_page, 'strava_hide_elevation', array( $this, 'sanitize_hide_elevation' ) ); - add_settings_field( 'strava_hide_elevation', __( 'Hide Activity Elevation', 'wp-strava' ), array( $this, 'print_hide_elevation_input' ), 'wp-strava', 'strava_options' ); + add_settings_field( 'strava_hide_elevation', __( 'Elevation', 'wp-strava' ), array( $this, 'print_hide_elevation_input' ), 'wp-strava', 'strava_options' ); + + // No Activity Links. + register_setting( $this->option_page, 'strava_no_link', array( $this, 'sanitize_no_link' ) ); + add_settings_field( 'strava_no_link', __( 'Links', 'wp-strava' ), array( $this, 'print_no_link_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' ); + add_settings_field( 'strava_cache_clear', __( 'Clear cache', 'wp-strava' ), array( $this, 'print_clear_input' ), 'wp-strava', 'strava_cache' ); } /** @@ -398,7 +402,8 @@ class WPStrava_Settings { */ public function print_hide_time_input() { ?> - hide_time, 'on' ); ?>/> + - hide_elevation, 'on' ); ?>/> + + * @since 2.3.2 + */ + public function print_no_link_input() { + ?> + + + * @since 2.3.2 + */ + public function sanitize_no_link( $checked ) { + if ( 'on' === $checked ) { + return $checked; + } + return null; + } + /** * Print checkbox option to clear cache. * @@ -452,7 +486,9 @@ class WPStrava_Settings { */ public function print_clear_input() { ?> - + +

Date: Fri, 26 Jun 2020 14:18:12 -0500 Subject: [PATCH 2/7] Add optional title param to image tag --- src/WPStrava/StaticMap.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/WPStrava/StaticMap.php b/src/WPStrava/StaticMap.php index bd3b441..3c12850 100644 --- a/src/WPStrava/StaticMap.php +++ b/src/WPStrava/StaticMap.php @@ -13,9 +13,10 @@ class WPStrava_StaticMap { * @param int $height Height of map in pixels. * @param int $width Width of map in pixels. * @param bool $markers Display start and finish markers. + * @param string $title Title attribute to accompany image (default empty). * @return string HTML img tag with static map image. */ - public static function get_image_tag( $activity, $height = 320, $width = 480, $markers = false, $link = true ) { + public static function get_image_tag( $activity, $height = 320, $width = 480, $markers = false, $title = '' ) { $key = WPStrava::get_instance()->settings->gmaps_key; // Short circuit if missing key or activity object doesn't have the data we need. @@ -42,7 +43,8 @@ class WPStrava_StaticMap { $url .= $markers; } - return ""; + $title_attr = $title ? " title='" . esc_attr( $title ) . "'" : ''; + return ""; } /** From 8244602957d47ea57dc6fd05bbb12d1ad189eea5 Mon Sep 17 00:00:00 2001 From: Justin Foell <630830+jrfoell@users.noreply.github.com> Date: Fri, 26 Jun 2020 14:19:40 -0500 Subject: [PATCH 3/7] Add new get_activity_link() method --- src/WPStrava/Activity.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/WPStrava/Activity.php b/src/WPStrava/Activity.php index e936779..c0d4db9 100755 --- a/src/WPStrava/Activity.php +++ b/src/WPStrava/Activity.php @@ -97,4 +97,23 @@ class WPStrava_Activity { return $long_activities; } + + /** + * Conditionally display a link based on settings. + * + * @param int $activity_id Strava Activity ID + * @param string $text Text (or HTML) that is the content of link. + * @param string $title Title attribute (default empty). + * @return void + * @author Justin Foell + * @since 2.3.2 + */ + public function get_activity_link( $activity_id, $text, $title = '' ) { + if ( WPStrava::get_instance()->settings->no_link ) { + return $text; + } + $url = esc_url( self::ATHLETES_URL . $activity_id ); + $title_attr = $title ? " title='" . esc_attr( $title ) . "'" : ''; + return "{$text}"; + } } From 0df78b8568248845aeaa78972b041b226268fa6c Mon Sep 17 00:00:00 2001 From: Justin Foell <630830+jrfoell@users.noreply.github.com> Date: Fri, 26 Jun 2020 14:20:55 -0500 Subject: [PATCH 4/7] Use new get_activity_link method --- src/WPStrava/ActivitiesList.php | 3 +-- src/WPStrava/ActivityRenderer.php | 11 +++++++---- src/WPStrava/LatestMap.php | 10 +++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/WPStrava/ActivitiesList.php b/src/WPStrava/ActivitiesList.php index 6193ab1..0cdd42c 100644 --- a/src/WPStrava/ActivitiesList.php +++ b/src/WPStrava/ActivitiesList.php @@ -42,8 +42,7 @@ class WPStrava_ActivitiesList { foreach ( $activities as $activity ) { $response .= "
  • "; $response .= empty( $activity->id ) ? - $activity->name : - "" . $activity->name . ''; + $activity->name : $strava_activity->get_activity_link( $activity->id, $activity->name ); $response .= "
    "; if ( ! empty( $activity->start_date_local ) ) { diff --git a/src/WPStrava/ActivityRenderer.php b/src/WPStrava/ActivityRenderer.php index 8a356b5..a286606 100644 --- a/src/WPStrava/ActivityRenderer.php +++ b/src/WPStrava/ActivityRenderer.php @@ -53,10 +53,13 @@ class WPStrava_ActivityRenderer { $map_width = str_replace( 'px', '', $map_width ); $map_height = str_replace( 'px', '', $map_height ); - $activity_output .= '' . - WPStrava_StaticMap::get_image_tag( $activity_details, $map_height, $map_width, $atts['markers'] ) . - ' -
    '; + $activity_output .= $activity->get_activity_link( + $activity_details->id, + WPStrava_StaticMap::get_image_tag( $activity_details, $map_height, $map_width, $atts['markers'], $activity_details->name ), + $activity_details->name + ); + + $activity_output .= ''; } // End if( $activity_details ). return $activity_output; } diff --git a/src/WPStrava/LatestMap.php b/src/WPStrava/LatestMap.php index 29866cd..67edac4 100644 --- a/src/WPStrava/LatestMap.php +++ b/src/WPStrava/LatestMap.php @@ -38,9 +38,13 @@ class WPStrava_LatestMap { echo empty( $activity->map ) ? // Translators: Text with activity name shown in place of image if not available. esc_html( sprintf( __( 'Map not available for activity "%s"', 'wp-strava' ), $activity->name ) ) : - "" . - WPStrava_StaticMap::get_image_tag( $activity ) . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Image OK. - ''; + // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Image OK. + $strava_activity->get_activity_link( + $activity->id, + WPStrava_StaticMap::get_image_tag( $activity, null, null, false, $activity->name ), + $activity->name + ); + // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped } } } From a440a74ffcec626fcdca8d6f6c80b209ac15240d Mon Sep 17 00:00:00 2001 From: Justin Foell <630830+jrfoell@users.noreply.github.com> Date: Fri, 26 Jun 2020 14:54:17 -0500 Subject: [PATCH 5/7] Upped version # --- readme.txt | 3 +++ wp-strava.php | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/readme.txt b/readme.txt index 1cd1ca2..d6ca340 100755 --- a/readme.txt +++ b/readme.txt @@ -116,6 +116,9 @@ On the WP-Strava settings page you cannot currently remove and add another athle == Changelog == += 2.3.2 = +Added support to not link to activities. + = 2.3.1 = Added Image Only and Display Markers toggles to Activity Block. diff --git a/wp-strava.php b/wp-strava.php index 9d63413..3d95fc4 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: Show your strava.com activity on your WordPress site. Some Icons are Copyright © Yusuke Kamiyamane. All rights reserved. Licensed under a Creative Commons Attribution 3.0 license. - * Version: 2.3.1 + * Version: 2.3.2 * Author: Carlos Santa Cruz, Justin Foell, Lance Willett, Daniel Lintott, Sebastian Erb * License: GPL2 * Text Domain: wp-strava @@ -27,7 +27,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -define( 'WPSTRAVA_PLUGIN_VERSION', '2.3.1' ); +define( 'WPSTRAVA_PLUGIN_VERSION', '2.3.2' ); define( 'WPSTRAVA_PLUGIN_FILE', __FILE__ ); define( 'WPSTRAVA_PLUGIN_DIR', trailingslashit( dirname( __FILE__ ) ) ); define( 'WPSTRAVA_PLUGIN_URL', plugins_url( '/', __FILE__ ) ); From ffd7762f436cb8a4508b2d15c60f9ed4b4594e1e Mon Sep 17 00:00:00 2001 From: Justin Foell <630830+jrfoell@users.noreply.github.com> Date: Fri, 26 Jun 2020 14:54:30 -0500 Subject: [PATCH 6/7] Fixed base URL --- src/WPStrava/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WPStrava/Activity.php b/src/WPStrava/Activity.php index c0d4db9..9623874 100755 --- a/src/WPStrava/Activity.php +++ b/src/WPStrava/Activity.php @@ -112,7 +112,7 @@ class WPStrava_Activity { if ( WPStrava::get_instance()->settings->no_link ) { return $text; } - $url = esc_url( self::ATHLETES_URL . $activity_id ); + $url = esc_url( self::ACTIVITIES_URL . $activity_id ); $title_attr = $title ? " title='" . esc_attr( $title ) . "'" : ''; return "{$text}"; } From f119ccf360633a6a7e41b17cc9d9a30ffbc54509 Mon Sep 17 00:00:00 2001 From: Justin Foell <630830+jrfoell@users.noreply.github.com> Date: Fri, 26 Jun 2020 14:54:44 -0500 Subject: [PATCH 7/7] Added activity link tests --- tests/WPStrava/ActivityTest.php | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/WPStrava/ActivityTest.php b/tests/WPStrava/ActivityTest.php index 0378568..5a8e0b8 100644 --- a/tests/WPStrava/ActivityTest.php +++ b/tests/WPStrava/ActivityTest.php @@ -54,4 +54,58 @@ class WPStrava_ActivityTest extends TestCase { $actual = $this->activity->get_activities_longer_than( $this->activities, '10' ); $this->assertEquals( $expected, $actual ); } + + /** + * Test that links with a title are rendered correctly. + * + * @author Justin Foell + * @since 2.3.2 + */ + public function test_activity_link_with_title() { + $activity_name = 'Chill Day'; + $activity_id = 123456778928065; + + $expected = "{$activity_name}"; + $actual = $this->activity->get_activity_link( $activity_id, $activity_name, $activity_name ); + + $this->assertEquals( $expected, $actual ); + } + + /** + * Test that links with no title are rendered correctly. + * + * @author Justin Foell + * @since 2.3.2 + */ + public function test_activity_link_no_title() { + $activity_name = 'Chill Day'; + $activity_id = 123456778928065; + + $expected = "{$activity_name}"; + $actual = $this->activity->get_activity_link( $activity_id, $activity_name ); + + $this->assertEquals( $expected, $actual ); + } + + /** + * Test that links with no_link set just render the supplied text. + * + * @author Justin Foell + * @since 2.3.2 + */ + public function test_activity_no_link() { + \WP_Mock::userFunction( + 'get_option', + array( + 'args' => 'strava_no_link', + 'times' => 1, + 'return' => true, + ) + ); + + $activity_name = 'Afternoon Ride'; + $actual = $this->activity->get_activity_link( 123456778928065, 'Afternoon Ride' ); + + $this->assertEquals( $activity_name, $actual ); + } }