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,22 +1,20 @@
<?php
namespace litebans;
use PDO;
require_once './includes/page.php';
$page = new Page("bans");
$page->print_title();
$headers = array("Name", "Banned By", "Reason", "Banned On", "Banned Until");
?>
<div class="container">
<?php
$page->print_page_header();
$page->print_check_form();
?>
<div class="row" style="margin-bottom:60px;">
<div class="col-lg-12">
<?php
$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']);
@ -32,8 +30,5 @@ $headers = array("Name", "Banned By", "Reason", "Banned On", "Banned Until");
}
$page->table_end();
$page->print_pager();
?>
</div>
</div>
<?php $page->print_footer(); ?>
</div>
$page->print_footer();

View File

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

View File

@ -11,7 +11,7 @@ $settings = new Settings(false);
<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;"><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>
<?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->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();
$map = $info->basic_info($row, $player_name);
$permanent_val = $info->page->permanent[$type];
@ -161,12 +156,5 @@ if ($st->execute(array($id))) {
echo "<tr><td>$key</td><td>$val</td></tr>";
}
$page->table_end(false);
?>
</div>
</div>
<?php
$page->print_footer();
?>
</div>
<?php
}

View File

@ -1,21 +1,18 @@
<?php
namespace litebans;
use PDO;
require_once './includes/page.php';
$page = new Page("kicks");
$page->print_title();
$headers = array("Name", "Kicked By", "Reason", "Date");
?>
<div class="container">
<?php
$page->print_page_header();
?>
<div class="row" style="margin-bottom:60px;">
<div class="col-lg-12">
<?php
$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']);
@ -30,8 +27,5 @@ $headers = array("Name", "Kicked By", "Reason", "Date");
}
$page->table_end();
$page->print_pager();
?>
</div>
</div>
<?php $page->print_footer(); ?>
</div>
$page->print_footer();

View File

@ -1,21 +1,18 @@
<?php
namespace litebans;
use PDO;
require_once './includes/page.php';
$page = new Page("mutes");
$page->print_title();
$headers = array("Name", "Muted By", "Reason", "Muted On", "Muted Until");
?>
<div class="container">
<?php
$page->print_page_header();
?>
<div class="row" style="margin-bottom:60px;">
<div class="col-lg-12">
<?php
$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']);
@ -31,8 +28,5 @@ $headers = array("Name", "Muted By", "Reason", "Muted On", "Muted Until");
}
$page->table_end();
$page->print_pager();
?>
</div>
</div>
<?php $page->print_footer(); ?>
</div>
$page->print_footer();

View File

@ -1,21 +1,18 @@
<?php
namespace litebans;
use PDO;
require_once './includes/page.php';
$page = new Page("warnings");
$page->print_title();
$headers = array("Name", "Warned By", "Reason", "Warned Until", "Received Warning?");
?>
<div class="container">
<?php
$page->print_page_header();
?>
<div class="row" style="margin-bottom:60px;">
<div class="col-lg-12">
<?php
$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']);
@ -31,8 +28,5 @@ $headers = array("Name", "Warned By", "Reason", "Warned Until", "Received Warnin
}
$page->table_end();
$page->print_pager();
?>
</div>
</div>
<?php $page->print_footer(); ?>
</div>
$page->print_footer();