function templateify() { global $CANCEL_TEMPLATEIFY; //In case, for example, you want to send an attachment. if (@$CANCEL_TEMPLATEIFY) { return; } global $pagesTitles, $hiddenPagesTitles, $adminPagesTitles; $pagename = basename($_SERVER['REQUEST_URI'], '.php'); //--TODO-- needs to be full relative paths - e.g. "classes/about.php" gets About. //likewise, links in navbar must be absolute or relative to ROOT_PATH if (!val('f', $pagename)) { $pagename = '404'; } //Make this consistent with the _actual_ 404s with htaccess ("foafi/dshiafos.php") if ($pagename == '' || $pagename == 'doeqs_new') { $pagename = 'index'; } //--todo-- hax if (array_key_exists($pagename, $pagesTitles)) { $title = $pagesTitles[$pagename]; $content = ob_get_clean(); } elseif (array_key_exists($pagename, $hiddenPagesTitles)) { $title = $hiddenPagesTitles[$pagename]; $content = ob_get_clean(); } elseif (array_key_exists($pagename, $adminPagesTitles) && userAccess('a')) { $title = $adminPagesTitles[$pagename] . ' <i>[Admin-Only Page]</i>'; $content = ob_get_clean(); } else { $title = 'Error 404 Not Found'; $content = get404(); ob_clean(); } $content = fetch_alerts_html() . $content; $nav = '['; foreach ($pagesTitles as $p => $t) { $nav .= " · <a href='" . ROOT_PATH . "{$p}.php'>{$t}</a>"; } if (userAccess('a')) { $nav .= ' — '; foreach ($adminPagesTitles as $p => $t) { $nav .= "<a href='" . ROOT_PATH . "{$p}.php'>{$t}</a>"; } } $nav .= ' · ]'; if (userAccess('u')) { $nav .= ' <form action="login.php" method="POST" style="display:inline-block;"><input type="hidden" name="ver" value="<?=csrfCode();?>"/><input type="submit" name="logout" value="Log Out" /></form>'; } //tried OB to get file contents which died for some reason... $template = file_get_contents(__DIR__ . '/html_template.html'); //--todo-- don't access files outside of protected object global $VERSION_NUMBER, $TIME_START; echo str_replace(array('%title%', '%content%', '%nav%', '%version%', '%loadtime%', '%root%'), array($title, $content, $nav, $VERSION_NUMBER, substr(1000 * (microtime(true) - $TIME_START), 0, 6), ROOT_PATH), $template); ob_flush(); flush(); }
function templateify() { global $CANCEL_TEMPLATEIFY; //In case, for example, you want to send an attachment. if (@$CANCEL_TEMPLATEIFY) { return; } global $page_title, $header_title, $header_class, $jquery_function, $LOCAL_BORDER_COLOR, $popup_code, $more_head_stuff; //Title bar: "Page_Name | LHS Math Club" if (!isset($header_title)) { $header_title = 'LHS Math Club'; } //Also in main white-on-black header "LHS Math Club" if (!isset($page_title)) { $page_title = basename($_SERVER['REQUEST_URI'], '.php'); } global $logged_in_header; if (isset($_SESSION['user_id'])) { $logged_in_header = '<div id="user"><span id="username">' . $_SESSION['user_name'] . '</span><span id="bar"> | </span><a href="' . URL::root() . '/Account/Signout">Sign Out</a></div>'; } if (isset($meta_refresh)) { $more_head_stuff .= '<meta http-equiv="refresh" content="' . $meta_refresh . '" />'; } $alerts_html = fetch_alerts_html(); $content = ob_get_clean(); //Very hacky solution to inserting alerts after h1 titles, but it works. if (strpos($content, '</h1>') !== false) { $content = substr_replace($content, $alerts_html, strpos("\n" . $content, '</h1>') + strlen('</h1>'), 0); } else { $content = $alerts_html . $content; } start_templateify(); //:( ?> <title><?php echo $page_title; ?> | <?php echo $header_title; ?> </title> <?php //Custom stuff - deprecated ?> <script type="text/javascript"><?php echo $jquery_function; ?> </script> <?php echo $more_head_stuff; ?> </head> <body> <div id="header" class="<?php echo $header_class; ?> " style="border-bottom: 4px solid <?php echo $LOCAL_BORDER_COLOR; ?> "> <a href="<?php echo URL::root(); ?> /Home" id="title"><?php echo $header_title; ?> </a><?php echo $logged_in_header; ?> </div> <div id="content"> <?php echo $content; ?> </div> <div id="linkbar"> <?php echo '<div class="linkgroup">' . navbar_html() . '</div>'; ?> </div> </body> </html> <?php if (ob_get_level() <= 0) { trigger_error("ob_get_level is " . ob_get_level() . " [\n" . var_export(debug_backtrace(), true) . "\n]", E_USER_ERROR); } else { ob_flush(); } flush(); //die();//DO NOT. Will cause other shutdown functions to not work. //--todo--For some reason it just keeps on "Waiting for localhost..." even though the script is done... }