GEstion de l'ajout et de l'afichage des photos pour les commentaires !! SQL modifié
This commit is contained in:
@@ -181,7 +181,7 @@
|
|||||||
<?php if ($isCommentable) { ?>
|
<?php if ($isCommentable) { ?>
|
||||||
<!-- Comments -->
|
<!-- Comments -->
|
||||||
<div id="new_comment">
|
<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' " : ""?>>
|
<div id="new_comment_label" <?=$isVisitor ? "class='sent' " : ""?>>
|
||||||
<?php if ($isArchiveOrPrivate) { ?>
|
<?php if ($isArchiveOrPrivate) { ?>
|
||||||
<p>Impossible de commenter un point non publié</p>
|
<p>Impossible de commenter un point non publié</p>
|
||||||
@@ -194,6 +194,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="new_comment_form">
|
<div id="new_comment_form">
|
||||||
<textarea id="comment" name="comment" rows="5" placeholder="Votre commentaire"></textarea>
|
<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>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@@ -242,6 +245,12 @@
|
|||||||
|
|
||||||
<div class="comment_content">
|
<div class="comment_content">
|
||||||
<?=$comment->comment_html?>
|
<?=$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>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
|||||||
@@ -233,6 +233,18 @@ switch ($controller->splitted_url[1]) {
|
|||||||
$Comment->author = $user->id;
|
$Comment->author = $user->id;
|
||||||
$Comment->content = $poi->content_id;
|
$Comment->content = $poi->content_id;
|
||||||
$Comment->comment = $_POST['comment'];
|
$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();
|
$Comment->insert();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,35 +28,32 @@ class Comment
|
|||||||
public $locale = NULL;
|
public $locale = NULL;
|
||||||
public $comment_html = NULL;
|
public $comment_html = NULL;
|
||||||
public $author_obj = NULL;
|
public $author_obj = NULL;
|
||||||
|
public $photo = NULL;
|
||||||
|
|
||||||
|
|
||||||
/*****
|
|
||||||
** Connect to correct account using ID and stores its ID
|
|
||||||
*****/
|
|
||||||
public function checkID($id) {
|
public function checkID($id) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
// Chargement du commentaire par ID.
|
// Chargement du commentaire par ID.
|
||||||
$con = sql_connect();
|
$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)
|
pg_prepare($con, "prepare_comment_join", $query)
|
||||||
or die ("Cannot prepare statement\n");
|
or die("Cannot prepare statement\n");
|
||||||
$result = pg_execute($con, "prepare1", array($id))
|
|
||||||
or die ("Cannot execute statement\n");
|
$result = pg_execute($con, "prepare_comment_join", array($id))
|
||||||
|
or die("Cannot execute statement\n");
|
||||||
|
|
||||||
pg_close($con);
|
pg_close($con);
|
||||||
|
|
||||||
if(pg_num_rows($result) == 1) {
|
if (pg_num_rows($result) == 1) {
|
||||||
$row = pg_fetch_assoc($result);
|
$row = pg_fetch_assoc($result);
|
||||||
$this->populate($row);
|
$this->populate($row);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*****
|
/*****
|
||||||
** Populate the object using its ID
|
** Populate the object using its ID
|
||||||
@@ -97,6 +94,9 @@ class Comment
|
|||||||
if (array_key_exists('locale', $row)) {
|
if (array_key_exists('locale', $row)) {
|
||||||
$this->locale = $row['locale'];
|
$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'];
|
$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);
|
pg_close($con);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,26 +217,30 @@ class Comments
|
|||||||
/*****
|
/*****
|
||||||
** Return the list of different articles
|
** Return the list of different articles
|
||||||
*****/
|
*****/
|
||||||
public function listComments($id, $archive=0) {
|
public function listComments($id, $archive = 0) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$con = sql_connect();
|
$con = sql_connect();
|
||||||
|
|
||||||
$query = "SELECT * FROM content_comments WHERE content = $1 ";
|
$query = "SELECT c.*, p.url AS photo_url FROM content_comments c
|
||||||
if ($archive == 0)
|
LEFT JOIN content_comment_photos p ON p.comment_id = c.id WHERE c.content = $1 ";
|
||||||
$query .= "AND is_archive IS FALSE AND is_public IS TRUE ";
|
|
||||||
$query .= "ORDER BY update_date DESC";
|
|
||||||
|
|
||||||
pg_prepare($con, "prepare1", $query)
|
if ($archive == 0)
|
||||||
or die ("Cannot prepare statement\n");
|
$query .= "AND c.is_archive IS FALSE AND c.is_public IS TRUE ";
|
||||||
$result = pg_execute($con, "prepare1", array($id))
|
|
||||||
or die ("Cannot execute statement\n");
|
$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);
|
pg_close($con);
|
||||||
|
|
||||||
$this->number = pg_num_rows($result);
|
$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);
|
$row = pg_fetch_assoc($result, $i);
|
||||||
$this->objs[$i] = new Comment;
|
$this->objs[$i] = new Comment;
|
||||||
$this->objs[$i]->populate($row);
|
$this->objs[$i]->populate($row);
|
||||||
|
|||||||
Reference in New Issue
Block a user