PluginProbe
wp-forecast / 9.6
wp-forecast v9.6
10.0 trunk 1.4 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3..5 3..8 3.0 3.1 3.2 3.3 3.4 3.6 All 86 releases
wp-forecast / func-openmeteo.php

func-openmeteo.php in wp-forecast 9.6, at func-openmeteo.php

557 lines 21.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /** This file is part of the wp-forecast plugin for WordPress
3 *
4 * Copyright 2024 Hans Matzen (email : webmaster at tuxlog dot de)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * @package wp-forecast
21 */
22
23 if ( ! function_exists( 'openmeteo_get_weather' ) ) {
24 /**
25 * Get the data from OpenMeteo.
26 *
27 * @param strin $baseuri the Base URI for OM.
28 * @param string $lat the latitude of the location.
29 * @param string $lon the longitude of the location.
30 * @param string $metric flag for getting metric values from OpenMeteo.
31 */
32 function openmeteo_get_weather( $baseuri, $lat, $lon, $metric ) {
33 $data = array();
34
35 $urlparms = '&hourly=relativehumidity_2m,apparent_temperature,pressure_msl,uv_index&daily=weathercode,temperature_2m_max,temperature_2m_min,apparent_temperature_max,apparent_temperature_min,sunrise,sunset,uv_index_max,uv_index_clear_sky_max,precipitation_sum,rain_sum,showers_sum,snowfall_sum,precipitation_hours,precipitation_probability_max,windspeed_10m_max,windgusts_10m_max,winddirection_10m_dominant&current_weather=true&timeformat=unixtime&timezone=auto';
36
37 // add non metric parms to url.
38 if ( 1 != $metric ) {
39 // $urlparms .= '&temperature_unit=fahrenheit&windspeed_unit=mph&precipitation_unit=inch';
40 $urlparms .= '&temperature_unit=fahrenheit&windspeed_unit=mph';
41 }
42
43 // check parms.
44 if ( trim( $lat ) == '' || trim( $lon ) == '' ) {
45 return array();
46 }
47 $url = $baseuri . 'latitude=' . $lat . '&longitude=' . $lon . $urlparms;
48
49 // Open the file and decode it.
50 try {
51 $response = wp_remote_get( $url );
52 if ( ! is_wp_error( $response ) && ( 400 > wp_remote_retrieve_response_code( $response ) ) ) {
53 if ( json_last_error() === JSON_ERROR_NONE ) {
54 $data = json_decode( $response['body'], true );
55 }
56 }
57 } catch ( Exception $ex ) {
58 error_log( print_r( $ex, true ) );
59 }
60
61 return $data;
62 }
63 }
64
65
66 if ( ! function_exists( 'openmeteo_get_data' ) ) {
67 /**
68 * Extract the weather data from json object returned from OM.
69 *
70 * @param array $weather_array the array to store the weather.
71 * @param array $wpf_vars the parameters of the weather widget.
72 */
73 function openmeteo_get_data( $weather_array, $wpf_vars ) {
74 $w = array();
75
76 if ( '1' == $wpf_vars['metric'] ) {
77 $w['un_temp'] = 'C';
78 $w['un_dist'] = 'km';
79 $w['un_speed'] = 'm/s';
80 $w['un_pres'] = 'mb';
81 $w['un_prec'] = 'mm';
82 } else {
83 $w['un_temp'] = 'F';
84 $w['un_dist'] = 'mi';
85 $w['un_speed'] = 'mph';
86 $w['un_pres'] = 'mb';
87 $w['un_prec'] = 'in';
88 }
89
90 if ( ! isset( $weather_array['current_weather'] ) || ! isset( $weather_array['daily'] ) ) {
91 $w['failure'] = 'No OpenMeteo data available. ';
92 if ( isset( $weather_array['message'] ) ) {
93 $w['failure'] .= $weather_array['message'];
94 }
95 return $w;
96 }
97
98 $w['lat'] = $weather_array['latitude'];
99 $w['lon'] = $weather_array['longitude'];
100 $w['time'] = $weather_array['current_weather']['time'];
101 $w['timezone'] = $weather_array['timezone'];
102 $mtz = new DateTimeZone( $w['timezone'] );
103
104 // values from hourly forecast.
105 $hourlyindex = 0;
106 for ( $i = 0; $i <= 165; $i++ ) {
107 if ( $weather_array['current_weather']['time'] == $weather_array['hourly']['time'][ $i ] ) {
108 $hourlyindex = $i;
109 break;
110 }
111 }
112
113 $w['pressure'] = $weather_array['hourly']['pressure_msl'][ $hourlyindex ];
114 $w['humidity'] = $weather_array['hourly']['relativehumidity_2m'][ $hourlyindex ];
115 $w['realfeel'] = round( $weather_array['hourly']['apparent_temperature'][ $hourlyindex ], 0 );
116 $w['uvindex'] = $weather_array['hourly']['uv_index'][ $hourlyindex ];
117
118 // values from current_weather and daily.
119 $w['temperature'] = round( $weather_array['current_weather']['temperature'], 0 );
120 $w['weathertext'] = openmeteo_wmocode2text( $weather_array['current_weather']['weathercode'] );
121 $w['weathericon'] = openmeteo_map_icon( $weather_array['current_weather']['weathercode'], false, $wpf_vars['fonticon'] );
122 $w['weatherid'] = $weather_array['current_weather']['weathercode'];
123 $w['wgusts'] = round( $weather_array['daily']['windgusts_10m_max'][0] / 3.6, 1 ); // convert from kmh to ms.
124 $w['windspeed'] = round( $weather_array['current_weather']['windspeed'] / 3.6, 1 ); // convert from kmh to ms.
125 $w['winddirection'] = $weather_array['current_weather']['winddirection'];
126
127 // map precipitation values.
128 $w['precipProbability'] = $weather_array['daily']['precipitation_probability_max'][0];
129 $w['precipIntensity'] = round( $weather_array['daily']['precipitation_sum'][0] / 2.54 / 10, 1 );
130 $w['precipType'] = 'Rain';
131
132 // if it snows set precipitation type to snow.
133 if ( $weather_array['daily']['snowfall_sum'][0] > 0 ) {
134 $w['precipType'] = 'Snow';
135 }
136
137 // sunset sunrise.
138 $sr = new DateTime();
139 $sr->setTimezone( $mtz );
140 $sr->setTimestamp( $weather_array['daily']['sunrise'][0] );
141 $w['sunrise'] = $sr->format( get_option( 'time_format' ) );
142
143 $ss = new DateTime();
144 $ss->setTimezone( $mtz );
145 $ss->setTimestamp( $weather_array['daily']['sunset'][0] );
146 $w['sunset'] = $ss->format( get_option( 'time_format' ) );
147
148 // get forecast data.
149 for ( $i = 0;$i <= 6;$i++ ) {
150
151 $j = $i + 1;
152 $odt = new DateTime();
153 $odt->setTimezone( $mtz );
154
155 $w[ 'fc_obsdate_' . $j ] = $weather_array['daily']['time'][ $i ] + $odt->getOffset();
156 $w[ 'fc_dt_short_' . $j ] = openmeteo_wmocode2text( $weather_array['daily']['weathercode'][ $i ] );
157 $w[ 'fc_dt_icon_' . $j ] = openmeteo_map_icon( $weather_array['daily']['weathercode'][ $i ], false, $wpf_vars['fonticon'] );
158 $w[ 'fc_dt_id_' . $j ] = $weather_array['daily']['weathercode'][ $i ];
159 $w[ 'fc_dt_htemp_' . $j ] = round( $weather_array['daily']['temperature_2m_max'][ $i ], 0 );
160 $w[ 'fc_dt_ltemp_' . $j ] = round( $weather_array['daily']['temperature_2m_min'][ $i ], 0 );
161 $w[ 'fc_dt_windspeed_' . $j ] = round( $weather_array['daily']['windspeed_10m_max'][ $i ] / 3.6, 1 ); // convert from kmh to ms.
162 $w[ 'fc_dt_winddir_' . $j ] = $weather_array['daily']['winddirection_10m_dominant'][ $i ];
163 $w[ 'fc_dt_wgusts_' . $j ] = round( $weather_array['daily']['windgusts_10m_max'][ $i ] / 3.6, 1 ); // convert from kmh to ms.
164 $w[ 'fc_dt_maxuv_' . $j ] = $weather_array['daily']['uv_index_max'][ $i ];
165 $w[ 'fc_nt_icon_' . $j ] = openmeteo_map_icon( $weather_array['daily']['weathercode'][ $i ], false, $wpf_vars['fonticon'] );
166 $w[ 'fc_nt_id_' . $j ] = $weather_array['daily']['weathercode'][ $i ];
167 $w[ 'fc_nt_htemp_' . $j ] = round( $weather_array['daily']['temperature_2m_max'][ $i ], 0 );
168 $w[ 'fc_nt_ltemp_' . $j ] = round( $weather_array['daily']['temperature_2m_min'][ $i ], 0 );
169 $w[ 'fc_nt_windspeed_' . $j ] = round( $weather_array['daily']['windspeed_10m_max'][ $i ] / 3.6, 1 ); // convert from kmh to ms.
170 $w[ 'fc_nt_winddir_' . $j ] = $weather_array['daily']['winddirection_10m_dominant'][ $i ];
171 $w[ 'fc_nt_wgusts_' . $j ] = round( $weather_array['daily']['windgusts_10m_max'][ $i ] / 3.6, 1 ); // convert from kmh to ms.
172 $w[ 'fc_nt_maxuv_' . $j ] = $weather_array['daily']['uv_index_max'][ $i ];
173
174 // map precipitation values.
175 // init vars.
176 $w[ 'fc_dt_precipProbability' . $j ] = $weather_array['daily']['precipitation_probability_max'][ $i ];
177 $w[ 'fc_dt_precipIntensity' . $j ] = $weather_array['daily']['precipitation_sum'][ $i ];
178 $w[ 'fc_dt_precipType' . $j ] = __( 'Rain', 'xxxdummy' );
179
180 // if it snows set precipitation type to snow.
181 if ( $weather_array['daily']['snowfall_sum'][ $i ] > 0 ) {
182 $w[ 'fc_dt_precipType' . $j ] = __( 'Snow', 'xxxdummy' );
183 }
184
185 // convert mm to inches for compatibility reasons with accuweather.
186 $w[ 'fc_dt_precipIntensity' . $j ] = round( $w[ 'fc_dt_precipIntensity' . $j ] / 2.54 / 10, 1 );
187 }
188
189 // fill failure anyway.
190 $w['failure'] = ( isset( $w['failure'] ) ? $w['failure'] : '' );
191
192 return $w;
193 }
194 }
195
196 if ( ! function_exists( 'openmeteo_forecast_data' ) ) {
197 /**
198 * Return the weather data for the cache from OM
199 *
200 * @param string $wpfcid the Widget ID.
201 * @param string $language_override the iso code of the language to use.
202 */
203 function openmeteo_forecast_data( $wpfcid = 'A', $language_override = null ) {
204
205 $wpf_vars = get_wpf_opts( $wpfcid );
206 if ( ! empty( $language_override ) ) {
207 $wpf_vars['wpf_language'] = $language_override;
208 }
209
210 $w = maybe_unserialize( wpf_get_option( 'wp-forecast-cache' . $wpfcid ) );
211
212 // get translations.
213 global $wpf_lang_dict;
214 $wpf_lang = array();
215 $langfile = WP_PLUGIN_DIR . '/wp-forecast/widgetlang/wp-forecast-' . strtolower( str_replace( '_', '-', $wpf_vars['wpf_language'] ) ) . '.php';
216 if ( file_exists( $langfile ) ) {
217 include $langfile;
218 }
219 $wpf_lang_dict[ $wpf_vars['wpf_language'] ] = $wpf_lang;
220
221 // --------------------------------------------------------------
222 // calc values for current conditions.
223 if ( isset( $w['failure'] ) && '' != $w['failure'] ) {
224 return array( 'failure' => $w['failure'] );
225 }
226
227 $w['servicelink'] = 'https://open-meteo.com';
228 $w['copyright'] = '<a href="https://open-meteo.com">&copy; ' . gmdate( 'Y' ) . ' Powered by Open-Meteo</a>';
229
230 // next line is for compatibility.
231 $w['acculink'] = $w['servicelink'];
232 $w['location'] = $wpf_vars['locname'];
233 $w['locname'] = $w['location'];
234
235 // handle empty timezone setting.
236 if ( ! isset( $w['timezone'] ) ) {
237 $w['timezone'] = get_option( 'timezone_string' );
238 }
239
240 $tz = new DateTimeZone( $w['timezone'] );
241 $w['gmtdiff'] = $tz->getOffset( new DateTime() );
242
243 // calculate blog date and time.
244 $ct = current_time( 'U' );
245 $ct = $ct + $wpf_vars['timeoffset'] * 60; // add or subtract time offset.
246 $w['blogdate'] = date_i18n( $wpf_vars['fc_date_format'], $ct );
247 $w['blogtime'] = date_i18n( $wpf_vars['fc_time_format'], $ct );
248
249 // calculate date/time from openmeteo.
250 $ct = $w['time'] + $w['gmtdiff'];
251 $w['accudate'] = date_i18n( $wpf_vars['fc_date_format'], $ct );
252 $w['accutime'] = date_i18n( $wpf_vars['fc_time_format'], $ct );
253
254 $ico = openmeteo_map_icon( $w['weatherid'], false, $wpf_vars['fonticon'] );
255 $iconfile = find_icon( $ico );
256 $w['icon'] = 'icons/' . $iconfile;
257 $w['iconcode'] = $ico;
258 $w['shorttext'] = openmeteo_wmocode2text( $w['weatherid'] );
259
260 $w['temperature'] = $w['temperature'] . '&deg;' . $w['un_temp'];
261 $w['realfeel'] = $w['realfeel'] . '&deg;' . $w['un_temp'];
262 $w['humidity'] = round( $w['humidity'], 0 );
263
264 // workaround different pressure values returned by accuweather.
265 $press = round( $w['pressure'], 0 );
266 if ( strlen( $press ) == 3 && substr( $press, 0, 1 ) == '1' ) {
267 $press = $press * 10;
268 }
269 $w['pressure'] = $press . ' ' . $w['un_pres'];
270 $w['humidity'] = round( $w['humidity'], 0 );
271 $w['windspeed'] = windstr( $wpf_vars['metric'], $w['windspeed'], $wpf_vars['windunit'] );
272 $w['winddir'] = translate_winddir_degree( $w['winddirection'], $wpf_vars['wpf_language'] );
273 $w['winddir_orig'] = str_replace( 'O', 'E', $w['winddir'] );
274 $w['windgusts'] = windstr( $wpf_vars['metric'], $w['wgusts'], $wpf_vars['windunit'] );
275
276 // calc values for forecast.
277 for ( $i = 1; $i < 7; $i++ ) {
278 // daytime forecast.
279 $w[ 'fc_obsdate_' . $i ] = date_i18n( $wpf_vars['fc_date_format'], $w[ 'fc_obsdate_' . $i ] );
280
281 $ico = openmeteo_map_icon( $w[ 'fc_dt_id_' . $i ], false, $wpf_vars['fonticon'] );
282 $iconfile = find_icon( $ico );
283 $w[ 'fc_dt_icon_' . $i ] = 'icons/' . $iconfile;
284 $w[ 'fc_dt_iconcode_' . $i ] = $ico;
285 $w[ 'fc_dt_desc_' . $i ] = openmeteo_wmocode2text( $w[ 'fc_dt_id_' . $i ] );
286 $w[ 'fc_dt_htemp_' . $i ] = $w[ 'fc_dt_htemp_' . $i ] . '&deg;' . $w['un_temp'];
287 $wstr = windstr( $wpf_vars['metric'], $w[ 'fc_dt_windspeed_' . $i ], $wpf_vars['windunit'] );
288 $w[ 'fc_dt_windspeed_' . $i ] = $wstr;
289 $w[ 'fc_dt_winddir_' . $i ] = translate_winddir_degree( $w[ 'fc_dt_winddir_' . $i ], $wpf_vars['wpf_language'] );
290 $w[ 'fc_dt_winddir_orig_' . $i ] = str_replace( 'O', 'E', $w[ 'fc_dt_winddir_' . $i ] );
291 $w[ 'fc_dt_wgusts_' . $i ] = windstr( $wpf_vars['metric'], $w[ 'fc_dt_wgusts_' . $i ], $wpf_vars['windunit'] );
292 $w[ 'fc_dt_maxuv_' . $i ] = $w[ 'fc_dt_maxuv_' . $i ];
293
294 // nighttime forecast.
295 $ico = openmeteo_map_icon( $w[ 'fc_nt_id_' . $i ], true, $wpf_vars['fonticon'] );
296 $iconfile = find_icon( $ico );
297 $w[ 'fc_nt_icon_' . $i ] = 'icons/' . $iconfile;
298 $w[ 'fc_nt_iconcode_' . $i ] = $ico;
299 $w[ 'fc_nt_desc_' . $i ] = openmeteo_wmocode2text( $w[ 'fc_nt_id_' . $i ] );
300 $w[ 'fc_nt_ltemp_' . $i ] = $w[ 'fc_nt_ltemp_' . $i ] . '&deg;' . $w['un_temp'];
301 $wstr = windstr( $wpf_vars['metric'], $w[ 'fc_nt_windspeed_' . $i ], $wpf_vars['windunit'] );
302 $w[ 'fc_nt_windspeed_' . $i ] = $wstr;
303 $w[ 'fc_nt_winddir_' . $i ] = translate_winddir_degree( $w[ 'fc_nt_winddir_' . $i ], $wpf_vars['wpf_language'] );
304 $w[ 'fc_nt_winddir_orig_' . $i ] = str_replace( 'O', 'E', $w[ 'fc_nt_winddir_' . $i ] );
305 $w[ 'fc_nt_wgusts_' . $i ] = windstr( $wpf_vars['metric'], $w[ 'fc_nt_wgusts_' . $i ], $wpf_vars['windunit'] );
306 $w[ 'fc_nt_maxuv_' . $i ] = $w[ 'fc_nt_maxuv_' . $i ];
307 }
308
309 // add hook for possible individual changes.
310 $w = apply_filters( 'wp-forecast-open-meteo-data', $w );
311
312 return $w;
313 }
314 }
315
316 if ( ! function_exists( 'openmeteo_map_icon' ) ) {
317 /**
318 * Function to map the weather code to a weather icon
319 *
320 * @param string $weatherid the id of the weather condition.
321 * @param bool $night the parameter to say if it is night or not.
322 * @param bool $icomode if true use weather icon font, if false use icons from gif.
323 */
324 function openmeteo_map_icon( $weatherid, $night = false, $icomode = false ) {
325 /*
326 Icon mapping from OpenMeteo
327 */
328
329 /*
330 WMO Weather interpretation codes (WW)
331 Code Description
332 0 Clear sky
333 1, 2, 3 Mainly clear, partly cloudy, and overcast
334 45, 48 Fog and depositing rime fog
335 51, 53, 55 Drizzle: Light, moderate, and dense intensity
336 56, 57 Freezing Drizzle: Light and dense intensity
337 61, 63, 65 Rain: Slight, moderate and heavy intensity
338 66, 67 Freezing Rain: Light and heavy intensity
339 71, 73, 75 Snow fall: Slight, moderate, and heavy intensity
340 77 Snow grains
341 80, 81, 82 Rain showers: Slight, moderate, and violent
342 85, 86 Snow showers slight and heavy
343 95 * Thunderstorm: Slight or moderate
344 96, 99 * Thunderstorm with slight and heavy hail
345 (*) Thunderstorm forecast with hail is only available in Central Europe
346 */
347
348 /*
349 The icons are defined in a two member array.
350 * First member is the name of the default weathericon gif file
351 * Second member is the name of the icon from weatherfont
352 */
353
354 /* defaul clear sky */
355 $icon = array( '01', 'wi-day-sunny' );
356
357 if ( $night ) {
358 // night icon mapping.
359 $ico_arr = array(
360 0 => array( '33', 'wi-night-clear' ),
361 1 => array( '34', 'wi-night-alt-cloudy' ),
362 2 => array( '35', 'wi-night-partly-cloudy' ),
363 3 => array( '38', 'wi-night-cloudy' ),
364 45 => array( '11', 'wi-night-fog' ),
365 48 => array( '11', 'wi-night-fog' ),
366 51 => array( '25', 'wi-night-sleet' ),
367 53 => array( '24', 'wi-night-sleet' ),
368 55 => array( '26', 'wi-night-sleet' ),
369 56 => array( '44', 'wi-night-alt-sleet' ),
370 57 => array( '44', 'wi-night-alt-sleet' ),
371 61 => array( '12', 'wi-night-rain' ),
372 63 => array( '40', 'wi-night-rain-mix' ),
373 65 => array( '40', 'wi-night-rain-wind' ),
374 66 => array( '44', 'wi-night-sleet' ),
375 67 => array( '26', 'wi-night-alt-sleet' ),
376 71 => array( '19', 'wi-night-snow' ),
377 73 => array( '22', 'wi-night-snow' ),
378 75 => array( '22', 'wi-night-alt-snow' ),
379 77 => array( '22', 'wi-night-alt-sleet' ),
380 80 => array( '12', 'wi-night-showers' ),
381 81 => array( '40', 'wi-night-rain-mix' ),
382 82 => array( '40', 'wi-night-rain-wind' ),
383 85 => array( '19', 'wi-night-snow' ),
384 86 => array( '22', 'wi-night-alt-snow' ),
385 95 => array( '41', 'wi-night-thunderstorm' ),
386 96 => array( '42', 'wi-night-alt-snow-thunderstorm' ),
387 99 => array( '15', 'wi-night-alt-snow-thunderstorm' ),
388 );
389 } else {
390 // day icon mapping.
391 $ico_arr = array(
392 0 => array( '01', 'wi-day-sunny' ),
393 1 => array( '03', 'wi-day-cloudy' ),
394 2 => array( '04', 'wi-day-sunny-overcast' ),
395 3 => array( '07', 'wi-day-cloudy' ),
396 45 => array( '11', 'wi-day-fog' ),
397 48 => array( '11', 'wi-day-fog' ),
398 51 => array( '25', 'wi-day-sleet' ),
399 53 => array( '24', 'wi-day-sleet' ),
400 55 => array( '26', 'wi-day-sleet' ),
401 56 => array( '29', 'wi-day-sleet' ),
402 57 => array( '29', 'wi-day-sleet' ),
403 61 => array( '12', 'wi-day-rain' ),
404 63 => array( '18', 'wi-day-rain-mix' ),
405 65 => array( '18', 'wi-day-rain-wind' ),
406 66 => array( '29', 'wi-day-sleet' ),
407 67 => array( '26', 'wi-day-sleet' ),
408 71 => array( '19', 'wi-day-snow' ),
409 73 => array( '22', 'wi-day-snow' ),
410 75 => array( '22', 'wi-day-snow' ),
411 77 => array( '22', 'wi-day-sleet' ),
412 80 => array( '12', 'wi-day-showers' ),
413 81 => array( '18', 'wi-day-rain-mix' ),
414 82 => array( '18', 'wi-day-rain-wind' ),
415 85 => array( '19', 'wi-day-snow' ),
416 86 => array( '22', 'wi-day-snow' ),
417 95 => array( '17', 'wi-day-thunderstorm' ),
418 96 => array( '16', 'wi-day-snow-thunderstorm' ),
419 99 => array( '15', 'wi-day-snow-thunderstorm' ),
420 );
421 }
422
423 // return either gif name or weatherfont icon name.
424 if ( '1' == $icomode ) {
425 return $ico_arr[ $weatherid ][1];
426 } else {
427 return $ico_arr[ $weatherid ][0];
428 }
429
430 }
431 }
432
433 if ( ! function_exists( 'openmeteo_wmocode2text' ) ) {
434 /**
435 * Return the weather data for the cache from OM
436 *
437 * @param string $wmocode the WMO code for the weather condition.
438 */
439 function openmeteo_wmocode2text( $wmocode ) {
440 /*
441 WMO Weather interpretation codes (WW)
442 Code Description
443 0 Clear sky
444 1, 2, 3 Mainly clear, partly cloudy, and overcast
445 45, 48 Fog and depositing rime fog
446 51, 53, 55 Drizzle: Light, moderate, and dense intensity
447 56, 57 Freezing Drizzle: Light and dense intensity
448 61, 63, 65 Rain: Slight, moderate and heavy intensity
449 66, 67 Freezing Rain: Light and heavy intensity
450 71, 73, 75 Snow fall: Slight, moderate, and heavy intensity
451 77 Snow grains
452 80, 81, 82 Rain showers: Slight, moderate, and violent
453 85, 86 Snow showers slight and heavy
454 95 * Thunderstorm: Slight or moderate
455 96, 99 * Thunderstorm with slight and heavy hail
456 (*) Thunderstorm forecast with hail is only available in Central Europe
457 *
458 * We use an textdomain dummy here, to avoid translation but make the strings fetchable for xgettext.
459 */
460
461 $c = ''; // the short description for the weather condition.
462
463 switch ( $wmocode ) {
464 case 0:
465 $c = __( 'Clear sky', 'xxxdummy' );
466 break;
467 case 1:
468 $c = __( 'Mainly clear', 'xxxdummy' );
469 break;
470 case 2:
471 $c = __( 'Partly cloudy', 'xxxdummy' );
472 break;
473 case 3:
474 $c = __( 'Overcast', 'xxxdummy' );
475 break;
476 case 45:
477 $c = __( 'Fog', 'xxxdummya' );
478 break;
479 case 48:
480 $c = __( 'Rime fog', 'xxxdummy' );
481 break;
482 case 51:
483 $c = __( 'Light drizzle', 'xxxdummy' );
484 break;
485 case 53:
486 $c = __( 'Moderate drizzle', 'xxxdummy' );
487 break;
488 case 55:
489 $c = __( 'Dense drizzle', 'xxxdummy' );
490 break;
491 case 56:
492 $c = __( 'Light freezing drizzle', 'xxxdummy' );
493 break;
494 case 57:
495 $c = __( 'Dense freezing drizzle', 'xxxdummy' );
496 break;
497 case 61:
498 $c = __( 'Slight rain', 'xxxdummy' );
499 break;
500 case 63:
501 $c = __( 'Moderate rain', 'xxxdummy' );
502 break;
503 case 65:
504 $c = __( 'Heavy rain', 'xxxdummy' );
505 break;
506 case 66:
507 $c = __( 'Light freezing rain', 'xxxdummy' );
508 break;
509 case 67:
510 $c = __( 'Heavy freezing rain', 'xxxdummy' );
511 break;
512 case 71:
513 $c = __( 'Slight snow fall', 'xxxdummy' );
514 break;
515 case 73:
516 $c = __( 'Moderate snow fall', 'xxxdummy' );
517 break;
518 case 75:
519 $c = __( 'Heavy snow fall', 'xxxdummy' );
520 break;
521 case 77:
522 $c = __( 'Snow grains', 'xxxdummy' );
523 break;
524 case 80:
525 $c = __( 'Slight rain showers', 'xxxdummy' );
526 break;
527 case 81:
528 $c = __( 'Moderate rain showers', 'xxxdummy' );
529 break;
530 case 82:
531 $c = __( 'Violent rain showers', 'xxxdummy' );
532 break;
533 case 85:
534 $c = __( 'Slight snow showers', 'xxxdummy' );
535 break;
536 case 86:
537 $c = __( 'Heavy snow showers', 'xxxdummy' );
538 break;
539 case 95:
540 $c = __( 'Thunderstorm', 'xxxdummy' );
541 break;
542 case 96:
543 $c = __( 'Thunderstorm with light hail', 'xxxdummy' );
544 break;
545 case 99:
546 $c = __( 'Thunderstorm with heavy hail', 'xxxdummy' );
547 break;
548
549 default:
550 $c = __( 'Clear sky', 'xxxdummy' );
551 break;
552 }
553
554 return $c;
555 }
556 }
557