]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - api/channels.php
Fix setting zlines on idents, reported by Jellis
[irc/unrealircd/unrealircd-webpanel.git] / api / channels.php
1 <?php
2
3 define('NO_EVENT_STREAM_HEADER',1);
4 require_once('common_api.php');
5 header("Content-type: application/json; charset=utf-8");
6
7 if (!$rpc)
8 die(json_encode([]));
9
10 /* Get the list */
11 $channels = $rpc->channel()->getAll();
12
13 $columns = array_column($channels, 'num_users');
14 array_multisort($columns, SORT_DESC, $channels);
15
16 $out = [];
17 foreach($channels as $channel)
18 {
19 $modes = (isset($channel->modes)) ? "+" . explode(" ",$channel->modes)[0] : "<none>";
20 $topic = '';
21 if (isset($channel->topic))
22 $topic = htmlentities(StripControlCharacters($channel->topic), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 | ENT_DISALLOWED);
23 $date = explode("T", $channel->creation_time)[0];
24 $out[] = [
25 "Name" => htmlspecialchars($channel->name),
26 "Users" => $channel->num_users,
27 "Modes" => "<span data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"+".htmlspecialchars($channel->modes)."\">$modes</span>",
28 "Topic" => $topic,
29 "Created" => "<span data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"".$channel->creation_time."\">$date</span>",
30 ];
31 }
32
33 function custom_sort($a,$b)
34 {
35 return $b["Users"] <=> $a["Users"];
36 }
37
38 usort($out, "custom_sort");
39
40 echo json_encode($out);