- |
- |
- |
- |
+ get_avatar($player_name); ?> |
+ get_avatar($page->get_banner_name($row)); ?> |
+ clean($row['reason']); ?> |
+ millis_to_date($row['time']); ?> |
settings->show_inactive_bans && !$row['active']) {
$until .= ' (Unbanned)';
}
echo $until;
@@ -38,4 +40,4 @@
-
\ No newline at end of file
+
diff --git a/check.php b/check.php
index c727ad9..5a60f55 100644
--- a/check.php
+++ b/check.php
@@ -7,9 +7,10 @@ if (isset($_POST['name'], $_POST['table'])) {
return;
}
require './includes/page.php';
+ $page = new Page();
$name = $_POST['name'];
- $stmt = $conn->prepare("SELECT name,uuid FROM " . $table_history . " WHERE name=? ORDER BY date LIMIT 1");
+ $stmt = $page->conn->prepare("SELECT name,uuid FROM " . $page->settings->table_history . " WHERE name=? ORDER BY date LIMIT 1");
if ($stmt->execute(array($name))) {
if ($row = $stmt->fetch()) {
$name = $row['name'];
@@ -21,21 +22,21 @@ if (isset($_POST['name'], $_POST['table'])) {
echo($name . ' has not joined before. ');
return;
}
- $table = $table_bans;
+ $table = $page->settings->table_bans;
- $stmt = $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. ');
return;
}
- $banner = get_banner_name($row);
+ $banner = $page->get_banner_name($row);
$reason = $row['reason'];
- $time = millis_to_date($row['time']);
- $until = millis_to_date($row['until']);
+ $time = $page->millis_to_date($row['time']);
+ $until = $page->millis_to_date($row['until']);
echo($name . ' is banned! ');
echo('Banned by: ' . $banner . ' ');
- echo('Reason: ' . clean($reason) . ' ');
+ echo('Reason: ' . $page->clean($reason) . ' ');
echo('Banned on: ' . $time . ' ');
if ($row['until'] > 0) {
echo('Banned until: ' . $until . ' ');
@@ -44,4 +45,4 @@ if (isset($_POST['name'], $_POST['table'])) {
}
}
}
-?>
\ No newline at end of file
+?>
diff --git a/includes/head.php b/includes/head.php
index 19479d5..fef4358 100644
--- a/includes/head.php
+++ b/includes/head.php
@@ -1,4 +1,3 @@
-
@@ -10,4 +9,4 @@
html {
background-image: url('includes/img/377759.png');
}
-
\ No newline at end of file
+
diff --git a/includes/header.php b/includes/header.php
index d86ee81..f445c02 100644
--- a/includes/header.php
+++ b/includes/header.php
@@ -1,7 +1,11 @@
\ No newline at end of file
+
diff --git a/includes/page.php b/includes/page.php
index aa37eaa..20b1c6b 100644
--- a/includes/page.php
+++ b/includes/page.php
@@ -3,100 +3,103 @@ require './includes/head.php';
require './includes/header.php';
require_once './includes/settings.php';
-litebans_connect();
+//litebans_connect();
-function get_query($table) {
- global $active_query, $limit_per_page;
- return 'SELECT * FROM ' . $table . $active_query .
- ' GROUP BY ' . $table . '.id ORDER BY time DESC LIMIT ' . $limit_per_page;
-}
-
-function run_query($table) {
- global $conn;
- $time = microtime(true);
- try {
- $result = $conn->query(get_query($table));
- } catch (PDOException $ex) {
- die($ex->getMessage());
+class Page {
+ public function __construct() {
+ $settings = new Settings();
+ $this->conn = $settings->conn;
+ $this->settings = $settings;
+ $this->uuid_name_cache = array();
}
- echo('');
- return $result;
-}
-function get_avatar($name) {
- return " " . $name;
-}
+ 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;
+ }
-$uuid_name_cache = array();
-
-function get_name($uuid) {
- global $conn, $table_history, $uuid_name_cache;
- if (array_key_exists($uuid, $uuid_name_cache)) return $uuid_name_cache[$uuid];
- $time = microtime(true);
- $stmt = $conn->prepare("SELECT name FROM " . $table_history . " WHERE uuid=? ORDER BY date DESC LIMIT 1");
- if ($stmt->execute(array($uuid)) && $row = $stmt->fetch()) {
+ function run_query($table) {
+ $time = microtime(true);
+ try {
+ $result = $this->conn->query($this->get_query($table));
+ } catch (PDOException $ex) {
+ die($ex->getMessage());
+ }
echo('');
- $banner = $row['name'];
- $uuid_name_cache[$uuid] = $banner;
- return $banner;
+ return $result;
}
- $uuid_name_cache[$uuid] = null;
- return null;
-}
-function get_banner_name($row) {
- $uuid = $row['banned_by_uuid'];
- $name = get_name($uuid);
- if ($name !== null) {
- return $name;
+ function get_avatar($name) {
+ return " " . $name;
}
- $name = $row['banned_by_name'];
- return clean($name);
-}
-function millis_to_date($millis) {
- global $date_format;
- return date($date_format, $millis / 1000);
-}
-/**
- * Prepares text to be displayed on the web interface.
- * Removes chat colours, replaces newlines with proper HTML, and sanitizes the text.
- * @param $text
- * @return mixed|string
- */
-function clean($text) {
- if (strstr($text, "\xa7") || strstr($text, "&")) {
- $regex = "/(?i)(\xa7|&)[0-9A-FK-OR]/";
- $text = preg_replace($regex, "", $text);
+ 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");
+ if ($stmt->execute(array($uuid)) && $row = $stmt->fetch()) {
+ echo('');
+ $banner = $row['name'];
+ $uuid_name_cache[$uuid] = $banner;
+ return $banner;
+ }
+ $uuid_name_cache[$uuid] = null;
+ return null;
}
- $text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
- if (strstr($text, "\n")) {
- $text = preg_replace("/\n/", " ", $text);
- }
- return $text;
-}
-function print_page_header($title) {
- echo('
+ function get_banner_name($row) {
+ $uuid = $row['banned_by_uuid'];
+ $name = $this->get_name($uuid);
+ if ($name !== null) {
+ return $name;
+ }
+ $name = $row['banned_by_name'];
+ return $this->clean($name);
+ }
+
+ function millis_to_date($millis) {
+ return date($this->settings->date_format, $millis / 1000);
+ }
+
+ /**
+ * Prepares text to be displayed on the web interface.
+ * Removes chat colours, replaces newlines with proper HTML, and sanitizes the text.
+ * @param $text
+ * @return mixed|string
+ */
+ function clean($text) {
+ if (strstr($text, "\xa7") || strstr($text, "&")) {
+ $regex = "/(?i)(\xa7|&)[0-9A-FK-OR]/";
+ $text = preg_replace($regex, "", $text);
+ }
+ $text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
+ if (strstr($text, "\n")) {
+ $text = preg_replace("/\n/", " ", $text);
+ }
+ return $text;
+ }
+
+ function print_page_header($title) {
+ echo('
');
-}
-
-function print_table_headers($headers) {
- echo("");
- foreach ($headers as $header) {
- echo '', $header, ' | ';
}
- echo(" |
");
+ }
+
+ function print_check_form($table) {
+ echo('
@@ -105,6 +108,7 @@ function print_check_form($table) {
');
+ }
}
?>
diff --git a/includes/settings.php b/includes/settings.php
index ce5a8b9..77653f5 100644
--- a/includes/settings.php
+++ b/includes/settings.php
@@ -1,62 +1,58 @@
name = 'LiteBans';
-$username = 'root';
-$password = 'password';
+ // Server host
+ $dbhost = 'localhost';
+ $dbport = 3306;
-// Database name
-$database = 'litebans';
+ $username = 'root';
+ $password = 'password';
-// Show inactive bans? Removed bans will show (Unbanned), mutes will show (Unmuted), warnings will show (Expired).
-$show_inactive_bans = true;
+ // Database name
+ $database = 'litebans';
-// Amount of bans/mutes/warnings to show on each page
-$limit_per_page = 20;
+ // Show inactive bans? Removed bans will show (Unbanned), mutes will show (Unmuted), warnings will show (Expired).
+ $this->show_inactive_bans = true;
-// If you set a table prefix in config.yml, put it here too
-$table_prefix = "";
+ // Amount of bans/mutes/warnings to show on each page
+ $this->limit_per_page = 20;
-// The date format can be changed here.
-// https://secure.php.net/manual/en/function.date.php
-// Example of default:
-// July 2, 2015, 9:19 pm
-$date_format = 'F j, Y, g:i a';
-date_default_timezone_set("UTC");
+ // If you set a table prefix in config.yml, put it here too
+ $this->table_prefix = "";
-$driver = 'mysql';
+ $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";
-/*****************************************************************************/
-function litebans_connect() {
- // imported
- global $dbhost, $dbport, $username, $password, $database, $table_prefix, $show_inactive_bans, $driver;
+ // The date format can be changed here.
+ // https://secure.php.net/manual/en/function.date.php
+ // Example of default:
+ // July 2, 2015, 9:19 pm
+ $this->date_format = 'F j, Y, g:i a';
+ date_default_timezone_set("UTC");
- // exported
- global $conn, $active_query;
- global $table_bans, $table_mutes, $table_warnings, $table_history;
+ $this->driver = 'mysql';
- $dsn = $driver . ':dbname=' . $database . ';host=' . $dbhost . ';port=' . $dbport . ';charset=utf8';
+ $this->active_query = "";
+ if (!$this->show_inactive_bans) {
+ $this->active_query = "WHERE active=1";
+ }
- try {
- $conn = new PDO($dsn, $username, $password);
- } catch (PDOException $e) {
- echo 'Connection failed: ' . $e->getMessage();
- }
+ if ($connect) {
+ $dsn = $this->driver . ':dbname=' . $database . ';host=' . $dbhost . ';port=' . $dbport . ';charset=utf8';
- $table_bans = $table_prefix . "bans";
- $table_mutes = $table_prefix . "mutes";
- $table_warnings = $table_prefix . "warnings";
- $table_history = $table_prefix . "history";
-
- $active_query = "WHERE active=1";
- if ($show_inactive_bans) {
- $active_query = "";
+ try {
+ $this->conn = new PDO($dsn, $username, $password);
+ } catch (PDOException $e) {
+ echo 'Connection failed: ' . $e->getMessage();
+ }
+ }
}
}
-?>
\ No newline at end of file
+?>
diff --git a/index.php b/index.php
index 07be1d5..169494d 100644
--- a/index.php
+++ b/index.php
@@ -1,9 +1,13 @@
-
-
-
Index -
+
+
Index - name; ?>
-
Welcome to 's Ban List.
+
Welcome to name; ?>'s Ban List.
Here is where our Bans, Mutes, and Warnings are listed.
diff --git a/mutes.php b/mutes.php
index 9ce21db..93135c8 100644
--- a/mutes.php
+++ b/mutes.php
@@ -1,31 +1,33 @@
-
-
TempMutes -
+
+
TempMutes - settings->name; ?>
print_page_header("Mutes");
?>
print_table_headers(array("Name", "Muted By", "Reason", "Muted On", "Muted Until"));
+ $result = $page->run_query($page->settings->table_mutes);
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
- $player_name = get_name($row['uuid']);
+ $player_name = $page->get_name($row['uuid']);
if ($player_name === null) continue;
- $until = millis_to_date($row['until']);
+ $until = $page->millis_to_date($row['until']);
?>
- |
- |
- |
- |
+ get_avatar($player_name); ?> |
+ get_avatar($page->get_banner_name($row)); ?> |
+ clean($row['reason']); ?> |
+ millis_to_date($row['time']); ?> |
settings->show_inactive_bans && !$row['active']) {
$until .= ' (Unmuted)';
}
echo $until;
@@ -37,4 +39,4 @@
-
\ No newline at end of file
+
diff --git a/warnings.php b/warnings.php
index 0b6430e..9e8203d 100644
--- a/warnings.php
+++ b/warnings.php
@@ -1,30 +1,32 @@
-
-Warnings -
+
+Warnings - settings->name; ?>
print_page_header("Warnings");
?>
print_table_headers(array("Name", "Warned By", "Reason", "Warned Until", "Received Warning?"));
+ $result = $page->run_query($page->settings->table_warnings);
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
- $player_name = get_name($row['uuid']);
+ $player_name = $page->get_name($row['uuid']);
if ($player_name === null) continue;
- $until = millis_to_date($row['until']);
+ $until = $page->millis_to_date($row['until']);
?>
- |
- |
- |
+ get_avatar($player_name); ?> |
+ get_avatar($page->get_banner_name($row)); ?> |
+ clean($row['reason']); ?> |
settings->show_inactive_bans && !$row['active']) {
$until .= ' (Expired)';
}
echo $until;
@@ -39,4 +41,4 @@
-
\ No newline at end of file
+
| |