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