diff --git a/check.php b/check.php index 3901604..3d6cfe4 100644 --- a/check.php +++ b/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.
'); + echo "$name has not joined before.
"; 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.
'); + echo "$name is not banned.
"; 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!
'); - echo('Banned by: ' . $banner . '
'); - echo('Reason: ' . $page->clean($reason) . '
'); - echo('Banned on: ' . $time . '
'); + echo "$name is banned!
"; + echo "Banned by: $banner
"; + echo "Reason: $reason
"; + echo "Banned on: $time
"; if ($row['until'] > 0) { - echo('Banned until: ' . $until . '
'); + echo "Banned until: $until
"; } else { - echo('Banned permanently.
'); + echo "Banned permanently.
"; } } } diff --git a/includes/page.php b/includes/page.php index f87f459..4a8858e 100644 --- a/includes/page.php +++ b/includes/page.php @@ -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(''); 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(''); $banner = $row['name']; $this->uuid_name_cache[$uuid] = $banner; return $banner; @@ -78,19 +76,20 @@ class Page { } function print_page_header($title) { - echo(' -
-
-

' . $title . '

+ $type = $title === "Bans" ? "modal" : "navbar"; + echo(" +
+
+

$title

- '); + "); } function print_table_headers($headers) { echo(""); foreach ($headers as $header) { - echo '
', $header, '
'; + echo "
$header
"; } echo(""); } diff --git a/includes/settings.php b/includes/settings.php index 77653f5..c53c08e 100644 --- a/includes/settings.php +++ b/includes/settings.php @@ -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);