view includes/class.post.php @ 72:217f56e6bc77

Si on arrive pas à vérifier le commentaire via Akismet, on l'affichera Le comportement précédent n'était pas réellement défini pour le cas ou l'authentification auprès d'Akismet ne se fait pas correctement, c'est maintenant réparé.
author Franck Deroche <webmaster@defr.org>
date Thu, 20 Mar 2008 19:47:11 +0100
parents 25c6e59f019e
children 55582b82c43d
line wrap: on
line source
<?php
class Post {
  private $tpl;
  private $infos;
  private $mess;
  private $dateFormatee = array();
  private $url;
  private $commentLabel;
  private $mood;
  private $tags;

  public function __construct($infos) {
    $this->infos = (object)$infos;

    $this->tpl = new Template(Skeleton::getTemplateFile('post'));

    // Création du document fragment contenant le message
    $Mess = str_replace(
                    array('<P>', '</P>'), 
                    array('<p>', '</p>'), 
                    $infos['Message']);
    $Mess = TextUtils::EnsureUTF8($Mess);
    $this->mess = $this->tpl->getDocumentFragment();
    $this->mess->appendXML($Mess);
    
    // Formatage de la date
    $time = strtotime($infos['DatePost']);
    $this->dateFormatee['human'] = strftime("%A %d %B %Y, %Hh%M", $time);
    $this->dateFormatee['iso']   = date("c", $time);
    
    // On détermine l'url de ce post
    $strippedTitle = TextUtils::StripTitle($infos['Titre']);
    $this->url = '/posts/' . $infos['num_mess'] . '-' . $strippedTitle;

   // On détermine le label du lien vers les commentaires
   $this->commentLabel = "Un p'tit commentaire ?";
   if($infos['NbCommentaires'] > 0)
        $this->commentLabel .= " (" . $infos['NbCommentaires'] . ")";

   // On s'occupe de l'indicateur d'humeur
   if(!empty($infos['Emot'])) {
        $mood = array('src' => BLOG_URL . "/mood/{$infos['Emot']}.png",
                      'alt' => 'Mood: ' . $infos['Emot']);
        $this->mood = (object)$mood;
   }

   // On détermine les tags du post
   $db = Factory::getDB();
   $nbTags = $db->Query("
	    SELECT T.Tag
	    FROM Tags T, Lien_Tags_Posts L
	    WHERE L.idMess={$infos['num_mess']} AND  L.idTag = T.idTag
	    ORDER BY T.Tag
      ", 2);
   $tags = '';
   if($nbTags > 0)
   {
	    while(0 !== ($tag = $db->GetRow(2)))
	    {
		$tags .= sprintf("<a href='%s'>%s</a> |",
		                BLOG_URL . '/tags/' . urlencode($tag['Tag']),
				$tag['Tag']);
	    }
	    $tags = substr($tags, 0, -1);
        $this->tags = $this->tpl->getDocumentFragment();
        $this->tags->appendXML($tags);
   }
   else {
        $this->tags = 'aucun';
   }
  }

  public function format() {
     $this->tpl->setParams($this->getTplParams());
     return $this->tpl;
  }

  public function getTplParams() {
    $params = array(
        '#post@class' => 'PostContent ' . $this->infos->Emot,
        'postTitle' => $this->infos->Titre,
        'postDate' => $this->dateFormatee['human'],
        'postDateISO' => $this->dateFormatee['iso'],
        'postContent' => $this->mess,
        'postNumber' => $this->infos->num_mess,
        'postComments' => $this->commentLabel,
        '#linkPostNumber@href' => $this->getURL(true),
        '#linkPostComments@href' => $this->getURL(true),
        'postTags' => $this->tags
     );
     if(!empty($this->mood->src)) {
        $params['#mood@src'] = $this->mood->src;
        $params['#mood@alt'] = $this->mood->alt;
        $params['#mood@class'] = 'mood';
     }
     return $params;
  }

  public function getURL() {
     return BLOG_URL . $this->url;
  }
}
?>