time() // Version 1.03 - 18-Jan-2022 - fix for extract of source HTML Charset to use // Version 1.04 - 27-Dec-2022 - fixes for PHP 8.1 // Version 1.05 - 09-Feb-2023 - fixes for PHP 8.2 and Notice errata // $Version = "V1.05 - 09-Feb-2023"; // // Settings: // --------- start of settings ---------- // // Go to http://weather.gc.ca/lightning/index_e.html // Click on the desired area page. // You should see a lightning page with an url like // http://weather.gc.ca/lightning/index_e.html?id=XXX // copy the three letter area id=XXX into $lightningID = 'XXX'; below // $lightningID = 'NAT'; // set to default Site for lightning (same as id=xxx on EC website) // // available sites: NAT ARC PAC WRN ONT QUE ATL $defaultLang = 'en'; // set to 'fr' for french default language // // set to 'en' for english default language // $lightningCacheName = 'ec-lightning.txt'; // note: will be changed to -en.txt or // -fr.txt depending on language choice and stored in $lightningDir $lightningDir = './radar/'; // directory for storing lightning-XXX-0.png to lightning-XXX-6.png images // note: relative to document root. $lightningWidth = 620; // width of images to output in pixels. default=620 // $refetchSeconds = 300; // look for new images from EC every 5 minutes (300 seconds) // NOTE: EC may take up to 20 minutes to publish new images $noLightningMinutes = 25; // minutes to wait before declaring the image site as 'N/O -not operational' // $aniSec = 1; // number of seconds between animations // $charsetOutput = 'ISO-8859-1'; // default character encoding of output // ---------- end of settings ----------- //------------------------------------------------ // overrides from Settings.php if available global $SITE; if (isset($SITE['eclightningID'])) {$lightningID = $SITE['eclightningID'];} if (isset($SITE['defaultlang'])) {$defaultLang = $SITE['defaultlang'];} if (isset($SITE['charset'])) {$charsetOutput = strtoupper($SITE['charset']); } // end of overrides from Settings.php if available // // ---------- main code ----------------- if (isset($_REQUEST['sce']) && strtolower($_REQUEST['sce']) == 'view' ) { //--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,charset=ISO-8859-1"); header("Accept-Ranges: bytes"); header("Content-Length: $download_size"); header('Connection: close'); readfile($filenameReal); exit; } //error_reporting(E_ALL); // uncomment to turn on full error reporting $hasUrlFopenSet = ini_get('allow_url_fopen'); if(!$hasUrlFopenSet) { print "
To fix, add the statement:
allow_url_fopen = on;\n\nto your php.ini file to enable ec-lightning.php operation.\n"; return; } $t = pathinfo(__FILE__); // get our program name for the HTML comments $Program = $t['basename']; $Status = "\n"; $printIt = true; if(isset($_REQUEST['inc']) && strtolower($_REQUEST['inc']) == 'y' or (isset($doInclude) and $doInclude)) {$doInclude = true;} if(isset($doPrint)) { $printIt = $doPrint; } if(! isset($doInclude)) {$doInclude = false; } if(isset($_REQUEST['id'])) { $lightningID = strtoupper($_REQUEST['id']); } $lightningID = preg_replace('|[^A-Z]+|s','',$lightningID); // Make sure only alpha in siteID if(strlen($lightningID) <> 3) { print "
Sorry... area id '$lightningID' is not a valid EC area site name.
\n"; return; } if (isset($_REQUEST['cache']) && (strtolower($_REQUEST['cache']) == 'no') ) { $forceRefresh = true; } else { $forceRefresh = false; } if (isset($doAutoPlay)) { $autoPlay = $doAutoPlay; } elseif (isset($_REQUEST['play']) && (strtolower($_REQUEST['play']) == 'no') ) { $autoPlay = false; } else { $autoPlay = true; } if (isset($_REQUEST['imgonly']) && (strtolower($_REQUEST['imgonly']) == 'y')) { $imageOnly = true; // just return the latest thumbnail image after processing $printIt = false; // and don't spoil the image with any other stuff } else { $imageOnly = false; } if (isset($_REQUEST['lang'])) { $Lang = strtolower($_REQUEST['lang']); } if (isset($doLang)) {$Lang = $doLang;}; if (! isset($Lang)) {$Lang = $defaultLang;}; if ($Lang == 'fr') { $LMode = 'f'; $ECLNAME = "Environnement Canada"; $ECLHEAD = 'Carte canadienne du risque de foudre'; $ECLNO = 'N/O - Non opérationnel'; $ECLNoJS = 'Pour voir l\'animation, il faut que JavaScript soit en fonction.'; $ECLPlay = 'Animer - Pause'; $ECLPrev = 'Image précédente'; $ECLNext = 'Prochaine image'; } else { $Lang = 'en'; $LMode = 'e'; $ECLNAME = "Environment Canada"; $ECLHEAD = 'Canadian Lightning Danger Map'; $ECLNO = 'N/O - Non-operational'; $ECLNoJS = 'Please enable JavaScript to view the animation.'; $ECLPlay = 'Play - Stop'; $ECLPrev = 'Previous'; $ECLNext = 'Next'; } $lightningCacheName = preg_replace('|.txt$|',"-$Lang.txt",$lightningCacheName); // if (isset($_SERVER['DOCUMENT_ROOT'])) { $ROOTDIR = $_SERVER['DOCUMENT_ROOT']; } else { $ROOTDIR = '.'; } $cacheDir = $lightningDir; $imageDir = $lightningDir; $Status .= "\n\n"; date_default_timezone_set( @date_default_timezone_get()); $Status .= "\n"; $ECLSizes = array ( // image sizes w,h 'NAT' => '850,633', 'ARC' => '850,646', 'PAC' => '667,700', 'WRN' => '795,700', 'ONT' => '764,700', 'QUE' => '622,700', 'ATL' => '792,700', ); if ( !isset($ECLSizes[$lightningID]) ) { print "Use one of the following as id: "; foreach ($ECLSizes as $key => $val) { print "$key "; } print " and retry.
\n"; return; } list($ECLbaseW,$ECLbaseH) = explode(',',$ECLSizes[$lightningID]); $new_width = $lightningWidth; $new_height = round($ECLbaseH * ($lightningWidth / $ECLbaseW),0); $thumb_width = 290; $thumb_height = round($ECLbaseH * (290 / $ECLbaseW),0); // all settings and overrides now loaded ... begin processing $Status .= "\n"; $lightningCacheName = preg_replace('|.txt$|',"-".$lightningID.".txt",$lightningCacheName); $RawImgURL = "https://weather.gc.ca"; $ECLURL = 'https://weather.gc.ca/lightning/index_' . $LMode . '.html?id=' . $lightningID; if($Lang == 'fr') { $RawImgURL = preg_replace('|weather|i','meteo',$RawImgURL); $ECLURL = preg_replace('|weather|i','meteo',$ECLURL); $Status .= "\n"; } $RealCacheName = $cacheDir . $lightningCacheName; $reloadImages = false; // assume we don't have to reload unless a newer image set is around if(file_exists($RealCacheName)) { $lastCacheTime = filemtime($RealCacheName); } else { $lastCacheTime = time(); $forceRefresh = true; } $lastCacheTimeHM = gmdate("Y-m-d H:i:s",$lastCacheTime) . " UTC"; $NOWgmtHM = gmdate("Y-m-d H:i:s",time()) . " UTC"; $diffSecs = time() - $lastCacheTime; $Status .= "\n"; if(isset($_GET['force']) | isset($_GET['cache'])) {$refetchSeconds = 0;} if($diffSecs > $refetchSeconds) {$forceRefresh = true;} $Status .= "\n"; // refresh cached copy of page if needed // fetch/cache code by Tom at carterlake.org if (! $forceRefresh) { $Status .= "\n"; $site = implode('', file($RealCacheName)); $forceRefresh = true; } else { $Status .= "\n"; $site = ECL_fetchUrlWithoutHang($ECLURL,false); $fp = fopen($RealCacheName, "w"); if (strlen($site) and $fp) { $write = fputs($fp, $site); fclose($fp); $Status .= "\n"; $reloadImages = true; } else { $Status .= "\n"; $Status .= "\n"; $Status .= "\n"; } } if(!file_exists($RealCacheName)) { print "Sorry. Unable to write $lightningCacheName to '$cacheDir'.
";
print "Make '$cacheDir' writable by PHP for this script to operate properly.
Sorry. Incomplete file received from Environment Canada website.
\n"; exit; } preg_match('|charset="{0,1}([^"]+)"{0,1}\r|i',$site,$matches); if (isset($matches[1])) { $charsetInput = trim(strtoupper($matches[1])); } else { $charsetInput = 'UTF-8'; } $doIconv = ($charsetInput == $charsetOutput)?false:true; // only do iconv() if sets are different $Status .= "\n"; // find the site name // preg_match_all('|\n". "\n". " | \n"; $ECLlegend .= "\n
|
(.*)
|Uis',$site,$matches) ) { $siteDescription = $matches[1][0]; if($doIconv and !empty($siteDescription)) { $siteDescription = iconv($charsetInput,$charsetOutput.'//TRANSLIT',$siteDescription); } } // find and extract the details about the images available preg_match('|Sorry, no current lightning images for site $lightningID are available.
\n"; return; } if ($numImages > 1) { // generate the animation for 2 or more images ?> $siteDescription\n"; } ?>
" alt="" width="" height="" id="L_Ath_Slide" title="" />
" alt="" width=" " height="" title="" />