Php webtags: Difference between revisions

106 bytes added ,  05:14, 20 April 2020
m
Line 6: Line 6:


= Web tag Complications =
= Web tag Complications =
 
== static content==
*Some web tags contain content that never changes, I will leave you to work out which these are; equally some web tags identify the month or year and only change when a new month or new year starts. It does not make for efficient use of resources if you make both PHP and Cumulus process every web tag each time Cumulus does a real time update. So although this article links to many single scripts assigning Cumulus web tags to PHP variables, it actually makes better sense to have multiple scripts, each processed only when the tags they contain may change.
*Some web tags contain content that never changes, I will leave you to work out which these are; equally some web tags identify the month or year and only change when a new month or new year starts. It does not make for efficient use of resources if you make both PHP and Cumulus process every web tag each time Cumulus does a real time update. So although this article links to many single scripts assigning Cumulus web tags to PHP variables, it actually makes better sense to have multiple scripts, each processed only when the tags they contain may change.
 
== station specific tags ==
*Remember some web tags are specific to particular station types and may not return any useful information for your station. For example <code>$light=<#Light>;</code> is a value that only applies to those Fine Offset stations that have a solar sensor and not to any other make or type (although note that Fine Offset are sold by a number of companies who brand those stations with their own name.
== parameters ==
*In early versions of Cumulus, its web tags did not take parameters and it was easy to assign each web tag to a variable that any data transfer approach could use;
*In early versions of Cumulus, its web tags did not take parameters and it was easy to assign each web tag to a variable that any data transfer approach could use;
*From version 1.9.3 various web tags (such as "Recent History") always take parameters, others (like those reporting times and/or dates) can take parameters.  
*From version 1.9.3 various web tags (such as "Recent History") always take parameters, others (like those reporting times and/or dates) can take parameters.  
Line 14: Line 16:
**Consequently anyone devising a sample file in any of the formats listed below can only guess which parameters are most useful.
**Consequently anyone devising a sample file in any of the formats listed below can only guess which parameters are most useful.
**Because of this 'guessing'; '''do not assume''' that a file from some one else, will meet your requirements ''out of the box'', you must understand the script language and be prepared to edit the file supplied into one that meets your own requirements.
**Because of this 'guessing'; '''do not assume''' that a file from some one else, will meet your requirements ''out of the box'', you must understand the script language and be prepared to edit the file supplied into one that meets your own requirements.
== variable content ==
*When editing the file remember that Cumulus web tags can return either numerical or string information, when using the script variables you may wish to do numeric calculations or comparisons, and these might behave differently if numeric information is processed as a string (for example the month of March as a number returns '3', but as a string may return '03', some comparisons don't recognise those are same).
*When editing the file remember that Cumulus web tags can return either numerical or string information, when using the script variables you may wish to do numeric calculations or comparisons, and these might behave differently if numeric information is processed as a string (for example the month of March as a number returns '3', but as a string may return '03', some comparisons don't recognise those are same).
**Some web tags that might be expected to return numerical information may contain dashes instead sometimes. You may get an error if that particular PHP variable is treated as numerical. As an example on the first day of a month <code>$monthHighDailyTempRange='<#MonthHighDailyTempRange>';</code> will return dashes as that particular item is not calculated by Cumulus until at least one complete day is available.
==embedded quotes==
**Also when returning string information Cumulus can include embedded quotes: e.g. <code>$LatestError = "Latest Error: 'Some filename was locked" recorded';</code> as the embedded ones are double quotes, single quotes are used in <code>$LatestError='<#LatestError>';</code> in the template file as delimiters for the whole string. Equally Longitude and Latitude web tags by default label the minutes and seconds part with the same symbols as used by quotes, so we have to choose the alternative decimal notation <code>$longitude=<#longitude dp=5>;</code>
**Also when returning string information Cumulus can include embedded quotes: e.g. <code>$LatestError = "Latest Error: 'Some filename was locked" recorded';</code> as the embedded ones are double quotes, single quotes are used in <code>$LatestError='<#LatestError>';</code> in the template file as delimiters for the whole string. Equally Longitude and Latitude web tags by default label the minutes and seconds part with the same symbols as used by quotes, so we have to choose the alternative decimal notation <code>$longitude=<#longitude dp=5>;</code>
**Some web tags that might be expected to return numerical information may contain dashes instead sometimes. You may get an error if that particular PHP variable is treated as numerical. As an example on the first day of a month <code>$monthHighDailyTempRange='<#MonthHighDailyTempRange>';</code> will return dashes as that particular item is not calculated by Cumulus until at least one complete day is available.
*Remember some web tags are specific to particular station types and may not return any useful information for your station. For example <code>$light=<#Light>;</code> is a value that only applies to those Fine Offset stations that have a solar sensor and not to any other make or type (although note that Fine Offset are sold by a number of companies who brand those stations with their own name.
*Yet another complication (for Cumulus 1 users) is that the values for  [[Webtags#Time.2FDate_.27format.27_Parameter|formatting parameters]] can include double and single quotes, but any assignment to a PHP variable requires the value to be quoted so it is treated as a string.  There are two ways round this, one is to concatenate several uses of the same Cumulus web tag to build up the required layout without using both versions of quotation marks within any single formatting value e.g. <code>$LastDataReadTDM='<#LastDataReadT format=h:nn'.' on '.'<#LastDataReadT format="d mmm">';</code>, and the other is to use the PHP 'heredoc' approach - see PHP manual.
*Yet another complication (for Cumulus 1 users) is that the values for  [[Webtags#Time.2FDate_.27format.27_Parameter|formatting parameters]] can include double and single quotes, but any assignment to a PHP variable requires the value to be quoted so it is treated as a string.  There are two ways round this, one is to concatenate several uses of the same Cumulus web tag to build up the required layout without using both versions of quotation marks within any single formatting value e.g. <code>$LastDataReadTDM='<#LastDataReadT format=h:nn'.' on '.'<#LastDataReadT format="d mmm">';</code>, and the other is to use the PHP 'heredoc' approach - see PHP manual.
*Cumulus MX web tags do allow embedding of HTML, see the [[Webtags|Web tags article]] for details.
*Cumulus MX web tags do allow embedding of HTML, see the [[Webtags|Web tags article]] for details.
5,838

edits