5,838
edits
m (→What is meant by 'Cumulus processes templates': Possibility of processing CSS) |
|||
If a particular webpage on a local web server includes a script requiring loading a local file like 'dayfile.txt', then just for that webpage enter its remote web file name, and select Binary and File Transfer Process, as per the previous set of instructions. (The remaining pages will be copied across locally using the specified full path without FTP as per instructions directly above).
= Using PHP Hypertext Pre-processor =
This Wiki article cannot teach you PHP, but it can give you some pointers.
== Using PHP templates ==
This approach incorporates some PHP script in a page that still contains Cumulus web tags so still requires processing by Cumulus. This is suitable when you want to try PHP, but do not want a big redesign of your set-up.
*The file still contains the HTML shown earlier, indeed it might be a simple edit of a standard cumulus template.
*It still contains Cumulus web tags, but as it is no longer a standard page, it has to be listed on the ''Files'' tab of the '''Internet''' screen within the 'Configuration' menu; the remote file name must have the extension ".php" so that the PHP processor will parse the file, before it is passed to the browser as a HTML page.
*The php script might be used for a decision more complicated than the [[Webtags_as_boolean_operators_in_HTML|boolean options]] that can be achieved just with standard HTML. For example, in the UK vehicle headlights must be used between half-an hour after sunset to half-an-hour before sunrise, so maybe you want to modify your "todayT.htm" page that becomes "today.htm" so it becomes "today.php" instead and incorporates 2 new chunks of code:
<code>
<?php // start of PHP script setting new variables not available in Cumulus web tags
// end of lighting up time (hours of darkness)
$darkness_end = new DateTime($latestDay.' '.$sunrise); // sunrise
$darkness_end -> sub(DateInterval::createFromDateString('30 minutes')); // subtract 30 minutes
// start of lighting up time (hours of darkness)
$darkness_start= new DateTime($latestDay.' '.$sunset); // sunset
$darkness_start-> add(new DateInterval('P0Y0DT0H30M')); // add 30 minutes
?> <!-- end of PHP script -->
....
<tr>
<th title="Darkness times calculated by PHP">Darkness starts</th>
<td><?php
echo ($darkness_start->format('g:i a'));
?></td>
</tr><tr>
<th>Darkness ends</th>
<td><?php
echo ($darkness_end->format('g:i a'));
?></td>
</tr>
</code>
== Replacing HTML by PHP ==
#A more efficient approach, this is a bigger implementation change, is to set Cumulus to process just [[Php_webtags| this file]] to create PHP variables/arrays from the Cumulus web tags you want to use.
#Then you create a new PHP script that does not get processed by Cumulus. For example "thismonth.php" would start with the same HTML5 as shown above, but the table is output by the PHP script:
<code><!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="<#location> weather data" />
<meta name="keywords" content="Cumulus, <#location> weather data, weather, data, weather station" />
<title><?php
include 'cumuluswebtags.php';
echo "$location";
?>weather</title>
<link href="weatherstyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="content">
<h1><?php
echo "$location";
?> weather</h1>
....
<table style="width:100%;border-collapse: collapse; border-spacing: 0;" >
<caption>This month's highs and lows</caption>
<tr>
<td colspan="3" class="tableseparator_temp">Temperature and Humidity </td>
</tr>
<tr class="td_temperature_data">
<?php
echo "<th>Highest</th>";
echo "<td>$MonthTempH $tempunit</td>";
echo "<td>$MonthTempHT on $MonthTempHD</td>";
echo "<th>Lowest</th>";
echo "<td>$MonthTempL $tempunit</td>";
echo "<td>$MonthTempLT on $MonthTempLD</td>";
?>
</tr>
....
echo <<< END_OF_QUOTE
<tr>
<td colspan="2" class="spacer">Pressure (sea level)</td>
</tr>
<tr>
<th class="labels">Lowest</th>
<td class="site_data">$MonthPressL {$pressunit}</td>
<td class="time_stamp">at $MonthPressLT on $MonthPressLD</td>
</tr>
<tr>
<th class="labels">Highest</th>
<td class="site_data">$MonthPressH {$pressunit}</td>
<td class="time_stamp">at $MonthPressHT on $MonthPressHD</td>
</tr>
</table>
END_OF_QUOTE;
....
</code>
Note that only excerpts from the code are shown. Note the two ways of getting PHP to output HTML code, either by using separate echo commands for each line or using the "heredoc" approach so that one echo can be applied to multiple lines. In the latter way, the syntax allows a space after echo and after <<< but does not allow any other spaces (or tabs) in the enclosing lines.
|
edits