-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.php
117 lines (109 loc) · 4.43 KB
/
user.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
<?php
require __DIR__.'/views/header.php';
if (isLoggedIn($_SESSION['user']['id'])) {
redirect('/');
}
//make a function for this
if (isset($_GET['id'])) {
$id = (int) $_GET['id'];
$getContent = getUser($pdo, $id);
$userPosts = getPostsByUser($id, $pdo);
} else {
redirect('/');
}
?>
<article class="profile">
<section class="profile-avatar">
<img src="<?= './app/users/avatar/'.$getContent['avatar']?>" alt="" class="avatar-img">
</section>
<section class="profile-bio">
<section class="info">
<h2>
<?= $getContent['name'] ?>
</h2>
<p>
<?= $getContent['profile_bio'] ?? ' ' ; ?>
</p>
</section>
<?php if ($_SESSION['user']['id'] == $getContent['user_id']) :?>
<section class="edit">
<a href="settings.php">Edit profile</a>
<a href="#" class="upload-btn">Upload Post</a>
</section>
<?php endif; ?>
</section>
</article>
<article class="profile message">
<?php if (isset($message)) : ?>
<p>
<?= $message ?>
</p>
<?php endif; ?>
<?php if ($getContent['image'] === null) : ?>
<p>This user has no posts yet</p>
<?php endif; ?>
</article>
<article class="profile upload">
<section class="upload-post">
<form action="./../app/posts/store.php" method="post" enctype="multipart/form-data" class="settings-form">
<input type="file" accept=".jpg" name="image" class="image">
<input type="text" name="description" class="description" placeholder="Description">
<button type="submit" name="button">Upload post</button>
</form>
</section>
</article>
<?php foreach ($userPosts as $post): ?>
<article class="posts">
<section class="header-info">
<section class="avatar-info">
<img src="./app/users/avatar/<?=$getContent['avatar']; ?>" class="user-avatar">
<form action="<?= '/user.php'; ?>" method="get">
<button type="submit" name="id" value="<?= $post['user_id']?>">
<?= $getContent['username']; ?></button>
</form>
</section>
<?php if ($_SESSION['user']['id'] == $getContent['user_id']) :?>
<section class="edit-post-button">
<button type="submit" data-id="<?= $post['id']?>"><i class="fas fa-pencil-alt"></i></button>
</section>
<?php endif; ?>
</section>
<section class="edit-post hidden" data-id="<?= $post['id']?>">
<form action="./../app/posts/update.php" method="post" enctype="multipart/form-data" class="description-form">
<label for="description">Change description</label>
<input type="text" name="description" placeholder="<?= $post['description']; ?>" value="<?= $post['description']; ?>">
<input type="hidden" name="page" value="<?='/profile.php';?>">
<button type="submit" name="id" value="<?= $post['id']; ?>">Update</button>
</form>
<form action="./../app/posts/delete.php" method="get" enctype="multipart/form-data" class="delete-form">
<input type="hidden" name="page" value="<?='/profile.php';?>">
<button type="submit" name="delete" value="<?= $post['id']; ?>"><i class="fas fa-trash-alt"></i></button>
</form>
</section>
<img src="./app/posts/uploaded/<?= $getContent['user_id'].'/'.$post['image'] ?>">
<article class="information">
<section class="description">
<p><a href="">
<?= $getContent['username'];?></a>
<?= $post['description'] ?>
</p>
<p class="time">
<?php $date = explode(' ', $post['created']); ?>
<?= $date[0];?>
</p>
</section>
<section class="likes">
<form class="like" action="./../app/likes/likes.php" method="post">
<input type="hidden" name="post_id" value="<?= $post['id'] ?>">
<p>
<?= (countPostLikes($post['id'], $pdo) > 0) ? countPostLikes($post['id'], $pdo) : ''; ?>
</p>
<button type="submit" name="likes">
<i class="<?= (checkLikedPost($post['id'], $_SESSION['user']['id'], $pdo)) ? 'fas fa-heart show' : 'far fa-heart';?>"></i>
</button>
</form>
</section>
</article>
</article>
<?php endforeach; ?>
<?php require __DIR__.'/views/footer.php'; ?>