2025-02-24 22:02:51 +01:00
|
|
|
<?php
|
|
|
|
global $pdo;
|
2025-02-12 20:13:29 +01:00
|
|
|
session_start();
|
2025-03-10 10:48:39 +01:00
|
|
|
$page = isset($_GET['page']) ? $_GET['page'] : 'posts';
|
|
|
|
$user_page = isset($_GET['user']) ? $_GET['user'] : 'posts';
|
2025-02-24 22:02:51 +01:00
|
|
|
|
|
|
|
if(!isset($_SESSION['user_id'])) {
|
2025-03-10 10:48:39 +01:00
|
|
|
header("Location: login/login-page.html");
|
|
|
|
}
|
|
|
|
|
|
|
|
include 'db_connect.php';
|
|
|
|
|
|
|
|
try {
|
|
|
|
$userId = $_SESSION['user_id'];
|
|
|
|
|
2025-02-12 20:13:29 +01:00
|
|
|
|
|
|
|
|
2025-03-10 10:48:39 +01:00
|
|
|
//Daten von Angemeldeten benutzer werden ausgelesen
|
|
|
|
$stmt1 = $pdo->prepare("SELECT username, email, created_at FROM users WHERE id = :id");
|
|
|
|
$stmt1->execute([':id' => $userId]);
|
|
|
|
$user = $stmt1->fetch(PDO::FETCH_ASSOC);
|
2025-02-24 22:02:51 +01:00
|
|
|
|
2025-02-12 20:13:29 +01:00
|
|
|
|
|
|
|
|
2025-03-10 10:48:39 +01:00
|
|
|
//Profilbild wird vom angemeldeten benutzer ausgelesen
|
|
|
|
$stmt2 = $pdo->prepare("SELECT file_path FROM profile_pictures WHERE user_id = :user_id");
|
|
|
|
$stmt2->execute([':user_id' => $userId]);
|
|
|
|
$profile_pic = $stmt2->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
|
|
|
|
//Benutzername und Profilbild werden von allen benutzer ausgelesen
|
|
|
|
$stmt3 = $pdo->prepare("
|
2025-02-12 20:13:29 +01:00
|
|
|
SELECT users.username, profile_pictures.file_path
|
|
|
|
FROM users
|
|
|
|
LEFT JOIN profile_pictures ON users.id = profile_pictures.user_id
|
|
|
|
ORDER BY profile_pictures.uploaded_at DESC
|
|
|
|
");
|
2025-03-10 10:48:39 +01:00
|
|
|
$stmt3->execute();
|
|
|
|
$users = $stmt3->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
//Alle beiträge von allen benutzer werden ausgelesen
|
|
|
|
$stmt4 = $pdo->prepare("
|
|
|
|
SELECT posts.*, profile_pictures.file_path AS profile_picture, users.username
|
|
|
|
FROM posts
|
|
|
|
LEFT JOIN profile_pictures ON posts.user_id = profile_pictures.user_id
|
|
|
|
LEFT JOIN users ON posts.user_id = users.id
|
|
|
|
ORDER BY posts.created_at DESC
|
|
|
|
");
|
|
|
|
$stmt4->execute();
|
|
|
|
$posts = $stmt4->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($profile_pic) {
|
|
|
|
$profile_image = $profile_pic['file_path'];
|
|
|
|
} else {
|
|
|
|
$profile_image = 'profile-pics/default.jpeg';
|
2025-02-12 20:13:29 +01:00
|
|
|
}
|
2025-03-10 10:48:39 +01:00
|
|
|
if(!$user){
|
|
|
|
die("Benutzer nicht gefunden!");
|
|
|
|
}
|
|
|
|
}catch (PDOException $e){
|
|
|
|
die("Fehler: " . $e->getMessage());
|
|
|
|
}
|
2025-02-12 20:13:29 +01:00
|
|
|
?>
|
2025-03-10 10:48:39 +01:00
|
|
|
|
2025-02-12 20:13:29 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="de">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<?php echo '<link rel="stylesheet" href="style.css?v='.time().'">'; ?>
|
|
|
|
<title>Profile</title>
|
2025-03-10 10:48:39 +01:00
|
|
|
|
2025-02-12 20:13:29 +01:00
|
|
|
</head>
|
2025-03-10 10:48:39 +01:00
|
|
|
|
2025-02-12 20:13:29 +01:00
|
|
|
<body>
|
|
|
|
|
|
|
|
<div class="container">
|
|
|
|
<div class="col-3">
|
|
|
|
<div class="navigation-body">
|
2025-03-10 10:48:39 +01:00
|
|
|
<div class="profile-name-header">
|
|
|
|
<?php echo "<img class = 'profile-pictures-header' src='$profile_image' alt='pv' width='50'>";?>
|
|
|
|
<h1>
|
|
|
|
<a href="">@<?php echo htmlspecialchars($user['username']); ?></a>
|
|
|
|
</h1>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<ul class="icons">
|
|
|
|
<li><a href="index.php"><img src="icons/home.svg" alt="">Home</a></li>
|
|
|
|
<li><a href="profile.php?user=<?= htmlspecialchars($user['username']) ?>"><img src="icons/user.svg" alt="">Profil</a></li>
|
|
|
|
<li><a href="chat.php"><img src="icons/envelope.svg" alt="">Nachrichten</a></li>
|
|
|
|
<li><a href="logout.php"><img src="icons/exit.svg" alt="">Abmelden</a></li>
|
2025-02-24 22:02:51 +01:00
|
|
|
|
2025-02-12 20:13:29 +01:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="navigation-body">
|
|
|
|
<ul>
|
|
|
|
<?php foreach ($users as $benutzer): ?>
|
|
|
|
<li>
|
2025-03-10 10:48:39 +01:00
|
|
|
<form class="user-card" action="profile.php" method="post">
|
|
|
|
<a href="profile.php?user=<?= urlencode($benutzer['username']) ?>"> <img class="profile-pictures" src="<?= htmlspecialchars($benutzer['file_path']) ?: 'profile-pics/default.jpeg' ?>" alt="Profilbild"><?= htmlspecialchars($benutzer['username']) ?></a>
|
2025-02-24 22:02:51 +01:00
|
|
|
</form>
|
2025-02-12 20:13:29 +01:00
|
|
|
</li>
|
|
|
|
<?php endforeach; ?>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="profile-body col-9">
|
|
|
|
<div class="profile-header">
|
|
|
|
<h1>Willkommen, <?php echo htmlspecialchars($user['username']); ?>!</h1>
|
|
|
|
<p>Email: <?php echo htmlspecialchars($user['email']); ?>!</p>
|
|
|
|
<p>Regestriert seit:, <?php echo htmlspecialchars($user['created_at']); ?>!</p>
|
2025-03-10 10:48:39 +01:00
|
|
|
|
|
|
|
|
2025-02-24 22:02:51 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if($user_page == $user['username']) {
|
|
|
|
echo htmlspecialchars($user['username']);
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
2025-02-12 20:13:29 +01:00
|
|
|
</div>
|
2025-03-10 10:48:39 +01:00
|
|
|
|
2025-02-12 20:13:29 +01:00
|
|
|
<div class="post-formular-body">
|
|
|
|
<form action='upload-post/upload-post.php' method='post' enctype='multipart/form-data'>
|
|
|
|
<textarea name='text_content' required placeholder='Schreibe etwas...'></textarea>
|
|
|
|
<input type='file' name='image'>
|
|
|
|
<button type='submit'>Posten</button>
|
|
|
|
</form>
|
2025-03-10 10:48:39 +01:00
|
|
|
</div>
|
2025-02-12 20:13:29 +01:00
|
|
|
<?php foreach ($posts as $post): ?>
|
2025-03-10 10:48:39 +01:00
|
|
|
<?php
|
|
|
|
$stmt5 = $pdo->prepare("SELECT COUNT(post_id) AS likes_count FROM likes WHERE post_id = :post_id");
|
|
|
|
$stmt5->execute([':post_id' => $post['id']]);
|
|
|
|
$likes = $stmt5->fetch(PDO::FETCH_ASSOC)['likes_count'];
|
|
|
|
|
|
|
|
$stmt6 = $pdo->prepare("SELECT user_id, post_id FROM likes WHERE post_id = :post_id AND user_id = :user_id");
|
|
|
|
$stmt6->execute([':post_id' => $post['id'], ':user_id' => $userId]);
|
|
|
|
$isLiked = $stmt6->fetch(PDO::FETCH_ASSOC);
|
|
|
|
?>
|
2025-02-12 20:13:29 +01:00
|
|
|
<div class="post">
|
2025-03-10 10:48:39 +01:00
|
|
|
<div class="post-nav">
|
|
|
|
<div class="post-header">
|
|
|
|
<img class="profile-pictures" src="<?= htmlspecialchars($post['profile_picture']) ?: 'profile-pics/default.jpeg'; ?>" width="50px" alt="">
|
|
|
|
<p><strong><?php echo $post['username']; ?></strong></p>
|
|
|
|
</div>
|
|
|
|
<?php if ($userId == $post['user_id']): ?>
|
|
|
|
<form action="upload-post/delete-post.php" method="post">
|
|
|
|
<input type="hidden" name="post_id" value="<?= htmlspecialchars($post['id']) ?>">
|
|
|
|
<button class="delete-post" type="submit"></button>
|
|
|
|
</form>
|
|
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
2025-02-12 20:13:29 +01:00
|
|
|
<p><?php echo nl2br(htmlspecialchars($post['text_content'])); ?></p>
|
|
|
|
|
|
|
|
<?php if (!empty($post['image_path'])): ?>
|
|
|
|
<img class="post-pics" src="<?php echo htmlspecialchars($post['image_path']); ?>" alt="Bild zum Post">
|
|
|
|
<?php endif; ?>
|
2025-03-10 10:48:39 +01:00
|
|
|
|
|
|
|
<h5>Likes: <?php echo htmlspecialchars($likes)?></h5>
|
2025-02-12 20:13:29 +01:00
|
|
|
|
|
|
|
<p><small>Erstellt am: <?php echo $post['created_at']; ?></small></p>
|
2025-02-24 22:15:30 +01:00
|
|
|
|
2025-03-10 10:48:39 +01:00
|
|
|
<div class="post-footer">
|
|
|
|
<?php if(!$isLiked):?>
|
|
|
|
<form action="like/like.php" method="post">
|
|
|
|
<input type="hidden" name="post_id" value="<?= htmlspecialchars($post['id']) ?>">
|
|
|
|
<button class="like-button unlike" type="submit"></button>
|
|
|
|
</form>
|
|
|
|
<?php else: ?>
|
|
|
|
<form action="like/unlike.php" method="post">
|
|
|
|
<input type="hidden" name="post_id" value="<?= htmlspecialchars($post['id']) ?>">
|
|
|
|
<button class="like-button liked" type="submit"></button>
|
|
|
|
</form>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2025-02-12 20:13:29 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
<?php endforeach; ?>
|
|
|
|
</div>
|
|
|
|
</div>
|
2025-03-10 10:48:39 +01:00
|
|
|
<script>
|
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
|
|
// Scroll-Position aus dem localStorage abrufen
|
|
|
|
let scrollPos = localStorage.getItem("scrollPosition");
|
|
|
|
|
|
|
|
if (scrollPos !== null) {
|
|
|
|
// Verzögert setzen, um das Springen zu minimieren
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
window.scrollTo(0, parseInt(scrollPos));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Speichert die Scroll-Position beim Verlassen der Seite
|
|
|
|
window.addEventListener("beforeunload", function() {
|
|
|
|
localStorage.setItem("scrollPosition", window.scrollY);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
2025-02-12 20:13:29 +01:00
|
|
|
</body>
|
|
|
|
</html>
|