Auto commit: 2025-11-28T19:14:48.729Z

This commit is contained in:
Flatlogic Bot 2025-11-28 19:14:48 +00:00
parent 12a2ae7116
commit e8bbf9fb84
14 changed files with 846 additions and 200 deletions

82
admin.php Normal file
View File

@ -0,0 +1,82 @@
<?php
session_start();
// If the user is not logged in, redirect to the login page.
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin | MyTube</title>
<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>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">MyTube Admin</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-4">
<h1>Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?>!</h1>
<div class="d-flex justify-content-between align-items-center mb-3">
<h2>Manage Videos</h2>
<a href="video_add.php" class="btn btn-success">Add New Video</a>
</div>
<table class="table table-striped table-dark">
<thead>
<tr>
<th>Title</th>
<th>Creator</th>
<th>Views</th>
<th>Upload Date</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
require_once __DIR__ . '/db/config.php';
try {
$pdo = db();
$stmt = $pdo->query("SELECT * FROM videos ORDER BY created_at DESC");
while ($video = $stmt->fetch()) {
echo '<tr>';
echo '<td>' . htmlspecialchars($video['title']) . '</td>';
echo '<td>' . htmlspecialchars($video['creator']) . '</td>';
echo '<td>' . htmlspecialchars($video['views']) . '</td>';
echo '<td>' . date("M j, Y", strtotime($video['upload_date'])) . '</td>';
echo '<td><span class="badge bg-' . ($video['status'] === 'approved' ? 'success' : 'warning') . '">' . htmlspecialchars($video['status']) . '</span></td>';
echo '<td>';
if ($video['status'] === 'pending') {
echo '<a href="video_approve.php?id=' . $video['id'] . '" class="btn btn-sm btn-success">Approve</a> ';
}
echo '<a href="video_edit.php?id=' . $video['id'] . '" class="btn btn-sm btn-primary">Edit</a> ';
echo '<a href="video_delete.php?id=' . $video['id'] . '" class="btn btn-sm btn-danger">Delete</a>';
echo '</td>';
echo '</tr>';
}
} catch (PDOException $e) {
echo '<tr><td colspan="6">Database error: ' . $e->getMessage() . '</td></tr>';
}
?>
</tbody>
</table>
</div>
</body>
</html>

View File

