-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.php
212 lines (193 loc) · 7.23 KB
/
post.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
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
<?php require_once('inc/top.php'); ?>
<body>
<?php require_once('inc/header.php'); ?>
<?php
if(isset($_GET['post_id'])){
$post_id = $_GET['post_id'];
// views functionality
$view_query = "UPDATE `posts` SET `views` = views+1 WHERE `posts`.`id` = $post_id;";
mysqli_query($conn,$view_query);
$query = "select * from posts where status = 'publish' and id='$post_id'";
$run = mysqli_query($conn,$query);
if(mysqli_num_rows($run)>0){
$row = mysqli_fetch_array($run);
$id = $row['id'];
$date = getdate($row['date']);
$day = $date['mday'];
$month = $date['month'];
$year = $date['year'];
$title = $row['title'];
$image = $row['image'];
$author_image = $row['author_image'];
$author = $row['author'];
$categories = $row['categories'];
$post_data = $row['post_data'];
$tags = $row['tags'];
$username = $row['username'];
}
else {
header('location: index.php');
}
} ?>
<div class="jumbotron">
<div class="container-fluid">
<div class="animated fadeInLeft" id="details">
<h1>Custom <span>Post</span></h1>
<p>Here you can put your tag line</p>
</div>
</div>
</div>
<section>
<div class="container-fluid">
<div class="row">
<div class="col-md-8">
<div class="col-md-12">
<div class="post">
<div class="row">
<div class="col-md-2 post-date">
<div class="day"><?php echo $day; ?></div>
<div class="month"><?php echo $month; ?></div>
<div class="year"><?php echo $year; ?></div>
</div>
<div class="col-md-8 post-title">
<a href="post.php?post_id=<?php echo $id; ?>"><h2><strong>
<?php echo $title; ?></strong></h2></a>
<p>Written By: <span><?php echo ucfirst($author); ?></span></p>
</div>
<div class="col-md-2 profile-picture ">
<img src="img/<?php echo $author_image; ?>" class="img-circle">
</div>
</div>
<a href="img/<?php echo $image; ?>"><img src="img/<?php echo $image; ?>" alt=""></a>
<div class="desc">
<?php echo $post_data; ?>
</div>
<div class="bottom">
<span class="first"><i class="fa fa-folder"></i> <a href="">Category</a></span> |
<span class="sec"><i class="fa fa-comment"></i> <a href="">Comment</a></span>
</div>
</div>
<div class="related-post">
<h2>Related Posts</h2><hr>
<div class="row">
<?php
$r_query = "SELECT * from posts where status = 'publish' AND title LIKE '%$title%' LIMIT 3";
$r_result = mysqli_query($conn,$r_query);
while($row = mysqli_fetch_array($r_result)){
$r_id = $row['id'];
$r_title = $row['title'];
$r_image = $row['image'];
?>
<div class="col-md-4"><a href="post.php?post_id=<?php echo $r_id; ?>"><img src="img/<?php echo $r_image; ?>" alt="post1"><h4><?php echo $r_title; ?></h4></a></div>
<?php } ?>
</div>
</div>
<div class="author">
<div class="row">
<div class="col-md-3">
<img src="img/<?php echo $author_image; ?>" class="img-circle">
</div>
<div class="col-md-9">
<h2><?php echo $author; ?></h2>
<?php $bio_query = "SELECT * FROM users where username = '$username'";
$bio_query_run = mysqli_query($conn,$bio_query);
if(mysqli_num_rows($bio_query_run)>0){
$det = mysqli_fetch_array($bio_query_run);
$bio_data = $det['details'];
?>
<p class="author-desc"><?php echo $bio_data; ?></p>
<?php } else {
echo "User details are not available";
} ?>
</div>
</div>
</div>
<?php $c_query="SELECT * FROM comments where status = 'approve' and post_id=$post_id ORDER BY id DESC";
$c_run = mysqli_query($conn,$c_query);
?>
<div class="comment">
<h3>Comments</h3>
<?php
while($c_row = mysqli_fetch_array($c_run)){
$c_id = $c_row['id'];
$c_username = $c_row['username'];
$c_author_image = $c_row['image'];
$c_comment = $c_row['comment'];
?>
<hr>
<div class="row single-comment">
<div class="col-md-2">
<img src="img/<?php echo $c_author_image; ?>" class="img-circle">
</div>
<div class="col-md-10">
<h2><?php echo $c_username; ?></h2>
<p class="author-desc"><?php echo $c_comment; ?></p>
</div>
</div>
<?php } ?>
</div>
<?php
if(isset($_POST['submit'])){
$cs_name = $_POST['name'];
$cs_email = $_POST['email'];
$cs_website = $_POST['website'];
$cs_comment = $_POST['comment'];
$cs_date = time();
if(empty($cs_name) or empty($cs_email) or empty($cs_comment)){
$err_msg = "All (*) fields are required.";
}
else {
$cs_query = "INSERT INTO `comments` (`id`, `date`, `name`, `username`, `post_id`, `email`, `website`, `image`, `comment`, `status`) VALUES (NULL, '$cs_date', '$cs_name', '$c_username', '$post_id', '$cs_email', '$cs_website', '$author_image', '$cs_comment', 'pending');";
if(mysqli_query($conn,$cs_query)){
$msg = "Comment submitted and waiting for approval";
$cs_name = "";
$cs_email = "";
$cs_website = "";
$cs_comment = "";
}
else {
$msg = "Comment has not been submitted";
}
}
}
?>
<div class="col-md-12 contact-form">
<h2>Comment Box</h2>
<hr>
<form action="" method="post">
<div class="form-group">
<label for="name">Full Name*:</label>
<input type="text" id="name" name="name" value="<?php if(isset($_POST['name'])){echo $cs_name;} ?>" placeholder="Full Name" class="form-control">
</div>
<div class="form-group">
<label for="email">Email*:</label>
<input type="text" id="email" name="email" value="<?php if(isset($_POST['email'])){echo $cs_email;} ?>" placeholder="Email" class="form-control">
</div>
<div class="form-group">
<label for="website">Website:</label>
<input type="text" id="website" name="website" value="<?php if(isset($_POST['website'])){echo $cs_website;} ?>" placeholder="Website" class="form-control">
</div>
<div class="form-group">
<label for="message">Comment*:</label>
<textarea id="message" cols="30" rows="10" name="comment" class="form-control" value="<?php if(isset($_POST['comment'])){echo $cs_comment;} ?>" placeholder="Your Comment Should Be Here!"></textarea>
</div>
<input type="submit" name="submit" value="Submit Comment" class="btn btn-primary">
<?php
if(isset($msg)) {
echo "<span style = 'color:darkgreen; font-weight:bold;' class='pull-right'>$msg</span>";
}
elseif(isset($err_msg)){
echo "<span class='pull-right' style = 'color:red; font-weight:bold;'>$err_msg</span>";
} ?>
</form>
</div>
</div>
</div>
<div class="col-md-4">
<?php require_once('inc/sidebar.php'); ?>
</div>
</div>
</section>
<?php require_once("inc/footer.php"); ?>
</body>
</html>