\n"; // Thanks to Ken True at saratoga-weather.org for this script fragment if (isset($_REQUEST['sce']) && ( strtolower($_REQUEST['sce']) == 'view' or strtolower($_REQUEST['sce']) == 'show') ) { //--self downloader -- $filenameReal = __FILE__; $download_size = filesize($filenameReal); header('Pragma: public'); header('Cache-Control: private'); header('Cache-Control: no-cache, must-revalidate'); header("Content-type: text/plain"); header("Accept-Ranges: bytes"); header("Content-Length: $download_size"); header('Connection: close'); readfile($filenameReal); exit; } include("AtomFeed-config.php"); $Status = "\n\n"; $Status .= "\n"; // set time zone if (isset ($SITE['tz'])) { $ourTZ = $SITE['tz']; } if (isset ($SITE['timeFormat'])) { $timeFormat = $SITE['timeFormat']; } $html2 = ''; $cache_folder = "/work/"; // do not chabge $cache_loc = dirname(__FILE__).$cache_folder; $cache_loc = preg_replace('|\\\|', '/', $cache_loc); if (phpversion() < 5) { echo 'This AtomFeed script requires PHP version 5 or greater. You only have PHP version: ' . phpversion(); exit; } // Establish timezone offset for time display date_default_timezone_set("$ourTZ"); // Time zone offset for xml date $TZ_offset = date("P"); // chnage codes to upper case $Code_Location = array_change_key_case($Code_Location, CASE_UPPER); $noZone_conversion = ''; // array of zone codes and chech county codes that don't have alternate codes foreach($Code_Location as $zlkey => $zlval) { if (@array_key_exists(1, $zlval)) { $noZone_conversion = 1; } if(isset($zlval[$zlkey])) { $ZL_set[$zlval] = $zlkey; } $CL_key[] = $zlkey; } // if cache/data folder isn't present, create it if(!is_dir($cache_loc)) { mkdir($cache_loc,0775,true); echo "Cache/data folder ** NOT ** found. Created $cache_loc"; $Status .= "\n"; } // start - get all county/zone data foreach($Code_Location as $noaa_code => $county) { if (!function_exists('curl_init')) { // get preliminary data for all codes - URL method GrabURLWithoutHanging($AlertURL.$noaa_code, 1, 0, $noaa_code); } else { // get preliminary data for all codes - CURL method curl_fetch_file($AlertURL.$noaa_code, 1, 0, $noaa_code); } } // get contents of each preliminary file foreach($Code_Location as $noaa_code => $county) { if(file_exists($cache_loc."Atom-".$noaa_code.".txt")) { $html = file_get_contents($cache_loc."Atom-".$noaa_code.".txt"); $html = preg_replace("/\/&[a-z]*;\//", " ", $html); } if(isset($html) and strlen($html) < 600) { echo "Cached file not complete
\n"; $Status .= "\n"; $html2 = ''; } if(isset($html) and strlen($html) > 600) { $html2[] = simplexml_load_string($html); } else { $html2 = ''; } } // check preliminary data for alerts and fetch alert data if ($html2) { foreach($html2 as $htmlFile) { $code_id = substr($htmlFile->id, -10, -4); // code from id if(isset($htmlFile->title)) { // [code]location $code_loc["$code_id"] = trim(preg_replace("/(.*) for (.*)\(.*\) (.*) Issued by(.*)/s", '${2}${3}',$htmlFile->title)); } if(isset($htmlFile->entry->summary)) { preg_match("/[A-Z]{2}[C|Z][0-9]{3}/", $htmlFile->id, $code_check); $cnt_entry = count($htmlFile->entry); for ($i = 0; $i < $cnt_entry; $i++){ if (!function_exists('curl_init')) { // get preliminary data for all codes - URL method GrabURLWithoutHanging($htmlFile->entry[$i]->id, 1, 1, $code_check[0].'-'.$i); $Status .= "\n"; } else { // get preliminary data for all codes - CURL method curl_fetch_file($htmlFile->entry[$i]->id, 1, 1, $code_check[0].'-'.$i); $Status .= "\n"; } } } } } // deletes old cache/data files foreach($Code_Location as $noaa_code => $county) { $last_code = $cache_loc."Atom-$noaa_code"; if(is_file($last_code.".txt")) { $last_codeFetch = date("U", filemtime($last_code.".txt")); foreach (glob($last_code."*.txt") as $glk => $glv ) { if($last_codeFetch-120 > date("U", filemtime($glv))) { if(!unlink($glv) and is_file($glv)) { echo "Could not delete file"; $Status .= "\n\n"; } else { $Status .= "\n\n"; } } } } } // deletes files unrelated to county/zones foreach (glob($cache_loc."*.*") as $fname) { preg_match("/[A-Z]{2}[C|Z][0-9]{3}/", $fname, $cd_check); if(!array_key_exists(@$cd_check[0], $Code_Location)) { if(isset($cache_loc) and isset($cache_folder)) { if(!unlink($fname) and is_file($fname)) { echo "Could not delete non-related files"; $Status .= "\n\n"; } else { $Status .= "\n\n"; } } } } $a_alrt = array(); $b_alrt = array(); $c_alrt = array(); // get preliminary county/zone cache files and separate them foreach (glob($cache_loc."*.txt") as $fname) { if (preg_match("/Atom-[A-Z]{2}[C|Z][0-9]{3}.txt/i", $fname)){ $a_alrt[] = $fname; // preliminary files } if (preg_match("/Atom-[A-Z]{2}[C|Z][0-9]{3}-[\d|\d+].txt/i", $fname)){ preg_match("/Atom-([A-Z]{2}[C|Z][0-9]{3}-[\d|\d+]).txt/i", $fname, $match); $b_alrt[$match[1]] = $fname; // alert files } if (preg_match("/Atom-[A-Z]{2}[C|Z][0-9]{3}-0.txt/i", $fname)){ $d_a = $fname; // alert files preg_match("/Atom-([A-Z]{2}[C|Z][0-9]{3})-[\d|\d+].txt/i", $d_a, $matches); $c_alrt[] = $matches[1]; // codes with alerts } } $NA_codes = array(); $FA_codes = array(); // cached data for Non Alerts if($a_alrt) { foreach ($a_alrt as $aak => $aav) { preg_match("/([A-Z]{2}[C|Z][0-9]{3}).txt/i", $aav, $matches); if($c_alrt) { if(!in_array($matches[1], $c_alrt)) { $na = file_get_contents($aav, true); // $na = preg_replace("/\/⁄\//", " ", $na); $na = preg_replace("/\/&[a-z]*;\//", " ", $na); $NA_codes[] = array("$matches[1]", simplexml_load_string($na)); } } else { $na = file_get_contents($aav, true); // $na = preg_replace("/\/⁄\//", " ", $na); $na = preg_replace("/\/&[a-z]*;\//", " ", $na); $NA_codes[] = array("$matches[1]", simplexml_load_string($na)); } } } // cached data for Full Alerts if($b_alrt) { foreach ($b_alrt as $bak => $bav) { preg_match("/([A-Z]{2}[C|Z][0-9]{3}).*/i", $bav, $matched); $fa = file_get_contents($bav, true); // $fa = preg_replace("/\/⁄\//", " ", $fa); $fa = preg_replace("/\/&[a-z]*;\//", " ", $fa); $FA_codes[] = array("$matched[1]", simplexml_load_string($fa)); } } foreach ($FA_codes as $FAk => $FAv) { // removes "expired alert" data if(preg_match('/This alert has expired/i', $FAv[1]->note)){ unset($FA_codes[$FAk]); } } $loc_code = array_flip($code_loc); // merge all data $full_report = array_merge($NA_codes, $FA_codes); // select data for array foreach ($full_report as $frk => $frv) { if(isset($frv[0])) { $entry_code = trim($frv[0]); } // 0 if(isset($frv[1]->id)) { $entry_id = trim($frv[1]->id); } // 1 if(isset($frv[1]->id) and isset($frv[1]->entry->id)) { $entry_id = trim($frv[1]->entry->id); } // 1 if(isset($frv[1]->identifier)) { $entry_id = trim(preg_replace("/NOAA-NWS-ALERTS-/i", $AlertURL2, $frv[1]->identifier)); } // 1 $entry_loc = array_search(trim($frv[0]), $loc_code); // 2 if(!$entry_loc) { $entry_loc = trim(preg_replace("/(.*) for (.*)\(.*\) (.*) Issued by(.*)/s", '${2}${3}',$frv[1]->title)); } if(isset($frv[1]->info->event)) { $entry_event = trim($frv[1]->info->event); } // 3 if(isset($frv[1]->entry->title)) { $entry_event = trim($frv[1]->entry->title); } // 3 if(isset($frv[1]->updated)) { $entry_sent = trim(date($timeFormat, strtotime($frv[1]->updated))); } // 4 if(isset($frv[1]->sent)) { $entry_sent = trim(date($timeFormat, strtotime($frv[1]->sent))); } // 4 if(isset($frv[1]->info->effective)) { $entry_effective = trim(date($timeFormat, strtotime($frv[1]->info->effective))); } // 5 else{ $entry_effective = '---'; } if(isset($frv[1]->info->expires)) { $entry_expires = trim(date($timeFormat, strtotime($frv[1]->info->expires))); } // 6 else{ $entry_expires = '---';} if(!isset($frv[1]->info->expires) and trim($frv[1]->entry->title) !== 'There are no active watches, warnings or advisories') { // 6 $entry_expires = trim(preg_replace("|.* expiring (.*) at (.*) by .*|i", '${1} ${2}',$frv[1]->entry->title)); $entry_expires = trim(date($timeFormat, strtotime($entry_expires))); } if(isset($frv[1]->status)) { $entry_status = trim($frv[1]->status); } // 7 else{ $entry_status = '---'; } if(isset($frv[1]->msgType)) { $entry_msgType = trim($frv[1]->msgType); } // 8 else{ $entry_msgType = '---'; } if(isset($frv[1]->info->category)) { $entry_category = trim($frv[1]->info->category);} // 9 else{ $entry_category = '---'; } if(isset($frv[1]->info->urgency)) { $entry_urgency = trim($frv[1]->info->urgency); } // 10 else{ $entry_urgency = ' None'; } if(isset($frv[1]->info->severity)) { $entry_severity = trim($frv[1]->info->severity); } // 11 else{ $entry_severity = ' None'; } if(isset($frv[1]->info->certainty)) { $entry_certainty = trim($frv[1]->info->certainty); } // 12 else{ $entry_certainty = ' None'; } if(isset($frv[1]->info->area->areaDesc)) { $entry_areaDesc = trim($frv[1]->info->area->areaDesc); } // 13 else{ $entry_areaDesc = '---'; } if(isset($frv[1]->info->instruction)) { $entry_instruction = trim($frv[1]->info->instruction); } // 14 else{ $entry_instruction = '---'; } // if(isset($frv[1]->info->description) and isset($frv[1]->note) and trim($frv[1]->note) !== 'This alert has expired') { // 15 summary if(isset($frv[1]->info->description) and isset($frv[1]->note)) { // 15 summary $desc_length = strlen($frv[1]->info->description); if($desc_length <= 220) { $entry_summary = trim($frv[1]->info->description); } else { $pos = strpos($frv[1]->info->description, '.', 221); $entry_summary = trim(substr($frv[1]->info->description, 0, $pos)); } } else { $entry_summary = '---';} if(isset($frv[1]->entry->summary)) { $ni[] = trim($frv[1]->entry->summary); } // 16 description else{ $ni[] = '---'; } if(isset($frv[1]->info->description)) { $entry_description = trim($frv[1]->info->description); } // 16 description else{ $entry_description = '---'; } $alert_color = '0'; // 17 $alert_severity = '0'; // 18 $county_name = array_search($entry_code, $ZL_set); // 19 $alert_icon = ''; // 20 if(isset($frv[1]->info->headline)) { $entry_headline = trim($frv[1]->info->headline); } // 21 else{ $entry_eventModified = trim(preg_replace("|(.*) http.*|i", '${1}',$entry_event)); $entry_headline = $entry_eventModified; } // main data array $entries[] = array( $entry_code, $entry_id, $entry_loc, $entry_event, $entry_sent, $entry_effective, $entry_expires, $entry_status, $entry_msgType, $entry_category, $entry_urgency, $entry_severity, $entry_certainty, $entry_areaDesc, $entry_instruction, $entry_summary, $entry_description, $alert_color, $alert_severity, $county_name, $alert_icon, $entry_headline ); } // associate alert types with color coding, severity, and icon $t_type = array( // Check for all types of warnings. Severity rating 0 array('N'=>'Tornado Warning', 'C'=>'#A00', 'S'=>'0', 'I'=>'TOR.gif'), // Check for all types of warnings. Severity rating 1 array('N'=>'Severe Thunderstorm Warning', 'C'=>'#B11', 'S'=>'1', 'I'=>'SVR.gif'), array('N'=>'Blizzard Warning', 'C'=>'#D00', 'S'=>'1', 'I'=>'WSW.gif'), array('N'=>'Hurricane Force Wind Warning', 'C'=>'#D00', 'S'=>'1', 'I'=>'HUW.gif'), array('N'=>'Heavy Snow Warning', 'C'=>'#D00', 'S'=>'1', 'I'=>'WSW.gif'), array('N'=>'Hurricane Warning', 'C'=>'#D00', 'S'=>'1', 'I'=>'HUW.gif'), array('N'=>'Hurricane Wind Warning', 'C'=>'#D00', 'S'=>'1', 'I'=>'HUW.gif'), array('N'=>'Tsunami Warning', 'C'=>'#D00', 'S'=>'1', 'I'=>'SMW.gif'), array('N'=>'Tropical Storm Warning', 'C'=>'#D00', 'S'=>'1', 'I'=>'TRW.gif'), array('N'=>'Winter Storm Warning', 'C'=>'#D00', 'S'=>'1', 'I'=>'WSW.gif'), array('N'=>'Winter Weather Warning', 'C'=>'#D00', 'S'=>'1', 'I'=>'WSW.gif'), // Check for all types of warnings. Severity rating 2 array('N'=>'Storm Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'SVR.gif'), array('N'=>'Ashfall Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'EWW.gif'), array('N'=>'Avalanche Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSW.gif'), array('N'=>'Civil Danger Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSW.gif'), array('N'=>'Coastal Flood Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'CFW.gif'), array('N'=>'Dust Storm Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'EWW.gif'), array('N'=>'Earthquake Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSW.gif'), array('N'=>'Extreme Cold Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'HZW.gif'), array('N'=>'Extreme Fire Danger', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSW.gif'), array('N'=>'Excessive Heat Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'EHW.gif'), array('N'=>'Extreme Wind Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'EWW.gif'), array('N'=>'Fire Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSW.gif'), array('N'=>'Flash Flood Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'FFW.gif'), array('N'=>'Flood Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'FFW.gif'), array('N'=>'Freeze Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'FZW.gif'), array('N'=>'Gale Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'HWW.gif'), array('N'=>'Hard Freeze Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'HZW.gif'), array('N'=>'Hazardous Materials Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSW.gif'), array('N'=>'Hazardous Seas Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'SMW.gif'), array('N'=>'High Surf Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'SMW.gif'), array('N'=>'High Wind Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'HWW.gif'), array('N'=>'Ice Storm Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'ISW.gif'), array('N'=>'Lake Effect Snow Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'SMW.gif'), array('N'=>'Lakeshore Flood Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'SMW.gif'), array('N'=>'Law Enforcement Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSA.gif'), array('N'=>'Nuclear Power Plant Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSW.gif'), array('N'=>'Radiological Hazard Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSW.gif'), array('N'=>'Red Flag Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'FWW.gif'), array('N'=>'River Flood Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'FLW.gif'), array('N'=>'Shelter In Place Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSW.gif'), array('N'=>'Sleet Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'IPW.gif'), array('N'=>'Special Marine Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'SMW.gif'), array('N'=>'Typhoon Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSW.gif'), array('N'=>'Volcano Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSW.gif'), array('N'=>'Wind Chill Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'WCW.gif'), // Check for Evacuation Immediate. Severity rating 3 array('N'=>'Evacuation Immediate', 'C'=>'EA00', 'S'=>'3', 'I'=>'SVW.gif'), // Check for all types of watches. Severity rating 4 array('N'=>'Tornado Watch', 'C'=>'#F33', 'S'=>'4', 'I'=>'TOA.gif'), // Check for all types of watches. Severity rating 5 array('N'=>'High Wind Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'WIY.gif'), array('N'=>'Hurricane Force Wind Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'HWW.gif'), array('N'=>'Hurricane Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'HUA.gif'), array('N'=>'Hurricane Wind Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'HWW.gif'), array('N'=>'Severe Thunderstorm Watch', 'C'=>'#F31', 'S'=>'5', 'I'=>'SVA.gif'), array('N'=>'Significant Weather Alert', 'C'=>'#F33', 'S'=>'5', 'I'=>'SWA.gif'), array('N'=>'Typhoon Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'HUA.gif'), // Check for all types of watches. Severity rating 6 array('N'=>'Avalanche Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'WSA.gif'), array('N'=>'Blizzard Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'WSA.gif'), array('N'=>'Coastal Flood Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'CFA.gif'), array('N'=>'Excessive Heat Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'EHA.gif'), array('N'=>'Extreme Cold Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'HZA.gif'), array('N'=>'Flash Flood Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'FFA.gif'), array('N'=>'Fire Weather Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'FWA.gif'), array('N'=>'Flood Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'FFA.gif'), array('N'=>'Freeze Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'FZA.gif'), array('N'=>'Gale Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'GLA.gif'), array('N'=>'Hard Freeze Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'HZA.gif'), array('N'=>'Hazardous Seas Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'SUY.gif'), array('N'=>'Heavy Freezing Spray Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'SWA.gif'), array('N'=>'Lake Effect Snow Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'WSA.gif'), array('N'=>'Lakeshore Flood Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'FFA.gif'), array('N'=>'Storm Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'SRA.gif'), array('N'=>'Tropical Storm Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'TRA.gif'), array('N'=>'Tropical Storm Wind Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'WIY.gif'), array('N'=>'Tsunami Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'WSA.gif'), array('N'=>'Wind Chill Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'WCA.gif'), array('N'=>'Winter Storm Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'SRA.gif'), array('N'=>'Winter Weather Watch', 'C'=>'#F33', 'S'=>'6', 'I'=>'WSA.gif'), // Check for Advisories. Severity rating 7 array('N'=>'Air Stagnation Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'SCY.gif'), array('N'=>'Ashfall Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'WSW.gif'), array('N'=>'Blowing Dust Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'HWW.gif'), array('N'=>'Blowing Snow Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'WSA.gif'), array('N'=>'Coastal Flood Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'FLS.gif'), array('N'=>'Small Craft Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'SCY.gif'), array('N'=>'Dense Fog Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'FGY.gif'), array('N'=>'Dense Smoke Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'SMY.gif'), array('N'=>'Brisk Wind Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'WIY.gif'), array('N'=>'Flash Flood Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'FLS.gif'), array('N'=>'Flood Advisory', 'C'=>'#C50', 'S'=>'7', 'I'=>'FLS.gif'), array('N'=>'Freezing Drizzle Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'SWA.gif'), array('N'=>'Freezing Fog Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'FZW.gif'), array('N'=>'Freezing Rain Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'ZRY.gif'), array('N'=>'Freezing Spray Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'SWA.gif'), array('N'=>'Frost Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'FRY.gif'), array('N'=>'Heat Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'HTY.gif'), array('N'=>'Heavy Freezing Spray Warning', 'C'=>'#F60', 'S'=>'7', 'I'=>'SWA.gif'), array('N'=>'High Surf Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'SUY.gif'), array('N'=>'Hydrologic Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'FLS.gif'), array('N'=>'Lake Effect Snow Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'WSA.gif'), array('N'=>'Lake Effect Snow and Blowing Snow Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'WSA.gif'), array('N'=>'Lake Wind Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'LWY.gif'), array('N'=>'Lakeshore Flood Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'FLS.gif'), array('N'=>'Low Water Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'FFA.gif'), array('N'=>'Sleet Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'SWA.gif'), array('N'=>'Snow Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'WSA.gif'), array('N'=>'Snow and Blowing Snow Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'WSA.gif'), array('N'=>'Tsunami Advisory', ' C'=>'#F60', 'S'=>'7', 'I'=>'SWA.gif'), array('N'=>'Wind Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'WIY.gif'), array('N'=>'Wind Chill Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'WCY.gif'), array('N'=>'Winter Weather Advisory', 'C'=>'#F60', 'S'=>'7', 'I'=>'WWY.gif'), // Check for any Statement. Severity rating 8 array('N'=>'Severe Weather Statement', 'C'=>'#F33', 'S'=>'8', 'I'=>'SVS.gif'), array('N'=>'Special Weather Statement', 'C'=>'#C70', 'S'=>'8', 'I'=>'SPS.gif'), array('N'=>'Coastal Flood Statement', 'C'=>'#C70', 'S'=>'8', 'I'=>'FFS.gif'), array('N'=>'Coastal Hazard', 'C'=>'#C70', 'S'=>'8', 'I'=>'CFS.gif'), array('N'=>'Flash Flood Statement', 'C'=>'#C70', 'S'=>'8', 'I'=>'FFS.gif'), array('N'=>'Flood Statement', 'C'=>'#33F', 'S'=>'8', 'I'=>'FFS.gif'), array('N'=>'Hurricane Statement', 'C'=>'#C70', 'S'=>'8', 'I'=>'HUA.gif'), array('N'=>'Lakeshore Flood Statement', 'C'=>'#33F', 'S'=>'8', 'I'=>'FFS.gif'), array('N'=>'Marine Weather Statement', 'C'=>'#C70', 'S'=>'8', 'I'=>'MWS.gif'), array('N'=>'Public Information Statement', 'C'=>'#C70', 'S'=>'8', 'I'=>'PNS.gif'), array('N'=>'River Flood Statement', 'C'=>'#C70', 'S'=>'8', 'I'=>'FLS.gif'), array('N'=>'River Statement', 'C'=>'#C70', 'S'=>'8', 'I'=>'RVS.gif'), array('N'=>'Tropical Statement', 'C'=>'#C70', 'S'=>'8', 'I'=>'HLS.gif'), array('N'=>'Typhoon Statement', 'C'=>'#C70', 'S'=>'8', 'I'=>'TRA.gif'), // Check for Air Quality Alerts. Severity rating 9 array('N'=>'Air Quality Alert', 'C'=>'#06C', 'S'=>'9', 'I'=>'SPS.gif'), // Check for Short Term Forecast. Severity rating 10 array('N'=>'Short Term Forecast', 'C'=>'#093', 'S'=>'10', 'I'=>'NOW.gif'), // Check for any Emergency. Severity rating 11 array('N'=>'Child Abduction Emergency', 'C'=>'#093', 'S'=>'11', 'I'=>'SPS.gif'), array('N'=>'Civil Emergency Message', 'C'=>'#093', 'S'=>'11', 'I'=>'SPS.gif'), array('N'=>'Hydrologic Outlook', 'C'=>'#36C', 'S'=>'11', 'I'=>'CFS.gif'), array('N'=>'Local Area Emergency', 'C'=>'#093', 'S'=>'11', 'I'=>'SPS.gif'), // Check for any Outage. Severity rating 12 array('N'=>'911 Telephone Outage', 'C'=>'#36C', 'S'=>'12', 'I'=>'SPS.gif'), // Check for no alert. Severity rating 13 array('N'=>'There are no active watches, warnings or advisories', 'C'=>'#333', 'S'=>'13', 'I'=>'') ); // assign numerical keys for county/zone codes $cz_codekeys = array_keys($Code_Location); $pri_NA = ''; $fm = range(0,13); $iconNA = array(); $ltp = ''; // add appropriate color-code, severity rating, icon, and code key to array foreach ($entries as $e_k => $e_v) { if(deep_in_array($e_v[3], $t_type)) { $entries[$e_k][17] = $t_type[$keyB]['C']; $entries[$e_k][18] = $t_type[$keyB]['S']; if($entries[$e_k][17] !== '#333') { $entries[$e_k][20] = "\"icn\" "; } } else { if($entries[$e_k][5] !== '---') { // add data if alert type is not found in t-type array $entries[$e_k][17] = '#36C'; $entries[$e_k][18] = '11'; $entries[$e_k][20] = "\"icn\" "; } } $entries[$e_k][22] = array_search($entries[$e_k][0], $cz_codekeys); // for sorting code locations if($entries[$e_k][16] == '---' and $entries[$e_k][3] !== 'There are no active watches, warnings or advisories') { preg_match("/(.*) issued/i", $entries[$e_k][3], $fix_alrt); if(deep_in_array($fix_alrt[1], $t_type)) { $entries[$e_k][17] = $t_type[$keyB]['C']; $entries[$e_k][18] = $t_type[$keyB]['S']; $entries[$e_k][20] = "\"icn\" "; } $entries[$e_k][3] = $fix_alrt[1]; $entries[$e_k][5] = $entries[$e_k][4]; $entries[$e_k][14] = ''; $entries[$e_k][16] = $ni[$e_k]; $entries[$e_k][15] = $ni[$e_k]; } if($entries[$e_k][0] == '') { unset($entries[$e_k]); } if(preg_match('/1969/', $entries[$e_k][6])){ $entries[$e_k][5] = '---'; $entries[$e_k][6] = '---'; } if($entries[$e_k][2] == '') { $entries[$e_k][2] = array_search($entries[$e_k][0], $ZL_set); } if($entries[$e_k][19] == '' and isset($entries[$e_k][2])) { $entries[$e_k][19] = $entries[$e_k][2]; } if($entries[$e_k][0] == $CL_key[0] and $entries[$e_k][5] == '---') { $pri_NA = " No active alerts for ".$entries[$e_k][2]." "; } if($entries[$e_k][0] == $CL_key[0] and $entries[$e_k][18] !== 13) { $ltp = $entries[$e_k][18]; } } // if using county code to zone code conversion if($noZone_conversion) { include("AtomFeed-conversion.php"); } else { // sort main data array by severity and then by location usort($entries, "u_sort"); $Status .= "\n"; } //$item = "entries"; echo "
\n* $item =
\n\n"; $item = $$item; print_r($item); echo "
count - " . count($item); echo "
\n===============
\n"; // Count arrays of current alerts $count = count($entries); // Prints summary if no full summary. Optional show no alerts or not. Change some text color. Clean up for ($i = 0; $i < $count; $i++){ // split description length if over 80 characters $pre_lines = explode("\n", $entries[$i][16]); foreach($pre_lines as $ma => $mb) { if(strlen($mb) >= 74) { $newtext = wordwrap($mb, 60, "\n"); $entries[$i][16] = str_replace($mb, $newtext, $entries[$i][16]); } } if($entries[$i][16] == false and $entries[$i][15] == true){ $entries[$i][16] = "

