Primary and side navs now use the new renderer

This commit is contained in:
Sky Johnson 2024-12-14 13:14:41 -06:00
parent bf0b05064a
commit 3152cca51f
7 changed files with 90 additions and 113 deletions

View File

@ -138,14 +138,9 @@ function doexplore()
*/
function show_character_info(int $id = 0): void
{
global $controlrow;
if ($id === 0) {
global $userrow;
} else {
$userrow = get_user_by_id($id);
}
global $controlrow, $userrow;
$userrow = ($id === 0) ? $userrow : get_user_by_id($id);
if ($userrow === false) exit('Failed to show info for user ID '.$id);
$levelrow = db()->query("SELECT `{$userrow["charclass"]}_exp` FROM levels WHERE id=? LIMIT 1;", [$userrow['level'] + 1])->fetchArray(SQLITE3_ASSOC);

View File

@ -49,9 +49,7 @@ function login()
redirect('/');
}
$page = gettemplate("login");
$title = "Log In";
display($page, $title, false, false, false, false);
display(render('login'), 'Log In', true, false, false);
}
/**
@ -111,7 +109,7 @@ function register()
$page = render('register', ['controlrow' => $controlrow]);
}
display($page, "Register", false, false, false);
display($page, 'Register', true, false, false);
}
function verify()
@ -152,9 +150,7 @@ function lostpassword()
}
}
$topnav = "<a href=\"/login\"><img src=\"/img/button_login.gif\" alt=\"Log In\" border=\"0\" /></a><a href=\"users.php?do=register\"><img src=\"/img/button_register.gif\" alt=\"Register\" border=\"0\" /></a><a href=\"/help\"><img src=\"/img/button_help.gif\" alt=\"Help\" border=\"0\" /></a>";
display(gettemplate("lostpassword"), "Lost Password", false, false, false);
display(gettemplate("lostpassword"), "Lost Password", true, false, false);
}
function changepassword()

View File

@ -119,28 +119,28 @@ function admindisplay($content, $title)
exit;
}
function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true, $badstart=false) { // Finalize page and output to browser.
/**
* Finalize page and output to browser.
*/
function display($content, $title, bool $topnav = true, bool $leftnav = true, bool $rightnav = true): void
{
global $userrow, $controlrow;
if (!isset($controlrow)) {
$query = db()->query('SELECT * FROM control WHERE id=1 LIMIT 1;');
$controlrow = $query->fetchArray(SQLITE3_ASSOC);
}
if ($badstart == false) { global $starttime; } else { $starttime = $badstart; }
if ($rightnav == true) { $rightnav = gettemplate("rightnav"); } else { $rightnav = ""; }
if ($leftnav == true) { $leftnav = gettemplate("leftnav"); } else { $leftnav = ""; }
if ($topnav == true) {
$topnav = <<<HTML
<a href='/logout'><img src='/img/button_logout.gif' alt='Log Out' title='Log Out'></a>
<a href='/help'><img src='/img/button_help.gif' alt='Help' title='Help'></a>
HTML;
if ($userrow !== false) { // user should be logged in
$topnav = <<<HTML
<a href='/logout'><img src='/img/button_logout.gif' alt='Log Out' title='Log Out'></a>
<a href='/help'><img src='/img/button_help.gif' alt='Help' title='Help'></a>
HTML;
} else {
$topnav = <<<HTML
<a href='/login'><img src='/img/button_login.gif' alt='Log In' title='Log In'></a>
<a href='/register'><img src='/img/button_register.gif' alt='Register' title='Register'></a>
<a href='/help'><img src='/img/button_help.gif' alt='Help' title='Help'></a>
HTML;
}
} else {
$topnav = <<<HTML
<a href='/login'><img src='/img/button_login.gif' alt='Log In' title='Log In'></a>
<a href='/register'><img src='/img/button_register.gif' alt='Register' title='Register'></a>
<a href='/help'><img src='/img/button_help.gif' alt='Help' title='Help'></a>
HTML;
$topnav = '';
}
if (isset($userrow) && $userrow !== false) {
@ -226,12 +226,12 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true,
$userrow = [];
}
$page = parsetemplate(gettemplate("primary"), [
echo render('primary', [
"dkgamename" => $controlrow["gamename"],
"title" => $title,
"content" => $content,
"rightnav" => parsetemplate($rightnav, $userrow),
"leftnav" => parsetemplate($leftnav, $userrow),
'rightnav' => $rightnav ? render('rightnav', ['user' => $userrow]) : '',
"leftnav" => $leftnav ? render('leftnav', ['user' => $userrow]) : '',
"topnav" => $topnav,
"totaltime" => round(getmicrotime() - START, 4),
"numqueries" => db()->count,
@ -240,8 +240,7 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true,
"querylog" => DEBUG ? '<pre>'.print_r(db()->log, true).'</pre>' : ''
]);
echo "<html>\n" . $page;
exit;
exit;
}
function checkcookies()

View File

@ -1,10 +1,8 @@
<?php
$template = <<<HTML
<section>
<div class="title"><img src="/img/button_location.gif" alt="Location" title="Location"></div>
Currently: {{currentaction}}<br>
Latitude: {{latitude}}<br>
Longitude: {{longitude}}<br>
Currently: <?= $user['currentaction'] ?><br>
Latitude: <?= $user['latitude'] ?><br>
Longitude: <?= $user['longitude'] ?><br>
<a href="javascript:openmappopup()">View Map</a><br>
<form action="/move" method="post" class="move-compass">
<button type="submit" name="direction" value="north" class="north">North</button>
@ -18,18 +16,17 @@ $template = <<<HTML
<section>
<div class="title"><img src="/img/button_towns.gif" alt="Towns" title="Towns"></div>
{{currenttown}}
<?= $user['currenttown'] ?>
Travel To:<br>
{{townslist}}
<?= $user['townslist'] ?>
</section>
<section>
<div class="title"><img src="/img/button_functions.gif" alt="Functions" title="Functions"></div>
<a href="/">Home</a><br>
{{forumslink}}
{{adminlink}}
<?= $user['forumslink'] ?>
<?= $user['adminlink'] ?>
<a href="/changepassword">Change Password</a><br>
<a href="/logout">Log Out</a><br>
<a href="/help">Help</a>
</section>
HTML;

View File

@ -1,35 +1,31 @@
<?php
$template = <<<HTML
<form action="/login" method="post">
<table width="75%">
<tr>
<td width="30%">Username:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>Remember me?</td>
<td>
<input type="hidden" name="remember" value="0">
<input type="checkbox" name="remember" value="1">
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Log In"></td>
</tr>
<tr>
<td colspan="2">
Checking the "Remember Me" option will store your login information in a cookie so you don't have
to enter it next time you get online.<br><br>Want to play? You gotta
<a href="users.php?do=register">register your own character.</a><br><br>You may also
<a href="users.php?do=changepassword">change your password</a>, or
<a href="users.php?do=lostpassword">request a new one</a> if you've lost yours.
</td>
</tr>
</table>
</form>
HTML;
<form action="/login" method="post">
<table width="75%">
<tr>
<td width="30%">Username:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>Remember me?</td>
<td>
<input type="hidden" name="remember" value="0">
<input type="checkbox" name="remember" value="1">
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Log In"></td>
</tr>
<tr>
<td colspan="2">
Checking the "Remember Me" option will store your login information in a cookie so you don't have
to enter it next time you get online.<br><br>Want to play? You gotta
<a href="users.php?do=register">register your own character.</a><br><br>You may also
<a href="users.php?do=changepassword">change your password</a>, or
<a href="users.php?do=lostpassword">request a new one</a> if you've lost yours.
</td>
</tr>
</table>
</form>

View File

@ -1,11 +1,9 @@
<?php
$template = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{title}}</title>
<title><?= $title ?></title>
<link rel="stylesheet" href="/css/dk.css">
<script>
@ -24,25 +22,24 @@ $template = <<<HTML
<body>
<div id="game-container">
<header>
<img id="logo" src="/img/logo.gif" alt="{{dkgamename}}" title="{{dkgamename}}">
<nav>{{topnav}}</nav>
<img id="logo" src="/img/logo.gif" alt="<?= $dkgamename ?>" title="<?= $dkgamename ?>">
<nav><?= $topnav ?></nav>
</header>
<main>
<section id="left">{{leftnav}}</section>
<section id="middle">{{content}}</section>
<section id="right">{{rightnav}}</section>
<section id="left"><?= $leftnav ?></section>
<section id="middle"><?= $content ?></section>
<section id="right"><?= $rightnav ?></section>
</main>
<footer>
<div>Powered by <a href="http://dragon.se7enet.com/dev.php" target="_new">Dragon Knight</a></div>
<div>Powered by <a href="/" target="_new">Dragon Knight</a></div>
<div>&copy; 2024 Sharkk</div>
<div>{{totaltime}} Seconds, {{numqueries}} Queries</div>
<div>Version {{version}} {{build}}</div>
<div><?= $totaltime ?> Seconds, <?= $numqueries ?> Queries</div>
<div>Version <?= $version ?> <?= $build ?></div>
</footer>
{{querylog}}
<?= $querylog ?>
</div>
</body>
</html>
HTML;

View File

@ -1,30 +1,27 @@
<?php
$template = <<<HTML
<section>
<div class="title"><img src="/img/button_character.gif" alt="Character" title="Character"></div>
<b>{{username}}</b><br>
Level: {{level}}<br>
Exp: {{experience}}<br>
Gold: {{gold}}<br>
HP: {{currenthp}}<br>
MP: {{currentmp}}<br>
TP: {{currenttp}}<br>
{{statbars}}<br>
<b><?= $user['username'] ?></b><br>
Level: <?= $user['level'] ?><br>
Exp: <?= $user['experience'] ?><br>
Gold: <?= $user['gold'] ?><br>
HP: <?= $user['currenthp'] ?><br>
MP: <?= $user['currentmp'] ?><br>
TP: <?= $user['currenttp'] ?><br>
<?= $user['statbars'] ?><br>
<a href="javascript:opencharpopup()">Extended Stats</a>
</section>
<section>
<div class="title"><img src="/img/button_inventory.gif" alt="Inventory" title="Inventory"></div>
<img src="/img/icon_weapon.gif" alt="Weapon" title="Weapon"> Weapon: {{weaponname}}<br>
<img src="/img/icon_armor.gif" alt="Armor" title="Armor"> Armor: {{armorname}}<br>
<img src="/img/icon_shield.gif" alt="Shield" title="Shield"> Shield: {{shieldname}}<br>
Slot 1: {{slot1name}}<br>
Slot 2: {{slot2name}}<br>
Slot 3: {{slot3name}}
<img src="/img/icon_weapon.gif" alt="Weapon" title="Weapon"> Weapon: <?= $user['weaponname'] ?><br>
<img src="/img/icon_armor.gif" alt="Armor" title="Armor"> Armor: <?= $user['armorname'] ?><br>
<img src="/img/icon_shield.gif" alt="Shield" title="Shield"> Shield: <?= $user['shieldname'] ?><br>
Slot 1: <?= $user['slot1name'] ?><br>
Slot 2: <?= $user['slot2name'] ?><br>
Slot 3: <?= $user['slot3name'] ?>
</section>
<section>
<div class="title"><img src="/img/button_fastspells.gif" alt="Fast Spells" title="Fast Spells"></div>
{{magiclist}}
<?= $user['magiclist'] ?>
</section>
HTML;