A PHP script to integrate the meteoalarm.eu warnings in your own weather website Version v3 For English clik here  Voor Nederlands klik hier 

Introduction


Purpose of this script:

  • to read, from the www.meteoalarm.eu website, the current meteo warning for the area where the weatherstation is located
  • translate the html into a PHP array
  • cache this array for later use - cache is adaptable in a setting
  • translate this intermidiate array into the language of the website
  • generate one or more divs which can be displayed on the website

Wind from: 28-01-2014 13:00 until: 29-01-2014 18:59 warning for: Wind level: Yellow info button
No Litoral rajadas da ordem de 80 km h Nas terras altas temporariamente durante a tarde do dia 28 rajadas da ordem de 100 km h


Very adaptable by use of settings:

  • area of the weatherstation and language
  • optional message box if there are no warnings
  • all warnings in one box or seperate box for every warning
  • to many warnings can be combined into one general warning
  • multi language warnings can be split based on standard characters in the warning

Examples


This example shows a box which can be used to display your own warning text:
The contents of the box are read form a text file . You can put any contents in it.
Please be aware that the contents of this file are not translated.

This is your own message box to warn visitors for maintenance or tell them about new pages on your site

Deze website is in opbouw / onderhoud. This website is under construction / in maintenance.
Ce site est en construction / l'entretien. Diese Website ist im Aufbau / Wartung.


The second box displays three weather-warnings for the area PT013.
This is an example from a testfile, not the real warnings for this area for this moment.
Clicking on the large I will bring you to a page with more information.
This can be one of your own pages or the meteoalarm.eu website for this area.

Kustbedreiging van: 28-01-2014 12:00 tot: 30-01-2014 12:59 waarschuwing voor: Kustbedreiging niveau: Oranje info button
Wind van: 28-01-2014 13:00 tot: 29-01-2014 18:59 waarschuwing voor: Wind niveau: Geel info button
Sneeuw/IJzel/Bevriezing van: 28-01-2014 16:00 tot: 29-01-2014 15:59 waarschuwing voor: Sneeuw/IJzel/Bevriezing niveau: Geel info button


This is the optional "no warning" box.

The weather provides no immediate danger. There are no warnings issued.


Only one box is displayed when the maximum number of warnings exceeds the setting.
NEW When clicking on the I the "hidden" warnings are displayed immediately.

There are multiple Weather-warnings  Click here for more information


And this is the example of "Every warning in its own box".

Kustbedreiging van: 28-01-2014 12:00 tot: 30-01-2014 12:59 waarschuwing voor: Kustbedreiging niveau: Oranje info button
Wind van: 28-01-2014 13:00 tot: 29-01-2014 18:59 waarschuwing voor: Wind niveau: Geel info button
Sneeuw/IJzel/Bevriezing van: 28-01-2014 16:00 tot: 29-01-2014 15:59 waarschuwing voor: Sneeuw/IJzel/Bevriezing niveau: Geel info button


In this example the complete warning text is displayed also.
This can be a very large textblock taking up a lot of room. Also for some areas the warning is supplied in multiple languages.
Important: The warning-text can not be translated as it is "free form" text typed by humans into the database.

Wind from: 28-01-2014 13:00 until: 29-01-2014 18:59 warning for: Wind level: Yellow info button
No Litoral rajadas da ordem de 80 km h Nas terras altas temporariamente durante a tarde do dia 28 rajadas da ordem de 100 km h


If you want to use your own detailed warning-page, the information for that page is generated also by this script. All information in all languages is displayed.

 From: 03-08-2014 10:48   Until: 04-08-2014 10:48
Extreme high temperature  Level: : Yellow 

Kymenlaakso: Lähivuorokauden aikana on odotettavissa tukalaa hellettä. (Varoitus kattaa seuraavat 24 h. Se annetaan ajanjakson suurimman vaaratason mukaan.)Kymmenedalen: Under det närmaste dygnet är det svår hettan att vänta. (Varningen gäller upp till 24 timmar enligt den högsta nivån.)Kymenlaakso: Warm weather is expected during the coming 24 hours. (Warning covers the next 24 h. It is based on the highest awareness level during the warning period.) 

 From: 03-08-2014 10:48   Until: 04-08-2014 10:48
Forest fire  Level: : Yellow 

Kymenlaakso: Metsäpalovaroitus annetaan tänään klo 12. (Varoitus annetaan kerran vuorokaudessa klo 12 ja kattaa seuraavat 24 h.)Kymmenedalen: Varning för skogsbrand ges i dag kl 12. (Varning ges en gång på dagen klockan 12 och gäller upp till 24 timmar.)Kymenlaakso: A forest fire warning is issued today at 12 local time. (Warning is given once a day at noon and covers the next 24 h.) 

