' . __('Please include your strava email and password the password will not be stored.', 'wp-strava' ) . '
';
} else {
$ride = new Rides();
$token = $ride->getAuthenticationToken($email, $_POST['strava_password']);
if($token) {
update_option('strava_token', $token);
echo '' . $ride->feedback . __('Token saved.', 'wp-strava' ) . '
';
} else {
echo '';
}
}
}
?>
'LatestRidesWidget', 'description' => __( 'Will publish your latest rides activity from strava.com.') );
parent::__construct('wp-strava', $name = 'Strava Latest Rides', $widget_ops);
wp_enqueue_style('wp-strava');
}
/** @see WP_Widget::widget */
function widget($args, $instance) {
extract($args);
//$widget_id = $args['widget_id'];
$title = apply_filters('widget_title', empty($instance['title']) ? _e('Rides', 'wp-strava') : $instance['title']);
$strava_search_option = empty($instance['strava_search_option']) ? 'athlete' : $instance['strava_search_option'];
$strava_som_option = empty($instance['strava_som_option']) ? 'metric' : $instance['strava_som_option'];
$strava_search_id = empty($instance['strava_search_id']) ? '' : $instance['strava_search_id'];
$quantity = empty($instance['quantity']) ? '5' : $instance['quantity'];
?>
getLatestRides($strava_search_option, $strava_search_id, $quantity);
$rides_details = $strava_rides->getRidesDetails($strava_som_option);
if ($strava_som_option == "metric") {
$units = array(
'elapsedTime' => __('hours','wp-strava'),
'movingTime' => __('hours','wp-strava'),
'distance' => __('km','wp-strava'),
'averageSpeed' => __('km/h','wp-strava'),
'maximumSpeed' => __('km/h','wp-strava'),
'elevationGain' => __('meters','wp-strava')
);
} elseif ($strava_som_option == "english") {
$units = array(
'elapsedTime' => __('hours','wp-strava'),
'movingTime' => __('hours','wp-strava'),
'distance' => __('miles','wp-strava'),
'averageSpeed' => __('miles/h','wp-strava'),
'maximumSpeed' => __('miles/h','wp-strava'),
'elevationGain' => __('feet','wp-strava')
);
}
$response .= "";
foreach($rides_details as $ride) {
$response .= "- ";
$response .= "" . $ride['name'] . "";
$response .= "
";
$response .= __("On ", "wp-strava") . $ride['startDate'];
$response .= __(" rode ", "wp-strava") . $ride['distance'] . " " . $units['distance'];
$response .= __(" during ", "wp-strava") . $ride['elapsedTime'] . " " . $units['elapsedTime'];
$response .= __(" climbing ", "wp-strava") . $ride['elevationGain'] . " " . $units['elevationGain'] . ".";
$response .= "
";
$response .= " ";
}
$response .= "
";
}
return $response;
} // Function strava_request_handler
class RideShortcode {
static $add_script;
static function init() {
add_shortcode('ride', array(__CLASS__, 'handler'));
add_action('init', array(__CLASS__, 'registerScripts'));
add_action('wp_footer', array(__CLASS__, 'printScripts'));
}
// Shortcode handler function
// [ride id=id som=metric efforts=false threshold=5 map-width="100%" map-height="400px"] tag
function handler($atts) {
self::$add_script = true;
$token = get_option('strava_token');
if($token) {
$pairs = array(
'id' => 0,
'som' => "metric",
'efforts' => false,
'threshold' => 0,
'map_width' => "100%",
'map_height' => "400px"
);
extract(shortcode_atts($pairs, $atts));
if (isset($som)) {
$strava_som = $som;
} else {
$strava_som = get_option('strava_som_option', 'metric');
}
$ride = new Rides();
$rideDetails = $ride->getRideDetails($id, $strava_som);
$rideCoordinates = $ride->getRideMap($id, $token, $efforts, $threshold);
if ($strava_som == "metric") {
$units = array(
'elapsedTime' => __('hours','wp-strava'),
'movingTime' => __('hours','wp-strava'),
'distance' => __('km','wp-strava'),
'averageSpeed' => __('km/h','wp-strava'),
//'maximumSpeed' => __('km/h','wp-strava'),
'elevationGain' => __('meters','wp-strava')
);
} elseif ($strava_som == "english") {
$units = array(
'elapsedTime' => __('hours','wp-strava'),
'movingTime' => __('hours','wp-strava'),
'distance' => __('miles','wp-strava'),
'averageSpeed' => __('miles/h','wp-strava'),
//'maximumSpeed' => __('miles/h','wp-strava'),
'elevationGain' => __('feet','wp-strava')
);
}
if($rideCoordinates) {
return "
";
}
} else {
return _e('Please first get your strava token using the settings wp strava page.', 'wp-strava');
}
} // handler
static function registerScripts() {
wp_register_style('wp-strava-style', plugins_url('css/wp-strava.css', __FILE__));
wp_register_script('wp-strava-script', plugins_url('js/wp-strava.js', __FILE__), array('jquery'), '1.0', true);
wp_register_script('google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
}
static function printScripts() {
if (self::$add_script) {
wp_enqueue_style('wp-strava-style');
wp_enqueue_script('jquery');
wp_print_scripts('google-maps');
wp_print_scripts('wp-strava-script');
}
}
}
// Initialize short code
RideShortcode::init();
?>