mirror of
https://gitlab.com/ruany/litebans-php.git
synced 2025-07-08 23:07:31 +00:00
Clean up concatenation
This commit is contained in:
parent
692629af09
commit
598dc950a9
25
check.php
25
check.php
@ -3,13 +3,14 @@ if (isset($_POST['name'], $_POST['table'])) {
|
||||
$name = $_POST['name'];
|
||||
// validate user input
|
||||
if (strlen($name) > 16 || !preg_match("/^[0-9a-zA-Z_]{1,16}$/", $name)) {
|
||||
echo('Invalid name.');
|
||||
echo "Invalid name.";
|
||||
return;
|
||||
}
|
||||
require './includes/page.php';
|
||||
$page = new Page();
|
||||
$history = $page->settings->table_history;
|
||||
|
||||
$stmt = $page->conn->prepare("SELECT name,uuid FROM " . $page->settings->table_history . " WHERE name=? ORDER BY date LIMIT 1");
|
||||
$stmt = $page->conn->prepare("SELECT name,uuid FROM $history WHERE name=? ORDER BY date LIMIT 1");
|
||||
if ($stmt->execute(array($name))) {
|
||||
if ($row = $stmt->fetch()) {
|
||||
$name = $row['name'];
|
||||
@ -18,29 +19,29 @@ if (isset($_POST['name'], $_POST['table'])) {
|
||||
}
|
||||
if (!isset($uuid)) {
|
||||
$name = htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
|
||||
echo($name . ' has not joined before.<br>');
|
||||
echo "$name has not joined before.<br>";
|
||||
return;
|
||||
}
|
||||
$table = $page->settings->table_bans;
|
||||
|
||||
$stmt = $page->conn->prepare("SELECT * FROM " . $table . " WHERE (uuid=? AND active=1) LIMIT 1");
|
||||
$stmt = $page->conn->prepare("SELECT * FROM $table WHERE (uuid=? AND active=1) LIMIT 1");
|
||||
if ($stmt->execute(array($uuid))) {
|
||||
if (!($row = $stmt->fetch())) {
|
||||
echo($name . ' is not banned.<br>');
|
||||
echo "$name is not banned.<br>";
|
||||
return;
|
||||
}
|
||||
$banner = $page->get_banner_name($row);
|
||||
$reason = $row['reason'];
|
||||
$reason = $page->clean($row['reason']);
|
||||
$time = $page->millis_to_date($row['time']);
|
||||
$until = $page->millis_to_date($row['until']);
|
||||
echo($name . ' is banned!<br>');
|
||||
echo('Banned by: ' . $banner . '<br>');
|
||||
echo('Reason: ' . $page->clean($reason) . '<br>');
|
||||
echo('Banned on: ' . $time . '<br>');
|
||||
echo "$name is banned!<br>";
|
||||
echo "Banned by: $banner<br>";
|
||||
echo "Reason: $reason<br>";
|
||||
echo "Banned on: $time<br>";
|
||||
if ($row['until'] > 0) {
|
||||
echo('Banned until: ' . $until . '<br>');
|
||||
echo "Banned until: $until<br>";
|
||||
} else {
|
||||
echo('Banned permanently.<br>');
|
||||
echo "Banned permanently.<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,18 +12,17 @@ class Page {
|
||||
}
|
||||
|
||||
function get_query($table) {
|
||||
return 'SELECT * FROM ' . $table . $this->settings->active_query .
|
||||
' GROUP BY ' . $table . '.id ORDER BY time DESC LIMIT ' . $this->settings->limit_per_page;
|
||||
$active_query = $this->settings->active_query;
|
||||
$limit = $this->settings->limit_per_page;
|
||||
return "SELECT * FROM $table $active_query GROUP BY $table.id ORDER BY time DESC LIMIT $limit";
|
||||
}
|
||||
|
||||
function run_query($table) {
|
||||
$time = microtime(true);
|
||||
try {
|
||||
$result = $this->conn->query($this->get_query($table));
|
||||
} catch (PDOException $ex) {
|
||||
die($ex->getMessage());
|
||||
}
|
||||
echo('<!-- Query executed in ' . (microtime(true) - $time) . ' sec -->');
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -33,10 +32,9 @@ class Page {
|
||||
|
||||
function get_name($uuid) {
|
||||
if (array_key_exists($uuid, $this->uuid_name_cache)) return $this->uuid_name_cache[$uuid];
|
||||
$time = microtime(true);
|
||||
$stmt = $this->conn->prepare("SELECT name FROM " . $this->settings->table_history . " WHERE uuid=? ORDER BY date DESC LIMIT 1");
|
||||
$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()) {
|
||||
echo('<!-- Query executed in ' . (microtime(true) - $time) . ' sec -->');
|
||||
$banner = $row['name'];
|
||||
$this->uuid_name_cache[$uuid] = $banner;
|
||||
return $banner;
|
||||
@ -78,19 +76,20 @@ class Page {
|
||||
}
|
||||
|
||||
function print_page_header($title) {
|
||||
echo('
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<h1 class="' . ($title === "Bans" ? "modal" : "navbar") . '-header">' . $title . '</h1>
|
||||
$type = $title === "Bans" ? "modal" : "navbar";
|
||||
echo("
|
||||
<div class=\"row\">
|
||||
<div class=\"col-lg-12\">
|
||||
<h1 class=\"$type-header\">$title</h1>
|
||||
</div>
|
||||
</div>
|
||||
');
|
||||
");
|
||||
}
|
||||
|
||||
function print_table_headers($headers) {
|
||||
echo("<thead><tr>");
|
||||
foreach ($headers as $header) {
|
||||
echo '<th><div style="text-align: center;">', $header, '</div></th>';
|
||||
echo "<th><div style=\"text-align: center;\">$header</div></th>";
|
||||
}
|
||||
echo("<tbody>");
|
||||
}
|
||||
|
@ -22,12 +22,12 @@ final class Settings {
|
||||
$this->limit_per_page = 20;
|
||||
|
||||
// If you set a table prefix in config.yml, put it here too
|
||||
$this->table_prefix = "";
|
||||
$table_prefix = "";
|
||||
|
||||
$this->table_bans = $this->table_prefix . "bans";
|
||||
$this->table_mutes = $this->table_prefix . "mutes";
|
||||
$this->table_warnings = $this->table_prefix . "warnings";
|
||||
$this->table_history = $this->table_prefix . "history";
|
||||
$this->table_bans = "{$table_prefix}bans";
|
||||
$this->table_mutes = "{$table_prefix}mutes";
|
||||
$this->table_warnings = "{$table_prefix}warnings";
|
||||
$this->table_history = "{$table_prefix}history";
|
||||
|
||||
// The date format can be changed here.
|
||||
// https://secure.php.net/manual/en/function.date.php
|
||||
@ -36,7 +36,7 @@ final class Settings {
|
||||
$this->date_format = 'F j, Y, g:i a';
|
||||
date_default_timezone_set("UTC");
|
||||
|
||||
$this->driver = 'mysql';
|
||||
$driver = 'mysql';
|
||||
|
||||
$this->active_query = "";
|
||||
if (!$this->show_inactive_bans) {
|
||||
@ -44,7 +44,7 @@ final class Settings {
|
||||
}
|
||||
|
||||
if ($connect) {
|
||||
$dsn = $this->driver . ':dbname=' . $database . ';host=' . $dbhost . ';port=' . $dbport . ';charset=utf8';
|
||||
$dsn = "$driver:dbname=$database;host=$dbhost;port=$dbport;charset=utf8";
|
||||
|
||||
try {
|
||||
$this->conn = new PDO($dsn, $username, $password);
|
||||
|
Loading…
x
Reference in New Issue
Block a user