Plugin Directory

Changeset 722799


Ignore:
Timestamp:
06/04/2013 09:49:49 PM (13 years ago)
Author:
MorganF
Message:

Ajout d'unités pour le vent (m/s + noeuds) et correction classes de températures pour les °F.

Location:
weather-layer/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • weather-layer/trunk/admin.php

    r603517 r722799  
    2929{
    3030    register_setting('wl_options', 'wl_options');
     31   
    3132    add_settings_section('main_section', 'General settings', 'weather_layer_settings_main_section', __FILE__);
     33   
    3234    add_settings_field('plugin_language', 'Language', 'weather_layer_settings_language', __FILE__, 'main_section');
    33     add_settings_field('plugin_degrees', 'Degrees', 'weather_layer_settings_degrees', __FILE__, 'main_section');
     35    add_settings_field('plugin_degrees', 'Degrees unit', 'weather_layer_settings_degrees', __FILE__, 'main_section');
     36    add_settings_field('plugin_windspeed', 'Wind speed unit', 'weather_layer_settings_windspeed', __FILE__, 'main_section');
    3437    add_settings_field('plugin_titleformat', 'Title format', 'weather_layer_settings_titleformat', __FILE__, 'main_section');
    3538    add_settings_field('plugin_branding', 'Activate promotional links', 'weather_layer_settings_branding', __FILE__, 'main_section');
     
    6063    global $WL_languages;
    6164    $options = get_option('wl_options');
    62     $language = isset($options['language']) && !empty($options['language']) && isset($WL_languages[$options['language']]) ? $options['language'] : LANGUAGE;
    6365    ?>
    6466   
     
    8385   
    8486    $options = get_option('wl_options');
    85     $degrees = isset($options['degrees']) && !empty($options['degrees']) && isset($WL_degrees[$options['degrees']]) ? $options['degrees'] : DEGREES;
    8687    ?>
    8788   
     
    9192            $selected = ((!isset($options['degrees']) || empty($options['degrees'])) && $label == DEGREES)
    9293                    ||  (isset($options['degrees']) && !empty($options['degrees']) && $label == $options['degrees']);
     94        ?>
     95            <option value="<?php echo $label; ?>" <?php echo ($selected ? 'selected="selected"' : ''); ?> /><?php echo $label; ?></option>
     96        <?php
     97        endforeach;
     98        ?>
     99    </select>
     100   
     101    <?php
     102}
     103
     104function weather_layer_settings_windspeed()
     105{
     106    global $WL_windspeed;
     107   
     108    $options = get_option('wl_options');
     109    ?>
     110   
     111    <select id="windspeed" name="wl_options[windspeed]">
     112        <?php
     113        foreach ($WL_windspeed as $label => $value) :
     114            $selected = ((!isset($options['windspeed']) || empty($options['windspeed'])) && $label == WINDSPEED)
     115                    ||  (isset($options['windspeed']) && !empty($options['windspeed']) && $label == $options['windspeed']);
    93116        ?>
    94117            <option value="<?php echo $label; ?>" <?php echo ($selected ? 'selected="selected"' : ''); ?> /><?php echo $label; ?></option>
  • weather-layer/trunk/config.php

    r722780 r722799  
    66
    77define ('LANGUAGE', 'fr'); // Langue par défaut
    8 define ('DEGREES', 'c'); // Unités de degrés par défaut
     8define ('DEGREES', 'c'); // Unités par défaut des degrés
     9define ('WINDSPEED', 'km/h'); // Unités par défaut de la vitesse du vent
    910define ('LAYER_TITLE_FORMAT', '%city% (%country%)'); // Formatage par défaut du titre du layer
    1011define ('IMAGES_PATH', get_bloginfo('wpurl') . '/wp-content/plugins/weather-layer/icones/'); // Répertoire des images
     
    2021    'Celsius'       => 'c',
    2122    'Fahrenheit'    => 'f'
     23);
     24
     25$WL_windspeed = array
     26(
     27    'km/h'      =>  'km/h',
     28    'm/s'       =>  'm/s',
     29    'Knots'     =>  'knots'
    2230);
    2331
  • weather-layer/trunk/weather_layer.php

    r722780 r722799  
    44  Plugin URI: http://blogovoyage.fr/weather-layer
    55  Description: This plugin allows you to display weather data on your blog thanks to Yahoo! Weather. Example of use with shortcode : [weatherlayer country="France" city="Paris"] You can also add the Weather Widget in order to display weather information into your sidebar.
    6   Version: 3.3.2
     6  Version: 3.4
    77  Author: Morgan Fabre
    88  Author URI: http://blogovoyage.fr
     
    170170function weather_layer_getDegreesClass ($value)
    171171{
     172    // Si les degrés sont en Fahrenheit, on les convertit Celsius pour assurer une correspondance des couleurs
     173    if (weather_layer_getDegreesUnit() == 'f')
     174        $value = ($value - 32) / 1.8;
     175   
    172176    if ($value < 12)
    173177        $class = COLD_CLASS;
    174     else if ($value < 26)
     178    else if ($value < 25)
    175179        $class = TEMPERATE_CLASS;
    176180    else
     
    204208   
    205209    return (isset($options['degrees']) && isset($WL_degrees[$options['degrees']]) ? $WL_degrees[$options['degrees']] : DEGREES);
     210}
     211
     212/**
     213    @Author Morgan Fabre
     214    Récupération des unités à utiliser pour la vitesse du vent
     215*/
     216function weather_layer_getWindSpeedUnit ()
     217{
     218    global $WL_windspeed;
     219   
     220    $options = get_option('wl_options');
     221   
     222    return (isset($options['windspeed']) && isset($WL_windspeed[$options['windspeed']]) ? $WL_windspeed[$options['windspeed']] : WINDSPEED);
     223}
     224
     225/**
     226    @Author Morgan Fabre
     227    Calcul de la valeur de la vitesse du vent
     228*/
     229function weather_layer_getWindSpeedValue($speed)
     230{
     231    switch (weather_layer_getWindSpeedUnit())
     232    {
     233        case "m/s" :
     234            $speed /= 3.6;
     235        break;
     236       
     237        case "knots" :
     238            $speed /= 1.852;
     239        break;
     240    }
     241   
     242    return round($speed, 1);
    206243}
    207244
     
    358395                            <?php echo weather_layer_getWeatherText($xml->item->condition['code']); ?>
    359396                            <br />
    360                             <?php echo weather_layer_translate('Wind'); ?> : <?php echo round($xml->wind['speed'], 0); ?> km/h
     397                            <?php echo weather_layer_translate('Wind'); ?> : <?php echo weather_layer_getWindSpeedValue($xml->wind['speed']); ?> <?php echo weather_layer_getWindSpeedUnit(); ?>
    361398                            <br />
    362399                            <?php echo weather_layer_translate('Humidity'); ?> : <?php echo $xml->atmosphere['humidity']; ?>%
Note: See TracChangeset for help on using the changeset viewer.