e59-website/html/users/index.php
Jan BELLON d174f7f196 Update 4 files
- /include/functions.php
- /html/users/index.php
- /html/admin/index.php
- /html/news/index.php
2024-03-14 23:49:12 +00:00

148 lines
7.6 KiB
PHP

<?php
require("../../include/variables.php");
require("../../include/functions.php");
$pdo = sqlConnect($sqlDatabaseHost, $sqlDatabaseName, $sqlDatabaseUser, $sqlDatabasePass);
if(isset($_GET['u']) && empty($_GET['u']) == false) {
$request = $pdo->prepare("SELECT ID, username, display_name, profile_picture, banner, bio, certification FROM users WHERE username = :username");
$request->bindParam(":username", htmlspecialchars($_GET['u']));
$request->execute();
$result = $request->fetchAll(PDO::FETCH_ASSOC);
if($result) {
$userID = $result[0]['ID'];
$userName = $result[0]['username'];
$userDisplayName = $result[0]['display_name'];
$userPPURL = $result[0]['profile_picture'] == NULL ? "https://abs.twimg.com/sticky/default_profile_images/default_profile_400x400.png" : $result[0]['profile_picture'];
$userBanner = $result[0]['banner'] = NULL ? "" : $result[0]['banner'];
$userBio = $result[0]['bio'];
$userCertification = $result[0]['certification'];
} else {
$userID = 0;
$userName = htmlspecialchars($_GET['u']);
$userDisplayName = "Unknown";
$userPPURL = "https://abs.twimg.com/sticky/default_profile_images/default_profile_400x400.png";
$userBanner = "";
$userBio = "";
$userCertification = 0;
}
} else {
$userID = 0;
$userName = htmlspecialchars($_GET['u']);
$userDisplayName = "Unknown";
$userPPURL = "https://abs.twimg.com/sticky/default_profile_images/default_profile_400x400.png";
$userBanner = "";
$userBio = "";
$userCertification = 0;
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<?php fillHead($rootPageURL, $pageTitle, $darkTheme, $lightTheme);?>
<style>
.content {
padding: 0;
width: 100%;
}
.user-banner {
<?php
if (empty($userBanner)) {
echo "background-color: black";
} else {
echo "background-image: url('" . $userBanner . "');";
}
?>
}
.certification {
fill: <?php echo $userCertification > 0 ? $certificationColors[$userCertification] : "#000000"?>;
}
</style>
</head>
<body class="body">
<header>
<div class="panel-content">
<?php fillHeader($rootPageURL, $headerTitle, $headerSubtitle);?>
</div>
</header>
<nav>
<div class="panel-content">
<?php fillNav($rootPageURL);?>
</div>
</nav>
<main>
<div class="content">
<div class="user-profile">
<div class="user-banner"></div>
<div class="user-header">
<div class="user-header-content">
<div class="user-pp"><img src="<?=$userPPURL?>"></div>
<div class="status"><?=$status?></div>
<div class="user-info">
<div class="names">
<div class="display-name"><?=$userDisplayName?></div>
<div class="user-level">
<?php
if($userCertification > 0) {
echo '<svg class="certification" viewBox="0 0 22 22" aria-label="Compte certifié" role="img"><g><path class="cls-1" d="M21.62,10.02l-.86-.95c-.31-.35-.44-.82-.34-1.28l.27-1.26c.16-.73-.26-1.46-.98-1.69l-1.22-.39c-.45-.14-.79-.49-.94-.94l-.39-1.22c-.23-.71-.96-1.13-1.69-.98l-1.26.27c-.46.1-.93-.03-1.28-.34l-.95-.86c-.55-.5-1.4-.5-1.95,0l-.95.86c-.35.31-.82.44-1.28.34l-1.26-.27c-.73-.16-1.46.26-1.69.98l-.39,1.22c-.14.45-.49.79-.94.94l-1.22.39c-.71.23-1.13.96-.98,1.69l.27,1.26c.1.46-.03.93-.34,1.28l-.86.95c-.5.55-.5,1.4,0,1.95l.86.95c.31.35.44.82.34,1.28l-.27,1.26c-.16.73.26,1.46.98,1.69l1.22.39c.45.14.79.49.94.94l.39,1.22c.23.71.96,1.13,1.69.98l1.26-.27c.46-.1.93.03,1.28.34l.95.86c.55.5,1.4.5,1.95,0l.95-.86c.35-.31.82-.44,1.28-.34l1.26.27c.73.16,1.46-.26,1.69-.98l.39-1.22c.14-.45.49-.79.94-.94l1.22-.39c.71-.23,1.13-.96.98-1.69l-.27-1.26c-.1-.46.03-.93.34-1.28l.86-.95c.5-.55.5-1.4,0-1.95ZM16.77,9.3l-6.67,6.67c-.36.36-.95.36-1.32,0l-3.55-3.55c-.47-.47-.47-1.24,0-1.71.47-.47,1.24-.47,1.71,0l2.5,2.5,5.61-5.61c.47-.47,1.24-.47,1.71,0,.47.47.47,1.24,0,1.71Z"/></g></svg>';
}
?>
</div>
<div class="username">@<?=$userName?></div>
<div class="bio"><?=$userBio?></div>
</div>
<div>
<?php
if ($userID == $_SESSION['userID']) {
echo '<a href="/account" class="button">Editer votre profil</a>';
}
?>
</div>
</div>
</div>
</div>
<div class="user-articles">
<div class="user-content">
<?php
$search = isset($_GET['search']) ? "%" . htmlspecialchars($_GET['search']) . "%" : "%%";
$request = $pdo->prepare("SELECT ID, title, date, miniature, resume FROM articles WHERE (title LIKE :search OR ID LIKE :search) AND author = :userID ORDER BY date DESC");
$request->bindParam(":search", $search);
$request->bindParam(":userID", $userID);
$request->execute();
$result = $request->fetchAll(PDO::FETCH_ASSOC);
echo ('<h1>Articles de ' . $userDisplayName . '</h1>');
echo ('<form action="#" method="get">');
$shapePath = '<path d="M10.25 3.75c-3.59 0-6.5 2.91-6.5 6.5s2.91 6.5 6.5 6.5c1.795 0 3.419-.726 4.596-1.904 1.178-1.177 1.904-2.801 1.904-4.596 0-3.59-2.91-6.5-6.5-6.5zm-8.5 6.5c0-4.694 3.806-8.5 8.5-8.5s8.5 3.806 8.5 8.5c0 1.986-.682 3.815-1.824 5.262l4.781 4.781-1.414 1.414-4.781-4.781c-1.447 1.142-3.276 1.824-5.262 1.824-4.694 0-8.5-3.806-8.5-8.5z"></path>';
textInput("text", $shapePath, "search", "Chercher", "");
echo ('</form>');
if ($result) {
echo('<div class="articles-list">');
listArticles($result, $rootPageURL);
echo ('</div>');
} else {
echo ($userDisplayName . ' n\'a encore rien publié');
}
?>
</div>
</div>
</form>
</div>
</div>
</main>
<footer>
<div class="panel-content">
<?php fillFooter($footerText);?>
</div>
</footer>
</body>
</html>