Refactor HTML+PHP code into simple PHP

This commit is contained in:
ruan 2015-09-12 09:27:22 +02:00
parent 8be6c03d38
commit b50ebe9808
7 changed files with 119 additions and 152 deletions

View File

@ -1,24 +1,22 @@
<?php <?php
namespace litebans; namespace litebans;
use PDO; use PDO;
require_once './includes/page.php'; require_once './includes/page.php';
$page = new Page("bans"); $page = new Page("bans");
$page->print_title(); $page->print_title();
$headers = array("Name", "Banned By", "Reason", "Banned On", "Banned Until"); $headers = array("Name", "Banned By", "Reason", "Banned On", "Banned Until");
?>
<div class="container"> $page->print_page_header();
<?php
$page->print_page_header(); $page->print_check_form();
$page->print_check_form();
?> $page->table_begin();
<div class="row" style="margin-bottom:60px;"> $page->table_print_headers($headers);
<div class="col-lg-12">
<?php $result = $page->run_query();
$page->table_begin(); while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$page->table_print_headers($headers);
$result = $page->run_query();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$player_name = $page->get_name($row['uuid']); $player_name = $page->get_name($row['uuid']);
if ($player_name === null) continue; if ($player_name === null) continue;
@ -29,11 +27,8 @@ $headers = array("Name", "Banned By", "Reason", "Banned On", "Banned Until");
'Banned On' => $page->millis_to_date($row['time']), 'Banned On' => $page->millis_to_date($row['time']),
'Banned Until' => $page->expiry($row), 'Banned Until' => $page->expiry($row),
)); ));
} }
$page->table_end(); $page->table_end();
$page->print_pager(); $page->print_pager();
?>
</div> $page->print_footer();
</div>
<?php $page->print_footer(); ?>
</div>

View File

@ -210,17 +210,16 @@ class Page {
echo "</tr>"; echo "</tr>";
} }
function print_page_header() { function print_page_header($container_start = true) {
$title = $this->title(); $title = $this->title();
//$type = ($title === "Bans") ? "modal-header" : "navbar-header"; if ($container_start) {
$type = "modal-header"; echo '<div class="container">';
echo(" }
<div class=\"row\">
<div style=\"text-align: center;\" class=\"col-lg-12\"> echo "<div class=\"row\"><div style=\"text-align: center;\" class=\"col-lg-12\"><h1 class=\"modal-header\">$title</h1></div></div>";
<h1 class=\"$type\">$title</h1> if ($container_start) {
</div> echo '<div class="row"><div style="text-align: center;" class="col-lg-12">';
</div> }
");
} }
function table_print_headers($headers) { function table_print_headers($headers) {
@ -277,7 +276,10 @@ class Page {
echo "$pager_prev $pager_next $pager_count"; echo "$pager_prev $pager_next $pager_count";
} }
function print_footer() { function print_footer($container_end = true) {
if ($container_end) {
echo "</div></div></div>";
}
include './includes/footer.php'; include './includes/footer.php';
$time = microtime(true) - $this->time; $time = microtime(true) - $this->time;
echo "<!-- Page generated in $time seconds. -->"; echo "<!-- Page generated in $time seconds. -->";

View File

@ -11,7 +11,7 @@ $settings = new Settings(false);
<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 $settings->name; ?>'s Ban List.</h2></div>
<div style="text-align: center;"><p>Here is where our Bans, Mutes, and Warnings are listed.</p></div> <div style="text-align: center;"><p>Here is where our Bans, Mutes, Warnings, and Kicks are listed.</p></div>
</div> </div>
</div> </div>
<?php include './includes/footer.php'; ?> <?php include './includes/footer.php'; ?>

View File

@ -144,13 +144,8 @@ if ($st->execute(array($id))) {
$page->name .= "<span $style class='label label-danger'>Permanent</span>"; $page->name .= "<span $style class='label label-danger'>Permanent</span>";
} }
} }
$page->print_page_header();
?>
<div class="container">
<div class="row" style="margin-bottom:60px;">
<?php $page->print_page_header(); ?>
<div style="text-align: center;" class="col-lg-12">
<?php
$page->table_begin(); $page->table_begin();
$map = $info->basic_info($row, $player_name); $map = $info->basic_info($row, $player_name);
$permanent_val = $info->page->permanent[$type]; $permanent_val = $info->page->permanent[$type];
@ -161,12 +156,5 @@ if ($st->execute(array($id))) {
echo "<tr><td>$key</td><td>$val</td></tr>"; echo "<tr><td>$key</td><td>$val</td></tr>";
} }
$page->table_end(false); $page->table_end(false);
?>
</div>
</div>
<?php
$page->print_footer(); $page->print_footer();
?>
</div>
<?php
} }

