128 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			128 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?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
 | |
| 	}
 | |
| 	else {
 | |
| 		$page=HOME_PAGE;
 | |
| 	}
 | |
| 	$pageUrl="p/$page.php";
 | |
| 	if (!file_exists($pageUrl)) {
 | |
| 		$pageUrl="p/404.php";
 | |
| 		$pageTitle = "Error 404";
 | |
| 	}
 | |
| 
 | |
| 	$optin = "";
 | |
| 	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
 | |
| 	
 | |
| 	$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'] . '">  ' . $item['label'] . '  </a></li> ';
 | |
| 			// The   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;
 | |
| 		$output = '<!DOCTYPE html>
 | |
| <html>
 | |
| 	<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;
 | |
| 		return $output;
 | |
| 	});
 | |
| ?>
 | |
| 
 | |
| 	<!--
 | |
| 		Hello random person reading the source code! Nice to meet you!
 | |
| 		This page has been generated by [Simpub CMS] which is open source software.
 | |
| 		You can find it here: https://git.notsyncing.net:8080/web/simpub
 | |
| 	-->
 | |
| 	<body>
 | |
| 		<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>
 | |
| 					<ul>
 | |
| 					<?php mkMenu(); ?>
 | |
| 						<?php if (RSS_ENABLED) { ?>
 | |
| 						<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>
 | |
| 						</li>
 | |
| 					<?php } ?>
 | |
| 				</ul>
 | |
| 			</div>
 | |
| 		</nav>
 | |
| 		<div id="contentContainer">
 | |
| 			<content>
 | |
| 				<div id="content">
 | |
| 	<?php
 | |
| 		require $pageUrl;
 | |
| 	?>
 | |
| 				</div>
 | |
| 			</content>
 | |
| 		</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"); ?>
 | |
| 		</div>
 | |
| 	</body>
 | |
| </html>
 | |
| 
 | |
| <?php
 | |
| 	ob_end_flush();
 | |
| ?>	
 |