Php webtags: Difference between revisions

From Cumulus Wiki
Jump to navigationJump to search
1,506 bytes added ,  20:27, 17 May 2021
m
 
(5 intermediate revisions by the same user not shown)
Line 72: Line 72:


== Option 3: JavaScript Object Notation ==
== Option 3: JavaScript Object Notation ==
Anybody using Cumulus MX is already using this option if they are set up to use the example web pages provided in the software package.


This is a lightweight data-interchange format (JSON) 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 (JSON) 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 uses this approach to provide variables for plotting the charts on your web site (Trends web page).
The 3.10.1 release of MX has functionality to optionally generate and upload many more json files for transfers to the external web server - see [[:Category:JSON_Files#Data_Transfer_Format]].
 
<div style="background: LemonChiffon;padding:5px; margin:2px;">
[[File:Crystal Clear info.png|40px]] This document was written for a MX release that is no longer latest!
 
'''The 3.10.1 release of MX changes the settings referenced below'''
</div>
 
Cumulus MX beta (and releases up to 3.9.8) uses this approach solely to provide variables for plotting the charts on your web site (Trends web page).
*To have the json files uploaded to your web site, you must enable '''Include standard files''' within the ''Web/FTP settings'' section of '''Internet Settings'''.
*To have the json files uploaded to your web site, you must enable '''Include standard files''' within the ''Web/FTP settings'' section of '''Internet Settings'''.
*Cumulus MX has one json file per weather chart
*Cumulus MX has one json file per weather chart
Line 82: Line 92:
*The interval between sub-arrays (time and value pairs) depends on the chart, for daily rain and daily temperature there is a sub array for each day; but for most there is a sub-array for every minute (assuming Cumulus is left running for long enough) for a full 24 hours.  
*The interval between sub-arrays (time and value pairs) depends on the chart, for daily rain and daily temperature there is a sub array for each day; but for most there is a sub-array for every minute (assuming Cumulus is left running for long enough) for a full 24 hours.  


For the admin interface, the Cumulus MX engine has to pass information to and from the admin interface, this is done using an application programming interface for each transfer (and each interface uses json format).
For the admin interface, the Cumulus MX engine has to pass information to and from the admin interface, this is done using an [[MX_Administrative_Interface#The_API_interface|application programming interface]] for each transfer (and each interface uses json format).


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.
Line 159: Line 169:
** Check your choice of read-made script can output dates in the format you prefer.
** Check your choice of read-made script can output dates in the format you prefer.


==== Time format =====
==== Time format ====
*Do you prefer 24-hour clock (some call this timetable format or military format) or 12 hour clock with am/pm?
*Do you prefer 24-hour clock (some call this timetable format or military format) or 12 hour clock with am/pm?
**Some ready made scripts may express times in both formats so you can choose the format you want
**Some ready made scripts may express times in both formats so you can choose the format you want
Line 454: Line 464:
<pre>
<pre>
<?php  
<?php  
  require_once("cumuluswebtags.php");
  require_once("cumuluswebtags.inc");
  echo $time;
  echo $time;
  echo "<br/>";
  echo "<br/>";
Line 470: Line 480:
See [[Sensor_Contact_PHP]] for another example script that uses this file.
See [[Sensor_Contact_PHP]] for another example script that uses this file.


==Debugging==
==Viewing the PHP==
 
Any PHP only exists on the web server, all a browser can see is the generated HTML, so this is what you see if you use the web browser's View Source option. As explained in [[PHP]] article not showing PHP has security advantages protecting content that might include stuff you don't want the public to see and preventing unauthorised changing of the script file. (Javascript files can be seen normally and most browsers provide an option to edit them).
 
Some authors when writing a script using PHP do include a downloading option at the start of the script before any other output. These downloaders allow you to see the actual PHP script. Unfortunately, there is no rule on how you invoke this downloader. I tried hard to get standardisation; see [https://cumulus.hosiene.co.uk/viewtopic.php?f=14&t=16425 Source Listing suggestion] in the forum. Another problem my suggestion addressed was the possibility that a web page includes multiple PHP scripts, and the downloader may list a different one to that you wanted to see.
 
Here are some querystrings you might try, in the brandon script download the PHP by appending the querystring <tt>?source=view</tt> to the end of the URL. Other templates might expect you to add the querystring <tt>?parse=source</tt>, <tt>download=source</tt>, <tt>sce=view</tt>,  or reversing the first idea <tt>?view=source</tt>. There are several other variants including <tt>"?view=getorfmiland</tt>.
 


If you wish to view all the values contained within a template file , some files (e.g. the brandon script) let you do this by appending the querystring <tt>?source=view</tt> to the end of the URL. Other templates expect you to add the querystring <code>?parse=source</code> and still others use <tt>?view=source</tt>. There may even be other variants. I tried hard to get standardisation see [https://cumulus.hosiene.co.uk/viewtopic.php?f=14&t=16425 Source Listing suggestion] in the forum, but I know of at least five other variants, source is abbreviated to 'sce' or 'src', and as well as parse, people use 'download'.


Example
Example
Line 479: Line 495:
This will display the source code of the file, listing all the variable names and the values Cumulus has assigned to the web tags during it's processing cycle. It won't show you the original template with web tags in it.
This will display the source code of the file, listing all the variable names and the values Cumulus has assigned to the web tags during it's processing cycle. It won't show you the original template with web tags in it.


[[Category:WebTools]][[Category:User Contributions]]
[[Category:WebTools]][[Category:User Contributions]][[Category:WebTips]]
5,838

edits

Navigation menu