View File

@ -1,23 +1,20 @@
<?php <?php
namespace litebans; namespace litebans;
use PDO; use PDO;
require_once './includes/page.php'; require_once './includes/page.php';
$page = new Page("kicks"); $page = new Page("kicks");
$page->print_title(); $page->print_title();
$headers = array("Name", "Kicked By", "Reason", "Date"); $headers = array("Name", "Kicked By", "Reason", "Date");
?>
<div class="container"> $page->print_page_header();
<?php
$page->print_page_header(); $page->table_begin();
?> $page->table_print_headers($headers);
<div class="row" style="margin-bottom:60px;">
<div class="col-lg-12"> $result = $page->run_query();
<?php while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$page->table_begin();
$page->table_print_headers($headers);
$result = $page->run_query();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$player_name = $page->get_name($row['uuid']); $player_name = $page->get_name($row['uuid']);
if ($player_name === null) continue; if ($player_name === null) continue;
@ -27,11 +24,8 @@ $headers = array("Name", "Kicked By", "Reason", "Date");
'Reason' => $page->clean($row['reason']), 'Reason' => $page->clean($row['reason']),
'Date' => $page->millis_to_date($row['time']), 'Date' => $page->millis_to_date($row['time']),
)); ));
} }
$page->table_end(); $page->table_end();
$page->print_pager(); $page->print_pager();
?>
</div> $page->print_footer();
</div>
<?php $page->print_footer(); ?>
</div>

View File

@ -1,23 +1,20 @@
<?php <?php
namespace litebans; namespace litebans;
use PDO; use PDO;
require_once './includes/page.php'; require_once './includes/page.php';
$page = new Page("mutes"); $page = new Page("mutes");
$page->print_title(); $page->print_title();
$headers = array("Name", "Muted By", "Reason", "Muted On", "Muted Until"); $headers = array("Name", "Muted By", "Reason", "Muted On", "Muted Until");
?>
<div class="container"> $page->print_page_header();
<?php
$page->print_page_header(); $page->table_begin();
?> $page->table_print_headers($headers);
<div class="row" style="margin-bottom:60px;">
<div class="col-lg-12"> $result = $page->run_query();
<?php while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$page->table_begin();
$page->table_print_headers($headers);
$result = $page->run_query();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$player_name = $page->get_name($row['uuid']); $player_name = $page->get_name($row['uuid']);
if ($player_name === null) continue; if ($player_name === null) continue;
@ -28,11 +25,8 @@ $headers = array("Name", "Muted By", "Reason", "Muted On", "Muted Until");
'Muted On' => $page->millis_to_date($row['time']), 'Muted On' => $page->millis_to_date($row['time']),
'Muted Until' => $page->expiry($row), 'Muted Until' => $page->expiry($row),
)); ));
} }
$page->table_end(); $page->table_end();
$page->print_pager(); $page->print_pager();
?>
</div> $page->print_footer();
</div>
<?php $page->print_footer(); ?>
</div>

View File

@ -1,23 +1,20 @@
<?php <?php
namespace litebans; namespace litebans;
use PDO; use PDO;
require_once './includes/page.php'; require_once './includes/page.php';
$page = new Page("warnings"); $page = new Page("warnings");
$page->print_title(); $page->print_title();
$headers = array("Name", "Warned By", "Reason", "Warned Until", "Received Warning?"); $headers = array("Name", "Warned By", "Reason", "Warned Until", "Received Warning?");
?>
<div class="container"> $page->print_page_header();
<?php
$page->print_page_header(); $page->table_begin();
?> $page->table_print_headers($headers);
<div class="row" style="margin-bottom:60px;">
<div class="col-lg-12"> $result = $page->run_query();
<?php while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$page->table_begin();
$page->table_print_headers($headers);
$result = $page->run_query();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$player_name = $page->get_name($row['uuid']); $player_name = $page->get_name($row['uuid']);
if ($player_name === null) continue; if ($player_name === null) continue;
@ -28,11 +25,8 @@ $headers = array("Name", "Warned By", "Reason", "Warned Until", "Received Warnin
'Warned Until' => $page->expiry($row), 'Warned Until' => $page->expiry($row),
'Received Warning?' => $row['warned'] ? "Yes" : "No", 'Received Warning?' => $row['warned'] ? "Yes" : "No",
)); ));
} }
$page->table_end(); $page->table_end();
$page->print_pager(); $page->print_pager();
?>
</div> $page->print_footer();
</div>
<?php $page->print_footer(); ?>
</div>