2019-11-01 12:57:40 -05:00
< ? php
2020-12-24 11:11:24 -06:00
/**
* LatestMap class
*
* @since 2.1.0
*/
2019-11-01 12:57:40 -05:00
class WPStrava_LatestMap {
2020-12-24 11:11:24 -06:00
/**
* Returns Latest Map HTML.
*
* @param array $args
* @return string HTML with static map image.
* @author Justin Foell <justin@foell.org>
* @since 2.1.0
*/
2019-11-01 12:57:40 -05:00
public static function get_map_html ( $args ) {
$defaults = array (
'client_id' => WPStrava :: get_instance () -> settings -> get_default_id (),
'strava_club_id' => null ,
'distance_min' => 0 ,
);
$args = wp_parse_args ( $args , $defaults );
2019-11-01 15:34:05 -05:00
$strava_activity = WPStrava :: get_instance () -> activity ;
2019-11-01 12:57:40 -05:00
2019-11-01 15:34:05 -05:00
$activities = array ();
2019-11-01 12:57:40 -05:00
2019-11-01 15:34:05 -05:00
try {
2020-04-24 16:07:19 -05:00
$activities = $strava_activity -> get_activities ( $args );
2019-11-01 15:34:05 -05:00
} catch ( WPStrava_Exception $e ) {
// If athlete_token is still set, warn about that first and foremost.
if ( isset ( $args [ 'athlete_token' ] ) ) {
// Translators: Message shown when using deprecated athlete_token parameter.
echo wp_kses_post ( __ ( 'The <code>athlete_token</code> parameter is deprecated as of WP-Strava version 2 and should be replaced with <code>client_id</code>.' , 'wp-strava' ) );
} else {
echo $e -> to_html (); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Debug only.
2019-11-01 12:57:40 -05:00
}
2019-11-01 15:34:05 -05:00
}
2019-11-01 12:57:40 -05:00
2019-11-01 15:34:05 -05:00
if ( ! empty ( $activities ) ) {
2019-11-01 12:57:40 -05:00
2019-11-01 15:34:05 -05:00
if ( ! empty ( $args [ 'distance_min' ] ) ) {
$activities = $strava_activity -> get_activities_longer_than ( $activities , $args [ 'distance_min' ] );
2019-11-01 12:57:40 -05:00
}
2019-11-01 15:34:05 -05:00
$activity = current ( $activities );
2020-12-24 11:11:24 -06:00
return empty ( $activity -> map ) ?
2019-11-01 12:57:40 -05:00
// Translators: Text with activity name shown in place of image if not available.
2019-11-01 13:34:47 -05:00
esc_html ( sprintf ( __ ( 'Map not available for activity "%s"' , 'wp-strava' ), $activity -> name ) ) :
2020-06-26 14:20:55 -05:00
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Image OK.
$strava_activity -> get_activity_link (
$activity -> id ,
2021-11-26 16:36:39 -06:00
WPStrava_StaticMap :: get_map () -> get_image_tag ( $activity , null , null , false , $activity -> name ),
2020-06-26 14:20:55 -05:00
$activity -> name
);
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
2019-11-01 12:57:40 -05:00
}
}
}