<?php
$pages = ["me", "report", "about", "multipage"];
$dir  = __DIR__ . "/";
$file = null;
$page = isset($_GET["page"]) ? $_GET["page"] : "me";
$title = "me";

if (in_array($page, $pages, true)) {
    $file = "$page.php";
    $title = $page;
} else {
    $file = "404.php";
    $title = "404";
}
?>
<!DOCTYPE html>
<html lang="sv">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="css/style.css"/>
        <link rel='shortcut icon' href='img/favicon.ico'/>
        <title><?= "Rasmus - " . $title ?></title>
    </head>
    <body>
        <main>
            <header class="site-header">
                <img src="img/logo.jpg" alt="logo" />
                <span class="site-title">Rasmus Steen</span>
                <span class="site-slogan">Potatisguden</span>
            </header>
            <hr>
            <nav class="navbar">
                <a class="<?= $page == "me" ? "selected" : ""; ?>" href="?page=me">Hem</a>
                <a class="<?= $page == "report" ? "selected" : ""; ?>" href="?page=report">Redovisning</a>
                <a class="<?= $page == "multipage" ? "selected" : ""; ?>" href="?page=multipage">Multipage</a>
                <a class="<?= $page == "about" ? "selected" : ""; ?>" href="?page=about">Om</a>
            </nav>
            <div>
                <?php include("$file")?>
            </div>
            <footer class="site-footer">
                <?php
                    $numFiles = count(get_included_files());
                    $memoryUsed = memory_get_peak_usage(true);
                    $loadTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'];
                ?>
                <hr>
                <div class="links">
                    Validatorer:
                    <a href="http://validator.w3.org/check/referer">HTML5</a>
                    <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>
                    <a href="http://validator.w3.org/unicorn/check?ucn_uri=referer&amp;ucn_task=conformance">Unicorn</a><br />
                    Specificationer:
                    <a href="http://www.w3.org/2009/cheatsheet">Cheatsheet</a>
                    <a href="http://www.w3.org/TR/html5">HTML5</a>
                    <a href="http://www.w3.org/TR/html4">HTML4</a>
                    <a href="http://www.w3.org/Style/CSS/current-work">CSS3</a>
                    <a href="http://dev.w3.org/csswg/css2">CSS2.2</a>
                    <a href="http://www.w3.org/TR/CSS21">CSS2.1</a><br />
                </div>
                <div class="performance">
                    <br />
                    Loadtime: <?= round($loadTime * 1000, 3) ?> ms. Files: <?= $numFiles ?>. Memory: <?= round($memoryUsed / pow(10, 6), 1)?> MiB.<br />
                </div>
            </footer>
        </main>
    </body>
</html>
