comparison includes/class.post.php @ 11:ff57b45eda37

Changement profond de l'index. Utilisation des templates. Dual Blog utilise maintenant intimement la libraire de templates que l'on peut trouver sur http://hg.defr.org/defr/templates, ce qui permet d'eviter de mixer du code PHP avec du HTML. Accessoirement, on est aussi assurer d'avoir du XML valide, puisque c'est l'API DOM qui est utilisée pour générer la sortie.
author Franck Deroche <webmaster@defr.org>
date Wed, 24 Oct 2007 20:06:00 +0200
parents
children fa43c43763a2
comparison
equal deleted inserted replaced
10:8f1125d27079 11:ff57b45eda37
1 <?php
2 class Post {
3 private $tpl;
4 private $infos;
5 private $mess;
6 private $dateFormatee;
7 private $url;
8 private $commentLabel;
9 private $mood;
10 private $tags;
11
12 public function __construct($infos) {
13 $this->infos = (object)$infos;
14
15 // Récupération du template
16 $this->tpl = new Template('post.xml');
17
18 // Création du document fragment contenant le message
19 $Mess = str_replace(
20 array('<P>', '</P>'),
21 array('<p>', '</p>'),
22 $infos['Message']);
23 $Mess = Factory::getDB()->utf8_ensure($Mess);
24 $this->mess = $this->tpl->getDocumentFragment();
25 $this->mess->appendXML($Mess);
26
27 // Formatage de la date
28 $time = strtotime($infos['DatePost']);
29 $this->dateFormatee = strftime("%A %d %B %Y, %Hh%M", $time);
30
31 // On détermine l'url de ce post
32 $strippedTitle = TextUtils::StripTitle($infos['Titre']);
33 $this->url = '/blog/posts/' . $infos['num_mess'] . '-' . $strippedTitle;
34
35 // On détermine le label du lien vers les commentaires
36 $this->commentLabel = "Un p'tit commentaire ?";
37 if($infos['NbCommentaires'] > 0)
38 $this->commentLabel .= " (" . $infos['NbCommentaires'] . ")";
39
40 // On s'occupe de l'indicateur d'humeur
41 if(!empty($infos['Emot'])) {
42 $mood = array('src' => "/blog/mood/{$infos['Emot']}.png",
43 'alt' => 'Mood: ' . $infos['Emot']);
44 $this->mood = (object)$mood;
45 }
46
47 // On détermine les tags du post
48 $db = Factory::getDB();
49 $nbTags = $db->Query("
50 SELECT T.Tag
51 FROM Tags T, Lien_Tags_Posts L
52 WHERE L.idMess={$infos['num_mess']} AND L.idTag = T.idTag
53 ORDER BY T.Tag
54 ", 2);
55 $tags = '';
56 if($nbTags > 0)
57 {
58 while(0 !== ($tag = $db->GetRow(2)))
59 $tags .= " <a href='/blog/tags/{$tag['Tag']}'>{$tag['Tag']}</a> |";
60 $tags = substr($tags, 0, -1);
61 $this->tags = $this->tpl->getDocumentFragment();
62 $this->tags->appendXML($tags);
63 }
64 else {
65 $this->tags = 'aucun';
66 }
67 }
68
69 public function format() {
70 $params = array(
71 '#post@class' => 'PostContent ' . $this->infos->Emot,
72 'postTitle' => $this->infos->Titre,
73 'postDate' => $this->dateFormatee,
74 'postContent' => $this->mess,
75 'postNumber' => $this->infos->num_mess,
76 'postComments' => $this->commentLabel,
77 '#linkPostNumber@href' => $this->url,
78 '#linkPostComments@href' => $this->url,
79 'postTags' => $this->tags
80 );
81 if(!empty($this->mood->src)) {
82 $params['#mood@src'] = $this->mood->src;
83 $params['#mood@alt'] = $this->mood->alt;
84 $params['#mood@class'] = 'mood';
85 }
86 $this->tpl->setParams($params);
87 return $this->tpl;
88 }
89 }
90 ?>