Joshua Ramon Enslin
a49746ab10
Added editing pages for footer, banner, aside. Added page overview. Added public page. Added settings page. Added generator for embed pseudocodes.
155 lines
3.5 KiB
PHP
155 lines
3.5 KiB
PHP
<?PHP
|
|
/**
|
|
* File for collecting functions building common HTML parts of the public page
|
|
*
|
|
* @file
|
|
*
|
|
* @author Joshua Ramon Enslin <joshua@jrenslin.de>
|
|
*/
|
|
|
|
/**
|
|
* Prints the head element of an HTML page in the public frontend.
|
|
*
|
|
* @param string $page ID of the current page.
|
|
* @param string $title Title of the page.
|
|
* @param string $icon The icon of the website.
|
|
*
|
|
* @return string
|
|
*/
|
|
function printPublicHead(string $page = "home", string $title = "Home", string $icon = ""):string {
|
|
|
|
$output = '<!DOCTYPE html>
|
|
<html lang="en" id="' . $page . '">
|
|
<head>
|
|
|
|
<!-- Content Security policies -->
|
|
<meta http-equiv="Content-Security-Policy" content="default-src \'none\'; script-src \'self\'; connect-src \'self\'; img-src \'self\'; style-src \'self\' \'unsafe-inline\'; font-src \'self\';" />
|
|
|
|
<title>' . $title . '</title>
|
|
<link rel="stylesheet" type="text/css" href="themes/default/default.css">
|
|
<meta http-equiv="content-type" content="text/html;charset=utf-8">';
|
|
|
|
if ($icon) {
|
|
$output .= '
|
|
<link rel="shortcut icon" sizes="16x16 32x32" href="' . $icon . '" />
|
|
';
|
|
}
|
|
|
|
$output .= '
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
|
|
<script type="text/javascript" src="./js/main.js"></script>
|
|
|
|
</head>
|
|
<body>
|
|
';
|
|
|
|
if (isset($_SESSION['editHistory'])) {
|
|
$output .= "<p class='editLine ".$_SESSION['editHistory'][0]."'>".$_SESSION['editHistory'][1]."</p>";
|
|
unset($_SESSION['editHistory']);
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
/**
|
|
* Prints the header element of an HTML page.
|
|
*
|
|
* @param string $title Title of the page.
|
|
*
|
|
* @return string
|
|
*/
|
|
function printPublicHeader(string $title = "Home"):string {
|
|
|
|
$output = '
|
|
|
|
<header id="mainHeader">
|
|
|
|
<h1>' . $title . '</h1>
|
|
|
|
</header>
|
|
';
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
/**
|
|
* Prints the finishing elements of public HTML pages.
|
|
*
|
|
* @return string
|
|
*/
|
|
function printPublicEnd():string {
|
|
|
|
$output = '
|
|
</body>
|
|
</html>';
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
/**
|
|
* This function prints a file (the sidebar, the banner, or the footer) if it is not empty.
|
|
*
|
|
* @param string $file File name. Must be either aside, banner or footer.
|
|
* @param string $elem Encapsulating HTML element.
|
|
*
|
|
* @return string
|
|
*/
|
|
function printStaticPagePart(string $file, string $elem):string {
|
|
|
|
if (!in_array($file, ['footer', 'aside', 'banner'])) {
|
|
echo "Trying to access disallowed file.";
|
|
}
|
|
|
|
if (!file_exists(__DIR__ . "/../data/$file.htm") || !filesize(__DIR__ . "/../data/$file.htm") > 5) return "";
|
|
$content = file_get_contents(__DIR__ . "/../data/$file.htm");
|
|
|
|
$output = "
|
|
<$elem>
|
|
$content
|
|
</$elem>";
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
/**
|
|
* This function prints an error page.
|
|
*
|
|
* @param string $content The error message.
|
|
*
|
|
* @return string
|
|
*/
|
|
function printErrorPage(string $content):string {
|
|
|
|
$output = '
|
|
<!DOCTYPE html>
|
|
<html id="errorPage">
|
|
<head>
|
|
<meta http-equiv="Content-Security-Policy" content="default-src \'none\'; script-src \'none\'; connect-src \'none\'; style-src \'self\'; font-src \'self\';" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
|
<meta charset="UTF-8" />
|
|
<title>' . $content . '</title>
|
|
<link rel="stylesheet" type="text/css" href="themes/default/default.css" />
|
|
</head>
|
|
<body>
|
|
|
|
<div>
|
|
' . $content . '
|
|
<div>
|
|
|
|
</body>
|
|
</html>
|
|
|
|
';
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
?>
|