Demande d'aide pour date dans calendrier
Posté : 05 févr. 2011, 01:43
Depuis quelques semaines je planche sur le script MyPHPNews, un script de News qui marche avec un système de template. J'ai réussi à l'installer(le script est connu pour être pénible à installer), mais le seul problème c'est que j'aimerai mettre la date en version française (soit 01/02/2011 par exemple, au lieu de 2011/02/01), j'ai déjà bricoler le script et tout marche sauf le calendrier ! Il ne met pas en lien la date où il y a une news. Exemple, je poste une news le 23/01/2011, et il n'y a pas le lien qui s'affiche dans le calendrier à cette date. Tout le reste fonctionne bien, c'est simplement ce petit détail qui ne marche pas.
Deux pages gères les dates, l'une est la page du calendrier (calendar.php) et l'autre une page qui regroupe plusieurs fonctions dans une class gèrant les dates (class_date.php). J'ai essayer de modifier cette page mais rien ne marchait.
Voilà la page calendar comme je l'ai modifiée :
En tout cas j'attend j'atend vos réponses avec impatience !
Deux pages gères les dates, l'une est la page du calendrier (calendar.php) et l'autre une page qui regroupe plusieurs fonctions dans une class gèrant les dates (class_date.php). J'ai essayer de modifier cette page mais rien ne marchait.
Voilà la page calendar comme je l'ai modifiée :
<?
$var = "act=date&";
$curmonth = date("m");
$curday = date("d");
if(!isset($d)) $d=date("d/m/Y");
$tbdate = explode("/",$d);
$day = (integer) $tbdate[0];
$month = (integer) $tbdate[1];
$year = (integer) $tbdate[2];
$cache = new cache("Calendar".$month."_".$day,$TimeCache,"cache/");
if($cache->isExpered()){
$date = new mydate($day,$month,$year);
$NbDayOfMonth = $date->GetNumDayOfMonth();
$FirstDayOfMonth = date("w",mktime(0,0,1,$month,01,$year));
$genNewsCalendar.= "<table border='0' width='125'><tr><td>";
$genNewsCalendar.= "<tr bgcolor='".$MyPHPNewsColorDefault."'>";
if(intval($month)==1){
$genNewsCalendar.= "<td align='left'><a href=\"/News2/?".$var."d=".sprintf("%02d/%02d/%04d",01,12,$year-1)."\"><</a></td>";
}else{
$genNewsCalendar.= "<td align='left'><a href=\"/News2/?".$var."d=".sprintf("%02d/%02d/%04d",01,$month-1,$year)."\"><</a></td>";
}
$genNewsCalendar.= "<td colspan='5' align=center><b><a href=\"/News2/?act=archmonth&d=".sprintf("%02d/%02d/%04d",01,$month,$year)."\" title=\"$ResStrArchivOfMonth\"><b>".$date->GetMonthName()." ".$year."</b></a></td>";
if((intval($month)==12)){
$genNewsCalendar.= "<td align='right'><a href=\"/News2/?".$var."d=".sprintf("%02d/%02d/%04d",01,01,$year+1)."\">></a></td>";
}else{
$genNewsCalendar.= "<td align='right'><a href=\"/News2/?".$var."d=".sprintf("%02d/%02d/%04d",01,$month+1,$year)."\">></a></td>";
}
$genNewsCalendar.= "</tr>\n";
$genNewsCalendar.= "<tr>
<td align='center'><font size='1'>L</font></td>
<td align='center'><font size='1'>M</font></td>
<td align='center'><font size='1'>M</font></td>
<td align='center'><font size='1'>J</font></td>
<td align='center'><font size='1'>V</font></td>
<td align='center'><font size='1'>S</font></td>
<td align='center'><font size='1'>D</font></td>
</tr>\n";
if($FirstDayOfMonth==0) $FirstDayOfMonth=7;
$genNewsCalendar.= "<tr>";
$dbs = new data(0,$MyPHPNewsHote, $MyPHPNewsBase, $MyPHPNewsUser, $MyPHPNewsPass);
if(!$dbs->connect())
die($dbs->error);
if(!$dbs->query("SELECT COUNT(id) AS nb, DATE_FORMAT(date,'%d') as d1, titre FROM ".$MyPHPNewsTBNews." WHERE activ='1' AND date LIKE '%".sprintf("%02d",$month)."/".$year."' GROUP BY d1 ORDER BY date"))
die($dbs->error);
while($dbs->nextrecord()){
$key = $dbs->value("d1");
$arrayofdate[$key] = $dbs->value("nb");
}
for($i=1;$i<$FirstDayOfMonth;$i++)
$genNewsCalendar.= "<td> </td>";
$j = $FirstDayOfMonth;
for($i=1;$i<=$NbDayOfMonth;$i++){
$datej = new mydate($i,$month,$year);
$bankday = $datej->isBankHolidays();
$nameofbankday = $datej->GetNameBankHolidays();
if($arrayofdate[sprintf("%02d",$i)]!=0){
$genNewsCalendar.= "<td align='center' width='25' ".(($day==$i) ? "bgcolor=\"".$MyPHPNewsColorDefault."\"" : "" )."><a href=\"/News2/?".$var."d=".sprintf("%02d/%02d/%04d",$i,$month,$year)."\" title=\"".$nameofbankday."\">".(($day==$i) ? "<b>".$i."</b>" : $i)."</a></td>";
}else{
$genNewsCalendar.= "<td align='center' width='25' ".(($day==$i) ? "bgcolor=\"".$MyPHPNewsColorDefault."\"" : "" ).">".(($day==$i) ? "<b>".$i."</b>" : $i)."</td>";
}
if($j==7){
if($i<$NbDayOfMonth){
$genNewsCalendar.= "</tr>\n";
$genNewsCalendar.= "<tr>";
$j = 1;
}
}else{
$j ++;
}
}
$genNewsCalendar.= "</tr>\n";
$genNewsCalendar.= "</table>\n";
$cache->SetCache($genNewsCalendar);
}
echo "<div class='bang'>Calendrier</div>";
echo $cache->GetCache("Calendar".$month."_".$day);
?>
et voila la page class_date.php non-modifiée:<?
class mydate{
/**
* Variables
*/
var $day;
var $month;
var $year;
var $separator="/";
var $monthname=array(1=>"Janvier",
2=>"Février",
3=>"Mars",
4=>"Avril",
5=>"Mai",
6=>"Juin",
7=>"Juillet",
8=>"Août",
9=>"Septembre",
10=>"Octobre",
11=>"Novembre",
12=>"Décembre");
var $dayname=array(1=>"Lundi",
2=>"Mardi",
3=>"Mercredi",
4=>"Jeudi",
5=>"Vendredi",
6=>"Samedi",
0=>"Dimanche");
/**
* Constructeur
*
* @param type
* @aDay int
* $aMonth int
* $aYear int
*/
function mydate($aDay,$aMonth,$aYear){
$this->day = $aDay;
$this->month = $aMonth;
$this->year = $aYear;
}
/**
* Affecte le séparateur pour l'affichage de la date
* @param type
* @aSeparator string
*/
function SetSeparator($aSeparator){
$this->separator=$aSeparator;
}
/**
* Retourne la date passée en paramètre
*/
function GetCurrentDate(){
return sprintf("%04d".$this->separator."%02d".$this->separator."%02d", $this->year, $this->month, $this->day);
}
/**
* Check la validité de la date
*/
function isDateValid(){
return checkdate($this->month,$this->day,$this->year);
}
/**
* Check si l'année est bissextile ou non
*/
function isYearBissextile(){
if($this->isDateValid()){
return date("L",mktime(0,0,0,01,01,$this->year));
}
}
/**
* Retourne l'id du jour dans l'année
*/
function GetIdDayOfYear(){
if($this->isDateValid()){
return $date = strftime("%j",mktime(0,0,0,$this->month,$this->day,$this->year));
}
}
/**
* Retourne l'id de la semaine dans l'année
*/
function GetIdWeekOfYear(){
if($this->isDateValid()){
return $idsemaine=strftime("%U",mktime(0,0,0,$this->month,$this->day,$this->year))+1;
}
}
/**
* Retourne l'id du jour dans la semaine
*/
function GetIdDayOfWeek(){
if($this->isDateValid()){
return date("w",mktime(0,0,1,$this->month,$this->day,$this->year));
}
}
/**
* Retourne le nom du jour
*/
function GetDayName(){
if($this->isDateValid()){
return $this->dayname[$this->GetIdDayOfWeek()];
}
}
/**
* Retourne le nom du mois
*/
function GetMonthName(){
if($this->isDateValid()){
return $this->monthname[$this->month];
}
}
/**
* Retourne le nombre de jour du mois
*/
function GetNumDayOfMonth(){
if($this->isDateValid()){
return date("t",mktime(0,0,1,$this->month,01,$this->year));
}
}
/**
* Retourne le dernier jours du mois
*/
function GetLastDayOfMonth(){
$lastday = 28;
while(checkdate($this->month, $lastday, $this->year))
$lastday++;
return $lastday-1;
}
/**
* Retourne un tableau des jours fériés (français)....
*/
function GetBankHolidays(){
$jf1 = $this->year-1900;
$jf2 = $jf1%19;
$jf3 = intval((7*$jf2+1)/19);
$jf4 = (11*$jf2+4-$jf3)%29;
$jf5 = intval($jf1/4);
$jf6 = ($jf1+$jf5+31-$jf4)%7;
$jfj = 25-$jf4-$jf6;
$jfm = 4;
if ($jfj <= 0){
$jfm = 3;
$jfj = $jfj + 31;
}
$paques=(($jfm < 10) ? "0".$jfm : $jfm)."/".(($jfj < 10) ? "0".$jfj : $jfj);
$lunpaques=date("m".$this->separator."d",mktime(12,0,0,$jfm,$jfj+1,$this->year));
$ascension=date("m".$this->separator."d",mktime(12,0,0,$jfm,$jfj+39,$this->year));
$pentecote=date("m".$this->separator."d",mktime(12,0,0,$jfm,$jfj+50,$this->year));
$ArryBankHolidays=Array("".$this->year.$this->separator."01".$this->separator."01"=>"Jour de l'an",
"".$this->year.$this->separator."05".$this->separator."01"=>"Fête du travail",
"".$this->year.$this->separator."05".$this->separator."08"=>"Anniversaire 1945",
"".$this->year.$this->separator."07".$this->separator."14"=>"Fête Nationale",
"".$this->year.$this->separator."08".$this->separator."15"=>"Assomption",
"".$this->year.$this->separator."11".$this->separator."01"=>"Toussaint",
"".$this->year.$this->separator."11".$this->separator."11"=>"Armistice 1918",
"".$this->year.$this->separator."12".$this->separator."25"=>"Noël",
"".$this->year.$this->separator."$paques"=>"Pâques",
"".$this->year.$this->separator."$lunpaques"=>"Lundi de Pâques",
"".$this->year.$this->separator."$ascension"=>"Ascension",
"".$this->year.$this->separator."$pentecote"=>"Pentecote");
return $ArryBankHolidays;
}
/**
* Retourne le nom de la fête du jour férié
*/
function GetNameBankHolidays(){
$bankdays = $this->GetBankHolidays();
return $bankdays[$this->GetCurrentDate()];
}
/**
* Check le jour si il est férié
*/
function isBankHolidays(){
$result = false;
$bankdays = $this->GetBankHolidays();
@reset($bankdays);
while(list($key,$value)=each($bankdays))
if($key==$this->GetCurrentDate()) return true;
}
}
?>
Je ne sais pas pourquoi tout le monde critique autant ce script, il est géniale, une fois qu'on sais comment il marche, il offre de nombreuses possibilités. Je fais appel à vous car je n'en peux plus, j'ai l'impression d'avoir tout essayer.En tout cas j'attend j'atend vos réponses avec impatience !