<style>#gasp_widget{width:100%;background-color:#EBEBEB;margin:auto;border-radius:0px;border:0px solid #EFEFEF;position:relative;font-family:'Merriweather Sans',sans-serif;padding:15px 10px 5px;box-sizing:border-box}#gasp_widget *{margin:0;padding:0}#gasp_widget a{text-decoration:none;outline:0;color:#1f8bcb}#gasp_widget a:hover{text-decoration:underline}#gasp_widget #gasp_top{margin:0;border:0}#gasp_widget #gasp_bottom{margin:0;border:0}#gasp_widget #gasp_bottom a.site{font-weight:400}#gasp_widget .gasp_title{font-weight:400; font-size: 1.1rem;text-align:center;line-height:22px;border:1px solid silver;border-width:0 0 2px;text-transform:uppercase;letter-spacing:.1em;font-family: 'Merriweather',serif;color:#333; padding-bottom:5px} #gasp_widget .gasp_no_border{border:0}#gasp_widget .gasp_title .gasp_subtitle{font-size:13px;font-family:'Merriweather Sans',sans-serif;line-height: 15px;}#gasp_widget .gasp_box{border-top:2px solid silver;border-bottom:2px solid silver;font-weight:400;font-size: 16px;color:#393939;line-height: 21px;}#gasp_widget .gasp_box>div{padding:3px 0}#gasp_widget .gasp_forecast{border-top:none}#gasp_widget .gasp_cat_1{background-color:#00e400;font-weight:700}#gasp_widget .gasp_cat_2{background-color:#ff0;font-weight:700}#gasp_widget .gasp_cat_3{background-color:#ff7e00;font-weight:700}#gasp_widget .gasp_cat_4{background-color:red;font-weight:700;color:#fff}#gasp_widget .gasp_cat_5{background-color:#99004c;font-weight:700;color:#fff}#gasp_widget .gasp_cat_6{background-color:#7e0023;font-weight:700;color:#fff}#gasp_widget .gasp_cat_4 a,#gasp_widget .gasp_cat_5 a,#gasp_widget .gasp_cat_6 a{color:#eaeaea}#gasp_widget .gasp_cat_1 a,#gasp_widget .gasp_cat_3 a{color:#242fca}#gasp_widget .gasp_center{text-align:center;font-family:'Merriweather Sans',sans-serif;}#gasp_widget .gasp_title a{font-size:11px}#gasp_widget .gasp_link a{font-size:11px}#gasp_widget .gasp_link{text-align:center}#gasp_widget .gasp_air_quality_link{margin:0 12px}#gasp_widget .gasp_embed{padding:0}#gasp_widget .gasp_forecast{background:#fff}#gasp_widget .gasp_box strong{letter-spacing:normal}#gasp_widget .gasp_logo{display:block}#gasp_widget .gasp_logo img{display:block;margin:-7px auto}#gasp_widget .gasp_logo img{width:50%}</style><div id='gasp_widget'> <?php<!-- [et_pb_line_break_holder] --> $datetime = new DateTime('tomorrow');<!-- [et_pb_line_break_holder] --> $today = date('Y-m-d');<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> $current_xml_url;<!-- [et_pb_line_break_holder] --> $forecast_xml_url;<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> //Check if cache exists<!-- [et_pb_line_break_holder] --> if(file_exists('current_airquality_cache.xml') && file_exists('forecast_airquality_cache.xml')){<!-- [et_pb_line_break_holder] --> $minutes_elapsed = (time() - filemtime('current_airquality_cache.xml'))/60;<!-- [et_pb_line_break_holder] --> //Check if cache expired<!-- [et_pb_line_break_holder] --> if($minutes_elapsed < 30){<!-- [et_pb_line_break_holder] --> // echo 'Time elapsed:';<!-- [et_pb_line_break_holder] --> // echo $minutes_elapsed;<!-- [et_pb_line_break_holder] --> // echo 'Loading from cache.';<!-- [et_pb_line_break_holder] --> $current_xml_url = 'current_airquality_cache.xml';<!-- [et_pb_line_break_holder] --> $forecast_xml_url = 'forecast_airquality_cache.xml';<!-- [et_pb_line_break_holder] --> }else{<!-- [et_pb_line_break_holder] --> // echo 'Time elapsed:';<!-- [et_pb_line_break_holder] --> // echo $minutes_elapsed;<!-- [et_pb_line_break_holder] --> // echo 'Refreshing cache.';<!-- [et_pb_line_break_holder] --> refresh_cache();<!-- [et_pb_line_break_holder] --> $current_xml_url = 'current_airquality_cache.xml';<!-- [et_pb_line_break_holder] --> $forecast_xml_url = 'forecast_airquality_cache.xml';<!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --> else{<!-- [et_pb_line_break_holder] --> // echo 'File does not exist - refreshing cache';<!-- [et_pb_line_break_holder] --> refresh_cache();<!-- [et_pb_line_break_holder] --> $current_xml_url = 'current_airquality_cache.xml';<!-- [et_pb_line_break_holder] --> $forecast_xml_url = 'forecast_airquality_cache.xml';<!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --> function refresh_cache(){<!-- [et_pb_line_break_holder] --> $datetime = new DateTime('tomorrow');<!-- [et_pb_line_break_holder] --> $forecast_api_url = 'http://www.airnowapi.org/aq/forecast/zipCode/?format=application/xml&zipCode=43215&date=' . $datetime->format('Y-m-d') . '&API_KEY=CEA1E3AD-8816-4B77-8877-FF803214BDE9';<!-- [et_pb_line_break_holder] --> $current_api_url = 'http://www.airnowapi.org/aq/observation/zipCode/current/?format=application/xml&zipCode= 43215&API_KEY=CEA1E3AD-8816-4B77-8877-FF803214BDE9';<!-- [et_pb_line_break_holder] --> file_put_contents('current_airquality_cache.xml', file_get_contents($current_api_url));<!-- [et_pb_line_break_holder] --> file_put_contents('forecast_airquality_cache.xml', file_get_contents($forecast_api_url));<!-- [et_pb_line_break_holder] --> <!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --> //Check if empty<!-- [et_pb_line_break_holder] --> $current_xml_content = trim(file_get_contents($current_xml_url));<!-- [et_pb_line_break_holder] --> $forecast_xml_content = trim(file_get_contents($forecast_xml_url));<!-- [et_pb_line_break_holder] --> if($current_xml_content == ''){<!-- [et_pb_line_break_holder] --> //Set to valid XML if it is<!-- [et_pb_line_break_holder] --> $current_xml = simplexml_load_string('<DataList>No data</DataList>');<!-- [et_pb_line_break_holder] --> }else{<!-- [et_pb_line_break_holder] --> $current_xml = simplexml_load_file($current_xml_url);<!-- [et_pb_line_break_holder] --> <!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> if($forecast_xml_content == ''){<!-- [et_pb_line_break_holder] --> $forecast_xml = simplexml_load_string('<DataList>No data</DataList>');<!-- [et_pb_line_break_holder] --> }else{<!-- [et_pb_line_break_holder] --> $forecast_xml = simplexml_load_file($forecast_xml_url);<!-- [et_pb_line_break_holder] --> <!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> //Check if current weather exists <!-- [et_pb_line_break_holder] --> if($current_xml->ObsByZip->count()){<!-- [et_pb_line_break_holder] --> $current_aqi = $current_xml->ObsByZip[0]->AQI;<!-- [et_pb_line_break_holder] --> $current_cat_num = $current_xml->ObsByZip[0]->CategoryNumber;<!-- [et_pb_line_break_holder] --> $current_cat_name = $current_xml->ObsByZip[0]->CategoryName;<!-- [et_pb_line_break_holder] --> <!-- [et_pb_line_break_holder] --> $current_aqi_particles = $current_xml->ObsByZip[1]->AQI;<!-- [et_pb_line_break_holder] --> $current_cat_num_particles = $current_xml->ObsByZip[1]->CategoryNumber;<!-- [et_pb_line_break_holder] --> $current_cat_name_particles = $current_xml->ObsByZip[1]->CategoryName;<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> $current_available = true;<!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --> else{<!-- [et_pb_line_break_holder] --> $current_available = false;<!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> //Check if forecast exists<!-- [et_pb_line_break_holder] --> if($forecast_xml->ForecastByZip->count()){<!-- [et_pb_line_break_holder] --> $forecast_aqi = $forecast_xml->ForecastByZip[0]->AQI;<!-- [et_pb_line_break_holder] --> $forecast_cat_num = $forecast_xml->ForecastByZip[0]->CategoryNumber;<!-- [et_pb_line_break_holder] --> $forecast_cat_name = $forecast_xml->ForecastByZip[0]->CategoryName;<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> $forecast_available = true;<!-- [et_pb_line_break_holder] --><!-- [et_pb_line_break_holder] --> }else{<!-- [et_pb_line_break_holder] --> $forecast_available = false;<!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --> if($forecast_xml->ForecastByZip->count() > 1){<!-- [et_pb_line_break_holder] --> $forecast_aqi_particles = $forecast_xml->ForecastByZip[1]->AQI;<!-- [et_pb_line_break_holder] --> $forecast_cat_num_particles = $forecast_xml->ForecastByZip[1]->CategoryNumber;<!-- [et_pb_line_break_holder] --> $forecast_cat_name_particles = $forecast_xml->ForecastByZip[1]->CategoryName;<!-- [et_pb_line_break_holder] --> }<!-- [et_pb_line_break_holder] --> <!-- [et_pb_line_break_holder] --> ?> <div class='gasp_title' id='gasp_top'><strong>Current Air Quality</strong><br><span class='gasp_subtitle'>Metro Birmingham</span></div><div class='gasp_box'> <?php <!-- [et_pb_line_break_holder] --> //Makes sure current is available before proceeding<!-- [et_pb_line_break_holder] --> if($current_available){<!-- [et_pb_line_break_holder] --> $current_aqi_particles = (int) $current_aqi_particles;<!-- [et_pb_line_break_holder] --> $current_aqi = (int) $current_aqi;<!-- [et_pb_line_break_holder] --> <!-- [et_pb_line_break_holder] --> ?> <?php if ($current_aqi_particles > $current_aqi) {?> <div class='gasp_center gasp_cat_<?php echo $current_cat_num_particles;?>'> <?php echo $current_cat_name_particles; ?><br> <?php echo $current_aqi_particles ;?> (PM2.5) <?php } else { ?> <div class='gasp_center gasp_cat_<?php echo $current_cat_num;?>'> <?php echo $current_cat_name; ?><br> <?php echo $current_aqi ;?> (Ozone) <?php }} else{?> <div class='gasp_center gasp_cat_0'> <?php echo 'No data available.'?> <?php }?> <p class='gasp_link gasp_air_quality_link'><a href='https://www.gaspgroup.org/air-quality/' >Learn More About Air Quality</a></div></div><div class='gasp_box gasp_forecast'><div class='gasp_center'><?php echo $datetime->format('m\/d'); ?> Forecast:<br> <?php if($forecast_available){ ?> <?php if ($forecast_cat_name || $forecast_aqi_particles > $forecast_aqi) { ?> <strong><?php echo $forecast_cat_name; ?></strong> <?php } else if ($forecast_cat_name || $forecast_aqi > $forecast_aqi_particles) { ?> <strong><?php echo $forecast_cat_name_particles; ?></strong> <?php } else { ?> <strong>Coming Soon</strong> <?php }<!-- [et_pb_line_break_holder] --> }else{<!-- [et_pb_line_break_holder] --> echo '<strong>Coming Soon</strong>';<!-- [et_pb_line_break_holder] --> } ?> </div></div><div class='gasp_center gasp_box' id='gasp_bottom'><div><a href='https://www.gaspgroup.org/' class='gasp_logo' title='Visit the Gasp website'><img alt='Gasp: Clean air, healthy communities.' src='https://gaspgroup.org/wp-content/uploads/2017/12/gasp_logo_tilt_no-tag.png'></a><p class='gasp_link gasp_embed'><a href='https://www.gaspgroup.org/air-quality/' >Embed this widget on your site</a></div></div></div>