127 lines
5.6 KiB
PHP
127 lines
5.6 KiB
PHP
<?php
|
|
session_start();
|
|
declare(strict_types=1);
|
|
@ini_set('display_errors', '1');
|
|
@error_reporting(E_ALL);
|
|
@date_default_timezone_set('UTC');
|
|
|
|
$phpVersion = PHP_VERSION;
|
|
$now = date('Y-m-d H:i:s');
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>MyTube - Video Platform</title>
|
|
<?php
|
|
// Read project preview data from environment
|
|
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
|
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
|
?>
|
|
<?php if ($projectDescription): ?>
|
|
<!-- Meta description -->
|
|
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
|
<?php endif; ?>
|
|
<?php if ($projectImageUrl): ?>
|
|
<!-- Open Graph image -->
|
|
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
|
<?php endif; ?>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">MyTube</a>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav ms-auto">
|
|
<?php if (isset($_SESSION['user_id'])): ?>
|
|
<li class="nav-item"><span class="nav-link">Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?></span></li>
|
|
<li class="nav-item"><a class="nav-link" href="upload.php">Upload Video</a></li>
|
|
<?php if (isset($_SESSION['is_admin']) && $_SESSION['is_admin']): ?>
|
|
<li class="nav-item"><a class="nav-link" href="admin.php">Admin</a></li>
|
|
<?php endif; ?>
|
|
<li class="nav-item"><a class="nav-link" href="logout.php">Logout</a></li>
|
|
<?php else: ?>
|
|
<li class="nav-item"><a class="nav-link" href="login.php">Login</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="signup.php">Sign Up</a></li>
|
|
<?php endif; ?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
<main class="container" style="padding-top: 80px;">
|
|
<div class="text-center mb-4">
|
|
<h1>Featured Videos</h1>
|
|
<p>A new place to share and watch videos.</p>
|
|
</div>
|
|
|
|
<div class="row justify-content-center my-4">
|
|
<div class="col-lg-8">
|
|
<form action="index.php" method="GET" class="d-flex">
|
|
<input class="form-control me-2" type="search" placeholder="Search for videos..." name="search" value="<?php echo isset($_GET['search']) ? htmlspecialchars($_GET['search']) : ''; ?>">
|
|
<button class="btn btn-primary" type="submit">Search</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
try {
|
|
$pdo = db();
|
|
$search_term = $_GET['search'] ?? null;
|
|
|
|
$sql = "SELECT * FROM videos WHERE status = 'approved'";
|
|
$params = [];
|
|
|
|
if ($search_term) {
|
|
$sql .= " AND (title LIKE ? OR description LIKE ?)";
|
|
$params[] = "%" . $search_term . "%";
|
|
$params[] = "%" . $search_term . "%";
|
|
}
|
|
|
|
$sql .= " ORDER BY created_at DESC";
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
while ($video = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
echo '<div class="col-md-4 mb-4">';
|
|
echo ' <div class="card h-100">';
|
|
echo ' <a href="video.php?id=' . $video['id'] . '" class="text-decoration-none text-dark">';
|
|
echo ' <img src="https://placehold.co/600x400/212529/FFFFFF?text=' . urlencode(htmlspecialchars($video['title'])) . '" class="card-img-top" alt="' . htmlspecialchars($video['title']) . '">';
|
|
echo ' <div class="card-body">';
|
|
echo ' <h5 class="card-title">' . htmlspecialchars($video['title']) . '</h5>';
|
|
echo ' <p class="card-text mb-0 small">By: ' . htmlspecialchars($video['creator']) . '</p>';
|
|
echo ' <small class="text-muted">Views: ' . htmlspecialchars($video['views']) . '</small>';
|
|
echo ' </div>';
|
|
echo ' </a>';
|
|
echo ' </div>';
|
|
echo '</div>';
|
|
}
|
|
} else {
|
|
if ($search_term) {
|
|
echo '<div class="col"><p class="text-center">No videos found matching your search for \'' . htmlspecialchars($search_term) . '\'.</p></div>';
|
|
} else {
|
|
echo '<div class="col"><p class="text-center">No approved videos available at the moment. Please check back later.</p></div>';
|
|
}
|
|
}
|
|
} catch (PDOException $e) {
|
|
echo '<div class="col"><p class="text-center text-danger">Database error. Please try again later.</p></div>';
|
|
}
|
|
?>
|
|
</div>
|
|
</main>
|
|
<footer class="text-center text-muted fixed-bottom py-3 bg-light">
|
|
Page generated at: <?= htmlspecialchars($now) ?> (UTC)
|
|
</footer>
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|