web-site-public-php/sys/site.php

122 lines
3.9 KiB
PHP

<?php
class Page {
function __construct($url, $title, $subpages, $icon) {
$this->url = $url;
$this->title = $title;
$this->subpages = $subpages;
$this->icon = $icon;
$this->outline = [];
}
static function this($title, $icon=NULL) {
$url = $_SERVER['PHP_SELF'];
$path_info = pathinfo($url);
if ($path_info['basename'] == "index.php") {
$url = $path_info['dirname'];
}
return new Page($url, $title, [], $icon);
}
}
class Site {
static $_sitemap = null;
static $sitename = "~keith's Web site";
static function sitemap() {
if (Site::$_sitemap != NULL) {
return Site::$_sitemap;
}
$sitemap = [
"/" => new Page("/", "Home", [], "folder_home"),
"/about_copyleft.php" => new Page("/about_copyleft.php", "Copyleft", [], NULL),
"/furryring.php" => new Page("/furryring.php", "Furryring", [], "network"),
"/anarchism" => new Page("/anarchism", "Anarchism", [
"gsa.php" => new Page("/anarchism/gsa.php", "Institutional Queerphobia in the GSA", [], "wordprocessing"),
// "horny.php" => new Page("/anarchism/horny.php", "Anarcho-hornyism", [], NULL),
], "folder_red"),
"/privacy" => new Page("/privacy", "Privacy", [
"apprank.php" => new Page("/privacy/apprank.php", "Privacy-focused software", [], NULL),
], "folder_grey"),
"/projects" => new Page("/projects", "Projects", [
"twitter-cw.php" => new Page("/projects/twitter-cw.php", "Better Twitter CWs", [], "www"),
"mc-log4j.php" => new Page("/projects/mc-log4j.php", "Minecraft Log4j patcher", [], "source_java"),
"emacs.php" => new Page("/projects/emacs.php", "Emacs stuff", [], NULL),
"gentoo-rpi4" => new Page("/projects/gentoo-rpi4", "Gentoo on Raspberry Pi 4", [], NULL),
"pride-flags" => new Page("/projects/pride-flags", "Pride Flags Mod", [], "source_java"),
"website.php" => new Page("/projects/website.php", "Web site", [], NULL),
], NULL),
"/videos" => new Page("/videos", "Videos", [
], "folder_video"),
"/mail.php" => new Page("/mail.php", "Anonymous mailbox", [], "message"),
];
Site::$_sitemap = $sitemap;
return $sitemap;
}
static function path_join($path_a, $path_b) {
return join('/', array(rtrim($path_a, '/'), ltrim($path_b, '/')));
}
// Add the internal document root if it's not there
static function intpath($path) {
if (substr($path, 0, strlen($_SERVER['DOCUMENT_ROOT'])) == $_SERVER['DOCUMENT_ROOT']) {
return $path;
}
return Site::path_join($_SERVER['DOCUMENT_ROOT'], $path);
}
}
class PageHead {
function __construct($page, $description=NULL, $custom_css=NULL, $extra=NULL, $refresh_post=true) {
?>
<head>
<meta charset="utf-8" />
<title><?=$page->title?> - <?=Site::$sitename?></title>
<link href="/assets/fonts/plex-serif.css" rel="stylesheet" type="text/css" />
<link href="/css/style_sass.css" rel="stylesheet" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="/assets/site_favicon.png" rel="shortcut icon" />
<!-- Open Graph stuff -->
<meta property="og:title" content="<?=$page->title?> - <?=Site::$sitename?>" />
<meta property="og:type" content="website" />
<meta property="og:url" content="<?=Site::path_join("https://keithhacks.cyou/",$page->url)?>" />
<meta property="og:image" content="https://keithhacks.cyou/assets/site_favicon_large.png" />
<?php
if ($description !== NULL) {
?>
<meta property="og:description" content="<?=$description?>" />
<?php
}
?>
<meta property="og:site_name" content="<?=Site::$sitename?>" />
<?php
if ($custom_css !== NULL) {
?>
<link href="<?=$custom_css?>" rel="stylesheet" type="text/css" />
<?php
}
if ($_SERVER['REQUEST_METHOD'] == "POST" && $refresh_post) {
$request_uri = $_SERVER['REQUEST_URI'];
echo "<meta http-equiv=\"refresh\" content=\"5; url=$request_uri\" />";
}
if ($extra !== NULL) {
echo $extra;
}
?>
</head>
<?php
}
}
?>