mirror of
https://gitlab.com/ruany/litebans-php.git
synced 2025-05-24 17:02:44 +00:00
Reformat code
This commit is contained in:
parent
9b3943ad5c
commit
ee70900b8e
@ -36,13 +36,13 @@ class Page {
|
|||||||
$this->set_info($info);
|
$this->set_info($info);
|
||||||
|
|
||||||
$this->permanent = array(
|
$this->permanent = array(
|
||||||
'ban' => 'Permanent Ban',
|
'ban' => 'Permanent Ban',
|
||||||
'mute' => 'Permanent Mute',
|
'mute' => 'Permanent Mute',
|
||||||
'warn' => 'Permanent',
|
'warn' => 'Permanent',
|
||||||
'kick' => null,
|
'kick' => null,
|
||||||
);
|
);
|
||||||
$this->expired = array(
|
$this->expired = array(
|
||||||
'ban' => '(Unbanned)',
|
'ban' => '(Unbanned)',
|
||||||
'mute' => '(Unmuted)',
|
'mute' => '(Unmuted)',
|
||||||
'warn' => '(Expired)',
|
'warn' => '(Expired)',
|
||||||
'kick' => null,
|
'kick' => null,
|
||||||
@ -62,49 +62,47 @@ class Page {
|
|||||||
case "ban":
|
case "ban":
|
||||||
case "bans":
|
case "bans":
|
||||||
return array(
|
return array(
|
||||||
"type" => "ban",
|
"type" => "ban",
|
||||||
"table" => $settings->table['bans'],
|
"table" => $settings->table['bans'],
|
||||||
"title" => "Bans",
|
"title" => "Bans",
|
||||||
);
|
);
|
||||||
case "mute":
|
case "mute":
|
||||||
case "mutes":
|
case "mutes":
|
||||||
return array(
|
return array(
|
||||||
"type" => "mute",
|
"type" => "mute",
|
||||||
"table" => $settings->table['mutes'],
|
"table" => $settings->table['mutes'],
|
||||||
"title" => "Mutes",
|
"title" => "Mutes",
|
||||||
);
|
);
|
||||||
case "warn":
|
case "warn":
|
||||||
case "warnings":
|
case "warnings":
|
||||||
return array(
|
return array(
|
||||||
"type" => "warn",
|
"type" => "warn",
|
||||||
"table" => $settings->table['warnings'],
|
"table" => $settings->table['warnings'],
|
||||||
"title" => "Warnings",
|
"title" => "Warnings",
|
||||||
);
|
);
|
||||||
case "kick":
|
case "kick":
|
||||||
case "kicks":
|
case "kicks":
|
||||||
return array(
|
return array(
|
||||||
"type" => "kick",
|
"type" => "kick",
|
||||||
"table" => $settings->table['kicks'],
|
"table" => $settings->table['kicks'],
|
||||||
"title" => "Kicks",
|
"title" => "Kicks",
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return array(
|
return array(
|
||||||
"type" => null,
|
"type" => null,
|
||||||
"table" => null,
|
"table" => null,
|
||||||
"title" => null,
|
"title" => null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_selection($table) {
|
/**
|
||||||
// Under certain versions of PHP, there is a bug with BIT columns.
|
* @param $info
|
||||||
// An empty string is returned no matter what the value is.
|
*/
|
||||||
// Workaround: cast to unsigned.
|
function set_info($info) {
|
||||||
$selection = "id,uuid,reason,banned_by_name,banned_by_uuid,time,until,CAST(active AS UNSIGNED) AS active";
|
$this->type = $info['type'];
|
||||||
if ($table === $this->settings->table['warnings']) {
|
$this->table = $info['table'];
|
||||||
$selection .= ",CAST(warned AS UNSIGNED) AS warned";
|
$this->title = $info['title'];
|
||||||
}
|
|
||||||
return $selection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function run_query() {
|
function run_query() {
|
||||||
@ -135,6 +133,17 @@ class Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_selection($table) {
|
||||||
|
// Under certain versions of PHP, there is a bug with BIT columns.
|
||||||
|
// An empty string is returned no matter what the value is.
|
||||||
|
// Workaround: cast to unsigned.
|
||||||
|
$selection = "id,uuid,reason,banned_by_name,banned_by_uuid,time,until,CAST(active AS UNSIGNED) AS active";
|
||||||
|
if ($table === $this->settings->table['warnings']) {
|
||||||
|
$selection .= ",CAST(warned AS UNSIGNED) AS warned";
|
||||||
|
}
|
||||||
|
return $selection;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns HTML representing the Minecraft avatar for a specific name or UUID.
|
* Returns HTML representing the Minecraft avatar for a specific name or UUID.
|
||||||
* @param $name
|
* @param $name
|
||||||
@ -165,28 +174,6 @@ class Page {
|
|||||||
return "<img class='avatar noselect' src='$src'/>$name";
|
return "<img class='avatar noselect' src='$src'/>$name";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the last name for a UUID, or null if their name is not recorded in the database.
|
|
||||||
* @param string
|
|
||||||
* @return null|string
|
|
||||||
*/
|
|
||||||
function get_name($uuid) {
|
|
||||||
if (in_array($uuid, $this->settings->console_aliases)) {
|
|
||||||
return $this->settings->console_name;
|
|
||||||
}
|
|
||||||
if (array_key_exists($uuid, $this->uuid_name_cache)) return $this->uuid_name_cache[$uuid];
|
|
||||||
|
|
||||||
$history = $this->settings->table['history'];
|
|
||||||
$stmt = $this->conn->prepare("SELECT name FROM $history WHERE uuid=? ORDER BY date DESC LIMIT 1");
|
|
||||||
if ($stmt->execute(array($uuid)) && $row = $stmt->fetch()) {
|
|
||||||
$banner = $row['name'];
|
|
||||||
$this->uuid_name_cache[$uuid] = $banner;
|
|
||||||
return $banner;
|
|
||||||
}
|
|
||||||
$this->uuid_name_cache[$uuid] = null;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the banner name for a specific row in the database
|
* Returns the banner name for a specific row in the database
|
||||||
* using their UUID->name if possible, otherwise returns their last recorded name.
|
* using their UUID->name if possible, otherwise returns their last recorded name.
|
||||||
@ -208,12 +195,25 @@ class Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a timestamp (in milliseconds) to a date using the configured date format.
|
* Returns the last name for a UUID, or null if their name is not recorded in the database.
|
||||||
* @param int
|
* @param string
|
||||||
* @return string
|
* @return null|string
|
||||||
*/
|
*/
|
||||||
function millis_to_date($millis) {
|
function get_name($uuid) {
|
||||||
return date($this->settings->date_format, $millis / 1000);
|
if (in_array($uuid, $this->settings->console_aliases)) {
|
||||||
|
return $this->settings->console_name;
|
||||||
|
}
|
||||||
|
if (array_key_exists($uuid, $this->uuid_name_cache)) return $this->uuid_name_cache[$uuid];
|
||||||
|
|
||||||
|
$history = $this->settings->table['history'];
|
||||||
|
$stmt = $this->conn->prepare("SELECT name FROM $history WHERE uuid=? ORDER BY date DESC LIMIT 1");
|
||||||
|
if ($stmt->execute(array($uuid)) && $row = $stmt->fetch()) {
|
||||||
|
$banner = $row['name'];
|
||||||
|
$this->uuid_name_cache[$uuid] = $banner;
|
||||||
|
return $banner;
|
||||||
|
}
|
||||||
|
$this->uuid_name_cache[$uuid] = null;
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -255,12 +255,17 @@ class Page {
|
|||||||
return $until;
|
return $until;
|
||||||
}
|
}
|
||||||
|
|
||||||
function active($row, $field = 'active') {
|
/**
|
||||||
return (((int)$row[$field]) !== 0);
|
* Converts a timestamp (in milliseconds) to a date using the configured date format.
|
||||||
|
* @param int
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function millis_to_date($millis) {
|
||||||
|
return date($this->settings->date_format, $millis / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function title() {
|
function active($row, $field = 'active') {
|
||||||
return ucfirst($this->name);
|
return (((int)$row[$field]) !== 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_title() {
|
function print_title() {
|
||||||
@ -269,6 +274,10 @@ class Page {
|
|||||||
echo "<title>$title - $name</title>";
|
echo "<title>$title - $name</title>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function title() {
|
||||||
|
return ucfirst($this->name);
|
||||||
|
}
|
||||||
|
|
||||||
function print_table_rows($row, $array, $print_headers = true) {
|
function print_table_rows($row, $array, $print_headers = true) {
|
||||||
if ($print_headers && !$this->table_headers_printed) {
|
if ($print_headers && !$this->table_headers_printed) {
|
||||||
$headers = array_keys($array);
|
$headers = array_keys($array);
|
||||||
@ -297,6 +306,14 @@ class Page {
|
|||||||
echo "</tr>";
|
echo "</tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function table_print_headers($headers) {
|
||||||
|
echo "<thead><tr>";
|
||||||
|
foreach ($headers as $header) {
|
||||||
|
echo "<th><div style=\"text-align: center;\">$header</div></th>";
|
||||||
|
}
|
||||||
|
echo "<tbody>";
|
||||||
|
}
|
||||||
|
|
||||||
function print_page_header($container_start = true) {
|
function print_page_header($container_start = true) {
|
||||||
$title = $this->title();
|
$title = $this->title();
|
||||||
if ($container_start) {
|
if ($container_start) {
|
||||||
@ -309,14 +326,6 @@ class Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function table_print_headers($headers) {
|
|
||||||
echo "<thead><tr>";
|
|
||||||
foreach ($headers as $header) {
|
|
||||||
echo "<th><div style=\"text-align: center;\">$header</div></th>";
|
|
||||||
}
|
|
||||||
echo "<tbody>";
|
|
||||||
}
|
|
||||||
|
|
||||||
function print_check_form() {
|
function print_check_form() {
|
||||||
$table = $this->name;
|
$table = $this->name;
|
||||||
echo '
|
echo '
|
||||||
@ -385,13 +394,4 @@ class Page {
|
|||||||
echo "<script type=\"text/javascript\">withjQuery(function(){ $('tr').click(function(){var href=$(this).find('a').attr('href');if(href!==undefined)window.location=href;}).hover(function(){\$(this).toggleClass('hover');}); });</script>";
|
echo "<script type=\"text/javascript\">withjQuery(function(){ $('tr').click(function(){var href=$(this).find('a').attr('href');if(href!==undefined)window.location=href;}).hover(function(){\$(this).toggleClass('hover');}); });</script>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $info
|
|
||||||
*/
|
|
||||||
function set_info($info) {
|
|
||||||
$this->type = $info['type'];
|
|
||||||
$this->table = $info['table'];
|
|
||||||
$this->title = $info['title'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
8
info.php
8
info.php
@ -38,14 +38,14 @@ abstract class Info {
|
|||||||
return ((int)$this->row['until']) <= 0;
|
return ((int)$this->row['until']) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function history_link($player_name, $uuid, $args = "") {
|
|
||||||
return "<a href=\"history.php?uuid=$uuid$args\">$player_name</a>";
|
|
||||||
}
|
|
||||||
|
|
||||||
function punished_avatar($player_name, $row) {
|
function punished_avatar($player_name, $row) {
|
||||||
return $this->page->get_avatar($player_name, $row['uuid'], false, $this->history_link($player_name, $row['uuid']));
|
return $this->page->get_avatar($player_name, $row['uuid'], false, $this->history_link($player_name, $row['uuid']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function history_link($player_name, $uuid, $args = "") {
|
||||||
|
return "<a href=\"history.php?uuid=$uuid$args\">$player_name</a>";
|
||||||
|
}
|
||||||
|
|
||||||
function moderator_avatar($row) {
|
function moderator_avatar($row) {
|
||||||
$banner_name = $this->page->get_banner_name($row);
|
$banner_name = $this->page->get_banner_name($row);
|
||||||
return $this->page->get_avatar($banner_name, $row['banned_by_uuid'], false, $this->history_link($banner_name, $row['banned_by_uuid'], "&staffhistory=1"));
|
return $this->page->get_avatar($banner_name, $row['banned_by_uuid'], false, $this->history_link($banner_name, $row['banned_by_uuid'], "&staffhistory=1"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user