| webmaster@11 | 1 <?php | 
| webmaster@11 | 2 class Post { | 
| webmaster@11 | 3   private $tpl; | 
| webmaster@11 | 4   private $infos; | 
| webmaster@11 | 5   private $mess; | 
| webmaster@11 | 6   private $dateFormatee; | 
| webmaster@11 | 7   private $url; | 
| webmaster@11 | 8   private $commentLabel; | 
| webmaster@11 | 9   private $mood; | 
| webmaster@11 | 10   private $tags; | 
| webmaster@11 | 11 | 
| webmaster@11 | 12   public function __construct($infos) { | 
| webmaster@11 | 13     $this->infos = (object)$infos; | 
| webmaster@11 | 14 | 
| webmaster@11 | 15     // Récupération du template | 
| webmaster@11 | 16     $this->tpl = new Template('post.xml'); | 
| webmaster@11 | 17 | 
| webmaster@11 | 18     // Création du document fragment contenant le message | 
| webmaster@11 | 19     $Mess = str_replace( | 
| webmaster@11 | 20                     array('<P>', '</P>'), | 
| webmaster@11 | 21                     array('<p>', '</p>'), | 
| webmaster@11 | 22                     $infos['Message']); | 
| webmaster@11 | 23     $Mess = Factory::getDB()->utf8_ensure($Mess); | 
| webmaster@11 | 24     $this->mess = $this->tpl->getDocumentFragment(); | 
| webmaster@11 | 25     $this->mess->appendXML($Mess); | 
| webmaster@11 | 26 | 
| webmaster@11 | 27     // Formatage de la date | 
| webmaster@11 | 28     $time = strtotime($infos['DatePost']); | 
| webmaster@11 | 29     $this->dateFormatee = strftime("%A %d %B %Y, %Hh%M", $time); | 
| webmaster@11 | 30 | 
| webmaster@11 | 31     // On détermine l'url de ce post | 
| webmaster@11 | 32     $strippedTitle = TextUtils::StripTitle($infos['Titre']); | 
| webmaster@11 | 33     $this->url = '/blog/posts/' . $infos['num_mess'] . '-' . $strippedTitle; | 
| webmaster@11 | 34 | 
| webmaster@11 | 35    // On détermine le label du lien vers les commentaires | 
| webmaster@11 | 36    $this->commentLabel = "Un p'tit commentaire ?"; | 
| webmaster@11 | 37    if($infos['NbCommentaires'] > 0) | 
| webmaster@11 | 38         $this->commentLabel .= " (" . $infos['NbCommentaires'] . ")"; | 
| webmaster@11 | 39 | 
| webmaster@11 | 40    // On s'occupe de l'indicateur d'humeur | 
| webmaster@11 | 41    if(!empty($infos['Emot'])) { | 
| webmaster@11 | 42         $mood = array('src' => "/blog/mood/{$infos['Emot']}.png", | 
| webmaster@11 | 43                       'alt' => 'Mood: ' . $infos['Emot']); | 
| webmaster@11 | 44         $this->mood = (object)$mood; | 
| webmaster@11 | 45    } | 
| webmaster@11 | 46 | 
| webmaster@11 | 47    // On détermine les tags du post | 
| webmaster@11 | 48    $db = Factory::getDB(); | 
| webmaster@11 | 49    $nbTags = $db->Query(" | 
| webmaster@11 | 50 	    SELECT T.Tag | 
| webmaster@11 | 51 	    FROM Tags T, Lien_Tags_Posts L | 
| webmaster@11 | 52 	    WHERE L.idMess={$infos['num_mess']} AND  L.idTag = T.idTag | 
| webmaster@11 | 53 	    ORDER BY T.Tag | 
| webmaster@11 | 54       ", 2); | 
| webmaster@11 | 55    $tags = ''; | 
| webmaster@11 | 56    if($nbTags > 0) | 
| webmaster@11 | 57    { | 
| webmaster@11 | 58 	    while(0 !== ($tag = $db->GetRow(2))) | 
| webmaster@11 | 59 	        $tags .= " <a href='/blog/tags/{$tag['Tag']}'>{$tag['Tag']}</a> |"; | 
| webmaster@11 | 60 	    $tags = substr($tags, 0, -1); | 
| webmaster@11 | 61         $this->tags = $this->tpl->getDocumentFragment(); | 
| webmaster@11 | 62         $this->tags->appendXML($tags); | 
| webmaster@11 | 63    } | 
| webmaster@11 | 64    else { | 
| webmaster@11 | 65         $this->tags = 'aucun'; | 
| webmaster@11 | 66    } | 
| webmaster@11 | 67   } | 
| webmaster@11 | 68 | 
| webmaster@11 | 69   public function format() { | 
| webmaster@11 | 70     $params = array( | 
| webmaster@11 | 71         '#post@class' => 'PostContent ' . $this->infos->Emot, | 
| webmaster@11 | 72         'postTitle' => $this->infos->Titre, | 
| webmaster@11 | 73         'postDate' => $this->dateFormatee, | 
| webmaster@11 | 74         'postContent' => $this->mess, | 
| webmaster@11 | 75         'postNumber' => $this->infos->num_mess, | 
| webmaster@11 | 76         'postComments' => $this->commentLabel, | 
| webmaster@11 | 77         '#linkPostNumber@href' => $this->url, | 
| webmaster@11 | 78         '#linkPostComments@href' => $this->url, | 
| webmaster@11 | 79         'postTags' => $this->tags | 
| webmaster@11 | 80      ); | 
| webmaster@11 | 81      if(!empty($this->mood->src)) { | 
| webmaster@11 | 82         $params['#mood@src'] = $this->mood->src; | 
| webmaster@11 | 83         $params['#mood@alt'] = $this->mood->alt; | 
| webmaster@11 | 84         $params['#mood@class'] = 'mood'; | 
| webmaster@11 | 85      } | 
| webmaster@11 | 86      $this->tpl->setParams($params); | 
| webmaster@11 | 87      return $this->tpl; | 
| webmaster@11 | 88   } | 
| webmaster@11 | 89 } | 
| webmaster@11 | 90 ?> |