GEstion de l'ajout et de l'afichage des photos pour les commentaires !! SQL modifié

This commit is contained in:
leosw
2026-04-12 12:51:12 +02:00
parent 6e516f05cb
commit b9297c8617
3 changed files with 75 additions and 41 deletions

View File

@@ -181,7 +181,7 @@
<?php if ($isCommentable) { ?>
<!-- Comments -->
<div id="new_comment">
<form class="form" action="<?=$config['rel_root_folder']?>poi/<?=$poi->permalink?>/new_comment" method="post">
<form class="form" action="<?=$config['rel_root_folder']?>poi/<?=$poi->permalink?>/new_comment" method="post" enctype="multipart/form-data">
<div id="new_comment_label" <?=$isVisitor ? "class='sent' " : ""?>>
<?php if ($isArchiveOrPrivate) { ?>
<p>Impossible de commenter un point non publié</p>
@@ -194,6 +194,9 @@
</div>
<div id="new_comment_form">
<textarea id="comment" name="comment" rows="5" placeholder="Votre commentaire"></textarea>
<label for="photo">Ajouter une photo</label>
<input type="file" id="photo" name="photo" accept="image/*">
</div>
</form>
</div>
@@ -242,6 +245,12 @@
<div class="comment_content">
<?=$comment->comment_html?>
<?php if (!empty($comment->photo)) { ?>
<div class="comment-photo">
<img src="<?=$config['rel_root_folder'].'medias/comment_photos/'.$comment->photo?>" alt="Photo du commentaire">
</div>
<?php } ?>
</div>
</article>

View File

@@ -233,6 +233,18 @@ switch ($controller->splitted_url[1]) {
$Comment->author = $user->id;
$Comment->content = $poi->content_id;
$Comment->comment = $_POST['comment'];
if (!empty($_FILES['photo']['tmp_name'])) {
$tmp = $_FILES['photo']['tmp_name'];
$filename = uniqid('comment_').'.jpg'; // ou extension dynamique
$destination = $config['medias_folder'].'comment_photos/'.$filename;
move_uploaded_file($tmp, $destination);
// URL publique
$Comment->photo = $filename;
}
$Comment->insert();
}
}

View File

@@ -28,35 +28,32 @@ class Comment
public $locale = NULL;
public $comment_html = NULL;
public $author_obj = NULL;
public $photo = NULL;
/*****
** Connect to correct account using ID and stores its ID
*****/
public function checkID($id) {
global $config;
// Chargement du commentaire par ID.
$con = sql_connect();
$query = "SELECT * FROM content_comments WHERE id=$1";
$query = "SELECT c.*, p.url AS photo_url FROM content_comments c
LEFT JOIN content_comment_photos p ON p.comment_id = c.id WHERE c.id = $1";
pg_prepare($con, "prepare1", $query)
or die ("Cannot prepare statement\n");
$result = pg_execute($con, "prepare1", array($id))
or die ("Cannot execute statement\n");
pg_prepare($con, "prepare_comment_join", $query)
or die("Cannot prepare statement\n");
$result = pg_execute($con, "prepare_comment_join", array($id))
or die("Cannot execute statement\n");
pg_close($con);
if(pg_num_rows($result) == 1) {
if (pg_num_rows($result) == 1) {
$row = pg_fetch_assoc($result);
$this->populate($row);
return 1;
}
else {
return 0;
}
}
/*****
** Populate the object using its ID
@@ -97,6 +94,9 @@ class Comment
if (array_key_exists('locale', $row)) {
$this->locale = $row['locale'];
}
if (array_key_exists('photo_url', $row)) {
$this->photo = $row['photo_url'];
}
}
/*****
@@ -118,6 +118,15 @@ class Comment
$this->id = pg_fetch_assoc($result)['id'];
if(isset($this->photo) && $this->photo != NULL) {
$query = "INSERT INTO content_comment_photos (comment_id, url) VALUES
($1, $2)";
pg_prepare($con, "prepare2", $query)
or die ("Cannot prepare statement\n");
pg_execute($con, "prepare2", array($this->id, $this->photo));
}
pg_close($con);
}
@@ -208,26 +217,30 @@ class Comments
/*****
** Return the list of different articles
*****/
public function listComments($id, $archive=0) {
public function listComments($id, $archive = 0) {
global $config;
$con = sql_connect();
$query = "SELECT * FROM content_comments WHERE content = $1 ";
if ($archive == 0)
$query .= "AND is_archive IS FALSE AND is_public IS TRUE ";
$query .= "ORDER BY update_date DESC";
$query = "SELECT c.*, p.url AS photo_url FROM content_comments c
LEFT JOIN content_comment_photos p ON p.comment_id = c.id WHERE c.content = $1 ";
pg_prepare($con, "prepare1", $query)
or die ("Cannot prepare statement\n");
$result = pg_execute($con, "prepare1", array($id))
or die ("Cannot execute statement\n");
if ($archive == 0)
$query .= "AND c.is_archive IS FALSE AND c.is_public IS TRUE ";
$query .= "ORDER BY c.update_date DESC";
pg_prepare($con, "prepare_comment_list", $query)
or die("Cannot prepare statement\n");
$result = pg_execute($con, "prepare_comment_list", array($id))
or die("Cannot execute statement\n");
pg_close($con);
$this->number = pg_num_rows($result);
for($i = 0; $i < pg_num_rows($result); $i++) {
for ($i = 0; $i < $this->number; $i++) {
$row = pg_fetch_assoc($result, $i);
$this->objs[$i] = new Comment;
$this->objs[$i]->populate($row);