mirror of
https://github.com/10h30/wp-strava.git
synced 2026-07-11 18:56:18 +09:00
Merge pull request #52 from cmanon/feature/51-no-link-setting
Feature/51 no link setting
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -42,8 +42,7 @@ class WPStrava_ActivitiesList {
|
||||
foreach ( $activities as $activity ) {
|
||||
$response .= "<li class='activity'>";
|
||||
$response .= empty( $activity->id ) ?
|
||||
$activity->name :
|
||||
"<a href='" . WPStrava_Activity::ACTIVITIES_URL . $activity->id . "'>" . $activity->name . '</a>';
|
||||
$activity->name : $strava_activity->get_activity_link( $activity->id, $activity->name );
|
||||
$response .= "<div class='activity-item'>";
|
||||
|
||||
if ( ! empty( $activity->start_date_local ) ) {
|
||||
|
||||
@@ -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 <justin@foell.org>
|
||||
* @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 "<a href='{$url}'{$title_attr}>{$text}</a>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,10 +53,13 @@ class WPStrava_ActivityRenderer {
|
||||
$map_width = str_replace( 'px', '', $map_width );
|
||||
$map_height = str_replace( 'px', '', $map_height );
|
||||
|
||||
$activity_output .= '<a title="' . $activity_details->name . '" href="' . WPStrava_Activity::ACTIVITIES_URL . $activity_details->id . '">' .
|
||||
WPStrava_StaticMap::get_image_tag( $activity_details, $map_height, $map_width, $atts['markers'] ) .
|
||||
'</a>
|
||||
</div>';
|
||||
$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 .= '</div>';
|
||||
} // End if( $activity_details ).
|
||||
return $activity_output;
|
||||
}
|
||||
|
||||
@@ -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 ) ) :
|
||||
"<a title='" . esc_attr( $activity->name ) . "' href='" . esc_attr( WPStrava_Activity::ACTIVITIES_URL . $activity->id ) . "'>" .
|
||||
WPStrava_StaticMap::get_image_tag( $activity ) . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Image OK.
|
||||
'</a>';
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
?>
|
||||
<input type="checkbox" id="strava_hide_time" name="strava_hide_time" <?php checked( $this->hide_time, 'on' ); ?>/>
|
||||
<label for="strava_hide_time"><input type="checkbox" id="strava_hide_time" name="strava_hide_time" <?php checked( $this->hide_time, 'on' ); ?>/>
|
||||
<?php _e( 'Do not show time on activities', 'wp-strava' ); ?></label>
|
||||
<?php
|
||||
}
|
||||
|
||||
@@ -425,7 +430,8 @@ class WPStrava_Settings {
|
||||
*/
|
||||
public function print_hide_elevation_input() {
|
||||
?>
|
||||
<input type="checkbox" id="strava_hide_elevation" name="strava_hide_elevation" <?php checked( $this->hide_elevation, 'on' ); ?>/>
|
||||
<label for="strava_hide_elevation"><input type="checkbox" id="strava_hide_elevation" name="strava_hide_elevation" <?php checked( $this->hide_elevation, 'on' ); ?>/>
|
||||
<?php _e( 'Do not show elevation on activities', 'wp-strava' ); ?></label>
|
||||
<?php
|
||||
}
|
||||
|
||||
@@ -444,6 +450,34 @@ class WPStrava_Settings {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the No Links Checkbox.
|
||||
*
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @since 2.3.2
|
||||
*/
|
||||
public function print_no_link_input() {
|
||||
?>
|
||||
<label for="strava_no_link"><input type="checkbox" id="strava_no_link" name="strava_no_link" <?php checked( $this->no_link, 'on' ); ?>/>
|
||||
<?php _e( 'Do not link activities to Strava.com', 'wp-strava' ); ?></label>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the No Links Checkbox.
|
||||
*
|
||||
* @param string $checked 'on' or null.
|
||||
* @return string 'on' if checked.
|
||||
* @author Justin Foell <justin@foell.org>
|
||||
* @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() {
|
||||
?>
|
||||
<input type="checkbox" id="strava_cache_clear" name="strava_cache_clear" />
|
||||
<label for="strava_cache_clear"><input type="checkbox" id="strava_cache_clear" name="strava_cache_clear" />
|
||||
<?php _e( 'Clear cached image and transient data', 'wp-strava' ); ?></label>
|
||||
<p class="description"><?php _e( 'To clear cache, check this box and click "Save Changes"' ); ?></p>
|
||||
<?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 "<img class='wp-strava-img' src='{$url}' />";
|
||||
$title_attr = $title ? " title='" . esc_attr( $title ) . "'" : '';
|
||||
return "<img class='wp-strava-img' src='{$url}'{$title_attr} />";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 <justin@foell.org>
|
||||
* @since 2.3.2
|
||||
*/
|
||||
public function test_activity_link_with_title() {
|
||||
$activity_name = 'Chill Day';
|
||||
$activity_id = 123456778928065;
|
||||
|
||||
$expected = "<a href='" . WPStrava_Activity::ACTIVITIES_URL . $activity_id . "' title='{$activity_name}'>{$activity_name}</a>";
|
||||
$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 <justin@foell.org>
|
||||
* @since 2.3.2
|
||||
*/
|
||||
public function test_activity_link_no_title() {
|
||||
$activity_name = 'Chill Day';
|
||||
$activity_id = 123456778928065;
|
||||
|
||||
$expected = "<a href='" . WPStrava_Activity::ACTIVITIES_URL . $activity_id . "'>{$activity_name}</a>";
|
||||
$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 <justin@foell.org>
|
||||
* @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 );
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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__ ) );
|
||||
|
||||
Reference in New Issue
Block a user