Mercurial > defr > DualBlog
comparison comment.php @ 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 | 7dec52982000 |
children | 6e084c604876 |
comparison
equal
deleted
inserted
replaced
15:3b7c1400f89a | 16:116ef98b4cb5 |
---|---|
1 <?php | 1 <?php |
2 setlocale(LC_ALL, "fr_FR.utf8@euro"); | 2 require_once("classes.php"); |
3 ini_set("display_errors", "off"); | 3 $sk = Factory::getSkeleton(); |
4 include("classes.php"); | |
5 $id = $_GET['id']; | 4 $id = $_GET['id']; |
6 $Data = new DataAccess; | 5 $Data = Factory::getDB(); |
7 $Req = new Requete; | 6 $Req = new Requete; |
8 | 7 |
8 | |
9 // Enregistrement éventuel d'un commentaire dans la base de données | |
9 $Auteur=$Req->get('Auteur'); | 10 $Auteur=$Req->get('Auteur'); |
10 $Adresse=$Req->get('Adresse'); | 11 $Adresse=$Req->get('Adresse'); |
11 $AdresseMail = $Req->get('AdresseMail'); | 12 $AdresseMail = $Req->get('AdresseMail'); |
12 $Comment=$Req->get('Comment'); | 13 $Comment=$Req->get('Comment'); |
13 $DateComment=gmdate("Y-m-d H:i:s", time() + 3600*2); | 14 $DateComment=gmdate("Y-m-d H:i:s", time() + 3600*2); |
14 if(!is_null($Auteur) && $Auteur!='Votre Nom' && $Auteur != $Adresse && !empty($Comment)) { | 15 if(!is_null($Auteur) && $Auteur!='Votre Nom' && $Auteur != $Adresse && !empty($Comment)) { |
15 // Prévention d'un "cassage" par ajout d'un commentaire incorrectement formaté | 16 // Prévention d'un "cassage" par ajout d'un commentaire incorrectement formaté |
16 $ip = $_SERVER['REMOTE_ADDR']; | 17 $ip = $_SERVER['REMOTE_ADDR']; |
17 $Auteur = str_replace(array('<', '>'), array('<', '>'), $Auteur); | 18 $Auteur = str_replace(array('<', '>'), array('<', '>'), $Auteur); |
18 /*if(!DOMDocument::loadXML('<comment>' . $Comment . '</comment>')) | |
19 $Comment = '<![CDATA[' . str_replace(']]>', ']]>',$Comment) . ']]>';*/ | |
20 if(DOMDocument::loadXML('<comment>' . $Comment . '</comment>')) { | 19 if(DOMDocument::loadXML('<comment>' . $Comment . '</comment>')) { |
21 $Data->debugQuery(" | 20 $Data->debugQuery(" |
22 INSERT INTO Commentaires(MessId, Auteur, Adresse, AdresseMail, Comment, DateComment, ip) | 21 INSERT INTO Commentaires(MessId, Auteur, Adresse, AdresseMail, Comment, DateComment, ip) |
23 VALUES({$id}, '{$Auteur}', '{$Adresse}', '{$AdresseMail}', '{$Comment}', '{$DateComment}', '{$ip}') | 22 VALUES({$id}, '{$Auteur}', '{$Adresse}', '{$AdresseMail}', '{$Comment}', '{$DateComment}', '{$ip}') |
24 "); | 23 "); |
28 else { | 27 else { |
29 $infos = 'Votre commentaire doit etre fait de XML valide pour apparaitre.'; | 28 $infos = 'Votre commentaire doit etre fait de XML valide pour apparaitre.'; |
30 } | 29 } |
31 } | 30 } |
32 | 31 |
32 // Ajout du post au squelette | |
33 $Data->Query("SELECT * FROM Mess WHERE num_mess = {$id}"); | 33 $Data->Query("SELECT * FROM Mess WHERE num_mess = {$id}"); |
34 $row = $Data->GetRow(); | 34 $row = $Data->GetRow(); |
35 $mood = ''; | 35 $post = new Post($row); |
36 $Mess=$Data->utf8_ensure(str_replace("<P>","<p>",str_replace("</P>","</p>", $row['Message']))); | 36 $sk->addBlogPost($post->format()); |
37 $dateFormatee = strftime("%A %d %B %Y, %Hh%M", strtotime($row['DatePost'])); | 37 |
38 $Titre = $Data->utf8_ensure($row['Titre']); | 38 // Récupération des commentaires |
39 $Titre_url = str_replace(" ", "_", strip_tags($Titre)); | |
40 $Titre_url = str_replace("-", "_", $Titre_url); | |
41 include("top.php"); | |
42 if(!empty($row['Emot'])) { | |
43 $mood = "<img src='/blog/mood/{$row['Emot']}.png' alt='Mood : {$row['Emot']}' class='mood' />"; | |
44 $row['Emot'] = " " . $row['Emot']; | |
45 } | |
46 echo(" | |
47 <div class='PostContent{$row['Emot']}'> | |
48 <h2>{$Titre} | <span class='Date'>{$dateFormatee}</span></h2> | |
49 {$mood} | |
50 {$Mess}<br /> | |
51 {$infos} | |
52 </div>"); | |
53 $Data->Query("SELECT * FROM Commentaires Where MessId={$id} AND Visible=1 ORDER BY num_comm"); | 39 $Data->Query("SELECT * FROM Commentaires Where MessId={$id} AND Visible=1 ORDER BY num_comm"); |
54 $defaultGravatar = urlencode("http://defr.org/Misc/NoGravatar.png"); | 40 $defaultGravatar = urlencode("http://defr.org/Misc/NoGravatar.png"); |
55 while(0 !== ($row = $Data->GetRow())) { | 41 while(0 !== ($row = $Data->GetRow())) { |
56 $dateFormatee = strftime(" à %Hh%M le <span class='Date'>%A %d %B %Y</span>", strtotime($row['DateComment'])); | 42 $commentTpl = new Template('comment.xml'); |
57 $AdresseMail = $row['AdresseMail']; | 43 $dateFormatee = strftime(" à %Hh%M le <span class='Date'>%A %d %B %Y</span>", strtotime($row['DateComment'])); |
58 $grav_id = md5($AdresseMail); | 44 $AdresseMail = $row['AdresseMail']; |
59 $Comment = nl2br($row['Comment']); | 45 $grav_id = md5($AdresseMail); |
60 $Comment = str_replace(" & ", " & ", $Comment); | 46 $grav_url = 'http://www.gravatar.com/avatar.php?gravatar_id=' . $grav_id . '&size=50&default=' . $defaultGravatar; |
61 if($row['num_comm'] == 172) $Comment = str_replace("</sup>", "</del>", $Comment); | 47 $Comment = nl2br($row['Comment']); |
62 //if(stristr($Adresse, "@")) $Adresse = "mailto:" . $Adresse; | 48 $Comment = str_replace(" & ", " & ", $Comment); |
63 $betterHref = (stristr($row['Adresse'], 'http://') != false)?"href='{$row['Adresse']}'":''; | 49 $commentFrag = $commentTpl->getDocumentFragment(); |
64 echo(" | 50 $commentFrag->appendXML($Comment); |
65 <div class='PostContent'> | 51 $params = array( |
66 <div class='Infos'> | 52 '#gravatar@src' => $grav_url, |
67 <img class='gravatar' src='http://www.gravatar.com/avatar.php?gravatar_id={$grav_id}&size=50&default=$defaultGravatar' alt='' /> | 53 '#auteur@href' => 'TODO', |
68 <a {$betterHref} name='c{$row['num_comm']}'>{$row['Auteur']}</a> {$dateFormatee} | 54 '#auteur@name' => 'c' . $row['num_comm'], |
69 </div> | 55 '#auteur' => $row['Auteur'], |
70 <div class='Comment'>{$Comment}</div> | 56 'commentDate' => $dateFormatee, |
71 <br class='endComment' /> | 57 'comment' => $commentFrag, |
72 </div>"); | 58 ); |
59 if(stristr($row['Adresse'], 'http://')) { | |
60 $params['#auteur@href'] = $row['Adresse']; | |
61 } | |
62 $commentTpl->setParams($params); | |
63 $sk->addBlogPost($commentTpl); | |
73 } | 64 } |
74 echo(" | 65 |
75 <div class='PostContent'> | 66 // Ajout du formulaire d'ajout de commentaires |
76 <a href='/blog/'>Revenir au blog</a> | 67 $commentForm = new Template('commentForm.xml'); |
77 </div> | 68 $sk->addBlogPost($commentForm); |
78 <div class='PostContent'> | 69 |
79 <form method='post' action='#'> | 70 echo $sk; |
80 <div id='FormCommentaire'> | |
81 Vous souhaitez ajouter un nouveau commentaire ? Faites donc, il vous suffit de remplir | |
82 le petit formulaire ci-dessous. | |
83 <input type='text' name='Auteur' value='Votre Nom' onfocus=\"if(this.value== this.getAttribute('value')) this.value='';\" /> | |
84 <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='';\"/> | |
85 <input type='text' name='Adresse' value='Un site web à vous ?' onfocus=\"if(this.value == this.getAttribute('value')) this.value='';\"/> | |
86 <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> | |
87 <input type='submit' value='Poster ce commentaire' /> | |
88 </div> | |
89 </form> | |
90 </div> | |
91 "); | |
92 include("foot.php"); | |
93 ?> | 71 ?> |