コード例 #1
0
 public static function get_instance()
 {
     if (!self::$instance) {
         $class = __CLASS__;
         self::$instance = new $class();
     }
     return self::$instance;
 }
コード例 #2
0
ファイル: SOM.class.php プロジェクト: nullify005/shcc-website
 public static function get_som($som = NULL)
 {
     $som = $som ? $som : WPStrava::get_instance()->settings->som;
     if ($som == 'english') {
         require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMEnglish.class.php';
         return new WPStrava_SOMEnglish();
     } else {
         //default to metric
         require_once WPSTRAVA_PLUGIN_DIR . 'lib/SOMMetric.class.php';
         return new WPStrava_SOMMetric();
     }
 }
コード例 #3
0
    function handler($atts)
    {
        self::$add_script = true;
        $defaults = array('id' => 0, 'som' => WPStrava::get_instance()->settings->som, 'map_width' => '480', 'map_height' => '320');
        extract(shortcode_atts($defaults, $atts));
        $strava_som = WPStrava_SOM::get_som($som);
        $strava_ride = WPStrava::get_instance()->rides;
        $rideDetails = $strava_ride->getRide($id);
        //sanitize width & height
        $map_width = str_replace('%', '', $map_width);
        $map_height = str_replace('%', '', $map_height);
        $map_width = str_replace('px', '', $map_width);
        $map_height = str_replace('px', '', $map_height);
        if ($rideDetails) {
            return '
				<div id="ride-header-' . $id . '" class="wp-strava-ride-container">
					<table id="ride-details-table">
						<thead>
							<tr>
								<th>' . __('Elapsed Time', 'wp-strava') . '</th>
								<th>' . __('Moving Time', 'wp-strava') . '</th>
								<th>' . __('Distance', 'wp-strava') . '</th>
								<th>' . __('Average Speed', 'wp-strava') . '</th>
								<th>' . __('Max Speed', 'wp-strava') . '</th>
								<th>' . __('Elevation Gain', 'wp-strava') . '</th>
							</tr>
						</thead>
						<tbody>
							<tr class="ride-details-table-info">
								<td>' . $strava_som->time($rideDetails->elapsed_time) . '</td>
								<td>' . $strava_som->time($rideDetails->moving_time) . '</td>
								<td>' . $strava_som->distance($rideDetails->distance) . '</td>
								<td>' . $strava_som->speed($rideDetails->average_speed) . '</td>
								<td>' . $strava_som->speed($rideDetails->max_speed) . '</td>
								<td>' . $strava_som->elevation($rideDetails->total_elevation_gain) . '</td>
							</tr>
							<tr class="ride-details-table-units">
								<td>' . $strava_som->get_time_label() . '</td>
								<td>' . $strava_som->get_time_label() . '</td>
								<td>' . $strava_som->get_distance_label() . '</td>
								<td>' . $strava_som->get_speed_label() . '</td>
								<td>' . $strava_som->get_speed_label() . '</td>
								<td>' . $strava_som->get_elevation_label() . '</td>
							</tr>
						</tbody>
					</table>' . WPStrava_StaticMap::get_image_tag($rideDetails, $map_height, $map_width) . '</div>';
        }
    }
コード例 #4
0
 public function getRides($club_id = NULL, $quantity = NULL)
 {
     $api = WPStrava::get_instance()->api;
     $data = NULL;
     $args = $quantity ? array('per_page' => $quantity) : NULL;
     //Get the json results using the constructor specified values.
     if (is_numeric($club_id)) {
         $data = $api->get("clubs/{$club_id}/activities", $args);
     } else {
         $data = $api->get('athlete/activities', $args);
     }
     if (is_wp_error($data)) {
         return $data;
     }
     if (is_array($data)) {
         return $data;
     }
     return array();
 }
コード例 #5
0
ファイル: wp-strava.php プロジェクト: nullify005/shcc-website
Version: 1.0
Author: Carlos Santa Cruz (cmanon), Justin Foell <*****@*****.**>
Author URI: http://cmanon.com
License: GPL2
*/
/*  Copyright 2011  Carlos Santa Cruz  (email : cmanon at gmail dot com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as 
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
define('WPSTRAVA_PLUGIN_DIR', trailingslashit(dirname(__FILE__)));
define('WPSTRAVA_PLUGIN_URL', plugins_url('/', __FILE__));
define('WPSTRAVA_PLUGIN_NAME', plugin_basename(__FILE__));
define('WPSTRAVA_DEBUG', false);
// Load the multilingual support.
if (file_exists(WPSTRAVA_PLUGIN_DIR . 'lang/' . get_locale() . '.mo')) {
    load_textdomain('wp-strava', WPSTRAVA_PLUGIN_DIR . 'lang/' . get_locale() . '.mo');
}
require_once WPSTRAVA_PLUGIN_DIR . 'lib/Strava.class.php';
$wpstrava = WPStrava::get_instance();
コード例 #6
0
 private function strava_request_handler($strava_club_id, $strava_som_option, $quantity)
 {
     $strava_rides = WPStrava::get_instance()->rides;
     $rides = $strava_rides->getRides($strava_club_id, $quantity);
     if (is_wp_error($rides)) {
         return $rides->get_error_message();
     }
     $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 .= "<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));
         if (is_numeric($strava_club_id)) {
             $response .= " <a href='" . WPStrava_Rides::ATHLETES_URL . $ride->athlete_id . "'>" . $ride->athlete_name . "</a>";
         }
         $response .= sprintf(__(" rode %s %s", "wp-strava"), $this->som->distance($ride->distance), $this->som->get_distance_label());
         $response .= sprintf(__(" during %s %s", "wp-strava"), $this->som->time($ride->elapsed_time), $this->som->get_time_label());
         $response .= sprintf(__(" climbing %s %s", "wp-strava"), $this->som->elevation($ride->total_elevation_gain), $this->som->get_elevation_label());
         $response .= "</div>";
         $response .= "</li>";
     }
     $response .= "</ul>";
     return $response;
 }
コード例 #7
0
 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);
         update_option('strava_latest_map', $img);
     }
     return $img;
 }
コード例 #8
0
 private function get_token($code)
 {
     $client_id = get_option('strava_client_id');
     $client_secret = get_option('strava_client_secret');
     if ($client_id && $client_secret) {
         $data = array('client_id' => $client_id, 'client_secret' => $client_secret, 'code' => $code);
         $strava_info = WPStrava::get_instance()->api->post('oauth/token', $data);
         if ($strava_info) {
             if (isset($strava_info->access_token)) {
                 $this->feedback .= __('Successfully authenticated.', 'wp-strava');
                 return $strava_info->access_token;
             } else {
                 $this->feedback .= __('Authentication failed, please check your credentials.', 'wp-strava');
                 return false;
             }
         } else {
             $this->feedback .= __(sprintf('There was an error receiving data from Strava: %s', print_r($strava_info, true)), 'wp-strava');
             return false;
         }
     } else {
         $this->feedback .= __('Missing Client ID or Client Secret.', 'wp-strava');
         return false;
     }
 }