-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblogView.php
229 lines (201 loc) · 6.37 KB
/
blogView.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
session_start();
require 'db.php';
if(!isset($_SESSION['logged_in']) OR $_SESSION['logged_in'] == 0)
{
$_SESSION['message'] = "You need to first login to access this page !!!";
header("Location: Login/error.php");
}
if ($_SERVER["REQUEST_METHOD"] == "POST" AND isset($_SESSION['logged_in']) AND $_SESSION['logged_in'] == 1)
{
if(isset($_POST['comment']) AND $_POST['comment'] != "")
{
$sql = "SELECT * FROM blogdata ORDER BY blogId DESC";
$result = mysqli_query($conn, $sql);
while($row = $result->fetch_array())
{
$check = "submit".$row['blogId'];
if(isset($_POST[$check]))
{
$blogId = $row['blogId'];
break;
}
}
$comment = dataFilter($_POST['comment']);
if(isset($_SESSION['logged_in']) AND $_SESSION['logged_in'] == 1)
{
$commentUser = $_SESSION['Username'];
$pic = $_SESSION['picName'];
}
else {
$commentUser = "Anonymous";
$pic = "profile0.png";
}
if(isset($blogId))
{
$sql = "INSERT INTO blogfeedback (blogId, comment, commentUser, commentPic)
VALUES ('$blogId' ,'$comment', '$commentUser', '$pic');";
$result = mysqli_query($conn, $sql);
}
}
else
{
$sql = "SELECT * FROM blogdata ORDER BY blogId DESC";
$result = mysqli_query($conn, $sql);
while($row = $result->fetch_array())
{
$check = "like".$row['blogId'];
if(isset($_POST[$check]))
{
$blogId = $row['blogId'];
break;
}
}
$likeCheck = "isLiked".$blogId;
if(!isset($_SESSION[$likeCheck]) OR $_SESSION[$likeCheck] == 0)
{
$id = $_SESSION['id'];
$sql = "SELECT * FROM likedata WHERE blogId = '$blogId' AND blogUserId = '$id'";
$result = mysqli_query($conn, $sql);
$num_rows = mysqli_num_rows($result);
if($num_rows == 0)
{
$sql = "INSERT INTO likedata (blogId, blogUserId)
VALUES('$blogId', '$id')";
$result = mysqli_query($conn, $sql);
$sql = "UPDATE blogdata SET likes = likes + 1 WHERE blogId = '$blogId'";
$result = mysqli_query($conn, $sql);
$_SESSION[$likeCheck] = 1;
}
}
}
}
function dataFilter($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$sql = "SELECT * FROM blogdata ORDER BY blogId DESC";
$result = mysqli_query($conn, $sql);
function formatDate($date)
{
return date('g:i a', strtotime($date));
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>AgroCulture : Blogs</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="bootstrap\css\bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="bootstrap\js\bootstrap.min.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]-->
<script src="js/jquery.min.js"></script>
<script src="js/skel.min.js"></script>
<script src="js/skel-layers.min.js"></script>
<script src="js/init.js"></script>
<link rel="stylesheet" href="css/skel.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/style-xlarge.css" />
<link rel="stylesheet" href="Blog/commentBox.css" />
</head>
<body class="subpage">
<?php
require 'menu.php';
?>
<section id="main" class="wrapper">
<div class="inner">
<div class="container" style="width: 70%">
<div class="row uniform">
<div class="9u 12u$(small)">
</div>
<div class="3u 12u$(small)">
<a href="blogWrite.php" class="button special fit"><span class="glyphicon glyphicon-pencil"></span> Write a Blog</a>
</div>
</div>
<br />
<?php
while($row = $result->fetch_array()) :
$id = $row['blogId'];
$sql = "SELECT * FROM blogfeedback WHERE blogId = '$id'";
$result1 = mysqli_query($conn, $sql);
$numComment = mysqli_num_rows($result1);
?>
<div class="box">
<h2><?= $row['blogTitle']; ?></h2>
<blockquote>
<?= $row['blogContent']; ?>
<p>--- <?= $row['blogUser']; ?></p>
<p><?= $row['blogTime']; ?></p>
</blockquote>
<form method="post" action="blogView.php">
<div class="row">
<div class="6u 12u$(xsmall)">
<button class = "button special small" name="<?php echo 'like'.$id; ?>">
<span class="glyphicon glyphicon-thumbs-up"></span> Like</button>
<span><?= $row['likes']?></span>
</div>
<div class="6u 12u$(xsmall)">
<span class="glyphicon glyphicon-pencil"></span> Comments : <?= $numComment ?></button>
</div>
<div class="12u$">
<br>
<textarea name="comment" id="comment" rows="1" placeholder="Write a Comment!"></textarea>
</div>
<div class="12u$">
<center>
<br>
<input type="submit" name="<?php echo 'submit'.$id; ?>" class="button special small" value="Submit"/>
</center>
</div>
</div>
</form>
<?php
if($result1) :
while($row1 = $result1->fetch_array()) :
?>
<div class="con darker">
<img src="<?php echo 'images/profileImages/'.$row1['commentPic']?>" alt="Avatar"><span><em><?= $row1['commentUser']; ?></em></span>
<br>
<?= $row1['comment']; ?>
<span class="time-right"><?= formatDate($row1['commentTime']); ?></span>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
</div>
</section>
<script>
/* function ajax()
{
var req = new XMLHttpRequest();
req.onreadystatechange = function()
{
if(req.readyState == 4 && req.status == 200)
{
document.getElementById('liked').innerHTML = req.responseText;
}
}
req.open('POST', 'Blog/blogViewProcess.php', 'true');
req.send();
}
setInterval(function(){ajax()}, 1000);*/
</script>
<script src="jquery/jquery-3.2.1.min.js"></script>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.scrolly.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/skel.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>