-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.php
More file actions
156 lines (152 loc) · 8.28 KB
/
post.php
File metadata and controls
156 lines (152 loc) · 8.28 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
require 'db.php';
$idp = isset($_GET['idp']) ? $_GET['idp'] : null;
$sql = "SELECT * FROM posts WHERE idp = '$idp'";
$comm = "SELECT * FROM posts WHERE under = '$idp'";
$sql = $conn->query($sql);
$comm = $conn->query($comm);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Post Page</title>
<base href="/form/">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700|Roboto+Slab:400,700" rel="stylesheet">
<link rel="stylesheet" href="post.css">
<script src="post.js" defer></script>
</head>
<body>
<?php require 'header.php';?>
<main>
<article class="post">
<?php if ($sql->num_rows > 0):?>
<?php $post = $sql->fetch_assoc();?>
<?php
$user_profile_pic_sql = "SELECT profile_pic FROM accounts WHERE username = '{$post['username']}'";
$user_profile_pic_result = $conn->query($user_profile_pic_sql);
$user_profile_pic = "";
if ($user_profile_pic_result->num_rows > 0) {
$user_profile_pic_data = $user_profile_pic_result->fetch_assoc();
$user_profile_pic = $user_profile_pic_data['profile_pic'];
}
?>
<div class="post-header">
<div class="user-info">
<img src="<?php echo $user_profile_pic;?>" alt="Profile Picture" class="profile-pic">
<h2><?php echo "<a href='user/{$post['id']}' class='user-link'>".htmlspecialchars($post['username'])."</a>";?></h2>
</div>
<h1><?php echo htmlspecialchars($post['title']); ?></h1>
<p><?php echo htmlspecialchars($post['content']);?></p>
<div class="buttons">
<button id="likeBtn" class="likeBtn">Like</button>
<button id="dislikeBtn" class="dislikeBtn">Dislike</button>
</div>
</div>
</article>
<section class="comments">
<h2>Comments</h2>
<?php if ($comm->num_rows > 0):?>
<?php while ($comment = $comm->fetch_assoc()):?>
<div class="comment">
<?php
$user_profile_pic_sql = "SELECT profile_pic FROM accounts WHERE username = '{$comment['username']}'";
$user_profile_pic_result = $conn->query($user_profile_pic_sql);
$user_profile_pic = "";
if ($user_profile_pic_result->num_rows > 0) {
$user_profile_pic_data = $user_profile_pic_result->fetch_assoc();
$user_profile_pic = $user_profile_pic_data['profile_pic'];
}
?>
<div class="post-header">
<div class="user-info">
<img src="<?php echo $user_profile_pic;?>" alt="Profile Picture" class="profile-pic">
<h3><?php echo "<a href='user/{$comment['id']}' class='user-link'>".htmlspecialchars($comment['username'])."</a>";?></h3>
</div>
<p><?php echo htmlspecialchars($comment['content']);?></p>
<div class="buttons">
<button id="likeBtn" class="likeBtn">Like</button>
<button id="dislikeBtn" class="dislikeBtn">Dislike</button>
</div>
</div>
<?php $reply_sql = "SELECT * FROM posts WHERE under = '{$comment['idp']}'";?>
<?php $reply_result = $conn->query($reply_sql);?>
<?php if ($reply_result->num_rows > 0):?>
<div class="replies">
<?php while ($single_reply = $reply_result->fetch_assoc()):?>
<div class="reply">
<?php
$user_profile_pic_sql = "SELECT profile_pic FROM accounts WHERE username = '{$single_reply['username']}'";
$user_profile_pic_result = $conn->query($user_profile_pic_sql);
$user_profile_pic = "";
if ($user_profile_pic_result->num_rows > 0) {
$user_profile_pic_data = $user_profile_pic_result->fetch_assoc();
$user_profile_pic = $user_profile_pic_data['profile_pic'];
}
?>
<div class="post-header">
<div class="user-info">
<img src="<?php echo $user_profile_pic;?>" alt="Profile Picture" class="profile-pic">
<h3><?php echo "<a href='user/{$single_reply['id']}' class='user-link'>".htmlspecialchars($single_reply['username'])."</a>";?></h3>
</div>
<p><?php echo htmlspecialchars($single_reply['content']);?></p>
<div class="buttons">
<button id="likeBtn" class="likeBtn">Like</button>
<button id="dislikeBtn" class="dislikeBtn">Dislike</button>
</div>
</div>
</div>
<?php endwhile;?>
</div>
<?php endif;?>
<section>
<?php if (isset($_SESSION["username"])): ?>
<?php
$username = $_SESSION["username"];
$sql = "SELECT * FROM accounts WHERE username = '$username'";
$sql = $conn->query($sql);
$sql = $sql->fetch_assoc();
?>
<div class="reply-form-container">
<form action="submit_reply.php" method="post" class="reply-form">
<input type="hidden" name="original" value="<?php echo $idp; ?>">
<input type="hidden" name="post_id" value="<?php echo $comment['idp']; ?>">
<input type="hidden" name="username" value="<?php echo $sql['username']; ?>">
<input type="hidden" name="user_id" value="<?php echo $sql['id']; ?>">
<textarea name="reply" placeholder="Write your reply here..." required></textarea>
<button type="submit">Submit Reply</button>
</form>
</div>
<?php endif; ?>
</section>
</div>
<?php endwhile;?>
<?php endif;?>
<section>
<?php if (isset($_SESSION["username"])): ?>
<?php
$username = $_SESSION["username"];
$sql = "SELECT * FROM accounts WHERE username = '$username'";
$sql = $conn->query($sql);
$sql = $sql->fetch_assoc();
?>
<div class="reply-form-container">
<form action="submit_reply.php" method="post" class="reply-form">
<input type="hidden" name="post_id" value="<?php echo $idp; ?>">
<input type="hidden" name="username" value="<?php echo $sql['username']; ?>">
<input type="hidden" name="user_id" value="<?php echo $sql['id']; ?>">
<input type="hidden" name="original" value ="<?php echo $idp; ?>">
<textarea name="reply" placeholder="Write your reply here..." required></textarea>
<button type="submit">Submit Reply</button>
</form>
</div>
<?php endif; ?>
</section>
<?php else:?>
<p>Error 404 Post not found!</p>
<?php endif;?>
</main>
<?php require 'footer.php';?>
</body>
</html>