-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.php
231 lines (222 loc) · 14.2 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
include('./classes/DB.php');
include('./classes/Login.php');
include('./classes/Comment.php');
$userId=Login::isLoggedIn();
if (!$userId) {
header('Location: login.html');
die;
}else{
$user = DB::query('SELECT username, profileimg, role FROM users WHERE id=:userid', array(':userid'=>Login::isLoggedIn()));
if (isset($_GET['id'])) {
$postId=$_GET['id'];
$post = DB::query('SELECT posts.id, posts.body, posts.posted_at, posts.postimg, posts.likes, users.`username`, users.id as userid FROM users, posts
WHERE users.id = posts.user_id
AND posts.id=:postid', array(':postid'=>$postId));
$authorId=$post[0]['userid'];
$comments=DB::query('SELECT comments.comment, comments.posted_at, users.username, users.profileimg FROM comments, users WHERE post_id = :postid AND comments.user_id = users.id ORDER BY comments.posted_at DESC', array(':postid'=>$postId));
if (!$post) {
die('Post not found!');
}
if ($_SERVER['REQUEST_METHOD']=='POST')
{
if (isset($_POST['post'])) {
$str = str_replace(array("\r\n", "\n", "\r"), ' ', htmlentities($_POST['postbody']));
Comment::createComment($str, $postId, $userId);
}
if (isset($_POST['deletepost'])) {
if (DB::query('SELECT id FROM posts WHERE id=:postid AND user_id=:userid', array(':postid'=>$_GET['postid'], ':userid'=>$followerid))) {
DB::query('DELETE FROM posts WHERE id=:postid and user_id=:userid', array(':postid'=>$_GET['postid'], ':userid'=>$followerid));
DB::query('DELETE FROM posts_likes WHERE post_id=:postid', array(':postid'=>$_GET['postid']));
}
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Social Network</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/fonts/ionicons.min.css">
<link rel="stylesheet" href="assets/css/Footer-Dark.css">
<link rel="stylesheet" href="assets/css/Highlight-Clean.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/aos/2.1.1/aos.css">
<link rel="stylesheet" href="assets/css/Login-Form-Clean.css">
<link rel="stylesheet" href="assets/css/Navigation-Clean1.css">
<link rel="stylesheet" href="assets/css/styles.css">
<link rel="stylesheet" href="assets/css/index.css">
</head>
<body>
<header class="hidden-sm hidden-md hidden-lg">
<div class="searchbox">
<form>
<?php
if ($user[0]['role']==1){
echo '<a href="admin.php"> <h1 class="text-left">SocNet</h1></a>';
}else{
echo '<a href="index.php"> <h1 class="text-left">SocNet</h1></a>';
}
?>
<div class="searchbox"><i class="glyphicon glyphicon-search"></i>
<input class="form-control sbox" type="text">
<ul class="list-group autocomplete" style="position:absolute;width:100%; z-index: 100">
</ul>
</div>
<div class="dropdown">
<button class="btn btn-link dropdown-toggle" data-toggle="dropdown" aria-expanded="false" type="button">MENU <span class="caret"></span>
<img src="" data-tempsrc="<?php echo $user[0]['profileimg']?>" class="postimg avatar"></button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li role="presentation">
<?php echo '<a href="profile.php?username='.$user[0]['username'].'">My Profile</a>'?></li>
<li class="divider" role="presentation"></li>
<li role="presentation"><a href="index.php">Timeline </a></li>
<li role="presentation"><a href="messages.php">Messages </a></li>
<li role="presentation"><a href="notify.php">Notifications </a></li>
<li role="presentation"><a href="my_account.php">Account Managment</a></li>
<li role="presentation"><a href="change_password.php">Password change</a></li>
<li role="presentation"><a href="logout.php">Logout </a></li>
</ul>
</div>
</form>
</div>
<hr>
</header>
<div>
<nav class="navbar navbar-default hidden-xs navigation-clean">
<div class="container">
<div class="navbar-header">
<?php
if ($user[0]['role']==1){
echo '<a class="navbar-brand navbar-link" href="admin.php"><i class="icon ion-ios-navigate"></i></a>';
}else{
echo '<a class="navbar-brand navbar-link" href="index.php"><i class="icon ion-ios-navigate"></i></a>';
}
?>
<button class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navcol-1"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>
</div>
<div class="collapse navbar-collapse" id="navcol-1">
<form class="navbar-form navbar-left">
<div class="searchbox"><i class="glyphicon glyphicon-search"></i>
<input class="form-control sbox" type="text">
<ul class="list-group autocomplete" style="position:absolute;width:100%; z-index:100">
</ul>
</div>
</form>
<ul class="nav navbar-nav hidden-md hidden-lg navbar-right">
<li role="presentation"><a href="index.php">My Timeline</a></li>
<li class="dropdown open">
<a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true" href="#">
<?php echo $user[0]['username']?>
<span class="caret"></span>
<img src="" data-tempsrc="<?php echo $user[0]['profileimg']?>" class="postimg avatar"></a>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li role="presentation">
<?php echo '<a href="profile.php?username='.$user[0]['username'].'">My Profile</a>'?></li>
<li class="divider" role="presentation"></li>
<li role="presentation"><a href="index.php">Timeline </a></li>
<li role="presentation"><a href="messages.php">Messages </a></li>
<li role="presentation"><a href="notify.php">Notifications </a></li>
<li role="presentation"><a href="my_account.php">Account Managment</a></li>
<li role="presentation"><a href="change_password.php">Password change</a></li>
<li role="presentation"><a href="logout.php">Logout </a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav hidden-xs hidden-sm navbar-right">
<li role="presentation"><a href="index.php">Timeline</a></li>
<li role="presentation"><a href="messages.php">Messages</a></li>
<li role="presentation"><a href="notify.php">Notifications</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" href="#">
<?php echo $user[0]['username']?>
<span class="caret"></span> <img src="" data-tempsrc="<?php echo $user[0]['profileimg']?>" class="postimg avatar"></a>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li role="presentation">
<?php echo '<a href="profile.php?username='.$user[0]['username'].'">My Profile</a>'?></li>
<li class="divider" role="presentation"></li>
<li role="presentation"><a href="index.php">Timeline </a></li>
<li role="presentation"><a href="messages.php">Messages </a></li>
<li role="presentation"><a href="notify.php">Notifications </a></li>
<li role="presentation"><a href="my_account.php">Account Managment</a></li>
<li role="presentation"><a href="change_password.php">Password change</a></li>
<li role="presentation"><a href="logout.php">Logout </a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
</div>
<div>
<div class="container">
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-8">
<ul class="list-group">
<div class="timelineposts">
<?php
if ($userId==$authorId||$user[0]['role']==1){
echo "<form action=''method='post' enctype='multipart/form-data'>
<input type='submit' name='deletepost' class='btn btn-primary' align='right' value='X' />
</form> ";
}
echo "<li class='list-group-item' id='".$post[0]['id']."'><blockquote><p>".$post[0]['body']."</p>";
if ($post[0]['postimg']!=""){
echo "<img data-tempsrc='".$post[0]['postimg']."' class='postimg'>";
}
echo "<footer>Posted by ".$post[0]['username']." on ".$post[0]['posted_at'];
echo "<button class='btn btn-default' type='button' style='color:#eb3b60;background-image:url("none");background-color:transparent;' data-id=".$post[0]['id']."> <span class='glyphicon glyphicon-heart' ></span> ".$post[0]['likes']." Likes</span></button></footer>"
?>
<form action="" method="post" enctype="multipart/form-data">
<textarea name="postbody" rows="8" cols="70" required></textarea>
<input type="submit" name="post" value="Comment" class="btn btn-default" type="button" style="background-image:url("none");background-color:#316808;color:#fff;padding:16px 32px;margin:0px 0px 6px;border:none;box-shadow:none;text-shadow:none;opacity:0.9;text-transform:uppercase;font-weight:bold;font-size:13px;letter-spacing:0.4px;line-height:1;outline:none;">
</form>
<?php
echo "</blockquote></li>";
?>
<li class='list-group-item'>
<blockquote>
<?php
if (!empty($comments)){
foreach ($comments as $comment){
echo "<div class='media'>
<div class='media-left'>
<img src='".$comment['profileimg']."' class='media-object' style='width:60px; height:60px; border-radius: 25px;'>
</div>
<div class='media-body'>
<h4 class='media-heading'>".$comment['username']."<small><i>Posted on ".$comment['posted_at']."</i></small></h4>
<p>".$comment['comment']."</p>
</div>
</div>";
}
}
?>
</blockquote>
</li>
</div>
</ul>
</div>
<div class="col-md-2">
</div>
</div>
</div>
</div>
<div class="footer-dark">
<footer>
<div class="container">
<p class="copyright">Valerijs Diks @ 2017/2018</p>
</div>
</footer>
</div>
</body>
</html>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/post.js"></script>
<script src="assets/js/pictureRender.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/aos/2.1.1/aos.js"></script>