Formatting, added target="_blank" to widget hrefs

This commit is contained in:
Justin Foell
2017-05-10 13:52:49 -05:00
parent d9399b14af
commit f165d9a4d5
4 changed files with 36 additions and 34 deletions
+17 -18
View File
@@ -3,17 +3,17 @@
class WPStrava_LatestMapWidget extends WP_Widget {
private $som;
public function __construct() {
$this->som = WPStrava_SOM::get_som();
parent::__construct(
false,
'Strava Latest Map', // Name
array( 'description' => __( 'Strava latest ride using static google map image', 'wp-strava' ), ) // Args
);
}
public function form( $instance ) {
// outputs the options form on admin
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : __( 'Latest Activity', 'wp-strava' );
@@ -21,7 +21,7 @@ class WPStrava_LatestMapWidget extends WP_Widget {
$strava_club_id = isset( $instance['strava_club_id'] ) ? esc_attr( $instance['strava_club_id'] ) : '';
//provide some defaults
//$ride_index_params = $ride_index_params ? $ride_index_params : 'athleteId=21';
//$ride_index_params = $ride_index_params ?: 'athleteId=21';
?>
<p>
@@ -36,9 +36,9 @@ class WPStrava_LatestMapWidget extends WP_Widget {
<label for="<?php echo $this->get_field_id('strava_club_id'); ?>"><?php _e('Club ID (leave blank to show Athlete):'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('strava_club_id'); ?>" name="<?php echo $this->get_field_name('strava_club_id'); ?>" type="text" value="<?php echo $strava_club_id; ?>" />
</p>
<?php
<?php
}
public function update( $new_instance, $old_instance ) {
// processes widget options to be saved from the admin
$instance = $old_instance;
@@ -50,18 +50,17 @@ class WPStrava_LatestMapWidget extends WP_Widget {
public function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Latest Activity', 'wp-strava' ) : $instance['title'] );
$distance_min = $instance['distance_min'];
$strava_club_id = empty( $instance['strava_club_id'] ) ? NULL : $instance['strava_club_id'];
$build_new = false;
//try our transient first
$ride_transient = get_transient( 'strava_latest_map_ride' );
$ride_option = get_option( 'strava_latest_map_ride' );
if ( $ride_transient )
$ride = $ride_transient;
$ride = $ride_transient ?: null;
if ( ! $ride ) {
$strava_rides = WPStrava::get_instance()->rides;
@@ -81,7 +80,7 @@ class WPStrava_LatestMapWidget extends WP_Widget {
}
if ( ! empty( $rides ) ) {
if ( ! empty( $distance_min ) )
$rides = $strava_rides->getRidesLongerThan( $rides, $distance_min );
@@ -93,25 +92,26 @@ class WPStrava_LatestMapWidget extends WP_Widget {
update_option( 'strava_latest_map_ride', $ride );
}
if ( $ride->id != $ride_transient->id )
set_transient( 'strava_latest_map_ride', $ride, 60 * 60 ); //one hour
if ( $ride->id != $ride_transient->id ) {
set_transient( 'strava_latest_map_ride', $ride, HOUR_IN_SECONDS );
}
}
}
if ( $ride ):
if ( $ride ) {
echo $before_widget;
if ( $title ) echo $before_title . $title . $after_title;
?><a title="<?php echo $ride->name ?>" href="http://app.strava.com/activities/<?php echo $ride->id ?>"><?php
?><a title="<?php echo $ride->name ?>" target="_blank" href="http://app.strava.com/activities/<?php echo $ride->id ?>"><?php
echo $this->getStaticImage( $ride->id, $build_new );
?></a><?php
echo $after_widget;
endif;
}
}
private function getStaticImage( $ride_id, $build_new ) {
$img = get_option( 'strava_latest_map' );
if ( $build_new || ! $img ) {
$ride = WPStrava::get_instance()->rides->getRide( $ride_id );
$img = WPStrava_StaticMap::get_image_tag( $ride );
@@ -120,5 +120,4 @@ class WPStrava_LatestMapWidget extends WP_Widget {
return $img;
}
}