mirror of
https://github.com/10h30/wp-strava.git
synced 2026-07-13 11:46:41 +09:00
Formatting, added target="_blank" to widget hrefs
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
|
||||
$response = "<ul id='rides'>";
|
||||
foreach( $rides as $ride ) {
|
||||
$response .= "<li class='ride'>";
|
||||
$response .= "<a href='" . WPStrava_Rides::RIDES_URL . $ride->id . "' >" . $ride->name . "</a>";
|
||||
$response .= "<a href='" . WPStrava_Rides::RIDES_URL . $ride->id . "' target='_blank'>" . $ride->name . "</a>";
|
||||
$response .= "<div class='ride-item'>";
|
||||
$unixtime = strtotime( $ride->start_date_local );
|
||||
$response .= sprintf( __("On %s %s", "wp-strava"), date_i18n( get_option( 'date_format' ), $unixtime ), date_i18n( get_option( 'time_format' ), $unixtime ) );
|
||||
|
||||
+3
-3
@@ -11,9 +11,9 @@ abstract class WPStrava_SOM {
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMMetric.class.php';
|
||||
return new WPStrava_SOMMetric();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
abstract public function distance( $m );
|
||||
abstract public function distance_inverse( $dist );
|
||||
abstract public function get_distance_label();
|
||||
@@ -29,4 +29,4 @@ abstract class WPStrava_SOM {
|
||||
public function get_time_label() {
|
||||
return __( 'hours', 'wp-strava' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-12
@@ -9,11 +9,11 @@ require_once WPSTRAVA_PLUGIN_DIR . 'lib/StaticMap.class.php';
|
||||
|
||||
class WPStrava {
|
||||
|
||||
private static $instance = NULL;
|
||||
private $settings = NULL;
|
||||
private $api = NULL;
|
||||
private $rides = NULL;
|
||||
|
||||
private static $instance = null;
|
||||
private $settings = null;
|
||||
private $api = null;
|
||||
private $rides = null;
|
||||
|
||||
private function __construct() {
|
||||
$this->settings = new WPStrava_Settings();
|
||||
|
||||
@@ -24,8 +24,8 @@ class WPStrava {
|
||||
}
|
||||
|
||||
// Register StravaLatestRidesWidget widget
|
||||
add_action( 'widgets_init', create_function('', 'return register_widget( "WPStrava_LatestRidesWidget" );') );
|
||||
add_action( 'widgets_init', create_function('', 'return register_widget( "WPStrava_LatestMapWidget" );' ) );
|
||||
add_action( 'widgets_init', create_function( '', 'return register_widget( "WPStrava_LatestRidesWidget" );' ) );
|
||||
add_action( 'widgets_init', create_function( '', 'return register_widget( "WPStrava_LatestMapWidget" );' ) );
|
||||
}
|
||||
|
||||
public static function get_instance() {
|
||||
@@ -38,16 +38,19 @@ class WPStrava {
|
||||
|
||||
public function __get( $name ) {
|
||||
//on-demand classes
|
||||
if ( $name == 'api' )
|
||||
if ( $name == 'api' ) {
|
||||
return $this->get_api();
|
||||
}
|
||||
|
||||
if ( $name == 'rides' )
|
||||
if ( $name == 'rides' ) {
|
||||
return $this->get_rides();
|
||||
}
|
||||
|
||||
if ( isset( $this->{$name} ) )
|
||||
if ( isset( $this->{$name} ) ) {
|
||||
return $this->{$name};
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_api() {
|
||||
@@ -58,7 +61,7 @@ class WPStrava {
|
||||
|
||||
return $this->api;
|
||||
}
|
||||
|
||||
|
||||
public function get_rides() {
|
||||
if ( ! $this->rides ) {
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/Rides.class.php';
|
||||
|
||||
Reference in New Issue
Block a user