This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
89 lines (77 loc) · 2.8 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
// Log IP address, page URL, username (if logged in), and timestamp
$requestLog = [
'ip' => $_SERVER['REMOTE_ADDR'],
'url' => $_SERVER['REQUEST_URI'],
'username' => isset($_SESSION['username']) ? $_SESSION['username'] : null,
'timestamp' => date('Y-m-d H:i:s')
];
// Load existing request logs
$requestLogs = json_decode(file_get_contents('db/request_logs.json'), true);
// Add the new request log to the existing logs
$requestLogs[] = $requestLog;
// Save the updated request logs
file_put_contents('db/request_logs.json', json_encode($requestLogs));
?>
<?php
$configs = include('config.php');
session_start();
// Check if setup needs to be run
$userFile = json_decode(file_get_contents('db/login.json'), true);
$userFile[] = $userFile;
if ($userFile[0] == ""){
header("Location: setup/index.php");
}
// Check if the user is already logged in
if (isset($_SESSION['username'])) {
// Redirect to the user's dashboard
header('Location: dashboard.php');
exit;
}
$messages = json_decode(file_get_contents('db/messages.json'), true);
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $configs["sitename"] ?> - Home</title>
<link rel="stylesheet" href="css/<?php echo $configs["theme"] ?>">
</head>
<body>
<div class="header">
<div class="login">
<a href="login.php">Login</a> <a href="register.php">Register</a>
</div>
<h2><?php echo $configs["sitename"] ?></h2>
<div class="registerBanner">
<?php
$sitename = $configs["sitename"];
$msg = $configs["registerPrompts"];
$rand = rand(0, count($msg) - 1);
echo str_replace("[sitename]", $sitename, $msg[$rand]);
?>
<a href="register.php">Register now!</a>
</div>
</div>
<div class="wrapper">
<!-- Bad solution, but I'm way too tired to fix it, should realy do checks before we actually try to use $messages. -->
<?php if ($messages !== null) foreach (array_reverse($messages) as $postId => $post):?>
<div>
<p>@<?php if ($messages !== null) {echo $post['author'];} ?></p>
<p><?php echo $post['content']; ?></p>
<p>Likes: <?php echo isset($post['likes']) ? count($post['likes']) : 0; ?></p>
</div>
<div class="replies">
<?php if (isset($post['replies'])): ?>
<?php foreach ($post['replies'] as $replyId => $reply): ?>
<div>
<p>@<?php echo $reply['author']; ?></p>
<p><?php echo $reply['content']; ?></p>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<hr>
<?php endforeach; ?>
</div>
</body>
</html>