forked from LightsOnHudson/FPP-Plugin-SportsTicker
/
getSPORTS.php
executable file
·171 lines (113 loc) · 3.83 KB
/
getSPORTS.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
#!/usr/bin/php
<?
error_reporting(0);
$pluginName ="SportsTicker";
$myPid = getmypid();
$messageQueue_Plugin = "MessageQueue";
$MESSAGE_QUEUE_PLUGIN_ENABLED=false;
$DEBUG=false;
$skipJSsettings = 1;
require_once("/opt/fpp/www/config.php");
require_once("/opt/fpp/www/common.php");
//include_once("/opt/fpp/www/plugin.php");
include_once("functions.inc.php");
include_once "SPORTS.inc.php";
require ("lock.helper.php");
define('LOCK_DIR', '/tmp/');
define('LOCK_SUFFIX', '.lock');
$pluginConfigFile = $settings['configDirectory'] . "/plugin." .$pluginName;
if (file_exists($pluginConfigFile))
$pluginSettings = parse_ini_file($pluginConfigFile);
//print_r($pluginSettings);
$logFile = $settings['logDirectory']."/".$pluginName.".log";
$messageQueuePluginPath = $pluginDirectory."/".$messageQueue_Plugin."/";
$messageQueueFile = urldecode(ReadSettingFromFile("MESSAGE_FILE",$messageQueue_Plugin));
if(($pid = lockHelper::lock()) === FALSE) {
exit(0);
}
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");
}
//if($MESSAGE_QUEUE_PLUGIN_ENABLED) {
// $queueMessages = getNewPluginMessages("SMS");
// print_r($queueMessages);
//} else {
// logEntry("MessageQueue plugin is not enabled/installed");
//}
// print_r($pluginSettings);
// echo "\n";
//$SPORTS = urldecode(ReadSettingFromFile("SPORTS",$pluginName));
$SPORTS = urldecode($pluginSettings['SPORTS']);
//$ENABLED = urldecode(ReadSettingFromFile("ENABLED",$pluginName));
$ENABLED = urldecode($pluginSettings['ENABLED']);
//$SEPARATOR = urldecode(ReadSettingFromFile("SEPARATOR",$pluginName));
$SEPARATOR = urldecode($pluginSettings['SEPARATOR']);
//$LAST_READ = urldecode(ReadSettingFromFile("LAST_READ",$pluginName));
$LAST_READ = $pluginSettings['LAST_READ'];
//echo "enabled: ".$ENABLED."\n";
//echo "ENABLED: ".$ENABLED."\n";
if($ENABLED != "1") {
logEntry("Plugin Status: DISABLED Please enable in Plugin Setup to use & Restart FPPD Daemon");
lockHelper::unlock();
exit(0);
}
//$SEPARATOR = urldecode(ReadSettingFromFile("SEPARATOR",$pluginName));
$SPORTS_READ = explode(",",$SPORTS);
//echo "Incoming sports reading: \n";
//print_r($SPORTS_READ);
//print_r($SPORTS_DATA_ARRAY);
$messageText="";
for($i=0;$i<=count($SPORTS_READ)-1;$i++) {
//echo "Retrieving data for: ".$SPORTS_READ[$i]."\n";
if( search_in_array($SPORTS_READ[$i],$SPORTS_DATA_ARRAY) > 0) {
//echo $SPORTS_READ[$i]. " is in Sports data array\n";
//fetch the information
$sportsScores = file_get_contents($SPORTS_DATA_ARRAY[$i][1]);
$new = str_replace('&',"|",$sportsScores);
//$new = str_replace('&',"|",$output);
$stats = explode('&',$sportsScores);
//print_r($stats);
foreach($stats as $item) {
$split = explode("=",$item);
$left = $split[0];
$right = (string)urldecode($split[1]);
if(substr($left,0,10) == strtolower($SPORTS_READ[$i]."_s_left")) {
//echo $right."<br/>";
//echo $split[0]." --- ".$right."<br/>";
if(substr($right,0,1) == "^") {
$right = substr($right,1);
}
if(trim($right) !="") {
$messageText .= " ".$SEPARATOR." ".$right;
}
}
}
//there gets some ^ in the output.. erase them!
$messageText = preg_replace('/\^/', '', $messageText);
$messageText = preg_replace('/\s[a]t\s/', ' @ ', $messageText);
if(trim($messageText) == "" ) {
$messageLine = $SPORTS_READ[$i]." - No Scores Availble";
} else {
$messageLine = $SPORTS_READ[$i]." ".$messageText;
}
addNewMessage($messageLine,$pluginName,$pluginData=$SPORTS_READ[$i]);
$messageText="";
$messageLine="";
}
}
function search_in_array($value, $arr){
$num = 0;
for ($i = 0; $i < count($arr); ) {
if($arr[$i][0] == $value) {
$num++;
}
$i++;
}
return $num ;
}
lockHelper::unlock();
?>