comparison 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
comparison
equal deleted inserted replaced
10:8f1125d27079 11:ff57b45eda37
1 <?php 1 <?php
2 setlocale(LC_ALL, "fr_FR.utf8@euro", "fr_FR.utf8"); 2 require_once("classes.php");
3 ini_set("display_errors", "off"); 3 $sk = Factory::getSkeleton();
4 include("classes.php"); 4 $sk->setTitle('Dual { v10 : OS Edition } Blog');
5 $type = $_GET['type']; 5 // Détermination de la requête à exécuter
6 $year = $_GET['year']; 6 if(!array_key_exists('mode', $_GET)) {
7 $month = $_GET['month']; 7 $query = "
8 $prevMonth = ($month - 1)%12; if($prevMonth == 0) $prevMonth = 12; 8 SELECT *
9 $prevYear = ($month == 1)? $year-1 : $year; 9 FROM Mess
10 $nextMonth = $month % 12 + 1;
11 $nextYear = ($month == 12) ? $year+1 : $year;
12 $Data = new DataAccess;
13 include("top.php");
14 $Data->Connect();
15 $query = ($type != 'cal') ?
16 " SELECT *
17 FROM Mess
18 WHERE num_version='Version 10' 10 WHERE num_version='Version 10'
19 ORDER BY num_mess DESC 11 ORDER BY num_mess DESC
20 LIMIT 10 12 LIMIT 10
21 " : " 13 ";
14 } elseif($_GET['mode'] == 'cal') {
15 $sk->showCalendar(true);
16 $year = intval($_GET['year']);
17 $month = intval($_GET['month']);
18 $sk->setCalendarMonth($month, $year);
19 $query = "
22 SELECT * 20 SELECT *
23 FROM Mess 21 FROM Mess
24 WHERE YEAR(DatePost)={$year} AND MONTH(DatePost)={$month} 22 WHERE
23 YEAR(DatePost) = $year AND
24 MONTH(DatePost) = $month
25 ORDER BY num_mess DESC 25 ORDER BY num_mess DESC
26 "; 26 LIMIT 10
27 $Data->query($query); 27 ";
28 if($type == "cal") { 28 } elseif($_GET['mode'] == 'tag') {
29 echo("<div class='cal'>"); 29 $tag = $_GET['tag'];
30 if($prevYear > $startDate['year'] - 1 || ($prevYear > $startDate['Year'] - 2 && $prevMonth > $startDate['month'] - 1)) 30 $query = "
31 echo("<a class='calPrev' href='/blog/posts/{$prevYear}/{$prevMonth}'>{$arMonth[$prevMonth - 1]} {$prevYear}</a>"); 31 SELECT *
32 else 32 FROM Mess m
33 echo("<a class='calPrev'>{$arMonth[$prevMonth - 1]} {$prevYear}</a>"); 33 LEFT JOIN Lien_Tags_Posts l ON m.num_mess=l.idMess
34 if(($curYear == $nextYear && $nextMonth < $curMonth + 1) || ($nextYear < $curYear) ) 34 LEFT JOIN Tags t ON l.idTag = t.idTag
35 echo("<a class='calNext' href='/blog/posts/{$nextYear}/" . ($month % 12 + 1) ."'>{$arMonth[$month%12]} {$nextYear}</a>"); 35 WHERE t.Tag='{$_GET['tag']}'
36 else 36 ORDER BY num_mess DESC
37 echo("<a class='calNext'>{$arMonth[$month%12]} {$nextYear}</a>"); 37 ";
38 echo("{$arMonth[$month - 1]} {$year}</div> ");
39 } 38 }
40 while($row=$Data->GetRow()) { 39 $db = Factory::getDB();
41 $mood = ''; 40 $db->debugquery($query);
42 $Mess=$Data->utf8_ensure(str_replace("<P>","<p>",str_replace("</P>","</p>", $row['Message']))); 41 while($row = $db->GetRow()) {
43 $dateFormatee = strftime("%A %d %B %Y, %Hh%M", strtotime($row['DatePost'])); 42 $post = new Post($row);
44 $Titre = $Data->utf8_ensure($row['Titre']); 43 $sk->addBlogPost($post->format());
45 $Titre_url = str_replace(" ", "_", strip_tags($Titre));
46 $Titre_url = str_replace("-", "_", $Titre_url);
47 $Titre_url = str_replace(array("é", "è"), "e", $Titre_url);
48 $Titre_url = str_replace("à", "a", $Titre_url);
49 $Titre_url = str_replace("ù", "u", $Titre_url);
50 $Titre_url = str_replace(array("î", "ï"), "i", $Titre_url);
51 if(!empty($row['Emot'])) {
52 $mood = "<img src='/blog/mood/{$row['Emot']}.png' alt='Mood : {$row['Emot']}' class='mood' />";
53 } 44 }
54 $nbTags = $Data->Query(" 45 echo $sk;
55 SELECT T.Tag
56 FROM Tags T, Lien_Tags_Posts L
57 WHERE L.idMess={$row['num_mess']} AND L.idTag = T.idTag
58 ORDER BY T.Tag
59 ", 2);
60 $tags = '';
61 if($nbTags > 0)
62 {
63 $tags = "<span class='Tags'><em>Tags</em> :";
64 while(0 !== ($tag = $Data->GetRow(2)))
65 $tags .= " <a href='/blog/tags/{$tag['Tag']}'>{$tag['Tag']}</a> |";
66 $tags = substr($tags, 0, -1) . ' ;</span><br />';
67 }
68
69 echo("
70 <div class='PostContent {$row['Emot']}'>
71 <h2>{$Titre} | <span class='Date'>{$dateFormatee}</span></h2>
72 {$mood}
73 {$Mess}
74 <p class='postInfos'>
75 {$tags}
76 <a href=\"/blog/posts/{$row['num_mess']}-{$Titre_url}\">#{$row['num_mess']}</a> -
77 <a href=\"/blog/posts/{$row['num_mess']}-{$Titre_url}\">
78 ");
79 if(!is_null($row['NbCommentaires']) && $row['NbCommentaires']!=0)
80 echo("Un 'tit commentaire ( {$row['NbCommentaires']} ) ?");
81 else
82 echo("Un 'tit commentaire ?");
83 echo("
84 </a>
85 </p>
86 </div>");
87 }
88 if($type == "cal") {
89 echo("<div class='cal'>");
90 if($prevYear > $startDate['year'] - 1 && $prevMonth > $startDate['month'] - 1)
91 echo("<a class='calPrev' href='/blog/posts/{$prevYear}/{$prevMonth}'>{$arMonth[$prevMonth - 1]} {$prevYear}</a>");
92 else
93 echo("<a class='calPrev'>{$arMonth[$prevMonth - 1]} {$prevYear}</a>");
94 if(($curYear == $nextYear && $nextMonth < $curMonth + 1) || ($nextYear < $curYear) )
95 echo("<a class='calNext' href='/blog/posts/{$nextYear}/" . ($month % 12 + 1) ."'>{$arMonth[$month%12]} {$nextYear}</a>");
96 else
97 echo("<a class='calNext'>{$arMonth[$month%12]} {$nextYear}</a>");
98 echo("{$arMonth[$month - 1]} {$year}</div> ");
99 }
100 $Data->Close();
101 include("foot.php");
102 ?> 46 ?>