-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle.php
More file actions
77 lines (61 loc) · 2.51 KB
/
article.php
File metadata and controls
77 lines (61 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
require('inc/functions.php');
require('inc/database.php');
checkConnection();
include('inc/header.php');
if(!empty($_GET['id']) && is_numeric($_GET['id'])){
$id = $_GET['id'];
}else{
die('404');
}
$sql = "SELECT articles.*, users.pseudo FROM articles INNER JOIN users ON users.id=articles.author WHERE articles.id = $id";
$query = $pdo->prepare($sql);
$query->execute();
$article = $query->fetch();
if(empty($article)){
die('404');
}
$errors = array();
if(isConnected() && !empty($_POST['submitted']) && !empty($_POST['comment'])){
$commentaire = trim(strip_tags($_POST['comment']));
$errors = mistake($commentaire, 3, 255, 'comment', $errors);
if(empty($errors)){
$sql = 'INSERT INTO comments (article, user, content, created_at) VALUES (:article, :user, :content, NOW())';
$query = $pdo->prepare($sql);
$query->bindValue(':article', $article['id'], PDO::PARAM_INT);
$query->bindValue(':user', $_SESSION['user']['identifier'], PDO::PARAM_INT);
$query->bindValue(':content', $commentaire, PDO::PARAM_STR);
$query->execute();
}
}
?>
<div class="wrap1">
<div class="content">
<h2 class="h2-2"> <?= $article['title'];?></h2>
<p class="author">Par: <?= $article['pseudo'];?></p>
<p> Déscription: <?= $article['description'].'<br>'.$article['content'];?></p>
<p class="date"> Publié le: <?= date("Y/m/d à H:i", strtotime($article['published_at']));?></p>
</div>
<div class="wrap2">
<form action="" method="POST">
<input class="text-comment" type="text" name="comment" value="<?php if(!empty($_POST['comment'])) {echo $_POST['comment'];} ?>">
<span class="error"><?php if(!empty($errors['comment'])){echo $errors['comment'];}?></span>
<input class="sub-comment" type="submit" name="submitted" value="Envoyer le commentaire">
</form>
</div>
<?php
$comments = getCommentsByArticle($pdo, $article['id'], isConnected()? $_SESSION['user']['identifier']: -1, isConnected() && hasRole($_SESSION, MODERATOR, ADMINISTRATOR));
foreach($comments as $comment){
?>
<div class="comment">
<h3>Auteur: <?=$comment['pseudo'];?></h3>
<p><?=$comment['content'] ?></p>
<p><?=date("Y/m/d à H:i", strtotime($comment['created_at'])); ?></p>
</div>
<?php }
?>
<div>
</div>
</div>
<?php
include('inc/footer.php');