mirror of
https://github.com/10h30/wp-strava.git
synced 2026-07-11 18:56:18 +09:00
Fixed broken references after moving things around a bit
This commit is contained in:
@@ -4,14 +4,15 @@
|
||||
* WP Strava Latest Rides Widget Class
|
||||
*/
|
||||
class WPStrava_LatestRidesWidget extends WP_Widget {
|
||||
function __construct() {
|
||||
|
||||
public function __construct() {
|
||||
$widget_ops = array('classname' => '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) {
|
||||
public function widget($args, $instance) {
|
||||
extract($args);
|
||||
|
||||
//$widget_id = $args['widget_id'];
|
||||
@@ -24,13 +25,13 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
|
||||
?>
|
||||
<?php echo $before_widget; ?>
|
||||
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
|
||||
<?php echo strava_request_handler($strava_search_option, $strava_search_id, $strava_som_option, $quantity); ?>
|
||||
<?php echo $this->strava_request_handler($strava_search_option, $strava_search_id, $strava_som_option, $quantity); ?>
|
||||
<?php echo $after_widget; ?>
|
||||
<?php
|
||||
}
|
||||
|
||||
/** @see WP_Widget::update */
|
||||
function update($new_instance, $old_instance) {
|
||||
public function update($new_instance, $old_instance) {
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
if(in_array($new_instance['strava_search_option'], array('athlete', 'club'))) {
|
||||
@@ -50,7 +51,7 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
|
||||
}
|
||||
|
||||
/** @see WP_Widget::form */
|
||||
function form($instance) {
|
||||
public function form($instance) {
|
||||
$title = isset($instance['title']) ? esc_attr($instance['title']) : _e('Rides', 'wp-strava');
|
||||
$strava_search_option = isset($instance['strava_search_option']) ? esc_attr($instance['strava_search_option']) : "athlete";
|
||||
$strava_som_option = isset($instance['strava_som_option']) ? esc_attr($instance['strava_som_option']) : "metric";
|
||||
@@ -62,6 +63,7 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
|
||||
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
|
||||
</p>
|
||||
<!-- TODO: make an 'advanced' option -->
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('strava_search_option'); ?>"><?php _e('Search Option:'); ?></label>
|
||||
<select class="widefat" id="<?php echo $this->get_field_id('strava_search_option'); ?>" name="<?php echo $this->get_field_name('strava_search_option'); ?>">
|
||||
@@ -86,5 +88,60 @@ class WPStrava_LatestRidesWidget extends WP_Widget {
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
// The handler to the ajax call, we will avoid this if Strava support jsonp request and we can do it
|
||||
// the parsing directly on the jQuery ajax call, the returned text will be enclosed in the $response variable.
|
||||
private function strava_request_handler( $strava_search_option, $strava_search_id, $strava_som_option, $quantity ) {
|
||||
$response = "";
|
||||
|
||||
//Check if the username is empty.
|
||||
if (empty($strava_search_id)) {
|
||||
$response .= __("Please configure the Strava search id on the widget options.", "wp-strava");
|
||||
} else {
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/Rides.class.php';
|
||||
$strava_rides = new WPStrava_Rides();
|
||||
$strava_rides->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 .= "<ul id='rides'>";
|
||||
foreach($rides_details as $ride) {
|
||||
$response .= "<li class='ride'>";
|
||||
$response .= "<a href='" . $strava_rides->ridesLinkUrl . $ride['id'] . "' >" . $ride['name'] . "</a>";
|
||||
$response .= "<div class='ride-item'>";
|
||||
$response .= __("On ", "wp-strava") . $ride['startDate'];
|
||||
if ($strava_search_option == "club") {
|
||||
$response .= " <a href='" . $strava_rides->athletesLinkUrl . $ride['athleteId'] . "'>" . $ride['athleteName'] . "</a>";
|
||||
}
|
||||
$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 .= "</div>";
|
||||
$response .= "</li>";
|
||||
}
|
||||
$response .= "</ul>";
|
||||
}
|
||||
return $response;
|
||||
} // Function strava_request_handler
|
||||
|
||||
} // class LatestRidesWidget
|
||||
|
||||
|
||||
+17
-17
@@ -4,32 +4,32 @@ class WPStrava_Settings {
|
||||
|
||||
//register admin menus
|
||||
public function hook() {
|
||||
add_action( 'admin_init', array( $this, 'registerStravaSettings' ) );
|
||||
add_action( 'admin_menu', array( $this, 'addStravaMenu' ) );
|
||||
add_action( 'admin_init', array( $this, 'register_strava_settings' ) );
|
||||
add_action( 'admin_menu', array( $this, 'add_strava_menu' ) );
|
||||
}
|
||||
|
||||
public function addStravaMenu() {
|
||||
public function add_strava_menu() {
|
||||
add_options_page( __( 'Strava Settings', 'wp-strava' ),
|
||||
__( 'Strava', 'wp-strava' ),
|
||||
'manage_options',
|
||||
'wp-strava-options',
|
||||
array( $this, 'printStravaOptions' ) );
|
||||
|
||||
array( $this, 'print_strava_options' ) );
|
||||
}
|
||||
|
||||
public function registerStravaSettings() {
|
||||
register_setting('wp-strava-settings-group','strava_email', array( $this, 'sanitizeEmail' ) );
|
||||
public function register_strava_settings() {
|
||||
register_setting('wp-strava-settings-group','strava_email', array( $this, 'sanitize_email' ) );
|
||||
register_setting('wp-strava-settings-group','strava_password', '__return_null' );
|
||||
register_setting('wp-strava-settings-group','strava_token', array( $this, 'sanitizeToken' ) );
|
||||
register_setting('wp-strava-settings-group','strava_token', array( $this, 'sanitize_token' ) );
|
||||
|
||||
add_settings_section( 'strava_api', NULL, '__return_null', 'wp-strava' ); //NULL / __return_null no section label needed
|
||||
add_settings_field( 'strava_email', 'Strava Email', array( $this, 'printEmailInput' ), 'wp-strava', 'strava_api' );
|
||||
add_settings_field( 'strava_password', 'Strava Password', array( $this, 'printPasswordInput' ), 'wp-strava', 'strava_api' );
|
||||
add_settings_field( 'strava_token', 'Strava Token', array( $this, 'printTokenInput' ), 'wp-strava', 'strava_api' );
|
||||
|
||||
add_settings_field( 'strava_email', __( 'Strava Email', 'wp-strava' ), array( $this, 'print_email_input' ), 'wp-strava', 'strava_api' );
|
||||
add_settings_field( 'strava_password', __( 'Strava Password', 'wp-strava' ), array( $this, 'print_password_input' ), 'wp-strava', 'strava_api' );
|
||||
add_settings_field( 'strava_token', __( 'Strava Token', 'wp-strava' ), array( $this, 'print_token_input' ), 'wp-strava', 'strava_api' );
|
||||
|
||||
}
|
||||
|
||||
public function printStravaOptions() {
|
||||
public function print_strava_options() {
|
||||
?>
|
||||
<div class="wrap">
|
||||
<div id="icon-options-general" class="icon32"><br/></div>
|
||||
@@ -48,29 +48,29 @@ class WPStrava_Settings {
|
||||
<?php
|
||||
}
|
||||
|
||||
public function printEmailInput() {
|
||||
public function print_email_input() {
|
||||
?><input type="text" id="strava_email" name="strava_email" value="<?php echo get_option('strava_email'); ?>" /><?php
|
||||
}
|
||||
|
||||
public function printPasswordInput() {
|
||||
public function print_password_input() {
|
||||
?>
|
||||
<input type="password" id="strava_password" name="strava_password" value="" />
|
||||
<p class="description"><?php _e( 'Your Password WILL NOT be saved. Only enter your password if you wish to retrieve a new API Token', 'wp-strava' ); ?></p>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function printTokenInput() {
|
||||
public function print_token_input() {
|
||||
?><input type="text" id="strava_token" name="strava_token" value="<?php echo get_option('strava_token'); ?>" /><?php
|
||||
}
|
||||
|
||||
public function sanitizeEmail( $email ) {
|
||||
public function sanitize_email( $email ) {
|
||||
if ( is_email( $email ) )
|
||||
return $email;
|
||||
add_settings_error( 'strava_email', 'strava_email', 'Invalid Email' );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function sanitizeToken( $token ) {
|
||||
public function sanitize_token( $token ) {
|
||||
if ( ! empty( $_POST['strava_password'] ) ) {
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/Rides.class.php';
|
||||
$ride = new WPStrava_Rides();
|
||||
|
||||
+1
-55
@@ -20,63 +20,9 @@ class WPStrava {
|
||||
|
||||
}
|
||||
|
||||
public static function getInstance() {
|
||||
public static function get_instance() {
|
||||
if ( ! self::$instance )
|
||||
self::$instance = new WPStrava();
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
// The handler to the ajax call, we will avoid this if Strava support jsonp request and we can do it
|
||||
// the parsing directly on the jQuery ajax call, the returned text will be enclosed in the $response variable.
|
||||
function strava_request_handler($strava_search_option, $strava_search_id, $strava_som_option, $quantity) {
|
||||
$response = "";
|
||||
|
||||
//Check if the username is empty.
|
||||
if (empty($strava_search_id)) {
|
||||
$response .= __("Please configure the Strava search id on the widget options.", "wp-strava");
|
||||
} else {
|
||||
$strava_rides = new Rides();
|
||||
$strava_rides->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 .= "<ul id='rides'>";
|
||||
foreach($rides_details as $ride) {
|
||||
$response .= "<li class='ride'>";
|
||||
$response .= "<a href='" . $strava_rides->ridesLinkUrl . $ride['id'] . "' >" . $ride['name'] . "</a>";
|
||||
$response .= "<div class='ride-item'>";
|
||||
$response .= __("On ", "wp-strava") . $ride['startDate'];
|
||||
if ($strava_search_option == "club") {
|
||||
$response .= " <a href='" . $strava_rides->athletesLinkUrl . $ride['athleteId'] . "'>" . $ride['athleteName'] . "</a>";
|
||||
}
|
||||
$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 .= "</div>";
|
||||
$response .= "</li>";
|
||||
}
|
||||
$response .= "</ul>";
|
||||
}
|
||||
return $response;
|
||||
} // Function strava_request_handler
|
||||
|
||||
}
|
||||
+10
-5
@@ -1,18 +1,23 @@
|
||||
=== Plugin Name ===
|
||||
Contributors: cmanon (@cmanon)
|
||||
Contributors: cmanon (@cmanon), jrfoell
|
||||
Donate link: http://cmanon.com/
|
||||
Tags: bycicle, strava
|
||||
Tags: bicycle, cycling, strava
|
||||
Requires at least: 2.0
|
||||
Tested up to: 3.3.2
|
||||
Tested up to: 3.5.1
|
||||
Stable tag: 0.62
|
||||
License: GPLv2 or later
|
||||
|
||||
This plugin is inteneded to show your strava.com information in your wordpress blog.
|
||||
This plugin is intended to show your strava.com information in your WordPress site.
|
||||
|
||||
== Description ==
|
||||
|
||||
This plugin uses the REST strava.com API to pull the data out and show the information in your wordpress blog.
|
||||
This plugin uses the REST strava.com API to pull the data out and show the information in your WordPress site.
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 0.70 =
|
||||
Use WordPress Settings API for settings page
|
||||
|
||||
= 0.62 =
|
||||
Refactor some code.
|
||||
Fixed several bugs.
|
||||
|
||||
+2
-4
@@ -34,9 +34,9 @@ if( file_exists( WPSTRAVA_PLUGIN_DIR . 'lang/' . get_locale() . '.mo' ) ) {
|
||||
}
|
||||
|
||||
require_once WPSTRAVA_PLUGIN_DIR . 'lib/Strava.class.php';
|
||||
$wpstrava = WPStrava::getInstance();
|
||||
$wpstrava = WPStrava::get_instance();
|
||||
|
||||
/*
|
||||
//@TODO only load these when needed
|
||||
function load_styles() {
|
||||
// Register a personalized stylesheet
|
||||
wp_register_style('wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' );
|
||||
@@ -50,5 +50,3 @@ function load_scripts() {
|
||||
//wp_enqueue_script('google-maps', 'http://maps.google.com/maps/api/js?sensor=false');
|
||||
}
|
||||
add_action('wp-enqueue_script', 'load_scripts');
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user