170 lines
7.7 KiB
PHP
170 lines
7.7 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.'); ?>">
|
|
|
|
<!-- Open Graph / Facebook -->
|
|
<meta property="og:type" content="website">
|
|
<meta property="og:title" content="<?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Web Directory'); ?>">
|
|
<meta property="og:description" content="<?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'A public web directory of curated links.'); ?>">
|
|
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
|
|
|
|
<!-- Twitter -->
|
|
<meta property="twitter:card" content="summary_large_image">
|
|
<meta property="twitter:title" content="<?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Web Directory'); ?>">
|
|
<meta property="twitter:description" content="<?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'A public web directory of curated links.'); ?>">
|
|
<meta property="twitter:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
|
|
|
|
<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();
|
|
|
|
error_log("DEBUG: GET Parameters: " . json_encode($_GET));
|
|
error_log("DEBUG: Current Category ID: " . ($current_category_id ?? "NULL"));
|
|
error_log("DEBUG: Current Category Name: " . $current_category_name);
|
|
error_log("DEBUG: SQL Query for links: " . ($current_category_id ? $link_stmt->queryString : "All Categories Query"));
|
|
error_log("DEBUG: Current Links Count: " . count($current_links));
|
|
|
|
|
|
|
|
?>
|
|
|
|
<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="container my-4">
|
|
<div class="row">
|
|
<!-- Categories Sidebar -->
|
|
<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>
|
|
|
|
<!-- Main Content -->
|
|
<div class="col-md-9">
|
|
<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']); ?>" 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>
|
|
</div>
|
|
</div>
|
|
|
|
<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>
|