-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfunctions.inc.php
executable file
·198 lines (142 loc) · 5 KB
/
functions.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
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
<?php
//from weather plugin // pjd 7/15/2019
function getHTML($url,$timeout)
{
$ch = curl_init($url); // initialize curl with given url
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
return @curl_exec($ch);
}
//get north pole scrape
function getNorthPole() {
include_once("simple_html_dom.php");
//use curl to get html content
$html=getHTML("http://psc.apl.washington.edu/northpole/",10);
// Find all images on webpage
// Find all links on webpage
foreach($html->find("a") as $element)
echo $element->href . '<br>';
}
//is fppd running?????
function isFPPDRunning() {
$FPPDStatus=null;
logEntry("Checking to see if fpp is running...");
exec("if ps cax | grep -i fppd; then echo \"True\"; else echo \"False\"; fi",$output);
if($output[1] == "True" || $output[1] == 1 || $output[1] == "1") {
$FPPDStatus = "RUNNING";
}
//print_r($output);
return $FPPDStatus;
//interate over the results and see if avahi is running?
}
//get current running playlist
function getRunningPlaylist() {
global $sequenceDirectory;
$playlistName = null;
$i=0;
//can we sleep here????
//sleep(10);
//FPPD is running and we shoud expect something back from it with the -s status query
// #,#,#,Playlist name
// #,1,# = running
$currentFPP = file_get_contents("/tmp/FPP.playlist");
logEntry("Reading /tmp/FPP.playlist : ".$currentFPP);
if($currentFPP == "false") {
logEntry("We got a FALSE status from fpp -s status file.. we should not really get this, the daemon is locked??");
}
$fppParts="";
$fppParts = explode(",",$currentFPP);
// logEntry("FPP Parts 1 = ".$fppParts[1]);
//check to see the second variable is 1 - meaning playing
if($fppParts[1] == 1 || $fppParts[1] == "1") {
//we are playing
$playlistParts = pathinfo($fppParts[3]);
$playlistName = $playlistParts['basename'];
logEntry("We are playing a playlist...: ".$playlistName);
} else {
logEntry("FPPD Daemon is starting up or no active playlist.. please try again");
}
//now we should have had something
return $playlistName;
}
function logEntry($data) {
global $logFile,$myPid;
$data = $_SERVER['PHP_SELF']." : [".$myPid."] ".$data;
$logWrite= fopen($logFile, "a") or die("Unable to open file!");
fwrite($logWrite, date('Y-m-d h:i:s A',time()).": ".$data."\n");
fclose($logWrite);
}
function processCallback($argv) {
global $DEBUG,$pluginName;
if($DEBUG)
print_r($argv);
//argv0 = program
//argv2 should equal our registration // need to process all the rgistrations we may have, array??
//argv3 should be --data
//argv4 should be json data
$registrationType = $argv[2];
$data = $argv[4];
logEntry("PROCESSING CALLBACK: ".$registrationType);
$clearMessage=FALSE;
switch ($registrationType)
{
case "media":
if($argv[3] == "--data")
{
$data=trim($data);
logEntry("DATA: ".$data);
$obj = json_decode($data);
$type = $obj->{'type'};
logEntry("Type: ".$type);
switch ($type) {
case "sequence":
logEntry("media sequence name received: ");
processSequenceName($obj->{'Sequence'},"STATUS");
break;
case "media":
logEntry("We do not support type media at this time");
//$songTitle = $obj->{'title'};
//$songArtist = $obj->{'artist'};
//sendMessage($songTitle, $songArtist);
//exit(0);
break;
case "both":
logEntry("We do not support type media/both at this time");
// logEntry("MEDIA ENTRY: EXTRACTING TITLE AND ARTIST");
// $songTitle = $obj->{'title'};
// $songArtist = $obj->{'artist'};
// if($songArtist != "") {
// sendMessage($songTitle, $songArtist);
//exit(0);
break;
default:
logEntry("We do not understand: type: ".$obj->{'type'}. " at this time");
exit(0);
break;
}
}
break;
exit(0);
case "playlist":
logEntry("playlist type received");
if($argv[3] == "--data")
{
$data=trim($data);
logEntry("DATA: ".$data);
$obj = json_decode($data);
$sequenceName = $obj->{'sequence0'}->{'Sequence'};
$sequenceAction = $obj->{'Action'};
processSequenceName($sequenceName,$sequenceAction);
//logEntry("We do not understand: type: ".$obj->{'type'}. " at this time");
// logEntry("We do not understand: type: ".$obj->{'type'}. " at this time");
}
break;
exit(0);
default:
exit(0);
}
}
?>