forked from FalconChristmas/FPP-Plugin-EventDate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_setup.php
executable file
·357 lines (263 loc) · 9.03 KB
/
plugin_setup.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?php
include_once "/opt/fpp/www/common.php";
include_once 'functions.inc.php';
include_once 'commonFunctions.inc.php';
$pluginName = basename(dirname(__FILE__));
include_once 'version.inc';
$PLAYLIST_NAME="";
$MAJOR = "98";
$MINOR = "01";
$eventExtension = ".fevt";
//arg0 is the program
//arg1 is the first argument in the registration this will be --list
$DEBUG=false;
$SMSEventFile = $eventDirectory . "/" . $MAJOR . "_" . $MINOR.$eventExtension;
$SMSGETScriptFilename = $scriptDirectory."/".$pluginName."_GET.sh";
$messageQueue_Plugin = "MessageQueue";
if (strpos($pluginName, "FPP-Plugin") !== false) {
$messageQueue_Plugin = "FPP-Plugin-MessageQueue";
}
$MESSAGE_QUEUE_PLUGIN_ENABLED=false;
$logFile = $settings['logDirectory']."/".$pluginName.".log";
$messageQueuePluginPath = $settings['pluginDirectory'] . "/" . $messageQueue_Plugin."/";
$messageQueueFile = urldecode(ReadSettingFromFile("MESSAGE_FILE", $messageQueue_Plugin));
if(file_exists($messageQueuePluginPath . "functions.inc.php"))
{
include $messageQueuePluginPath . "functions.inc.php";
$MESSAGE_QUEUE_PLUGIN_ENABLED=true;
} else {
logEntry("Message Queue Plugin not installed, please install");
echo "Message Queue Plugin not installed, please install and return to this plugin page";
exit(0);
}
$gitURL = "https://github.com/FalconChristmas/FPP-Plugin-EventDate.git";
$pluginUpdateFile = $settings['pluginDirectory']."/".$pluginName."/"."pluginUpdate.inc";
logEntry("plugin update file: " . $pluginUpdateFile);
if(isset($_POST['updatePlugin']))
{
$updateResult = updatePluginFromGitHub($gitURL, $branch="master", $pluginName);
logEntry("update result: ". $updateResult);//."<br/> \n";
if(file_exists($settings['pluginDirectory']."/".$pluginName."/fpp_install.sh"))
{
$updateInstallCMD = $settings['pluginDirectory']."/".$pluginName."/fpp_install.sh";
logEntry("running upgrade install script: ".$updateInstallCMD);
exec($updateInstallCMD,$sysOutput);
//echo $sysOutput;
} else {
logEntry("No fpp_install.sh upgrade script available");
}
}
if (isset($pluginSettings['DEBUG'])) {
$DEBUG = $pluginSettings['DEBUG'];
}
if(isset($_POST['submit']))
{
if($DEBUG)
print_r($_POST);
// echo "Writring config fie <br/> \n";
WriteSettingToFile("MONTH",urlencode($_POST['MONTH']), $pluginName);
WriteSettingToFile("DAY",urlencode($_POST['DAY']), $pluginName);
WriteSettingToFile("YEAR",urlencode($_POST['YEAR']), $pluginName);
WriteSettingToFile("MIN",urlencode($_POST['MIN']), $pluginName);
WriteSettingToFile("HOUR",urlencode($_POST['HOUR']), $pluginName);
WriteSettingToFile("PRE_TEXT",urlencode($_POST["PRE_TEXT"]), $pluginName);
WriteSettingToFile("POST_TEXT",urlencode($_POST["POST_TEXT"]), $pluginName);
WriteSettingToFile("EVENT_NAME",urlencode($_POST["EVENT_NAME"]), $pluginName);
WriteSettingToFile("LAST_READ",urlencode($_POST["LAST_READ"]), $pluginName);
WriteSettingToFile("MATRIX_LOCATION",urlencode($_POST["MATRIX_LOCATION"]), $pluginName);
$pluginConfigFile = $settings['configDirectory'] . "/plugin." . $pluginName;
if (file_exists($pluginConfigFile)) {
$pluginSettings = parse_ini_file($pluginConfigFile);
}
}
//THIS IS SO COOL!
//set the variable names as necessary??? do we even need to do this???
foreach ($pluginSettings as $key => $value) {
if($DEBUG) {
logEntry("KEY: ".$key." = ".$value);
}
// echo "Key: ".$key." " .$value."\n";
${$key} = urldecode($value);
}
if(!isset($PRE_TEXT) || $PRE_TEXT == "") {
$PRE_TEXT = "It is ";
}
if(!isset($POST_TEXT) || $POST_TEXT =="") {
$POST_TEXT = " until ";
}
if(!isset($EVENT_NAME) || $EVENT_NAME == "") {
$EVENT_NAME = " THE EVENT!";
}
if(!isset($LAST_READ) || (int)$LAST_READ == 0 || $LAST_READ == "") {
$LAST_READ=0;
}
if (!isset($YEAR)) {
$YEAR = date("Y");
}
if (!isset($MONTH)) {
$MONTH = 12;
}
if (!isset($DAY)) {
$DAY = 25;
}
if (!isset($HOUR)) {
$HOUR = 0;
}
if (!isset($MIN)) {
$MIN = 0;
}
$Plugin_DBName = $messageQueueFile;
$db = new SQLite3($Plugin_DBName) or die('Unable to open database');
//create the default tables if they do not exist!
createTables();
?>
<html>
<head>
</head>
<div id="EventDate" class="settings">
<fieldset>
<legend><?php echo $pluginName . " Version: ". $pluginVersion;?> Support Instructions</legend>
<p>Known Issues:
<ul>
<li>None
</ul>
<p>Configuration:
<ul>
<li>Configure the date and time of your event</li>
<li>Enter in the PRE TEXT that will appear before your countdown</li>
<li>Configure 12 or 24 hour countdown mode</li>
<li>Schedule the event in your Playlist to send the countdown out your Matrix</li>
</ul>
<p/>
<b>This plugin requires ACCURATE time for its calculation. Please ensure RTC is working properly</b>
<p/>
<form method="post" action="/plugin.php?plugin=<?echo $pluginName;?>&page=plugin_setup.php">
<?
//will add a 'reset' to this later
echo "<input type=\"hidden\" name=\"LAST_READ\" value=\"".$LAST_READ."\"> \n";
$restart=0;
$reboot=0;
echo "ENABLE PLUGIN: ";
PrintSettingCheckbox("Plugin: " . $pluginName . " ", "ENABLED", $restart = 0, $reboot = 0, "ON", "OFF", $pluginName = $pluginName, $callbackName = "");
echo "<p/> \n";
echo "Pre Text: (It is): \n";
echo "<input type=\"text\" value=\"".$PRE_TEXT."\" name=\"PRE_TEXT\"> \n";
echo "<p/> \n";
$strEventDate = $YEAR."-".$MONTH."-".$DAY." ".$HOUR.":".$MIN.":00";
logEntry( "event date: " . $strEventDate);
//$date1 = strtotime('2013-07-03 18:00:00');
$date1 = strtotime($strEventDate);
$date2 = time();
$subTime = $date1 - $date2;
//$subTime = $date2 - $date1;
$y = ($subTime/(60*60*24*365));
$d = ($subTime/(60*60*24))%365;
$h = ($subTime/(60*60))%24;
$m = ($subTime/60)%60 + 1;
logEntry( "Difference between ".date('Y-m-d H:i:s',$date1)." and ".date('Y-m-d H:i:s',$date2)." is:".$y." years ".$d." days ".$h." hours ".$m." minutes");
//echo $y." years\n";
//echo $d." days\n";
//echo $h." hours\n";
//echo $m." minutes\n";
$messageText = $PRE_TEXT;
if ($y >= 1){
if ($y >=2){
$messageText .= intval($y). " years ";
} else {
$messageText .= intval($y). " year ";
}
}
if ($d >= 1){
if ($d >=2){
$messageText .= intval($d). " days ";
} else {
$messageText .= intval($d). " day ";
}
if($INCLUDE_HOURS == "ON"){
if ($h >=2) {
$messageText .= intval($h). " hours ";
} else {
if ($h >= 1) {
$messageText .= intval($h). " hour ";
}
}
}
if($INCLUDE_MINUTES == "ON"){
if ($m >=2) {
$messageText .= intval($m). " minutes ";
} else {
$messageText .= intval($m). " minute ";
}
}
} else {
if ($h >=2) {
$messageText .= intval($h). " hours ";
} else {
if ($h >=1) {
$messageText .= intval($h). " hour ";
}
}
if ($m >=2) {
$messageText .= intval($m). " minutes ";
} else {
$messageText .= intval($m). " minute ";
}
}
$messageText .= " ".$POST_TEXT. " ".$EVENT_NAME;
echo "<p/> \n";
echo "EVENT DATE: \n";
printMonthSelection($MONTH, "MONTH");
printDaySelection($DAY, "DAY");
printYearSelection($YEAR, "YEAR");
echo "Hour: \n";
printHourSelection($HOUR, "HOUR");
echo "Min: \n";
printMinSelection($MIN, "MIN");
echo "<p/> \n";
echo "Post Text: (Until <Event Name>): \n";
echo "<input type=\"text\" value=\"".$POST_TEXT."\" name=\"POST_TEXT\"> \n";
echo "<p/> \n";
echo "Event Name: (Christmas, Halloween, Labor day): \n";
echo "<input type=\"text\" value=\"".$EVENT_NAME."\" name=\"EVENT_NAME\"> \n";
echo "<p/>";
echo "If Remaining time >= 1 day, include: \n";
echo "<br/> \n";
echo "Include Hours: \n";
PrintSettingCheckbox("Include Days ", "INCLUDE_HOURS", $restart = 0, $reboot = 0, "ON", "OFF", $pluginName = $pluginName, $callbackName = "");
echo "<br/> \n";
echo "Include Minutes: \n";
PrintSettingCheckbox("Include Hours", "INCLUDE_MINUTES", $restart = 0, $reboot = 0, "ON", "OFF", $pluginName = $pluginName, $callbackName = "");
echo "<p/> \n";
echo "Will appear as: \n";
echo "<hr/> \n";
echo "<marquee behavior=\"scroll\" scrollamount=\"5\" direction=\"left\" onmouseover=\"this.stop();\" onmouseout=\"this.start();\">\n";
echo preg_replace('!\s+!', ' ', $messageText);
echo "</marquee> \n";
echo "<hr/> \n";
echo "<p/> \n";
echo "Immediately output to Matrix (Run MATRIX plugin): ";
//if($IMMEDIATE_OUTPUT == "on" || $IMMEDIATE_OUTPUT == 1) {
// echo "<input type=\"checkbox\" checked name=\"IMMEDIATE_OUTPUT\"> \n";
PrintSettingCheckbox("Immediate output to Matrix", "IMMEDIATE_OUTPUT", $restart = 0, $reboot = 0, "ON", "OFF", $pluginName = $pluginName, $callbackName = "");
//} else {
//echo "<input type=\"checkbox\" name=\"IMMEDIATE_OUTPUT\"> \n";
//}
echo "<p/> \n";
?>
MATRIX Message Plugin Location: (IP Address. default 127.0.0.1);
<input type="text" size="15" value="<? if($MATRIX_LOCATION !="" ) { echo $MATRIX_LOCATION; } else { echo "127.0.0.1";}?>" name="MATRIX_LOCATION" id="MATRIX_LOCATION"></input>
<p/>
<input id="submit_button" name="submit" type="submit" class="buttons" value="Save Config">
<?
if(file_exists($pluginUpdateFile))
{
//echo "updating plugin included";
include $pluginUpdateFile;
}
?>
</form>
<p>To report a bug, please file it against the sms Control plugin project on Git:<? echo $gitURL;?>
</fieldset>
</div>
<br />
</html>