-
Notifications
You must be signed in to change notification settings - Fork 4
/
runEventDate.php
executable file
·194 lines (136 loc) · 5.11 KB
/
runEventDate.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
#!/usr/bin/php
<?
error_reporting(0);
//
//Version 1 for release
$pluginName ="EventDate";
$myPid = getmypid();
$messageQueue_Plugin = "MessageQueue";
$MESSAGE_QUEUE_PLUGIN_ENABLED=false;
$skipJSsettings = 1;
include_once("/opt/fpp/www/config.php");
include_once("/opt/fpp/www/common.php");
include_once("functions.inc.php");
include_once("commonFunctions.inc.php");
$logFile = $settings['logDirectory']."/".$pluginName.".log";
$messageQueuePluginPath = $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, some features will be disabled");
}
$MATRIX_MESSAGE_PLUGIN_NAME = "MatrixMessage";
//page name to run the matrix code to output to matrix (remote or local);
$MATRIX_EXEC_PAGE_NAME = "matrix.php";
require ("lock.helper.php");
define('LOCK_DIR', '/tmp/');
define('LOCK_SUFFIX', $pluginName.'.lock');
$pluginConfigFile = $settings['configDirectory'] . "/plugin." .$pluginName;
if (file_exists($pluginConfigFile))
$pluginSettings = parse_ini_file($pluginConfigFile);
$logFile = $settings['logDirectory']."/".$pluginName.".log";
$DEBUG=urldecode($pluginSettings['DEBUG']);
//THIS IS O 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(strtoupper($ENABLED) != "ON") {
$REPLY_TEXT_PLUGIN_DISABLED = "We're sorry, the system is not accepting SMS at this time";
logEntry("Plugin Status: DISABLED Please enable in Plugin Setup to use");
lockHelper::unlock();
exit(0);
}
//want to reply even if locked / disabled
if(($pid = lockHelper::lock()) === FALSE) {
exit(0);
}
$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;
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 ((int) $y >= 2){
$messageText .= $y. " years ";
}
if ((int) $d >= 2 ){
$messageText .= $d. " days ";
}
if ((int) $h >= 2 && $INCLUDE_HOURS == "ON"){
$messageText .= $h. " hours ";
}
if ((int) $m >= 2 && $INCLUDE_MINUTES == "ON"){
$messageText .= $m. " minutes ";
}
if ((int) $y == 1){
$messageText .= $y. " year ";
}
if ((int) $d ==1 ){
$messageText .= $d. " day ";
}
if ((int) $h == 1 && $INCLUDE_HOURS == "ON"){
$messageText .= $h. " hour ";
}
if ((int) $m == 1 && $INCLUDE_MINUTES == "ON"){
$messageText .= $m. " minute ";
}
$messageText .= " ".$POST_TEXT. " ".$EVENT_NAME;
$messageText = preg_replace('!\s+!', ' ', $messageText);
logEntry("Adding message ".$messageText. " to message queue");
if($MESSAGE_QUEUE_PLUGIN_ENABLED) {
addNewMessage($messageText,$pluginName,$EVENT_NAME);
} else {
logEntry("MessageQueue plugin is not enabled/installed: Cannot add message: ".$messageText);
}
if($IMMEDIATE_OUTPUT != "ON") {
logEntry("NOT immediately outputting to matrix");
} else {
logEntry ( "IMMEDIATE OUTPUT ENABLED" );
// write high water mark, so that if run-matrix is run it will not re-run old messages
$pluginLatest = time ();
// logEntry("message queue latest: ".$pluginLatest);
// logEntry("Writing high water mark for plugin: ".$pluginName." LAST_READ = ".$pluginLatest);
// file_put_contents($messageQueuePluginPath.$pluginSubscriptions[$pluginIndex].".lastRead",$pluginLatest);
// WriteSettingToFile("LAST_READ",urlencode($pluginLatest),$pluginName);
// do{
logEntry ( "Matrix location: " . $MATRIX_LOCATION );
logEntry ( "Matrix Exec page: " . $MATRIX_EXEC_PAGE_NAME );
$MATRIX_ACTIVE = true;
WriteSettingToFile ( "MATRIX_ACTIVE", urlencode ( $MATRIX_ACTIVE ), $pluginName );
logEntry ( "MATRIX ACTIVE: " . $MATRIX_ACTIVE );
$curlURL = "http://" . $MATRIX_LOCATION . "/plugin.php?plugin=" . $MATRIX_MESSAGE_PLUGIN_NAME . "&page=" . $MATRIX_EXEC_PAGE_NAME . "&nopage=1&subscribedPlugin=" . $pluginName . "&onDemandMessage=" . urlencode ( $messageText );
if ($DEBUG)
logEntry ( "MATRIX TRIGGER: " . $curlURL );
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $curlURL );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $ch, CURLOPT_WRITEFUNCTION, 'do_nothing' );
curl_setopt ( $ch, CURLOPT_VERBOSE, false );
$result = curl_exec ( $ch );
logEntry ( "Curl result: " . $result ); // $result;
curl_close ( $ch );
$MATRIX_ACTIVE = false;
WriteSettingToFile ( "MATRIX_ACTIVE", urlencode ( $MATRIX_ACTIVE ), $pluginName );
}
lockHelper::unlock();
exit(0);
?>