Php webtags: Difference between revisions

9,372 bytes added ,  18:48, 26 June 2020
m
Resequence
m (Resequence)
Line 86: Line 86:
If you want to set up your own json files, you may follow the same approach but need to choose the interval between such sub-arrays that suits your use in your web pages.
If you want to set up your own json files, you may follow the same approach but need to choose the interval between such sub-arrays that suits your use in your web pages.


= Using PHP script =
=Option 2 - implementation details=


If you adopt PHP Hypertext Processing (other alternatives described below) on your web site; there are two main approaches:
If you adopt PHP Hypertext Processing to transfer values to 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 '''parsed''' (interpreted) after the '''template processed by Cumulus''' has been uploaded to your web server, but before the resulting HTML is sent to the browser.
#Either simply [[Customised_templates|customise]] the standard template pages by adding some PHP script that will be '''parsed''' (interpreted) 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 derived value information that Cumulus provides, all your new pages can "'''include_once'''" (if you want the page to fail without that cumulus derived information - use "''require_once''" instead) one, or more, PHP script file(s) 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. After all having to upload multiple full HTML structure definitions for all web pages is a far larger uploading burden than uploading just the files containing the variables at their appropriate frequency.
#Or write a web page including PHP code that does not need to be processed by Cumulus. To get the derived value information that Cumulus provides, all your new pages can "'''include_once'''" (if you want the page to fail without that cumulus derived information - use "''require_once''" instead) one, or more, PHP script file(s) 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. After all having to upload multiple full HTML structure definitions for all web pages is a far larger uploading burden than uploading just the files containing the variables at their appropriate frequency.
Line 347: Line 347:
<?php } ?>
<?php } ?>
</pre>
</pre>
The installation, usage, and example sections below apply to a template file called "cumuluswebtags.txt", so if you are using a file with another name or multiple template files, adapt the instructions as relevant.
== Choose your template(s) ==
First either download a read made template, choosing from those available as listed above; or write your own template(s) following the guidance above.
== Edit your template(s) ==
If you have chosen a ready made template, or have realised you need a PHP variable for a different set of parameters to those coded already, you will need to edit your template.
# It is best to use an editor that allows you to choose the encoding for the file it saves. Any editor designed for editing code should do this (e.g. Notepad++), but word processors and the popular online editors will add unwanted extra characters. The best encoding for files to work with Cumulus is  "UTF-8 without BOM".
# Open your file in your chosen editor.
#*If the first line contains the following sequence of 4 characters "'''&lt;'''" then replace those 4 characters with a single "''<''" (so the first line becomes "''<php''") NOTE - the Wiki cannot have a PHP script uploaded to it, so changing the first line stops the Wiki from treating it as PHP script, but after Cumulus has processed it (Cumulus does not care what it processes, but will copy anything it does not recognise across unchanged) we do want the generated file to be treated as a PHP script.
#Add any new web tags that have been added for the Cumulus version you are using, that were not available when the template was created.
#Next look at any web tags that can take input and/or output parameters; add any parameter combinations that you need for your own implementation.
#*For example, for my implementation, I found that my customisation of the template version had used many more Cumulus web tags with parameters than I expected, consequently my cumuluswebtag.cum template file has (amongst others) the following extras
#**$LastDataReadTDM='<#LastDataReadT format=h:nn'.' on '.'<#LastDataReadT format="d mmm">';
#**$LastDataReadTDMY='<#LastDataReadT format="h:nn am/pm"> on calendar day <#LastDataReadT format="dddd d mmmm yyyy">';
#**$LastTimeStamp='<#LastDataReadT format="h:nn 'on' d mmm">';
#**$metdateM='<#metdate format="mmm">';
#**$metdateMM='<#metdate format="mmmm">';
#**$monthYear='<#metdate format="mmmm yyyy">';
#**$monthStart='<#metdate format="yyyy-mm-01">';
#Next delete any rows with web tags that are not relevant to your weather station model for greater efficiency;
# Finally save your edited template file or files in either the "web" directory where Cumulus has the files it will process or where you store your customised templates.
#* The choice of filename and extension is up to you, it might make sense to use a different name or extension (e,g. "cumuluswebtagsT.cumMX"), if you have edited the file to be sure you don't confuse it and the original and you know which version of Cumulus it is for.
#* If you have several templates being uploaded at different intervals you might choose names like "webtagsRealtimeT.txt", "webtagsNormalT.txt" and "webtagsEoDT.txt".
== Add your template(s) to Extra Files processing ==
=== Cumulus 1 ===
Here is a screenshot for Cumulus 1 using the name as "cumuluswebtags.txt" if you are basically using the provided code).[[File:ScreenShot-PHPWebtags-ConfigSetup.png|right|'Screenshot top and bottom extracts Cumulus v1.9.4']]
#On the 'Cumulus main screen', in the '''Configuration''' menu, select the ''Internet'' option;
#On the 'Internet Settings' screen, select the ''Files'' tab;<br><br>
#Edit the screen columns as indicated by red in the figure:
#*in one of the local side boxes (under the 'Local filenames' header), enter the path (directory\file) to where you have stored the template:<br>e.g. '''your_customised_template_location\cumuluswebtags.txt'''<br> (you can use the 'Browse' button to find and select the exact location of the file);<br><br>
#*in one of the remote side boxes (under the 'Remote filenames' header), enter the name '''cumuluswebtags.php''':
#** -- if needed add the relative server path (see Cumulus Help for explanation) before the file name;
#** (-- if you are using a local server, and want Cumulus to do a 'copy' instead of using 'FTP' then specify the full path for the destination file here);
#** -- ''notice that the file extension has been changed from'' '''txt''' (on the left side) to '''php''' (on the right side) ''as the remote file needs to be recognised by the PHP processor on the web server;''
#* place a check mark in the box under the 'Process?' header;
#** -- this tells Cumulus that the file '''cumuluswebtags.txt''' contains tags which need to be replaced by actual values when it processes the template into a web page;
#*(there is no red arrow under the 'Realtime' header as it may not be appropriate),
#** -- If any of your PHP pages require the latest information at your chosen real-time interval (rather than the 'normal' web site '''updating''' interval) they could be using this file because they require any web tags not in the realtime file, then you might need to select this option (indeed I have on my implementation);
#*place a check mark in the box under the 'UTF-8' header;
#* place a check mark in the box under the 'FTP?' header;
#** -- this tells Cumulus that the processed file must be uploaded by file transfer to the remote Web server with all the other files;
#** (if you use a local web server, you can leave this un-checked and Cumulus will copy across the processed file to the location specified in the right hand box, but for this you need to specify the full path there);
#* place a check mark in the box under the 'UTF-8?' header:
#** -- this tells Cumulus to output the web page using the standard UTF-8 encoding as used by its standard files;
# Finally, click on the lower-right '''OK''' button to save the newly entered settings.
=== Cumulus MX ===
It is broadly similar for Cumulus MX.
# Select '''Settings''' menu in the user interface, then select the ''Extra Files'' page. Scroll through to a page with empty rows if necessary.[[File:Extra.PNG|right|'Screenshot Cumulus v3.5.3']]
# The local file name column does not have the browse selection available in the equivalent Cumulus 1 feature. So be very careful that you type in the full path correctly. You don't need a drive selector, Cumulus will assume the file is on same drive as the MX executable, so only specify drive if it is somewhere else. You might have a feature that allows you to do a list of files and for the file picked show its path, if so you can copy that path into the box in the Local files column.
#* In the example illustrated there are 4 web tag templates, each containing the web tags that are to be processed at a different frequency, all following advice on this page:
#*# one ('static') only needs to be processed once, it is shown as using EOD here, but actually you would use real-time once, and then delete the local name so Cumulus did not try to process it again.
#*# one('real_time') is processed at real time interval and uploaded by FTP at same interval
#*# one ('standard_update') is processed and uploaded at the standard uploading interval
#*# the remaining one is processed and uploaded at the last task when [[Cumulus_MX#MX_End_of_Day_Process|the MX_End_of_Day_Process]] runs.
# The remote filename column needs to contain the FTP path and required destination file name if you want Cumulus MX to FTP the processed file to your web server. If you have your web server on the same local network as the device where you run the MX engine, then MX can use copy to transfer the file to your web server and you need the full path and file name relative to where the Cumulus executable is stored (again you don't need the drive if same drive).
# You must have a tick in the process column, your template file (or files) will not be valid PHP until Cumulus MX has processed it and each PHP variable has a value.
# If you want your file processed and uploaded at the real-time interval you put a tick in the realtime column.
#*Note that Cumulus cannot process a file at the real-time interval unless you have enabled the real-time timer ('''Internet settings''' page, ''Web/FTP settings'' section, tick '''Enable Realtime''')
#*Note that Cumulus cannot upload a file by FTP at the real-time interval unless you have set a FTP process to happen at real-time interval ('''Internet settings''' page, ''Web/FTP settings'' section, tick '''Enable realtime FTP''')
#Unless your web server is on the same local network as your Cumulus software, tick the '''FTP''' column.
#If you have followed the instructions above and saved your file in UTF-8 encoding, tick the '''UTF8''' column.
#Leave the '''Binary''' column unticked.
#If you have not ticked the realtime column, your file will be uploaded at the normal uploading interval unless you tick the '''End of Day''' column. If you do tick here, then your file will be uploaded right at the end of the rollover process, at this stage Cumulus will have the new date in every date type tag, it will have initialised the monthly tags to be empty, and the yesterday tags will have been set. In other words, you will only use this option if you have other web tag templates being uploaded during the day.




5,838

edits