tma/include/standard.inc.php

416 lines
14 KiB
PHP
Raw Normal View History

2020-11-29 11:25:34 +01:00
<?php
2024-02-12 20:46:07 +01:00
2020-11-29 11:25:34 +01:00
// extract($themeset, EXTR_OVERWRITE);
// fonctions & icones par nitro skateboarding
// http://www.multimania.com/nskate
$souriez = array(
2024-02-12 20:46:07 +01:00
array("|:-)", "lunettes.gif"),
array(";-)", "clin.gif"),
array(";)", "clin.gif"),
array(";o)", "clin.gif"),
array(":-))", "dents.gif"),
array(":))", "dents.gif"),
array(":-)", "content.gif"),
array(":)", "content.gif"),
array(":-o", "couteau.gif"),
array(":o)", "debile.gif"),
array(":-((", "enerve.gif"),
array(":((", "enerve.gif"),
array(":-(", "decu.gif"),
array(":(", "decu.gif"),
array("8-)", "hallucine.gif"),
array(":-p", "langue.gif"),
array(";-(", "pleure.gif"),
array(";(", "pleure.gif"),
array(";o(", "pleure.gif")
2020-11-29 11:25:34 +01:00
);
// traitement des chaines - transformation des caractères
function parse_string($chaine)
{
2024-02-12 20:46:07 +01:00
include "include/theme.inc.php";
// smileys
global $souriez;
$traite = str_replace($souriez[0][0], "<img src='modules/share/".$souriez[0][1]."' border='0' alt='|:-&#41;' />", $chaine);
$traite = str_replace($souriez[1][0], "<img src='modules/share/".$souriez[1][1]."' border='0' alt=';-&#41;' />", $traite);
$traite = str_replace($souriez[2][0], "<img src='modules/share/".$souriez[2][1]."' border='0' alt=';&#41;' />", $traite);
$traite = str_replace($souriez[3][0], "<img src='modules/share/".$souriez[3][1]."' border='0' alt=';o&#41;' />", $traite);
$traite = str_replace($souriez[4][0], "<img src='modules/share/".$souriez[4][1]."' border='0' alt=':-&#41;&#41; /'>", $traite);
$traite = str_replace($souriez[5][0], "<img src='modules/share/".$souriez[5][1]."' border='0' alt=':&#41;&#41' />", $traite);
$traite = str_replace($souriez[6][0], "<img src='modules/share/".$souriez[6][1]."' border='0' alt=':-&#41;' />", $traite);
$traite = str_replace($souriez[7][0], "<img src='modules/share/".$souriez[7][1]."' border='0' alt=':&#41;' />", $traite);
$traite = str_replace($souriez[8][0], "<img src='modules/share/".$souriez[8][1]."' border='0' alt=':-o' />", $traite);
$traite = str_replace($souriez[9][0], "<img src='modules/share/".$souriez[9][1]."' border='0' alt=':o&#40; /'>", $traite);
$traite = str_replace($souriez[10][0], "<img src='modules/share/".$souriez[10][1]."' border='0' alt=':o&#40;&#40; /'>", $traite);
$traite = str_replace($souriez[11][0], "<img src='modules/share/".$souriez[11][1]."' border='0' alt=':&#40;&#40;' />", $traite);
$traite = str_replace($souriez[12][0], "<img src='modules/share/".$souriez[12][1]."' border='0' alt=':-&#40;' />", $traite);
$traite = str_replace($souriez[13][0], "<img src='modules/share/".$souriez[13][1]."' border='0' alt=':&#40;' />", $traite);
$traite = str_replace($souriez[14][0], "<img src='modules/share/".$souriez[14][1]."' border='0' alt='8-&#41' />", $traite);
$traite = str_replace($souriez[15][0], "<img src='modules/share/".$souriez[15][1]."' border='0' alt=':-p' />", $traite);
$traite = str_replace($souriez[16][0], "<img src='modules/share/".$souriez[16][1]."' border='0' alt=';-&#40;' />", $traite);
$traite = str_replace($souriez[17][0], "<img src='modules/share/".$souriez[17][1]."' border='0' alt=';-&#40;' />", $traite);
$traite = str_replace($souriez[18][0], "<img src='modules/share/".$souriez[18][1]."' border='0' alt=';-&#40;' />", $traite);
// liens
//$traite = ereg_replace("\n","<br />",$traite);
//$traite = ereg_replace("<url>","<a href=\"",$traite);
//$traite = ereg_replace("</url>","\">[Lien]</a>",$traite);
// themes
global $theme;
$traite = ereg_replace("THEME_COURANT", $theme, $traite);
return $traite;
2020-11-29 11:25:34 +01:00
}
// renvoie la page ou le module en cours
// (nécessaire car netscape ne reconnait pas la constante __SELF__)
function caller()
{
2024-02-12 20:46:07 +01:00
include "include/theme.inc.php";
global $section;
global $page;
global $modulepage;
global $theme;
if (($section != "") && ($page != "")) {
$liencaller = "index.php?section=$section&page=$page&theme=$theme";
} elseif ($modulepage != "") {
$liencaller = "index.php?modulepage=$modulepage&theme=$theme";
} else {
$liencaller = "index.php?theme=$theme";
}
return $liencaller;
2020-11-29 11:25:34 +01:00
}
// renvoie la page ou le module en cours, à ajouter dans un formulaire
// (pour le passage de paramètres par méthode get)
function formcaller()
{
2024-02-12 20:46:07 +01:00
require_once "include/theme.inc.php";
global $section;
global $page;
global $modulepage;
global $theme;
if (($section != "") && ($page != "")) {
$formcaller = "<input name='theme' value='$theme' type=hidden>
2020-11-29 11:25:34 +01:00
<input name='section' value='$section' type=hidden>
<input name='page' value='$page' type=hidden>";
2024-02-12 20:46:07 +01:00
} elseif ($modulepage != "") {
$formcaller = "<input name='theme' value='$theme' type=hidden>
2020-11-29 11:25:34 +01:00
<input name='modulepage' value='$modulepage' type=hidden>";
2024-02-12 20:46:07 +01:00
} else {
$formcaller = "<input name='theme' value='$theme' type=hidden>";
}
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
return $formcaller;
2020-11-29 11:25:34 +01:00
}
// formate un nombre pour stockage dans un fichier d'index
function splitchar($Number)
{
2024-02-12 20:46:07 +01:00
$byte = strval(dechex($Number));
2024-09-14 21:20:01 +02:00
switch (strlen($byte)) {
2024-02-12 20:46:07 +01:00
case 1:
$byte0 = $byte;
$byte1 = $byte2 = $byte3 = 0;
break;
case 2:
$byte0 = "$byte[0]$byte[1]";
$byte1 = $byte2 = $byte3 = 0;
break;
case 3:
$byte0 = "$byte[1]$byte[2]";
$byte1 = $byte[0];
$byte2 = $byte3 = 0;
break;
case 4:
$byte0 = "$byte[2]$byte[3]";
$byte1 = "$byte[0]$byte[1]";
$byte2 = $byte3 = 0;
break;
case 5:
$byte0 = "$byte[3]$byte[4]";
$byte1 = "$byte[1]$byte[2]";
$byte2 = $byte[0];
$byte3 = 0;
break;
case 6:
$byte0 = "$byte[4]$byte[5]";
$byte1 = "$byte[2]$byte[3]";
$byte2 = "$byte[0]$byte[1]";
$byte3 = 0;
// no break
case 7:
$byte0 = "$byte[5]$byte[6]";
$byte1 = "$byte[3]$byte[4]";
$byte2 = "$byte[1]$byte[2]";
$byte3 = $byte[0];
break;
case 8:
$byte0 = "$byte[6]$byte[7]";
$byte1 = "$byte[4]$byte[5]";
$byte2 = "$byte[2]$byte[3]";
$byte3 = "$byte[0]$byte[1]";
break;
default:
echo "depassement !!!!!!";
}
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
$string = sprintf("%c%c%c%c", hexdec($byte3), hexdec($byte2), hexdec($byte1), hexdec($byte0));
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
return $string;
2020-11-29 11:25:34 +01:00
}
// créé un fichier d'index
function strfile($FileName)
{
2024-02-12 20:46:07 +01:00
$Nb = 0;
$index[$Nb++] = "0";
$input = fopen("$FileName.csv", "r");
while ($data = fgetcsv($input, 10000, ",")) {
$index[$Nb++] = ftell($input);
}
fclose($input);
$index[--$Nb] = 0;
$output = fopen("$FileName.dat", "w");
fwrite($output, splitchar($Nb));
for ($i = 0 ; $i < $Nb ; $i++) {
fwrite($output, splitchar($index[$i]));
}
fclose($output);
2020-11-29 11:25:34 +01:00
}
// lit un fichier d'index et renvoie l'index correspondant au numéro d'enregistrement
2024-02-12 20:46:07 +01:00
function unstr($FileName, $Num)
2020-11-29 11:25:34 +01:00
{
2024-02-12 20:46:07 +01:00
if (!file_exists("$FileName.dat")) {
strfile($FileName);
}
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
$indexfile = fopen("$FileName.dat", "r");
$total = hexdec(bin2hex(fread($indexfile, 4)));
// echo $total;
if ($Num > $total) {
2020-11-29 11:25:34 +01:00
$Num = $total;
2024-02-12 20:46:07 +01:00
}
fseek($indexfile, ($Num * 4) + 4);
$pos = hexdec(bin2hex(fread($indexfile, 4)));
fclose($indexfile);
return $pos;
2020-11-29 11:25:34 +01:00
}
// retourne le nombre d'enregistrement d'après le fichier d'index
function gettotal($FileName)
{
2024-02-12 20:46:07 +01:00
if (!file_exists("$FileName.dat")) {
strfile($FileName);
}
$indexfile = fopen("$FileName.dat", "r");
return hexdec(bin2hex(fread($indexfile, 4)));
2020-11-29 11:25:34 +01:00
}
// compte le nombre d'enregistrement d'un fichier csv
function countcsv($File)
{
2024-02-12 20:46:07 +01:00
$max = 0;
$fd = fopen("$File.csv", "r");
while (fgetcsv($fd, 10000, ",")) {
2020-11-29 11:25:34 +01:00
$max++;
2024-02-12 20:46:07 +01:00
}
fclose($fd);
return $max;
2020-11-29 11:25:34 +01:00
}
// créé un fichier
function createfile($FileName)
{
2024-02-12 20:46:07 +01:00
$fp = fopen($FileName, "w+");
fclose($fp);
2020-11-29 11:25:34 +01:00
}
// affiche une erreur 401
function err401($msg_err)
{
2024-02-12 20:46:07 +01:00
echo "
2020-11-29 11:25:34 +01:00
<html>
<head>
<meta http-equiv='Content-Type' content='HTTP/1.0 401 Unauthorized' />
<title>Rapport d'erreur</title>
</head>
<body>
<h1><font color='red'>Erreur 401</font></h1>
<br />
<br />$msg_err<br />
<hr />
</body>
</html>";
2024-02-12 20:46:07 +01:00
exit();
2020-11-29 11:25:34 +01:00
}
// affiche une demande de mot de passe suivant le fichier password.txt
function password($folder)
{
2024-02-12 20:46:07 +01:00
//************** indentification de l'utilisateur *************
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
$fd = fopen("$folder/password.txt", "r");
$titre = fgetcsv($fd, 10000, ",");
2020-11-29 11:25:34 +01:00
2024-09-14 21:20:01 +02:00
while ($fd) {
2024-02-12 20:46:07 +01:00
$data = fgetcsv($fd, 10000, ",");
$login[$i] = $data[0];
$mdp[$i] = $data[1];
$bienvenue[$i] = parse_string(stripcslashes($data[2]));
}
fclose($fd);
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
// vide le cache
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date du passé
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
if (!isset($PHP_AUTH_USER)) {
header("WWW-Authenticate: Basic realm=\"iphp\" ");
err401("Action annulée");
} else {
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
if ($login[0] == $PHP_AUTH_USER) {
echo "bienvenue superuser !";
} else {
while (($login[$Cpt++] != $PHP_AUTH_USER) && ($mdp[$Cpt++] != $PHP_AUTH_PW));
echo "bienvenue user !";
2020-11-29 11:25:34 +01:00
}
2024-02-12 20:46:07 +01:00
}
2020-11-29 11:25:34 +01:00
}
// créé un fichier de log
function addlog($url)
{
2024-02-12 20:46:07 +01:00
$File = "/logs/".str_replace("/", "_", $url).".log";
// si le fichier n'existe pas, on le crée:
if (!file_exists("$File.csv")) {
createfile("$File.csv");
}
2020-11-29 11:25:34 +01:00
$date = date_format(date_create(), "d/m/Y");
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
$string = sprintf("\"".$date."\",\"".iheure()."\",\"".$_SERVER["REMOTE_ADDR"]."\",\"".$_SERVER["HTTP_REFERER"]."\",\"".$_SERVER["HTTP_USER_AGENT"]."\"\n");
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
$fp = fopen("$File.csv", "a");
fwrite($fp, $string);
fclose($fp);
strfile($File);
2020-11-29 11:25:34 +01:00
}
// convertit les entités HTML en charactères spéciaux
function html2ascii($inputstring)
{
2024-02-12 20:46:07 +01:00
$outputstring = eregi_replace("&eacute;", "é", $inputstring);
$outputstring = eregi_replace("&egrave;", "è", $outputstring);
$outputstring = eregi_replace("&agrave;", "à", $outputstring);
$outputstring = eregi_replace("&ugrave;", "ù", $outputstring);
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
$outputstring = eregi_replace("&ocirc;", "ô", $outputstring);
$outputstring = eregi_replace("&ecirc;", "ê", $outputstring);
$outputstring = eregi_replace("&icirc;", "î", $outputstring);
$outputstring = eregi_replace("&acirc;", "â", $outputstring);
$outputstring = eregi_replace("&ucirc;", "û", $outputstring);
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
$outputstring = eregi_replace("&iuml;", "ï", $outputstring);
$outputstring = eregi_replace("&euml;", "ë", $outputstring);
$outputstring = eregi_replace("&ccedil;", "ç", $outputstring);
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
$outputstring = eregi_replace("&nbsp;", " ", $outputstring);
$outputstring = eregi_replace("&quot;", "\"", $outputstring);
$outputstring = eregi_replace("&amp;", "&", $outputstring);
2020-11-29 11:25:34 +01:00
2024-02-12 20:46:07 +01:00
return $outputstring;
2020-11-29 11:25:34 +01:00
}
// ------------------------------------------------------------------------- //
// Compteur de connectés //
// ------------------------------------------------------------------------- //
// Auteur: Merckel Loïc <loic@merckel.org> //
// Web: http://www.merckel.org/spip //
// ------------------------------------------------------------------------- //
/*
Ce script permet de connaitre le nombre de visiteurs connectés sur une période
de temps donnée (i.e. permet de savoir combien il y a de visiteurs en ligne).
Ce script n'utilise pas de base de données. Il stocke les informations dans un
fichier .dat
*/
// $time est le temps en seconde à partir duquel on considère que
// le visiteur n'est plus connecté
// $text_color est la couleur d'affichage du compteur
// $filename est le nom du fichier créé pour stocker les informations
2024-02-12 20:46:07 +01:00
function nb_visiteurs_connecte($time, $filename = "/tmp/nbweb.dat")
2020-11-29 11:25:34 +01:00
{
$ip = getenv("REMOTE_ADDR");
2024-02-12 20:46:07 +01:00
$date = time();
$i = 0;
$ii = 0;
$bool = 0;
2024-09-14 21:20:01 +02:00
if (file_exists($filename)) {
if ($fichier = fopen($filename, "r")) {
while (!feof($fichier)) {
2024-02-12 20:46:07 +01:00
$ligne = fgets($fichier, 4096);
$tab = explode("|", $ligne);
2024-09-14 21:20:01 +02:00
if ($tab[1] > 0) {
2024-02-12 20:46:07 +01:00
$tab_de_tab[$i][0] = $tab[0];
$tab_de_tab[$i][1] = $tab[1];
2020-11-29 11:25:34 +01:00
$i++;
}
}
fclose($fichier);
}
}
2024-09-14 21:20:01 +02:00
for ($j = 0;$j < $i;$j++) {
if (($date - chop($tab_de_tab[$j][1])) > $time) {
2020-11-29 11:25:34 +01:00
//on ne fait rien
2024-02-12 20:46:07 +01:00
} else {
$tab_de_tab_actualise[$ii][0] = $tab_de_tab[$j][0];
$tab_de_tab_actualise[$ii][1] = chop($tab_de_tab[$j][1]);
2020-11-29 11:25:34 +01:00
$ii++;
}
}
2024-09-14 21:20:01 +02:00
for ($j = 0;$j < $ii;$j++) {
if ($tab_de_tab_actualise[$j][0] == $ip) {
2024-02-12 20:46:07 +01:00
$bool = 1;
2020-11-29 11:25:34 +01:00
}
}
2024-09-14 21:20:01 +02:00
if ($bool == 0) {
2024-02-12 20:46:07 +01:00
$tab_de_tab_actualise[$ii][0] = $ip;
$tab_de_tab_actualise[$ii][1] = $date;
2020-11-29 11:25:34 +01:00
$ii++;
}
2024-09-14 21:20:01 +02:00
if ($fichier = fopen($filename, "w")) {
for ($j = 0;$j < $ii;$j++) {
2024-02-12 20:46:07 +01:00
fputs($fichier, chop($tab_de_tab_actualise[$j][0]));
fputs($fichier, "|");
fputs($fichier, chop($tab_de_tab_actualise[$j][1]));
fputs($fichier, "\n");
2020-11-29 11:25:34 +01:00
}
fclose($fichier);
}
return $ii;
}