Skip to content

Commit 4976743

Browse files
committed
Removed unnecessary whitespace and php tags
1 parent 9bcbeea commit 4976743

16 files changed

+203
-218
lines changed

beer-panel.php

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* along with BrewPi. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818
?>
19-
2019
<div id="top-bar" class="ui-widget ui-widget-header ui-corner-all">
2120
<div id="lcd" class="lcddisplay"><span class="lcd-text">
2221
<span class="lcd-line" id="lcd-line-0">Live LCD waiting</span>

configuration.php

-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ function getConfig($key, $defaultValue)
44
{
55
return isset($GLOBALS[$key]) ? $GLOBALS[$key] : $defaultValue;
66
}
7-
8-
?>

control-panel.php

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* along with BrewPi. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818
?>
19-
2019
<ul>
2120
<div id="control-bar-text">
2221
<div id="set-mode-text">Set temperature mode:</div>

getLogs.php

-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,3 @@ function getEndOfFile($filename){
5656
}
5757
return str_replace(array("\r\n", "\n", "\r"), '<br />', $output);
5858
}
59-
// no closing tag to prevent newlines in echoed output

get_beer_data.php

+49-50
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,63 @@
1616
* along with BrewPi. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
$beerName = $_POST["beername"];
20-
$fileNames = array();
21-
$currentBeerDir = 'data/' . $beerName;
22-
if(!file_exists($currentBeerDir)){
23-
echo json_encode( array( "error" => "directory: $beerName, does not exist" ) );
24-
return;
19+
$beerName = $_POST["beername"];
20+
$fileNames = array();
21+
$currentBeerDir = 'data/' . $beerName;
22+
if(!file_exists($currentBeerDir)){
23+
echo json_encode( array( "error" => "directory: $beerName, does not exist" ) );
24+
return;
25+
}
26+
$handle = opendir($currentBeerDir);
27+
if($handle == false){
28+
echo json_encode( array( "error" => "Cannot retrieve beer files directory: " . $currentBeerDir ) );
29+
return;
2530
}
26-
$handle = opendir($currentBeerDir);
27-
if($handle == false){
28-
echo json_encode( array( "error" => "Cannot retrieve beer files directory: " . $currentBeerDir ) );
29-
return;
30-
}
31-
$first = true;
32-
$i=0;
33-
while (false !== ($file = readdir($handle))){ // iterate over all json files in directory
34-
$extension = strtolower(substr(strrchr($file, '.'), 1));
35-
if($extension == 'json' ){
36-
$jsonFile = $currentBeerDir . '/' . $file;
37-
$fileNames[$i] = str_replace(".json", "", $jsonFile); // strip extension for sorting
38-
$i=$i+1;
39-
}
31+
$first = true;
32+
$i=0;
33+
while (false !== ($file = readdir($handle))){ // iterate over all json files in directory
34+
$extension = strtolower(substr(strrchr($file, '.'), 1));
35+
if($extension == 'json' ){
36+
$jsonFile = $currentBeerDir . '/' . $file;
37+
$fileNames[$i] = str_replace(".json", "", $jsonFile); // strip extension for sorting
38+
$i=$i+1;
4039
}
41-
closedir($handle);
40+
}
41+
closedir($handle);
4242

43-
$cols = "";
43+
$cols = "";
4444

45-
if ( !empty($fileNames) ) {
45+
if ( !empty($fileNames) ) {
4646

47-
sort($fileNames, SORT_NATURAL); // sort files to return them in order from oldest to newest
48-
array_walk($fileNames, function(&$value) { $value .= '.json'; }); // add .json again
47+
sort($fileNames, SORT_NATURAL); // sort files to return them in order from oldest to newest
48+
array_walk($fileNames, function(&$value) { $value .= '.json'; }); // add .json again
4949

50-
// aggregate all json data for the beer
51-
$renderedRow = false;
52-
echo "{\"rows\":[";
53-
foreach ( $fileNames as $fileName ) {
54-
$contents = file_get_contents(dirname(__FILE__) . '/' . $fileName);
55-
if ( strlen($contents) != 0 ) {
56-
if ( $renderedRow ) {
57-
echo ","; // comma between each file's rows array
58-
}
59-
echo get_list_between($contents, '"rows":' , ']}]');
60-
$renderedRow = true;
50+
// aggregate all json data for the beer
51+
$renderedRow = false;
52+
echo "{\"rows\":[";
53+
foreach ( $fileNames as $fileName ) {
54+
$contents = file_get_contents(dirname(__FILE__) . '/' . $fileName);
55+
if ( strlen($contents) != 0 ) {
56+
if ( $renderedRow ) {
57+
echo ","; // comma between each file's rows array
58+
}
59+
echo get_list_between($contents, '"rows":' , ']}]');
60+
$renderedRow = true;
6161

62-
$colsThisFile = get_list_between($contents, '"cols":' , ']');
63-
if(strlen($colsThisFile) > strlen($cols)){
64-
// use largest column list
65-
$cols = $colsThisFile;
66-
}
62+
$colsThisFile = get_list_between($contents, '"cols":' , ']');
63+
if(strlen($colsThisFile) > strlen($cols)){
64+
// use largest column list
65+
$cols = $colsThisFile;
6766
}
6867
}
69-
echo '],"cols":[' . $cols . ']}';
7068
}
69+
echo '],"cols":[' . $cols . ']}';
70+
}
7171

72-
function get_list_between($string, $start, $end){
73-
$begin = strpos($string,$start);
74-
if ($begin == 0) return "[]"; // return empty list when not found
75-
$begin = strpos($string,"[", $begin) + 1; // start after list opening bracket
76-
$len = strpos($string,$end,$begin) - $begin + strlen($end) - 1;
77-
return substr($string,$begin,$len);
78-
}
79-
?>
72+
function get_list_between($string, $start, $end){
73+
$begin = strpos($string,$start);
74+
if ($begin == 0) return "[]"; // return empty list when not found
75+
$begin = strpos($string,"[", $begin) + 1; // start after list opening bracket
76+
$len = strpos($string,$end,$begin) - $begin + strlen($end) - 1;
77+
return substr($string,$begin,$len);
78+
}

get_beer_files.php

+30-33
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,34 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with BrewPi. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
?>
1918

20-
<?php
21-
$beerName = $_POST["beername"];
22-
$fileNames = array();
23-
$currentBeerDir = 'data/' . $beerName;
24-
if(!file_exists($currentBeerDir)){
25-
echo "directory does not exist";
26-
return;
27-
}
28-
$handle = opendir($currentBeerDir);
29-
if($handle == false){
30-
die("Cannot retrieve beer files directory: " . $currentBeerDir);
31-
}
32-
$first = true;
33-
$i=0;
34-
while (false !== ($file = readdir($handle))){ // iterate over all json files in directory
35-
$extension = strtolower(substr(strrchr($file, '.'), 1));
36-
if($extension == 'json' ){
37-
$jsonFile = $currentBeerDir . '/' . $file;
38-
$fileNames[$i] = str_replace(".json", "", $jsonFile); // strip extension for sorting
39-
$i=$i+1;
40-
}
41-
}
42-
closedir($handle);
43-
if(empty($fileNames)){
44-
echo "";
45-
}
46-
else{
47-
sort($fileNames, SORT_NATURAL); // sort files to return them in order from oldest to newest
48-
array_walk($fileNames, function(&$value) { $value .= '.json'; }); // add .json again
49-
echo json_encode($fileNames);
50-
}
51-
?>
19+
$beerName = $_POST["beername"];
20+
$fileNames = array();
21+
$currentBeerDir = 'data/' . $beerName;
22+
if(!file_exists($currentBeerDir)){
23+
echo "directory does not exist";
24+
return;
25+
}
26+
$handle = opendir($currentBeerDir);
27+
if($handle == false){
28+
die("Cannot retrieve beer files directory: " . $currentBeerDir);
29+
}
30+
$first = true;
31+
$i=0;
32+
while (false !== ($file = readdir($handle))){ // iterate over all json files in directory
33+
$extension = strtolower(substr(strrchr($file, '.'), 1));
34+
if($extension == 'json' ){
35+
$jsonFile = $currentBeerDir . '/' . $file;
36+
$fileNames[$i] = str_replace(".json", "", $jsonFile); // strip extension for sorting
37+
$i=$i+1;
38+
}
39+
}
40+
closedir($handle);
41+
if(empty($fileNames)){
42+
echo "";
43+
}
44+
else{
45+
sort($fileNames, SORT_NATURAL); // sort files to return them in order from oldest to newest
46+
array_walk($fileNames, function(&$value) { $value .= '.json'; }); // add .json again
47+
echo json_encode($fileNames);
48+
}

get_beer_profile.php

+18-21
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,25 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with BrewPi. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
?>
1918

20-
<?php
21-
$profile = $_REQUEST["name"];
22-
$beerProfile = 'data/profiles/' . $profile . ".csv";
23-
if(!file_exists($beerProfile)){
24-
echo json_encode( array( "error" => "beer profile does not exist for beer: $profile" ) );
25-
return;
26-
}
27-
28-
$lines = file($beerProfile, FILE_IGNORE_NEW_LINES) or die(json_encode( array( "error" => "Unable to open profile for beer: " + $profile ) ));
29-
$rows = array();
30-
$idx = 0;
31-
foreach( $lines as $line) {
32-
if ( $idx > 0 ) {
33-
$row = explode(",", $line);
34-
array_push( $rows, array( "date" => $row[0], "temperature" => $row[1], "days" => $row[2]) );
35-
}
36-
$idx++;
19+
$profile = $_REQUEST["name"];
20+
$beerProfile = 'data/profiles/' . $profile . ".csv";
21+
if(!file_exists($beerProfile)){
22+
echo json_encode( array( "error" => "beer profile does not exist for beer: $profile" ) );
23+
return;
24+
}
25+
26+
$lines = file($beerProfile, FILE_IGNORE_NEW_LINES) or die(json_encode( array( "error" => "Unable to open profile for beer: " + $profile ) ));
27+
$rows = array();
28+
$idx = 0;
29+
foreach( $lines as $line) {
30+
if ( $idx > 0 ) {
31+
$row = explode(",", $line);
32+
array_push( $rows, array( "date" => $row[0], "temperature" => $row[1], "days" => $row[2]) );
3733
}
34+
$idx++;
35+
}
3836

39-
$resp = array( "name" => $profile, "profile" => $rows );
37+
$resp = array( "name" => $profile, "profile" => $rows );
4038

41-
echo json_encode($resp);
42-
?>
39+
echo json_encode($resp);

get_beer_profiles.php

+18-21
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,24 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with BrewPi. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
?>
1918

20-
<?php
21-
$profiles = array();
22-
$profilesDir = 'data/profiles';
23-
if(!file_exists($profilesDir)){
24-
echo json_encode( array( "error" => "directory: $profilesDir, does not exist" ) );
25-
return;
19+
$profiles = array();
20+
$profilesDir = 'data/profiles';
21+
if(!file_exists($profilesDir)){
22+
echo json_encode( array( "error" => "directory: $profilesDir, does not exist" ) );
23+
return;
24+
}
25+
$handle = opendir($profilesDir);
26+
if($handle == false){
27+
die("Cannot retrieve profiles directory: " . $profilesDir);
2628
}
27-
$handle = opendir($profilesDir);
28-
if($handle == false){
29-
die("Cannot retrieve profiles directory: " . $profilesDir);
30-
}
31-
$i=0;
32-
while (false !== ($file = readdir($handle))){ // iterate over all csv files in directory
33-
$extension = strtolower(substr(strrchr($file, '.'), 1));
34-
if($extension == 'csv' ){
35-
$profiles[$i] = str_replace(".csv", "", $file); // strip extension for sorting
36-
$i=$i+1;
37-
}
29+
$i=0;
30+
while (false !== ($file = readdir($handle))){ // iterate over all csv files in directory
31+
$extension = strtolower(substr(strrchr($file, '.'), 1));
32+
if($extension == 'csv' ){
33+
$profiles[$i] = str_replace(".csv", "", $file); // strip extension for sorting
34+
$i=$i+1;
3835
}
39-
closedir($handle);
40-
echo json_encode( array( "profiles" => $profiles) );
41-
?>
36+
}
37+
closedir($handle);
38+
echo json_encode( array( "profiles" => $profiles) );

index.php

+13-18
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
* You should have received a copy of the GNU General Public License
1616
* along with BrewPi. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18-
?>
1918

20-
<?php
2119
// load default settings from file
2220
$defaultSettings = file_get_contents('defaultSettings.json');
2321
if($defaultSettings == false){
@@ -42,14 +40,25 @@
4240
}
4341
}
4442

45-
4643
$beerName = $settingsArray["beerName"];
4744
$tempFormat = $settingsArray["tempFormat"];
4845
$profileName = $settingsArray["profileName"];
4946
$dateTimeFormat = $settingsArray["dateTimeFormat"];
5047
$dateTimeFormatDisplay = $settingsArray["dateTimeFormatDisplay"];
51-
?>
5248

49+
function prepareJSON($input) {
50+
//This will convert ASCII/ISO-8859-1 to UTF-8.
51+
//Be careful with the third parameter (encoding detect list), because
52+
//if set wrong, some input encodings will get garbled (including UTF-8!)
53+
$input = mb_convert_encoding($input, 'UTF-8', 'ASCII,UTF-8,ISO-8859-1');
54+
55+
//Remove UTF-8 BOM if present, json_decode() does not like it.
56+
if(substr($input, 0, 3) == pack("CCC", 0xEF, 0xBB, 0xBF)) $input = substr($input, 3);
57+
58+
return $input;
59+
}
60+
61+
?>
5362
<!DOCTYPE html >
5463
<html>
5564
<head>
@@ -97,17 +106,3 @@
97106
<script type="text/javascript" src="js/profile-table.js"></script>
98107
</body>
99108
</html>
100-
101-
<?php
102-
function prepareJSON($input) {
103-
//This will convert ASCII/ISO-8859-1 to UTF-8.
104-
//Be careful with the third parameter (encoding detect list), because
105-
//if set wrong, some input encodings will get garbled (including UTF-8!)
106-
$input = mb_convert_encoding($input, 'UTF-8', 'ASCII,UTF-8,ISO-8859-1');
107-
108-
//Remove UTF-8 BOM if present, json_decode() does not like it.
109-
if(substr($input, 0, 3) == pack("CCC", 0xEF, 0xBB, 0xBF)) $input = substr($input, 3);
110-
111-
return $input;
112-
}
113-
?>

0 commit comments

Comments
 (0)