diff --git a/public/index.php b/public/index.php index 63fed66..8054d95 100644 --- a/public/index.php +++ b/public/index.php @@ -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); diff --git a/src/actions/users.php b/src/actions/users.php index bf68201..d52e074 100644 --- a/src/actions/users.php +++ b/src/actions/users.php @@ -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 = ""; - display(gettemplate("lostpassword"), "Lost Password", false, false, false); - + display(gettemplate("lostpassword"), "Lost Password", true, false, false); } function changepassword() diff --git a/src/lib.php b/src/lib.php index 2416257..0bfa07b 100644 --- a/src/lib.php +++ b/src/lib.php @@ -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; + if ($userrow !== false) { // user should be logged in + $topnav = << + + HTML; + } else { + $topnav = << + + + HTML; + } } else { - $topnav = << - - - 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 ? '
'.print_r(db()->log, true).'' : '' ]); - echo "\n" . $page; - exit; + exit; } function checkcookies() diff --git a/templates/leftnav.php b/templates/leftnav.php index ab6d762..e89237e 100644 --- a/templates/leftnav.php +++ b/templates/leftnav.php @@ -1,10 +1,8 @@ - - Currently: {{currentaction}}