forked from LightsOnHudson/FPP-Plugin-Projector-Control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commonFunctions.inc.php
executable file
·171 lines (111 loc) · 3.65 KB
/
commonFunctions.inc.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
function updatePluginFromGitHub($gitURL, $branch="master", $pluginName) {
global $settings;
logEntry ("updating plugin: ".$pluginName);
logEntry("settings: ".$settings['pluginDirectory']);
//create update script
//$gitUpdateCMD = "sudo cd ".$settings['pluginDirectory']."/".$pluginName."/; sudo /usr/bin/git git pull ".$gitURL." ".$branch;
$pluginUpdateCMD = "/opt/fpp/scripts/update_plugin ".$pluginName;
logEntry("update command: ".$pluginUpdateCMD);
exec($pluginUpdateCMD, $updateResult);
//logEntry("update result: ".print_r($updateResult));
//loop through result
return;// ($updateResult);
}
//create script to randmomize
function createScriptFile($scriptFilename,$scriptCMD) {
global $scriptDirectory,$pluginName;
$scriptFilename = $scriptDirectory."/".$scriptFilename;
logEntry("Creating script: ".$scriptFilename);
$ext = pathinfo($scriptFilename, PATHINFO_EXTENSION);
$data = "";
$data .="#!/bin/sh\n";
$data .= "\n";
$data .= "#Script to run randomizer\n";
$data .= "#Created by ".$pluginName."\n";
$data .= "#\n";
$data .= "/usr/bin/php ".$scriptCMD."\n";
logEntry($data);
$fs = fopen($scriptFilename,"w");
fputs($fs, $data);
fclose($fs);
}
//return the next event file available for use
//get the next available event filename
function getNextEventFilename() {
$MAX_MAJOR_DIGITS=2;
$MAX_MINOR_DIGITS=2;
global $eventDirectory;
//echo "Event Directory: ".$eventDirectory."<br/> \n";
$MAJOR=array();
$MINOR=array();
$MAJOR_INDEX=0;
$MINOR_INDEX=0;
$EVENT_FILES = directoryToArray($eventDirectory, false);
//print_r($EVENT_FILES);
foreach ($EVENT_FILES as $eventFile) {
$eventFileParts = explode("_",$eventFile);
$MAJOR[] = (int)basename($eventFileParts[0]);
//$MAJOR = $eventFileParts[0];
$minorTmp = explode(".fevt",$eventFileParts[1]);
$MINOR[] = (int)$minorTmp[0];
//echo "MAJOR: ".$MAJOR." MINOR: ".$MINOR."\n";
//print_r($MAJOR);
//print_r($MINOR);
}
$MAJOR_INDEX = max(array_values($MAJOR));
$MINOR_INDEX = max(array_values($MINOR));
//echo "Major max: ".$MAJOR_INDEX." MINOR MAX: ".$MINOR_INDEX."\n";
if($MAJOR_INDEX <= 0) {
$MAJOR_INDEX=1;
}
if($MINOR_INDEX <= 0) {
$MINOR_INDEX=1;
} else {
$MINOR_INDEX++;
}
$MAJOR_INDEX = str_pad($MAJOR_INDEX, $MAX_MAJOR_DIGITS, '0', STR_PAD_LEFT);
$MINOR_INDEX = str_pad($MINOR_INDEX, $MAX_MINOR_DIGITS, '0', STR_PAD_LEFT);
//for now just return the next MINOR index up and keep the same Major
$newIndex=$MAJOR_INDEX."_".$MINOR_INDEX.".fevt";
//echo "new index: ".$newIndex."\n";
return $newIndex;
}
function directoryToArray($directory, $recursive) {
$array_items = array();
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($directory. "/" . $file)) {
if($recursive) {
$array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive));
}
$file = $directory . "/" . $file;
$array_items[] = preg_replace("/\/\//si", "/", $file);
} else {
$file = $directory . "/" . $file;
$array_items[] = preg_replace("/\/\//si", "/", $file);
}
}
}
closedir($handle);
}
return $array_items;
}
//check all the event files for a string matching this and return true/false if exist
function checkEventFilesForKey($keyCheckString) {
global $eventDirectory;
$keyExist = false;
$eventFiles = array();
$eventFiles = directoryToArray($eventDirectory, false);
foreach ($eventFiles as $eventFile) {
if( strpos(file_get_contents($eventFile),$keyCheckString) !== false) {
// do stuff
$keyExist= true;
break;
// return $keyExist;
}
}
return $keyExist;
}
?>