I made a printable weather flyer page to help promote my weather site to locals. The page is specially formatted to be printed as a flier (flyer). All the pertinent weather data should fit on one page. To see how it would look printed, click on “print preview” in your web browser. The flier may be freely used by local hotels, motels, restaurants, businesses, and local government offices to pin on bulletin boards or distribute to their patrons. This is a Plugin Page for the USA.
<?php
require_once('Settings.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-US">
<head>
<?php
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 1);
//ini_set('log_errors', 1);
//ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
require_once('common.php');
require_once('testtags.php');
$wxflyer_version = 'Version: 1.11 - 06-Nov-2009 Carterlake Plugin Page - Printable Weather Flyer by Mike Challis';
// BEGIN SETTINGS --------------------------------------------------------------
// 'www.642weather.com' domain with no http and no slash at end!
// used for identifying your site: "... this discussion continues at www.642weather.com"
$domain = 'www.642weather.com';
// flyerpromo will show on your printable flyer page just after an advisory headline
// example: High Wind Warning - South Washington Coast (Washington)(view at www.642weather.com)
// Note: this setting requires version 2.00 or higher of rss-advisory.php to be installed
$flyerpromo = '<span style="font-size: 11px;"> (view at www.642weather.com)</span>';
// 'Reports from [station name] at [neighborhood]';
$reports_from = 'Reports from Long Beach Weather Station at Sandridge Rd., near Pioneer Rd.';
//$wu_satellite_image = 'http://icons.wunderground.com/data/640x480/pa_ir.gif'; // Northwest USA
$wu_satellite_image = 'http://icons.wunderground.com/data/640x480/pa_ir.gif';
// NWS Area Forecast Discussion URL for your area (must be in text format)
$WRH_URL = 'http://www.crh.noaa.gov/product.php?site=NWS&issuedby=PQR&product=AFD&format=TXT&version=1&glossary=0';
// The rest of the settings are imported from Settings.php
// -------------------------------------------------------
//$site_name = 'Long Beach Weather';
$site_name = $SITE['organ'];
//$location = 'Long Beach, WA 98631';
$location = $SITE['location'];
//$noaazone = 'WAZ021';
$noaazone = $SITE['noaazone'];
//$uomTemp = '&deg;F';
$uomTemp = $SITE['uomTemp'];
//$uomBaro = ' inHg';
$uomBaro = $SITE['uomBaro'];
//$uomWind = ' mph';
$uomWind = $SITE['uomWind'];
//$uomRain = ' in';
$uomRain = $SITE['uomRain'];
// END SETTINGS --------------------------------------------------------------
?>
<title>Printable local weather flyer</title>
<meta name="description" content="Printable local weather flyer for <?php echo $location; ?>. The flyer may be freely used by local hotels, motels, restaurants, businesses, and local government offices" />
<meta name="keywords" content="weather,flier,flyer,forecast,<?php echo $location; ?>" />
<meta http-equiv="content-type" content="application/xhtml+xml; charset=<?php echo $SITE['charset']; ?>" />
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="<?php echo $SITE['CSSscreen']; ?>" media="screen" title="screen" />
<link rel="stylesheet" type="text/css" href="<?php echo $SITE['CSSprint']; ?>" media="print" />
<?php
if (isset($SITE['flyoutmenu']) and $SITE['flyoutmenu'] or
isset($_REQUEST['menu']) and strtolower($_REQUEST['menu']) == 'test' ) {
$SITE['flyoutmenu'] = true;
$PrintFlyoutMenu = false;
$genDiv =false;
global $FlyoutCSS, $FlyoutMenuText;
include_once('flyout-menu.php');
print $FlyoutCSS;
}
?>
<style type="text/css">
.column-flyer {
font-size: 8px;
text-align: left;
}
</style>
</head>
<body>
<div id="page">
<!-- For non-visual user agents: -->
<a href="#main-copy">Skip to main content.</a>
<!-- ##### Header ##### -->
<div id="header">
<h1>
<span style="font-size: 34px;"><b><?php echo $domain ?></b></span>
</h1>
<div>
<?php echo $location; ?>
</div>
<div>Published: <?php echo date("l") . ' ' .$date ?> <?php echo $time ?> <?php echo date('T')?>
</div>
</div>
<?php include("menubar.php"); ?>
<div id="main-copy">
<div>
<h3>Printable local weather flyer for <?php echo $location; ?></h3>
<br />
</div>
<span style="font-size: 14px;">
Notice: This page is specially formatted to be printed as a flyer.
All the pertinent weather data should fit on one page. To see how it would look printed,
click on "print preview" in your web browser.
The flyer may be freely used by local hotels, motels, restaurants, businesses,
and local government offices to pin on bulletin boards or distribute to their patrons.
If you find the flyer useful, please
<a href="wxcontact.php">contact us</a>, we would be happy to know.
<br />
</span>
<div>
<?php
if ( isset($_GET['zone']) ) {
$DefaultZone = $_GET['zone'];
} else {
$DefaultZone = $noaazone;
}
$doSummary = 1; // display alert links, not full alert details
$includeOnly = 1; // include mode
$noprint = 1; // required for echo $advisory_html output
$flyer = 1; // alerts are just the titles without links
include 'atom-advisory.php';
$advisories = 0;
if (preg_match("|There are no active|i",$advisory_html) || preg_match("|Advisory Information Unavailable|i",$advisory_html)) {
// do nothing
}else{
$advisories = 1;
echo '<br /><div>' . $advisory_html .'</div>';
}
?>
<br />
<div align="center">
<?php
$doPrintNWS = false;
require_once("advforecast2.php");
?>
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td colspan="4" valign="top">
<span style="font-size: 18px;"><b>Today's Weather for <?php echo $location; ?></b></span>
</td>
<td rowspan="2" align="center" valign="top">
<img src="<?php echo $wu_satellite_image; ?>?dontcache=<?php echo time(); ?>"
alt="Satellite Image" title="Satellite Image" width="240" height="180"
style="border:1px; border-color:#000000; border-style:solid;" />
</td>
</tr>
<tr>
<td width="20%" align="center" valign="top">
<div style="font-size: 12px;">
<?php print "$forecasticons[0]\n"; ?>
<br />
<?php print "$forecasttemp[0]\n"; ?>
</div></td>
<td width="20%" align="center" valign="top">
<div style="font-size: 12px;">
<?php print "$forecasticons[1]\n"; ?>
<br />
<?php print "$forecasttemp[1]\n"; ?>
</div></td>
<td width="20%" align="center" valign="top">
<div style="font-size: 12px;">
<?php print "$forecasticons[2]\n"; ?>
<br />
<?php print "$forecasttemp[2]\n"; ?>
</div></td>
<td width="20%" align="center" valign="top">
<div style="font-size: 12px;">
<?php print "$forecasticons[3]\n"; ?>
<br />
<?php print "$forecasttemp[3]\n"; ?>
</div></td>
</tr>
</table>
</div>
<p><b><?php print "$forecasttitles[0]\n"; ?></b>
<br /><?php print "$forecasttext[0]\n"; ?></p>
<p><b><?php print "$forecasttitles[1]\n"; ?></b>
<br /><?php print "$forecasttext[1]\n"; ?></p>
<?php
// make a short paragraph of the forecast discussion
$Status = $curl_debug = '';
echo get_forecast_discussion_flyer();
?>
<br />
<br />
<b><?php echo $reports_from; ?></b>
<br />
<table cellpadding="2" cellspacing="0" border="1">
<tr>
<td colspan="2"><b>Rain</b></td><td colspan="2"><b>Wind Gust</b></td><td colspan="2"><b>Sun</b></td><td colspan="2"><b>Moon</b></td>
<td rowspan="4">
<img src="cwp_logo.gif" alt="Citizen Weather Observer Program Logo" title="Citizen Weather Observer Program Logo" width="80" height="80" />
</td>
</tr>
<tr>
<td><b>Yest.</b></td>
<td><?php echo $yesterdayrain ?></td>
<td><b>Yest.</b></td>
<td><?php echo $maxgustyest ?> at <?php echo $maxgustyestt ?></td>
<td><b>Sunrise:</b></td>
<td><?php echo $sunrise ?></td>
<td><b>Moonrise:</b></td>
<td><?php echo $moonrise ?></td>
</tr>
<tr>
<td><b>Month</b></td>
<td><?php echo $monthrn ?></td>
<td><b>Month</b></td>
<td><?php echo $mrecordwindgust ?> <?php echo $uomWind ?> on
<?php echo $mrecordhighgustmonth ?>/<?php echo $mrecordhighgustday ?>/<?php echo $mrecordhighgustyear ?></td>
<td><b>Sunset:</b></td>
<td><?php echo $sunset ?></td>
<td><b>Moonset:</b></td>
<td><?php echo $moonset ?></td>
</tr>
<tr>
<td><b>Year</b></td>
<td><?php echo $yearrn ?></td>
<td><b>Year</b></td>
<td><?php echo $yrecordwindgust ?> <?php echo $uomWind ?> on
<?php echo $yrecordhighgustmonth ?>/<?php echo $yrecordhighgustday ?>/<?php echo $yrecordhighgustyear ?></td>
<td><b>Daylight Hrs:</b></td>
<td><?php echo $hoursofpossibledaylight ?></td>
<td><b>Illuminated:</b></td>
<td><?php echo $moonphase ?></td>
</tr>
</table>
<?php
// when there are more than 2 advisories, hide this table so it might still fit on one page
if ((!$advisories) || ($advisories && $advcount < 3)) {
?>
<br />
<table cellpadding="2" cellspacing="0" border="1">
<tr>
<td colspan="3"><b>Temperature</b></td><td colspan="3"><b>Barometer</b></td>
</tr>
<tr>
<td><b>Yest.</b></td>
<td><b>Hi</b> <?php echo $maxtempyest ?> at <?php echo $maxtempyestt ?></td>
<td><b>Lo</b> <?php echo $mintempyest ?> at <?php echo $mintempyestt ?></td>
<td><b>Yest.</b></td>
<td><b>Hi</b> <?php echo $maxbaroyest ?> at <?php echo $maxbaroyestt ?></td>
<td><b>Lo</b> <?php echo $minbaroyest ?> at <?php echo $minbaroyestt ?></td>
</tr>
<tr>
<td><b>Month</b></td>
<td><b>Hi</b> <?php echo $mrecordhightemp ?> <?php echo $uomTemp ?> on <?php echo $mrecordhightempmonth ?>/<?php echo $mrecordhightempday ?>/<?php echo $mrecordhightempyear ?></td>
<td><b>Lo</b> <?php echo $mrecordlowtemp ?> <?php echo $uomTemp ?> on <?php echo $mrecordlowtempmonth ?>/<?php echo $mrecordlowtempday ?>/<?php echo $mrecordlowtempyear ?></td>
<td><b>Month</b></td>
<td><b>Hi</b> <?php echo $mrecordhighbaro ?> <?php echo $uomRain ?> on <?php echo $mrecordhighbaromonth ?>/<?php echo $mrecordhighbaroday ?>/<?php echo $mrecordhighbaroyear ?></td>
<td><b>Lo</b> <?php echo $mrecordlowbaro ?> <?php echo $uomRain ?> on <?php echo $mrecordlowbaromonth ?>/<?php echo $mrecordlowbaroday ?>/<?php echo $mrecordlowbaroyear ?></td>
</tr>
<tr>
<td><b>Year</b></td>
<td><b>Hi</b> <?php echo $yrecordhightemp ?> <?php echo $uomTemp ?> on <?php echo $yrecordhightempmonth ?>/<?php echo $yrecordhightempday ?>/<?php echo $yrecordhightempyear ?></td>
<td><b>Lo</b> <?php echo $yrecordlowtemp ?> <?php echo $uomTemp ?> on <?php echo $yrecordlowtempmonth ?>/<?php echo $yrecordlowtempday ?>/<?php echo $yrecordlowtempyear ?></td>
<td><b>Year</b></td>
<td><b>Hi</b> <?php echo $yrecordhighbaro ?> <?php echo $uomRain ?> on <?php echo $yrecordhighbaromonth ?>/<?php echo $yrecordhighbaroday ?>/<?php echo $yrecordhighbaroyear ?></td>
<td><b>Lo</b> <?php echo $yrecordlowbaro ?> <?php echo $uomRain ?> on <?php echo $yrecordlowbaromonth ?>/<?php echo $yrecordlowbaroday ?>/<?php echo $yrecordlowbaroyear ?></td>
</tr>
</table>
<?php
} // if ! $advisories
echo '<!-- '.$wxflyer_version." -->\n";
echo "<!-- http://www.642weather.com/weather/scripts.php -->\n\n";
?>
<!-- ##### EOF Main Copy ##### -->
</div>
</div>
<!-- ##### Footer ##### -->
<div align="center">
<?php
echo '<span style="font-size: 11px;"><br />Copyright &copy; '.date('Y').', '.$site_name.'<br />
Forecast by National Weather Service and Satellite Image by Weather Underground (excluded from copyright)</span><br />
<span style="font-size: 8px;">
This weather data provided "as is," and '.$site_name.' disclaims any and all warranties,
whether express or implied, including (without limitation) any implied warranties of merchantability or fitness for a particular purpose.
Never base important decisions that could result in harm to people or property on this weather information.
This weather flyer is freely redistributable without modification provided this notice is preserved.
</span>';
?>
</div>
<?php
// functions -------------------------------------------------------------------
function get_forecast_discussion_flyer() {
//import NWS Area Forecast Discussion
global $domain, $Status, $curl_debug, $WRH_URL;
$cacheName = "./nws-forecast-discussion.txt";
$refetchSeconds = 3600;
$xml = '';
$get_file_failed = 0;
$force =0;
if (isset($_GET['force']) && $_GET['force'] == 1) {
$force = 1;
}
if (!$force and file_exists($cacheName) and filemtime($cacheName) + $refetchSeconds > time()) { //600=10 min
$age = time() - filectime($cacheName);
$nextFetch = $refetchSeconds - $age;
$Status .= "<!-- using cached forecast-discussion version from $cacheName - age=$age secs. Next fetch in $nextFetch secs. -->\n";
//$html = file_get_contents($cacheName);
$xml = implode('', file($cacheName));
if (strlen($xml) < 300) {
$Status .= "<!-- Warning: forecast-discussion cache file size = " . strlen($xml) . " is too small.. fetched data not found. -->\n";
$Status .= "<!-- forecast-discussion Cache file HTML contents: " . htmlspecialchars(strip_tags(str_replace('-->','',trim($xml)))) . " -->\n";
$get_file_failed = 1;
}
}
else {
if (!function_exists('curl_init')) {
$xml = GrabURLWithoutHangingRA($WRH_URL);
$Status .= "<!-- Using fsocketopen to get new forecast-discussion file from $WRH_URL -->\n";
}
else {
$xml = curl_fetch_file($WRH_URL,0);
$Status .= "<!-- Using CURL to get new forecast-discussion file from $WRH_URL -->\n";
}
$Status .= $curl_debug;
$curl_debug = '';
$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("/No data were returned/i", $xml)) {
$xml = 'no data';
}
if ($xml != 'no data') { // 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 .= "<!-- forecast-discussion cache saved to $cacheName -->\n";
}
else {
$Status .= "<!-- forecast-discussion unable to write $cacheName -->\n";
}
}
if (strlen($xml) < 300 && $xml != 'no data') { // not going to be a valid data return, do cache it
$Status .= "<!-- forecast-discussion HTML characters length = " . strlen($xml) . " -->\n";
$Status .= "<!-- HTML headers received: " . htmlspecialchars(strip_tags(trim($junk))) . " -->\n";
$Status .= "<!-- HTML received: " . htmlspecialchars(strip_tags(str_replace('-->','',trim($xml)))) . " -->\n";
$get_file_failed = 1;
}
}
echo $Status;
$html = $xml;
$text = '';
// now slice it up
// some forecast discussions start with "synopsys..." and some start with "short term..."
// make different attempts to select the text
// attempt
preg_match("|synopsis\.\.\.([^&{2}]+)&{2}|is", $html, $betweenspan);
$text = trim($betweenspan[1]);
// attempt
if ($text == '') {
preg_match("|synopsis\.\.\.([^&&]+)&{2}|is", $html, $betweenspan);
$text = trim($betweenspan[1]);
}
// attempt
if ($text == '') {
preg_match("|SHORT TERM \([ a-zA-Z]+\)\.\.\.(.*)LONG TERM|is", $html, $betweenspan);
$text = trim($betweenspan[1]);
}
// attempt
if ($text == '') {
preg_match("|SHORT TERM[ a-zA-Z/]*\.\.\.([^&{2}]+)&{2}|is", $html, $betweenspan);
$text = trim($betweenspan[1]);
}
// attempt
if ($text == '') {
preg_match("|SHORT TERM[ a-zA-Z/]*\.\.\.([^&&]+)&{2}|is", $html, $betweenspan);
$text = trim($betweenspan[1]);
}
// attempt
if ($text == '') {
preg_match("|DISCUSSION\.\.\.(.*)\.PREVIOUS|Us", $html, $betweenspan);
$text = trim($betweenspan[1]);
}
// attempt
if ($text == '') {
preg_match("|DISCUSSION\.\.\.(.*)\.\.\.|Us", $html, $betweenspan);
$text = trim($betweenspan[1]);
}
// attempt
if ($text == '') {
preg_match("|PREV DISCUSSION\.\.\.([^&&]+)&{2}|is", $html, $betweenspan);
$text = trim($betweenspan[1]);
}
if ($text != '') {
$text = ucfirst(htmlspecialchars(strip_tags(strtolower($text))));
$text = truncate_flyer($text,750,'');
// uppercase first word of every sentance
$text = preg_replace('/([\.!\?]\s+|\A)(\w)/e', '"$1" . strtoupper("$2")', $text);
return $text .' ... This discussion continues at '. $domain;
} else {
return '<!-- error: could not find text in forecast discussion -->';
}
} // end function get_forecast_duscussion_flyer
// change the hh:mm AM/PM to h:mmam/pm format
function fixup_time ( $WDtime ) {
return date('g:ia' , strtotime($WDtime));
}
// strip trailing units from a measurement
// i.e. '30.01 in. Hg' becomes '30.01'
function strip_units ($data) {
preg_match('/([\d\.\+\-]+)/',$data,$t);
// print "<!-- '$data'\n";
// print_r($t);
// print "-->\n";
return $t[1];
}
function truncate_flyer($text,$numb,$etc = "...") {
$text = html_entity_decode($text, ENT_QUOTES);
if (strlen($text) > $numb) {
$text = substr($text, 0, $numb);
$text = substr($text,0,strrpos($text,' '));
$punctuation = "!?:;,-"; //punctuation you want removed
$text = (strspn(strrev($text), $punctuation)!=0) ? substr($text, 0, -strspn(strrev($text), $punctuation)) : $text;
$text = $text.$etc;
}
$text = htmlentities($text, ENT_QUOTES);
return $text;
}
?>
</div>
</body>
</html>
&nbsp;