-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.inc.php
More file actions
121 lines (103 loc) · 3.53 KB
/
functions.inc.php
File metadata and controls
121 lines (103 loc) · 3.53 KB
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
<?php
include_once("/opt/fpp/www/common.php");
$pluginName = basename(dirname(__FILE__));
// Safely get the plugin config file path
if (isset($settings) && isset($settings['configDirectory'])) {
$pluginConfigFile = $settings['configDirectory'] . "/plugin." . $pluginName;
} else {
// Fallback to default FPP config directory
$pluginConfigFile = "/home/fpp/media/config/plugin." . $pluginName;
}
if (file_exists($pluginConfigFile)){
$pluginSettings = parse_ini_file($pluginConfigFile);
}else{
$pluginSettings = array();
}
// Get plugin setting by key
function advancedstats_getPluginSetting($key, $default = '') {
global $pluginSettings;
return isset($pluginSettings[$key]) ? $pluginSettings[$key] : $default;
}
// Get all playlists from FPP
function advancedstats_getPlaylistsFromFPP() {
$ch = curl_init('http://localhost/api/playlists');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$result = json_decode($data, true);
// FPP API returns a simple array of playlist names
if (is_array($result)) {
return $result;
}
return array();
}
// Get FPP status
function advancedstats_getFPPStatus() {
$ch = curl_init('http://localhost/api/fppd/status');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
return json_decode($data, true);
}
// Check if a playlist is currently running
function advancedstats_isPlaylistRunning($playlistName) {
$status = advancedstats_getFPPStatus();
$currentPlaylist = isset($status['current_playlist']['playlist']) ? $status['current_playlist']['playlist'] : '';
return ($currentPlaylist === $playlistName && $playlistName !== '');
}
// Start a playlist
function advancedstats_startPlaylist($playlistName, $repeat = false) {
$data = array('command' => 'start', 'playlist' => $playlistName);
if ($repeat) {
$data['repeat'] = true;
}
$ch = curl_init('http://localhost/api/command');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Stop all playlists
function advancedstats_stopAllPlaylists() {
$data = array('command' => 'stop');
$ch = curl_init('http://localhost/api/command');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Get current brightness
function advancedstats_getCurrentBrightness() {
$brightness = getSetting('brightness');
if ($brightness === false || $brightness === '') {
return 100;
}
return intval($brightness);
}
// Set brightness
function advancedstats_setFPPBrightness($level) {
if ($level < 0) $level = 0;
if ($level > 100) $level = 100;
$ch = curl_init('http://localhost/api/system/brightness/' . $level);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Log to plugin log file
function advancedstats_logPluginMessage($message) {
$logFile = '/home/fpp/media/logs/fpp-plugin-AdvancedStats.log';
$timestamp = date('Y-m-d H:i:s');
$logMessage = "[$timestamp] $message\n";
file_put_contents($logFile, $logMessage, FILE_APPEND);
}
?>