Php webtags: Difference between revisions

1,106 bytes added ,  16:42, 4 March 2015
m
→‎Options available: sequence change to make alternative more obvious
m (Re-structuring)
m (→‎Options available: sequence change to make alternative more obvious)
Line 5: Line 5:
#Or write a web page including PHP code that does not need to be processed by Cumulus. To get the information that Cumulus provides, all your new pages can "'''include'''" (if you want the page to fail without that cumulus information - use "''require''" instead) another single PHP file that Cumulus does process in which all the [[webtags]] values are assigned to PHP variables.  This is more efficient for those using PHP on their website.
#Or write a web page including PHP code that does not need to be processed by Cumulus. To get the information that Cumulus provides, all your new pages can "'''include'''" (if you want the page to fail without that cumulus information - use "''require''" instead) another single PHP file that Cumulus does process in which all the [[webtags]] values are assigned to PHP variables.  This is more efficient for those using PHP on their website.


Cumulus produces [[webtags]] that can be incorporated in files that it processes and then the output has the appropriate values where those place-holders were encountered. The standard web templates use some of these webtags and genrate HTML pages that can be viewed on a web site.
If you are customising your web site, then you might choose to use script to produce what you want on your web site, and this page describes a way to have cumulus process a single file, and make the resulting values available in script variables for you to use anywhere on your site.
=Options available=
=Options available=
*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 PHP 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 PHP 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. There are now a vast number of possible combinations and it would be in-efficient for all those combinations to be generated whether needed or not. Consequently anyone devising a sample file in any of the formats listed below can only guess which parameters are most useful.
*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. There are now a vast number of possible combinations and it would be in-efficient for all those combinations to be generated whether needed or not. Consequently anyone devising a sample file in any of the formats listed below can only guess which parameters are most useful.
*Note that Cumulus web tags can return either numerical or string information, and 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 notaion <code>$longitude=<#longitude dp=5>;</code>
*Because of this 'guessing' '''do not assume''' that a file from some one else will meet your requirements '''out of the box'' ''and be prepared to edit it''.
*Note that Cumulus web tags can return either numerical or string information, and 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 notaion <code>$longitude=<#longitude dp=5>;</code>
*Depending on how long you have been running Cumulus, some webtags that might be expected to return numerical information may contain dashes. You may get an error if that particular PHP variable is treated as numerical.
*Remember some webtags are specific to particular station types and may not return any useful information for your station.
*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.


Line 20: Line 25:
#*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. #*Using this array your customised pages would replace any reference to a Cumulus web tag <code><#xxyyzz optional_parameter></code> by a PHP array element <code>$WX[xxyyzz] [optional_additional_selector]</code> (some elements include the m=10 type selector).<br/><br/>
#*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. #*Using this array your customised pages would replace any reference to a Cumulus web tag <code><#xxyyzz optional_parameter></code> by a PHP array element <code>$WX[xxyyzz] [optional_additional_selector]</code> (some elements include the m=10 type selector).<br/><br/>
# Another approach is to create a separate PHP variable (or in a few cases an array) for each Cumulus web tag.
# Another approach is to create a separate PHP variable (or in a few cases an array) for each Cumulus web tag.
#*For a discussion about problems with delimiting strings see [http://sandaysoft.com/forum/viewtopic.php?f=4&t=1 another cumulus support forum thread link].
#*In this case your customised pages would replace any reference to a Cumulus web tag <code><#xxyyzz optional_parameter></code> by a PHP variable or array - either <code>$xxyyzz[optional_index]</code> or <code>$xyyxwx</code>.
#*In this case your customised pages would replace any reference to a Cumulus web tag <code><#xxyyzz optional_parameter></code> by a PHP variable or array - either <code>$xxyyzz[optional_index]</code> or <code>$xyyxwx</code>.
#*In your customised pages, use the instruction '''require cumuluswebtags.php'''.
#*In your customised pages, use the instruction '''require cumuluswebtags.php'''.
#*To produce this PHP file, you need a template file (download [[File:Cumuluswebtags.txt]]) that is [[Customised_templates#What_is_meant_by_.27Cumulus_processes_templates.27|processed]] by Cumulus.
#*To produce this PHP file, you need a template file that is [[Customised_templates#What_is_meant_by_.27Cumulus_processes_templates.27|processed]] by Cumulus.
#*For alternative files see [http://sandaysoft.com/forum/viewtopic.php?f=6&t=10424 cumulus web tags support forum link].
#*You may prefer the template that you can download at [http://sandaysoft.com/forum/viewtopic.php?f=6&t=10424 cumulus web tags support forum link].
#*For a discussion about problems with delimiting strings see [http://sandaysoft.com/forum/viewtopic.php?f=4&t=1 another cumulus support forum thread link].
#*The download file on this page (download [[File:Cumuluswebtags.txt]]) contains all current [[webtags]] produced by Cumulus v 1.9.4.
#*The download file contains all current [[webtags]] produced by Cumulus v 1.9.4.
#*Note that in download above 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 so if you want to use them you need to put in the necessary time selectors yourself.<br/><br/>
#*Note that as supplied 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 so if you want to use them you need to put in the necessary time selectors yourself.<br/><br/>
# There was another project [[xml webtags|XML webtags]] but that is now obsolete.<br/><br/>
# There was another project [[xml webtags|XML webtags]] but that is now obsolete.<br/><br/>
# An alternative approach is to use JSON for transferring the variables in a portable way.
# An alternative approach is to use JSON for transferring the variables in a portable way.
5,838

edits