
- /include/functions.php - /html/users/index.php - /html/admin/index.php - /html/news/index.php
217 lines
8.4 KiB
PHP
217 lines
8.4 KiB
PHP
<?php // Functions
|
|
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['userID'])) {
|
|
$_SESSION['userAccreditation'] = 0;
|
|
$_SESSION['userLevel'] = 0;
|
|
}
|
|
|
|
if (!isset($_COOKIE['theme'])) {
|
|
setcookie('theme', 0, time()+10*60*60);
|
|
$darkTheme = $darkThemes[0];
|
|
$lightTheme = $lightThemes[0];
|
|
}
|
|
|
|
if (isset($_GET['theme'])) {
|
|
$newTheme = (int)$_GET['theme'] % 2;
|
|
setcookie('theme', $newTheme); // % 2 => Number of different themes
|
|
$darkTheme = $darkThemes[$newTheme];
|
|
$lightTHeme = $lightThemes[$newTheme];
|
|
|
|
} else if (isset($_COOKIE['theme'])) {
|
|
$theme = (int)$_COOKIE['theme'] % 2;
|
|
$darkTheme = $darkThemes[$theme];
|
|
$lightTheme = $lightThemes[$theme];
|
|
}
|
|
|
|
$status = "";
|
|
|
|
function markdownContent($filePath, $rootFilePath) {
|
|
$markdownContent = file_get_contents($filePath);
|
|
require_once $rootFilePath . 'include/parsedown.php';
|
|
$parsedown = new Parsedown();
|
|
return $parsedown->text($markdownContent);
|
|
}
|
|
|
|
function fillHead($rootPageURL, $pageTitle, $darkTheme, $lightTheme) {
|
|
|
|
echo ('<meta charset="UTF-8">');
|
|
echo ('<meta name="viewport" content="width=device-width, initial-scale=1.0">');
|
|
echo ('<link rel="stylesheet" href="' . $rootPageURL . 'src/css/style.css">');
|
|
echo ('<link rel="icon" href="' . $rootPageURL . 'src/img/favicon.ico">');
|
|
|
|
echo ('<style>');
|
|
|
|
echo ('@media (prefers-color-scheme: dark) {');
|
|
echo ('.body {');
|
|
echo ($darkTheme);
|
|
echo ('}');
|
|
echo ('}');
|
|
|
|
echo ('@media (prefers-color-scheme: light) {');
|
|
echo ('.body {');
|
|
echo ($lightTheme);
|
|
echo ('}');
|
|
echo ('}');
|
|
|
|
echo ('</style>');
|
|
|
|
echo ('<title>' . $pageTitle . '</title>');
|
|
}
|
|
|
|
function fillHeader($rootPageURL, $headerTitle, $headerSubtitle) {
|
|
|
|
echo ('<div class="logo-container">');
|
|
|
|
echo ('<a href="' . $rootPageURL . '">');
|
|
echo ('<img src="' . $rootPageURL . 'src/img/athena-mono.png" class="logo-img">');
|
|
echo ('</a>');
|
|
|
|
echo ('</div>');
|
|
|
|
echo ('<div class="content">');
|
|
|
|
echo ('<div class="header-title-container">');
|
|
echo ('<div class="header-title">' . $headerTitle . '</div>');
|
|
echo ('<div class="header-subtitle">' . $headerSubtitle . '</div>');
|
|
echo ('</div>');
|
|
|
|
echo ('</div>');
|
|
}
|
|
|
|
function fillNav($rootPageURL) {
|
|
|
|
echo ('<a href="' . $rootPageURL . 'news"><div class="nav-link">News</div></a>');
|
|
echo ('<a href="' . $rootPageURL . 'about"><div class="nav-link">A propos</div></a>');
|
|
|
|
if ($_SESSION['userLevel'] >= 3) {
|
|
echo ('<a href="' . $rootPageURL . 'admin"><div class="nav-link">Admin</div></a>');
|
|
}
|
|
|
|
if(isset($_SESSION['userID'])) {
|
|
echo ('<a href="' . $rootPageURL . 'account"><div class="nav-link">Profil</div></a>');
|
|
echo ('<a href="' . $rootPageURL . 'settings"><div class="nav-link">Options</div></a>');
|
|
echo ('<a href="' . $rootPageURL . 'login/logout.php"><div class="nav-link">Déconnexion</div></a>');
|
|
} else {
|
|
echo ('<a href="' . $rootPageURL . 'login"><div class="nav-link">Se connecter</div></a>');
|
|
}
|
|
}
|
|
|
|
function fillFooter($footerText) {
|
|
echo($footerText);
|
|
}
|
|
|
|
function sqlConnect($dbHost, $dbName, $dbUser, $dbPass) {
|
|
try {
|
|
$pdo = new PDO('mysql:host=' . $dbHost . ';dbname=' . $dbName . ';charset=UTF8mb4', $dbUser, $dbPass);
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
} catch(Exception $e) {
|
|
require('error.php');
|
|
die();
|
|
}
|
|
|
|
return $pdo;
|
|
}
|
|
|
|
function userWidget($userPPURL, $userDisplayName, $userName, $userCertification, $certificationColors, $rootPageURL) {
|
|
|
|
echo ('<a href="' . $rootPageURL . 'users?u=' . $userName . '" class="user-widget-link">');
|
|
echo ('<div class="user-widget">');
|
|
|
|
echo ('<div class="user-pp">');
|
|
echo ('<img src="' . $userPPURL . '">');
|
|
echo ('</div>');
|
|
|
|
echo ('<div class="user-info">');
|
|
|
|
echo ('<div class="user-display-name">');
|
|
echo ($userDisplayName);
|
|
if ($userCertification > 0) {
|
|
echo ('<svg class="certification" fill="' . $certificationColors[$userCertification] . '" viewBox="0 0 22 22" aria-label="' . $certificationColors[$userCertification] . '" role="img">');
|
|
echo ('<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>');
|
|
echo ('</svg>');
|
|
}
|
|
echo ('</div>');
|
|
|
|
echo ('<div class="user-name">@' . $userName . '</div>');
|
|
|
|
echo ('</div>');
|
|
|
|
echo ('</div>');
|
|
echo ('</a>');
|
|
}
|
|
|
|
function listArticles($result, $rootPageURL) {
|
|
|
|
foreach($result as $article) {
|
|
$pubDateTime = strtotime($article['date']);
|
|
$pubDate = date('d/m/Y', $pubDateTime);
|
|
$articleID = $article['ID'];
|
|
$articleTitle = $article['title'];
|
|
$articleResume = $article['resume'];
|
|
$miniatureURL = empty($article['miniature']) ? $rootPageURL . "src/img/empty.jpg" : $article['miniature'];
|
|
if(isset($article['username']) && isset($article['display_name'])) {
|
|
$authorLink = ' | <a href="user.php?user=' . $article['username'] . '">' . $article['display_name'] . '</a>';
|
|
} else {
|
|
$authorLink = '';
|
|
}
|
|
|
|
echo('<div class="article-preview">');
|
|
|
|
echo('<a href="'. $rootPageURL .'news?article=' . $articleID . '" class="article-link">');
|
|
echo('<div class="article-illustration">');
|
|
|
|
echo('<img src="' . $miniatureURL . '" class="article-miniature">');
|
|
|
|
echo('</div>');
|
|
echo('</a>');
|
|
|
|
echo('<div class="article-info">');
|
|
echo('<div class="article-data">n° ' . $articleID . ' | ' . $pubDate . '</div>');
|
|
|
|
echo('<a href="'. $rootPageURL .'news?article=' . $articleID . '" class="article-link">');
|
|
echo('<div class="article-title">' . $articleTitle . '</div>');
|
|
echo('</a>');
|
|
|
|
echo('<div class="article-resume">' . $articleResume . '</div>');
|
|
|
|
echo('</div>');
|
|
echo('</div> ');
|
|
}
|
|
}
|
|
|
|
function textInput($type, $shapePath, $name, $placeholder, $value) {
|
|
|
|
echo ('<div class="text-input">');
|
|
echo ('<label for="' . $name . '">');
|
|
echo ('<svg viewBox="0 0 24 24" aria-hidden="true" class="input-icon">');
|
|
echo ('<g>' . $shapePath . '</g>');
|
|
echo ('</svg>');
|
|
echo ('</label>');
|
|
echo ('<input type="' . $type . '" placeholder="' . $placeholder . '" name="' . $name . '" value="' . $value . '">');
|
|
echo ('</div>');
|
|
}
|
|
|
|
function fileInput($name) {
|
|
echo ('<div class="file-input">');
|
|
echo ('<input type="file" name="' . $name . '">');
|
|
echo ('</div>');
|
|
}
|
|
|
|
function selectInput($name, $label, $options, $defaultValue) {
|
|
echo('<div class="select-input">');
|
|
echo('<label for="' . $name . '">' . $label . '</label>');
|
|
echo('<select name="' . $name .'" required>');
|
|
|
|
foreach($options as $value => $name) {
|
|
$selectStatus = $value == $defaultValue ? "selected" : "";
|
|
echo ('<option value="' . $value .'" ' . $selectStatus . '>' . $name . '</option>');
|
|
}
|
|
|
|
echo('</select>');
|
|
echo('</div>');
|
|
}
|
|
|
|
?>
|