- 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->bindParam(":uuid", $uuid, PDO::PARAM_STR);
// Incompatible with pager as rows are usort()'d
// $st->bindParam(':limit', $limit, PDO::PARAM_INT);
if ($st->execute()) {
while ($row = $st->fetch(PDO::FETCH_ASSOC)) {
@ -59,18 +57,14 @@ class History {
$page = new Page("history");
if (!isset($_GET['uuid'])) {
die("Missing arguments (uuid).");
}
isset($_GET['uuid']) or die("Missing arguments (uuid).");
$staffhistory = (isset($_GET['staffhistory']) && $_GET['staffhistory'] === "1");
$uuid = $_GET['uuid'];
$name = $page->get_name($uuid);
if ($name === null) {
die("Player not found in database.");
}
$name !== null or die("Player not found in database.");
if ($staffhistory) {
$page->name = "Recent Punishments by $name";

View File

@ -1,8 +1,34 @@
<?php
namespace litebans;
require_once './includes/settings.php';
$settings = new Settings(false);
use PDO;
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) {
echo '<ul class="nav navbar-nav">';
@ -11,11 +37,18 @@ function navbar($links) {
if ((substr($_SERVER['SCRIPT_NAME'], -strlen($page))) === $page) {
$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 '</ul>';
}
function print_header() {
$settings = $this->page->settings;
?>
<!DOCTYPE html>
<html lang="en">
@ -48,11 +81,12 @@ function navbar($links) {
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</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>
<nav id="litebans-navbar" class="collapse navbar-collapse">
<?php
navbar(array(
$this->navbar(array(
"index.php" => "Home",
"bans.php" => "Bans",
"mutes.php" => "Mutes",
@ -67,3 +101,8 @@ function navbar($links) {
</nav>
</div>
</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'])) {
$page = $_GET['page']; // user input
if (filter_var($page, FILTER_VALIDATE_INT)) {
$this->page = (int)$page;
$this->page = max(0,(int)$page);
}
}
$this->name = $name;
@ -43,6 +43,9 @@ class Page {
'warn' => '(Expired)',
'kick' => null,
);
$h = new Header($this);
$h->print_header();
}
public function type_info($type) {
@ -303,7 +306,7 @@ class Page {
<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>
</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>
';

View File

@ -57,6 +57,9 @@ final class Settings {
// If enabled, names will be shown below avatars instead of being shown next to them.
$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.
// https://secure.php.net/manual/en/function.date.php
// Example of default: July 2, 2015, 9:19 PM
@ -85,6 +88,7 @@ final class Settings {
if (!$this->show_inactive_bans) {
$this->active_query = "WHERE active=" . Settings::$TRUE;
}
$this->driver = $driver;
if ($connect) {
$dsn = "$driver:dbname=$database;host=$host;port=$port";

View File

@ -1,16 +1,16 @@
<?php
namespace litebans;
include_once './includes/header.php';
include_once './includes/settings.php';
$settings = new Settings(false);
require_once './includes/page.php';
$page = new Page("index");
$page->print_title();
?>
<title>Index - <?php echo $settings->name; ?></title>
<div class="container">
<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>
<?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;
}
if (!isset($_GET['type'], $_GET['id'])) {
die("Missing arguments (type, id).");
}
isset($_GET['type'], $_GET['id']) or die("Missing arguments (type, id).");
$type = $_GET['type'];
$id = $_GET['id'];
$page = new Page($type);
if ($page->type === null) {
die("Unknown page type requested.");
}
($page->type !== null) or 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;
$type = $page->type;
@ -138,13 +133,11 @@ $query = "SELECT * FROM $table WHERE id=? LIMIT 1";
$st = $page->conn->prepare($query);
if ($st->execute(array($id))) {
if (!($row = $st->fetch())) {
die("Error: $type not found in database.");
}
($row = $st->fetch()) or die("Error: $type not found in database.");
$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);
@ -173,6 +166,7 @@ if ($st->execute(array($id))) {
$permanent_val = $info->page->permanent[$type];
foreach ($map as $key => $val) {
if ($permanent && $key === "Expires" && $val === $permanent_val) {
// skip "Expires" row if punishment is permanent
continue;
}
echo "<tr><td>$key</td><td>$val</td></tr>";