-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdetails.php
167 lines (141 loc) · 6.37 KB
/
details.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
<?php
require_once("bootstrap/bootstrap.php");
//Check if user session is active (Is user logged in?)
User::userLoggedIn();
// GET id of post
$id = $_GET['id'];
//var_dump($id);
// Connection
$conn = Db::getConnection();
$userId = User::getUserId();
// GET current post
$post = Image::getPostById($id);
//get the username of the user that has posted this image
$username = Image::getPostUsername($id);
$comments = Image::getCommentsByPostId($post["id"]);
// GET comments
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/cssgram.css">
<title>IMDSTAGRAM - detail page</title>
</head>
<body class="details">
<?php include_once("nav.incl.php"); ?>
<header>
</header>
<main class="feed">
<div class="postContainer">
<?php
if($userId === $post["user_id"]){
echo "<a href=\"editPost.php?id=$id\" class=\"btnEdit\" >edit post</a>";
}
?>
<!-- echo picture -->
<div class="postTopBar">
<div class="topBar--flex topBar--username">
<a href="userProfile.php?username=<?php echo htmlspecialchars($username); ?>">
<div class="postUsername"><?php echo htmlspecialchars($username); ?></div>
</a>
<p class="timeAgo"><?php echo Image::timeAgo($post['time']); ?></p>
</div>
<div class="topBar--flex topBar--report">
<?php if (User::userHasReported($post['id'], $userId) == true): ?>
<a href="#" data-id="<?php echo $post['id'] ?>" class="inappropriate inappropriatedLink">
<img src="images/report.svg" alt="grey button" class="inappropriateIcon">
</a>
<?php else: ?>
<a href="#" data-id="<?php echo $post['id'] ?>" class="inappropriate">
<img src="images/report.svg" alt="red button" class="inappropriateIcon">
</a>
<?php endif ?>
</div>
</div>
<p class="postLocation"><?php echo htmlspecialchars($post['city']); ?></p>
<!-- echo picture -->
<div class="detailsFilter">
<div class="<?php echo htmlspecialchars($post['filter']); ?>">
<img src="images/<?php echo htmlspecialchars($post['url']); ?>" alt="Post picture">
</div>
</div>
<!-- echo description -->
<p><?php echo htmlspecialchars($post['description']); ?></p>
<div class="postStats">
<div>
<?php if (Like::userHasLiked($post['id'], $userId) == true) : ?>
<a href="#" data-id="<?php echo $post['id'] ?>" class="like"><img
class="icon postLikeIcon"
src="images/liked.svg"
alt="like icon"></a>
<?php else: ?>
<a href="#" data-id="<?php echo $post['id'] ?>" class="like"><img
class="icon postLikeIcon"
src="images/like.svg"
alt="like icon"></a>
<?php endif ?>
<p class="postLikes"><?php echo Like::getLikeAmount($post['id']); ?></p>
</div>
<div class="colorBlock">
<a href="index.php?color=<?php echo $post['color1']; ?>"
style="background-color:<?php echo "#" . $post['color1'] ?>;" class="colorBtn">
<p><?php echo $post['color1'] ?></p></a>
<a href="index.php?color=<?php echo $post['color2']; ?>"
style="background-color:<?php echo "#" . $post['color2'] ?>;" class="colorBtn">
<p><?php echo $post['color2'] ?></p></a>
<a href="index.php?color=<?php echo $post['color3']; ?>"
style="background-color:<?php echo "#" . $post['color3'] ?>;" class="colorBtn">
<p><?php echo $post['color3'] ?></p></a>
<a href="index.php?color=<?php echo $post['color4']; ?>"
style="background-color:<?php echo "#" . $post['color4'] ?>;" class="colorBtn">
<p><?php echo $post['color4'] ?></p></a>
</div>
<div>
<p class="postComments">0<?php //echo number of comments ?></p>
<img class="icon postCommentIcon" src="images/comment.svg" alt="comments icon">
</div>
</div>
<div class="commentContainer">
<div id="commentContainer">
<?php if( !empty($comments) ){ ?>
<!-- echo comments -->
<?php foreach($comments as $comment): ?>
<div class="comments">
<!-- echo timestamp, username and comment -->
<p> <?php echo htmlspecialchars($comment['username']) . ": " . htmlspecialchars($comment['comment']) ?> </p>
</div>
<?php endforeach;?>
<?php } //Closing if
else{ //No comments ?>
<p class="postContainer">Be the first to comment!</p>
<?php } //Closing else ?>
</div>
<div id="<?php echo $id; ?>">
<input class="commentInput" type="text" name="comment" placeholder="comment...">
<!--
Change to button and don't post the form
onClick="() => sendpostmethod(<\?php echo $id; ?>)"
-->
<!-- <input class="commentBtn" type="submit" value="Post"> -->
<button class="commentBtn" type="button" data-id="<?php echo $id; ?>">send</button>
</div>
</div>
</main>
<footer>
<footer>
</footer>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="js/saveLikes.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="js/post.js"></script>
<script src="js/navigation.js"></script>
<script src="js/inappropriate.js"></script>
<script>
changePosts(<?php echo($id); ?>);
</script>
</body>
</html>