Php webtags: Difference between revisions

1,777 bytes added ,  07:28, 20 April 2020
m
no edit summary
mNo edit summary
mNo edit summary
Line 1: Line 1:
{{TOCright}}
= Introduction =
= Introduction =


Line 8: Line 9:
*# these other files can be resident on your web server, they never need to be updated locally (and uploaded) as they do not need to be processed first locally.
*# these other files can be resident on your web server, they never need to be updated locally (and uploaded) as they do not need to be processed first locally.


This article will first address some of the complications that make providing such a script more difficult than you might expect. This implies that you cannot have a ready made template script that will suit everyone, but also means if you are producing your own set of scripts there is quite a lot to think about. Next this article has links to a number of ready made fairly simple templates explaining which versions of Cumulus they will work with. After that this article helps you to produce your own set of templates, and finally it describes some alternative approaches.
= Using PHP script =
 
If you adopt PHP Hypertext Processing on your web site; there are two main approaches:
#Either simply [[Customised_templates|customise]] the standard template pages by adding some PHP script that will be obeyed after the template processed by Cumulus has been uploaded to your web server, but before the resulting HTML is sent to the browser.
#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 derived information - use "''require''" instead) one, or more, PHP script file that Cumulus '''has'''previously  processed. In that processing all the [[webtags]] values were assigned to PHP variables.  This second approach is more efficient for those using PHP on their website as the actual web pages are produced from PHP scripts on the web server and do not need to be uploaded each time the numbers they output change. In general each full HTML structure definition for a web page is a far larger uploading burden than the file containing the variables.
 
This article will first address some of the complications that make providing such a variable assigning script more difficult than you might expect. The multiple complications imply that nobody can write a ready made single template script that will suit everyone. It also means if you are considering producing your own set of scripts to suit what you might do on your web site, there is quite a lot to think about. Next this article has links to a number of ready made fairly simple templates explaining which versions of Cumulus they will work with. After that this article helps you to produce your own set of templates, while it also describes some alternative approaches.


== Web tag Complications ==
== Web tag Complications ==
Don't think that making all web tags available as PHP variables on your web server is easy, let us see why.


=== Version specific tags ===
=== Version specific tags ===
Line 61: Line 69:
*For the final version 1.9.4 of Cumulus 1 use the download file on '''this page''' (download [[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.
*For the final version 1.9.4 of Cumulus 1 use the download file on '''this page''' (download [[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.
*An alternative simpler template, that should work for Cumulus 1 or MX as it does not contain any output parameters, can be downloaded at [https://cumulus.hosiene.co.uk/viewtopic.php?f=6&t=10424&sid=123ca9bf91d769094eed72096c7920ea&start=15#p99549 by Brandon in this support forum link].
*An alternative simpler template, that should work for Cumulus 1 or MX as it does not contain any output parameters, can be downloaded at [https://cumulus.hosiene.co.uk/viewtopic.php?f=6&t=10424&sid=123ca9bf91d769094eed72096c7920ea&start=15#p99549 by Brandon in this support forum link].
* Another simple template produced by BCJKiwi 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 of mine in a zip], this one does not contain any web tags that are only available in MX, nor does it contain any that require output parameters.
* Another simple template called ''CUtags.txt'' produced by BCJKiwi 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 of mine in a zip], this one does not contain any web tags that are only available in MX, nor does it contain any that require output parameters.
*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 '''<#xxyyzz optional_parameter>''' by a PHP array element '''$WX[xxyyzz] [optional_additional_selector]''' (the recent history web tags include for example '''m=10''' as an input parameter, so you select the one you want using the 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.


= The different Main Approaches to data transfer =


The main focus of this article is assigning to PHP variables, but similar arguments apply for XML or JSON approaches so let us briefly review all the different approaches.


The main focus of this article is assigning to PHP variables, but similar arguments apply for XML or JSON approaches so let us briefly review those.
== Option 1: eXtensible Markup Language alternative ==


= The Four Main Approaches to data transfer =
Extensible Markup Language (XML) is a mark-up language that defines a set of rules for defining data in a format which is very focussed on being machine-readable but both software and hardware independent. Therefore it has great appeal to those writing packages that are designed to be very efficient code, very portable across different applications, where non-technical people just accept the outputs provided and don't need to understand what goes on within the black box. If you don't want to use PHP, or just don't understand how to use it, you might consider this and you will find more about this approach on the [[xml webtags|XML web tags]] page in this wiki.


=== Option 1: Single PHP array ===
Some people consider XML is too complicated and a long winded way to represent variables (they would say languages like PHP are easier for humans to read), but XML was the way that Steve Loft chose to implement the Weather Diary feature in Cumulus 1, so if you want to include whether snow is falling or lying (or the text entered into the diary) in your web pages you must use a routine that reads XML within the PHP you write if you are still using Cumulus 1.
One approach is to create an array '''$WX'''
*Within it have elements for all the Cumulus web tags, choosing which parameter combinations to implement;.
*A file to do this is called ''CUtags.txt'' and 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.
*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).


Before leaving the subject of XML it is worth recording that XML is considered as the best approach for the future by many (for example the WMO and ICAO have specified a XML and geographical location based approach for reporting weather conditions at airports and for some years have been persuading those running airports to swap from METAR in traditional alphanumeric characters. Those were introduced when the shortness of the code was critical for easy transmission by telex). The new approach is not designed for human observers and pilots to read the weather reports, but it makes it easier for computer driven flying to take account of changing weather conditions.


=== Option 2: Multiple PHP Variables ===
 
== Option 2: PHP array or 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:
Line 105: Line 116:
'''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.
'''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.


=== Option 3: EXtensible Markup Language alternative ===
The ready made templates referenced earlier use this approach.
Extensible Markup Language (XML) is a mark-up language that defines a set of rules for defining data in a format which is very focussed on being machine-readable but both software and hardware independent.


You can see more about this approach on the [[xml webtags|XML webtags]] page, but that approach is now considered an obsolete one by some who find languages like PHP easier for humans to read, while XML is considered as the best approach for the future by others (for example the WMO and ICAO have recently specified a XML and geographical based approach for reporting weather conditions at airports and are persauding those running airports to swap from METAR in traditional alphanumeric characters as introduced when the shortness of the code was easiest for transmission by telex).
== Option 3: JavaScript Object Notation ==
 
=== Option 4: JavaScript Object Notation ===
This is a lightweight data-interchange format that is easy for humans to read and write, but critically it is easy for machines to parse and generate for transferring the variables in a portable way.
This is a lightweight data-interchange format that is easy for humans to read and write, but critically it is easy for machines to parse and generate for transferring the variables in a portable way.
*Cumulus MX has one array per weather variable; each element being a sub-array containing a time-stamp and the value at that time.  Again you may need to choose the interval between such sub-arrays that suits your use in your web pages.
*Cumulus MX has one array per weather variable; each element being a sub-array containing a time-stamp and the value at that time.  Again you may need to choose the interval between such sub-arrays that suits your use in your web pages.


= Using PHP script =
If you adopt PHP Hypertext Processing on your web site; there are two main approaches:
#Either simply [[Customised_templates|customise]] the standard template pages by adding some PHP script that will be obeyed after the template has been processed by Cumulus before the resulting HTML is sent to the browser.
#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.


The single file idea of the second choice above might use approach option 1 or option 2, the latter is described further below.
The single file idea of the second choice above might use approach option 1 or option 2, the latter is described further below.
5,838

edits