first
This commit is contained in:
parent
2902ab3d4a
commit
b96d6dd21e
@ -121,16 +121,17 @@ main.container {
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
.form-group input, .form-group textarea {
|
||||
width: 100%;
|
||||
padding: 0.75rem 1rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 0.5rem;
|
||||
font-size: 1rem;
|
||||
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
||||
background-color: var(--color-background);
|
||||
}
|
||||
|
||||
.form-group input:focus {
|
||||
.form-group input:focus, .form-group textarea:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
|
||||
@ -338,3 +339,66 @@ main.container {
|
||||
.style-sketch {
|
||||
filter: grayscale(1) brightness(1.2) contrast(1.5);
|
||||
}
|
||||
|
||||
/* Comments Section */
|
||||
.comments-container {
|
||||
max-width: 800px;
|
||||
margin: 4rem auto 2rem;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.comments-title {
|
||||
font-size: 1.75rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 1.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.comment-form-wrapper {
|
||||
background-color: var(--color-surface);
|
||||
padding: 1.5rem;
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.comment-form-wrapper textarea {
|
||||
min-height: 80px;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.comment-form-wrapper .btn {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.comments-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.comment-card {
|
||||
background-color: var(--color-surface);
|
||||
padding: 1.5rem;
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.comment-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1rem;
|
||||
font-size: 0.9rem;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.comment-author {
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.comment-body p {
|
||||
margin: 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
@ -1,22 +1,26 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../db/config.php';
|
||||
// db/migrations/001_create_users_table.php
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
$sql = "
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(50) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=INNODB;
|
||||
";
|
||||
|
||||
$pdo->exec($sql);
|
||||
|
||||
echo "Migration 001: users table created or already exists." . PHP_EOL;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("Migration failed: " . $e->getMessage());
|
||||
if (function_exists('migrate_001_create_users_table')) {
|
||||
return;
|
||||
}
|
||||
|
||||
function migrate_001_create_users_table() {
|
||||
require_once __DIR__ . '/../config.php';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$sql = "
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(50) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
";
|
||||
$pdo->exec($sql);
|
||||
echo "Migration 001: 'users' table created or already exists.\n";
|
||||
} catch (PDOException $e) {
|
||||
die("Migration 001 failed: " . $e->getMessage() . "\n");
|
||||
}
|
||||
}
|
||||
@ -1,25 +1,27 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config.php';
|
||||
// db/migrations/002_create_comments_table.php
|
||||
|
||||
if (function_exists('migrate_002_create_comments_table')) {
|
||||
return;
|
||||
}
|
||||
|
||||
function migrate_002_create_comments_table() {
|
||||
require_once __DIR__ . '/../config.php';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$sql = "
|
||||
CREATE TABLE IF NOT EXISTS `comments` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`post_id` int(11) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`comment` text NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `post_id` (`post_id`),
|
||||
CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
";
|
||||
CREATE TABLE IF NOT EXISTS comments (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
comment TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
";
|
||||
$pdo->exec($sql);
|
||||
echo "Migration 002: Comments table created successfully.\n";
|
||||
echo "Migration 002: 'comments' table created or already exists.\n";
|
||||
} catch (PDOException $e) {
|
||||
die("Migration 002 failed: " . $e->getMessage() . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
66
index.php
66
index.php
@ -1,6 +1,39 @@
|
||||
<?php
|
||||
$title = 'Home - Avatar Generator';
|
||||
require_once 'partials/header.php';
|
||||
|
||||
// Handle comment submission
|
||||
if (isset($_SESSION['user_id']) && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['comment'])) {
|
||||
$comment_text = trim($_POST['comment']);
|
||||
if (!empty($comment_text)) {
|
||||
try {
|
||||
$stmt = db()->prepare("INSERT INTO comments (user_id, comment) VALUES (:user_id, :comment)");
|
||||
$stmt->execute(['user_id' => $_SESSION['user_id'], 'comment' => $comment_text]);
|
||||
} catch (PDOException $e) {
|
||||
// Optional: handle error, e.g., log it or show a generic error message
|
||||
}
|
||||
}
|
||||
// Redirect to the same page to prevent form resubmission
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Fetch comments
|
||||
$comments = [];
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
try {
|
||||
$stmt = db()->query("
|
||||
SELECT c.comment, c.created_at, u.username
|
||||
FROM comments c
|
||||
JOIN users u ON c.user_id = u.id
|
||||
ORDER BY c.created_at DESC
|
||||
");
|
||||
$comments = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
// Optional: handle error
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
@ -48,6 +81,39 @@ require_once 'partials/header.php';
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Comments Section -->
|
||||
<div class="comments-container">
|
||||
<h2 class="comments-title">Community Feedback</h2>
|
||||
<div class="comment-form-wrapper">
|
||||
<form action="index.php" method="POST">
|
||||
<div class="form-group">
|
||||
<textarea name="comment" class="form-control" placeholder="Share your thoughts..." required></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary btn-gradient">Post Comment</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="comments-list">
|
||||
<?php if (empty($comments)): ?>
|
||||
<p>No comments yet. Be the first to share your thoughts!</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($comments as $comment): ?>
|
||||
<div class="comment-card">
|
||||
<div class="comment-header">
|
||||
<span class="comment-author"><?php echo htmlspecialchars($comment['username']); ?></span>
|
||||
<span class="comment-date"><?php echo date('M j, Y, g:i a', strtotime($comment['created_at'])); ?></span>
|
||||
</div>
|
||||
<div class="comment-body">
|
||||
<p><?php echo htmlspecialchars($comment['comment']); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<!-- End Comments Section -->
|
||||
|
||||
<?php else: ?>
|
||||
<div class="hero-section">
|
||||
<h1>Create Stunning Avatars from Your Photos</h1>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user