-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
191 lines (185 loc) · 9.77 KB
/
index.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
<?php
include_once(__DIR__ . "/includes/nav.php");
include_once(__DIR__ . "/classes/Post.php");
include_once(__DIR__ . "/classes/User.php");
include_once(__DIR__ . "/classes/Comment.php");
include_once(__DIR__ . "/includes/checkSession.php");
$sessionUser = User::fetchUserByUsername($_SESSION['user']);
$newComment = new Comment();
if (isset($_GET['search'])) {
try {
$posts = Post::search($_GET['search']);
} catch (Exception $e) {
$error = $e->getMessage();
}
}
try {
$posts = Post::fetchRecentPostsFromFollowing(20, 0);
} catch (Exception $e) {
$error = $e->getMessage();
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="styles/bootstrap.min.css">
<link rel="stylesheet" href="styles/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/cssgram/0.1.10/cssgram.min.css">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"/>
<title>Pixelab</title>
</head>
<body>
<div id="PostContainer">
<?php if (isset($error)): ?>
<div class="mt-5 text-center">
<h3 class="mb-3" >Welcome to Pixelab!</h3>
<p><?php echo $error ?></p>
<p>Start following people to check out their amazing desings on your feed!</p>
<a class="btn btn-primary" href="explore.php">Explore designs</a>
</div>
<?php else: ?>
<?php if (!empty($posts)) {
foreach ($posts as $post): ?>
<?php
$username = $post->getUser();
try {
$user = User::fetchUserByUsername($post->getUser());
} catch (Exception $e) {
}
?>
<div class="container-fluid shadow w-35 pt-1 pb-1 mt-5">
<!-- username and avatar:-->
<div class="row h-5">
<div class="col-auto flex-fill align-self-center text-center p-0">
<a href="./profilePage.php?user=<?php try {
echo htmlspecialchars($post->getUser());
} catch (Exception $e) {
} ?>"><?php if (!empty($user)) {
if (!empty($user->getAvatar())) : ?>
<img src="./uploads/avatars/<?php echo $user->getAvatar(); ?>" class="rounded-circle avatarIcon" alt="avatar image"/>
<?php else: ?>
<img src="./images/blank_avatar.png" class="rounded-circle avatarIcon" role='button' alt="blank avatar"/>
<?php endif;
} ?></a>
</div>
<div class="col-4 flex-fill align-self-center p-0">
<a class="text-decoration-none text-black fw-bold" href="./profilePage.php?user=<?php try {
echo htmlspecialchars($post->getUser());
} catch (Exception $e) {
} ?>"><?php echo htmlspecialchars($post->getUser()); ?></a>
</div>
<div class="col-6 d-flex flex-fill align-self-center justify-content-end timestamp-post">
<p class="mb-0"><?php echo "Posted " . $post->postedTimeAgo($post->getId()) . " ago"; ?></p>
</div>
</div>
<div class="row mb-1">
<div class="col-12">
<a href="?search=loc:<?php echo urlencode(htmlspecialchars($post->getLocation())); ?>" class="text-decoration-none text-black"><?php echo htmlspecialchars($post->getLocation()); ?></a>
</div>
</div>
<!-- post:-->
<div class="row">
<div class="col-12 text-center p-0">
<?php if (!empty($post)) {
if (!empty($post->getImage())) : ?>
<figure class="<?php echo $post->getFilter();?>">
<img class="max-w-100 min-w-100" src="./uploads/posts/<?php echo $post->getImage();?>" alt="post image">
</figure>
<?php else: ?>
<img class="max-w-100 min-w-100" src="./images/blank_post.jpg" alt="blank post image">
<?php endif;
} ?>
</div>
</div>
<!-- action buttons:-->
<div class="row d-flex pt-1">
<div class="col-1 max-w-7">
<a href="#" class="border-0 outline-none bg-none text-black btn-like"
data-postid="<?php echo $post->getId(); ?>"
data-liked="<?php echo in_array($_SESSION['user'], $post->getLikes()) ? "1" : "0"; ?>"
data-userid="<?php echo User::fetchUserByUsername($_SESSION['user'])->getId(); ?>">
<i class="fa <?php echo in_array($_SESSION['user'], $post->getLikes()) ? "fa-heart" : "fa-heart-o"; ?> btn-icon"
aria-hidden="true"></i>
</a>
</div>
<div class="col-11 d-flex justify-content-end">
<a href="#" class="border-0 outline-none bg-none text-black btn-report text-end"
data-postid="<?php echo $post->getId(); ?>"
>Report</a>
</div>
<!-- likes:-->
</div>
<div class="row pt-half">
<div class="col-12">
<span class="like-count" id="<?php echo $post->getId(); ?>">
<?php echo sizeof($post->getLikes()); ?>
</span>
<span>
likes
</span>
</div>
</div>
<!-- description:-->
<div class="row pt-half description">
<div class="col-12">
<div class="row">
<div class="col-12 pb-2">
<span class="fw-bold"><?php echo htmlspecialchars($post->getUser()); ?></span><span> <?php echo Post::interactiveDescription($post->getDescription()) ?></span>
</div>
</div>
</div>
</div>
<!-- comments:-->
<?php if (!empty($post->getComments())): ?>
<?php foreach ($post->getComments() as $comment) : ?>
<div class="row pt-half comment">
<div class="col-12 pb-2">
<div class="row">
<div class="col-12">
<span class="fw-bold"><?php echo htmlspecialchars($comment['username']); ?></span>
</div>
</div>
<div class="row">
<div class="col-12">
<span><?php echo htmlspecialchars($comment['content']); ?></span>
<span class="timestamp-comment"><?php echo Comment::timeAgo($comment['id']) . " ago"; ?></span>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
<!-- comment input field :-->
<div class="d-flex border-top-gray">
<input class="w-100 border-0 addComment py-half-rem" type="text" name="comment"
placeholder="Add a comment as <?php echo htmlspecialchars($_SESSION['user']); ?>..."
data-postid="<?php echo $post->getId(); ?>"
data-username="<?php echo htmlspecialchars($_SESSION['user']); ?>">
</div>
</div>
<?php endforeach;
} ?>
<?php endif; ?>
</div>
<?php if(sizeof(User::fetchFollowingUsernames($_SESSION['userId'])) > 0 || $sessionUser::hasPosts($_SESSION['userId'])) : ?>
<div class="d-flex justify-content-center pt-5 pb-5">
<button class="btn btn-primary m-4" data-currentpostamount="20" id="btn-loadmore">Load more</button>
</div>
<?php endif; ?>
<script src="https://use.fontawesome.com/2dd2522a24.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="js/liveCommentPost.js"></script>
<script src="js/liveLikePost.js"></script>
<script src="js/liveMorePosts.js"></script>
<script src="js/liveReportPost.js"></script>
</body>
</html>