Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CHANGES: 8.11->8.2
- Files changed:
- /style.css
- /includes/td-config.php
- /includes/wp_booster/td_js_generator.php
- /includes/wp_booster/td_weather.php
- /includes/wp_booster/wp-admin/css/wp-admin.css
- /includes/wp_booster/wp-admin/css/wp-panels/demos.less
- /includes/wp_booster/wp-admin/panel/views/td_panel_header.php
- /js/tadiv_theme.min.js
- /js/tadiv_theme.js
- /parts/header/top-menu.php
- DETAILED CHANGES: see - https://pastebin.com/t1NgGYTs
- /style.css
- 5c5
- < Version: 8.1.1
- ---
- > Version: 8.2
- 7141c7141
- < max-width: 100% !important;
- ---
- > max-width: 100%;
- /includes/td-config.php
- 7c7
- < define("TD_THEME_VERSION", "8.1.1");
- ---
- > define("TD_THEME_VERSION", "8.2");
- 4264a4265,4274
- > "param_name" => "w_key",
- > "type" => "textfield",
- > "value" => '',
- > "heading" => "Weather api key",
- > "description" => '<a href="https://forum.tagdiv.com/weather-widget/" target="_blank">How to get an api key</a>',
- > "holder" => "div",
- > "class" => "",
- > 'group' => 'Weather'
- > ),
- > array(
- /includes/wp_booster/td_js_generator.php
- 59,72d58
- <
- < // get months and days
- < global $wp_locale;
- < $monthNames = array_map(array($wp_locale, 'get_month'), range(1, 12));
- < $monthNamesShort = array_map(array($wp_locale, 'get_month_abbrev'), $monthNames);
- < $dayNames = array_map(array($wp_locale, 'get_weekday'), range(0, 6));
- < $dayNamesShort = array_map(array($wp_locale, 'get_weekday_abbrev'), $dayNames);
- <
- < td_js_buffer::add_variable('tdDateNamesI18n', array(
- < "month_names" => $monthNames,
- < "month_names_short" => $monthNamesShort,
- < "day_names" => $dayNames,
- < "day_names_short" => $dayNamesShort
- < ));
- 73a60,72
- >
- > // global used by tdDatei18n.js
- > global $wp_locale;
- > $monthNames = array_map(array($wp_locale, 'get_month'), range(1, 12));
- > $monthNamesShort = array_map(array($wp_locale, 'get_month_abbrev'), $monthNames);
- > $dayNames = array_map(array($wp_locale, 'get_weekday'), range(0, 6));
- > $dayNamesShort = array_map(array($wp_locale, 'get_weekday_abbrev'), $dayNames);
- > td_js_buffer::add_variable('tdDateNamesI18n', array(
- > "month_names" => $monthNames,
- > "month_names_short" => $monthNamesShort,
- > "day_names" => $dayNames,
- > "day_names_short" => $dayNamesShort
- > ));
- /includes/wp_booster/td_weather.php
- 8c8,9
- < class td_weather {
- ---
- > class td_weather
- > {
- 11d11
- < private static $caching_overtime = 315360000; // 60 * 60 * 24 * 365 * 10
- 14,31c14,16
- < private static $owm_api_keys = array (
- < 'e5342a41a77f36d7802f350362aa6725',
- < '5f0e41b16ad3752a1ccb886bceb5ed51',
- < '5893ae71fbc9d28b832691406f6ba39b',
- < '93d95bd6e3378a6cb7c7e3e6f6cb5483',
- < '44458592cde0010a8a963db522bf6be5',
- < '9c252c3f1a0036ea446f45651330701e',
- < '0c3f5c17cf5499acaabff3ff594eec5c',
- < '2b08ac14030ba455470237725275d7f8',
- < 'c3075d0842fb57c51faada7fc3cbba6b',
- < 'f5dc074e364b4d0bbaacbab0030031a3',
- < '17aa0dd026f22e09f52ad000002991c6',
- < '849339ce83cba73963c74b390cba23dd',
- < '6dc28d5e9e6ef985034b6e9d153e73c7',
- < 'f166e0697a8541984a1c4dce5221f592',
- < 'd24d6df2a159679a31cf70400e87a26c'
- < );
- <
- ---
- > // private static $owm_api_keys = array (
- > // //'4d99fdabeab40f86485ab0cdefab561b',
- > // );
- 40c25,30
- < static function render_generic($atts, $block_uid, $template = 'block_template') {
- ---
- > static function render_generic($atts, $block_uid, $template = 'block_template')
- > {
- >
- > if (empty($atts['w_key']) and empty($atts['w_location'])) {
- > return td_util::get_block_error('Weather widget', "Configure this block/widget's settings to get weather");
- > }
- 43,44c33,37
- < return td_util::get_block_error('Weather', '<strong>Location field</strong> is empty. Configure this block/widget and enter a location and we\'ll show the weather from that location.');
- < //return self::error('<div class="td-block-missing-settings"><span>weather widget</span> <strong>Location field</strong> is empty. Configure this block/widget and enter a location and we\'ll show the weather from that location.</div>');
- ---
- > return td_util::get_block_error('Weather widget', "<strong>Location</strong> is empty. Configure this block/widget and enter a location and we will show the weather from that location :)");
- > }
- >
- > if (empty($atts['w_key'])) {
- > return td_util::get_block_error('Weather widget', "<strong>Api key</strong> is empty. Configure this block/widget and enter an api key :)");
- 46a40
- >
- 58c52
- < $weather_data = array (
- ---
- > $weather_data = array(
- 63c57
- < //'api_key' => self::get_a_owm_key(),
- ---
- > 'api_key' => $atts['w_key'],
- 66c60
- < 'today_temp' => array (
- ---
- > 'today_temp' => array(
- 71c65
- < 'today_wind_speed' => array (
- ---
- > 'today_wind_speed' => array(
- 75c69
- < 'today_min' => array (
- ---
- > 'today_min' => array(
- 79c73
- < 'today_max' => array (
- ---
- > 'today_max' => array(
- 90c84
- < // td_remote_cache::_disable_cache();
- ---
- > //td_remote_cache::_disable_cache();
- 103c97
- < $buffy = '<!-- td weather source: ' . $weather_data_status . ' -->';
- ---
- > $buffy = '<!-- td weather source: ' . $weather_data_status . ' -->';
- 122c116
- < tdWeather.addItem(<?php echo json_encode( $weather_data ) ?>);
- ---
- > tdWeather.addItem(<?php echo json_encode($weather_data) ?>);
- 128c122
- < td_js_buffer::add_to_footer( "\n" . td_util::remove_script_tag( ob_get_clean() ) );
- ---
- > td_js_buffer::add_to_footer("\n" . td_util::remove_script_tag(ob_get_clean()));
- 143c137,138
- < private static function render_top_bar_template($atts, $weather_data, $current_temp_label) {
- ---
- > private static function render_top_bar_template($atts, $weather_data, $current_temp_label)
- > {
- 171c166,167
- < private static function render_block_template($atts, $weather_data, $current_temp_label, $current_speed_label, $block_uid) {
- ---
- > private static function render_block_template($atts, $weather_data, $current_temp_label, $current_speed_label, $block_uid)
- > {
- 179c175
- < <i class="td-location-icon td-icons-location" data-block-uid="<?php echo $weather_data['block_uid'] ?>"></i>
- ---
- > <i class="td-location-icon td-icons-location" data-block-uid="<?php echo $weather_data['block_uid'] ?>"></i>
- 184c180,181
- < <input id="<?php echo $weather_data['block_uid'] ?>" class="td-location-set-input" type="text" name="location" value="" >
- ---
- > <input id="<?php echo $weather_data['block_uid'] ?>" class="td-location-set-input" type="text"
- > name="location" value="">
- 192c189,191
- < <span class="td_animation_sprite-27-100-80-0-0-1 <?php echo $weather_data['today_icon'] ?> td-w-today-icon" data-td-block-uid="<?php echo $block_uid?>"></span>
- ---
- > <span
- > class="td_animation_sprite-27-100-80-0-0-1 <?php echo $weather_data['today_icon'] ?> td-w-today-icon"
- > data-td-block-uid="<?php echo $block_uid ?>"></span>
- 202c201,202
- < <span class="td-small-degrees td-w-high-temp"><?php echo $weather_data['today_max'][$current_unit] ?></span>
- ---
- > <span
- > class="td-small-degrees td-w-high-temp"><?php echo $weather_data['today_max'][$current_unit] ?></span>
- 207c207,208
- < <span class="td-small-degrees td-w-low-temp"><?php echo $weather_data['today_min'][$current_unit] ?></span>
- ---
- > <span
- > class="td-small-degrees td-w-low-temp"><?php echo $weather_data['today_min'][$current_unit] ?></span>
- 218c219,220
- < <span class="td-weather-parameter td-w-today-humidity"><?php echo $weather_data['today_humidity'] ?>%</span>
- ---
- > <span class="td-weather-parameter td-w-today-humidity"><?php echo $weather_data['today_humidity'] ?>
- > %</span>
- 222c224,225
- < <span class="td-weather-parameter td-w-today-wind-speed"><?php echo $weather_data['today_wind_speed'][$current_unit] . $current_speed_label; ?></span>
- ---
- > <span
- > class="td-weather-parameter td-w-today-wind-speed"><?php echo $weather_data['today_wind_speed'][$current_unit] . $current_speed_label; ?></span>
- 226c229,230
- < <span class="td-weather-parameter td-w-today-clouds"><?php echo $weather_data['today_clouds'] ?>%</span>
- ---
- > <span class="td-weather-parameter td-w-today-clouds"><?php echo $weather_data['today_clouds'] ?>
- > %</span>
- 233c237
- <
- ---
- > $count = 0;
- 234a239,241
- > if ($count === 5) {
- > break;
- > }
- 237a245
- >
- 239c247,248
- < <span class="td-degrees-<?php echo $forecast_index ?>"><?php echo $day_forecast['day_temp'][$current_unit] ?></span>
- ---
- > <span
- > class="td-degrees-<?php echo $forecast_index ?>"><?php echo $day_forecast['day_temp'][$current_unit] ?></span>
- 243a253
- > $count++;
- 247a258
- >
- 253d263
- <
- 261c271,272
- < private static function get_weather_data($atts, &$weather_data) {
- ---
- > private static function get_weather_data($atts, &$weather_data)
- > {
- 265c276
- < $available_locales = array( 'en', 'es', 'sp', 'fr', 'it', 'de', 'pt', 'ro', 'pl', 'ru', 'uk', 'ua', 'fi', 'nl', 'bg', 'sv', 'se', 'ca', 'tr', 'hr', 'zh', 'zh_tw', 'zh_cn', 'hu' );
- ---
- > $available_locales = array('en', 'es', 'sp', 'fr', 'it', 'de', 'pt', 'ro', 'pl', 'ru', 'uk', 'ua', 'fi', 'nl', 'bg', 'sv', 'se', 'ca', 'tr', 'hr', 'zh', 'zh_tw', 'zh_cn', 'hu');
- 268c279
- < if( in_array( $sytem_locale , $available_locales ) ) {
- ---
- > if (in_array($sytem_locale, $available_locales)) {
- 272c283
- < if( in_array(substr($sytem_locale, 0, 2), $available_locales ) ) {
- ---
- > if (in_array(substr($sytem_locale, 0, 2), $available_locales)) {
- 280a292,293
- > $today_api_data = self::owm_get_today_data($atts, $weather_data);
- > $forecast_api_data = self::owm_get_five_days_data($atts, $weather_data);
- 283,307c296,300
- <
- < // The array of keys that have been checked
- < $avoid_keys = array();
- <
- < // The flag marks we need a 'today' check
- < $atts['w_type'] = 'today';
- <
- < $response = self::get_weather_data_method($atts, $cache_key, true, $weather_data, $avoid_keys);
- <
- < if (isset($response)) {
- < return $response;
- < }
- <
- < $remaining_keys = array_diff(self::$owm_api_keys, $avoid_keys);
- <
- < // The flag marks we need a 'forecast' check
- < $atts['w_type'] = 'forecast';
- <
- < if (empty($remaining_keys)) {
- <
- < // It means that just one key was available, so now, we give a try, using again the entire set of keys
- < $response = self::get_weather_data_method($atts, $cache_key, true, $weather_data);
- <
- < if (isset($response)) {
- < return $response;
- ---
- > if ($today_api_data !== true or $forecast_api_data !== true) {
- > // we have an error on one of the apis
- > $weather_data = td_remote_cache::get(__CLASS__, $cache_key);
- > if ($weather_data === false) { // miss and io error... shit / die
- > return self::error('Weather API error: ' . $today_api_data . ' ' . $forecast_api_data);
- 309d301
- < } else {
- 311,323c303,304
- < // - First, try to get keys from the $remaining_keys array, and when we finish, get the already used $avoid_keys to reuse them
- < // - The cache is not checked, because we'll do it when we check again using the previously avoided keys
- <
- < self::get_weather_data_method($atts, $cache_key, false, $weather_data, $avoid_keys);
- <
- < if ($weather_data['api_key'] === null) {
- <
- < // It means that the $remaining_keys array was exhausted, so, as we said, get the already used $avoid_keys to reuse them
- < $response_using_avoided_keys = self::get_weather_data_method($atts, $cache_key, true, $weather_data, $remaining_keys);
- < if (isset($response_using_avoided_keys)) {
- < return $response_using_avoided_keys;
- < }
- < }
- ---
- > td_remote_cache::extend(__CLASS__, $cache_key, self::$caching_time);
- > return 'api_fail_cache';
- 332,358c313
- <
- < if ( $weather_data === false ) {
- <
- < // It means an error has happened at the getting weather data, so an non expired cache value has been set for this $cache_key
- < return '';
- < } else {
- < return 'cache';
- < }
- < }
- < }
- <
- <
- < private static function get_weather_data_method($atts, $cache_key, $check_the_cache, &$weather_data, &$avoid_keys = array()) {
- <
- < // The method used is given by the $atts['w_type'] attribute
- < switch ($atts['w_type']) {
- < case 'today': $method = 'owm_get_today_data'; break;
- < case 'forecast': $method = 'owm_get_five_days_data'; break;
- < }
- <
- < $weather_data['api_key'] = self::get_a_owm_key($avoid_keys);
- < $api_data = self::$method($atts, $weather_data);
- <
- < while ( $api_data !== true && $weather_data['api_key'] !== null) {
- < $avoid_keys[] = $weather_data['api_key'];
- < $weather_data['api_key'] = self::get_a_owm_key($avoid_keys);
- < $api_data = self::$method($atts, $weather_data);
- ---
- > return 'cache';
- 361,378d315
- < // - Check will be done only when we didn't get api data and we can check the cache
- < // - We do not allow cache checking when the weather data is obtained using a subset of the available keys
- < // (the cache checking allowed only when all keys were used)
- < if ($api_data !== true && $check_the_cache) {
- <
- < $weather_data = td_remote_cache::get(__CLASS__, $cache_key);
- < if ($weather_data === false) {
- <
- < // - If we allow cache checking (all api weather keys have been used) and there's nothing in cache, we set non expiring cache time
- < // - Important! This will not allow any further api weather checks for this $cache_key (which represents a location)
- < td_remote_cache::set(__CLASS__, $cache_key, false, self::$caching_overtime);
- <
- < return self::error('Weather API error: ' . $api_data);
- < }
- <
- < td_remote_cache::extend(__CLASS__, $cache_key, self::$caching_time);
- < return 'api_fail_cache';
- < }
- 382d318
- <
- 392,393c328,330
- < private static function owm_get_today_data($atts, &$weather_data) {
- < $today_weather_url = 'http://api.openweathermap.org/data/2.5/weather?q=' . urlencode($atts['w_location']) . '&lang=' . $atts['w_language'] . '&units=metric&appid=' . $weather_data['api_key'];
- ---
- > private static function owm_get_today_data($atts, &$weather_data)
- > {
- > $today_weather_url = 'https://api.openweathermap.org/data/2.5/weather?q=' . urlencode($atts['w_location']) . '&lang=' . $atts['w_language'] . '&units=metric&appid=' . $weather_data['api_key'];
- 404c341
- < td_log::log(__FILE__, __FUNCTION__, 'Api call failed', $today_weather_url);
- ---
- > td_log::log(__FILE__, __FUNCTION__, 'Api call failed', $today_weather_url);
- 411c348
- < td_log::log(__FILE__, __FUNCTION__, 'Error decoding the json', $api_response);
- ---
- > td_log::log(__FILE__, __FUNCTION__, 'Error decoding the json', $api_response);
- 428d364
- <
- 474c410
- < $icons = array (
- ---
- > $icons = array(
- 506,508c442
- <
- <
- <
- ---
- >
- 518c452,453
- < private static function owm_get_five_days_data ($atts, &$weather_data) {
- ---
- > private static function owm_get_five_days_data($atts, &$weather_data)
- > {
- 520c455
- < $today_weather_url = 'http://api.openweathermap.org/data/2.5/forecast/daily?q=' . urlencode($atts['w_location']) . '&lang=' . $atts['w_language'] . '&units=metric&cnt=7&appid=' . $weather_data['api_key'];
- ---
- > $today_weather_url = 'https://api.openweathermap.org/data/2.5/forecast?q=' . urlencode($atts['w_location']) . '&lang=' . $atts['w_language'] . '&units=metric&cnt=35&appid=' . $weather_data['api_key'];
- 531c466
- < td_log::log(__FILE__, __FUNCTION__, 'Api call failed', $today_weather_url);
- ---
- > td_log::log(__FILE__, __FUNCTION__, 'Api call failed', $today_weather_url);
- 538c473
- < td_log::log(__FILE__, __FUNCTION__, 'Error decoding the json', $api_response);
- ---
- > td_log::log(__FILE__, __FUNCTION__, 'Error decoding the json', $api_response);
- 541,542c476
- <
- <
- ---
- >
- 544,546c478,479
- < $today_date = date( 'Ymd', current_time( 'timestamp', 0 ) );
- <
- <
- ---
- > //$today_date = date('Y-m-d', current_time('timestamp', 0));
- >
- 548c481
- < $cnt = 0;
- ---
- > $tmp_temps = array();
- 554,558c487,508
- < and !empty($day_forecast['temp']['day'])
- < and $today_date < date('Ymd', $day_forecast['dt']) // compare today with the forecast date in the format 20150210, today must be smaller. We have to do this hack
- < ) { // because the api return UTC time and we may have different timezones on the server. Avoid showing the same day twice
- < if ($cnt > 4) { // show only 5
- < break;
- ---
- > and !empty($day_forecast['main']['temp'])
- > ) {// because the api return UTC time and we may have different timezones on the server. Avoid showing the same day twice
- >
- > $current_day = date('j', $day_forecast['dt']);
- >
- > if (!isset($tmp_temps[$current_day])) {
- > $tmp_temps[$current_day]= array (
- > 'timestamp' => $day_forecast['dt'],
- > 'day_name' => date_i18n('D', $day_forecast['dt']),
- > 'day_temp' => array(
- > round($day_forecast['main']['temp_max']), // metric
- > round(self::celsius_to_fahrenheit($day_forecast['main']['temp_max'])) //imperial
- > ),
- > 'owm_day_index' => $index, // used in js to update only the displayed days when we do api calls from JS
- > );
- > } else {
- >
- > if ($tmp_temps[$current_day]['day_temp'][0] < round($day_forecast['main']['temp_max'])) {
- >
- > $tmp_temps[$current_day]['day_temp'][0] = round($day_forecast['main']['temp_max']); // metric
- > $tmp_temps[$current_day]['day_temp'][1] = round(self::celsius_to_fahrenheit($day_forecast['main']['temp_max'])); //imperial
- > }
- 560,570d509
- < $weather_data['forecast'][] = array (
- < 'timestamp' => $day_forecast['dt'],
- < //'timestamp_readable' => date('Ymd', $day_forecast['dt']),
- < 'day_temp' => array (
- < round($day_forecast['temp']['day']), // metric
- < round(self::celsius_to_fahrenheit($day_forecast['temp']['day'])) //imperial
- < ),
- < 'day_name' => date_i18n('D', $day_forecast['dt']),
- < 'owm_day_index' => $index // used in js to update only the displayed days when we do api calls from JS
- < );
- < $cnt++;
- 573a513,514
- >
- > $weather_data['forecast'] = array_values($tmp_temps);
- 580d520
- <
- 586c526,527
- < private static function celsius_to_fahrenheit ($celsius_degrees) {
- ---
- > private static function celsius_to_fahrenheit($celsius_degrees)
- > {
- 598d538
- <
- 604c544,545
- < private static function kmph_to_mph ($kmph) {
- ---
- > private static function kmph_to_mph($kmph)
- > {
- 609d549
- <
- 615c555,556
- < private static function error($msg) {
- ---
- > private static function error($msg)
- > {
- 623,637d563
- <
- < private static function get_a_owm_key( $avoid_keys = array() ) {
- <
- < if (empty($avoid_keys)) {
- < return self::$owm_api_keys[rand(0, count(self::$owm_api_keys) - 1)];
- < }
- <
- < $available_keys = array_values(array_diff(self::$owm_api_keys, $avoid_keys));
- <
- < if (empty($available_keys)) {
- < return null;
- < }
- <
- < return $available_keys[rand(0, count($available_keys) - 1)];
- < }
- /includes/wp_booster/wp-admin/css/wp-admin.css
- 1318a1319
- > vertical-align: top;
- 1320c1321
- < .wp-picker-container .button {
- ---
- > .wp-picker-container input.button {
- 1333,1336c1334,1337
- < .wp-picker-container .button:hover,
- < .wp-picker-container .button:focus,
- < .wp-picker-container .button:active,
- < .wp-picker-container .button:visited {
- ---
- > .wp-picker-container input.button:hover,
- > .wp-picker-container input.button:focus,
- > .wp-picker-container input.button:active,
- > .wp-picker-container input.button:visited {
- 1341a1343,1344
- > -webkit-transform: none;
- > transform: none;
- 1348,1350c1351,1353
- < -webkit-box-shadow: inset 1px 1px 6px -2px rgba(0, 0, 0, 0.4);
- < -moz-box-shadow: inset 1px 1px 6px -2px rgba(0, 0, 0, 0.4);
- < box-shadow: inset 1px 1px 6px -2px rgba(0, 0, 0, 0.4);
- ---
- > -webkit-box-shadow: inset 1px 1px 6px -2px rgba(0, 0, 0, 0.4) !important;
- > -moz-box-shadow: inset 1px 1px 6px -2px rgba(0, 0, 0, 0.4) !important;
- > box-shadow: inset 1px 1px 6px -2px rgba(0, 0, 0, 0.4) !important;
- 1352c1355,1356
- < .wp-picker-container .wp-color-result:after {
- ---
- > .wp-picker-container .wp-color-result:after,
- > .wp-picker-container .wp-color-result .wp-color-result-text {
- 1365a1370,1379
- > .wp-picker-container .wp-color-result .wp-color-result-text {
- > top: 0;
- > }
- > .wp-picker-container .wp-color-result.button {
- > height: 32px;
- > padding-left: 35px;
- > }
- > .wp-picker-container {
- > display: inline-block;
- > }
- 4186a4201,4202
- > -webkit-transform: none !important;
- > transform: none !important;
- /includes/wp_booster/wp-admin/css/wp-panels/demos.less
- 413a414,415
- > -webkit-transform: none !important;
- > transform: none !important;
- /includes/wp_booster/wp-admin/panel/views/td_panel_header.php
- 281a282,296
- > <!-- Weather: api key -->
- > <div class="td-box-row td-box-weather">
- > <div class="td-box-description">
- > <span class="td-box-title">Weather api key</span>
- > <p><a href="https://forum.tagdiv.com/weather-widget/" target="_blank">How to get an api key</a></p>
- > </div>
- > <div class="td-box-control-full">
- > <?php
- > echo td_panel_generator::input(array(
- > 'ds' => 'td_option',
- > 'option_id' => 'tds_weather_key_top_menu'
- > ));
- > ?>
- > </div>
- > </div>
- /js/tadiv_theme.js
- 14052c14052
- < var weather = 'http://api.openweathermap.org/data/2.5/forecast/daily?lat=' + tdWeather._currentLatitude + '&lon=' + tdWeather._currentLongitude + '&units=metric&lang=' + tdWeather._currentItem.api_language + '&appid=' + tdWeather._currentItem.api_key;
- ---
- > var weather = 'http://api.openweathermap.org/data/2.5/forecast?lat=' + tdWeather._currentLatitude + '&lon=' + tdWeather._currentLongitude + '&units=metric&lang=' + tdWeather._currentItem.api_language + '&appid=' + tdWeather._currentItem.api_key;
- 14075a14076,14079
- > //limit forecast to 5 days - api brings 35 x 3 hour intervals and at the end of the day you get 6 days forecast
- > if (item_index === 5) {
- > break;
- > }
- 14077c14081
- < current_forecast.day_temp[0] = tdUtil.round(data.list[current_forecast.owm_day_index].temp.day); //celsius
- ---
- > current_forecast.day_temp[0] = tdUtil.round(data.list[current_forecast.owm_day_index].main.temp_max); //celsius
- 14150a14155
- > blockInner.find('.td-day-' + item_index).html(tdWeather._currentItem.forecast[item_index].day_name);
- 14281c14286
- < var weather = 'http://api.openweathermap.org/data/2.5/weather?q=' + encodeURIComponent(location) + '&lang=' + tdWeather._currentItem.api_language + '&units=metric&appid=' + tdWeather._currentItem.api_key;
- ---
- > var weather = 'https://api.openweathermap.org/data/2.5/weather?q=' + encodeURIComponent(location) + '&lang=' + tdWeather._currentItem.api_language + '&units=metric&appid=' + tdWeather._currentItem.api_key;
- 14330c14335
- < var weather = 'http://api.openweathermap.org/data/2.5/forecast/daily?q=' + tdWeather._currentItem.api_location + '&lang=' + tdWeather._currentItem.api_language + '&units=metric&cnt=7&appid=' + tdWeather._currentItem.api_key;
- ---
- > var weather = 'https://api.openweathermap.org/data/2.5/forecast?q=' + tdWeather._currentItem.api_location + '&lang=' + tdWeather._currentItem.api_language + '&units=metric&cnt=35&appid=' + tdWeather._currentItem.api_key;
- 14355,14360c14360,14364
- < /**
- < * ---------------------------------------------------------------------------------------------------
- < * go through the api data list and increment the counter when we find a past day or the same as today
- < * ---------------------------------------------------------------------------------------------------
- < */
- < var counter = 0;
- ---
- > var newForecast = {},
- > newForecastIsEmpty = true,
- > ObjProto = Object.prototype,
- > hasOwnProperty = ObjProto.hasOwnProperty; //safe reference to the hasOwnProperty function, in case it's been overridden accidentally
- >
- 14361a14366
- > if (hasOwnProperty.call(data.list[list_item_index], 'dt')) {
- 14363,14364c14368,14369
- < var timestamp = data.list[list_item_index].dt;
- < //console.log(timestamp);
- ---
- > var timestamp = data.list[list_item_index].dt,
- > currentDay = td_date_i18n('Ymd', timestamp);
- 14366,14378c14371,14387
- < //the forecast day in a 'easy to read' format - for testing purposes
- < var forecast_day_format = td_date_i18n('Y m d, H:i a, T', timestamp);
- < //console.log(forecast_day_format);
- <
- < var today_date = td_date_i18n('Ymd');
- < var forecast_day = td_date_i18n('Ymd', timestamp);
- <
- < // compare today with the forecast date in the format 20150210, today must be smaller
- < if (today_date >= forecast_day){
- < counter = counter + 1;
- < }
- <
- < }
- ---
- > if (hasOwnProperty.call(newForecast, currentDay) === false) {
- > newForecast[currentDay] = {
- > timestamp: timestamp,
- > day_name: td_date_i18n('D', timestamp),
- > day_temp: [
- > tdUtil.round(data.list[list_item_index].main.temp_max),
- > tdUtil.round(tdWeather._celsiusToFahrenheit(data.list[list_item_index].main.temp_max))
- > ],
- > owm_day_index: list_item_index
- > }
- > } else {
- > if (newForecast[currentDay].day_temp[0] < tdUtil.round(data.list[list_item_index].main.temp_max)) {
- >
- > newForecast[currentDay].day_temp[0] = tdUtil.round(data.list[list_item_index].main.temp_max);
- > newForecast[currentDay].day_temp[1] = tdUtil.round(tdWeather._celsiusToFahrenheit(data.list[list_item_index].main.temp_max));
- > }
- > }
- 14380,14395c14389
- < /**
- < * --------------------------------------------------------------------------------------------------
- < * check the data and set the current forecast day index accordingly
- < * --------------------------------------------------------------------------------------------------
- < */
- < for (var item_index = 0; item_index < tdWeather._currentItem.forecast.length ; item_index++) {
- < var current_forecast = tdWeather._currentItem.forecast[item_index];
- <
- < //daca indexul ii pe 1 si trebuie trecut pe 2
- < if (item_index === 0 && counter > 1 && current_forecast.owm_day_index < 2){
- < var current_forecast_owm_day_index_update_status_2 = true;
- < }
- <
- < //daca trebuie setat pe 2 actulizeaza indexul curent
- < if (current_forecast_owm_day_index_update_status_2) {
- < current_forecast.owm_day_index = current_forecast.owm_day_index + 1;
- ---
- > newForecastIsEmpty = false;
- 14396a14391
- > }
- 14398,14401d14392
- < //daca e pe 2 si trebuie trecut pe 1
- < if (item_index === 0 && counter < 2 && current_forecast.owm_day_index > 1){
- < var current_forecast_owm_day_index_update_status_1 = true;
- < }
- 14403,14405c14394,14401
- < //daca trebuie setat pe 1 actulizeaza indexul curent
- < if (current_forecast_owm_day_index_update_status_1) {
- < current_forecast.owm_day_index = current_forecast.owm_day_index - 1;
- ---
- > if (newForecastIsEmpty === false) {
- > tdWeather._currentItem.forecast = [];
- > for (var key in newForecast) {
- > //limit forecast to 5 days - api brings 35 x 3 hour intervals and at the end of the day you get 6 days forecast
- > if (tdWeather._currentItem.forecast.length === 5) {
- > break;
- > }
- > tdWeather._currentItem.forecast[tdWeather._currentItem.forecast.length] = newForecast[key];
- 14407,14409d14402
- <
- < current_forecast.day_temp[0] = tdUtil.round(data.list[current_forecast.owm_day_index].temp.day); //celsius
- < current_forecast.day_temp[1] = tdWeather._celsiusToFahrenheit(current_forecast.day_temp[0]); //imperial
- 14410a14404
- >
- 14417a14412,14413
- >
- >
- /js/tadiv_theme.min.js - see /js/tadiv_theme.js
- /parts/header/top-menu.php
- 7a8
- > $atts['w_key'] = td_util::get_option('tds_weather_key_top_menu');
Advertisement
Add Comment
Please, Sign In to add comment