-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFullPost.php
More file actions
224 lines (203 loc) · 9.22 KB
/
FullPost.php
File metadata and controls
224 lines (203 loc) · 9.22 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
<?php require_once("include/DB.php"); ?>
<?php require_once("include/Sessions.php"); ?>
<?php require_once("include/Functions.php"); ?>
<?php
if(!isset($_SESSION["Username"])){
$_SESSION["ErrorMessage"] = "Please Register/Login to view content.";
Redirect_to("Blog.php");
}
?>
<?php
if(isset($_POST["Submit"])){
$Name = $Connection->real_escape_string($_POST["Name"]);
$Email = $Connection->real_escape_string($_POST["Email"]);
$Comment = $Connection->real_escape_string($_POST["Comment"]);
date_default_timezone_set("Asia/Kolkata");
$CurrentTime = time();
$DateTime = strftime("%B-%d-%Y %H:%M:%S", $CurrentTime);
$PostId = $_GET["id"];
if(empty($Name) || empty($Email) || empty($Comment)){
$_SESSION["ErrorMessage"]="All Fields are required.";
} elseif(strlen($Comment)>500){
$_SESSION["ErrorMessage"]="Maximum 500 characters are allowed.";
} else{
global $ConnectingDB;
$PostIdFromUrl = $_GET["id"];
$Query = "INSERT INTO comments(datetime,name,email,comment,approvedby,status,admin_panel_id)
VALUES('$DateTime','$Name','$Email','$Comment','Pending','OFF','$PostIdFromUrl')";
$Execute = $Connection->query($Query);
if($Execute){
$_SESSION["SuccessMessage"] = "Comment Submitted Successfully";
Redirect_to("FullPost.php?id={$PostId}");
} else{
$_SESSION["ErrorMessage"] = "Something Went Wrong, Try Again!";
Redirect_to("FullPost.php?id={$PostId}");
}
}
}
if(isset($_GET["ClappedBy"]) && isset($_GET["OnPost"])){
date_default_timezone_set("Asia/Kolkata");
$CurrentTime = time();
$DateTime = strftime("%B-%d-%Y %H:%M:%S", $CurrentTime);
$ClappedBy = $_GET["ClappedBy"];
$PostId = $_GET["OnPost"];
$ConnectingDB;
$Query = "INSERT INTO claps(datetime,clapedby,admin_panel_id)
VALUES('$DateTime','$ClappedBy','$PostId' )";
$Execute = $Connection->query($Query);
if($Execute){
$_SESSION["SuccessMessage"] = "Applause Submitted Successfully";
Redirect_to("FullPost.php?id={$PostId}");
} else{
$_SESSION["ErrorMessage"] = "Something Went Wrong, Try Again!";
Redirect_to("FullPost.php?id={$PostId}");
}
}
if(isset($_GET["UnClappedBy"]) && isset($_GET["OnThePost"])){
date_default_timezone_set("Asia/Kolkata");
$CurrentTime = time();
$DateTime = strftime("%B-%d-%Y %H:%M:%S", $CurrentTime);
$UnClappedBy = $_GET["UnClappedBy"];
$PostId = $_GET["OnThePost"];
$ConnectingDB;
$Query = "DELETE FROM claps WHERE
admin_panel_id='$PostId' AND clapedby='$UnClappedBy' ";
$Execute = $Connection->query($Query);
if($Execute){
$_SESSION["SuccessMessage"] = "Applause Removed Successfully";
Redirect_to("FullPost.php?id={$PostId}");
} else{
$_SESSION["ErrorMessage"] = "Something Went Wrong, Try Again!";
Redirect_to("FullPost.php?id={$PostId}");
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TechVents | Post</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="js/search.js" ></script>
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" integrity="sha256-h20CPZ0QyXlBuAw7A+KluUYx/3pK+c7lYEpqLTlxjYQ=" crossorigin="anonymous" />
</head>
<body>
<?php include("base.php"); ?>
<div class="full-post-container">
<?php echo Message(); echo SuccessMessage(); ?>
<?php
global $ConnectingDB;
if(isset($_GET["Search"])){
$Search = $_GET["Search"];
$ViewQuery = "SELECT * FROM admin_panel
WHERE datetime LIKE '%$Search%'
OR title LIKE '%$Search%'
OR category LIKE '%$Search%'
OR post LIKE '%$Search%'
OR author LIKE '%$Search%'";
}else {
$PostIdFromUrl = $_GET["id"];
$ViewQuery = "SELECT * FROM admin_panel WHERE id='$PostIdFromUrl' ORDER BY id desc";
}
$Execute = $Connection->query($ViewQuery);
while($DataRows = $Execute->fetch_assoc()){
$PostId = $DataRows["id"];
$DateTime = $DataRows["datetime"];
$Title = $DataRows["title"];
$Category = $DataRows["category"];
$Admin = $DataRows["author"];
$Image = $DataRows["image"];
$Post = $DataRows["post"];
?>
<div class="full-post-header">
<div class="category-tags">
<button class="btn-select" style="border:none"><?php echo $Category;?></button>
</div>
<h1><?php echo $Title;?></h1>
</div>
<div class="full-post-body">
<div class="post-stats">
<div class="date">
<i class="fas fa-calendar" aria-hidden="true"></i>
<p><?php echo $DateTime;?></p>
</div>
<?php
$ConnectingDB;
$UserId = $_SESSION["User_Id"];
$CheckClapQuery = "SELECT COUNT(*) FROM claps
WHERE clapedby='$UserId'
AND admin_panel_id='$PostId' ";
$ExecuteClapQuery = $Connection->query($CheckClapQuery);
if($ExecuteClapQuery->fetch_assoc()['COUNT(*)']==0)
{
print "
<a href=\"FullPost.php?ClappedBy={$UserId}&OnPost={$PostId}\">
<img src=\"https://img.icons8.com/ios/25/000000/applause.png\"/>
</a>
";
}
else
{
print "
<a href=\"FullPost.php?UnClappedBy={$UserId}&OnThePost={$PostId}\">
<img src=\"https://img.icons8.com/ios-filled/25/000000/applause.png\"/>
</a>
";
}
?>
</div>
<div class="post-main-body">
<img src="uploads/<?php echo $Image; ?>" alt="Post Image" class="post-img">
<p>
<?php
echo nl2br($Post);
?>
</p>
</div>
<div class="post-source">
<img src="images/icons8-bluestacks-48.png" alt="Source">
<div class="source-info">
<h3>Author:</h3>
<p><?php echo $Admin; ?></p>
</div>
</div>
<?php } ?>
<!-- Comments -->
<div class="comments">
<h2>Comments:</h2>
<?php
$ConnectingDB;
$PostIdForComments = $_GET["id"];
$ExtractingCommentsQuery = "SELECT * FROM comments WHERE admin_panel_id='$PostIdForComments'
AND status='ON' ";
$Execute = $Connection->query($ExtractingCommentsQuery);
while($DataRows = $Execute->fetch_assoc()){
$CommentDate = $DataRows["datetime"];
$CommenterName = $DataRows["name"];
$Comments = $DataRows["comment"];
?>
<div class="show-comments">
<h4>By : <span id="commentor"><?php echo $CommenterName; ?></span> </h4>
<p><?php echo $CommentDate; ?></p>
<p style="color: black; margin-bottom: 20px;"><?php echo nl2br($Comments); ?></p>
</div>
<?php } ?>
<hr>
<p>Share your Thoughts about the post</p>
<p>Comments</p>
<form action="FullPost.php?id=<?php echo $PostId;?>" method="post" enctype="multipart/form-data">
<label for="name">Name:</label>
<input type="text" name="Name" placeholder="Name" id="name">
<label for="email">Email:</label>
<input type="text" name="Email" placeholder="Email" id="email">
<label for="comment">Comment:</label>
<textarea cols="100%" rows="6%" placeholder="Comment" name="Comment" id="comment"></textarea>
<input type="Submit" name="Submit" value="Add New Comment" class = "btn-submit">
</form>
</div>
</div>
</div>
</body>
</html>