diff --git a/admin.php b/admin.php new file mode 100644 index 0000000..59cd5da --- /dev/null +++ b/admin.php @@ -0,0 +1,82 @@ + + + + + + + Admin | MyTube + + + + + + +
+

Welcome, !

+ +
+

Manage Videos

+ Add New Video +
+ + + + + + + + + + + + + + query("SELECT * FROM videos ORDER BY created_at DESC"); + while ($video = $stmt->fetch()) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + } catch (PDOException $e) { + echo ''; + } + ?> + +
TitleCreatorViewsUpload DateStatusActions
' . htmlspecialchars($video['title']) . '' . htmlspecialchars($video['creator']) . '' . htmlspecialchars($video['views']) . '' . date("M j, Y", strtotime($video['upload_date'])) . '' . htmlspecialchars($video['status']) . ''; + if ($video['status'] === 'pending') { + echo 'Approve '; + } + echo 'Edit '; + echo 'Delete'; + echo '
Database error: ' . $e->getMessage() . '
+
+ + diff --git a/assets/css/custom.css b/assets/css/custom.css index 7ddf7c1..5fd151d 100644 --- a/assets/css/custom.css +++ b/assets/css/custom.css @@ -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; -} +} \ No newline at end of file diff --git a/db/migrations/002_create_categories_tables.sql b/db/migrations/002_create_categories_tables.sql new file mode 100644 index 0000000..51b0c4e --- /dev/null +++ b/db/migrations/002_create_categories_tables.sql @@ -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; diff --git a/db/setup.php b/db/setup.php new file mode 100644 index 0000000..b863bb8 --- /dev/null +++ b/db/setup.php @@ -0,0 +1,54 @@ +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()); +} \ No newline at end of file diff --git a/index.php b/index.php index 50d12d3..4f74a5d 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@ - New Style + MyTube - Video Platform - - - - - - - - - - + + + -
-
-
-

Welcome to MyTube

-

A new place to share and watch videos. Check out our first featured video!

- Watch Video -
+
+ +
+
+
+

Featured Videos

+

A new place to share and watch videos.

+
+ +
+
+
+ + +
+
+
+ +
+ prepare($sql); + $stmt->execute($params); + + if ($stmt->rowCount() > 0) { + while ($video = $stmt->fetch(PDO::FETCH_ASSOC)) { + echo ''; + } + } else { + if ($search_term) { + echo '

No videos found matching your search for \'' . htmlspecialchars($search_term) . '\'.

'; + } else { + echo '

No approved videos available at the moment. Please check back later.

'; + } + } + } catch (PDOException $e) { + echo '

Database error. Please try again later.

'; + } + ?>
-
+
Page generated at: (UTC)
+ diff --git a/login.php b/login.php new file mode 100644 index 0000000..fc44f17 --- /dev/null +++ b/login.php @@ -0,0 +1,82 @@ +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.'; + } +} +?> + + + + + + Login | MyTube + + + + + + + + + + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..766a593 --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ +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(); + } + } +} +?> + + + + + + Sign Up | MyTube + + + + + + + + + + diff --git a/upload.php b/upload.php new file mode 100644 index 0000000..47f5c5d --- /dev/null +++ b/upload.php @@ -0,0 +1,84 @@ +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()); + } + } +} +?> + + + + + + Upload Video | MyTube + + + + + +
+

Upload a New Video

+

Your video will be submitted for approval and will not be public until an admin reviews it.

+ + +
+ + +
+
+ + +
+
+ + +
+
+ + + Please provide a direct link to the video (e.g., a YouTube embed link). +
+ + Cancel +
+
+ + diff --git a/video.php b/video.php index 8f87936..1f676bc 100644 --- a/video.php +++ b/video.php @@ -1,92 +1,107 @@ +videocam_off

No video URL provided.

'; + } + + $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 '
'; + } + + // Fallback for other video URLs + return '
'; +} + +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 "

Sorry, the requested video was not found or is not currently available.

"; + include 'includes/footer.php'; // Assuming you create a footer file + exit; +} + +$embed_html = getEmbedHtml($video['video_url'] ?? ''); + +?> - Video Title | MyTube + <?php echo htmlspecialchars($video['title']); ?> | MyTube +
+
+
+ +
+ +
-
- -
-
- play_circle_filled -
-
- - -

Exploring the Alps: A Scenic Journey

-
-
- 1,234,567 views - - 2 weeks ago -
-
- - - - -
-
- - -
- Channel Avatar -
-
NatureWalks
-
2.3M subscribers
-
- -
- - -
- Description -
-

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.

-

Filmed with a Drone Pro 4K.

-
-
- - -
-

3 Comments

-
- User Avatar -
-
Alex Doe
-
Wow, amazing footage! What drone did you use?
-
- LikeReply + +

+
+
+ views + +
-
-
- User Avatar -
-
Jane Smith
-
Makes me want to book a flight right now!
-
- LikeReply -
- -
- User Avatar -
-
NatureWalks
-
Glad you liked it! It was filmed with a Drone Pro 4K.
-
- LikeReply -
-
+ + +
+ Creator Avatar +
+
+
+ + +
+

Description

+

+
+ +
+
+

Up Next

+ +

Related videos will be shown here.

@@ -94,4 +109,4 @@ - + \ No newline at end of file diff --git a/video_add.php b/video_add.php new file mode 100644 index 0000000..c283085 --- /dev/null +++ b/video_add.php @@ -0,0 +1,77 @@ +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(); + } + } +} +?> + + + + + + Add Video | MyTube Admin + + + + + +
+

Add New Video

+ +
+ +
+
+ + +
+
+ + +
+
+ + + Please provide a direct link to the video (e.g., a YouTube embed link). +
+
+ + +
+ + Cancel +
+
+ + diff --git a/video_approve.php b/video_approve.php new file mode 100644 index 0000000..c454283 --- /dev/null +++ b/video_approve.php @@ -0,0 +1,28 @@ +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; +?> \ No newline at end of file diff --git a/video_delete.php b/video_delete.php new file mode 100644 index 0000000..edc9729 --- /dev/null +++ b/video_delete.php @@ -0,0 +1,25 @@ +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; diff --git a/video_edit.php b/video_edit.php new file mode 100644 index 0000000..66b07df --- /dev/null +++ b/video_edit.php @@ -0,0 +1,94 @@ +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; +} +?> + + + + + + Edit Video | MyTube Admin + + + + + +
+

Edit Video

+ +
+ +
+
+ + +
+
+ + +
+
+ + + Please provide a direct link to the video (e.g., a YouTube embed link). +
+
+ + +
+ + Cancel +
+
+ +