]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - api/users.php
Add Plugins: remove author from card footer
[irc/unrealircd/unrealircd-webpanel.git] / api / users.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 user list */
11 $users = $rpc->user()->getAll();
12
13 $out = [];
14 foreach($users as $user)
15 {
16 $isBot = (strpos($user->user->modes, "B") !== false) ? ' <span class="badge rounded-pill badge-dark">Bot</span>' : "";
17 $nick = htmlspecialchars($user->name).$isBot;
18
19 $country = isset($user->geoip->country_code) ? '<img src="https://flagcdn.com/48x36/'.htmlspecialchars(strtolower($user->geoip->country_code)).'.png" width="20" height="15"> '.htmlspecialchars($user->geoip->country_code) : "";
20
21 if ($user->hostname == $user->ip)
22 $hostip = $user->ip;
23 else if ($user->ip == null)
24 $hostip = $user->hostname;
25 else
26 $hostip = $user->hostname . " (".$user->ip.")";
27 $hostip = htmlspecialchars($hostip);
28
29 $account = (isset($user->user->account)) ? "<a href=\"".get_config("base_url")."users/?account=".$user->user->account."\">".htmlspecialchars($user->user->account)."</a>" : '<span class="badge rounded-pill badge-primary">None</span>';
30 $oper = (isset($user->user->operlogin)) ? $user->user->operlogin." <span class=\"badge rounded-pill badge-secondary\">".$user->user->operclass."</span>" : "";
31 if (!strlen($oper))
32 $oper = (strpos($user->user->modes, "S") !== false) ? '<span class="badge rounded-pill badge-warning">Services Bot</span>' : "";
33 $servername = $user->user->servername;
34 $reputation = $user->user->reputation;
35
36 $nick = "<a href=\"details.php?nick=".$user->id."\">$nick</a>";
37
38 $out[] = [
39 "Select" => "<input type=\"checkbox\" value='" . base64_encode($user->id)."' name=\"userch[]\">", /* yeah ridiculous to have here in this file and the feed ;) */
40 "Nick" => $nick,
41 "Country" => $country,
42 "Host/IP" => $hostip,
43 "Account" => $account,
44 "Oper" => $oper,
45 "Connected to" => $servername,
46 "Reputation" => $reputation,
47 ];
48 }
49
50 function custom_sort($a,$b)
51 {
52 return strcmp(strtoupper($a["Nick"]), strtoupper($b["Nick"]));
53 }
54
55 usort($out, "custom_sort");
56
57 echo json_encode($out);