-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.php
More file actions
85 lines (71 loc) · 2.05 KB
/
data.php
File metadata and controls
85 lines (71 loc) · 2.05 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
<?php
require_once('classes/MurmurQuery.php');
$settings = array
(
'host' => '10.0.10.100', // <- insert server address
'port' => 27800,
'timeout' => 5000,
'format' => 'json'
);
$murmur = new MurmurQuery();
$murmur->setup($settings);
$murmur->query();
function buildTree(array &$elements, $parentId = 0) {
$branch = array();
foreach ($elements as $element) {
if ($element['parent'] == $parentId) {
$children = buildTree($elements, $element['id']);
if ($children) {
$element['children'] += $children;
}
$branch[$element['id']] = $element;
unset($elements[$element['id']]);
}
}
return $branch;
}
function insertUsers(&$channels, $users) {
foreach ($users as $user) foreach ($channels as &$channel) {
if ($channel['id'] == $user['channel']) $channel['children'] += array('u'.$user['userid'] => $user);
}
}
function printTree($tree) {
static $id = 0;
print('<ul id=\'ul'.$id++.'\'>');
foreach ($tree as $branch) {
if (isset($branch['userid'])) {
$classes = '';
if ($branch['bytespersec'] > 0) $classes .= ' speaking';
if ($branch['selfMute']) $classes .= ' mute';
if ($branch['suppress']) $classes .= ' suppress';
if ($branch['selfDeaf']) $classes .= ' deaf';
if ($branch['userid'] > -1) $classes .= ' auth';
print('<li class=\'user'.$classes.'\'>');
} else print('<li class=\'channel\'>');
print($branch['name']);
if (isset($branch['children'])) printTree($branch['children']);
print('</li>');
}
print('</ul>');
}
if($murmur->is_online())
{
$response = $murmur->get_status();
$channels = $response['channels'];
$users = $response['users'];
usort($channels, function ($a, $b) {
if ($a['position'] == $b['position']) return 0;
return ($a['position'] < $b['position']) ? -1 : 1;
});
foreach ($channels as &$channel) {
$channel['children'] = array();
unset($channel['description']);
}
foreach ($users as &$user) {
unset($user['comment']);
}
insertUsers($channels, $users);
$tree = buildTree($channels);
printTree($tree);
}
?>