Mercurial > defr > DualBlog
changeset 16:116ef98b4cb5
L'affichage d'un post unique avec commentaire utilise maintenant les templates aussi.
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Fri, 26 Oct 2007 16:26:56 +0200 |
parents | 3b7c1400f89a |
children | c6d2b32e4992 |
files | comment.php templates/comment.xml templates/commentForm.xml |
diffstat | 3 files changed, 71 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/comment.php Fri Oct 26 14:36:59 2007 +0200 +++ b/comment.php Fri Oct 26 16:26:56 2007 +0200 @@ -1,11 +1,12 @@ <?php - setlocale(LC_ALL, "fr_FR.utf8@euro"); - ini_set("display_errors", "off"); - include("classes.php"); + require_once("classes.php"); + $sk = Factory::getSkeleton(); $id = $_GET['id']; - $Data = new DataAccess; + $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'); @@ -15,8 +16,6 @@ // 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>')) - $Comment = '<![CDATA[' . str_replace(']]>', ']]>',$Comment) . ']]>';*/ if(DOMDocument::loadXML('<comment>' . $Comment . '</comment>')) { $Data->debugQuery(" INSERT INTO Commentaires(MessId, Auteur, Adresse, AdresseMail, Comment, DateComment, ip) @@ -30,64 +29,43 @@ } } + // Ajout du post au squelette $Data->Query("SELECT * FROM Mess WHERE num_mess = {$id}"); $row = $Data->GetRow(); - $mood = ''; - $Mess=$Data->utf8_ensure(str_replace("<P>","<p>",str_replace("</P>","</p>", $row['Message']))); - $dateFormatee = strftime("%A %d %B %Y, %Hh%M", strtotime($row['DatePost'])); - $Titre = $Data->utf8_ensure($row['Titre']); - $Titre_url = str_replace(" ", "_", strip_tags($Titre)); - $Titre_url = str_replace("-", "_", $Titre_url); - include("top.php"); - if(!empty($row['Emot'])) { - $mood = "<img src='/blog/mood/{$row['Emot']}.png' alt='Mood : {$row['Emot']}' class='mood' />"; - $row['Emot'] = " " . $row['Emot']; - } - echo(" - <div class='PostContent{$row['Emot']}'> - <h2>{$Titre} | <span class='Date'>{$dateFormatee}</span></h2> - {$mood} - {$Mess}<br /> - {$infos} - </div>"); + $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())) { - $dateFormatee = strftime(" à %Hh%M le <span class='Date'>%A %d %B %Y</span>", strtotime($row['DateComment'])); - $AdresseMail = $row['AdresseMail']; - $grav_id = md5($AdresseMail); - $Comment = nl2br($row['Comment']); - $Comment = str_replace(" & ", " & ", $Comment); - if($row['num_comm'] == 172) $Comment = str_replace("</sup>", "</del>", $Comment); - //if(stristr($Adresse, "@")) $Adresse = "mailto:" . $Adresse; - $betterHref = (stristr($row['Adresse'], 'http://') != false)?"href='{$row['Adresse']}'":''; - echo(" - <div class='PostContent'> - <div class='Infos'> - <img class='gravatar' src='http://www.gravatar.com/avatar.php?gravatar_id={$grav_id}&size=50&default=$defaultGravatar' alt='' /> - <a {$betterHref} name='c{$row['num_comm']}'>{$row['Auteur']}</a> {$dateFormatee} - </div> - <div class='Comment'>{$Comment}</div> - <br class='endComment' /> - </div>"); + $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); } - echo(" - <div class='PostContent'> - <a href='/blog/'>Revenir au blog</a> - </div> - <div class='PostContent'> - <form method='post' action='#'> - <div id='FormCommentaire'> - Vous souhaitez ajouter un nouveau commentaire ? Faites donc, il vous suffit de remplir - le petit formulaire ci-dessous. - <input type='text' name='Auteur' value='Votre Nom' onfocus=\"if(this.value== this.getAttribute('value')) this.value='';\" /> - <input type='text' name='AdresseMail' value='Une adresse mail où vous joindre ? ( Non affichée publiquement )' onfocus=\"if(this.value == this.getAttribute('value')) this.value='';\"/> - <input type='text' name='Adresse' value='Un site web à vous ?' onfocus=\"if(this.value == this.getAttribute('value')) this.value='';\"/> - <textarea name='Comment' rows='10' cols='40' onfocus=\"if(this.value == 'Et z\'enfin, votre petit commentaire') this.value='';\">Et z'enfin, votre petit commentaire</textarea> - <input type='submit' value='Poster ce commentaire' /> - </div> - </form> - </div> - "); - include("foot.php"); + + // Ajout du formulaire d'ajout de commentaires + $commentForm = new Template('commentForm.xml'); + $sk->addBlogPost($commentForm); + + echo $sk; ?>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/comment.xml Fri Oct 26 16:26:56 2007 +0200 @@ -0,0 +1,11 @@ +<?xml version='1.0' encoding='UTF-8'?> +<div class='PostContent' + xmlns='http://www.w3.org/1999/xhtml' + xmlns:tr='http://defr.net/2007/template'> + <div class='Infos'> + <img class='gravatar' tr:id='gravatar' alt='' /> + <a tr:id='auteur' /> <tr:dateComment /> + </div> + <div class='Comment'><tr:comment /></div> + <br class='endComment' /> +</div>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/commentForm.xml Fri Oct 26 16:26:56 2007 +0200 @@ -0,0 +1,21 @@ +<?xml version='1.0' encoding='UTF-8'?> +<tr:wrapper + xmlns='http://www.w3.org/1999/xhtml' + xmlns:tr='http://defr.net/2007/template'> +<div class='PostContent'> + <a href='/blog/'>Revenir au blog</a> +</div> +<div class='PostContent'> +<form method='post' action='#'> + <div id='FormCommentaire'> + Vous souhaitez ajouter un nouveau commentaire ? Faites donc, il vous suffit de remplir + le petit formulaire ci-dessous. + <input type='text' name='Auteur' value='Votre Nom' onfocus="if(this.value== this.getAttribute('value')) this.value='';" /> + <input type='text' name='AdresseMail' value='Une adresse mail où vous joindre ? ( Non affichée publiquement )' onfocus="if(this.value == this.getAttribute('value')) this.value='';"/> + <input type='text' name='Adresse' value='Un site web à vous ?' onfocus="if(this.value == this.getAttribute('value')) this.value='';"/> + <textarea name='Comment' rows='10' cols='40' onfocus="if(this.value == 'Et z\'enfin, votre petit commentaire') this.value='';">Et z'enfin, votre petit commentaire</textarea> + <input type='submit' value='Poster ce commentaire' /> + </div> +</form> +</div> +</tr:wrapper>