' . $advisory_html .'
';
}
#########
# Include and display full alert details::
# Live example: http://www.642weather.com/weather/advisories.php
#########
to include this with Full advisory output, put the following code in your php page inside php tags:
if ( isset($_GET['zone']) ) {
$DefaultZone = $_GET['zone'];
} else {
$DefaultZone = 'WAZ021'; // set to your NOAA zone
}
$detailpage = 'advisories.php'; // overrides $hurlURL setting
$includeOnly = 1; // include mode
$noprint = 1; // required for echo $advisory_html output
include 'originals-nonphp8/atom-advisory.php';
if (preg_match("|There are no active|i",$advisory_html) ||
preg_match("|Advisory Information Unavailable|i",$advisory_html)) {
echo '/",$html)) {
$Status .= "\n";
$get_file_failed = 2;
}
}
else {
if (!function_exists('curl_init')) {
$xml = GrabURLWithoutHangingRA($RSS_URL);
}
else {
$xml = curl_fetch_file($RSS_URL,0);
}
$Status .= $curl_debug;
$curl_debug = '';
// mchallis added to format cap code tags
$xml = str_replace("cap:", 'cap_', $xml);
$xml = str_replace('/&//&/', '', $xml);
$junk = 'n/a';
if (preg_match("/\r\n\r\n/", $xml)) {
list($junk, $xml) = explode("\r\n\r\n", $xml, 2);
}
if ($xml == '') {
$xml = $junk; // curl method does not have the headers
$junk = 'n/a';
}
if (preg_match("/invalid zone/i", $xml)) {
$xml = 'invalid zone';
}
if ($xml != 'invalid zone') { // not going to be a valid data return, do not cache it
$fp = fopen($cacheName, "w");
if ($fp) {
$write = fputs($fp, $xml);
fclose($fp);
$Status .= "\n";
}
else {
$Status .= "\n";
}
}
if (strlen($xml) < 300 && $xml != 'invalid zone') { // not going to be a valid data return, do cache it
$Status .= "\n";
$Status .= "\n";
$Status .= "','',trim($xml)))) . " -->\n";
$get_file_failed = 1;
}
}
} else {
$xml = 'invalid zone';
}
if (!$includeOnly) { // omit HTML headers if doing inc=Y
$string .= '
RSS Advisory Script
';
if (!$includeOnly and $doSummary) {
$string .= "\n";
} // for XHTML 1.0-Strict validation
} // end .. only printed if full html needed
// all output from program goes into $advisory_html
if ($xml == 'invalid zone') {
$advisory_html = "{$string}{$Status}
Advisory Information Unavailable, invalid advisory zone selected.
";
}
else if ($get_file_failed == 1) {
$advisory_html = "{$string}{$Status}" . graceful_error();
}
else if ($get_file_failed == 2) {
$advisory_html = "{$string}{$Status}Advisory Information Unavailable, cache file conflict, view source for details.
";
}
else {
$advisory_html = advisory_main_code();
}
$advisory_html .= "\n";
if (!$includeOnly) {
if (!$includeOnly and $doSummary) {
$advisory_html .= "\n";
}
$advisory_html .= '
';
} // end !$includeOnly - only printed if full html wanted (no inc=Y)
if (!$includeOnly || !$noprint) {
echo $advisory_html;
$advisory_html = "\n";
}
// ---------------------------- functions -----------------------------------
function advisory_main_code() {
// mchallis added
global $Summary, $HD, $hurlURL, $RSS_URL, $timeFormat, $fullMessagesMode, $doLongTitles, $doZoneTitles, $advcount, $enable_alert_icons, $icons_folder;
global $doSummary, $Zone, $WLink, $cacheName, $includeOnly, $string, $Status, $doLowerCase, $flyer, $flyerpromo;
$string .= $Status;
if (!$xml = @ simplexml_load_file($cacheName)) {
return graceful_error();
}
foreach ($xml->entry as $entry) {
/*
available 'entry' fields from the xml:
$entry->id (url)
$entry->updated (time) 2009-05-30T15:50:00-08:00
$entry->title (alert name)
$entry->summary (details)
$entry->cap_effective (time) 2009-05-30T15:50:00-08:00
$entry->cap_expires (time) 2009-05-31T16:00:00-08:00
$entry->cap_status
$entry->cap_msgType
$entry->cap_category
$entry->cap_urgency
$entry->cap_severity
$entry->cap_certanty
$entry->cap_areaDesc ( location(s) )
*/
$title = htmlspecialchars(strip_tags(trim($entry->title)));
$entry->summary = str_replace('/&//&/', '', $entry->summary);
if ($enable_alert_icons && !is_file($icons_folder.'/iconkey.png')) {
$icons_warning = '(Script settings error: Alert icons are enabled but cannot be found by the script. Check the settings for $icons_folder.)
';
} else {
$icons_warning = '';
}
if (preg_match("|There are no active|i", $title)) {
if ($doZoneTitles) {
$zone_name = preg_match("/Advisories for (.*)\(.*\)(.*) Issued by/", trim($xml->title), $matches);
$zone_name = $matches[1].'('.trim($matches[2]).')';
if (!$doSummary) {
$string .= '' . $icons_warning.$title . " for $zone_name.
";
}
// "There are no active watches, warnings or advisories for $Zone"
$Summary = $icons_warning.$title . " for $zone_name.";
} else {
if (!$doSummary) {
$string .= '' . $icons_warning.$title . " for zone $Zone.
";
}
// "There are no active watches, warnings or advisories for $Zone"
$Summary = $icons_warning.$title . " for zone $Zone.";
}
}
else {
// title with zone name in it.
if (!$WLink && !$doSummary)
$string .= "<$HD>" . htmlspecialchars(strip_tags(trim($xml->title))) . "$HD>\n\n";
if (preg_match("| issued|", $title)) {
//echo '|'.$title.'|(issued)'; // debugging
$title = explode(" issued", $title);
}
else {
//echo '|'.$title.'|(date)'; // debugging
$title = explode(date("Y"), $title);
}
$title = $title[0];
$alert_icon_arr = find_alert_icon(trim($title));
if ($enable_alert_icons && !$icons_warning) {
$this_icon = ' ';
} else {
$this_icon = '';
}
// find the zone name: South Washington Coast (Washington)
// in this string: 'Current Watches, Warnings and Advisories for South Washington Coast (WAZ021) Washington Issued by the National Weather Service';
if ($doLongTitles) {
$zone_name = preg_match("/Advisories for (.*)\(.*\)(.*) Issued by/", trim($xml->title), $matches);
$title .= ' - '.$matches[1].'('.trim($matches[2]).')';
}
$WLink++;
if (!$doSummary) {
$string .= '
<'.$HD.'>'.$icons_warning.$this_icon."id) . '" title="Click to view this statement at the NWS" style="color: '. $alert_icon_arr['color'] .'">' . $title . "$HD>\n";
$updated_date = date($timeFormat, strtotime($entry->updated));
$string .= "\n";
$string .= ' |
|
';
$string .= "\n";
$string .= "\n";
$string .= "Updated: | " . $updated_date . " | \n";
$string .= " \n";
$string .= "Effective: | " . date($timeFormat, strtotime($entry->cap_effective)) . " | \n";
$string .= " \n";
$string .= "Expires: | " . date($timeFormat, strtotime($entry->cap_expires)) . " | \n";
$string .= " \n";
$string .= " \n";
$string .= " | \n";
$string .= "\n";
$string .= "\n";
$string .= 'Severity: | ' . htmlspecialchars(strip_tags(trim($entry->cap_severity))) . " | \n";
$string .= " \n";
$string .= "Urgency: | ";
if (trim($entry->cap_urgency) == 'Immediate') {
$string .= '' . htmlspecialchars(strip_tags(trim($entry->cap_urgency))) . '';
}
else {
$string .= htmlspecialchars(strip_tags(trim($entry->cap_urgency)));
}
$string .= " | \n";
$string .= " \n";
$string .= "Certainty: | " . htmlspecialchars(strip_tags(trim($entry->cap_certainty))) . " | \n";
$string .= " \n";
$string .= " \n";
$string .= " | \n";
$string .= "\n";
$string .= "\n";
$string .= "Status: | " . htmlspecialchars(strip_tags(trim($entry->cap_status))) . " | \n";
$string .= " \n";
$string .= "Type: | " . htmlspecialchars(strip_tags(trim($entry->cap_msgType))) . " | \n";
$string .= " \n";
$string .= "Category: | " . htmlspecialchars(strip_tags(trim($entry->cap_category))). " | \n";
$string .= " \n";
$string .= " \n";
$string .= ' |
|
';
$string .= "Areas affected: " . htmlspecialchars(strip_tags(trim($entry->cap_areaDesc))) . ' |
|
';
if ($fullMessagesMode) {
$FMarray = get_full_message(trim($entry->id));
if (is_array($FMarray)) { // if it came back a string, fall back to $fullMessagesMode off
$entry->summary = $FMarray['description'];
if ($FMarray['instruction'] != '') { // instructions are not included in all alerts
if ($doLowerCase) {
// uppercase first word of every sentence
$FMinstruction = ucfirst(htmlspecialchars(strip_tags(strtolower($FMarray['instruction']))));
# $FMinstruction = preg_replace('/([\.!\?]\s+|\A)(\w)/e', '"$1" . strtoupper("$2")', $FMinstruction);
$FMinstruction = preg_replace_callback('/([\.!\?]\s+|\A)(\w)/',
function ($matches) { return($matches[1] . strtoupper($matches[2])); },
$FMinstruction);
$string .= 'Instructions: ' . $FMinstruction;
}
else {
$string .= 'Instructions: ' . trim(htmlspecialchars(strip_tags($FMarray['instruction'])));
}
$string .= "
\n";
}
} // end if is_array
} // end if $fullMessagesMode
if ($doLowerCase) {
// uppercase first word of every sentence
$FMsummary = trim($entry->summary);
$FMsummary = ucfirst(htmlspecialchars(strip_tags(strtolower($FMsummary))));
# $FMsummary = preg_replace('/([\.!\?]\s+|\A)(\w)/e', '"$1" . strtoupper("$2")', $FMsummary);
$FMsummary = preg_replace_callback('/([\.!\?]\s+|\A)(\w)/',
function ($matches) {return ( $matches[1] . strtoupper($matches[2])); },
$FMsummary);
}
else {
$FMsummary = trim($entry->summary);
$FMsummary = htmlspecialchars(strip_tags($FMsummary));
}
// line break corrections
$FMsummary = preg_replace('/\.\.\.\n/', '... ', $FMsummary);
$FMsummary = preg_replace('/\n\.\.\./', ' ...', $FMsummary);
$FMsummary = preg_replace('/\n\*/', ' *', $FMsummary);
$string .= 'Message summary: ' . $FMsummary;
if ($FMsummary != 'This alert has expired')
$string .= " ...id) . "\">view the complete message\n";
$string .= " |
\n";
}
// mchallis modified for flyer usage
if ($flyer) {
$Summary .= '' . htmlspecialchars(strip_tags(trim($title))) . "$flyerpromo
\n";
}
else {
$Summary .= "".$this_icon."" . htmlspecialchars(strip_tags(trim($title))) . "
\n";
}
$advcount++;
}
$title = '';
$link = '';
} // end foreach
if ($doSummary) {
$string .= $Summary;
// mchallis modified for flyer usage
if ($WLink && !$flyer) {
$string .= "Click on link";
if ($WLink > 1) {$string .= "s";}
$string .= " above to see details on the $WLink NOAA advisor";
if ($WLink > 1) {$string .= "ies"; } else { $string .= "y"; };
$string .= " for zone $Zone.\n";
}
}
if ($WLink && !$doSummary) {
$string .= "\n";
if ($enable_alert_icons) {
$string .= 'Icon Legend: Icon key
';
}
$string .= "Source: NWS Watches, Warnings or Advisories for zone $Zone\n
";
}
return $string;
} // end function advisory_main_code
// ------------------------------------------------------------------
function get_full_message($url) {
// mchallis added to get full contents of alert messages in real time
global $string, $curl_debug;
if (!function_exists('curl_init')) { // some do not have CURL
$string .= "\n";
if (!$xml = @ simplexml_load_file($url)) {
$string .= "\n";
return 'failed';
}
}
else { // use CURL
$xml = curl_fetch_file($url,1);
$string .= "\n";
$string .= $curl_debug;
if (!$xml = @ simplexml_load_string($xml)) {
$string .= "\n";
return 'failed';
}
}
$FMarray = array();
$FMarray['instruction'] = trim($xml->info->instruction);
$FMarray['description'] = trim($xml->info->description);
$FMarray['description'] = str_replace('/&//&/', '', $FMarray['description']);
//print_r($xml); // for debugging
return $FMarray;
} // end function get_full_message
// ------------------------------------------------------------------
function find_alert_icon($title){
// This function searches all alert titles to assign color code, severity, and icon
// function code by (mchallis) mike challis, inspired by curly's AtomFeed.php
$a = array();
$alert_types = array (
// looking for warning
array('N'=>'Ashfall Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'EWW.gif'),
array('N'=>'Avalanche Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSW.gif'),
array('N'=>'Blizzard Warning', 'C'=>'#D00', 'S'=>'1', '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'=>'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'=>'Heavy Freezing Spray Warning', 'C'=>'#F60', 'S'=>'6', 'I'=>'SWA.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'=>'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'=>'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'=>'Severe Thunderstorm Warning', 'C'=>'#B11', 'S'=>'1', 'I'=>'SVR.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'=>'Tornado Warning', 'C'=>'#A00', 'S'=>'0', 'I'=>'TOR.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'=>'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'),
array('N'=>'Winter Storm Warning', 'C'=>'#D00', 'S'=>'1', 'I'=>'WSW.gif'),
array('N'=>'Winter Weather Warning', 'C'=>'#D00', 'S'=>'1', 'I'=>'WSW.gif'),
array('N'=>'Storm Warning', 'C'=>'#D00', 'S'=>'2', 'I'=>'SVR.gif'),
// looking for watch
array('N'=>'Avalanche Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'WSA.gif'),
array('N'=>'Blizzard Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'WSA.gif'),
array('N'=>'Coastal Flood Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'CFA.gif'),
array('N'=>'Excessive Heat Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'EHA.gif'),
array('N'=>'Extreme Cold Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'HZA.gif'),
array('N'=>'Flash Flood Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'FFA.gif'),
array('N'=>'Fire Weather Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'FWA.gif'),
array('N'=>'Flood Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'FFA.gif'),
array('N'=>'Freeze Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'FZA.gif'),
array('N'=>'Gale Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'GLA.gif'),
array('N'=>'Hard Freeze Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'HZA.gif'),
array('N'=>'Hazardous Seas Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'SUY.gif'),
array('N'=>'Heavy Freezing Spray Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'SWA.gif'),
array('N'=>'High Wind Watch', 'C'=>'#F33', 'S'=>'4', 'I'=>'WIY.gif'),
array('N'=>'Hurricane Force Wind Watch', 'C'=>'#F33', 'S'=>'4', 'I'=>'HWW.gif'),
array('N'=>'Hurricane Watch', 'C'=>'#F33', 'S'=>'4', 'I'=>'HUA.gif'),
array('N'=>'Hurricane Wind Watch', 'C'=>'#F33', 'S'=>'4', 'I'=>'HWW.gif'),
array('N'=>'Lake Effect Snow Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'WSA.gif'),
array('N'=>'Lakeshore Flood Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'FFA.gif'),
array('N'=>'Severe Thunderstorm Watch', 'C'=>'#F31', 'S'=>'4', 'I'=>'SVA.gif'),
array('N'=>'Tornado Watch', 'C'=>'#F33', 'S'=>'3', 'I'=>'TOA.gif'),
array('N'=>'Tropical Storm Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'TRA.gif'),
array('N'=>'Tropical Storm Wind Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'WIY.gif'),
array('N'=>'Tsunami Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'WSA.gif'),
array('N'=>'Typhoon Watch', 'C'=>'#F33', 'S'=>'4', 'I'=>'HUA.gif'),
array('N'=>'Wind Chill Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'WCA.gif'),
array('N'=>'Winter Storm Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'SRA.gif'),
array('N'=>'Winter Weather Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'WSA.gif'),
array('N'=>'Storm Watch', 'C'=>'#F33', 'S'=>'5', 'I'=>'SRA.gif'),
// looking for advisory
array('N'=>'Air Stagnation Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'SCY.gif'),
array('N'=>'Ashfall Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'WSW.gif'),
array('N'=>'Blowing Dust Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'HWW.gif'),
array('N'=>'Blowing Snow Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'WSA.gif'),
array('N'=>'Coastal Flood Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'FLS.gif'),
array('N'=>'Small Craft Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'SCY.gif'),
array('N'=>'Dense Fog Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'FGY.gif'),
array('N'=>'Dense Smoke Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'SMY.gif'),
array('N'=>'Brisk Wind Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'WIY.gif'),
array('N'=>'Flash Flood Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'FLS.gif'),
array('N'=>'Flood Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'FLS.gif'),
array('N'=>'Freezing Drizzle Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'SWA.gif'),
array('N'=>'Freezing Fog Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'FZW.gif'),
array('N'=>'Freezing Rain Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'SWA.gif'),
array('N'=>'Freezing Spray Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'SWA.gif'),
array('N'=>'Frost Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'FRY.gif'),
array('N'=>'Heat Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'HTY.gif'),
array('N'=>'High Surf Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'SUY.gif'),
array('N'=>'Hydrologic Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'FLS.gif'),
array('N'=>'Lake Effect Snow Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'WSA.gif'),
array('N'=>'Lake Effect Snow and Blowing Snow Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'WSA.gif'),
array('N'=>'Lake Wind Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'LWY.gif'),
array('N'=>'Lakeshore Flood Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'FLS.gif'),
array('N'=>'Low Water Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'FFA.gif'),
array('N'=>'Sleet Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'SWA.gif'),
array('N'=>'Snow Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'WSA.gif'),
array('N'=>'Snow and Blowing Snow Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'WSA.gif'),
array('N'=>'Tsunami Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'SWA.gif'),
array('N'=>'Wind Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'WIY.gif'),
array('N'=>'Wind Chill Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'WCY.gif'),
array('N'=>'Winter Weather Advisory', 'C'=>'#F60', 'S'=>'6', 'I'=>'WWY.gif'),
// looking for statement
array('N'=>'Coastal Flood Statement', 'C'=>'#C70', 'S'=>'7', 'I'=>'FFS.gif'),
array('N'=>'Flash Flood Statement', 'C'=>'#C70', 'S'=>'7', 'I'=>'FFS.gif'),
array('N'=>'Flood Statement', 'C'=>'#C70', 'S'=>'7', 'I'=>'FFS.gif'),
array('N'=>'Hurricane Statement', 'C'=>'#C70', 'S'=>'7', 'I'=>'HUA.gif'),
array('N'=>'Lakeshore Flood Statement', 'C'=>'#C70', 'S'=>'7', 'I'=>'FFS.gif'),
array('N'=>'Marine Weather Statement', 'C'=>'#C70', 'S'=>'7', 'I'=>'MWS.gif'),
array('N'=>'Public Information Statement', 'C'=>'#C70', 'S'=>'7', 'I'=>'PNS.gif'),
array('N'=>'River Flood Statement', 'C'=>'#C70', 'S'=>'7', 'I'=>'FLS.gif'),
array('N'=>'River Statement', 'C'=>'#C70', 'S'=>'7', 'I'=>'RVS.gif'),
array('N'=>'Severe Weather Statement', 'C'=>'#F33', 'S'=>'7', 'I'=>'SVS.gif'),
array('N'=>'Special Weather Statement', 'C'=>'#C70', 'S'=>'7', 'I'=>'SPS.gif'),
array('N'=>'Tropical Statement', 'C'=>'#C70', 'S'=>'7', 'I'=>'HLS.gif'),
array('N'=>'Typhoon Statement', 'C'=>'#C70', 'S'=>'7', 'I'=>'TRA.gif'),
// looking for other misc. things
array('N'=>'Air Quality Alert', 'C'=>'#06C', 'S'=>'8', 'I'=>'SPS.gif'),
array('N'=>'Significant Weather Alert', 'C'=>'#F33', 'S'=>'4', 'I'=>'SWA.gif'),
array('N'=>'Child Abduction Emergency', 'C'=>'#093', 'S'=>'10', 'I'=>'SPS.gif'),
array('N'=>'Civil Emergency Message', 'C'=>'#093', 'S'=>'4', 'I'=>'SPS.gif'),
array('N'=>'Local Area Emergency', 'C'=>'#093', 'S'=>'4', 'I'=>'SPS.gif'),
array('N'=>'Extreme Fire Danger', 'C'=>'#D00', 'S'=>'2', 'I'=>'WSW.gif'),
array('N'=>'Coastal Hazard', 'C'=>'#C70', 'S'=>'7', 'I'=>'CFS.gif'),
array('N'=>'Short Term', 'C'=>'#093', 'S'=>'9', 'I'=>'NOW.gif'),
array('N'=>'911 Telephone Outage', 'C'=>'#36C', 'S'=>'11', 'I'=>'SPS.gif'),
array('N'=>'Evacuation Immediate', 'C'=>'EA00', 'S'=>'2', 'I'=>'SVW.gif'),
// looking for no active
array('N'=>'no active', 'C'=>'#333', 'S'=>'', 'I'=>''),
);
// loop through the $alert_types array now
foreach ($alert_types as $a_type) {
if(strpos($title,$a_type['N']) !== false){
$a['color'] = $a_type['C'];
$a['severity'] = $a_type['S'];
$a['icon'] = $a_type['I'];
return $a; // found it so just return out of this function now
}
}
// still did not find anything....
// assign a default for each alert type
if (strpos($title,"Warning") !== false) {
$a['color'] = "#D11";
$a['severity'] = 2;
$a['icon'] = 'SVW.gif';
return $a; // found it so just return now
}
if (strpos($title,"Watch") !== false) {
$a['color'] = "#F30";
$a['severity'] = 4;
$a['icon'] = 'SWA.gif';
return $a; // found it so just return now
}
if (strpos($title,"Advisory") !== false) {
$a['color'] = "#F60";
$a['severity'] = 6;
$a['icon'] = 'SWA.gif';
return $a; // found it so just return now
}
if (strpos($title,"Statement") !== false) {
$a['color'] = "#C70";
$a['severity'] = 7;
$a['icon'] = 'SWA.gif';
return $a; // found it so just return now
}
if (strpos($title,"Air") !== false) {
$a['color'] = "#06C";
$a['severity'] = 8;
$a['icon'] = 'SPS.gif';
return $a; // found it so just return now
}
if (strpos($title,"Short") !== false) {
$a['color'] = "#093";
$a['severity'] = 9;
$a['icon'] = 'NOW.gif';
return $a; // found it so just return now
}
if (strpos($title,"Emergency") !== false) {
$a['color'] = "#093";
$a['severity'] = 4;
$a['icon'] = 'SPS.gif';
return $a; // found it so just return now
}
if (strpos($title,"Outage") !== false) {
$a['color'] = "#36C";
$a['severity'] = 11;
$a['icon'] = 'SPS.gif';
return $a; // found it so just return now
}
if (strpos($title,"no active") !== false) {
$a['color'] = "#333";
$a['severity'] = 14;
$a['icon'] = ''; // this might need a 'no active' icon?
}
// wow, all the way down here and did not match any alerts...
// well then here is some kind of default for nothing found.
$a['color'] = "#333";
$a['severity'] = 14;
$a['icon'] = 'SPS.gif';
return $a;
} // end function find_alert_icon
// ------------------------------------------------------------------
function GrabURLWithoutHangingRA($url) {
// force https access to alerts.weather.gov and use file_get_contents()
global $Status;
$URL = str_replace('http://alerts.weather.gov/','https://alerts.weather.gov/',$url);
$Status .= "\n";
$TOTALtime = 0;
$STRopts = array(
'http'=>array(
'method'=>"GET",
'protocol_version' => 1.1,
'header'=>"Cache-Control: no-cache, must-revalidate\r\n" .
"Cache-control: max-age=0\r\n" .
"Connection: close\r\n" .
"User-agent: Mozilla/5.0 ($Version, saratoga-weather.org)\r\n" .
"Accept: text/plain,text/html\r\n"
),
'https'=>array(
'method'=>"GET",
'protocol_version' => 1.1,
'header'=>"Cache-Control: no-cache, must-revalidate\r\n" .
"Cache-control: max-age=0\r\n" .
"Connection: close\r\n" .
"User-agent: Mozilla/5.0 ($Version, saratoga-weather.org)\r\n" .
"Accept: text/plain,text/html\r\n"
)
);
$STRcontext = stream_context_create($STRopts);
$T_start = microtime_float();
$xml = file_get_contents($URL,false,$STRcontext);
$headerarray = get_headers($URL,0);
$theaders = join("\r\n",$headerarray);
$xml = $theaders . "\r\n\r\n" . $xml;
$T_close = microtime_float();
$ms_total = sprintf("%01.3f",round($T_close - $T_start,3));
$Status .= "\n";
$Status .= "\n";
$Status .= "\n";
return($xml);
} // end function GrabURLWithoutHangingRA
// ------------------------------------------------------------------
function curl_fetch_file($url, $fullMessages = 0) {
// mchallis added get contents from one URL using a CURL call and return as string
global $curl_debug, $fullMessagesMode;
$URL = str_replace('http://alerts.weather.gov/','https://alerts.weather.gov/',$url);
$curl_debug .= "\n";
$curlurl = str_replace("http://", '', $url);
$urlComponents = explode("/", $curlurl);
$domain = $urlComponents[0];
$resourcePath = str_replace($domain, '', $curlurl);
$curl_debug .= "\n";
$time_start = microtime_float();
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)');
curl_setopt($ch, CURLOPT_URL, $URL);
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, 15); // 15 sec timeout
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // write the response to a variable
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); // don't require peer verification
$data = curl_exec($ch);
if ($data === false) {
// could not connect
$curl_debug .= '\n";
$fullMessagesMode = false; // turn off $fullMessagesMode to shorten timeouts
}
curl_close($ch);
$time_stop = microtime_float();
$total_time = 0.0;
$total_time += ($time_stop - $time_start);
$time_fetch = sprintf("%01.3f", round($time_stop - $time_start, 3));
$curl_debug .= "\n";
//echo $data;
return $data;
} // end function curl_fetch_file
// ------------------------------------------------------------------
function microtime_float() {
// set a timer
list($usec, $sec) = explode(" ", microtime());
return ((float) $usec + (float) $sec);
} // end function microtime_float
// ------------------------------------------------------------------
function graceful_error() {
// mchallis added graceful error function so your site stays with valid HTML after soft errors
global $RSS_URL;
$returnstring = "Advisory Information Unavailable, error fetching or reading data from the NOAA advisories server.
\n";
return $returnstring;
} // end function graceful_error
// ------------------------------------------------------------------
?>