@ -1,7 +1,15 @@
:root {
--background-dark: #121212;
--surface-dark: #1E1E1E;
--primary-accent: #D83F87; /* Rose Red */
--text-primary: #FFFFFF;
--text-secondary: #AAAAAA;
--border-color: #383838;
}
body {
background-color: #121212;
color: #FFFFFF;
background-color: var(--background-dark);
color: var(--text-primary);
font-family: 'Roboto', sans-serif;
}
@ -43,7 +51,7 @@ body {
.video-stats {
display: flex;
align-items: center;
color: #AAAAAA;
color: var(--text-secondary);
margin-bottom: 16px;
}
@ -55,19 +63,19 @@ body {
margin-right: 8px;
background-color: #282828;
border: none;
color: #FFFFFF;
color: var(--text-primary);
}
.action-buttons .btn:hover {
background-color: #383838;
background-color: var(--primary-accent);
}
.channel-info {
display: flex;
align-items: center;
padding: 16px 0;
border-top: 1px solid #383838;
border-bottom: 1px solid #383838;
border-top: 1px solid var(--border-color);
border-bottom: 1px solid var(--border-color);
margin-bottom: 16px;
}
@ -83,17 +91,17 @@ body {
}
.channel-subs {
color: #AAAAAA;
color: var(--text-secondary);
}
.subscribe-btn {
background-color: #E50914;
color: #FFFFFF;
background-color: var(--primary-accent);
color: var(--text-primary);
font-weight: 700;
}
.description-box {
background-color: #1E1E1E;
background-color: var(--surface-dark);
padding: 16px;
border-radius: 8px;
margin-bottom: 24px;
@ -134,6 +142,6 @@ body {
}
.comment-actions {
color: #AAAAAA;
color: var(--text-secondary);
font-size: 12px;
}

View File

@ -0,0 +1,15 @@
CREATE TABLE IF NOT EXISTS `categories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `video_categories` (
`video_id` int(11) NOT NULL,
`category_id` int(11) NOT NULL,
PRIMARY KEY (`video_id`,`category_id`),
KEY `category_id` (`category_id`),
CONSTRAINT `video_categories_ibfk_1` FOREIGN KEY (`video_id`) REFERENCES `videos` (`id`) ON DELETE CASCADE,
CONSTRAINT `video_categories_ibfk_2` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

54
db/setup.php Normal file
View File

@ -0,0 +1,54 @@
<?php
require_once __DIR__ . '/config.php';
try {
$pdo = db();
// Create users table
$pdo->exec("
CREATE TABLE IF NOT EXISTS `users` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(255) NOT NULL UNIQUE,
`email` VARCHAR(255) NOT NULL UNIQUE,
`password` VARCHAR(255) NOT NULL,
`is_admin` BOOLEAN NOT NULL DEFAULT 0,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=INNODB;
");
echo "Table 'users' created successfully or already exists.\n";
// Create videos table
$pdo->exec("
CREATE TABLE IF NOT EXISTS `videos` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`user_id` INT,
`title` VARCHAR(255) NOT NULL,
`description` TEXT,
`upload_date` DATE,
`views` INT DEFAULT 0,
`creator` VARCHAR(255),
`creator_avatar` VARCHAR(255),
`thumbnail_url` VARCHAR(255),
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE SET NULL
) ENGINE=INNODB;
");
echo "Table 'videos' created successfully or already exists.\n";
// Insert a default admin user if one doesn't exist
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?");
$stmt->execute(['admin']);
if ($stmt->fetch()) {
echo "Admin user already exists.\n";
} else {
$password_hash = password_hash('password', PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (username, email, password, is_admin) VALUES (?, ?, ?, ?)");
$stmt->execute(['admin', 'admin@example.com', $password_hash, 1]);
echo "Default admin user created successfully. Username: admin, Password: password\n";
}
} catch (PDOException $e) {
die("Database setup failed: " . $e->getMessage());
}

204
index.php
View File

@ -1,4 +1,5 @@
<?php
session_start();
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@ -12,7 +13,7 @@ $now = date('Y-m-d H:i:s');
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>New Style</title>
<title>MyTube - Video Platform</title>
<?php
// Read project preview data from environment
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
@ -21,128 +22,105 @@ $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
<?php if ($projectDescription): ?>
<!-- Meta description -->
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
<!-- Open Graph meta tags -->
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<!-- Twitter meta tags -->
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<!-- Open Graph image -->
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<!-- Twitter image -->
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<?php endif; ?>
<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=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}
.loader {
margin: 1.25rem auto 1.25rem;
width: 48px;
height: 48px;
border: 3px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.hint {
opacity: 0.9;
}
.sr-only {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
}
</style>
<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>
<main class="container mt-5">
<div class="card text-white bg-dark text-center">
<div class="card-body">
<h1 class="card-title">Welcome to MyTube</h1>
<p class="card-text">A new place to share and watch videos. Check out our first featured video!</p>
<a href="video.php" class="btn btn-danger">Watch Video</a>
</div>
<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">
<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>

82
login.php Normal file
View File

@ -0,0 +1,82 @@
<?php
session_start();
require_once __DIR__ . '/db/config.php';
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!empty($_POST['username']) && !empty($_POST['password'])) {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
$stmt->execute([$_POST['username']]);
$user = $stmt->fetch();
if ($user && password_verify($_POST['password'], $user['password'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
$_SESSION['is_admin'] = $user['is_admin'];
header("Location: admin.php");
exit;
} else {
$error_message = 'Invalid username or password.';
}
} catch (PDOException $e) {
$error_message = 'Database error: ' . $e->getMessage();
}
} else {
$error_message = 'Please fill in both fields.';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login | MyTube</title>
<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 href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-card {
width: 100%;
max-width: 400px;
padding: 40px;
border-radius: 12px;
background-color: var(--surface-color);
color: var(--text-color);
}
</style>
</head>
<body>
<div class="login-card">
<h2 class="text-center mb-4">Login</h2>
<?php if (isset($_GET['signup']) && $_GET['signup'] === 'success'): ?>
<div class="alert alert-success">Your account has been created successfully. Please login.</div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<form method="POST" action="login.php">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<button type="submit" class="btn btn-primary w-100">Login</button>
</form>
<p class="text-center mt-3">Don't have an account? <a href="signup.php">Sign up</a></p>
</div>
</body>
</html>

6
logout.php Normal file
View File

@ -0,0 +1,6 @@
<?php
session_start();
session_unset();
session_destroy();
header("Location: login.php");
exit;

98
signup.php Normal file
View File

@ -0,0 +1,98 @@
<?php
session_start();
require_once __DIR__ . '/db/config.php';
$error_message = '';
$success_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$email = $_POST['email'] ?? '';
$password = $_POST['password'] ?? '';
$confirm_password = $_POST['confirm_password'] ?? '';
if (empty($username) || empty($email) || empty($password)) {
$error_message = 'Please fill in all fields.';
} elseif ($password !== $confirm_password) {
$error_message = 'Passwords do not match.';
} else {
try {
$pdo = db();
// Check if username or email already exists
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
$stmt->execute([$username, $email]);
if ($stmt->fetch()) {
$error_message = 'Username or email already taken.';
} else {
// Insert new user
$password_hash = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)");
$stmt->execute([$username, $email, $password_hash]);
// Redirect to login page with a success message
header("Location: login.php?signup=success");
exit;
}
} catch (PDOException $e) {
$error_message = 'Database error: ' . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign Up | MyTube</title>
<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 href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.signup-card {
width: 100%;
max-width: 450px;
padding: 40px;
border-radius: 12px;
background-color: var(--surface-color);
color: var(--text-color);
}
</style>
</head>
<body>
<div class="signup-card">
<h2 class="text-center mb-4">Create Account</h2>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<form method="POST" action="signup.php">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="mb-3">
<label for="confirm_password" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
</div>
<button type="submit" class="btn btn-primary w-100">Sign Up</button>
</form>
<p class="text-center mt-3">Already have an account? <a href="login.php">Login</a></p>
</div>
</body>
</html>

84
upload.php Normal file
View File

@ -0,0 +1,84 @@
<?php
session_start();
require_once __DIR__ . '/db/config.php';
// If the user is not logged in, redirect them to the login page.
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
$error_message = '';
$success_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'] ?? '';
$description = $_POST['description'] ?? '';
$video_url = $_POST['video_url'] ?? '';
if (empty($title) || empty($description) || empty($video_url)) {
$error_message = 'Please fill in all fields, including the Video URL.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare(
"INSERT INTO videos (user_id, title, description, video_url, creator, upload_date, status) VALUES (?, ?, ?, ?, ?, ?, 'pending')"
);
$stmt->execute([
$_SESSION['user_id'],
$title,
$description,
$video_url,
$_SESSION['username'],
date('Y-m-d')
]);
header("Location: index.php?upload=success");
exit;
} catch (PDOException $e) {
$error_message = 'An error occurred while uploading your video. Please try again later.';
error_log('Upload failed: ' . $e->getMessage());
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Video | MyTube</title>
<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>
<div class="container mt-5">
<h2>Upload a New Video</h2>
<p>Your video will be submitted for approval and will not be public until an admin reviews it.</p>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
<?php endif; ?>
<form method="POST" action="upload.php">
<div class="mb-3">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" id="title" name="title" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="3" required></textarea>
</div>
<div class="mb-3">
<label for="video_url" class="form-label">Video URL</label>
<input type="url" class="form-control" id="video_url" name="video_url" required>
<small class="form-text text-muted">Please provide a direct link to the video (e.g., a YouTube embed link).</small>
</div>
<button type="submit" class="btn btn-primary">Submit for Approval</button>
<a href="index.php" class="btn btn-secondary">Cancel</a>
</form>
</div>
</body>
</html>

161
video.php
View File

@ -1,92 +1,107 @@
<?php
session_start();
require_once 'db/config.php';
// Get video ID from URL, default to 1 if not set
$video_id = isset($_GET['id']) ? (int)$_GET['id'] : 1;
// Helper function to process video URLs
function getEmbedHtml($url) {
if (empty($url)) {
return '<div class="video-player-placeholder bg-dark text-white d-flex justify-content-center align-items-center"><i class="material-icons" style="font-size: 64px;">videocam_off</i><p>No video URL provided.</p></div>';
}
$youtube_id = '';
if (preg_match('/youtube\.com\/watch\?v=([a-zA-Z0-9_\-]+)/', $url, $matches)) {
$youtube_id = $matches[1];
} elseif (preg_match('/youtu\.be\/([a-zA-Z0-9_\-]+)/', $url, $matches)) {
$youtube_id = $matches[1];
} elseif (preg_match('/youtube\.com\/embed\/([a-zA-Z0-9_\-]+)/', $url, $matches)) {
$youtube_id = $matches[1];
}
if ($youtube_id) {
$embed_url = 'https://www.youtube.com/embed/' . $youtube_id;
return '<div class="ratio ratio-16x9"><iframe src="' . $embed_url . '" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>';
}
// Fallback for other video URLs
return '<div class="ratio ratio-16x9"><video controls autoplay muted src="' . htmlspecialchars($url) . '" style="width:100%; height:100%;">Your browser does not support the video tag.</video></div>';
}
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM videos WHERE id = ? AND status = 'approved'");
$stmt->execute([$video_id]);
$video = $stmt->fetch();
} catch (PDOException $e) {
die("Database error: " . $e->getMessage());
}
// If no video is found, display a simple message
if (!$video) {
http_response_code(404);
// You can create a nicer 404 page later
$page_title = "Video Not Found";
include 'includes/header.php'; // Assuming you create a header file
echo "<div class='container text-center'><p>Sorry, the requested video was not found or is not currently available.</p></div>";
include 'includes/footer.php'; // Assuming you create a footer file
exit;
}
$embed_html = getEmbedHtml($video['video_url'] ?? '');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Video Title | MyTube</title>
<title><?php echo htmlspecialchars($video['title']); ?> | MyTube</title>
<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 href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<div class="container mt-4">
<div class="row">
<div class="col-lg-8">
<!-- Video Player -->
<div class="video-player mb-3">
<?php echo $embed_html; ?>
</div>
<div class="video-container">
<!-- Video Player -->
<div class="video-player">
<div class="video-player-placeholder">
<i class="material-icons" style="font-size: 64px;">play_circle_filled</i>
</div>
</div>
<!-- Video Info -->
<h1 class="video-title">Exploring the Alps: A Scenic Journey</h1>
<div class="d-flex justify-content-between align-items-center">
<div class="video-stats">
<span>1,234,567 views</span>
<span>&bull;</span>
<span>2 weeks ago</span>
</div>
<div class="action-buttons">
<button class="btn"><i class="material-icons">thumb_up</i> 15K</button>
<button class="btn"><i class="material-icons">thumb_down</i> 432</button>
<button class="btn"><i class="material-icons">share</i> Share</button>
<button class="btn"><i class="material-icons">playlist_add</i> Save</button>
</div>
</div>
<!-- Channel Info -->
<div class="channel-info">
<img src="https://i.pravatar.cc/48?u=channel1" alt="Channel Avatar">
<div class="flex-grow-1">
<div class="channel-name">NatureWalks</div>
<div class="channel-subs">2.3M subscribers</div>
</div>
<button class="btn subscribe-btn">Subscribe</button>
</div>
<!-- Description -->
<div class="description-box">
<strong>Description</strong>
<div class="description-content">
<p>Join us on an incredible adventure through the stunning landscapes of the Swiss Alps. From breathtaking peaks to serene lakes, this is a journey you won't forget.</p>
<p>Filmed with a Drone Pro 4K.</p>
</div>
</div>
<!-- Comments -->
<div class="comments-section">
<h3>3 Comments</h3>
<div class="comment">
<img src="https://i.pravatar.cc/40?u=user1" alt="User Avatar">
<div class="comment-body">
<div class="comment-author">Alex Doe</div>
<div class="comment-text">Wow, amazing footage! What drone did you use?</div>
<div class="comment-actions">
<span>Like</span> &bull; <span>Reply</span>
<!-- Video Info -->
<h1 class="video-title h3"><?php echo htmlspecialchars($video['title']); ?></h1>
<div class="d-flex justify-content-between align-items-center text-muted small mb-2">
<div class="video-stats">
<span><?php echo htmlspecialchars($video['views']); ?> views</span>
<span>&bull;</span>
<span><?php echo date("M j, Y", strtotime($video['upload_date'])); ?></span>
</div>
</div>
</div>
<div class="comment">
<img src="https://i.pravatar.cc/40?u=user2" alt="User Avatar">
<div class="comment-body">
<div class="comment-author">Jane Smith</div>
<div class="comment-text">Makes me want to book a flight right now!</div>
<div class="comment-actions">
<span>Like</span> &bull; <span>Reply</span>
</div>
<!-- Nested Comment -->
<div class="comment mt-3">
<img src="https://i.pravatar.cc/40?u=channel1" alt="User Avatar">
<div class="comment-body">
<div class="comment-author">NatureWalks</div>
<div class="comment-text">Glad you liked it! It was filmed with a Drone Pro 4K.</div>
<div class="comment-actions">
<span>Like</span> &bull; <span>Reply</span>
</div>
</div>
<!-- Creator Info -->
<div class="d-flex align-items-center border-top pt-3 mt-3">
<img src="<?php echo htmlspecialchars($video['creator_avatar'] ?? 'https://placehold.co/48x48/ced4da/212529?text='.strtoupper(substr($video['creator'], 0, 1))); ?>" alt="Creator Avatar" class="rounded-circle me-3" width="48" height="48">
<div class="flex-grow-1">
<div class="fw-bold"><?php echo htmlspecialchars($video['creator']); ?></div>
</div>
<button class="btn btn-danger">Subscribe</button>
</div>
<!-- Description -->
<div class="description-box mt-3 p-3 bg-light rounded">
<p class="fw-bold">Description</p>
<p><?php echo nl2br(htmlspecialchars($video['description'])); ?></p>
</div>
</div>
<div class="col-lg-4">
<h4 class="h5 mb-3">Up Next</h4>
<!-- Placeholder for related videos -->
<p class="text-muted">Related videos will be shown here.</p>
</div>
</div>
</div>

77
video_add.php Normal file
View File

@ -0,0 +1,77 @@
<?php
session_start();
require_once __DIR__ . '/db/config.php';
// If the user is not logged in or not an admin, redirect them.
if (!isset($_SESSION['user_id']) || !$_SESSION['is_admin']) {
header("Location: login.php");
exit;
}
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'] ?? '';
$description = $_POST['description'] ?? '';
$video_url = $_POST['video_url'] ?? '';
$creator = $_POST['creator'] ?? '';
if (empty($title) || empty($description) || empty($video_url) || empty($creator)) {
$error_message = 'Please fill in all fields, including the Video URL.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare(
"INSERT INTO videos (user_id, title, description, video_url, creator, upload_date) VALUES (?, ?, ?, ?, ?, ?)"
);
// Using session user_id and current date
$stmt->execute([$_SESSION['user_id'], $title, $description, $video_url, $creator, date('Y-m-d')]);
header("Location: admin.php");
exit;
} catch (PDOException $e) {
$error_message = 'Database error: ' . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Video | MyTube Admin</title>
<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>
<div class="container mt-5">
<h2>Add New Video</h2>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<form method="POST" action="video_add.php">
<div class="mb-3">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" id="title" name="title" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="3" required></textarea>
</div>
<div class="mb-3">
<label for="video_url" class="form-label">Video URL</label>
<input type="url" class="form-control" id="video_url" name="video_url" required>
<small class="form-text text-muted">Please provide a direct link to the video (e.g., a YouTube embed link).</small>
</div>
<div class="mb-3">
<label for="creator" class="form-label">Creator</label>
<input type="text" class="form-control" id="creator" name="creator" required>
</div>
<button type="submit" class="btn btn-success">Add Video</button>
<a href="admin.php" class="btn btn-secondary">Cancel</a>
</form>
</div>
</body>
</html>

28
video_approve.php Normal file
View File

@ -0,0 +1,28 @@
<?php
session_start();
// If the user is not logged in, redirect to the login page.
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
require_once __DIR__ . '/db/config.php';
if (isset($_GET['id']) && !empty($_GET['id'])) {
$video_id = $_GET['id'];
try {
$pdo = db();
$sql = "UPDATE videos SET status = 'approved' WHERE id = :id";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':id', $video_id, PDO::PARAM_INT);
$stmt->execute();
} catch (PDOException $e) {
die("Database error: " . $e->getMessage());
}
}
header("Location: admin.php");
exit;
?>

25
video_delete.php Normal file
View File

@ -0,0 +1,25 @@
<?php
session_start();
require_once __DIR__ . '/db/config.php';
// If the user is not logged in or not an admin, redirect them.
if (!isset($_SESSION['user_id']) || !$_SESSION['is_admin']) {
header("Location: login.php");
exit;
}
$video_id = $_GET['id'] ?? null;
if ($video_id) {
try {
$pdo = db();
$stmt = $pdo->prepare("DELETE FROM videos WHERE id = ?");
$stmt->execute([$video_id]);
} catch (PDOException $e) {
// You might want to log this error instead of dying
die("Database error: " . $e->getMessage());
}
}
header("Location: admin.php");
exit;

94
video_edit.php Normal file
View File

@ -0,0 +1,94 @@
<?php
session_start();
require_once __DIR__ . '/db/config.php';
// If the user is not logged in or not an admin, redirect them.
if (!isset($_SESSION['user_id']) || !$_SESSION['is_admin']) {
header("Location: login.php");
exit;
}
$error_message = '';
$video_id = $_GET['id'] ?? null;
if (!$video_id) {
header("Location: admin.php");
exit;
}
$pdo = db();
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'] ?? '';
$description = $_POST['description'] ?? '';
$video_url = $_POST['video_url'] ?? '';
$creator = $_POST['creator'] ?? '';
if (empty($title) || empty($description) || empty($video_url) || empty($creator)) {
$error_message = 'Please fill in all fields, including the Video URL.';
} else {
try {
$stmt = $pdo->prepare(
"UPDATE videos SET title = ?, description = ?, video_url = ?, creator = ? WHERE id = ?"
);
$stmt->execute([$title, $description, $video_url, $creator, $video_id]);
header("Location: admin.php");
exit;
} catch (PDOException $e) {
$error_message = 'Database error: ' . $e->getMessage();
}
}
}
// Fetch existing video data
$stmt = $pdo->prepare("SELECT * FROM videos WHERE id = ?");
$stmt->execute([$video_id]);
$video = $stmt->fetch();
if (!$video) {
header("Location: admin.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Video | MyTube Admin</title>
<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>
<div class="container mt-5">
<h2>Edit Video</h2>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<form method="POST" action="video_edit.php?id=<?php echo $video['id']; ?>">
<div class="mb-3">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" id="title" name="title" value="<?php echo htmlspecialchars($video['title']); ?>" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="3" required><?php echo htmlspecialchars($video['description']); ?></textarea>
</div>
<div class="mb-3">
<label for="video_url" class="form-label">Video URL</label>
<input type="url" class="form-control" id="video_url" name="video_url" value="<?php echo htmlspecialchars($video['video_url']); ?>" required>
<small class="form-text text-muted">Please provide a direct link to the video (e.g., a YouTube embed link).</small>
</div>
<div class="mb-3">
<label for="creator" class="form-label">Creator</label>
<input type="text" class="form-control" id="creator" name="creator" value="<?php echo htmlspecialchars($video['creator']); ?>" required>
</div>
<button type="submit" class="btn btn-success">Save Changes</button>
<a href="admin.php" class="btn btn-secondary">Cancel</a>
</form>
</div>
</body>
</html>