Warning data courtesy of and Copyright © EUMETNET-METEOalarm (http://www.meteoalarm.eu/). Used with permission.
Time delays between this website and the www.meteoalarm.eu website are possible, for the most up to date information about alert levels as published by the participating National Meteorological Services please use www.meteoalarm.eu


Download

  1. Download form this link here
  2. These files and folders are contained in the download after unzip:
    nameWhat is it and what to do with it
    _read-me.txtfileThis information in a text file
    cachefoldercache folder
    flag-??.giffileflags => wrnExample.php
    wrnExample.phpscriptA very small example program to test the "Warning" script
    Copy to the same folder where you copied the "Warning" script to.
    wrnImages
    wrnImagesLarge
    folderThe images as used by Meteoalarm.eu
    Copy to the main folder of your website, often the root or a special folder called "weather"
    You could also copy the images into your current image folder. One of the settings have to be adapted than to link to your image folder.
    wrnPrintWarnings.phpscriptLeuven-template: Example script for the warnings on a separate page
    wrnWarningv3.phpscriptThe main "Warning" script to retrieve the warning and generate html to be displayed on your website.
    Copy to the main folder of your website, often the root or a special folder called "weather"
    wrnWarning.txtfileA test version of your own message box.
    Copy to the same folder where you copied the "Warning" script to.
    wxAdvisoryv3.phpscriptSaratoga-template: Example script for the warnings on a separate page
  3. First test the wrnExample.php script. It should run without errors. You can use this script as an example of how to use the "warning" script.
  4. Set the settings in the first part of the wrnWarning.php script. Check the description at the tab "Settings"

Settings


You find those settings at the start of the warning script.

  • First item: the important language setting. The weather-warnings are translated into this language, if the translations are at the end of the wrnWarningv3.php script itself..
    #-----------------------------------------------------------------------------------------
    # these are your settings for retrieving information from www.meteoalarm.eu/en_UK/0/0/xx123.html
    #-----------------------------------------------------------------------------------------
    #
    $lang           = 'en';                 // default language - supported nl en fr de

  • If you really need to install the script and the pictures in another folder, you can specify the folder here
    $myfolder       = './';                 //##### set if include 'foldername/wrnWarningv3.php'; is used
    #$myfolder      = './EUwarning/';       // EXAMPLE: include './EUwarning/uvforecastv3.php';

  • If for some reason, f.i. meteoalarm site is down, you do not want to process the weather warnings, you change this setting to false and no warnings will be loaded. Also no green box.
    $warnings       = true;                 // do we want to print warnings

  • The area your weather station is located. You can find your area code when browsing the meteoalarm.eu website.
    $warnArea       = 'BE004';              //      the area we want the warnings for

  • Here you set the printing of the "no warning" green box
    $warningGreen   = true;                 //      do we print a message also when there are no warnings

  • If communication fails with the meteoalarm site a box is displayed informing the user to visit the www.meteoalarm.eu site directly
    $warningFailed   = true;                //      do we print a message when the Metoalarm site is unavailable

  • If you have a general message to the visitors of the website you could place those messages in a text file and let the warning script generate the html box with those messages.
    $warnMsg        = true;                  // do we want a message f.i. maintenance on each page
    $warnMsgTxt     = $myfolder.'wrnWarning.txt';    // location of our own message text
    #$warnMsgTxt	= '../maintenance.txt';  // example for a file to be found in the root

  • The location of the images. Default in their own folder. But they can be placed anywhere onyour site. The second setting points to the meteoalarm site directly, if you prefer that.
    $warnImg        = $myfolder.'/wrnImages/warn_';  // location and first part of the name for the small images of the warnings, f.i. full name warn_11.gif
    #$warnImg	= 'http://www.meteoalarm.eu/Bilder/warnflags/warn_';
    
    $warnImgLarge   = $myfolder.'wrnImagesLarge/';   // location for the large warnimages
    #$warnImgLarge  = 'http://www.meteoalarm.eu/theme/common/pictures/';
    
    $infoImg        = $myfolder.'wrnImages/i_symbol.png';   // name + location of  the big I which is used in to click on for more information

  • If you have your own page with detailed warnings (f.i. in the saratoga template) you can set that here by setting the $warnpage setting to that script name, example: 'wxadvisoryv3.php'. Default the meteoalarm.eu page is used.
    $warnPage       = '';                   // we have no warning page of our own
    #$warnPage	= 'index.php?p=57-1';	  //      exact name for leuven template	        
    #$warnPage      = 'wxadvisoryv3.php';   //      or the exact name of the page to load

  • If set high enough all warnings are printed. But more than 3 warnings take a lot of room.
    So if there are more warnings to display than set here, there will be only one box printed with a general text. clicking on the large I will then immediately show the "hidden" warnings themselves.
    $warningDetail  = 1;                    // maximum number of warnings before we switch to one warning

  • To take up less room, all warnings can be combined in 1 box and 1 line per warning
    $warn1Box       = true;                 // true = put all warnings in one box;  false = one box for every warning

  • If set the complete warning text is displayed also. This can be a very large textblock taking up a lot of room. Also for some areas the warning is supplied in multiple languages.
    Important: The warning-text can not be translated as it is "free form" text typed by humans into the database.
    $warningsXtnd   = true;                 // false =  one line per warning, true = also the long text description = DO NOT USE IN BELGIUM
    #                                       //      this can be very large chunks of text, be carefull 
    $warningSplit   = true;                 // if the large text has multiple languages and a "standard" character-string to divide them is used
    #                                       //      only the current language is shown
    #                                       //      not all countries support that, at the moment only AT BA  BE  HR  ME  NL  NO PO  RO  RS  SI

  • Those standard texts are not really needed, you can omit them by setting this to false
    $printLevelText = false;                // print standard texts such as 'The weather is potentially dangerous for outside activities.'

  • Meteoalarm.eu returns the warnings in the UTF-8 character set. Here you set the character set in use for your website
    $charset        = 'UTF-8';               // default character set for webpages, UTF-8 is the modern one, windows-1252 is the most used one

  • The warnings from meteoalarm.eu are cached for a short period of time to lower the load on the meteoalarm.eu website.
    $cacheDir        = $myfolder.'cache/';           // directory to cache files     IMPORTANT setting

  • Do not change without visiting http://php.net/manual/en/timezones.php first to obtain the correct spelling.
    $timezone       = 'Europe/Brussels';     // again important, valid for most of europe.  Do not change if you do not know what valid codes are.
    #                                        //      check here:     http://php.net/manual/en/timezones.php
    

Installation

  1. How to use
    1. Include the script in the "first" part of your page
      The script generates three PHP variables which then can be displayed on any part of the page
    2. $wrnHead contains the complete HTML for your own message-box or is an empty string if you do not use this possibillity.
    3. $wrnStrings contains the html for the warnings or for the green box or is an empty string, based on how you set your settings.
    4. $ownpagehtml contains the html for the warnings or for the green box in the same "format" as on the meteoalarm.eu site.
    5. You should "echo" $wrnHead, $wrnStrings or $ownpagehtml on the place where you want the message-box and / or warning-box to appear.
  2. How-to Saratoga
    • Add this item to your fly-out menu or change the existing wxadvisory.php entry
      <item caption="Advisories" link="wxadvisoryv3.php" />

    • Open with a program editor the header.php script and find the line with
      <div id="page">

    • Add the 4 lines as here below.
      Remove the comment mark # on the third line, if you want the warnings on top of your pages.
      <?php	include ('wrnWarningv3.php');  
      		echo $wrnHead;                  // if you want the yellow box with your message
      #		echo $wrnStrings                // if you want the warnings before anything else remove the #
      ?>

    • Optional: If you want the warnings below the top-area - next to the side menu
      1. Open the menubar.php script and locate those two lines:
        // generate navigation links script - Ken True - webmaster@saratoga-weather.org
        function gen_navlinks($html) {

      2. Add that extra line in between that displays the warnings on the exact right spot.
        // generate navigation links script - Ken True - webmaster@saratoga-weather.org
        echo '<div style="margin-left: 114px;">'.$wrnStrings.'</div>';
        function gen_navlinks($html) {

  3. How-to Leuven-template
    • As described by the tab "donwload" you move a few scripts from the download to the main folder of your site: weather2
      1. The scripts wrnWarningv3.php and wrnPrintWarnings.php
      2. The folders with the images wrnImages and wrnImagesLarge
    • Until now, there were always two places with settings: Most of them in the wsSetting file and some in the scripts itself.
      From release v3 all settings will be in the script. Only the name of the script will be in the wsSettings.php!
    • First you check and set the settings in wrnWarning.php. After you have done that, you modify the warning-script name wsSettings.php with the new name:
      	$SITE['warningScript']	= 'wsWarning.php';  // Euro 

    • change it to
      	$SITE['warningScript']	= 'wrnWarningv3.php';  // Euro 

    • And in wsMenudat.xml you rename the name of the one-page script from:
      	<item 	nr="57-1"	show="warningsEuro"
      			link="meteoalarm/meteoalarmPrintWarnings.php" 
      			caption="Advisories"
      			title="Weather alarms by European MeteoAlarm"
      			/>

    • change it to
      	<item 	nr="57-1"	show="warningsEuro"
      			link="wrnPrintWarnings.php" 
      			caption="Advisories"
      			title="Weather alarms by European MeteoAlarm"
      			/>

    • Those page numbers in the menu xml can vary (p=xx) so check and modify according to your page-number in wrnWarningv3.php
      $warnPage	= '';

    • change it to your number - normally:
      $warnPage	= 'index.php?p=57-1';