Php webtags: Difference between revisions

3,573 bytes added ,  11:55, 19 April 2020
m
Line 33: Line 33:
=== Option 2: Multiple PHP Variables ===
=== Option 2: Multiple PHP Variables ===


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 [https://cumulus.hosiene.co.uk/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 your customised pages, use the instruction '''require cumuluswebtags.php'''.
*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.
*You may prefer the template that you can download at [https://cumulus.hosiene.co.uk/viewtopic.php?f=6&t=10424&sid=123ca9bf91d769094eed72096c7920ea&start=15#p99549 by Brandon in cumulus support forum link].
*The download file on '''this page''' (download [[File:Cumuluswebtags.txt]]) contains all current [[webtags]] produced by Cumulus v 1.9.4.
'''IMPORTANT''' This file is only for use with Cumulus v1.9.4, it will not work with Cumulus [[Webtags#New_Webtags_in_MX_builds| MX]].
*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.


'''The most up to date''' equivalent for MX is at [https://cumulus.hosiene.co.uk/viewtopic.php?f=39&t=13252&p=103860&hilit=cumuluswebtags.txt#p103830 this page on  support forum], but that was last edited in 2015 and does not contain any web tags added since then.
1. You write one or more Cumulus template files, each having a "&lt;?php" in the first line, each then has a number of lines of the following format:
<pre>$_php_variable_name = '<#_cumulus_tag_name optional_input_parameters optional_output_parameters>';</pre>
 
2. One convention is to make the php_variable_name match the cumulus_tag_name. This breaks down if you use names like $version for other purposes, or if you get confused by the random naming standard adopted by Steve Loft (some yesterday tags have Y at end, some don't, sometimes Y means yesterday, other times Y means yearly), so feel feel free to invent you own consistent naming standard.
 
3. If the cumulus web tag always returns a numeric value, it is better to leave off the quotes, because then it can be used in PHP arithmetic more easily.
 
4. I have shown single quotes there, but they do not always work, see the discussion about problems with delimiting strings at [https://cumulus.hosiene.co.uk/viewtopic.php?f=4&t=1 this cumulus support forum link].
 
5. In the format example, I mention input parameters, see the [[Webtags|Web tags]] page for full details of where you can use them, but they might indicate what information you are seeking if like '''Recent History''' you can get values for a range of different times. I also mention output formats, these are also explained on the web tags page, but they might select whether a time is shown in am/pm format or 24-hour format, whether a date uses the full month name or a number and so on.  You might want to quote the same web tag with different selections and either assign each to a different variable name or to a different element of an array variable.
 
6. You can include PHP comments any where you like, if on a separate line delimit by "/*" to "*/", if at end of line prefix by "#" or "//". Don't put any special characters at the end of this file, it will become pure PHP, and that never uses a terminator "?&gt;". The teminator is needed only in mixed content files when there are HTML statements after the terminator.
 
7. I say above "1 or more template files". Since you can tell Cumulus to process/upload files at different intervals, you might want to include those web tags that change frequently (now and today for example) in a template file that you will action at the real time interval, and include those web tags that rarely change (e.g. yesterday, station-related, units) in a template file that is only uploaded at end of day. Yet another template file can be uploaded at normal updating interval, that might include the monthly and yearly tags for example. You decide what suits your own restrictions on total size of files to upload at different frequencies.
 
8. Having produced this template file, give it a name that makes sense to you, some people include a T just before the extension to remind you it is a template file. The normal extension is ".txt", but you could be inventive and put ".cum" if you want; Cumulus will not care what extension is used for a file it is asked to process.
 
9. The template files are then listed in the "extra files" settings of Cumulus, so they are processed at a selected interval and turned into PHP scripts. 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>.
 
10. To make use of the relevant script in your customised pages, use the instruction '''require cumuluswebtags.php''', substituting whatever you set as the remote name.
 
For more information on how to write a template file or how to ask Cumulus to process files see [[Customised_templates#What_is_meant_by_.27Cumulus_processes_templates.27|processed by Cumulus]] topic.
 
'''Instead of producing your own template''', there are a number already produced, none of them cover all web tags, but they might cover enough for your purposes:
 
*The download file on '''this page''' (download [[File:Cumuluswebtags.txt]]) contains all current [[webtags]] produced by Cumulus v 1.9.4. '''IMPORTANT''' This file is only for use with Cumulus v1.9.4, it will not work with [[CumulusMX|Cumulus  MX]]. 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 so if you want to use them you need to put in the necessary time selectors yourself.
*You may prefer the template that you can download at [https://cumulus.hosiene.co.uk/viewtopic.php?f=6&t=10424&sid=123ca9bf91d769094eed72096c7920ea&start=15#p99549 by Brandon in this cumulus support forum link]. It should work for Cumulus 1 or MX.
* An equivalent for MX only is at [https://cumulus.hosiene.co.uk/viewtopic.php?f=39&t=13252&p=103860&hilit=cumuluswebtags.txt#p103830 this page on  support forum], but that was last edited in 2015 and does not contain any web tags added since then.
* Another version that works with both Cumulus 1 and MX is at [https://cumulus.hosiene.co.uk/viewtopic.php?f=40&t=17985&p=140688#p140688 this post in a zip], once again that does not contain any web tags that are only available in MX.


=== Option 3: EXtensible Markup Language alternative ===
=== Option 3: EXtensible Markup Language alternative ===
5,838

edits