n/oldblog
Archived
1
0
Fork 0
This repository has been archived on 2024-02-13. You can view files and clone it, but cannot push or open issues or pull requests.
oldblog/modules/include/tribune.inc.php
2023-04-30 21:50:11 +02:00

56 lines
1.6 KiB
PHP

<?php
// renvoie les NbMsg derniers messages du fichier de tribune
function gettribunemsg($NbMsg)
{
$File = "modules/tribune/tribune";
if (!(file_exists("$File.csv")))
echo "Aucune nouvelle pour l'instant !<br>Attention: Fichier de nouvelles '$File' inexistant !!<br>";
else
{
// lecture des messages
$totmsg = gettotal($File);
$fd = fopen("$File.csv","r");
fseek($fd,unstr($File,($totmsg-$NbMsg)));
for($i=0;$i<$NbMsg+1;$i++)
{
$data = fgetcsv($fd, 10000, ",");
$msgtribune[$i]["date"] = $data[0];
$msgtribune[$i]["heure"] = $data[1];
$msgtribune[$i]["message"] = parse_string(stripcslashes($data[2]));
}
fclose($fd);
}
return $msgtribune;
}
// poste un message dans un fichier de tribune
function writetotribune($Message)
{
$FileName = "modules/tribune/tribune";
$Cpt = 0;
addlog("tribune");
// si le fichier n'existe pas, on le crée:
if (!file_exists("$FileName.csv") )
createfile("$FileName.csv");
if (!file_exists("$FileName.dat") )
strfile($FileName);
// ajout des messages
if ($Message != "")
{
$date = strftime ("%d/%m/%Y", time());
$string = sprintf("\"".$date."\",\"".iheure()."\",\"".$Message."\"\n");
$fp = fopen("$FileName.csv","a");
fwrite($fp,$string);
fclose($fp);
strfile($FileName);
}
unset($Message);
}
?>