94 lines
4.4 KiB
PHP
94 lines
4.4 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
require_once 'includes/flash_messages.php';
|
|
|
|
if (!isset($_GET['id'])) {
|
|
header('Location: index.php');
|
|
exit();
|
|
}
|
|
|
|
$user_id = $_GET['id'];
|
|
$p = db();
|
|
|
|
// Fetch user data
|
|
$stmt = $p->prepare('SELECT display_name, description, occupation FROM users WHERE id = ?');
|
|
$stmt->execute([$user_id]);
|
|
$user = $stmt->fetch();
|
|
|
|
if (!$user) {
|
|
header('Location: index.php');
|
|
exit();
|
|
}
|
|
|
|
$stmt = $p->prepare('SELECT p.id, p.content, p.created_at, u.display_name, (SELECT COUNT(*) FROM post_votes WHERE post_id = p.id AND vote = 1) as likes, (SELECT COUNT(*) FROM post_votes WHERE post_id = p.id AND vote = -1) as dislikes FROM posts p JOIN users u ON p.user_id = u.id WHERE p.user_id = ? ORDER BY p.created_at DESC');
|
|
$stmt->execute([$user_id]);
|
|
$posts = $stmt->fetchAll();
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?= htmlspecialchars($user['display_name']) ?>'s Profile</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<nav class="navbar">
|
|
<a class="navbar-brand" href="index.php">Social Platform</a>
|
|
<div class="nav-links">
|
|
<?php if (isset($_SESSION['user_id'])): ?>
|
|
<a href="profile.php?id=<?php echo $_SESSION['user_id']; ?>">My Profile</a>
|
|
<a href="logout.php">Logout</a>
|
|
<?php else: ?>
|
|
<a href="login.php">Login</a>
|
|
<a href="signup.php">Sign Up</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container">
|
|
<?php display_flash_message(); ?>
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h2 class="card-title"><?= htmlspecialchars($user['display_name']) ?></h2>
|
|
<p class="card-text"><?= htmlspecialchars($user['description']) ?></p>
|
|
<p class="card-text"><small class="text-muted"><?= htmlspecialchars($user['occupation']) ?></small></p>
|
|
</div>
|
|
</div>
|
|
|
|
<h3 class="mt-5">Posts by <?= htmlspecialchars($user['display_name']) ?></h3>
|
|
|
|
<?php if (empty($posts)) : ?>
|
|
<p>This user has no posts yet.</p>
|
|
<?php else : ?>
|
|
<?php foreach ($posts as $post) : ?>
|
|
<div class="card my-3">
|
|
<div class="card-body">
|
|
<p class="card-text"><?= htmlspecialchars($post['content']) ?></p>
|
|
<div class="vote-buttons">
|
|
<a href="handle_like.php?post_id=<?= $post['id'] ?>&action=like" class="like-button">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7 10v12"/><path d="M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 18.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h3z"/></svg>
|
|
<span><?= $post['likes'] ?></span>
|
|
</a>
|
|
<a href="handle_like.php?post_id=<?= $post['id'] ?>&action=dislike" class="dislike-button">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7 14V2"/><path d="M15 18.12 14 14H8.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 10.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-3z"/></svg>
|
|
<span><?= $post['dislikes'] ?></span>
|
|
</a>
|
|
</div>
|
|
<p class="card-text mt-2"><small class="text-muted">Posted on <?= date('F j, Y, g:i a', strtotime($post['created_at'])) ?></small></p>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
<a href="index.php" class="btn btn-secondary mt-3">Back to Feed</a>
|
|
</div>
|
|
|
|
<footer class="footer">
|
|
<p>© <?php echo date("Y"); ?> Social Platform. All rights reserved.</p>
|
|
</footer>
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
</html>
|