- Updated jQuery to v2.1.4,  include original unformatted versions

- Added punishment totals to the header (bans, mutes, warnings, kicks) as badges

- Refactored and cleaned up a few classes
This commit is contained in:
ruan 2015-10-09 04:27:07 +02:00
parent 329088cb0d
commit 162d0ede65
8 changed files with 3868 additions and 7570 deletions

View File

@ -30,8 +30,6 @@ class History {
$st = $page->conn->prepare("SELECT * FROM $table WHERE $field=:uuid ORDER BY time"); $st = $page->conn->prepare("SELECT * FROM $table WHERE $field=:uuid ORDER BY time");
$st->bindParam(":uuid", $uuid, PDO::PARAM_STR); $st->bindParam(":uuid", $uuid, PDO::PARAM_STR);
// Incompatible with pager as rows are usort()'d
// $st->bindParam(':limit', $limit, PDO::PARAM_INT);
if ($st->execute()) { if ($st->execute()) {
while ($row = $st->fetch(PDO::FETCH_ASSOC)) { while ($row = $st->fetch(PDO::FETCH_ASSOC)) {
@ -59,18 +57,14 @@ class History {
$page = new Page("history"); $page = new Page("history");
if (!isset($_GET['uuid'])) { isset($_GET['uuid']) or die("Missing arguments (uuid).");
die("Missing arguments (uuid).");
}
$staffhistory = (isset($_GET['staffhistory']) && $_GET['staffhistory'] === "1"); $staffhistory = (isset($_GET['staffhistory']) && $_GET['staffhistory'] === "1");
$uuid = $_GET['uuid']; $uuid = $_GET['uuid'];
$name = $page->get_name($uuid); $name = $page->get_name($uuid);
if ($name === null) { $name !== null or die("Player not found in database.");
die("Player not found in database.");
}
if ($staffhistory) { if ($staffhistory) {
$page->name = "Recent Punishments by $name"; $page->name = "Recent Punishments by $name";

View File

@ -1,8 +1,34 @@
<?php <?php
namespace litebans; namespace litebans;
require_once './includes/settings.php'; use PDO;
$settings = new Settings(false);
class Header {
/**
* @param $page Page
*/
function __construct($page) {
$this->page = $page;
if ($page->settings->header_show_totals) {
$t = $page->settings->table;
$t_bans = $t['bans'];
$t_mutes = $t['mutes'];
$t_warnings = $t['warnings'];
$t_kicks = $t['kicks'];
$st = $page->conn->query("SELECT
(SELECT COUNT(*) FROM $t_bans) AS c_bans,
(SELECT COUNT(*) FROM $t_mutes) AS c_mutes,
(SELECT COUNT(*) FROM $t_warnings) AS c_warnings,
(SELECT COUNT(*) FROM $t_kicks) AS c_kicks");
($row = $st->fetch(PDO::FETCH_ASSOC)) or die('Failed to fetch row counts.');
$this->count = array(
'bans.php' => $row['c_bans'],
'mutes.php' => $row['c_mutes'],
'warnings.php' => $row['c_warnings'],
'kicks.php' => $row['c_kicks'],
);
}
}
function navbar($links) { function navbar($links) {
echo '<ul class="nav navbar-nav">'; echo '<ul class="nav navbar-nav">';
@ -11,11 +37,18 @@ function navbar($links) {
if ((substr($_SERVER['SCRIPT_NAME'], -strlen($page))) === $page) { if ((substr($_SERVER['SCRIPT_NAME'], -strlen($page))) === $page) {
$li .= ' class="active"'; $li .= ' class="active"';
} }
if ($this->page->settings->header_show_totals && isset($this->count[$page])) {
$title .= " <span class=\"badge\">";
$title .= $this->count[$page];
$title .= "</span>";
}
echo "<$li><a href=\"$page\">$title</a></li>"; echo "<$li><a href=\"$page\">$title</a></li>";
} }
echo '</ul>'; echo '</ul>';
} }
function print_header() {
$settings = $this->page->settings;
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
@ -48,11 +81,12 @@ function navbar($links) {
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="navbar-brand" href="<?php echo $settings->name_link; ?>"><?php echo $settings->name; ?></a> <a class="navbar-brand"
href="<?php echo $settings->name_link; ?>"><?php echo $settings->name; ?></a>
</div> </div>
<nav id="litebans-navbar" class="collapse navbar-collapse"> <nav id="litebans-navbar" class="collapse navbar-collapse">
<?php <?php
navbar(array( $this->navbar(array(
"index.php" => "Home", "index.php" => "Home",
"bans.php" => "Bans", "bans.php" => "Bans",
"mutes.php" => "Mutes", "mutes.php" => "Mutes",
@ -67,3 +101,8 @@ function navbar($links) {
</nav> </nav>
</div> </div>
</header> </header>
<?php
}
}
?>

8702
includes/js/jquery.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -19,7 +19,7 @@ class Page {
if (isset($_GET['page'])) { if (isset($_GET['page'])) {
$page = $_GET['page']; // user input $page = $_GET['page']; // user input
if (filter_var($page, FILTER_VALIDATE_INT)) { if (filter_var($page, FILTER_VALIDATE_INT)) {
$this->page = (int)$page; $this->page = max(0,(int)$page);
} }
} }
$this->name = $name; $this->name = $name;
@ -43,6 +43,9 @@ class Page {
'warn' => '(Expired)', 'warn' => '(Expired)',
'kick' => null, 'kick' => null,
); );
$h = new Header($this);
$h->print_header();
} }
public function type_info($type) { public function type_info($type) {
@ -303,7 +306,7 @@ class Page {
<div style="margin-left: 15px;"> <div style="margin-left: 15px;">
<form onsubmit="captureForm(event);" class="form-inline"><div class="form-group"><input type="text" class="form-control" id="user" placeholder="Player"></div><button type="submit" class="btn btn-default" style="margin-left: 5px;">Check</button></form> <form onsubmit="captureForm(event);" class="form-inline"><div class="form-group"><input type="text" class="form-control" id="user" placeholder="Player"></div><button type="submit" class="btn btn-default" style="margin-left: 5px;">Check</button></form>
</div> </div>
<script type="text/javascript">function captureForm(b){o=$("#output");o.removeClass("in");x=setTimeout(function(){o.html("<br>")}, 150);$.ajax({type:"GET",url:"check.php?name="+$("#user").val()+"&table=' . $table . '"}).done(function(c){clearTimeout(x);o.html(c);o.addClass("in")});b.preventDefault();return false};</script> <script type="text/javascript">function captureForm(b){var o=$("#output");o.removeClass("in");var x=setTimeout(function(){o.html("<br>")}, 150);$.ajax({type:"GET",url:"check.php?name="+$("#user").val()+"&table=' . $table . '"}).done(function(c){clearTimeout(x);o.html(c);o.addClass("in")});b.preventDefault();return false};</script>
<div id="output" class="success fade" data-alert="alert" style="margin-left: 15px;"><br></div> <div id="output" class="success fade" data-alert="alert" style="margin-left: 15px;"><br></div>
</div> </div>
'; ';

View File

@ -57,6 +57,9 @@ final class Settings {
// If enabled, names will be shown below avatars instead of being shown next to them. // If enabled, names will be shown below avatars instead of being shown next to them.
$this->avatar_names_below = true; $this->avatar_names_below = true;
// If enabled, the total amount of bans, mutes, warnings, and kicks will be shown next to the buttons in the header.
$this->header_show_totals = true;
// The date format can be changed here. // The date format can be changed here.
// https://secure.php.net/manual/en/function.date.php // https://secure.php.net/manual/en/function.date.php
// Example of default: July 2, 2015, 9:19 PM // Example of default: July 2, 2015, 9:19 PM
@ -85,6 +88,7 @@ final class Settings {
if (!$this->show_inactive_bans) { if (!$this->show_inactive_bans) {
$this->active_query = "WHERE active=" . Settings::$TRUE; $this->active_query = "WHERE active=" . Settings::$TRUE;
} }
$this->driver = $driver; $this->driver = $driver;
if ($connect) { if ($connect) {
$dsn = "$driver:dbname=$database;host=$host;port=$port"; $dsn = "$driver:dbname=$database;host=$host;port=$port";

View File

@ -1,16 +1,16 @@
<?php <?php
namespace litebans; namespace litebans;
include_once './includes/header.php'; require_once './includes/page.php';
include_once './includes/settings.php'; $page = new Page("index");
$settings = new Settings(false); $page->print_title();
?> ?>
<title>Index - <?php echo $settings->name; ?></title>
<div class="container"> <div class="container">
<div class="jumbotron"> <div class="jumbotron">
<div style="text-align: center;"><h2>Welcome to <?php echo $settings->name; ?>'s Ban List.</h2></div> <div style="text-align: center;"><h2>Welcome to <?php echo $page->settings->name; ?>'s Ban List.</h2></div>
<div style="text-align: center;"><p>Here is where our Bans, Mutes, Warnings, and Kicks are listed.</p></div> <div style="text-align: center;"><p>Here is where all of our punishments are listed.</p></div>
</div> </div>
</div> </div>
<?php include_once './includes/footer.php'; ?> <?php $page->print_footer(false); ?>

View File

@ -114,21 +114,16 @@ if ((substr($_SERVER['SCRIPT_NAME'], -strlen("info.php"))) !== "info.php") {
return; return;
} }
if (!isset($_GET['type'], $_GET['id'])) { isset($_GET['type'], $_GET['id']) or die("Missing arguments (type, id).");
die("Missing arguments (type, id).");
}
$type = $_GET['type']; $type = $_GET['type'];
$id = $_GET['id']; $id = $_GET['id'];
$page = new Page($type); $page = new Page($type);
if ($page->type === null) { ($page->type !== null) or die("Unknown page type requested.");
die("Unknown page type requested.");
} filter_var($id, FILTER_VALIDATE_INT) or die("Invalid ID.");
if (!filter_var($id, FILTER_VALIDATE_INT)) {
die("Invalid ID.");
}
$id = (int)$id; $id = (int)$id;
$type = $page->type; $type = $page->type;
@ -138,13 +133,11 @@ $query = "SELECT * FROM $table WHERE id=? LIMIT 1";
$st = $page->conn->prepare($query); $st = $page->conn->prepare($query);
if ($st->execute(array($id))) { if ($st->execute(array($id))) {
if (!($row = $st->fetch())) { ($row = $st->fetch()) or die("Error: $type not found in database.");
die("Error: $type not found in database.");
}
$player_name = $page->get_name($row['uuid']); $player_name = $page->get_name($row['uuid']);
if ($player_name === null) {
die("Error: Player name not found."); ($player_name !== null) or die("Error: Player name not found.");
}
$info = Info::create($row, $page, $type); $info = Info::create($row, $page, $type);
@ -173,6 +166,7 @@ if ($st->execute(array($id))) {
$permanent_val = $info->page->permanent[$type]; $permanent_val = $info->page->permanent[$type];
foreach ($map as $key => $val) { foreach ($map as $key => $val) {
if ($permanent && $key === "Expires" && $val === $permanent_val) { if ($permanent && $key === "Expires" && $val === $permanent_val) {
// skip "Expires" row if punishment is permanent
continue; continue;
} }
echo "<tr><td>$key</td><td>$val</td></tr>"; echo "<tr><td>$key</td><td>$val</td></tr>";