Mercurial > defr > DualBlog
view comment.php @ 17:c6d2b32e4992
Ne *pas* utiliser la forme courte sur les <script />, IE ne comprend pas.
En conséquence, ajout d'un commentaire javascript adéquat de façon à ce que
l'on ne se retrouve jamais avec une balise vide que le serializer XML aurait
tendance, et avec raison, à transformer.
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Fri, 26 Oct 2007 16:35:08 +0200 |
parents | 116ef98b4cb5 |
children | 6e084c604876 |
line wrap: on
line source
<?php require_once("classes.php"); $sk = Factory::getSkeleton(); $id = $_GET['id']; $Data = Factory::getDB(); $Req = new Requete; // Enregistrement éventuel d'un commentaire dans la base de données $Auteur=$Req->get('Auteur'); $Adresse=$Req->get('Adresse'); $AdresseMail = $Req->get('AdresseMail'); $Comment=$Req->get('Comment'); $DateComment=gmdate("Y-m-d H:i:s", time() + 3600*2); if(!is_null($Auteur) && $Auteur!='Votre Nom' && $Auteur != $Adresse && !empty($Comment)) { // Prévention d'un "cassage" par ajout d'un commentaire incorrectement formaté $ip = $_SERVER['REMOTE_ADDR']; $Auteur = str_replace(array('<', '>'), array('<', '>'), $Auteur); if(DOMDocument::loadXML('<comment>' . $Comment . '</comment>')) { $Data->debugQuery(" INSERT INTO Commentaires(MessId, Auteur, Adresse, AdresseMail, Comment, DateComment, ip) VALUES({$id}, '{$Auteur}', '{$Adresse}', '{$AdresseMail}', '{$Comment}', '{$DateComment}', '{$ip}') "); $Data->Query("UPDATE Mess SET NbCommentaires=NbCommentaires+1 WHERE num_mess={$id}"); mail('webmaster+blogcomment@defr.org', 'Nouveau commentaire sur de ' . $Auteur, $Auteur . " vient de mettre en ligne le commentaire suivant: \n" . wordwrap($Comment, 70)); } else { $infos = 'Votre commentaire doit etre fait de XML valide pour apparaitre.'; } } // Ajout du post au squelette $Data->Query("SELECT * FROM Mess WHERE num_mess = {$id}"); $row = $Data->GetRow(); $post = new Post($row); $sk->addBlogPost($post->format()); // Récupération des commentaires $Data->Query("SELECT * FROM Commentaires Where MessId={$id} AND Visible=1 ORDER BY num_comm"); $defaultGravatar = urlencode("http://defr.org/Misc/NoGravatar.png"); while(0 !== ($row = $Data->GetRow())) { $commentTpl = new Template('comment.xml'); $dateFormatee = strftime(" à %Hh%M le <span class='Date'>%A %d %B %Y</span>", strtotime($row['DateComment'])); $AdresseMail = $row['AdresseMail']; $grav_id = md5($AdresseMail); $grav_url = 'http://www.gravatar.com/avatar.php?gravatar_id=' . $grav_id . '&size=50&default=' . $defaultGravatar; $Comment = nl2br($row['Comment']); $Comment = str_replace(" & ", " & ", $Comment); $commentFrag = $commentTpl->getDocumentFragment(); $commentFrag->appendXML($Comment); $params = array( '#gravatar@src' => $grav_url, '#auteur@href' => 'TODO', '#auteur@name' => 'c' . $row['num_comm'], '#auteur' => $row['Auteur'], 'commentDate' => $dateFormatee, 'comment' => $commentFrag, ); if(stristr($row['Adresse'], 'http://')) { $params['#auteur@href'] = $row['Adresse']; } $commentTpl->setParams($params); $sk->addBlogPost($commentTpl); } // Ajout du formulaire d'ajout de commentaires $commentForm = new Template('commentForm.xml'); $sk->addBlogPost($commentForm); echo $sk; ?>