183 lines
8.1 KiB
PHP
183 lines
8.1 KiB
PHP
<?php session_start(); ?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title><?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Web Directory'); ?></title>
|
|
<meta name="description" content="<?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'A public web directory of curated links.'); ?>">
|
|
|
|
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@300;400;700&family=Zen+Old+Mincho:wght@400;700&display=swap" rel="stylesheet">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
|
|
</head>
|
|
<body>
|
|
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$pdo = db();
|
|
|
|
// Fetch visible categories from the database
|
|
$stmt = $pdo->query("SELECT * FROM categories WHERE visibility = 1 ORDER BY display_order ASC, name ASC");
|
|
$categories = $stmt->fetchAll();
|
|
|
|
// Determine the current category
|
|
$current_category_id = null;
|
|
$current_category_name = 'All Categories';
|
|
if (isset($_GET['category']) && filter_var($_GET['category'], FILTER_VALIDATE_INT)) {
|
|
$category_id_from_get = (int)$_GET['category'];
|
|
$stmt = $pdo->prepare("SELECT id, name FROM categories WHERE id = ? AND visibility = 1");
|
|
$stmt->execute([$category_id_from_get]);
|
|
$cat = $stmt->fetch();
|
|
if ($cat) {
|
|
$current_category_id = $cat['id'];
|
|
$current_category_name = $cat['name'];
|
|
}
|
|
}
|
|
|
|
// Fetch links for the current category
|
|
$link_stmt = null;
|
|
if ($current_category_id) {
|
|
$link_stmt = $pdo->prepare(
|
|
"SELECT l.*, s.name as subcategory_name FROM links l " .
|
|
"JOIN subcategories s ON l.subcategory_id = s.id " .
|
|
"WHERE s.category_id = ? AND l.status = 'approved' ORDER BY s.name ASC, l.created_at DESC"
|
|
);
|
|
$link_stmt->execute([$current_category_id]);
|
|
} else {
|
|
$link_stmt = $pdo->query(
|
|
"SELECT l.*, s.name as subcategory_name, c.name as category_name " .
|
|
"FROM links l " .
|
|
"JOIN subcategories s ON l.subcategory_id = s.id " .
|
|
"JOIN categories c ON s.category_id = c.id " .
|
|
"WHERE l.status = 'approved' " .
|
|
"ORDER BY c.name ASC, s.name ASC, l.created_at DESC"
|
|
);
|
|
}
|
|
$current_links = $link_stmt->fetchAll();
|
|
?>
|
|
<pre style="background-color: #fdd; border: 1px solid #f99; padding: 10px; margin: 10px;">
|
|
DEBUG INFORMATION:
|
|
GET Parameters: <?php echo htmlspecialchars(json_encode($_GET, JSON_PRETTY_PRINT)); ?>
|
|
Current Category ID: <?php echo htmlspecialchars($current_category_id ?? "NULL"); ?>
|
|
Current Category Name: <?php echo htmlspecialchars($current_category_name ?? "Not Set"); ?>
|
|
Current Links Count: <?php echo htmlspecialchars(isset($current_links) ? count($current_links) : 0); ?>
|
|
Raw Query String: <?php echo htmlspecialchars($_SERVER['QUERY_STRING'] ?? 'Not Set'); ?>
|
|
SQL Query for links: <?php echo htmlspecialchars($link_stmt->queryString ?? "SQL Query not set yet."); ?>
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
<header class="header">
|
|
<h1><?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Web Directory'); ?></h1>
|
|
<div class="auth-links">
|
|
<?php if (isset($_SESSION['user_id'])): ?>
|
|
<a href="submit.php">Submit Link</a>
|
|
<?php if ($_SESSION['user_role'] === 'admin'): ?>
|
|
<a href="admin/index.php">Admin Panel</a>
|
|
<?php endif; ?>
|
|
<a href="logout.php">Logout</a>
|
|
<?php else: ?>
|
|
<a href="register.php">Register</a>
|
|
<a href="login.php">Login</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="main-wrapper container my-4">
|
|
<div class="row">
|
|
<!-- Left Column - Categories -->
|
|
<div class="col-md-3">
|
|
<aside class="category-list">
|
|
<h3>Categories</h3>
|
|
<nav class="nav flex-column">
|
|
<a class="nav-link <?php echo ($current_category_id === null) ? 'fw-bold' : ''; ?>" href="index.php">All Categories</a>
|
|
<?php foreach ($categories as $category): ?>
|
|
<a class="nav-link <?php echo ($category['id'] === $current_category_id) ? 'fw-bold' : ''; ?>" href="?category=<?php echo $category['id']; ?>">
|
|
<?php echo htmlspecialchars($category['name']); ?>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</nav>
|
|
</aside>
|
|
</div>
|
|
|
|
<!-- Center Column - Main Content -->
|
|
<div class="col-md-6">
|
|
<main class="content">
|
|
<h2><?php echo htmlspecialchars($current_category_name); ?></h2>
|
|
|
|
<?php if (empty($current_links)): ?>
|
|
<p>No links found in this category yet.</p>
|
|
<?php else: ?>
|
|
<?php
|
|
$current_category_for_display = null;
|
|
$current_subcategory = null;
|
|
foreach ($current_links as $link):
|
|
if ($current_category_id === null && isset($link['category_name']) && $link['category_name'] !== $current_category_for_display) {
|
|
$current_category_for_display = $link['category_name'];
|
|
echo '<h3>' . htmlspecialchars($current_category_for_display) . '</h3>';
|
|
$current_subcategory = null; // Reset subcategory when category changes
|
|
}
|
|
|
|
if ($link['subcategory_name'] !== $current_subcategory) {
|
|
$current_subcategory = $link['subcategory_name'];
|
|
echo '<h4>' . htmlspecialchars($current_subcategory) . '</h4>';
|
|
}
|
|
?>
|
|
<div class="link-item">
|
|
<img src="<?php echo htmlspecialchars($link['thumbnail_url']); ?>" alt="Thumbnail for <?php echo htmlspecialchars($link['title']); ?>" class="thumbnail">
|
|
<div class="link-item-body">
|
|
<div class="link-item-title">
|
|
<a href="<?php echo htmlspecialchars($link['url']); ?>" target="_blank" rel="noopener noreferrer">
|
|
<?php echo htmlspecialchars($link['title']); ?>
|
|
</a>
|
|
</div>
|
|
<a href="<?php echo htmlspecialchars($link['url']); ?>" target="_blank" rel="noopener noreferrer" class="link-item-url"><?php echo htmlspecialchars($link['url']); ?></a>
|
|
<p class="link-item-description">
|
|
<?php echo htmlspecialchars($link['description']); ?>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
|
|
</main>
|
|
</div>
|
|
|
|
<!-- Right Column -->
|
|
<div class="col-md-3">
|
|
<aside class="featured-section">
|
|
<h3>Featured Content</h3>
|
|
<div class="featured-item">
|
|
<h4>Special Link 1</h4>
|
|
<p>A description for a special featured link.</p>
|
|
<a href="#" class="btn btn-sm btn-primary">View More</a>
|
|
</div>
|
|
<div class="featured-item mt-3">
|
|
<h4>Announcement</h4>
|
|
<p>Check out our latest updates!</p>
|
|
<a href="#" class="btn btn-sm btn-secondary">Read Blog</a>
|
|
</div>
|
|
</aside>
|
|
</div>
|
|
</div>
|
|
</div><!-- /main-wrapper -->
|
|
|
|
<footer class="footer">
|
|
<p>© <?php echo date("Y"); ?> <?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Web Directory'); ?>. All Rights Reserved.</p>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
|
|
</body>
|
|
</html>
|