watch.twip-network.org/index.php

81 lines
1.9 KiB
PHP
Raw Normal View History

2024-01-20 16:04:27 +01:00
<?php
function include_ob($file){
ob_start();
include $file;
return ob_get_clean();
}
function sanitize_template_strings($indata){
$sanit_pattern = '/<template.*>/is';
return preg_replace($sanit_pattern, '', $indata);
}
2024-01-20 16:04:27 +01:00
session_start();
require_once 'config.php';
2024-01-20 19:10:12 +01:00
$paths_to_check = array();
$paths_to_check[] = "pages/global";
2024-01-20 19:10:12 +01:00
$page = basename($_SERVER['QUERY_STRING']);
$nav = include_ob("$template_dir/navigation.html");
$page_regex = '/<!--PAGENAME=(.*?)-->/';
if(preg_match($page_regex, $htmlWithComments, $matches)){
$page_name = $matches[1];
}
else{
$page_name = ucfirst($page);
}
2024-01-20 19:04:39 +01:00
2024-01-20 19:10:12 +01:00
if(empty($page)){
$page = 'index';
}
2024-01-20 19:04:39 +01:00
2024-01-20 19:10:12 +01:00
// Check if user is logged in
if (isset($_SESSION['user_id'])) {
2024-01-20 19:04:39 +01:00
if ($user['isAdmin'] == 1) {
$paths_to_check[] = "pages/admin";
}
$paths_to_check[] = "pages/user";
2024-01-20 19:10:12 +01:00
}
2024-01-20 19:10:12 +01:00
$page_file = "$template_dir/404.html";
2024-01-20 19:10:12 +01:00
foreach($paths_to_check as $page_dir){
$page_file_tmp = "$page_dir/$page.html";
if(file_exists($page_file_tmp)){
$page_file = $page_file_tmp;
break;
2024-01-20 18:00:30 +01:00
}
2024-01-20 19:10:12 +01:00
}
ob_start();
include $page_file;
$page_data = ob_get_clean();
$page_data = preg_replace($page_regex, '', $page_data);
$output = file_get_contents("$template_dir/skeleton.html");
$output = str_replace('<template name="navigation">', $nav, $output);
$output = str_replace('<template name="page content">', $page_data, $output);
if (isset($_SESSION['user_id'])) {
$hash = md5(strtolower(trim($_SESSION['user_email'])));
$gravatarUrl = "https://www.gravatar.com/avatar/$hash?s=100";
$gravatarTag = "<img src='$gravatarUrl' alt='Gravatar Profile Picture'>";
$page_data = str_replace('<template name="gravatar image">', $gravatarTag, $page_data);
$page_data = str_replace('<template name="username">', $_SESSION['user_username'], $page_data);
}
$output = str_replace('<template name="page name">', $page_name, $output);
2024-01-20 19:55:14 +01:00
echo $output;
2024-01-20 16:04:27 +01:00
?>