\n".$entries[$i][15]."

\n"; } else { $entries[$i][16] = '
' . $entries[$i][16] . "
"; } $entries[$i][16] = str_replace('and and ', " ", $entries[$i][16]); if(preg_match('/There are no/i', $entries[$i][3])){ $entries[$i][3] = $no_alert; } if(preg_match('/Extreme/', $entries[$i][11])){ $entries[$i][11] = ' Extreme '; } if(preg_match('/Severe/', $entries[$i][11])){ $entries[$i][11] = 'Severe'; } if(preg_match('/Immediate/', $entries[$i][10])){ $entries[$i][10] = 'Immediate'; } if(strlen($entries[$i][16]) < 16){ $entries[$i][14] = ''; $entries[$i][16] = $entries[$i][15]; } if($entries[$i][19] == ''){ $entries[$i][19] = $entries[$i][2]; } if($entries[$i][16] == '---'){ $entries[$i][16] = "

 No alerts for ".$entries[$i][2]."  

"; } if($entries[$i][13] == '---'){ $entries[$i][13] = " ".$entries[$i][19]; } if(preg_match("/alert has expired/", $entries[$i][16])){ unset($entries[$i]); } if($entries[$i][5] == '---' and $entries[$i][19] !== '---') { $ikey2 = array_search($entries[$i][18], $fm); $iconNA[] = array($ikey2, "No alerts", $entries[$i][2], $entries[$i][19]); } // create all big icons if($all_BIGicons) { if($entries[$i][18] >= 0 and $entries[$i][18] <= 3) { $bi = "A-warn.png"; } if($entries[$i][18] >= 4 and $entries[$i][18] <= 6) { $bi = "A-watch.png"; } if($entries[$i][18] == 7) { $bi = "A-advisory.png"; } if($entries[$i][18] == 8) { $bi = "A-statement.png"; } if($entries[$i][18] == 9) { $bi = "A-air.png"; } if($entries[$i][18] >= 10 and $entries[$i][18] <= 12) { $bi = "A-alert.png"; } if($entries[$i][18] == 13) { $bi = "A-none.png"; } if($icon2details) { $icoURL = $AdvisURL.'?zone='.$entries[$i][0].'&loc='.str_replace(" ", "+", $entries[$i][2]) .'" title="  Details for '.$entries[$i][2].' - '. $entries[$i][3] .'"'; } else { $icoURL = $AlertSummary.'" title="'.$entries[$i][3].' for '. $entries[$i][2] .' - Click to view summaries"'; } $allBig_icons[$entries[$i][19]][] = 'alert
'.$entries[$i][19] ."
\n"; } } if($all_BIGicons) { foreach($allBig_icons as $aik => $aiv) { $all_icons[] = $aiv[0]; } } // Time zone offset for xml date $TZ_offset = date("P"); // XML page $xml_entries = $entries; function rss_sort($c, $d){ if($c[4] == $d[4]){ return 0; } elseif($c[4] > $d[4]){ return -1; } elseif($c[4] < $d[4]){ return 1; } } // end rss_sort function // XML writing if($xml_SortByDate) { usort($xml_entries, 'rss_sort'); $xml_sort = $xml_entries; } else { $xml_sort = $entries; } $xml_zones = ""; foreach($xml_sort as $xmlk => $xmlv) { $loc = str_replace(" ", "+", $xmlv[2]); if($xml_Link2message) { $xml_url = $AdvisURL.'?zone='.$xmlv[0].'&loc='.$loc; } else { $xml_url = $AlertSummary; } if($xmlv[15] == "---"){ $short_desc = "No active alerts"; } else { $short_desc = " ".$xmlv[15].' ....click the link for more details'; } if($xmlv[6] !== "---"){ $expires = " - Expires: ".$xmlv[6]; } if($xmlv[6] == "---"){ $title_link = $no_alert; } if($xmlv[6] !== "---"){ $title_link = $xmlv[3].$expires; } if($xmlv[6] !== "---" and $use_headline) { $title_link = $xmlv[21]; } // headline $ex_date = date("Y-m-d\TH:i:s$TZ_offset", strtotime($xmlv[4])); $xml_zones .= "\n\t".$xmlv[19].' - '.$title_link ."\n\t\n\t".$short_desc. "\n\t".$xmlv[1]."\n\t".$ex_date."\n\n"; } $xml_zone = "\n$titleA\nLast update: ".$xmlv[4] ."\nhttp://".$_SERVER['SERVER_NAME']."\n".$ex_date."\n\n\tNWS\n\n\n".$xml_zones . ""; // writes xml to a file. $fpia = fopen($xmlFilename, 'wb'); fputs($fpia, $xml_zone); fclose($fpia); // close file // end XML writing // start alert box $fpwb = fopen($a_arrays,'wb'); $fpac = fopen($a_arrays,'ab'); $iconFA = array(); $aa = true; // all alerts $alertBox = ''; $spanA = ''; $spanB = $spanA; $endSpan = ''; $endSpanB = $endSpan; $aB_align = 'text-align: center; '; $inner_border = ''; $add_table = "\n
"; $end_Table = "
\n"; $innerTable = "\n
"; $end_innerTable = $end_Table; // group alerts spacing if($group_alerts and $aBox_Width) { $spanA = ''; $endSpan = ''; $space0 = "\n "; $space1 = ""; $space2 = ""; $space3 = ""; $space7 = ""; $space8 = "\n"; $space9 = "  "; $space10 = "\n  "; } if($group_alerts and $aBox_Width and $line_break) { $spanA = ''; $endSpan = ''; $space0 = ""; $separator = ''; $space4 = ""; $space5 = ""; $space6 = "
\n"; $space8 = ""; $space9 = "
\n"; $space10 = "
\n"; } if($group_alerts and $aBox_Width and $line_break and $align_left) { $spanA = ''; $endSpan = ''; $exTable = $innerTable; $end_exTable = $end_innerTable; $space4 = "    "; } if($group_alerts and !$aBox_Width) { $spanA = ''; $endSpan = ''; $space0 = ""; $space2 = ""; $space3 = ""; $separator = ''; $space4 = ""; $space5 = ""; $space6 = ""; $space7 = ""; $space8 = "
\n"; $space9 = "
"; $space10 = "
\n"; } if($group_alerts and !$aBox_Width and $align_left) { $space4 = "    "; $space10 = "
\n"; } // NON group alerts spacing if(!$group_alerts and $aBox_Width) { $spanB = ''; $endSpanB = ''; $space0 = "  "; $space7 = ""; } if(!$group_alerts and !$aBox_Width) { $spanB = ''; $endSpanB = ''; $spanA = ''; $endSpan = ''; $space0 = ""; $space2 = " "; $space6 = "
\n"; $space7 = ""; $space8 = ""; } if(!$group_alerts and $aBox_Width and $line_break) { $spanB = ''; $endSpanB = ''; $space0 = ""; $space6 = ""; $space7 = ""; $space8 = "
\n"; } if(!$group_alerts and $aBox_Width and $align_left) { $spanB = ''; $endSpanB = ''; $exTable = $innerTable; $end_exTable = $end_innerTable; } // start assembling the work file fputs($fpwb, " $bv) { $bv[2] = str_replace("'", "'", $bv[2]); $bv[19] = str_replace("'", "'", $bv[19]); if($bv[5] !== '---') { $ikey = array_search($bv[18], $fm); $log[] = array($bv[2], $bv[3], $bv[5], $bv[6], $bv[17]); $iconFA[] = array($ikey, $bv[3], $bv[2], $bv[19],$bv[0]); } $loc_url = str_replace(" ", "+", $bv[2]); $bv[3] = str_replace(" ", " ", $bv[3]); $bv[19] = str_replace(" ", " ", $bv[19]); if($colorCode_bckgrnd) { $text_clr = "color: ".$text_color."; "; // use the funtion set_background } if($link2details) { $bv[19] = ''. $space2.$space3.$separator.$space4.$space5.$bv[19]."".$endSpan.$space6.$space7.$space8; } else { $bv[19] = "".$space2.$space3.$separator.$space4.$space5.$bv[19]."".$endSpan.$space6.$space7.$space8; } if(!$group_alerts and $link2details) { $t_link = $AdvisURL.'?zone='.$bv[0].'&loc='.$loc_url.'" title="  Details for '.$bv[2].' - '.$bv[3].'"'; } $bv[3] = ''.$bv[3].''; $bv[20] = $spanA.$space0.$bv[20]; $d_array = array(3 => $bv[3], 2 => $bv[2], 19 => $bv[19], 0 => $bv[0], 18 => $bv[18], 22 => $bv[22], 20 => $bv[20]); if($bv[18] !== "13" or $local_alerts) { if($aa) { // all alerts $Abox_array[] = $d_array; $local_alerts = false; $limit_topAlerts = false; $group_alerts = false; } if($local_alerts and ($bv[22] == 0 or !$d_array)) { // local alerts $Abox_array[] = $d_array; $limit_topAlerts = false; $group_alerts = false; } if($limit_topAlerts) { // top alerts $Abox_array[$bv[2]][] = $d_array; $local_alerts = false; $group_alerts = false; } if($group_alerts) { // group alerts @$ga_loc2[] = array(0=>$bv[20],$bv[3],$bv[19]); @$ga_loc[$bv[19]] = array(0=>$bv[20],$bv[3],$bv[19]); $local_alerts = false; $limit_topAlerts = false; } } else { if($group_alerts and !$limit_NoAlerts and !$FA_codes) { $aa = false; $local_alerts = false; $limit_topAlerts = false; @$ga_loc2[] = array(0=>$bv[20],$bv[3],$bv[19]); @$ga_loc[$bv[19]] = array(0=>$bv[20],$bv[3],$bv[19]); } if($group_alerts and $limit_NoAlerts and !$FA_codes) { $aa = false; $local_alerts = false; $limit_topAlerts = false; @$ga_loc2[] = array(1=>$bv[3]); @$ga_loc[$bv[19]] = array(0=>$bv[3]); } if(!$limit_NoAlerts and !$FA_codes and !$group_alerts) { $aa = true; $local_alerts = false; $group_alerts = false; $limit_topAlerts = false; $Abox_array[] = $d_array; } if($limit_NoAlerts and !$FA_codes and !$group_alerts) { $aa = false; $local_alerts = false; $group_alerts = false; $limit_topAlerts = false; $br = ''; $sec_alrts = array(3 => 'No warnings, watches, or advisories', 2 => '', 19 => '', 0 => '', 18 => '', 22 => '', 20 => ''); } } } if($aa) { // all alerts foreach($Abox_array as $ak => $av) { if($aBox_Icon == false) { $av[20] = $spanA; } $sec_alrts[] = $av[20].$av[3].$av[19]; } } if($local_alerts) { // local alerts foreach($Abox_array as $lk => $lv) { if($aBox_Icon == false) { $lv[20] = $spanA; } if(!$lv[20]) { $lv[3] = str_replace("", "", $lv[3]); $lv[3] = str_replace("", "", $lv[3]); $lv[3] = str_replace("   ", "", $lv[3]); } $sec_alrts[] = $lv[20].$lv[3].$lv[19]; } } if($limit_topAlerts) { // top alerts foreach($Abox_array as $tk => $tv) { if($aBox_Icon == false) { $tv[20] = $spanA; } $sec_alrts[] = $tv[0][20].$tv[0][3].$tv[0][19]; } } $var = ''; if($group_alerts) { // group alerts $ga = $ga_loc2; if($limit_GroupAlerts) { $ga = $ga_loc; } foreach($ga as $gk => $gv) { @$var[$gv[1]][$gv[0]] .= $gv[2]; } foreach($var as $vk => $vv) { if($GroupAlerts_TitleBreak and $aBox_Width and !$line_break) {$space10 = '  '; $space11 = "
\n"; } $sec_alrts[] = $spanB.key($vv).$vk.$endSpanB.$space10.$vv[key($var[$vk])].$space11.' '; } } foreach($sec_alrts as $sak => $sav) { $alertBox .= $sav; } if($always_show or ($FA_codes and (!$local_alerts or !$pri_NA ))) { fputs($fpac, $div.$Table.$exTable.$alertBox.$end_exTable.$end_Table.$end_div."';\n\n"); // close the table } else { fputs($fpac, "';\n\n"); // close the tag } } if(!$always_show and !$FA_codes) { fputs($fpac, "';\n\n"); // close the tag } // end of alert box // group codes with alerts foreach($entries as $ke => $vl) { $result[$vl[0]][] = $entries[$ke]; } // Append results to work file foreach($result as $kea => $vla) { fputs($fpac, '$'.$kea .'='. var_export($vla, 1).";\n\n"); } // create big icons $top_icon = array(); $hcount = count($iconFA); $ncount = count($iconNA); if($show_allBI and $iconFA) { $iconFA = array_merge($iconFA,$iconNA); $hcount = $hcount + $ncount; } if($show_allBI and !$iconFA) { $iconFA = $iconNA; $hcount = $ncount; } $banner_icon = array(); foreach($iconFA as $ai) { // associated icon with alert type if($ai[0] >= 0 and $ai[0] <= 3) { $big_icon = "A-warn.png"; } if($ai[0] >= 4 and $ai[0] <= 6) { $big_icon = "A-watch.png"; } if($ai[0] == 7) { $big_icon = "A-advisory.png"; } if($ai[0] == 8) { $big_icon = "A-statement.png"; } if($ai[0] == 9) { $big_icon = "A-air.png"; } if($ai[0] >= 10 and $ai[0] <= 12) { $big_icon = "A-alert.png"; } if($ai[0] == 13) { $big_icon = "A-none.png"; } if($icon2details) { $icoURL = $AdvisURL.'?zone='.$ai[4].'&loc='.str_replace(" ", "+", $ai[2]) .'" title="   '.$ai[1].' for '. $ai[2] .'"'; } else { $icoURL = $AlertSummary.'" title="   '.$ai[1].' for '. $ai[2] .' - Click to view summaries"'; } // configure icon for alert type $top_icon[] = 'alert
'.$ai[3] ."

\n"; if(isset($ai[4])) { $banner_icon[$ai[4]][] = array($ai[1],$icon_folder.'/'.$big_icon); // for adding an icon to a banner } } // limit the amount of icons by setting icon_limit in the config page if(!empty($icon_limit) and $icon_limit < $hcount) { if($icon_limit < $hcount) { $dcount = $hcount - $icon_limit; $hcount = $icon_limit; $top_icon = array_chunk($top_icon, $hcount, true); $top_icon = $top_icon[0]; if($dcount == 1) { $calerts = "other"; } else { $calerts = "others"; } } $top_icon[$hcount] = "\n+ $dcount $calerts"; } if(!$iconFA and !$show_allBI) { $top_icon[] = 'alert'; } // create all big icons $AB_icons = array_merge($iconFA,$iconNA); // create an array called $all_data with all alerts and write it to the file $ex_data = '$all_data = '. var_export($entries, 1).";\n\n"; fputs($fpac, $ex_data); // writes all data as an array // write icon data to work file fputs($fpac, '$top_icons = '.var_export($top_icon, 1).";\n\n"); // add the top advisory icons if($all_BIGicons) { fputs($fpac, '$all_icons = '.var_export($all_icons, 1).";\n"); // add the top advisory icons } else {fputs($fpac, '$all_icons = '."'';\n");} fputs($fpac, '$banner_icon = '.var_export($banner_icon, 1).";\n"); // add icons for a banner if($FA_codes) { fputs($fpac, "\n".'$alert_status = '."1;\n"); // add the top advisory icons } else { fputs($fpac, "\n".'$alert_status = '."'';\n"); // add the top advisory icons } // finish work file and close fputs($fpac, "\n ?>"); fclose($fpac); // log daily alerts for archiving if($log_alerts) { $Status .= "\n"; $log_date = date("Ymd"); $Log_file = $log_folder."AtomAlertLog".$log_date.".txt"; $added_alert = ''; $dy_log = array(); $dly_log = array(); if(!is_file($Log_file) and $log) { $fplf = fopen($Log_file,'wb'); fwrite($fplf, ""); // write first line for php ant top warnings tag fclose($fplf); // close file } if(is_file($Log_file)) { include($Log_file); } if($log) { foreach($log as $lk => $lv) { $dlog[] = array($lv[0],$lv[2],$lv[1],$lv[3],$lv[4]); } foreach($dlog as $dlk => $dlv) { if(!in_array($dlv, $daily_log)) { $dy_log[] = $dlv; $added_alert = 1; } } $dly_log = array_merge($daily_log, $dy_log); } if($added_alert) { $fplf = fopen($Log_file,'wb'); fwrite($fplf, ""); // write first line for php ant top warnings tag fclose($fplf); // close file } } ################################################################################################################# ############################# FUNCTIONS ######################################################################### ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ------------------------------------------------------------------ /* Begin Function get_data */ function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_USERAGENT,'24hr Precip Fetch/1.1 (Web Application, www.gwwilkins.org)'); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } /* End Function get_data */ // ------------------------------------------------------------------ // CURL method of fetching data ///////////////////////////////////////////////////////////////////////////////// function curl_fetch_file($url, $fullMessages = 1, $whichFetch = 0, $checkCode) { // mchallis added get contents from one URL using a CURL call and return as string global $curl_debug, $Status, $xmlH, $xmlN, $idlink, $have_Ldata, $idcode, $f_time, $county_check, $allData, $cache_loc; $curlurl = str_replace("http://", '', $url); $urlComponents = explode("/", $curlurl); $domain = $urlComponents[0]; $resourcePath = str_replace($domain, '', $curlurl); $time_start = microtime_float(); $Status .= "\n\n"; $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)'); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); if ($fullMessages == 1) { // use a different timeout while getting $fullMessages curl_setopt($ch, CURLOPT_TIMEOUT, 3); // 3 sec timeout } else { curl_setopt($ch, CURLOPT_TIMEOUT, 5); // 5 sec timeout } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // write the response to a variable $data = curl_exec($ch); if ($data === false) { // could not connect $Status .= "\n\n"; echo "\n * CURL Network error: " . curl_error($ch)."\n" ; $Status .= "\n\n"; } curl_close($ch); $time_stop = microtime_float(); $total_time = ''; $total_time += ($time_stop - $time_start); $time_fetch = sprintf("%01.3f", round($time_stop - $time_start, 3)); $Status .= "\n"; $f_time[] = $time_fetch; if($whichFetch == 0 and strlen($data) > 600) { // write all preliminary alerts $allData[] = $data; $Status .= "\n"; $county_check = "Atom-".$checkCode.".txt"; $fp = fopen($cache_loc.$county_check, "w"); if ($fp) { $write = fwrite($fp, $data); fclose($fp); $Status .= "\n"; } } if($whichFetch == 1 and strlen($data) > 600) { // write full alerts $Status .= "\n"; $code_check = "Atom-".$checkCode.".txt"; $fp = fopen($cache_loc.$code_check, "w"); if($fp) { $write = fputs($fp, $data); fclose($fp); $Status .= "\n"; } } if(isset($checkCode) and strlen($data) < 400) { $Status .= "\n"; echo "*ERROR in fetching data. Cache file not updated. \n"; echo "string length: " . strlen($data) ." \n"; echo "code: " . $checkCode ." \n"; echo "
"; } if(!isset($checkCode) and strlen($data) < 400) { $Status .= "\n"; echo "*ERROR fetching data. Possible cause: Invalid county or zone code. \n"; echo "string length: " . strlen($data) ." \n"; echo "code: unknown \n"; echo "
"; } } // end function curl_fetch_file //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // URL method of fetching data ///////////////////////////////////////////////////////////////////////////////// function GrabURLWithoutHanging($url, $fullMessages = 1, $whichFetch = 0, $checkCode) { // get contents from one URL and return as string // thanks to Tom at Carterlake.org for this script fragment global $curl_debug, $Status, $xmlH, $xmlN, $idlink, $have_Ldata, $idcode, $f_time, $cache_loc; $UA = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)'; // Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed $numberOfSeconds = 4; // Suppress error reporting so Web site visitors are unaware if the feed fails error_reporting(0); // Extract resource path and domain from URL ready for fsockopen $FullUrl = $url; $url = str_replace("http://", '', $url); $urlComponents = explode("/", $url); $domain = $urlComponents[0]; $resourcePath = str_replace($domain, '', $url); $time_start = microtime_float(); $Status .= "\n\n"; // Establish a connection $socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds); if (!$socketConnection) { $Status .= "\n\n"; } else { $data = ''; fputs($socketConnection, "GET $resourcePath HTTP/1.1\r\nHost: $domain\r\nUser-agent: $UA\r\nConnection: close\r\n\r\n"); // Loop until end of file while (!feof($socketConnection)) { $data .= fgets($socketConnection, 4096); } fclose($socketConnection); $time_stop = microtime_float(); $total_time = ''; $total_time += ($time_stop - $time_start); $time_fetch = sprintf("%01.3f", round($time_stop - $time_start, 3)); $f_time[] = $time_fetch; } // end else $Status .= "\n"; if(preg_match("/\r\n\r\n/", $data)) { list($junk, $data) = explode("\r\n\r\n", $data, 2); } if($whichFetch == 0 and strlen($data) > 400) { // write all preliminary alerts $allData[] = $data; $Status .= "\n"; $county_check = "Atom-".$checkCode.".txt"; $fp = fopen($cache_loc.$county_check, "w"); if ($fp) { $write = fwrite($fp, $data); fclose($fp); $Status .= "\n"; } } if($whichFetch == 1 and strlen($data) > 400) { // write full alerts $Status .= "\n"; $code_check = "Atom-".$checkCode.".txt"; $fp = fopen($cache_loc.$code_check, "w"); if($fp) { $write = fputs($fp, $data); fclose($fp); $Status .= "\n"; } } if(isset($checkCode) and strlen($data) < 400) { $Status .= "\n"; echo "*ERROR in fetching data. Cache file not saved. \n"; echo "string length: " . strlen($data) ." \n"; echo "code: " . $checkCode ." \n"; echo "
"; } if(!isset($checkCode) and strlen($data) < 400) { $Status .= "\n"; echo "*ERROR fetching data. Possible cause: Invalid county or zone code. \n"; echo "string length: " . strlen($data) ." \n"; echo "code: unknown \n"; echo "
"; } } // end function GrabURLWithoutHangingRA ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // function to search for a matching alert in t-type and provide the key /////////////////////////////////////////////// function deep_in_array($value, $array) { global $keyB; foreach($array as $keyB => $item) { if(!is_array($item)) { if ($item == $value) { return true; return $keyB; } else continue; } if(in_array($value, $item)) { return true; return $keyB; } else if(deep_in_array($value, $item)) { return true; return $keyB; } } return false; } // end deep_in_array function ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // function to sort array by severity and then by zone code //////////////////////////////////////////////////////////// function u_sort($c, $d){ if($c[18] == $d[18]){ if($c[22] == $d[22]){ return 0; } elseif($c[22] > $d[22]){ return 1; } elseif($c[22] < $d[22]){ return -1; } } elseif($c[18] > $d[18]){ return 1; } elseif($c[18] < $d[18]){ return -1; } } // end u-sort function ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // function to set background color //////////////////////////////////////////////////////////////////////////////////// function set_background($cr_code) { global $bckgrnd, $text_color; if($cr_code >= 0 and $cr_code <= 3) { // warning background $bckgrnd = '#CC0000'; $text_color = 'white'; } if($cr_code >= 4 and $cr_code <= 6) { // watch background $bckgrnd = '#FF9900'; $text_color = 'black'; } if($cr_code == 7) { // advisory background $bckgrnd = '#FFCC00'; $text_color = 'black'; } if($cr_code >= 8 and $cr_code <= 12) { // other background $bckgrnd = '#E6E6E3'; $text_color = 'black'; } if($cr_code >= 13 ) { // none background $bckgrnd = '#E6E6E3'; $text_color = 'black'; } } // end background color ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // microtime function /////////////////////////////////////////////////////////////////////////////////////////////////// function microtime_float() { // mchallis added function // set a timer list($usec, $sec) = explode(" ", microtime()); return ((float) $usec + (float) $sec); } // end function microtime_float ############################################# END FUNCTIONS #################################################################### // copy the work file and rename it if (!copy($a_arrays, $file_output)) { echo "Copying work file to array file failed. Check file permissions if this persists"; $Status .= "\n"; } $time_now = date($timeFormat); $Status .= "\n"; $Status .= "\n"; echo $Status; // writes Status file $Status_file = "AtomStatus.txt"; $fpsf = fopen($Status_file,'wb'); fwrite($fpsf, $Status); fclose($fpsf); // close file ?>