]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - api/channels.php
Fix setting zlines on idents, reported by Jellis
[irc/unrealircd/unrealircd-webpanel.git] / api / channels.php
CommitLineData
bf719cce
BM
1<?php
2
3define('NO_EVENT_STREAM_HEADER',1);
4require_once('common_api.php');
5header("Content-type: application/json; charset=utf-8");
6
7if (!$rpc)
8 die(json_encode([]));
9
10/* Get the list */
11$channels = $rpc->channel()->getAll();
12
13$columns = array_column($channels, 'num_users');
14array_multisort($columns, SORT_DESC, $channels);
15
16$out = [];
17foreach($channels as $channel)
18{
19 $modes = (isset($channel->modes)) ? "+" . explode(" ",$channel->modes)[0] : "<none>";
20 $topic = '';
21 if (isset($channel->topic))
064843a8 22 $topic = htmlentities(StripControlCharacters($channel->topic), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 | ENT_DISALLOWED);
bf719cce
BM
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
33function custom_sort($a,$b)
34{
eb7d3d96 35 return $b["Users"] <=> $a["Users"];
bf719cce
BM
36}
37
38usort($out, "custom_sort");
39
40echo json_encode($out);