diff index.php @ 11:ff57b45eda37

Changement profond de l'index. Utilisation des templates. Dual Blog utilise maintenant intimement la libraire de templates que l'on peut trouver sur http://hg.defr.org/defr/templates, ce qui permet d'eviter de mixer du code PHP avec du HTML. Accessoirement, on est aussi assurer d'avoir du XML valide, puisque c'est l'API DOM qui est utilisée pour générer la sortie.
author Franck Deroche <webmaster@defr.org>
date Wed, 24 Oct 2007 20:06:00 +0200
parents c5bc194d7255
children 6125c7a882b8
line wrap: on
line diff
--- a/index.php	Wed Oct 24 14:38:08 2007 +0200
+++ b/index.php	Wed Oct 24 20:06:00 2007 +0200
@@ -1,102 +1,46 @@
 <?php
-    setlocale(LC_ALL, "fr_FR.utf8@euro", "fr_FR.utf8");
-    ini_set("display_errors", "off");
-     include("classes.php");
-     $type = $_GET['type'];
-     $year = $_GET['year'];
-     $month = $_GET['month'];
-     $prevMonth = ($month - 1)%12; if($prevMonth == 0) $prevMonth = 12; 
-     $prevYear = ($month == 1)? $year-1 : $year;
-     $nextMonth = $month % 12 + 1; 
-     $nextYear = ($month == 12) ? $year+1 : $year;
-     $Data = new DataAccess;
-     include("top.php");
-     $Data->Connect();
-     $query = ($type != 'cal') ?
-     "	SELECT * 
-	FROM Mess 
+    require_once("classes.php");
+    $sk = Factory::getSkeleton();
+    $sk->setTitle('Dual { v10 : OS Edition } Blog');
+    // Détermination de la requête à exécuter
+    if(!array_key_exists('mode', $_GET)) {
+        $query = "
+        SELECT * 
+    	FROM Mess 
         WHERE num_version='Version 10'
         ORDER BY num_mess DESC
         LIMIT 10
-     " : "
+        ";
+    } elseif($_GET['mode'] == 'cal') {
+        $sk->showCalendar(true);
+        $year = intval($_GET['year']);
+        $month = intval($_GET['month']);
+        $sk->setCalendarMonth($month, $year);
+        $query = "
         SELECT * 
-        FROM Mess 
-        WHERE YEAR(DatePost)={$year} AND MONTH(DatePost)={$month} 
+    	FROM Mess 
+        WHERE 
+            YEAR(DatePost) = $year AND
+            MONTH(DatePost) = $month
         ORDER BY num_mess DESC
-     ";
-     $Data->query($query);
-     if($type == "cal") {
-	echo("<div class='cal'>");
-	if($prevYear > $startDate['year'] - 1 || ($prevYear > $startDate['Year'] - 2 && $prevMonth > $startDate['month'] - 1))
-		echo("<a class='calPrev' href='/blog/posts/{$prevYear}/{$prevMonth}'>{$arMonth[$prevMonth - 1]} {$prevYear}</a>");
-	else
-	    echo("<a class='calPrev'>{$arMonth[$prevMonth - 1]} {$prevYear}</a>");
-	if(($curYear == $nextYear && $nextMonth < $curMonth + 1) || ($nextYear < $curYear) )
-	    echo("<a class='calNext' href='/blog/posts/{$nextYear}/" . ($month % 12 + 1)  ."'>{$arMonth[$month%12]} {$nextYear}</a>");
-	else
-	    echo("<a class='calNext'>{$arMonth[$month%12]} {$nextYear}</a>");
-	echo("{$arMonth[$month - 1]} {$year}</div> ");
+        LIMIT 10
+        ";
+    } elseif($_GET['mode'] == 'tag') {
+        $tag = $_GET['tag'];
+        $query = "
+        SELECT * 
+        FROM Mess m
+        LEFT JOIN Lien_Tags_Posts l ON m.num_mess=l.idMess
+        LEFT JOIN Tags t ON l.idTag = t.idTag 
+        WHERE t.Tag='{$_GET['tag']}'
+        ORDER BY num_mess DESC
+        ";
     }
-    while($row=$Data->GetRow()) {
-    $mood = '';
-    $Mess=$Data->utf8_ensure(str_replace("<P>","<p>",str_replace("</P>","</p>", $row['Message'])));
-    $dateFormatee = strftime("%A %d %B %Y, %Hh%M", strtotime($row['DatePost']));
-    $Titre = $Data->utf8_ensure($row['Titre']);
-    $Titre_url = str_replace(" ", "_", strip_tags($Titre));
-    $Titre_url = str_replace("-", "_", $Titre_url);
-    $Titre_url = str_replace(array("é", "è"), "e", $Titre_url);
-    $Titre_url = str_replace("à", "a", $Titre_url);
-    $Titre_url = str_replace("ù", "u", $Titre_url);
-    $Titre_url = str_replace(array("î", "ï"), "i", $Titre_url);
-    if(!empty($row['Emot'])) {
-	$mood = "<img src='/blog/mood/{$row['Emot']}.png' alt='Mood : {$row['Emot']}' class='mood' />";
+    $db = Factory::getDB();
+    $db->debugquery($query);
+    while($row = $db->GetRow()) {
+      $post = new Post($row);
+      $sk->addBlogPost($post->format());
     }
-    $nbTags = $Data->Query("
-	SELECT T.Tag
-	FROM Tags T, Lien_Tags_Posts L
-	WHERE L.idMess={$row['num_mess']} AND  L.idTag = T.idTag
-	ORDER BY T.Tag
-      ", 2);
-      $tags = '';
-      if($nbTags > 0)
-      {
-	$tags = "<span class='Tags'><em>Tags</em> :";
-	while(0 !== ($tag = $Data->GetRow(2)))
-	    $tags .= " <a href='/blog/tags/{$tag['Tag']}'>{$tag['Tag']}</a> |";
-	$tags = substr($tags, 0, -1) . ' ;</span><br />';
-      }
-
-      echo("
-       <div class='PostContent {$row['Emot']}'>
-	<h2>{$Titre} | <span class='Date'>{$dateFormatee}</span></h2>
-	{$mood}
-	{$Mess}
-	<p class='postInfos'>
-	{$tags}
-	<a href=\"/blog/posts/{$row['num_mess']}-{$Titre_url}\">#{$row['num_mess']}</a> - 
-	<a href=\"/blog/posts/{$row['num_mess']}-{$Titre_url}\">
-	 ");
-      if(!is_null($row['NbCommentaires']) && $row['NbCommentaires']!=0)
-	echo("Un 'tit commentaire ( {$row['NbCommentaires']} ) ?");
-      else
-       echo("Un 'tit commentaire ?");
-      echo("
-        </a>
-	</p>
-       </div>");
-     }
-     if($type == "cal") {
-	echo("<div class='cal'>");
-	if($prevYear > $startDate['year'] - 1 && $prevMonth > $startDate['month'] - 1)
-		echo("<a class='calPrev' href='/blog/posts/{$prevYear}/{$prevMonth}'>{$arMonth[$prevMonth - 1]} {$prevYear}</a>");
-	else
-		echo("<a class='calPrev'>{$arMonth[$prevMonth - 1]} {$prevYear}</a>");
-	if(($curYear == $nextYear && $nextMonth < $curMonth + 1) || ($nextYear < $curYear) )
-		echo("<a class='calNext' href='/blog/posts/{$nextYear}/" . ($month % 12 + 1)  ."'>{$arMonth[$month%12]} {$nextYear}</a>");
-	else
-		echo("<a class='calNext'>{$arMonth[$month%12]} {$nextYear}</a>");
-	echo("{$arMonth[$month - 1]} {$year}</div> ");
-     }
-     $Data->Close();
-     include("foot.php");
+    echo $sk;
 ?>