forked from Hostname47/PHP-CHAT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-viewer.php
290 lines (255 loc) · 11.8 KB
/
post-viewer.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
require_once "vendor/autoload.php";
require_once "core/init.php";
use classes\{DB, Config, Validation, Common, Session, Token, Hash, Redirect, Cookie};
use models\{Post, User, Comment, Like};
use layouts\post\Post as Post_View;
if(!$user->getPropertyValue("isLoggedIn")) {
Redirect::to("login/login.php");
}
require_once "functions/sanitize_id.php";
$pid = null;
if(isset($_GET["pid"])) {
$pid = sanitize_id($_GET["pid"]);
} else {
// Redirect user to post not found page
Redirect::to(Config::get("root/path") . "page_parts/errors/404.php");
}
$current_user_id = $user->getPropertyValue("id");
$post = new Post();
$post->fetchPost($pid);
$post_owner_id = $post->get_property("post_owner");
$post_owner = new User();
$post_owner->fetchUser("id", $post_owner_id);
$post_owner_picture = $root . (empty($post_owner->getPropertyValue("picture")) ? "public/assets/images/logos/logo512.png" : $post_owner->getPropertyValue("picture"));
$post_owner_fullname = $post_owner->getPropertyValue("firstname") . " " . $post_owner->getPropertyValue("lastname");
$post_owner_username = $post_owner->getPropertyValue("username");
$post_date = $post->get_property("post_date");
$post_date = date("F d \a\\t Y h:i A",strtotime($post_date));
$post_visibility_image_path = "";
if($post->get_property("post_visibility") == 1) {
$post_visibility_image_path = "public";
} else if($post->get_property("post_visibility") == 2) {
$post_visibility_image_path = "friends";
} else {
$post_visibility_image_path = "lock";
}
$post_text_data = $post->get_property("text_content");
// Get images
$poster_image_directory = $post->get_property("picture_media");
$root = Config::get("root/path");
$project_name = Config::get("root/project_name");
$project_path = $_SERVER['DOCUMENT_ROOT'] . "/" . $project_name . "/";
$post_images_dir = $project_path . $post->get_property("picture_media");
$post_text_content = htmlspecialchars_decode($post->get_property("text_content"));
$images = "";
if(is_dir($post_images_dir)) {
if(is_dir_empty($post_images_dir) == false) {
$fileSystemIterator = new \FilesystemIterator($post_images_dir);
foreach ($fileSystemIterator as $fileInfo){
$fileName = $root . $poster_image_directory . $fileInfo->getFilename();
$images .= "<input type='hidden' value='$fileName' class='post-asset-image'>";
}
$images .= "<input type='hidden' value='0' class='current-asset-image'>";
}
}
$post_meta_like = <<<LM
<div class="no-display post-meta-likes post-meta"><span class="meta-count">0</span>Likes</div>
LM;
$post_meta_comment = <<<CM
<div class="no-display post-meta-comments post-meta"><span class="meta-count">0</span>Comments</div>
CM;
$post_meta_share = <<<SM
<div class="no-display post-meta-shares post-meta"><span class="meta-count">0</span>Shares</div>
SM;
$ce = $se = "";
// Comment meta
$pmc = count(Comment::fetch_post_comments($pid));
if($pmc == 0) {
$ce = "no-display";
}
// Like
$like_manager = new Like();
$likes_count = count($like_manager->get_post_users_likes_by_post($pid));
$lk = "like-black-filled.png";
if($likes_count == 0) {
$likes_count = "";
$lk = "like-black.png";
}
$like_text_state = "Like";
$like_manager->setData(array(
"user_id"=>$user->getPropertyValue("id"),
"post_id"=>$pid
));
$like_image = "like-black.png";
if($like_manager->exists()) {
$like_text_state = "Liked";
$like_image = "like-black-filled.png";
}
// Share
$shares = Post::get_post_share_numbers($pid);
if($shares == 0) {
$se = "no-display";
}
$current_user_picture = $root . (empty($user->getPropertyValue("picture")) ? "public/assets/images/logos/logo512.png" : $user->getPropertyValue("picture"));
function is_dir_empty($dir) {
return (count(glob("$dir/*")) === 0); // empty
}
function str_replace_first($search, $replace, $subject) {
$pos = strpos($subject, $search);
if ($pos !== false) {
return substr_replace($subject, $replace, $pos, strlen($search));
}
return $subject;
}
/*if(!is_dir($poster_image_directory)) {
exit('Invalid diretory path');
}
/*$files = array();
foreach (scandir($directory) as $file) {
if ($file !== '.' && $file !== '..') {
$files[] = $file;
}
}*/
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>V01D47</title>
<link rel='shortcut icon' type='image/x-icon' href='public/assets/images/favicons/favicon.ico' />
<link rel="stylesheet" href="public/css/header.css">
<link rel="stylesheet" href="public/css/global.css">
<link rel="stylesheet" href="public/css/post.css">
<link rel="stylesheet" href="public/css/post-viewer.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="public/javascript/config.js" defer></script>
<script src="public/javascript/post.js" defer></script>
<script src="public/javascript/post-viewer.js" defer></script>
<script src="public/javascript/global.js" defer></script>
</head>
<body>
<?php include_once "page_parts/basic/header.php"; ?>
<main>
<div class="notification-bottom-container">
<p class="notification-bottom-sentence">THIS IS TEST</p>
</div>
<?php // Redirect to Post not found page ?>
<div id="post-viewer" class="post-item">
<div class="images">
<?php echo $images; ?>
</div>
<div id="post-assets-container" class="relative">
<div id="asset-wrapper">
<img src="" class="asset-image" alt="">
</div>
<div class="asset-back asset-move-button">
</div>
<div class="asset-next asset-move-button">
</div>
<div class="exit-button">
</div>
</div>
<div id="post-info" class="relative">
<!-- post owner header -->
<div class="flex">
<div class="flex">
<div class="poster-image-container">
<a href=""><img src="<?php echo $post_owner_picture ?>" class="poster-image" alt=""></a>
</div>
<div style="margin-left: 6px;">
<a href="http://127.0.0.1/CHAT/profile.php?username=<?php echo $post_owner_username; ?>" class="post-owner-name"><?php echo $post_owner_fullname; ?> -@<?php echo $post_owner_username ?></a>
<div class="row-v-flex">
<p class="regular-text"><a href="" class="post-date"><?php echo $post_date; ?></a> <span style="font-size: 14px; color: rgb(78, 78, 78);">.</span></p>
<img src="public/assets/images/icons/<?php echo $post_visibility_image_path; ?>.png" class="image-style-8" alt="" style="margin-left: 8px">
</div>
</div>
</div>
<div class="right-pos-margin relative">
<a href="" class="black-more-button button-with-suboption"></a>
<div class="sub-options-container sub-options-container-style-2">
<div class="options-container-style-1">
<div class="sub-option-style-2 save-post-button">
<p for="" class="regular-text margintb4 padding-back-style-1 save-back">Save post</p>
</div>
<div class="sub-option-style-2 download-post-button">
<p for="" class="regular-text margintb4 padding-back-style-1 download-back">Download</p>
</div>
<div class="sub-option-style-2 full-screen-post">
<p for="" class="regular-text margintb4 padding-back-style-1 full-screen-black-back">Enter full-screen</p>
</div>
</div>
</div>
</div>
</div>
<!-- post text -->
<div>
<div style="margin-top: 8px">
<span class="hidden-post-text no-display"><?php echo $post_text_data; ?></span>
<span class="post-text"><?php echo $post_text_data; ?></span>
<div class="collapse-text">See more</div>
</div>
</div>
<!-- post reactions number, comments and shares -->
<div style="margin-top: 14px" class="flex">
<div class="pointer list-liked-people row-v-flex">
<img src="public/assets/images/icons/like-black.png" class="like-friends-btn reaction-button-image" alt="">
<p class="regular-text-style-2 bold like-counter"><?php echo $likes_count; ?></p>
</div>
<div class="right-pos-margin flex">
<div style="margin-right: 6px" class="pointer hover-underline <?php echo $ce ?> noc-container"><span class="num-of-comments regular-text"><?php echo $pmc ?></span>Comments</div>
<div class="pointer hover-underline nos-container <?php echo $se ?>"><span class="num-of-shares regular-text"><?php echo $shares; ?></span>shares</div>
</div>
</div>
<div class="reaction-box">
<div class="pointer like row-v-flex reaction-button">
<img src="public/assets/images/icons/<?php echo $like_image; ?>" class="reaction-button-image like-button-image" alt="">
<a class="regular-text-style-2 bold like-text-state"><?php echo $like_text_state ?></a>
</div>
<div class="pointer row-v-flex reaction-button comment" style="flex: 4">
<img src="public/assets/images/icons/black-comment.png" class="reaction-button-image comment-button-image" alt="">
<a class="regular-text-style-2 bold">Comment</a>
</div>
<div class="relative share-button-container">
<div class="pointer row-v-flex reaction-button share">
<img src="public/assets/images/icons/reply-black.png" class="reaction-button-image share-button-image" alt="">
<a class="regular-text-style-2 bold">Share</a>
</div>
<div class="share-animation-container flex-row-column">
<div class="share-animation-outer-circle-container">
</div>
<div class="share-animation-inner-circle-container">
</div>
<div class="animation-hand">
</div>
</div>
</div>
</div>
<div class="comment-section">
<div class="comment-block owner_type_section">
<div class="comment_owner_picture_container">
<img src="<?php echo $current_user_picture ?>" class="comment_owner_picture" alt="TT">
</div>
<div class="comment-input-form-wrapper">
<form action="" method="POST" class="comment-form relative">
<input type="text" name="comment" placeholder="Write a comment .." autocomplete="off" class="comment-input-style comment-inp">
</form>
</div>
</div>
<div id="pcomments">
<?php
$comments_components = '';
foreach(Comment::fetch_post_comments($pid) as $comment) {
$cm = new Comment();
$cm->fetch_comment($comment->id);
echo Post_View::generate_comment($cm, $current_user_id);
}
?>
</div>
</div>
</div>
</div>
</main>
</body>
</html>