webmaster@11: styleSheets = array(); webmaster@11: $this->addDefaultSheets(); webmaster@11: $this->blogPosts = array(); webmaster@11: } webmaster@11: webmaster@11: public function setTitle($titre) { webmaster@11: $this->setParams(array('title' => $titre)); webmaster@11: } webmaster@11: webmaster@11: private function buildSidebar() { webmaster@11: $sidebar = new Template('sidebar.xml'); webmaster@11: // 1. Récupération des archives webmaster@11: $db = Factory::getDB(); webmaster@11: $db->Query(" webmaster@11: SELECT webmaster@11: MONTH(DatePost) As Month, webmaster@11: YEAR(DatePost) As Year, webmaster@11: COUNT(num_mess) As Nb webmaster@11: FROM Mess webmaster@11: GROUP BY webmaster@11: MONTH(DatePost), webmaster@11: YEAR(DatePost) webmaster@11: ORDER BY webmaster@11: YEAR(DatePost) DESC, webmaster@11: Month(DatePost) DESC webmaster@11: "); webmaster@11: $archives = array(); webmaster@11: while($row = $db->GetRow()) { webmaster@11: $curArchiveTpl = new Template('archive.xml'); webmaster@11: $monthName = TextUtils::getMonthName($row['Month']); webmaster@11: $curArchiveTpl->setParams(array( webmaster@11: 'a' => $monthName . ' ' . $row['Year'], webmaster@11: 'a@href' => "http://defr.org/blog/posts/{$row['Year']}/{$row['Month']}", webmaster@11: 'postCount' => '(' . $row['Nb'] . ')' webmaster@11: )); webmaster@11: $archives[] = array('li' => $curArchiveTpl); webmaster@11: } webmaster@11: // 2. Récupération des derniers commentaires webmaster@11: $db->Query(" webmaster@11: SELECT C.*, M.Titre webmaster@11: FROM Commentaires C, Mess M webmaster@11: WHERE C.MessId = M.num_mess AND C.Visible=1 webmaster@11: ORDER BY num_comm DESC LIMIT 20"); webmaster@11: $i = 0; webmaster@11: $comments = array(); webmaster@11: while($row = $db->GetRow()) { webmaster@11: $curCommentTpl = new Template('commentIndex.xml'); webmaster@11: // On récupère une version filtrée du titre du post ... webmaster@11: $tf = TextUtils::StripTitle($row['Titre']); webmaster@11: // ... Qui nous permet d'obtenir l'adresse du commentaire sur le post webmaster@11: $c_url = "/blog/post/{$row['MessId']}-$tf#c{$row['num_comm']}"; webmaster@11: // Si jamais on a une adresse mail, on rajoute un mailto: webmaster@11: if(strpos($row['Adresse'], '@') !== false) webmaster@11: $row['Adresse'] = 'mailto:' . $row['Adresse']; webmaster@11: // On commence par définir les paramètres généraux webmaster@11: $params = array( webmaster@11: '#CommentAuthor' => $row['Auteur'], webmaster@11: '#CommentAuthor@href' => $row['Adresse'], webmaster@11: '#Post' => $row['Titre'], webmaster@11: '#Post@href' => $c_url webmaster@11: ); webmaster@11: // On affiche les 5 commentaires les plus récents en version complète webmaster@11: // puis les 15 autres en versions résumées webmaster@11: if($i < 5) { webmaster@11: $Comment = nl2br($row['Comment']); webmaster@11: } webmaster@11: else { webmaster@11: $Comment = str_replace("\n", " ", strip_tags($row['Comment'])); webmaster@11: if(strlen($Comment > 100)) webmaster@11: $Comment = utf8_encode(substr(utf8_decode($Comment), 0, 97)) . "..."; webmaster@11: $params['li@class'] = 'fold'; webmaster@11: } webmaster@11: webmaster@11: $frag = $curCommentTpl->getDocumentFragment(); webmaster@11: $frag->appendXML($Comment); webmaster@11: $params['comment'] = $frag; webmaster@11: $curCommentTpl->setParams($params); webmaster@11: $comments[] = array('blogComment' => $curCommentTpl); webmaster@11: $i++; webmaster@11: } webmaster@11: // 3. Application des paramètres webmaster@11: $sidebar->setParams(array( webmaster@11: '#archives' => $archives, webmaster@11: '#BlogCommentIndex' => $comments webmaster@11: )); webmaster@11: return $sidebar; webmaster@11: } webmaster@11: webmaster@11: private function buildLinks() { webmaster@11: $links = new Template('links.xml'); webmaster@11: return $links; webmaster@11: } webmaster@11: webmaster@11: private function buildCalendar() { webmaster@11: $retVal = null; webmaster@11: if($this->showCalendar) { webmaster@11: $cMonth = $this->calendarMonth; webmaster@11: $cYear = $this->calendarYear; webmaster@11: $nextMonth = ($cMonth % 12) + 1; webmaster@11: $nextYear = ($nextMonth == 1) ? $cYear + 1 : $cYear; webmaster@14: $prevMonth = $cMonth - 1; webmaster@14: if($prevMonth == 0) webmaster@14: $prevMonth = 12; webmaster@11: $prevYear = ($prevMonth == 12) ? $cYear - 1 : $cYear; webmaster@11: $retVal = new Template('calendar.xml'); webmaster@11: $retVal->setParams(array( webmaster@11: '#calPrev' => TextUtils::getMonthName($prevMonth) . ' ' . $prevYear, webmaster@11: '#calPrev@href' => '/blog/posts/' . $prevYear . '/' . $prevMonth, webmaster@11: '#calNext' => TextUtils::getMonthName($nextMonth) . ' ' . $nextYear, webmaster@11: '#calNext@href' => '/blog/posts/' . $nextYear . '/' . $nextMonth, webmaster@11: 'currentMonth' => TextUtils::getMonthName($cMonth) . ' ' . $cYear webmaster@11: )); webmaster@11: } else { webmaster@11: $retVal = ''; webmaster@11: } webmaster@11: return $retVal; webmaster@11: } webmaster@11: webmaster@11: public function addStyleSheet($SheetName, $CSSFile, $enabled = false) { webmaster@11: $this->styleSheets[] = (object)array( webmaster@11: 'name' => $SheetName, webmaster@11: 'CSSFile' => $CSSFile, webmaster@11: 'enabled' => $enabled webmaster@11: ); webmaster@11: } webmaster@11: webmaster@11: public function enableStyleSheet($styleSheetName) { webmaster@11: foreach($this->styleSheets as $styleSheet) { webmaster@11: $styleSheet->enabled = ($styleSheet->name == $styleSheetName); webmaster@11: } webmaster@11: } webmaster@11: webmaster@11: public function addDefaultSheets() { webmaster@11: $StyleSheets = array( webmaster@11: "Somatic" => "Somatic.css", webmaster@11: "OliveVerde" => "OliveVerde.css", webmaster@11: "Lite:Reloaded" => "Lite_nv.css", webmaster@11: "Brushed" => "Brushed.css", webmaster@11: ":Hover" => "HoverExp.css"); webmaster@11: $CkStyle = (array_key_exists("style", $_COOKIE) && webmaster@11: array_key_exists($_COOKIE['style'], $StyleSheets)) webmaster@11: ? $_COOKIE['style'] webmaster@11: :"Somatic"; webmaster@11: foreach($StyleSheets as $SheetName => $CSSFile) webmaster@11: $this->addStyleSheet($SheetName, $CSSFile, ($SheetName == $CkStyle)); webmaster@11: } webmaster@11: webmaster@11: public function addBlogPost(Template $blogPost) { webmaster@11: $this->blogPosts[] = $blogPost; webmaster@11: } webmaster@11: webmaster@11: public function showCalendar($newValue = false) { webmaster@11: $this->showCalendar = $newValue; webmaster@11: } webmaster@11: webmaster@11: public function setCalendarMonth($month, $year) { webmaster@11: $this->calendarMonth = $month; webmaster@11: $this->calendarYear = $year; webmaster@11: } webmaster@11: webmaster@11: private function prepareOutput() { webmaster@11: $params = array(); webmaster@11: webmaster@11: // Ajout de la sidebar webmaster@11: $params['sidebar'] = $this->buildSideBar(); webmaster@11: webmaster@11: // Ajout de la liste des liens webmaster@11: $params['links'] = $this->buildLinks(); webmaster@11: webmaster@11: // Ajout des feuilles de style webmaster@11: $params['possibleStyleSheets'] = array(); webmaster@11: foreach($this->styleSheets as $styleSheet) { webmaster@11: $type = ($styleSheet->enabled) ? "" : "Alternate "; webmaster@11: $type .= "StyleSheet"; webmaster@11: $params['possibleStyleSheets'][] = array( webmaster@11: 'link@href' => '/blog/css/' . $styleSheet->CSSFile, webmaster@11: 'link@rel' => $type, webmaster@11: 'link@title' => $styleSheet->name webmaster@11: ); webmaster@11: } webmaster@11: webmaster@11: // Affichage éventuel des liens vers les mois précédents et suivants webmaster@11: $params['calendarPrevNext'] = $this->buildCalendar(); webmaster@11: webmaster@11: // Ajout des posts de blog webmaster@11: $params['#Posts'] = array(); webmaster@11: foreach($this->blogPosts as $blogPost) { webmaster@11: $params['#Posts'][] = array('post' => $blogPost); webmaster@11: } webmaster@11: webmaster@11: // Application des l'ensemble de ces paramètres webmaster@11: $this->setParams($params); webmaster@11: } webmaster@11: webmaster@11: public function __toString() { webmaster@11: $this->prepareOutput(); webmaster@11: return parent::__toString(); webmaster@11: } webmaster@11: } webmaster@11: ?>