Mercurial > defr > DualBlog
view comment.php @ 21:86a6793f1408
Temporary fix: si on envoie le prolog xml, IE sort du mode strict...
Idealement, il faudrait detecter ça en amont, et utiliser saveHTML
ou saveXML en fonction: ce serait probablement plus robuste.
Toutefois, il faut encore decider si cela doit se faire par
défaut dans la classe Template ou en spécialisation dans
skeleton (auquel cas, il est indispensable de passer Template::xmlDocument
en protected).
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Fri, 26 Oct 2007 17:55:35 +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; ?>