-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
401 lines (377 loc) · 20.5 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
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<?php
session_start();
$DATABASE_HOST = 'localhost';
$DATABASE_USER = 'root';
$DATABASE_PASS = '';
$DATABASE_NAME = 'blog_db';
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if ( mysqli_connect_errno() ) {
// If there is an error with the connection, stop the script and display the error.
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
if (isset($_SESSION['loggedin'], $_SESSION['id'])) {
// Query that retrieves the pfp_path of the currently logged-in user
if ($stmt_pfp = $con->prepare("SELECT pfp_path FROM accounts WHERE id = ?")) {
$stmt_pfp->bind_param('i', $_SESSION['id']);
$stmt_pfp->execute();
$stmt_pfp->bind_result($pfp_path);
$stmt_pfp->fetch();
$stmt_pfp->close();
$pfp_path = str_replace("../", "", $pfp_path); // Remove "../" from "../uploads/..."
}
}
// Assigns to default pfp if no pfp_path returned
if (!isset($pfp_path) || $pfp_path == "" || $pfp_path == NULL) {
$pfp_path = "img/default_user.png";
}
// LEFT JOIN Query that retrieves the 3 most recent posts and the corresponding author's pfp_path to display max 3 posts on home page
if ($stmt_latest = $con->prepare("SELECT p.post_id, p.creator_name, p.date, p.title, p.post_body, p.private, p.num_comments, p.img_path, a.pfp_path FROM posts p LEFT JOIN accounts a ON p.creator_id = a.id WHERE p.private = 0 ORDER BY p.date DESC LIMIT 0,3")) {
$stmt_latest->execute();
$latest = $stmt_latest->get_result();
if ($latest->num_rows > 0) {
$i = 0;
while ($row = mysqli_fetch_array($latest)) {
$results_latest[] = $row;
// If there's already an img assigned to the post, trim "../" from the path b/c index.php is in the root dir
if (isset($results_latest[$i]['img_path']) || $results_latest[$i]['img_path'] != "" || $results_latest[$i]['img_path'] != NULL) {
$results_latest[$i]['img_path'] = str_replace("../", "", $results_latest[$i]['img_path']);
}
// Assign default_user as pfp if no pfp_path returned, o.w. remove "../" from path since index.php is already in root dir
if (!isset($results_latest[$i]['pfp_path']) || $results_latest[$i]['pfp_path'] == "" || $results_latest[$i]['pfp_path'] == NULL) {
$results_latest[$i]['pfp_path'] = "img/default_user.png";
} else {
$results_latest[$i]['pfp_path'] = str_replace("../", "", $results_latest[$i]['pfp_path']);
}
$i++;
}
}
$stmt_latest->close();
} else {
echo "failed query1";
}
$con->close();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Tol Project</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="all,follow">
<!-- Bootstrap CSS-->
<link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
<!-- Font Awesome CSS-->
<link rel="stylesheet" href="vendor/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css">
<!-- Custom icon font-->
<link rel="stylesheet" href="css/fontastic.css">
<!-- Google fonts - Open Sans-->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700">
<!-- Fancybox-->
<link rel="stylesheet" href="vendor/@fancyapps/fancybox/jquery.fancybox.min.css">
<!-- theme stylesheet-->
<link rel="stylesheet" href="css/style.default.css" id="theme-stylesheet">
<!-- Custom stylesheet - for your changes-->
<link rel="stylesheet" href="css/custom.css">
<!-- Favicon-->
<link rel="shortcut icon" href="../favicon.png">
<!-- Tweaks for older IEs--><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
</head>
<body>
<header class="header">
<!-- Main Navbar-->
<nav class="navbar navbar-expand-lg">
<div class="search-area">
<div class="search-area-inner d-flex align-items-center justify-content-center">
<div class="close-btn"><i class="icon-close"></i></div>
<div class="row d-flex justify-content-center">
<div class="col-md-8">
<form action="#">
<div class="form-group">
<input type="search" name="search" id="search" placeholder="What are you looking for?">
<button type="submit" class="submit"><i class="icon-search-1"></i></button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="container">
<!-- Navbar Brand -->
<div class="navbar-header d-flex align-items-center justify-content-between">
<!-- Navbar Brand --><a href="index.php" class="navbar-brand">PROJECT TOL</a>
<!-- Toggle Button-->
<button type="button" data-toggle="collapse" data-target="#navbarcollapse" aria-controls="navbarcollapse" aria-expanded="false" aria-label="Toggle navigation" class="navbar-toggler"><span></span><span></span><span></span></button>
</div>
<!-- Navbar Menu -->
<div id="navbarcollapse" class="collapse navbar-collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a href="index.php" class="nav-link active">Home</a></li>
<li class="nav-item"><a href="php/blog.php" class="nav-link ">Blog</a></li>
<!-- <li class="nav-item"><a href="php/post.php" class="nav-link ">Post</a></li> -->
<?php if (isset($_SESSION['loggedin']) && isset($_SESSION['name'])): ?>
<li class="nav-item"><a href="php/yourPosts.php" class="nav-link">Your Posts</a></li>
<li class="nav-item"><a href="php/newPost.php" class="nav-link "><i class="far fa-plus-square"></i> New Post</a></li>
<li class="nav-item"><a href="php/profile.php" class="nav-link">
<div class="avatar" style="display: inline-block; width:25px; height: 25px;"><img src="<?php echo $pfp_path; ?>" alt="..." class="avatar rounded-circle img-fluid"></div>
<?php echo substr($_SESSION['name'], 0, 15); ?></a>
</li>
<li class="nav-item"><a href="php/logout.php" class="nav-link"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
<?php elseif(!isset($_SESSION['loggedin']) || !isset($_SESSION['name'])): ?>
<li class="nav-item"><a href="php/login.php" class="nav-link ">Login</a></li>
<?php endif; ?>
</ul>
<div class="navbar-text"><a href="php/#" class="search-btn"><i class="icon-search-1"></i></a></div>
<!-- <ul class="langs navbar-text"><a href="#" class="active">EN</a><span> </span><a href="#">ES</a></ul> -->
</div>
</div>
</nav>
</header>
<!-- Hero Section-->
<section style="background: url(img/mountains.jpg); background-size: cover; background-position: center center" class="hero">
<div class="container">
<div class="row">
<div class="col-lg-7">
<h1>PROJECT TOL</h1>
<a href=".intro" class="hero-link link-scroll">Discover More <i class="fas fa-arrow-down"></i></a>
</div>
</div>
<!-- <a href=".intro" class="continue link-scroll"><i class="fas fa-arrow-down"></i> Scroll Down</a> -->
</div>
</section>
<!-- Intro Section-->
<section class="intro">
<div class="container">
<div class="row">
<div class="col-lg-8">
<h2 class="h3">PROJECT TOL (Tree of Life) - A Place to Share and for Knowledge to Grow</h2>
<p class="text-big">This blog was developed primarily for my younger sister for the purpose of allowing her to write daily journals. The blog is developed
using PHP 7, MySQL, HTML 5, and CSS 3 (Bootstrap).
<br/><br/>
Currently, the blog enables users to write public/private postings (w/ images attached) as well as
<strong>log-in authentication, account creation, password reset via an emailed link following SMTP</strong> and many other cool features!
<br/>
</p>
</div>
</div>
</div>
</section>
<section class="featured-posts no-padding-top">
<div class="container">
<header>
<h2>Latest from the blog</h2>
<p class="text-big">Just the latest of the many posts on this blog</p>
</header>
<?php
for ($i = 0; $i < sizeof($results_latest); $i++) { ?>
<!-- Post-->
<div class="row d-flex align-items-stretch">
<?php if ($i % 2 != 0) { ?>
<div class="image col-lg-5">
<a href="php/post.php?post_id=<?php echo $results_latest[$i]['post_id']; ?>&publicPost=1">
<img src="<?php if (!isset($results_latest[$i]['img_path']) || $results_latest[$i]['img_path'] == "" || $results_latest[$i]['img_path'] == NULL) { $results_latest[$i]['img_path'] = "uploads/default.jpeg"; echo $results_latest[$i]['img_path']; } else { echo $results_latest[$i]['img_path']; } ?>" alt="..." class="img-fluid">
</a>
</div> <?php
} ?>
<div class="text col-lg-7">
<div class="text-inner d-flex align-items-center">
<div class="content">
<header class="post-header">
<!-- <div class="category"><a href="#">Business</a><a href="#">Technology</a></div><a href="post.html"> -->
<h2 class="h4">
<a href="php/post.php?post_id=<?php echo $results_latest[$i]['post_id']; ?>&publicPost=1">
<?php echo $results_latest[$i]['title']; ?>
</a>
</h2>
</header>
<p><?php if (strlen($results_latest[$i]['post_body']) < 100) { echo $results_latest[$i]['post_body']; } else { echo substr($results_latest[$i]['post_body'], 0, 100) . "..."; } ?></p>
<footer class="post-footer d-flex align-items-center"><a href="#" class="author d-flex align-items-center flex-wrap">
<div class="avatar">
<img src="<?php echo $results_latest[$i]['pfp_path']; ?>" alt="..." class="img-fluid">
</div>
<div class="title"><span><?php echo $results_latest[$i]['creator_name']; ?></span></div></a>
<div class="date"><i class="icon-clock"></i> <?php echo date_format(date_create($results_latest[$i]['date']), "d-M | Y"); ?></div>
<div class="comments"><i class="icon-comment"></i><?php echo $results_latest[$i]['num_comments']; ?></div>
</footer>
</div>
</div>
</div>
<?php if ($i % 2 == 0) { ?>
<div class="image col-lg-5">
<a href="php/post.php?post_id=<?php echo $results_latest[$i]['post_id']; ?>&publicPost=1">
<img src="<?php if (!isset($results_latest[$i]['img_path']) || $results_latest[$i]['img_path'] == "" || $results_latest[$i]['img_path'] == NULL) { $results_latest[$i]['img_path'] = "uploads/default.jpeg"; echo $results_latest[$i]['img_path']; } else { echo $results_latest[$i]['img_path']; } ?>" alt="..." class="img-fluid">
</a>
</div> <?php
} ?>
</div> <?php
}
?>
</div>
</section>
<!-- Divider Section-->
<!-- <section style="background: url(img/divider-bg.jpg); background-size: cover; background-position: center bottom" class="divider">
<div class="container">
<div class="row">
<div class="col-md-7">
<h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua</h2><a href="#" class="hero-link">View More</a>
</div>
</div>
</div>
</section> -->
<!-- Latest Posts -->
<!-- <section class="latest-posts">
<div class="container">
<header>
<h2>Latest from the blog</h2>
<p class="text-big">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</header>
<div class="row">
<div class="post col-md-4">
<div class="post-thumbnail"><a href="post.html"><img src="img/blog-1.jpg" alt="..." class="img-fluid"></a></div>
<div class="post-details">
<div class="post-meta d-flex justify-content-between">
<div class="date">20 May | 2016</div>
<div class="category"><a href="#">Business</a></div>
</div><a href="post.html">
<h3 class="h4">Ways to remember your important ideas</h3></a>
<p class="text-muted">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore.</p>
</div>
</div>
<div class="post col-md-4">
<div class="post-thumbnail"><a href="post.html"><img src="img/blog-2.jpg" alt="..." class="img-fluid"></a></div>
<div class="post-details">
<div class="post-meta d-flex justify-content-between">
<div class="date">20 May | 2016</div>
<div class="category"><a href="#">Technology</a></div>
</div><a href="post.html">
<h3 class="h4">Diversity in Engineering: Effect on Questions</h3></a>
<p class="text-muted">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore.</p>
</div>
</div>
<div class="post col-md-4">
<div class="post-thumbnail"><a href="post.html"><img src="img/blog-3.jpg" alt="..." class="img-fluid"></a></div>
<div class="post-details">
<div class="post-meta d-flex justify-content-between">
<div class="date">20 May | 2016</div>
<div class="category"><a href="#">Financial</a></div>
</div><a href="post.html">
<h3 class="h4">Alberto Savoia Can Teach You About Interior</h3></a>
<p class="text-muted">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore.</p>
</div>
</div>
</div>
</div>
</section> -->
<!-- Newsletter Section-->
<!-- <section class="newsletter no-padding-top">
<div class="container">
<div class="row">
<div class="col-md-6">
<h2>Subscribe to Newsletter</h2>
<p class="text-big">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<div class="col-md-8">
<div class="form-holder">
<form action="#">
<div class="form-group">
<input type="email" name="email" id="email" placeholder="Type your email address">
<button type="submit" class="submit">Subscribe</button>
</div>
</form>
</div>
</div>
</div>
</div>
</section> -->
<!-- Gallery Section-->
<!-- <section class="gallery no-padding">
<div class="row">
<div class="mix col-lg-3 col-md-3 col-sm-6">
<div class="item"><a href="img/gallery-1.jpg" data-fancybox="gallery" class="image"><img src="img/gallery-1.jpg" alt="..." class="img-fluid">
<div class="overlay d-flex align-items-center justify-content-center"><i class="icon-search"></i></div></a></div>
</div>
<div class="mix col-lg-3 col-md-3 col-sm-6">
<div class="item"><a href="img/gallery-2.jpg" data-fancybox="gallery" class="image"><img src="img/gallery-2.jpg" alt="..." class="img-fluid">
<div class="overlay d-flex align-items-center justify-content-center"><i class="icon-search"></i></div></a></div>
</div>
<div class="mix col-lg-3 col-md-3 col-sm-6">
<div class="item"><a href="img/gallery-3.jpg" data-fancybox="gallery" class="image"><img src="img/gallery-3.jpg" alt="..." class="img-fluid">
<div class="overlay d-flex align-items-center justify-content-center"><i class="icon-search"></i></div></a></div>
</div>
<div class="mix col-lg-3 col-md-3 col-sm-6">
<div class="item"><a href="img/gallery-4.jpg" data-fancybox="gallery" class="image"><img src="img/gallery-4.jpg" alt="..." class="img-fluid">
<div class="overlay d-flex align-items-center justify-content-center"><i class="icon-search"></i></div></a></div>
</div>
</div>
</section> -->
<!-- Page Footer-->
<footer class="main-footer">
<div class="container">
<div class="row">
<div class="col-md-4">
<ul class="list-inline social-buttons">
<li class="list-inline-item">
Developer Contact:
</li>
<li class="list-inline-item">
<a href="https://github.com/JacksonYuanjx" target="_blank">
<i class="fab fa-github"></i>
</a>
</li>
<li class="list-inline-item">
<a href="https://www.linkedin.com/in/jackson-yuan/" target="_blank">
<i class="fab fa-linkedin-in"></i>
</a>
</li>
<li class="list-inline-item">
<a href="mailto:jacksonyuanjx@hotmail.com?subject=Contact Request">
<i class="fas fa-envelope"></i>
</a>
</li>
</ul>
</div>
<!-- <div class="col-md-4">
<div class="latest-posts"><a href="#">
<div class="post d-flex align-items-center">
<div class="image"><img src="img/small-thumbnail-1.jpg" alt="..." class="img-fluid"></div>
<div class="title"><strong>Hotels for all budgets</strong><span class="date last-meta">October 26, 2016</span></div>
</div></a><a href="#">
<div class="post d-flex align-items-center">
<div class="image"><img src="img/small-thumbnail-2.jpg" alt="..." class="img-fluid"></div>
<div class="title"><strong>Great street atrs in London</strong><span class="date last-meta">October 26, 2016</span></div>
</div></a><a href="#">
<div class="post d-flex align-items-center">
<div class="image"><img src="img/small-thumbnail-3.jpg" alt="..." class="img-fluid"></div>
<div class="title"><strong>Best coffee shops in Sydney</strong><span class="date last-meta">October 26, 2016</span></div>
</div></a></div>
</div> -->
</div>
</div>
<div class="copyrights">
<div class="container">
<div class="row">
<div class="col-md-6">
<p>© 2019. All rights reserved. PROJECT TOL</p>
</div>
<div class="col-md-6 text-right">
<p>Template By <a href="https://bootstraptemple.com" class="text-white">Bootstrap Temple</a>
<!-- Please do not remove the backlink to Bootstrap Temple unless you purchase an attribution-free license @ Bootstrap Temple or support us at http://bootstrapious.com/donate. It is part of the license conditions. Thanks for understanding :) -->
</p>
</div>
</div>
</div>
</div>
</footer>
<!-- Javascript files-->
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"> </script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="vendor/jquery.cookie/jquery.cookie.js"> </script>
<script src="vendor/@fancyapps/fancybox/jquery.fancybox.min.js"></script>
<script src="js/front.js"></script>
</body>
</html>