]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - api/channels.php
Move extra header where it should be
[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');
bf719cce
BM
5
6if (!$rpc)
7 die(json_encode([]));
8
9/* Get the list */
10$channels = $rpc->channel()->getAll();
11
12$columns = array_column($channels, 'num_users');
13array_multisort($columns, SORT_DESC, $channels);
14
15$out = [];
16foreach($channels as $channel)
17{
18 $modes = (isset($channel->modes)) ? "+" . explode(" ",$channel->modes)[0] : "<none>";
19 $topic = '';
20 if (isset($channel->topic))
064843a8 21 $topic = htmlentities(StripControlCharacters($channel->topic), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 | ENT_DISALLOWED);
bf719cce
BM
22 $date = explode("T", $channel->creation_time)[0];
23 $out[] = [
24 "Name" => htmlspecialchars($channel->name),
25 "Users" => $channel->num_users,
26 "Modes" => "<span data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"+".htmlspecialchars($channel->modes)."\">$modes</span>",
27 "Topic" => $topic,
28 "Created" => "<span data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"".$channel->creation_time."\">$date</span>",
29 ];
30}
31
32function custom_sort($a,$b)
33{
eb7d3d96 34 return $b["Users"] <=> $a["Users"];
bf719cce
BM
35}
36
37usort($out, "custom_sort");
38
39echo json_encode($out);