-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
63 lines (53 loc) · 2.28 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
<?php
require_once('./includes/config.php');
require_once('./includes/functions.php');
require_once('./includes/header.php');
$page = filter_var($_GET['page'] ?? 1, FILTER_VALIDATE_INT);
$page = ($page !== false && $page > 0) ? $page : 1;
try {
$quotes = getQuotesForPage($page);
if (empty($quotes)) {
throw new Exception('No quotes found for this page.');
}
$totalPages = getTotalPages();
if ($totalPages < 1) {
throw new Exception('No pages available.');
}
} catch (Exception $e) {
error_log($e->getMessage());
// Prepare a error message to display to the user
$errorMessage = 'An error occurred while fetching quotes. Please try again later.';
// Show a more specific message based on the exception type (if needed)
if ($e->getMessage() === 'No quotes found for this page.') {
$errorMessage = 'There are no quotes available for the selected page. Please try another page.';
} elseif ($e->getMessage() === 'No pages available.') {
$errorMessage = 'No pages are available at the moment. Please try again later.';
}
// Display a user-friendly error message with an option to try again later
echo '<div class="container" style="margin-top: 80px;">
<p class="notification is-danger">' . htmlspecialchars($errorMessage, ENT_QUOTES, 'UTF-8') . '</p>
</div>';
require_once('./includes/footer.php');
exit;
}
?>
<?php foreach ($quotes as $quote): ?>
<div id="quotes-container" class="quotes-container">
<div class="quote-box">
<p class="content quote-text"><?php echo nl2br(escapeHtml($quote['content'])); ?></p>
<hr>
<a href="k/<?php echo urlencode(escapeHtml($quote['slug'])); ?>" class="button is-rounded is-danger read-more">
மேலும் வாசிக்க
</a>
</div>
</div>
<?php endforeach; ?>
<div class="pagination-container" style="margin-bottom: 50px;">
<?php if ($page > 1): ?>
<a href="?page=<?php echo $page - 1; ?>" class="pagination-button">Previous</a>
<?php endif; ?>
<?php if ($page < $totalPages): ?>
<a href="?page=<?php echo $page + 1; ?>" class="pagination-button">Next</a>
<?php endif; ?>
</div>
<?php require_once('./includes/footer.php'); ?>