simpub/index.php

128 lines
3.6 KiB
PHP
Raw Permalink Normal View History

2017-01-27 20:29:27 +01:00
<?php
$CMS_ACTIVE = true;
require_once "shared.php";
$pageTitle = "";
if (isset($_GET['p'])) {
$page = $_GET['p'];
preg_match("/^[a-z0-9\-]*$/", $page, $matches); // SECURITY: Only lowercase a-z + numbers + -
if (!$matches)
$page=HOME_PAGE;
$page=substr($page, 0, 16); // SECURITY: Max 16 chars
2017-01-27 20:29:27 +01:00
}
else {
$page=HOME_PAGE;
}
$pageUrl="p/$page.php";
if (!file_exists($pageUrl)) {
$pageUrl="p/404.php";
$pageTitle = "Error 404";
}
$optin = "";
2018-06-03 18:46:24 +02:00
if (isset($_POST['optin-once'])) {
$_COOKIE['opt-in'] = $_POST['optin-once'];
}
if (isset($_COOKIE['opt-in'])) {
$opt = $_COOKIE['opt-in'];
if (strlen($opt) <= 8) {
preg_match("/^[a-z0-9\-]*$/", $opt, $matches);
if ($matches) {
if (isset($_GET['optout'])) {
$opt = str_replace($_GET['optout'], '', $opt);
}
$optin = $opt;
}
}
}
if (isset($_GET['optin'])) {
if ((strlen($_GET['optin']) == 1) && !opted_in($_GET['optin'])) {
$optin .= $_GET['optin'];
}
}
if (isset($_GET['optout']) || isset($_GET['optin'])) {
setcookie('opt-in', $optin, strtotime("+1 year"));
}
// --- $page, $pageUrl and $optin are now SAFE TO USE
2017-01-27 20:29:27 +01:00
$htmlHead = "";
function mkMenu() {
global $page;
global $menuItems;
global $pageTitle;
foreach ($menuItems as $item) {
$menCls = "";
$titleStyle = "";
if (($_SERVER['REQUEST_URI'] == $item['link']) || (strstr($item['highlight'], $page))) {
$menCls = "class=\"selectedMenu\"";
$pageTitle = $item['label'];
}
echo '<li ' . $menCls . '><a href="' . $item['link'] . '">&nbsp;&nbsp;' . $item['label'] . '&nbsp;&nbsp;</a></li> ';
// The &nbsp; in the line above can be removed when using a fixed width style in the .css file.
}
}
if ($page==HOME_PAGE && !strstr($_SERVER['REQUEST_URI'], "&")) // TODO: The second clause is pretty cheap...
$homesel = 'class="selectedMenu"';
else
$homesel = "";
ob_start(function($output) {
global $pageTitle;
global $htmlHead;
2018-05-30 15:06:34 +02:00
$output = '<!DOCTYPE html>
2017-01-27 20:29:27 +01:00
<html>
2018-05-30 15:06:34 +02:00
<head>
<title>' . $pageTitle . ($pageTitle == "" ? "" : " - ") . PAGE_NAME . '</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=700px, initial-scale=.5"><!-- or width=device-width -->
' . $htmlHead . '
<link rel="stylesheet" type="text/css" href="/style.css" />
<link rel="stylesheet" type="text/css" href="/userstyle.css" />
</head>' . $output;
2017-01-27 20:29:27 +01:00
return $output;
});
?>
<!--
Hello random person reading the source code! Nice to meet you!
2021-11-02 21:24:08 +01:00
This page has been generated by [Simpub CMS], which is open source software.
You can find it here: https://git.notsyncing.net/web/simpub
2017-01-27 20:29:27 +01:00
-->
2018-05-30 15:06:34 +02:00
<body>
2017-01-27 20:29:27 +01:00
<nav>
<div id="navContainer">
<ul class="pagetitle"><li <?php echo $homesel; ?> style="float: left;"><a class="pagetitle" href="/"><?php echo PAGE_NAME; ?></a></li></ul>
2018-05-30 15:06:34 +02:00
<ul>
2017-01-27 20:29:27 +01:00
<?php mkMenu(); ?>
2018-05-30 15:06:34 +02:00
<?php if (RSS_ENABLED) { ?>
2017-05-27 11:45:08 +02:00
<li style="float: right; margin: 10px;">
<a href="/rss.php" title="RSS Feed" style="margin: 0px; padding: 0px; border: none;"><img src="/img/rss.svg" style="width:32px; height:32px;"></a>
2017-05-27 11:45:08 +02:00
</li>
<?php } ?>
</ul>
2017-01-27 20:29:27 +01:00
</div>
</nav>
2018-05-30 15:06:34 +02:00
<div id="contentContainer">
2017-01-27 20:29:27 +01:00
<content>
<div id="content">
<?php
require $pageUrl;
?>
</div>
</content>
2020-05-22 12:38:57 +02:00
</div>
<div id="footer">
Copyright <?php echo PAGE_AUTHOR; ?><!-- and <a href="/?p=extcontent">others</a>--> | <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/us/"><img style="position:relative;top:4px;opacity:0.75;" src="/img/cc-byncsa.png"></a> | <a href="/?p=contact#privacy">Privacy Policy</a> | <?php echo date("Y"); ?>
2018-05-30 15:06:34 +02:00
</div>
</body>
2017-01-27 20:29:27 +01:00
</html>
<?php
ob_end_flush();
?>