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/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/Activity.php b/src/WPStrava/Activity.php index e936779..9623874 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::ACTIVITIES_URL . $activity_id ); + $title_attr = $title ? " title='" . esc_attr( $title ) . "'" : ''; + return "{$text}"; + } } 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 } } } 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() { ?> - + +

    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 ""; } /** 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 ); + } } 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__ ) );