-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
304 lines (278 loc) · 13.6 KB
/
index.php
File metadata and controls
304 lines (278 loc) · 13.6 KB
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
<?php
/**
* BLOG HUT - Landing Page
*/
// Start session
session_start();
// Include required files
require_once 'config/database.php';
require_once 'config/constants.php';
require_once 'includes/helper.php';
require_once 'includes/post_function.php';
// Fetch data for landing page
try {
// Get trending posts
$trendingPosts = getTrendingPosts(3);
// Get latest posts
$latestPosts = getLatestPosts(6);
// Get all categories
$categories = getAllCategories();
// Get site statistics
$statsQuery = "SELECT
(SELECT COUNT(*) FROM users) as total_users,
(SELECT COUNT(*) FROM blogPost WHERE status = 'published') as total_posts,
(SELECT COUNT(*) FROM comments) as total_comments,
(SELECT COUNT(*) FROM categories) as total_categories";
$stats = fetchOne($statsQuery);
} catch (Exception $e) {
error_log("Index Page Error: " . $e->getMessage());
$trendingPosts = [];
$latestPosts = [];
$categories = [];
$stats = ['total_users' => 0, 'total_posts' => 0, 'total_comments' => 0, 'total_categories' => 0];
}
// Set page title
$pageTitle = SITE_NAME . ' - ' . SITE_TAGLINE;
$pageDescription = SITE_DESCRIPTION;
?>
<?php include 'includes/header.php'; ?>
<!-- Hero Section -->
<section class="hero-section">
<div class="container">
<div class="row align-items-center min-vh-75">
<div class="col-lg-6" data-aos="fade-right">
<h1 class="display-3 fw-bold mb-4">
Share Your <span class="text-primary">Stories</span>, <br>
Inspire The World
</h1>
<p class="lead text-muted mb-4">
Join our community of writers, creators, and storytellers.
Start your blogging journey today and connect with readers worldwide.
</p>
<div class="d-flex gap-3 flex-wrap">
<?php if (isLoggedIn()): ?>
<a href="<?php echo SITE_URL; ?>/posts/create_blog.php" class="btn btn-primary btn-lg">
<i class="fas fa-pen me-2"></i> Start Writing
</a>
<a href="<?php echo SITE_URL; ?>/posts/home.php" class="btn btn-outline-primary btn-lg">
<i class="fas fa-book-open me-2"></i> Explore Blogs
</a>
<?php else: ?>
<a href="<?php echo SITE_URL; ?>/auth/register.php" class="btn btn-primary btn-lg">
<i class="fas fa-user-plus me-2"></i> Get Started
</a>
<a href="<?php echo SITE_URL; ?>/posts/home.php" class="btn btn-outline-primary btn-lg">
<i class="fas fa-book-open me-2"></i> Browse Blogs
</a>
<?php endif; ?>
</div>
</div>
<div class="col-lg-6 mt-5 mt-lg-0" data-aos="fade-left">
<div class="hero-image-wrapper">
<img src="<?php echo IMAGES_URL; ?>/hero-bg.jpg"
alt="Blog Hut Hero"
class="img-fluid rounded-4 shadow-lg"
onerror="this.src='https://via.placeholder.com/600x400/FFB100/FFFFFF?text=Blog+Hut'">
</div>
</div>
</div>
</div>
</section>
<!-- Statistics Section -->
<section class="py-5 bg-primary text-white">
<div class="container">
<div class="row text-center g-4">
<div class="col-6 col-md-3" data-aos="fade-up" data-aos-delay="100">
<div class="stat-item">
<i class="fas fa-users fa-2x mb-3"></i>
<h2 class="fw-bold mb-0"><?php echo number_format($stats['total_users']); ?>+</h2>
<p class="mb-0">Writers</p>
</div>
</div>
<div class="col-6 col-md-3" data-aos="fade-up" data-aos-delay="200">
<div class="stat-item">
<i class="fas fa-blog fa-2x mb-3"></i>
<h2 class="fw-bold mb-0"><?php echo number_format($stats['total_posts']); ?>+</h2>
<p class="mb-0">Blog Posts</p>
</div>
</div>
<div class="col-6 col-md-3" data-aos="fade-up" data-aos-delay="300">
<div class="stat-item">
<i class="fas fa-comments fa-2x mb-3"></i>
<h2 class="fw-bold mb-0"><?php echo number_format($stats['total_comments']); ?>+</h2>
<p class="mb-0">Comments</p>
</div>
</div>
<div class="col-6 col-md-3" data-aos="fade-up" data-aos-delay="400">
<div class="stat-item">
<i class="fas fa-tags fa-2x mb-3"></i>
<h2 class="fw-bold mb-0"><?php echo number_format($stats['total_categories']); ?>+</h2>
<p class="mb-0">Categories</p>
</div>
</div>
</div>
</div>
</section>
<!-- Trending Posts Section -->
<?php if (!empty($trendingPosts)): ?>
<section class="py-5">
<div class="container">
<div class="text-center mb-5" data-aos="fade-up">
<h2 class="fw-bold mb-3">
<i class="fas fa-fire text-danger me-2"></i> Trending Now
</h2>
<p class="text-muted">Most popular posts from our community</p>
</div>
<div class="row g-4">
<?php foreach ($trendingPosts as $index => $post): ?>
<div class="col-md-4" data-aos="fade-up" data-aos-delay="<?php echo ($index + 1) * 100; ?>">
<div class="card post-card h-100 border-0 shadow-sm">
<?php if ($post['featured_image']): ?>
<img src="<?php echo POST_IMAGE_URL . '/' . $post['featured_image']; ?>"
class="card-img-top"
alt="<?php echo e($post['title']); ?>"
style="height: 200px; object-fit: cover;"
onerror="this.src='https://via.placeholder.com/400x200/FFB100/FFFFFF?text=Blog+Image'">
<?php endif; ?>
<div class="card-body">
<div class="d-flex align-items-center mb-2">
<img src="<?php echo AVATAR_URL . '/' . ($post['profile_image'] ?? DEFAULT_AVATAR); ?>"
alt="<?php echo e($post['username']); ?>"
class="rounded-circle me-2"
style="width: 30px; height: 30px; object-fit: cover;">
<small class="text-muted"><?php echo e($post['username']); ?></small>
<small class="text-muted ms-auto">
<i class="fas fa-clock me-1"></i>
<?php echo timeAgo($post['created_at']); ?>
</small>
</div>
<h5 class="card-title">
<a href="<?php echo SITE_URL; ?>/posts/view_blog.php?id=<?php echo $post['id']; ?>"
class="text-decoration-none text-dark">
<?php echo e(truncate($post['title'], 60)); ?>
</a>
</h5>
<p class="card-text text-muted small">
<?php echo e(truncate(strip_tags($post['summary'] ?? $post['content']), 100)); ?>
</p>
<div class="d-flex justify-content-between align-items-center">
<div class="post-meta small text-muted">
<span class="me-3">
<i class="fas fa-eye me-1"></i> <?php echo number_format($post['views']); ?>
</span>
<span class="me-3">
<i class="fas fa-heart me-1"></i> <?php echo $post['reaction_count']; ?>
</span>
<span>
<i class="fas fa-comment me-1"></i> <?php echo $post['comment_count']; ?>
</span>
</div>
<a href="<?php echo SITE_URL; ?>/posts/view_blog.php?id=<?php echo $post['id']; ?>"
class="btn btn-sm btn-outline-primary">
Read More
</a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</section>
<?php endif; ?>
<!-- Categories Section -->
<?php if (!empty($categories)): ?>
<section class="py-5 bg-light">
<div class="container">
<div class="text-center mb-5" data-aos="fade-up">
<h2 class="fw-bold mb-3">
<i class="fas fa-th-large me-2"></i> Explore Categories
</h2>
<p class="text-muted">Discover content that interests you</p>
</div>
<div class="row g-3">
<?php foreach (array_slice($categories, 0, 8) as $index => $category): ?>
<div class="col-6 col-md-4 col-lg-3" data-aos="zoom-in" data-aos-delay="<?php echo ($index + 1) * 50; ?>">
<a href="<?php echo SITE_URL; ?>/posts/home.php?category=<?php echo $category['id']; ?>"
class="category-card text-decoration-none">
<div class="card border-0 shadow-sm h-100 text-center p-3">
<div class="card-body">
<i class="fas fa-tag fa-2x text-primary mb-2"></i>
<h6 class="mb-0"><?php echo e($category['name']); ?></h6>
</div>
</div>
</a>
</div>
<?php endforeach; ?>
</div>
</div>
</section>
<?php endif; ?>
<!-- Latest Posts Section -->
<?php if (!empty($latestPosts)): ?>
<section class="py-5">
<div class="container">
<div class="text-center mb-5" data-aos="fade-up">
<h2 class="fw-bold mb-3">
<i class="fas fa-clock me-2"></i> Latest Stories
</h2>
<p class="text-muted">Fresh content from our writers</p>
</div>
<div class="row g-4">
<?php foreach ($latestPosts as $index => $post): ?>
<div class="col-md-6 col-lg-4" data-aos="fade-up" data-aos-delay="<?php echo ($index + 1) * 100; ?>">
<div class="card post-card h-100 border-0 shadow-sm">
<?php if ($post['featured_image']): ?>
<img src="<?php echo POST_IMAGE_URL . '/' . $post['featured_image']; ?>"
class="card-img-top"
alt="<?php echo e($post['title']); ?>"
style="height: 180px; object-fit: cover;"
onerror="this.src='https://via.placeholder.com/400x180/FFB100/FFFFFF?text=Blog+Image'">
<?php endif; ?>
<div class="card-body">
<div class="d-flex align-items-center mb-2">
<img src="<?php echo AVATAR_URL . '/' . ($post['profile_image'] ?? DEFAULT_AVATAR); ?>"
alt="<?php echo e($post['username']); ?>"
class="rounded-circle me-2"
style="width: 30px; height: 30px; object-fit: cover;">
<small class="text-muted"><?php echo e($post['username']); ?></small>
</div>
<h5 class="card-title">
<a href="<?php echo SITE_URL; ?>/posts/view_blog.php?id=<?php echo $post['id']; ?>"
class="text-decoration-none text-dark">
<?php echo e(truncate($post['title'], 60)); ?>
</a>
</h5>
<p class="card-text text-muted small">
<?php echo timeAgo($post['created_at']); ?>
</p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="text-center mt-5" data-aos="fade-up">
<a href="<?php echo SITE_URL; ?>/posts/home.php" class="btn btn-primary btn-lg">
<i class="fas fa-arrow-right me-2"></i> View All Posts
</a>
</div>
</div>
</section>
<?php endif; ?>
<!-- Call to Action Section -->
<section class="py-5 bg-primary text-white">
<div class="container text-center" data-aos="fade-up">
<h2 class="fw-bold mb-3">Ready to Share Your Story?</h2>
<p class="lead mb-4">Join thousands of writers and start your blogging journey today</p>
<?php if (isLoggedIn()): ?>
<a href="<?php echo SITE_URL; ?>/posts/create_blog.php" class="btn btn-light btn-lg">
<i class="fas fa-pen me-2"></i> Create Your First Post
</a>
<?php else: ?>
<a href="<?php echo SITE_URL; ?>/auth/register.php" class="btn btn-light btn-lg">
<i class="fas fa-user-plus me-2"></i> Sign Up Free
</a>
<?php endif; ?>
</div>
</section>
<?php include 'includes/footer.php'; ?>