-
Notifications
You must be signed in to change notification settings - Fork 0
/
live.php
220 lines (204 loc) · 6.92 KB
/
live.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
<?php //created by Jason McHuff, http://www.rosecitytransit.org/
include("live.config.php");
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?php echo $pagetitle; ?></title>
<script type="text/javascript">
<?php date_default_timezone_set('America/Los_Angeles');
if (isset($_SERVER['QUERY_STRING']) && (strlen($_SERVER['QUERY_STRING']) < 35))
$calls = explode("+",$_SERVER['QUERY_STRING']);
if (end($calls) == "fewer") {
$fewer = array_pop($calls);
echo ' var fewer = "+fewer";
';
} else {
$fewer = false;
echo ' var fewer = "";
';
}
if (!isset($calls[0]))
$calls[0] = $default_system;
if (!isset($calls[3]))
$calls[3] = date('Y-n-j');
if (!isset($calls[1]) || ($calls[1] == "")) {
$calls[1] = "ALL";
echo ' var calls="ALL";
';
} else echo ' var calls = "'.$_SERVER['QUERY_STRING'].'";
'; ?>
var player;
var playlist;
var currentcall;
var channel;
var e;
var loadcalls;
function init() {
e = document.createElement('div');
player = document.getElementById('audioplayer');
playlist = document.getElementById('theplaylist');
channel = document.getElementById('channels');
getcalls();
player.volume = 0.2;
playlist.addEventListener('click',function (e) {
//e.preventDefault();
if ((e.target.parentElement.nodeName == "DIV") && (e.target.parentElement != playlist) && e.target.parentElement.getElementsByTagName('a')[1]) {
playnext(e.target.parentElement);
e.target.parentElement.style.backgroundColor = "#FFFF99";
}
else if ((e.target.parentElement == playlist) && e.target.getElementsByTagName('a')[1]) {
playnext(e.target);
e.target.style.backgroundColor = "#FFFF99";
}
}, false);
player.addEventListener('ended',function () {
if (currentcall.nextSibling && (document.getElementById('autoplay').checked == true)) {
playnext(currentcall.nextSibling);
}
}, false);
}
window.onload=init;
<?php if (!isset($calls[2]))
echo " var loadcalls=setInterval(getcalls, 20000);"; ?>
function getcalls() {
if ((document.getElementById('addnew').checked == true) || (playlist.innerHTML == ''))
downloadUrl("calls.php?"+calls, function(data) {
newcalls = document.getElementById('newcalls');
if (newcalls)
newcalls.removeAttribute("id");
calls += "+";
calls = calls.substr(0, calls.indexOf("+"))+"+"+data.match(/\d+/)+fewer;
data = data.replace(/\d+/,"");
e.innerHTML = data;
while(e.firstChild) {
playlist.appendChild(e.firstChild);
}
if (!currentcall && playlist.childNodes) {
playnext(playlist.firstChild);
}
if ((document.getElementById('autoplay').checked == true) && (player.ended == true) && newcalls) {
playnext(newcalls);
window.location="#newcalls";
}
});
}
function playnext(nextcall) {
do {
if (nextcall.getElementsByTagName('a')[1]) {
if (currentcall)
currentcall.style.fontWeight = "normal";
nextcall.style.fontWeight = "bold";
nextcall.style.backgroundColor = "#FFFFCC";
player.setAttribute('src',nextcall.getElementsByTagName('a')[1]);
player.load();
if (currentcall)
player.play();
currentcall = nextcall;
break;
}
} while (nextcall = nextcall.nextSibling)
}
function changecalls(day,today) {
newtitle = "<?php echo $pagetitle; ?>"+channel.options[channel.selectedIndex].text;
calls = channel.value;
if (day)
calls += "+00";
else
loadcalls=setInterval(getcalls, 20000);
if (!today) {
calls += "+"+document.getElementById("m").value+"-"+document.getElementById("d").value;
newtitle += " on "+document.getElementById("m").value+"-"+document.getElementById("d").value;
clearInterval(loadcalls);
}
if (document.getElementById('fewer').checked == true) {
fewer = "+fewer";
calls += "+fewer";
}
else
fewer = "";
document.title = newtitle;
document.getElementById('curchan').innerHTML = "<a href=\"?"+calls+"\">"+newtitle+"</a>";
currentcall = undefined;
playlist.innerHTML="";
getcalls();
}
function createXmlHttpRequest() {
try {
if (typeof ActiveXObject != 'undefined') {
return new ActiveXObject('Microsoft.XMLHTTP');
} else if (window["XMLHttpRequest"]) {
return new XMLHttpRequest();
}
} catch (e) {
changeStatus(e);
}
return null;
};
function downloadUrl(url, callback) {
var status = -1;
var request = createXmlHttpRequest();
if (!request) {
return false;
}
request.onreadystatechange = function() {
if (request.readyState == 4) {
try {
status = request.status;
} catch (e) {
// Usually indicates request timed out in FF.
}
if (status == 200) {
callback(request.responseText, request.status);
request.onreadystatechange = function() {};
}
}
}
request.open('GET', url, true);
try {
request.send(null);
} catch (e) {
changeStatus(e);
}
};
</script>
<style>#theplaylist span { padding-left: 5px; padding-right: 5px; padding-top: 1px; padding-bottom: 1px; display: table-cell; max-width: 450px; }
#theplaylist div {display: table-row; cursor: default;} .e { color: red;}
#theplaylist a { text-decoration: none; color: black; }
#theplaylist { display: table; margin-left: auto; margin-right: auto; }
#curchan { margin-top: 0; margin-bottom: 0; font-size: large; }
#infop { font-weight: bold; margin-top: 100px; text-align: center; }
#player { position:fixed; background: white; top: 0; width: 100%; background: #FFFFEE; text-align: center; }</style>
<body style="font-family: Arial;" ><div id="player">
<h1 id="curchan"><?php echo $pagetitle; ?></h1>
<form action="" name="changecall">Channel(s): <select name="channels" id="channels">
foreach ($tglist as $thistg => $thisvalue) {
echo '<option value="'.$thistg.'"';
if ($calls[1] == $thistg) echo ' selected="selected"';
echo '>'.$thisvalue.'</option>
';
}
unset($thistg); ?>
</select><input type="button" value="Now" onclick="changecalls(false, true);"><input type="button" value="Today" onclick="changecalls(true, true);">
<select name="m" id="m">
<?php $themon = explode("-",$calls[3]);
foreach (glob("2*/*", GLOB_ONLYDIR) as $mon) {
echo '<option value="'.str_replace("/","-",$mon).'"';
if ($mon == $themon[0]."/".$themon[1]) echo ' selected="selected"';
echo '>'.$mon.'</option>
'; }
unset ($mon);
echo '</select>/<select name="d" id="d">';
for ($x = 1; $x <= 31; $x++) {
echo '<option value="'.$x.'"';
if ($x == $themon[2]) echo ' selected="selected"';
echo '>'.$x.'</option>
'; }
unset($x); ?></select><input type="button" value="Day" onclick="changecalls(true, false);"> <label><input id="fewer"<?php
if ($fewer) echo ' checked="checked"' ?> type="checkbox"/>Fewer columns</label>
<br /><audio id="audioplayer" src="blank.mp3" preload="none" tabindex="0" controls>
Sorry, your browser does not support HTML5 audio.
</audio> <label><input id="addnew" type="checkbox" checked="checked" />Add new calls</label> <label><input id="autoplay" type="checkbox" />Auto play</label></div>
<p id ="infop">Click on a row to play, click # for link, or click file size to download</p>
<div id="theplaylist"></div>
</body></html>