defr/DualBlog

view includes/class.post.php @ 61:25c6e59f019e

Suppression des urls en dur présentes dans le code.

Le code ne présuppose plus qu'il est hébergé directement sur
http://defr.org/blog. Ce n'est par contre pas vrai pour les différents
templates pour le moment, et les fichiers CSS pensent toujours qu'on est
hébergé dans le repertoire /blog, mais ca reste des présupposés à mon avis
moins ennuyeux.

Accessoirement, le code suppose que les trois constantes supplémentaires
suivantes ait été définie dans le fichier config.php:

BLOG_URL, l'adresse du blog, sans / à la fin
BLOG_DEFAULT_GRAVATAR, l'image par défaut pour les personnes laissant des
commentaires
ADMIN_MAIl, l'adresse mail ou sont envoyé les informations sur les
commentaires autorisés.
author Franck Deroche <webmaster@defr.org>
date Tue Mar 11 15:53:15 2008 +0100 (2008-03-11)
parents ded2849cf38c
children 55582b82c43d
line source
1 <?php
2 class Post {
3 private $tpl;
4 private $infos;
5 private $mess;
6 private $dateFormatee = array();
7 private $url;
8 private $commentLabel;
9 private $mood;
10 private $tags;
12 public function __construct($infos) {
13 $this->infos = (object)$infos;
15 $this->tpl = new Template(Skeleton::getTemplateFile('post'));
17 // Création du document fragment contenant le message
18 $Mess = str_replace(
19 array('<P>', '</P>'),
20 array('<p>', '</p>'),
21 $infos['Message']);
22 $Mess = TextUtils::EnsureUTF8($Mess);
23 $this->mess = $this->tpl->getDocumentFragment();
24 $this->mess->appendXML($Mess);
26 // Formatage de la date
27 $time = strtotime($infos['DatePost']);
28 $this->dateFormatee['human'] = strftime("%A %d %B %Y, %Hh%M", $time);
29 $this->dateFormatee['iso'] = date("c", $time);
31 // On détermine l'url de ce post
32 $strippedTitle = TextUtils::StripTitle($infos['Titre']);
33 $this->url = '/posts/' . $infos['num_mess'] . '-' . $strippedTitle;
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'] . ")";
40 // On s'occupe de l'indicateur d'humeur
41 if(!empty($infos['Emot'])) {
42 $mood = array('src' => BLOG_URL . "/mood/{$infos['Emot']}.png",
43 'alt' => 'Mood: ' . $infos['Emot']);
44 $this->mood = (object)$mood;
45 }
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 {
60 $tags .= sprintf("<a href='%s'>%s</a> |",
61 BLOG_URL . '/tags/' . urlencode($tag['Tag']),
62 $tag['Tag']);
63 }
64 $tags = substr($tags, 0, -1);
65 $this->tags = $this->tpl->getDocumentFragment();
66 $this->tags->appendXML($tags);
67 }
68 else {
69 $this->tags = 'aucun';
70 }
71 }
73 public function format() {
74 $this->tpl->setParams($this->getTplParams());
75 return $this->tpl;
76 }
78 public function getTplParams() {
79 $params = array(
80 '#post@class' => 'PostContent ' . $this->infos->Emot,
81 'postTitle' => $this->infos->Titre,
82 'postDate' => $this->dateFormatee['human'],
83 'postDateISO' => $this->dateFormatee['iso'],
84 'postContent' => $this->mess,
85 'postNumber' => $this->infos->num_mess,
86 'postComments' => $this->commentLabel,
87 '#linkPostNumber@href' => $this->getURL(true),
88 '#linkPostComments@href' => $this->getURL(true),
89 'postTags' => $this->tags
90 );
91 if(!empty($this->mood->src)) {
92 $params['#mood@src'] = $this->mood->src;
93 $params['#mood@alt'] = $this->mood->alt;
94 $params['#mood@class'] = 'mood';
95 }
96 return $params;
97 }
99 public function getURL() {
100 return BLOG_URL . $this->url;
103 ?>