forked from Yive/maxbans-php
-
Notifications
You must be signed in to change notification settings - Fork 1
/
info.php
189 lines (153 loc) · 6.12 KB
/
info.php
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
require_once './inc/page.php';
abstract class Info {
/**
* @param $row PDO::PDORow
* @param $page Page
*/
public function __construct($row, $page) {
$this->row = $row;
$this->page = $page;
$this->table = $page->table;
}
static function create($row, $page, $type) {
switch ($type) {
case "ban":
return new BanInfo($row, $page);
case "mute":
return new MuteInfo($row, $page);
case "warn":
return new WarnInfo($row, $page);
case "kick":
return new KickInfo($row, $page);
}
return null;
}
function name() {
return ucfirst($this->page->type);
}
function permanent() {
return ((int)$this->row['until']) <= 0;
}
function punished_avatar($player_name, $row) {
return $this->page->get_avatar($player_name, $row['uuid'], true, $this->history_link($player_name, $row['uuid']), $name_left = false);
}
function history_link($player_name, $uuid, $args = "") {
return "<a href=\"history.php?uuid=$uuid$args\">$player_name</a>";
}
function moderator_avatar($row) {
$banner_name = $this->page->get_banner_name($row);
return $this->page->get_avatar($banner_name, $row['banned_by_uuid'], true, $this->history_link($banner_name, $row['banned_by_uuid'], "&staffhistory=1"), $name_left = false);
}
abstract function basic_info($row, $player_name);
}
class BanInfo extends Info {
function basic_info($row, $player_name) {
$page = $this->page;
return array(
$page->t("info_banned_player") => $this->punished_avatar($player_name, $row),
$page->t("info_banned_by") => $this->moderator_avatar($row),
$page->t("info_banned_reason") => $page->clean($row['reason']),
$page->t("info_banned_when") => $page->millis_to_date($row['time']),
$page->t("info_banned_expiry") => $page->expiry($row),
$page->t("column_server") => $page->server($row),
);
}
}
class MuteInfo extends Info {
function basic_info($row, $player_name) {
$page = $this->page;
return array(
$page->t("info_muted_player") => $this->punished_avatar($player_name, $row),
$page->t("info_muted_by") => $this->moderator_avatar($row),
$page->t("info_muted_reason") => $page->clean($row['reason']),
$page->t("info_muted_when") => $page->millis_to_date($row['time']),
$page->t("info_muted_expiry") => $page->expiry($row),
$page->t("column_server") => $page->server($row),
);
}
}
class WarnInfo extends Info {
function name() {
return $this->page->lang->info_warn_name;
}
function basic_info($row, $player_name) {
$page = $this->page;
return array(
$page->t("info_warn_player") => $this->punished_avatar($player_name, $row),
$page->t("info_warn_by") => $this->moderator_avatar($row),
$page->t("info_warn_reason") => $page->clean($row['reason']),
$page->t("info_warn_when") => $page->millis_to_date($row['time']),
$page->t("info_warn_expiry") => $page->expiry($row),
$page->t("column_server") => $page->server($row),
);
}
}
class KickInfo extends Info {
function basic_info($row, $player_name) {
$page = $this->page;
return array(
$page->t("info_kick_player") => $this->punished_avatar($player_name, $row),
$page->t("info_kick_by") => $this->moderator_avatar($row),
$page->t("info_kick_reason") => $page->clean($row['reason']),
$page->t("info_kick_when") => $page->millis_to_date($row['time']),
$page->t("column_server") => $page->server($row),
);
}
}
// check if info.php is requested, otherwise it's included
if ((substr($_SERVER['SCRIPT_NAME'], -strlen("info.php"))) !== "info.php") {
return;
}
isset($_GET['type'], $_GET['id']) && is_string($_GET['type']) && is_string($_GET['id']) or die($page->t("info_error_missingarg"));
$type = $_GET['type'];
$id = $_GET['id'];
$page = new Page($type);
($page->type !== null) or die($page->t("info_error_unknown"));
filter_var($id, FILTER_VALIDATE_INT) or die($page->t("info_error_invalidid"));
$id = (int)$id;
$type = $page->type;
$table = $page->table;
$sel = $page->get_selection($table);
$query = "SELECT $sel FROM $table WHERE id=? LIMIT 1";
$st = $page->conn->prepare($query);
if ($st->execute(array($id))) {
($row = $st->fetch()) or die($page->t("info_error_notfound1") . $type . $page->t("info_error_notfound2"));
$st->closeCursor();
$player_name = $page->get_name($row['uuid']);
($player_name !== null) or die($page->t("info_error_notplayer"));
$info = Info::create($row, $page, $type);
$name = $info->name();
$permanent = $info->permanent();
$page->name = $page->title = "$name #$id";
$page->print_title();
$header = $page->name;
if (!($info instanceof KickInfo)) {
$style = 'style="margin-left: 13px; font-size: 16px;"';
$active = $page->active($row);
if ($active === true) {
$header .= "<span $style class='label label-danger'>Active</span>";
if ($permanent) {
$header .= "<span $style class='label label-danger'>Permanent</span>";
}
} else {
$header .= "<span $style class='label label-warning'>Inactive</span>";
}
}
$page->print_header(true, $header);
$map = $info->basic_info($row, $player_name);
$permanent_val = $info->page->permanent[$type];
$page->table_begin();
foreach ($map as $key => $val) {
if ($permanent &&
($key === $page->t("info_banned_expiry") || $key === $page->t("info_muted_expiry") || $key === $page->t("info_warn_expiry")) &&
$val === $permanent_val
) {
// skip "Expires" row if punishment is permanent
continue;
}
echo "<tr><td>$key</td><td>$val</td></tr>";
}
$page->table_end(false);
$page->print_footer();
}