format
// Version 1.03 - 04-Aug-2008 corrected for XHTML 1.0-Strict
// Version 1.04 - 18-Sep-2010 omit .SHP/.KML links
// script available at http://saratoga-weather.org/scripts.php
//
// you may copy/modify/use this script as you see fit,
// no warranty is expressed or implied.
//
// This script gets the current RSS Tropical Cyclone Advisories released by the NHC/TPC
// from www.nhc.noaa.gov/aboutrss.shtml and provides either
// a summary (titles only, with links) or details. It returns
// 'There are no active watches, warnings or advisories'
// if there are no cited hazards in the Zone.
//
// output: creates XHTML 1.0-Strict HTML page (default)
//
// Options on URL:
// inc=Y -- returns only the body code for inclusion
// in other webpages. Omit to return full HTML.
// summary=Y -- returns only the titles of the cited hazards
// N.N or greater.
// zone=[A|P|AS] -- select the zone to use:
// 'A' for Atlantic, Caribbean, and Gulf of Mexico
// 'P' for Eastern Pacific tropical cyclones
// 'AS' for Atlantic in Spanish Language
//
// example URL:
// http://your.website/rss-tropical-test.php?zone=A&inc=Y
// would return data without HTML header/footer for hazards in Atlantic
//
// Usage:
// you can use this webpage standalone (customize the HTML portion below)
// or you can include it in an existing page:
// no parms: include("rss-tropical-test.php");
// parms: include("http://your.website/rss-tropical.test.php?inc=Y&summary=Y&zone=A");
//
//
// settings:
// change $Zone default(below) to your stations county zone
// other settings are outlined below, and are optional
//
// settings ----------------------------------------------------------
if ( ! isset($_REQUEST['zone']) ) {
$_REQUEST['zone']="A"; // <=== Change this default to your Zone
}
$Zone = $_REQUEST['zone'];
$hurlURL = $_SERVER['PHP_SELF']; // <=== change this default to webpage
// to open for details
// on that page, you can have the following PHP
//
// if ( ! isset($_REQUEST['zone']) ) {
// $_REQUEST['zone']="A"; // <=== Change this to your Zone
// }
// $Zone = $_REQUEST['zone'];
//
// include("http://your.website/rss-tropical-test.php?zone=$Zone&inc=Y");
//
//
//
$HD = "h2"; // <=== type of heading for advisorys <$HD>...$HD>
// end of settings -------------------------------------------------
$RSSURL = 'https://www.nhc.noaa.gov/index-at.xml';
if ($Zone == 'P') {
$RSSURL = 'https://www.nhc.noaa.gov/index-ep.xml';
}
if ($Zone == 'AS') {
$RSSURL = 'https://www.nhc.noaa.gov/index-at-sp.xml';
}
// get request parameters
// full html output or just contents (inc=Y)?
if ( ! isset($_REQUEST['inc']) ) {
$_REQUEST['inc']="";
}
$includeOnly = $_REQUEST['inc']; // any nonblank is ok
if ($includeOnly) {$includeOnly = "Y";}
if ( isset($_REQUEST['summary'])) {
$doSummary = TRUE;
} else {
$doSummary = FALSE;
}
// the following is another way to pass the name of the page for testing
if (isset($_REQUEST['detailpage']) ) {
$hurlURL = $_REQUEST['detailpage'];
}
if (isset($_REQUEST['sce']) and $_REQUEST['sce'] == 'view' ) {
$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;
}
// begin code -----------------------------------------------------------
$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";
$lastBuildDate = "";
$tracking = "";
$Summary = "";
$WLink = 0;
$PageTitle = "";
// function for XML parsing .. invoked at start of XML element
function startElement($parser, $name, $attrs) {
global $insideitem, $tag, $title, $description, $link, $lastBuildDate,$doSummary,$Summary, $PageTitle;
if ($insideitem) {
$tag = $name;
} elseif ($name == "ITEM") {
$insideitem = true;
}
if ($name == "LASTBUILDDATE") {
$tag = $name;
}
}
// function for XML parsing .. invoked at end of XML element
// bulk of the work is done here
function endElement($parser, $name) {
global $insideitem, $tag, $title, $description, $link, $lastBuildDate, $tracking,$doSummary,$Summary,$Zone,$hurlURL,$WLink,$HD, $PageTitle;
if ($name == "ITEM") {
if (preg_match('/\.[shp|kml]/i',$title) ) {
$title = "";
$description = "";
$link = "";
$insideitem = false;
return;
}
if (preg_match("|There are no tropical|i",$description)) {
if (! $doSummary) {
printf("%s",htmlspecialchars(trim($description)));
}
$Summary = htmlspecialchars(trim($description));
} else {
$WLink++;
$description = preg_replace("|
|s","
\n",$description);
$description = preg_replace("|href=http([^>]+)>|is","href=\"http\\1\">",$description);
if (! $doSummary) {
printf("<$HD>%s$HD>\n",
trim($link),htmlspecialchars(trim($title)));
// printf("
Updated: %s
\n
%s\n", $lastBuildDate,trim($description)); print "\n"; if (strlen($description) < 100 ) { printf("
%s\n",trim($description)); } else { $nl = strpos($description,"\n"); print "\n"; if ($nl >= 80) { printf("
%s
\n",trim($description)); } else { printf("%s\n",trim($description)); } } } $Summary .= "" . htmlspecialchars(trim($title)) . "