Hello!
";*/ return apixu_weather_logic($atts); } // THE LOGIC function apixu_weather_logic( $atts ) { global $apixu_weather_sizes; $rtn = ""; $weather_data = array(); $location = isset($atts['location']) ? $atts['location'] : false; $owm_city_id = isset($atts['owm_city_id']) ? $atts['owm_city_id'] : false; $size = (isset($atts['size']) AND $atts['size'] == "tall") ? 'tall' : 'wide'; $units = (isset($atts['units']) AND strtoupper($atts['units']) == "C") ? "metric" : "imperial"; $units_display = $units == "metric" ? __('C', 'apixu-weather') : __('F', 'apixu-weather'); $days_to_show = isset($atts['forecast_days']) ? $atts['forecast_days'] : 5; $show_stats = (isset($atts['show_stats']) AND $atts['show_stats'] == 1) ? 1 : 0; //$show_link = (isset($atts['show_link']) AND $atts['show_link'] == 1) ? 1 : 0; $show_link = 1; $inline_style = isset($atts['inline_style']) ? $atts['inline_style'] : ''; $widget_scheme = isset($atts['scheme']) ? $atts['scheme'] : 1; $location_case = isset($atts['location_case']) ? esc_attr($atts['location_case']) : 3; $locale = 'en'; $sytem_locale = get_locale(); $available_locales = apply_filters('apixu_weather_available_locales', array('en')); $custom_bg_color = ($atts['custom_bg_color']) ? $atts['custom_bg_color'] : "#f2f2f2"; $text_color = ($atts['text_color']) ? $atts['text_color'] : "#20a5d6"; // CHECK FOR LOCALE if (in_array($sytem_locale, $available_locales)) $locale = $sytem_locale; // CHECK FOR LOCALE BY FIRST TWO DIGITS if (in_array(substr($sytem_locale, 0, 2), $available_locales)) $locale = substr($sytem_locale, 0, 2); // OVERRIDE LOCALE PARAMETER if (isset($atts['locale'])) $locale = $atts['locale']; // DISPLAY SYMBOL $units_display_symbol = apply_filters('apixu_weather_units_display', "°"); if (isset($atts['units_display_symbol'])) $units_display_symbol = $atts['units_display_symbol']; // NO LOCATION, ABORT ABORT!!!! if (!$location) return apixu_weather_error(); //FIND AND CACHE CITY ID if ($owm_city_id) { $city_name_slug = sanitize_title($location); } else if (is_numeric($location)) { $city_name_slug = sanitize_title($location); } else { $city_name_slug = sanitize_title($location); } $location_parts = explode(',',trim($location)); $location_city = $location_parts[0]; $location_country=trim(end($location_parts)); // TRANSIENT NAME $weather_transient_name = 'awe_' . $city_name_slug . "_" . $days_to_show . "_" . strtolower($units) . '_' . $locale; // CLEAR THE TRANSIENT if (isset($_GET['clear_apixu_widget'])) delete_transient($weather_transient_name); // GET KEY $key = apply_filters('apixu_weather_appid', awe_get_appid()); // GET WEATHER DATA if (get_transient($weather_transient_name)) { $weather_data = get_transient($weather_transient_name); } else { $weather_data['now'] = array(); $weather_data['forecast'] = array(); $weather_data['location'] = array(); if ($days_to_show != "hide") { // FORECAST $weather_apixu = apixuWeather::get_forecast_weather($key, $location_city, $location_country, $days_to_show + 1); $weather_data['now'] = $weather_apixu->current; $weather_data['forecast'] = $weather_apixu->forecast; } else { // NOW $weather_apixu = apixuWeather::get_current_weather($key, $location_city, $location_country); $weather_data['now'] = $weather_apixu->current; } $weather_data['location'] = $weather_apixu->location; if ($weather_data['now'] OR $weather_data['forecast']) { set_transient($weather_transient_name, $weather_data, apply_filters('apixu_weather_cache', 1800)); } } // NO WEATHER if (!$weather_data OR !isset($weather_data['now'])) return apixu_weather_error(); // TODAYS TEMPS $today = $weather_data['now']; $today_temp = ($units == "imperial") ? (int)$today->temp_f : (int)$today->temp_c; $location = $weather_data['location']; // BACKGROUND DATA, CLASSES AND OR IMAGES $background_classes = array(); $background_classes[] = "apixu-weather-wrap"; $background_classes[] = "awecf"; $background_classes[] = "awe_" . $size; // DATA //$header_title = $override_title ? $override_title : $today->name; // WIND $wind_direction = false; if (isset($today->wind_dir)) $wind_direction = apply_filters('apixu_weather_wind_direction', __($today->wind_dir, 'apixu-weather')); $background_classes[] = ($show_stats) ? "awe_with_stats" : "awe_without_stats"; // ADD WEATHER CONDITIONS CLASSES TO WRAP if (isset($today->condition)) { $weather_code = $today->condition->code; $weather_descr = explode(' ', strtolower(trim($today->condition->text))); $weather_description_slug = sanitize_title($weather_descr[ count($weather_descr) - 1 ]); $background_classes[] = "awe-code-" . $weather_code; $background_classes[] = "awe-desc-" . $weather_description_slug; } // EXTRA STYLES $background_class_string = @implode(" ", apply_filters('apixu_weather_background_classes', $background_classes)); $today_sign = ($today_temp > 0) ? '+' : ''; if (in_array($widget_scheme, array(41, 42, 43, 44, 45))){ $widget_scheme_group = 'shm_4'; } elseif (in_array($widget_scheme, array(71, 72, 73))) { $widget_scheme_group = 'shm_7'; } elseif (in_array($widget_scheme, array(81, 82, 83))) { $widget_scheme_group = 'shm_8'; } elseif (in_array($widget_scheme, array(91))) { $widget_scheme_group = 'shm_9'; } if (in_array($widget_scheme, array(1,81))){ $inline_style = "color:{$text_color};background:{$custom_bg_color}"; } if ($inline_style){ $inline_style = "style='{$inline_style}'"; } $background_class_string .= ' ' . $widget_scheme_group; // DISPLAY WIDGET $rtn .= "