NOAA RSS Advisory 2.0 PHP Script

I added a few features suggested by Ken True:

He said:
"I’d suggest that a detection for PHP5 be inserted in the script, since you’re using simple_xml function and that could save a few trouble calls :slight_smile:

An option to ‘fetch-through’ to the real alert text would be nice so folks don’t get short-changed by the

text display (fetch the link and save the for display if the non-summary mode is active)."

I added detection for installations less than PHP5 and a failure message.

I just added a new feature/setting to workaround the short message problem:
You just download the latest version from the first post, then set $fullMessagesMode = true;
It will fetch (in realtime) the complete message and instructions(if available) for all the messages when alerts are viewed in non-summary mode.

I also added a fine versioning number after the word BETA so you can tell if I have made slight edits or not.
$Version = ‘V2.00 01-Jun-2009 BETA .002’;

Nice work Mike!

:signthanks:
:salute:

Since you are using PHP5, how about a Curl replacement for direct URL file gets?

This would allow a site that has URL file restrictions to still use the script using a Curl alternative.

Then you could use simplexml_load_string instead of simplexml_load_file to parse the same data using a simple switch in the script.

I’ve run into problems a number of times recently where the ISP blocked file URL access but Curl worked fine.

BTW I don’t write for PHP4 any longer.

Ok thanks for the suggestions. Some installations do not have CURL, but most do. I can do a CURL check, then fall back to other way if they do not have CURL.

If anybody still has PHP4 they probably have a compromised server. They need to ask web host to upgrade their account to a server with PHP5.

New Curl version is working on my test server, but I need to adjust a few minor things and have to go out for an hour. I will upload it later.

Just uploaded the new version with CURL support. It took awhile to test all the debugging info you see if you view the source.
V2.00 01-Jun-2009 BETA .004

Any testers?

V2.00 01-Jun-2009 BETA .004 The CURL feature checks out OK with multiple alerts, one alert, no alerts and a bad zone entered.

V2.00 01-Jun-2009 BETA .005 - added proper fail message for when an invalid advisory zone is selected.

update - protect zone value input. allowed zone = [2letters][Z][3numbers]
this is critical because the zone input determines part of the cache file names that are written on the server.

Thanks Mike,

V2.00 01-Jun-2009 BETA .005 installed and seems to be working fine.

John

Mike,

Excellent work! :slight_smile:

I will install tonight to help with the feedback process.

Michael

Wow, ace job there Mike :smiley:

V2.00 02-Jun-2009 BETA .006

file cache improvement - cache files are never written to the server unless there is a valid zone selected or set in settings. Before it would make an empty cache file anyway.

Hi Mike,

Added to a temporary area of my site: http://www.relayweather.com/wxadvisory-2009.php

One thing I noticed is that I loose my background color. Upon investigation, it seems like the script pulls some extra data.

Here is my call:

<?php include("http://www.relayweather.com/rss-advisory-2009.php"); ?>

Take a look at the source of my code. When the script is called it pulls the following “extra” information:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>RSS Advisory Script</title>
</head>
 
<body style="background-color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;">
<!-- rss-advisory-2009.php - V2.00 02-Jun-2009 BETA .006 -->
<!-- getting new file from http://www.weather.gov/alerts-beta/wwaatmget.php?x=MDZ011 -->
<!-- CURL GET /alerts-beta/wwaatmget.php?x=MDZ011 HTTP/1.0 Host: www.weather.gov -->
<!-- Time to fetch: 0.697 sec -->
<!-- cache saved to rss-advisory-2009-MDZ011.txt -->

Is this normal for the script?

Michael

Michael,
Instead of this on your page

 <?php include("http://www.relayweather.com/rss-advisory-2009.php"); ?>

Try this


<?php
 $_REQUEST['zone'] = 'MDZ011';
 $_REQUEST['inc'] = 'Y';
 $_REQUEST['noprint'] = 1;
 include 'rss-advisory-2009.php';
 if (preg_match("|There are no active|i",$advisory_html) ||
     preg_match("|Advisory Information Unavailable|i",$advisory_html)) {
       echo '<div class="advisoryBoxnoactive">' .$advisory_html .'</div>';
 }else{
       echo $advisory_html;
 }
?>

This corrected the problem. Thanks Curly!

V2.00 02-Jun-2009 BETA .007

added a code fix suggested by curly: Sometimes the word " issued" isn’t included in the entry title so it won’t explode properly to “Tornado Watch”.

added more fixes for handling invalid zones - now checks both input and default zone configuration for both syntax and actual existence of the NOAA zone. If a bogus zone is offered, it does not write any cache files and then displays “Advisory Information Unavailable, invalid advisory zone selected.”

Various code cleanup.

I’m using $_REQUEST[‘summary’] = ‘Y’; on a test page (http://www.harpersferry-weather.com/wxadvisory-2009.php). There are no watches, warnings, and advisories. What is returned is a link “Source: NWS Watches, Warnings or Advisories for zone WVZ053” only. I was expecting it should return something like "There are no active watches, warnings or advisories for zone WVZ053. "

<?php $_REQUEST['zone'] = 'WVZ053'; $_REQUEST['inc'] = 'Y'; $_REQUEST['summary'] = 'Y'; $_REQUEST['noprint'] = 1; include 'rrs-advisory-2009.php'; if (preg_match("|There are no active|i",$advisory_html) || preg_match("|Advisory Information Unavailable|i",$advisory_html)) { echo '
' .$advisory_html .'
'; }else{ echo '
' . $advisory_html .'
'; } ?>

John

Thanks for testing. :smiley:
I may have broke something in my last update. 8O
I will test it some more and let you know.

Edit: found the problem… new beta soon.

All the prior beta versions had summary mode broken, this one should be better.

V2.00 02-Jun-2009 BETA .008

Fixed all reported issues:

  • various issues with summary mode, fixed
  • detail page link was not working, fixed

Thanks for testing and reporting errors,
everybody please keep testing. Thanks :slight_smile: :smiley:

Mike,

V2.00 01-Jun-2009 BETA .008 installed and seems to be working fine.

Thanks,
John

Seems to work for me. No errors. Only thing im getting that is odd, is a double advisory box.

http://www.snoqualmieweather.com/wxtest.php

Good Job Mike. Thanks for your time on making a fix for this.