Php webtags: Difference between revisions

995 bytes added ,  18:26, 26 June 2020
m
Line 148: Line 148:
*One approach, that is perhaps easier is to modify a ready-made script (as has happened for some of those listed below) by adding new lines, each with a PHP variable name (it must start with "$") on the left of an equals sign and a web tag (<#tag_name>) on the right, and end the line with a ";".  
*One approach, that is perhaps easier is to modify a ready-made script (as has happened for some of those listed below) by adding new lines, each with a PHP variable name (it must start with "$") on the left of an equals sign and a web tag (<#tag_name>) on the right, and end the line with a ";".  
*You can add a comment at end of line using prefix "//".  
*You can add a comment at end of line using prefix "//".  
*In this way, you can add anything missing from the PHP variables in the existing template.  
*You can add a comment anywhere by enclosing it in <tt>/*</tt> and <tt>*/</tt>.
*You don't need to know any more about PHP than I have said above (requirement for "$" and ";").  
 
*You don't need to know any more about PHP than I have said above (requirement for "$" as the first character of a PHP variable name, use of "=" between PHP variable name and Cumulus web tag, and requirement for ";" at end of each assignment).  
*All you need is an understanding of the web tag syntax gained from studying the [[Webtags|Web tags]] wiki page.
*All you need is an understanding of the web tag syntax gained from studying the [[Webtags|Web tags]] wiki page.
*The scary bit is understanding the right format to use in those web tags for the output parameters because it is easy to specify items like minutes, hour, or month, incorrectly.
*The scary bit is understanding the right format to use in those web tags for the output parameters because it is easy to specify items like minutes, hour, or month, incorrectly, especially if you have moved from Cumulus 1 to MX.


Given all the web tag complications discussed above, you made find a ready made template that suits you from those listed below, remember to check if it is specific to whichever flavour of Cumulus you use, remember of course ''none of them cover all web tag combinations'' possible using output parameters, but they might cover enough for your purposes:


*Be aware that if you are using Cumulus 1, when processing it ignores any web tags it does not recognise.  
*Be aware that if you are using Cumulus 1, when processing it ignores any web tags it does not recognise.  
Line 159: Line 160:




=== Based on original by David Jamieson and Ray Beriau ===
=== Ready-made scripts based on original by David Jamieson and Ray Beriau ===
They all contain PHP variables for all the web tags available in Cumulus 1, some contain all web tags available in MX. You will notice the USA style month first bias of the original authors in some of the date formats below, and consequently a few of the PHP variables might not work perfectly in other locales, all depending of course on which of the defined PHP variables you actually use.
 
They all contain PHP variables for all the web tags available in Cumulus 1, some contain all web tags available in MX. You will notice the USA style month first bias of the original authors in some of the date formats below, the assumptions for separators for date, time, and decimal)
 
Consequently a few of the PHP variables defined in these scripts might not work perfectly outside USA, all depending of course on which of the defined PHP variables you actually use.


For the files marked as for MX versions, the PHP variables that relate to web tags not available in  MX have been given arbitrary fixed values, not nulls, so only really work for the system of the person who last updated the file.  
For the files marked as for MX versions, the PHP variables that relate to web tags not available in  MX have been given arbitrary fixed values, not nulls, so only really work for the system of the person who last updated the file.  
Line 170: Line 174:
Otherwise, apart from a few web tags that report dates where alternative formats are added (as shown below) using output parameters and new variable names, most php variable names match the corresponding web tags name, there are no alternatives for the time-stamps and date-stamps in any weather derivatives.  
Otherwise, apart from a few web tags that report dates where alternative formats are added (as shown below) using output parameters and new variable names, most php variable names match the corresponding web tags name, there are no alternatives for the time-stamps and date-stamps in any weather derivatives.  


'''Note there is an error in every single one of these files''' - they contain a "?>" at the end, that should not be used in pure PHP files - see PHP manual instruction.  Should white-space or new lines being added after the PHP closing tag, even accidentally,  there may be unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script. That applies even if the extra is after the include/require in the script using this file.
==== Caution for some scripts ====
 
If you choose a ready-made script that includes a "?>" at the end, you will have a problem if you add even a single space or new line after that code, or in any of your own scripts that "include" the script with that code. That code is only supposed to be used when HTML commands follow it, not when there is more PHP after it.
 
==== Example of dates and times provided in these ready made scripts ====
 
Note that web tags <#hour>, <#minute> are amongst those not available in PHP variables, but also note that Greenwich Mean Time has had its abbreviation transposed by these Americans as well as month first date formats.
 
<pre>$date2          = strtotime(str_replace('/','-',"<#date>"));  //  current date (example format: 1346569200)
<pre>$date2          = strtotime(str_replace('/','-',"<#date>"));  //  current date (example format: 1346569200)
$dateU              = strtotime(str_replace('/','-',"<#date>"));  //  current date (Unix datestamp format)
$dateU              = strtotime(str_replace('/','-',"<#date>"));  //  current date (Unix datestamp format)
Line 193: Line 204:




*For version 3.5.3 (build 3074), a single template file can be downloaded from [https://cumulus.hosiene.co.uk/viewtopic.php?f=14&t=17991 CumulusMX PHPwebtags] topic in the support forum, posted by the administrator (water01) as an update to the one below.
*For latest MX version, a single template file can be downloaded from [https://cumulus.hosiene.co.uk/viewtopic.php?f=14&t=17991 CumulusMX PHPwebtags] topic in the support forum, posted by forum administrator (water01) soon after each MX update that changes web tags. It is the latest version of the American one referenced above.
*An equivalent for version 3.0.x is at [https://cumulus.hosiene.co.uk/viewtopic.php?f=39&t=13252&p=103860&hilit=cumuluswebtags.txt#p103830 this page on  support forum] also posted by the administrator (water01), and developed from the . This one does not contain any web tags added since 2015, but use this one also for versions before 3.5.3 to avoid any errors being reported and accept it may not include some of the web tags available in in-between versions.
*If you are not using the latest MX version, then use his earlier file that can be downloaded at [https://cumulus.hosiene.co.uk/viewtopic.php?f=39&t=13252&p=103860&hilit=cumuluswebtags.txt#p103830 this page on  support forum]. This one does not contain any web tags added since 2015, so will work for any earlier MX versions and won't report the errors that his latest version does for any web tag missing at your version. Equally you need to accept it may not include some of the web tags available in your particular version.
* An alternative approach in the early days of MX was taken by Duke. You can download his version from [https://cumulus.hosiene.co.uk/viewtopic.php?f=6&t=10424#p99536 this storm rain topic]. His zip contains two files '''cumulustags_no_description.tpl''' and '''cumulustags_with_description.tpl''', each uses the approach of defining an array $WX in which the index to the array elements is the web tag name for example <code>$WX['rfall'] = '<#rfall>';  //  total rainfall so far today</code>. It contains all tags used by either Cumulus 1 or MX  in September 2014. If you use this script you need to call it by '''require_once 'cumulustags_no_description.php';''' because it contains functions that can only be declared once to convert between decimal degrees and degrees, minutes, seconds formats in either direction, basically because it it stripping out the HTML space characters used by Steve Loft for latitude and longitude. For Recent History web tags there are up to 27 different input parameters in some cases. The extra time and date parameters shown above appear, but as array elements e.g. <code>$WX['timeshort']  = '<#time format="hh:nn">';  //  current time (example format: 12:34)</code>.
*If you are using Cumulus 1.9.4, then the download file available on [[File:Cumuluswebtags.txt]]) might suit you. Note that in this download the recent history tags only occur with a single 3 hours ago parameter but if you use these tags it is likely you will want to include them for several other periods too.  Edit this template file to put in the necessary time selectors yourself.
*For the final version 1.9.4 of Cumulus 1 use the download file available on [[File:Cumuluswebtags.txt]]). Note that in this download the recent history tags only occur with a single 3 hours ago parameter but if you use these tags it is likely you will want to include them for several other periods too.  Edit this template file to put in the necessary time selectors yourself.
** The advantage of only choosing one possible input parameter is that this template can use PHP variable names that match the web tag name, and only use PHP arrays when the web tag returns an array.
** The advantage of only choosing one possible input parameter is that this template can use PHP variable names that match the web tag name, and only use PHP arrays when the web tag returns an array.
=== Using an array ===
While the ready made scripts described above have a separate PHP variable name for each web tag, some authors have set up a single PHP variable as an array, and each web tag definition is coded as a separate element '''$WX[xxyyzz]''' of that array. The two described below differ only in their selection of input parameters for the recent history web tags; one has preselected 27 combinations, the other includes only 10. Neither offers a choice of output parameters.
*One ready-made script using an array '''$WX''' was made by Duke.
*You can download his version from [https://cumulus.hosiene.co.uk/viewtopic.php?f=6&t=10424#p99536 this storm rain topic]. 
*If you use this script you need to call it by '''require_once 'cumulustags_no_description.php';''' because it contains functions that can only be declared once to convert between decimal degrees and degrees, minutes, seconds formats in either direction, basically because it is stripping out the HTML space characters used by Steve Loft for latitude and longitude.
*His zip contains two files '''cumulustags_no_description.tpl''' and '''cumulustags_with_description.tpl''', each uses the approach of defining an array $WX in which the index to the array elements is the web tag name for example <code>$WX['rfall'] = '<#rfall>';  //  total rainfall so far today</code>.
*For Recent History web tags there are up to 27 different input parameters in some cases, you pick the array elements for each of the different times you require.
*It contains all tags used by either Cumulus 1 or MX  in September 2014.
*It uses default output formatting, so that is why it will work with both flavours.
*The extra time and date parameters shown above appear, but as array elements e.g. <code>$WX['timeshort']  = '<#time format="hh:nn">';  //  current time (example format: 12:34)</code>.
*Another ready-made script using an array '''$WX''' was made by Ken True.
**Using this array your customised pages would replace any reference to a Cumulus web tag <tt><#xxyyzz optional_parameter></tt> by a PHP array element '''$WX[xxyyzz]'''''[optional_additional_selector]''
*It only holds a sub-set of Cumulus web tags relevant to the Saratoga template.
*For some of these web tags there are a number of output parameters that have been selected to implement:
**For those web tags that do have a parameter defined (the recent history web tags include for example '''m=10''' as an input parameter),  you select the one you want using the optional second index.
**Most of the web tags might not need any input or output parameters to be specified, you are using their default output, so the corresponding PHP element would not need a second index.
**This template file is called ''CUtags.txt'' and it can be downloaded from [http://saratoga-weather.org/wxtemplates/install.php Saratoga-Weather.org].
**That download includes just 10 elements for the recent history tags at 5, 10, 15, 20, 30, 45, 60, 75, 90, 105 and 120 minutes. If you want older values or values at other times, then you will need to add these to the array yourself.


=== Alternatives ===
=== Alternatives ===
These templates have not been influenced by the original template, but instead have tried to cover what suited each author at the time the template was written, and each author has made their own independent decision about what parameters to use.
These templates have not been influenced by the original template, but instead have tried to cover what suited each author at the time the template was written, and each author has made their own independent decision about what parameters to use.


Line 205: Line 239:
* Another simple template, but this one includes far fewer web tags, is called ''CUtags.txt'', it was produced by BCJKiwi as a single template file able to work with both Cumulus 1 and MX. It can be downloaded as part of his [[CumulusMX_and_Cumulus1_UI_style_Multilingual_Websites|package]] or separately at [https://cumulus.hosiene.co.uk/viewtopic.php?f=40&t=17985&p=140688#p140688 this post of mine in a zip].
* Another simple template, but this one includes far fewer web tags, is called ''CUtags.txt'', it was produced by BCJKiwi as a single template file able to work with both Cumulus 1 and MX. It can be downloaded as part of his [[CumulusMX_and_Cumulus1_UI_style_Multilingual_Websites|package]] or separately at [https://cumulus.hosiene.co.uk/viewtopic.php?f=40&t=17985&p=140688#p140688 this post of mine in a zip].
**This template does not contain any web tags that are only available in MX, nor does it contain any web tags that require input or output parameters. The PHP variable names match Cumulus web tag names, but some of those PHP variables are set to "not used", instead of to the web tag contents, because this template file is designed for a specific set of web pages.
**This template does not contain any web tags that are only available in MX, nor does it contain any web tags that require input or output parameters. The PHP variable names match Cumulus web tag names, but some of those PHP variables are set to "not used", instead of to the web tag contents, because this template file is designed for a specific set of web pages.
*Another approach is to create an array '''$WX''' that holds a sub-set of Cumulus web tags, choosing some parameter combinations to implement:
**Using this array your customised pages would replace any reference to a Cumulus web tag <tt><#xxyyzz optional_parameter></tt> by a PHP array element '''$WX[xxyyzz]'''''[optional_additional_selector]''
**Most of the web tags might not need any input or output parameters to be specified, you are using their default output, so the corresponding PHP element would not need a second index.
**For those web tags that do have a parameter defined (the recent history web tags include for example '''m=10''' as an input parameter),  you select the one you want using the optional second index.
**A template file to do this is also called ''CUtags.txt'' and it can be downloaded from [http://saratoga-weather.org/wxtemplates/install.php Saratoga-Weather.org].
**That download includes elements for the recent history tags at 5, 10, 15, 20, 30, 45, 60, 75, 90, 105 and 120 minutes. If you want older values or values at other times, then you will need to add these to the array yourself.
*This [[File:Web tag templates.zip|zip]] contains a set of templates, each updated at different frequencies. It includes all web tags for either Cumulus 1 or MX. You may get an error reported locally when Cumulus processes an individual file as your version of Cumulus does not include every tag it will try to process. However, once it has been converted to a PHP script, it will test the version and should not give any errors as you use it on your production web site. I have taken the decision to write all the templates assuming your locale uses a fullstop as decimal separator. I am working on templates that use the Remove Comma options that Cumulus 1 and MX provide, but those are not ready to release.
*This [[File:Web tag templates.zip|zip]] contains a set of templates, each updated at different frequencies. It includes all web tags for either Cumulus 1 or MX. You may get an error reported locally when Cumulus processes an individual file as your version of Cumulus does not include every tag it will try to process. However, once it has been converted to a PHP script, it will test the version and should not give any errors as you use it on your production web site. I have taken the decision to write all the templates assuming your locale uses a fullstop as decimal separator. I am working on templates that use the Remove Comma options that Cumulus 1 and MX provide, but those are not ready to release.


5,838

edits