pics/templates/MainTemplate.php

117 lines
3.1 KiB
PHP
Raw Permalink Normal View History

<?php
/*****************************************************************************
* MainTemplate.php
* Defines the key template MainTemplate.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class MainTemplate extends Template
{
private $title = '';
private $classes = [];
private $area;
private $css = '';
private $header_html = '';
private $canonical_url = '';
public function __construct($title = '')
{
$this->title = $title;
}
public function html_main()
{
echo '<!DOCTYPE html>
<html lang="en">
<head>
<title>', $this->title, '</title>';
if (!empty($this->canonical_url))
echo '
<link rel="canonical" href="', $this->canonical_url, '">';
echo '
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
echo '
<link rel="stylesheet" href="', BASEURL, '/vendor/twbs/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="', BASEURL, '/vendor/twbs/bootstrap-icons/font/bootstrap-icons.css">
<link type="text/css" rel="stylesheet" href="', BASEURL, '/css/default.css?v2">
2023-11-11 11:37:26 +01:00
<script type="text/javascript" src="', BASEURL, '/js/main.js"></script>
<script type="text/javascript" src="', BASEURL, '/js/color-modes.js"></script>'
, $this->header_html, '
</head>
<body', !empty($this->classes) ? ' class="' . implode(' ', $this->classes) . '"' : '', '>
<header>';
$bar = new MainNavBar();
$bar->html_main();
echo '
</header>
<div id="wrapper">';
foreach ($this->_subtemplates as $template)
$template->html_main();
echo '
<footer>';
if (Registry::has('user') && Registry::get('user')->isAdmin())
{
if (Registry::has('start'))
echo '
<span class="creation-time">Page creation time: ', sprintf('%1.4f', microtime(true) - Registry::get('start')), ' seconds</span>';
if (Registry::has('db'))
echo '<br>
<span class="query-count">Database interaction: ', Registry::get('db')->getQueryCount(), ' queries</span>';
}
else
echo '
<span class="vanity">Powered by <a href="https://aaronweb.net/projects/kabuki/" target="_blank">Kabuki CMS</a></span>';
echo '
</footer>
</div>';
if (Registry::has('db') && defined("DB_LOG_QUERIES") && DB_LOG_QUERIES)
foreach (Registry::get('db')->getLoggedQueries() as $query)
echo '<pre>', strtr($query, "\t", " "), '</pre>';
echo '
<script type="text/javascript" src="', BASEURL, '/vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>';
}
public function appendHeaderHtml($html)
{
$this->header_html .= "\n\t\t" . $html;
}
public function appendStylesheet($uri)
{
$this->appendHeaderHtml('<link text="text/css" rel="stylesheet" href="'. $uri . '">');
}
public function setCanonicalUrl($url)
{
$this->canonical_url = $url;
}
public function addClass($class)
{
if (!in_array($class, $this->classes))
$this->classes[] = $class;
}
public function removeClass($class)
{
if ($key = array_search($class, $this->classes) !== false)
unset($this->classes[$key]);
}
}