-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment_frame.php
More file actions
229 lines (195 loc) · 6.79 KB
/
Copy pathcomment_frame.php
File metadata and controls
229 lines (195 loc) · 6.79 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="assets/css/comments.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
</head>
<body>
<style type="text/css">
* {
font-size: 12px;
font-family: Arial, Helvetica, Sans-serif;
}
.comment_section {
padding: 0 5px 5px 5px;
}
.comment_section img {
margin: 0 3px 3px 3px;
border-radius: 3px;
}
#comment_form textarea {
border-color: #D3D3D3;
width: 85%;
height: 35px;
border-radius: 5px;
color: #616060;
font-size: 14px;
margin: 3px 3px 3px 5px;
}
#comment_form input[type="submit"] {
border: none;
background-color: #20AAE5;
color: #156588;
border-radius: 5px;
width: 13%;
height: 35px;
margin-top: 3px;
position: absolute;
font-family: 'Bellota-BoldItalic', sans-serif;
text-shadow: #73B6E2 0.5px 0.5px 0px;
}
</style>
<?php
require 'config/config.php';
include("includes/classes/User.php");
include("includes/classes/Post.php");
include("includes/classes/Notification.php");
if (isset($_SESSION['username'])) {
$userLoggedIn = $_SESSION['username'];
$user_details_query = mysqli_query($con, "SELECT * FROM users WHERE username='$userLoggedIn'");
$user = mysqli_fetch_array($user_details_query);
} else {
header("Location: register.php");
}
?>
<script>
function toggle() {
var element = document.getElementById("comment_section");
if (element.style.display == "block")
element.style.display = "none";
else
element.style.display = "block";
}
</script>
<?php
//Get id of post
if (isset($_GET['post_id'])) {
$post_id = $_GET['post_id'];
$post_type = $_GET['post_type'];
}
if ($post_type == 'photo') {
$user_query = mysqli_query($con, "SELECT added_by, user_to FROM posts WHERE id='$post_id'");
$row = mysqli_fetch_array($user_query);
$posted_to = $row['added_by'];
$user_to = $row['user_to'];
}
if ($post_type == 'video') {
$user_query = mysqli_query($con, "SELECT added_by FROM videos WHERE id='$post_id'");
$row = mysqli_fetch_array($user_query);
$posted_to = $row['added_by'];
$user_to = 'none';
}
if (isset($_POST['postComment' . $post_id . $post_type])) {
$post_body = $_POST['post_body'];
$post_body = mysqli_escape_string($con, $post_body);
$date_time_now = date("Y-m-d H:i:s");
$insert_post = mysqli_query($con, "INSERT INTO comments VALUES (NULL, '$post_body', '$userLoggedIn', '$posted_to','$post_type', '$date_time_now', 'no','$post_id')");
if ($posted_to != $userLoggedIn) {
$notification = new Notification($con, $userLoggedIn);
$notification->insertNotification($post_id, $posted_to, "comment");
}
if ($user_to != 'none' && $user_to != $userLoggedIn) {
$notification = new Notification($con, $userLoggedIn);
$notification->insertNotification($post_id, $user_to, "profile_comment");
}
$get_commenters = mysqli_query($con, "SELECT * FROM comments WHERE post_id='$post_id' AND post_type='$post_type'");
$notified_users = array();
while ($row = mysqli_fetch_array($get_commenters)) {
if (
$row['posted_by'] != $posted_to && $row['posted_by'] != $user_to
&& $row['posted_by'] != $userLoggedIn && !in_array($row['posted_by'], $notified_users)
) {
$notification = new Notification($con, $userLoggedIn);
$notification->insertNotification($post_id, $row['posted_by'], "comment_non_owner");
array_push($notified_users, $row['posted_by']);
}
}
echo "<p>Comment Posted! </p>";
}
?>
<form action="comment_frame.php?post_id=<?php echo $post_id; ?>&post_type=<?php echo $post_type; ?>" id="comment_form" name="postComment<?php echo $post_id . $post_type; ?>" method="POST">
<div class="form-row">
<div class="col-10">
<textarea name="post_body" id="post_body" style="width:100%; border-radius:5px" placeholder="Got something to say?"></textarea>
</div>
<div class="col">
<button class="btn btn-primary" type="submit" name="postComment<?php echo $post_id . $post_type; ?>" id="post_button" style="border-radius:20px; margin:5px">Comment</button>
</div>
</div>
</form>
<!-- Load comments -->
<?php
$get_comments = mysqli_query($con, "SELECT * FROM comments WHERE post_id='$post_id' AND post_type='$post_type' ORDER BY id ASC");
$count = mysqli_num_rows($get_comments);
if ($count != 0) {
while ($comment = mysqli_fetch_array($get_comments)) {
$comment_body = $comment['post_body'];
$posted_to = $comment['posted_to'];
$posted_by = $comment['posted_by'];
$date_added = $comment['date_added'];
$removed = $comment['removed'];
//Timeframe
$date_time_now = date("Y-m-d H:i:s");
$start_date = new DateTime($date_added); //Time of post
$end_date = new DateTime($date_time_now); //Current time
$interval = $start_date->diff($end_date); //Difference between dates
if ($interval->y >= 1) {
if ($interval->y == 1)
$time_message = $interval->y . " year ago"; //1 year ago
else
$time_message = $interval->y . " years ago"; //1+ year ago
} else if ($interval->m >= 1) {
if ($interval->d == 0) {
$days = " ago";
} else if ($interval->d == 1) {
$days = $interval->d . " day ago";
} else {
$days = $interval->d . " days ago";
}
if ($interval->m == 1) {
$time_message = $interval->m . " month" . $days;
} else {
$time_message = $interval->m . " months" . $days;
}
} else if ($interval->d >= 1) {
if ($interval->d == 1) {
$time_message = "Yesterday";
} else {
$time_message = $interval->d . " days ago";
}
} else if ($interval->h >= 1) {
if ($interval->h == 1) {
$time_message = $interval->h . " hour ago";
} else {
$time_message = $interval->h . " hours ago";
}
} else if ($interval->i >= 1) {
if ($interval->i == 1) {
$time_message = $interval->i . " minute ago";
} else {
$time_message = $interval->i . " minutes ago";
}
} else {
if ($interval->s < 30) {
$time_message = "Just now";
} else {
$time_message = $interval->s . " seconds ago";
}
}
$user_obj = new User($con, $posted_by);
?>
<div class="comment_section">
<a href="<?php echo $posted_by ?>" target="_parent"><img src="<?php echo $user_obj->getProfilePic(); ?>" title="<?php echo $posted_by; ?>" style="float:left;" height="30"></a>
<a href="<?php echo $posted_by ?>" target="_parent"> <b> <?php echo $user_obj->getFirstAndLastName(); ?> </b></a>
<?php echo $time_message . "<br>" . $comment_body; ?>
<hr>
</div>
<?php
}
} else {
echo "<center><br><br>No Comments to Show!</center>";
}
?>
</body>
</html>