You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
3.6 KiB
PHP
145 lines
3.6 KiB
PHP
<?php
|
|
|
|
require 'lib/database.php';
|
|
require 'lib/project.php';
|
|
|
|
if (!isset($_GET['id'])) {
|
|
include '404.php';
|
|
die;
|
|
}
|
|
|
|
$id = (int) $_GET['id'];
|
|
|
|
$project = getProject($id);
|
|
|
|
if (false === $project) {
|
|
include '404.php';
|
|
die;
|
|
}
|
|
|
|
if (isset($_POST['name'], $_POST['email'], $_POST['website'], $_POST['content'])) {
|
|
$name = trim($_POST['name']);
|
|
$email = trim($_POST['email']);
|
|
$website = trim($_POST['website']);
|
|
$content = trim($_POST['content']);
|
|
|
|
$valid = true;
|
|
|
|
foreach ([$name, $email, $content] as $field) {
|
|
if (empty($field)) {
|
|
$valid = false;
|
|
}
|
|
}
|
|
|
|
if ($valid) {
|
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$valid = false;
|
|
}
|
|
}
|
|
|
|
if ($valid) {
|
|
createComment(
|
|
$name,
|
|
$email,
|
|
$website,
|
|
$content,
|
|
new DateTime('now'),
|
|
$id
|
|
);
|
|
|
|
header('Location: project.php?id='.$id);
|
|
die;
|
|
}
|
|
}
|
|
|
|
$comments = getCommentsByProject($id);
|
|
|
|
?>
|
|
<!DOCTYPE HTML>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<link rel="stylesheet" href="style.css" />
|
|
<title>
|
|
Mon super portfolio - <?php echo $project['title'] ?>
|
|
</title>
|
|
</head>
|
|
<body>
|
|
<h1>
|
|
<?php echo $project['title'] ?>
|
|
</h1>
|
|
|
|
<section>
|
|
<article>
|
|
<figure>
|
|
<img src="images/<?php echo $project['illustration'] ?>" alt="" width="130px" />
|
|
</figure>
|
|
|
|
<p class="description">
|
|
<?php echo $project['description'] ?>
|
|
</p>
|
|
|
|
<?php $date = new DateTime($project['date']); ?>
|
|
|
|
<p class="date">
|
|
<time datetime="<?php echo $date->format(DateTime::W3C) ?>">
|
|
<?php echo $date->format('d/m/Y') ?>
|
|
</time>
|
|
</p>
|
|
</article>
|
|
</section>
|
|
|
|
<section>
|
|
<h2>Commentaires</h2>
|
|
|
|
<div>
|
|
<form action="" method="POST">
|
|
<p>
|
|
<label for="form-name">Nom</label>
|
|
<input name="name" required id="form-name" type="text" />
|
|
</p>
|
|
<p>
|
|
<label for="form-mail">Email</label>
|
|
<input name="email" required id="form-mail" type="mail" />
|
|
</p>
|
|
<p>
|
|
<label for="form-website">Site web</label>
|
|
<input name="website" id="form-website" type="website" />
|
|
</p>
|
|
<p>
|
|
<textarea name="content" required rows="10" cols="30"></textarea>
|
|
</p>
|
|
|
|
<p>
|
|
<input type="submit" value="Go go go!" />
|
|
</p>
|
|
</form>
|
|
</div>
|
|
|
|
<?php foreach ($comments as $comment): ?>
|
|
<div>
|
|
<p>
|
|
<img src="<?php echo $comment['avatar'] ?>" alt="" />
|
|
|
|
<?php if ($comment['website']): ?>
|
|
<a href="<?php echo htmlspecialchars($comment['website']) ?>">
|
|
<?php endif ?>
|
|
|
|
<?php echo htmlspecialchars($comment['name']) ?>
|
|
|
|
<?php if ($comment['website']): ?>
|
|
</a>
|
|
<?php endif ?>
|
|
|
|
- Posté le <?php echo $comment['date']->format('d/m/Y à H:i') ?>
|
|
</p>
|
|
|
|
<p>
|
|
<?php echo nl2br(htmlspecialchars($comment['content'])) ?>
|
|
</p>
|
|
</div>
|
|
<?php endforeach ?>
|
|
</section>
|
|
</body>
|
|
</html>
|