-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbb-common.php
61 lines (53 loc) · 2 KB
/
bbb-common.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?
function returnIfExists($json, $setting) {
if ($json == null) {
return "";
}
if (array_key_exists($setting, $json)) {
return $json[$setting];
}
return "";
}
function convertAndGetSettings() {
global $settings;
$cfgFile = $settings['configDirectory'] . "/plugin.fpp-BigBeautifulButtons";
if (file_exists($cfgFile)) {
$pluginSettings = parse_ini_file($cfgFile);
$json = array();
for ($x = 1; $x <= 20; $x++) {
$buttonName = "button" . sprintf('%02d', $x);
$color = returnIfExists($pluginSettings, $buttonName . "color");
$desc = returnIfExists($pluginSettings, $buttonName . "desc");
$script = returnIfExists($pluginSettings, $buttonName . "script");
if ($color != "" || $desc != "" || $script != "") {
$json["buttons"][$x]["description"] = $desc;
$json["buttons"][$x]["color"] = $color;
if ($script != "" && $script != null) {
$json["buttons"][$x]["command"] = "Run Script";
$json["buttons"][$x]["args"][] = $script;
} else {
$json["buttons"][$x]["command"] = "";
}
}
}
$fontsize = returnIfExists($pluginSettings, "buttonFontSize");
if ($fontsize != "" && $fontsize != null) {
$json["fontSize"] = (int)$fontsize;
}
$title = returnIfExists($pluginSettings, "buttonTitle");
if ($title != "" && $title != null) {
$json["title"] = $title;
}
file_put_contents($cfgFile . ".json", json_encode($json, JSON_PRETTY_PRINT));
unlink($cfgFile);
return $json;
}
if (file_exists($cfgFile . ".json")) {
$j = file_get_contents($cfgFile . ".json");
$json = json_decode($j, true);
return $json;
}
$j = "{\"fontSize\": 12, \"title\": \"\", \"buttons\": {\"1\": {}}}";
return json_decode($j, true);
}
?>