"skús to commitnúť, počkaj toto ../ dám ešte preč aby to nevypadalo tak..."
This commit is contained in:
49
index.php
49
index.php
@@ -1,4 +1,16 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
session_start();
|
||||
require_once 'config.php';
|
||||
|
||||
@@ -7,7 +19,19 @@ $paths_to_check[] = "pages/global";
|
||||
|
||||
|
||||
$page = basename($_SERVER['QUERY_STRING']);
|
||||
$nav = file_get_contents("$template_dir/navigation.html");
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(empty($page)){
|
||||
$page = 'index';
|
||||
@@ -20,12 +44,6 @@ if (isset($_SESSION['user_id'])) {
|
||||
}
|
||||
|
||||
$paths_to_check[] = "pages/user";
|
||||
|
||||
// Fetch user details
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$query = "SELECT * FROM users WHERE id = $user_id";
|
||||
$result = mysqli_query($mysqli, $query);
|
||||
$user = mysqli_fetch_assoc($result);
|
||||
}
|
||||
|
||||
$page_file = "$template_dir/404.html";
|
||||
@@ -41,7 +59,22 @@ ob_start();
|
||||
include $page_file;
|
||||
$page_data = ob_get_clean();
|
||||
|
||||
$page_data = str_replace("__NAV_TEMPLATE__", $nav, $page_data);
|
||||
$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);
|
||||
|
||||
echo $page_data;
|
||||
?>
|
||||
|
Reference in New Issue
Block a user