Php webtags: Difference between revisions

From Cumulus Wiki
Jump to navigationJump to search
m (→‎Options available: Improve layout)
Line 5: Line 5:
It is more efficient  for those using PHP on their website to have Cumulus process one single file and place all the [[webtags]] values into a file of PHP variables.  You can include this file in all your PHP web files and use the variables as you would in PHP.
It is more efficient  for those using PHP on their website to have Cumulus process one single file and place all the [[webtags]] values into a file of PHP variables.  You can include this file in all your PHP web files and use the variables as you would in PHP.
=Options available=
=Options available=
# One approach is to create an array '''$WX''' and within it have elements for all the Cumulus web tags. 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 approach includes elements for the recent history tags at 5, 10, 15, 20, 30, 45, 60, 75, 90, 105 and 120 minutes. In this case your customised pages would replace any reference to a Cumulus web tag <#xxyyzz> by a PHP array element $WX[xxyyzz] (some elements include the m=10 type selector).
# One approach is to create an array '''$WX'''
# Another approach is to create a PHP variable for each Cumulus web tag. In this case your customised pages would replace any reference to a Cumulus web tag <#xxyyzz> by a PHP variable $xxyyzz. This is done by the file cumuluswebtags.tx, and this PHP file (download [http://sandaysoft.com/forum/viewtopic.php?f=6&t=10424 cumuluswebtags.txt  link]) contains all current [[webtags]] produced by Cumulus v 1.9.4, but as supplied the recent history tags are commented out and if you want to use them you need to put in the necessary time selectors yourself.
#*Within it have elements for all the Cumulus web tags.
#*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 approach 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 <#xxyyzz> by a PHP array element $WX[xxyyzz] (some elements include the m=10 type selector).
# Another approach is to create a PHP variable for each Cumulus web tag.
#*In this case your customised pages would replace any reference to a Cumulus web tag <#xxyyzz> by a PHP variable $xxyyzz.
#*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.
#*For more information see [http://sandaysoft.com/forum/viewtopic.php?f=6&t=10424 cumulus web tags support forum link].
#*The download file contains all current [[webtags]] produced by Cumulus v 1.9.4.
#*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.
# There was another project [[xml webtags|XML webtags]] but that is now obsolete.
# There was another project [[xml webtags|XML webtags]] but that is now obsolete.
# Yet another approach is to use JSON 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.
# An alternative approach is to use JSON 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.
=Option 2 - implementation details=
The installation, usage, and example sections below apply to option 2, but are similar for the other options.
The installation, usage, and example sections below apply to option 2, but are similar for the other options.
==Installation ==
==Installation ==
For the file you have downloaded at option 2 above, open it in any text editor and look at first and last line.  In each of these find the following sequence of 4 characters "'''&''' '''l''' '''t''' ''';'''" and replace all of those with just one "''<''" and then save the file in the directory where you want Cumulus to read it.
[[File:ScreenShot-PHPWebtags-ConfigSetup.png|right|'Screenshot top and bottom extracts Cumulus v1.9.4']]
[[File:ScreenShot-PHPWebtags-ConfigSetup.png|right|'Screenshot top and bottom extracts Cumulus v1.9.4']]
# Choose a local directory (that Cumulus can read) where you store your customised templates as the destination for this download, or copy the file there after download;
# Choose a local directory (that Cumulus can read) where you store your customised templates as the destination for this download, or copy the file there after download;

Revision as of 20:19, 7 February 2015

Cumulus automatically processes a number of template pages into HTML web pages. These template files contain webtags which Cumulus replaces with actual values from your weather station.

If you adopt PHP Hypertext Processing on your web site, you could customise those standard template pages by simply using PHP script to add extra content after the template has been processed by Cumulus.

It is more efficient for those using PHP on their website to have Cumulus process one single file and place all the webtags values into a file of PHP variables. You can include this file in all your PHP web files and use the variables as you would in PHP.

Options available

  1. One approach is to create an array $WX
    • Within it have elements for all the Cumulus web tags.
    • A file to do this is called CUtags.txt and can be downloaded from Saratoga-Weather.org.
    • That approach 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 <#xxyyzz> by a PHP array element $WX[xxyyzz] (some elements include the m=10 type selector).
  2. Another approach is to create a PHP variable for each Cumulus web tag.
    • In this case your customised pages would replace any reference to a Cumulus web tag <#xxyyzz> by a PHP variable $xxyyzz.
    • 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 processed by Cumulus.
    • For more information see cumulus web tags support forum link.
    • The download file contains all current webtags produced by Cumulus v 1.9.4.
    • 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.
  3. There was another project XML webtags but that is now obsolete.
  4. An alternative approach is to use JSON 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.

Option 2 - implementation details

The installation, usage, and example sections below apply to option 2, but are similar for the other options.

Installation

For the file you have downloaded at option 2 above, open it in any text editor and look at first and last line. In each of these find the following sequence of 4 characters "& l t ;" and replace all of those with just one "<" and then save the file in the directory where you want Cumulus to read it.

'Screenshot top and bottom extracts Cumulus v1.9.4'
  1. Choose a local directory (that Cumulus can read) where you store your customised templates as the destination for this download, or copy the file there after download;
  2. On the 'Cumulus main screen', in the Configuration menu, select the Internet option;
  3. On the 'Internet Settings' screen, select the Files tab;

  4. 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:
      e.g. your_customised_template_location\cumuluswebtags.txt
      (you can use the 'Browse' button to find and select the exact location of the file);

    • in one of the remote side boxes (under the 'Remote filenames' header), enter the name cumuluswebtags.php:
      • -- if you are uploading the Cumulus files to a different server directory (to that specified on the Sites/Options tab), add the relative server path (from either the FTP default or the directory specified on Sites/Options) 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 to the 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;
    • 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;
  5. Finally, click on the lower-right OK button to save the newly entered settings.

Usage

Use the PHP include/require command to include the Cumulus webtags into your PHP file.

All PHP variable names are identical to their webtags equivalent. For example, the Cumulus webtag <#forecast> would be referred to as $forecast in your PHP file.

See Sensor_Contact_PHP for an example script that uses this file.

Example

A simple PHP file:

<?php 
 require_once("cumuluswebtags.php");
 echo $time;
 echo "<br/>";
 Echo "The current forecast is " . $forecast;
?>

The results:

20:31 on 02 September 2009
The current forecast is Precipitation, very unsettled

Debugging

If you wish to view all the values contained within the cumulswebtags.php file, append the parameter ?source=view to the end of the URL.

Example

www.myweathersite.com/cumuluswebtags.php?source=view

This will display the source code of the file, listing all the variable names and the values Cumulus has assigned to the webtags during it's processing cycle.