-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment_frame.php
More file actions
180 lines (141 loc) · 4.68 KB
/
comment_frame.php
File metadata and controls
180 lines (141 loc) · 4.68 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
<html>
<head>
<title>
</title>
<link rel = "stylesheet" type = "text/css" href = "css/style.css">
<link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Muli|Raleway|Ubuntu" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Heebo:500|Montserrat|PT+Sans|Sarala|Satisfy" rel="stylesheet">
</head>
<body>
<?php
require 'connection.php';
include("user.php");
include("posts.php");
if(isset($_SESSION['username']))
{
$user_logged = $_SESSION['username'];
$user_details = mysqli_query($connect, "SELECT * FROM users WHERE username = '$user_logged'");
$user = mysqli_fetch_array($user_details);
}
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
if(isset($_GET['post_id'])) //getting post id
{
$post_id = $_GET['post_id'];
}
$comment_query = mysqli_query($connect, "SELECT post_by FROM posts WHERE id = '$post_id'");
$row = mysqli_fetch_array($comment_query);
$posted_to = $row['post_by'];
if(isset($_POST['postComment' . $post_id])){
$post_body = $_POST['post_body'];
$post_body = mysqli_escape_string($connect, $post_body);
$date_time = date("Y-m-d H:i:s");
$comment_query = mysqli_query($connect , "INSERT INTO posts_comments VALUES ('', '$posted_to' , '$user_logged' , '$post_body' , '0' , '$date_time' , 'no' , '$post_id')");
//echo "comment posted!";
}
?>
<form action="comment_frame.php?post_id=<?php echo $post_id; ?>" id="comment_form" name="postComment<?php echo $post_id; ?>" method="POST">
<textarea name="post_body"></textarea>
<input type="submit" name="postComment<?php echo $post_id; ?>" value="Comment">
</form>
<?php
$get_comments = mysqli_query($connect, "SELECT * FROM posts_comments WHERE post_id='$post_id' ORDER BY id DESC");
$count = mysqli_num_rows($get_comments);
if($count != 0) {
while($comment = mysqli_fetch_array($get_comments)) {
$comment_body = $comment['comment_body'];
$is_empty = preg_replace('/\s+/' , '' ,$comment_body);
if($is_empty != ""){
$posted_to = $comment['comment_on'];
$posted_by = $comment['comment_by'];
$date_added = $comment['comment_date'];
$removed = $comment['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 == 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($connect, $posted_by);
$name = $user_obj->getFirstAndLastName();
?>
<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 ;padding :5px;" height="35" ;></a>
<a class = "commenter" href="<?php echo $posted_by?>" target="_parent" > <?php echo $name ?> </a>
<?php echo "<span id ='timec'>$time_message</span>" . "<br>" . "<span id = 'comment_body'>$comment_body</span>" ?>
<hr size="0.1px" color ="white" noshade>
</div>
<?php
}
}
}
?>
</body>
</html>