-
Notifications
You must be signed in to change notification settings - Fork 1
/
runCountdown.php
305 lines (258 loc) · 7.91 KB
/
runCountdown.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
#!/usr/bin/php
<?
$pluginName = basename(dirname(__FILE__));
$skipJSsettings = 1;
include_once("/opt/fpp/www/common.php");
include_once("functions.inc.php");
$logFile = $settings['logDirectory']."/".$pluginName.".log";
$pluginConfigFile = $settings['configDirectory'] . "/plugin." .$pluginName;
//get settings and if no user stored setting, use a default value
if (file_exists($pluginConfigFile)){
$pluginSettings = parse_ini_file($pluginConfigFile);
}else{
$pluginSettings = array(); //There have been no settings saved by the user, create empty array
}
if (isset($pluginSettings['ENABLED'])){
$enabled = $pluginSettings['ENABLED'];
}else{
$enabled ="";
logEntry("Plugin has not been enabled, exiting");
exit(0);
}
if (isset($pluginSettings['EVENT_NAME'])){
$eventName = $pluginSettings['EVENT_NAME'];
}else{
$eventName ="The Event!";
logEntry("Event Name not specifically defined, using default The Event!");
}
if (isset($pluginSettings['MONTH'])){
$month = $pluginSettings['MONTH'];
}else{
$month ="1";
logEntry("Month not specifically defined, using default of January");
}
if (isset($pluginSettings['DAY'])){
$day = $pluginSettings['DAY'];
}else{
$day ="1";
logEntry("Day not specifically defined, using default of 1");
}
if (isset($pluginSettings['YEAR'])){
$year = $pluginSettings['YEAR'];
}else{
$year = date("Y")+1;
logEntry("Year not specifically defined, using default of next year");
}
if (isset($pluginSettings['HOUR'])){
$hour = $pluginSettings['HOUR'];
}else{
$hour = "0";
logEntry("Hour not specifically defined, using default");
}
if (isset($pluginSettings['MIN'])){
$minute = $pluginSettings['MIN'];
}else{
$minute = "0";
logEntry("Minutes not specifically defined, using default");
}
if (isset($pluginSettings['PRE_TEXT'])){
$preText = $pluginSettings['PRE_TEXT'];
}else{
$preText = "It is";
logEntry("Pre Text not specifically defined, using default");
}
if (isset($pluginSettings['POST_TEXT'])){
$postText = $pluginSettings['POST_TEXT'];
}else{
$postText = "until";
logEntry("Post Text not specifically defined, using default");
}
if (isset($pluginSettings['COUNTUP_PRE_TEXT'])){
$countUpPreText = $pluginSettings['COUNTUP_PRE_TEXT'];
}else{
$countUpPreText = "It has been";
logEntry("Count up Pre Text not specifically defined, using default");
}
if (isset($pluginSettings['COUNTUP_POST_TEXT'])){
$countUpPostText = $pluginSettings['COUNTUP_POST_TEXT'];
}else{
$countUpPostText = "since";
logEntry("Count up Post Text not specifically defined, using default");
}
if (isset($pluginSettings['COMPLETED_MESSAGE'])){
$completedText = $pluginSettings['COMPLETED_MESSAGE'];
}else{
$completedText = "since";
logEntry("Completed Text not specifically defined, using default");
}
if (isset($pluginSettings['COUNT_UP'])){
$countup = $pluginSettings['COUNT_UP'];
}else{
$countup = "";
logEntry("Count up not specifically defined, using default of off");
}
if (isset($pluginSettings['INCLUDE_HOURS'])){
$includeHours = $pluginSettings['INCLUDE_HOURS'];
}else{
$includeHours = "";
logEntry("Include hours not specifically defined, using default");
}
if (isset($pluginSettings['INCLUDE_MINUTES'])){
$includeMinutes = $pluginSettings['INCLUDE_MINUTES'];
}else{
$includeMinutes = "";
logEntry("Include minutes not specifically defined, using default");
}
if (isset($pluginSettings['HOST_LOCATION']))
$hostLocation = $pluginSettings['HOST_LOCATION'];
if (isset($pluginSettings['OVERLAY_MODEL'])){
$overlayModel = urldecode($pluginSettings['OVERLAY_MODEL']);
}else{
$overlayModel = reset(GetOverlayList());
if ($overlayModel ==""){
logEntry("****ERROR**** Overlay Model not specifically defined and there are no Pixel Overlay Models defined");
}
logEntry("Overlay Model not specifically defined, using default Overlay instead");
}
if (isset($pluginSettings['OVERLAY_MODE'])){
$overlayMode = urldecode($pluginSettings['OVERLAY_MODE']);
switch ($overlayMode){
case "1":
$auto="Enabled";
break;
case "2":
$auto="Transparent";
break;
case "3":
$auto="TransparentRGB";
break;
default:
$auto="Enabled";
}
}else{
$auto="Enabled";
logEntry("Overlay Mode not specifically defined, using default Full Overlay instead");
}
if (isset($pluginSettings['FONT'])){
$font = urldecode($pluginSettings['FONT']);
}else{
$font = reset(getFontsInstalled());
logEntry("Font not specifically defined, using default of first font found");
}
if (isset($pluginSettings['FONT_SIZE'])){
$fontSize = urldecode($pluginSettings['FONT_SIZE']);
}else{
$fontSize = "20";
logEntry("Font Size not specifically defined, using default size of 20 instead");
}
if (isset($pluginSettings['FONT_ANTIALIAS'])){
$fontAntialias = urldecode($pluginSettings['FONT_ANTIALIAS']);
}else{
$fontAntialias = "";
logEntry("AntiAlias not specifically defined, using default no AntiAlias instead");
}
if (isset($pluginSettings['SCROLL_SPEED'])){
$scrollSpeed = urldecode($pluginSettings['SCROLL_SPEED']);
}else{
$scrollSpeed = "20";
logEntry("Scroll Speed not specifically defined, using default of 20 instead");
}
$Position="R2L";
if ($scrollSpeed=="0"){
$Position="Center";
}
if (isset($pluginSettings['DURATION'])){
$duration = urldecode($pluginSettings['DURATION']);
}else{
$duration = "20";
logEntry("Duration not specifically defined, using default of 20 instead");
}
if (isset($pluginSettings['COLOR'])){
$color = urldecode($pluginSettings['COLOR']);
}else{
$color = "#ffffff";
logEntry("Color not specifically defined, using default of White instead");
}
$strEventDate = $year."-".$month."-".$day." ".$hour.":".$minute.":00";
logEntry( "event date: ".$strEventDate);
$date1 = strtotime($strEventDate);
$date2 = time();
$subTime = $date1 - $date2;
$elapsed=false;
if ($subTime<0){
$elapsed=true;
}
$y = abs($subTime/(60*60*24*365));
$d = abs(($subTime/(60*60*24))%365);
$h = abs(($subTime/(60*60))%24);
$m = abs(($subTime/60)%60 +1);
if ($elapsed){
$messagePreText = $countUpPreText;
$messagePostText = $countUpPostText;
$m +=1;
}else{
$messagePreText = $preText;
$messagePostText = $postText;
}
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");
$messageText = $messagePreText;
if ($y >= 1){
if ($y >=2){
$messageText .= intval($y). " years ";
} else {
$messageText .= intval($y). " year ";
}
} else {
$messageText .= " ";
}
if ($d >= 1){
if ($d >=2){
$messageText .= intval($d). " days ";
} else {
$messageText .= intval($d). " day ";
}
if($includeHours == "ON"){
if ($h >=2) {
$messageText .= intval($h). " hours ";
} else {
if ($h >= 1) {
$messageText .= intval($h). " hour ";
}
}
}
if($includeMinutes == "ON"){
if($includeHours == "OFF"){
$m += $h *60;
}
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 ";
}
}
if ($elapsed && $countup!="ON"){
$messageText= "Countdown complete! Your target is in the past.";
}else{
$messageText .= " ".$messagePostText. " ".$eventName;
}
$messageText = preg_replace('!\s+!', ' ', $messageText);
logEntry("messageText= ".$messageText);
//error_log("RunEventDate.php- messageText= ".$messageText);
logEntry("ScrollText options-hostLocation= ".$hostLocation. " overlayModel= ".$overlayModel. " Position= " .$Position. " Font = " .$font. " fontsize= " .$fontSize. " fontColor= " .$color. " scrollSpeed= " .$scrollSpeed. " Auto= " .$auto." duration= " .$duration);
ScrollText($hostLocation, $overlayModel, $messageText, $Position, $font, $fontSize, $color, $scrollSpeed, $fontAntialias, $duration, $auto);
exit(0); //is this needed?
?>