The following files exists in this folder. Click to view.
profile.php118 lines UTF-8 Unix (LF) 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
<?php
require_once("databaseconnection.php");
include("check_session.php");
if(!isset($_GET["mess"])){
header("location:home.php?mess=error");
exit;
}
$sql = "SELECT `displayName` FROM users WHERE `userId` = :userId";
$stm = $pdo->prepare($sql);
$stm->execute(['userId' => $_GET["mess"]]);
$profileName = $stm->fetch(PDO::FETCH_ASSOC);
$sql = "SELECT `blogId` FROM manage WHERE `userId` = :userId";
$stm = $pdo->prepare($sql);
$stm->execute(['userId' => $_GET["mess"]]);
$blogIdArray = $stm->fetchAll(PDO::FETCH_COLUMN); #Hämta alla Id på bloggar skapade utav användaren med id:t i GET_mess
if (!empty($blogIdArray)){ #stoppar nedanstående SQL från att köras om användaren inte har några bloggar. (stoppar error)
$placeholders = implode(',', array_fill(0, count($blogIdArray), '?'));
$sql = "SELECT `name` FROM blog WHERE `blogId` IN ($placeholders)"; #tar alla namn på bloggar som användaren har tillgång till.
$stm = $pdo->prepare($sql);
$stm->execute($blogIdArray);
$dbOutput = $stm->fetchAll(PDO::FETCH_COLUMN);
$authorId = $_GET["mess"];
$sql = "SELECT `headline`, `postId` FROM post WHERE `blogId` IN ($placeholders) AND `authorId` = ? ORDER BY `postId` DESC LIMIT 5"; #plockar info om de 5 senaste blogginläggen
$params = array_merge($blogIdArray, [$authorId]);
$stm = $pdo->prepare($sql);
$stm->execute($params);
$postInfo = $stm->fetchAll(PDO::FETCH_ASSOC);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php $outputName = htmlspecialchars($profileName["displayName"]); echo"$outputName"?>'s Profile</title>
<link rel="stylesheet" href="/spectre/spectre-master/dist/spectre.css">
<script src="https://kit.fontawesome.com/0b0c9a8dc7.js" crossorigin="anonymous"></script>
<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=Special+Gothic+Expanded+One&family=Special+Gothic:wght@400..700&display=swap" rel="stylesheet">
<style>
#navTop{
font-family: "Special Gothic Expanded One", Helvetica;
}
</style>
</head>
<body style="text-align:center;">
<header class="navbar">
<section class="navbar-section">
<a href="settings.php" class="btn btn-link">Settings</a>
<a href="home.php" class="btn btn-link">Home</a>
</section>
<section class="navbar-center">
<h3 id="navTop">PHiNTERNET</h3>
</section>
<section class="navbar-section">
<a href="newpost.php" class="btn btn-link">Create Post</a>
<a href="#" class="btn btn-link">Profile</a>
</section>
</header>
<?php
echo"<h1>{$outputName}'s profile</h1>";
if($_GET["mess"]==$_SESSION["userId"]){
echo"<p>this is your profile</p>";
}
else{
$sql = "SELECT 1 FROM `following` WHERE `userId` = :userId AND `followedUserId` = :followedUserId LIMIT 1";
$stm = $pdo->prepare($sql);
$stm->execute([
':userId' => $_SESSION["userId"],
':followedUserId' => $_GET["mess"]
]);
if($stm->fetch()){
echo"<p>you follow this person</p><a href=\"search.php?mess=u|{$_GET["mess"]}\" class=\"btn\">unfollow</a>";
}
else{
echo"<p>you do not follow this person</p><a href=\"search.php?mess=f|{$_GET["mess"]}\" class=\"btn btn-primary\">follow</a>";
}
}
echo"<hr><h3>Blogs:</h3>";
if (isset($dbOutput)){
for ($i=0; $i<= count($dbOutput)-1; $i++){
$outputBlogName=htmlspecialchars($dbOutput[$i]);
echo"<a style=\"margin:0.2rem;\" class=\"btn\" href=\"blogpostdisplay.php?mess=$blogIdArray[$i]\">{$outputBlogName}</a>"; #skriv ut alla bloggar som knappar
}
}
else{
echo"<p>user has no blogs</p>";
};
echo"<hr><h3>Latest Posts:</h3>";
if (isset($postInfo[0])){
for ($i=0; $i<=4; $i++){
if (isset($postInfo[$i])){
$outputPostName=htmlspecialchars($postInfo[$i]["headline"]);
echo"<a style=\"margin:0.2rem;\" class=\"h3\" href=\"blogwatcher.php?mess={$postInfo[$i]["postId"]}\">{$outputPostName}</a><br>"; #skriv ut alla posts som länkar i storlek h3
}
}
}
else{
echo"<p>user has no posts</p>";
};
?>
</body>
</html>