415 lines
14 KiB
PHP
415 lines
14 KiB
PHP
<?php
|
|
|
|
// extract($themeset, EXTR_OVERWRITE);
|
|
|
|
// fonctions & icones par nitro skateboarding
|
|
// http://www.multimania.com/nskate
|
|
|
|
$souriez = array(
|
|
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")
|
|
);
|
|
|
|
// traitement des chaines - transformation des caractères
|
|
function parse_string($chaine)
|
|
{
|
|
include "include/theme.inc.php";
|
|
|
|
// smileys
|
|
global $souriez;
|
|
$traite = str_replace($souriez[0][0], "<img src='modules/share/".$souriez[0][1]."' border='0' alt='|:-)' />", $chaine);
|
|
$traite = str_replace($souriez[1][0], "<img src='modules/share/".$souriez[1][1]."' border='0' alt=';-)' />", $traite);
|
|
$traite = str_replace($souriez[2][0], "<img src='modules/share/".$souriez[2][1]."' border='0' alt=';)' />", $traite);
|
|
$traite = str_replace($souriez[3][0], "<img src='modules/share/".$souriez[3][1]."' border='0' alt=';o)' />", $traite);
|
|
$traite = str_replace($souriez[4][0], "<img src='modules/share/".$souriez[4][1]."' border='0' alt=':-)) /'>", $traite);
|
|
$traite = str_replace($souriez[5][0], "<img src='modules/share/".$souriez[5][1]."' border='0' alt=':))' />", $traite);
|
|
$traite = str_replace($souriez[6][0], "<img src='modules/share/".$souriez[6][1]."' border='0' alt=':-)' />", $traite);
|
|
$traite = str_replace($souriez[7][0], "<img src='modules/share/".$souriez[7][1]."' border='0' alt=':)' />", $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( /'>", $traite);
|
|
$traite = str_replace($souriez[10][0], "<img src='modules/share/".$souriez[10][1]."' border='0' alt=':o(( /'>", $traite);
|
|
$traite = str_replace($souriez[11][0], "<img src='modules/share/".$souriez[11][1]."' border='0' alt=':((' />", $traite);
|
|
$traite = str_replace($souriez[12][0], "<img src='modules/share/".$souriez[12][1]."' border='0' alt=':-(' />", $traite);
|
|
$traite = str_replace($souriez[13][0], "<img src='modules/share/".$souriez[13][1]."' border='0' alt=':(' />", $traite);
|
|
$traite = str_replace($souriez[14][0], "<img src='modules/share/".$souriez[14][1]."' border='0' alt='8-)' />", $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=';-(' />", $traite);
|
|
$traite = str_replace($souriez[17][0], "<img src='modules/share/".$souriez[17][1]."' border='0' alt=';-(' />", $traite);
|
|
$traite = str_replace($souriez[18][0], "<img src='modules/share/".$souriez[18][1]."' border='0' alt=';-(' />", $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;
|
|
}
|
|
|
|
// renvoie la page ou le module en cours
|
|
// (nécessaire car netscape ne reconnait pas la constante __SELF__)
|
|
function caller()
|
|
{
|
|
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;
|
|
}
|
|
|
|
// renvoie la page ou le module en cours, à ajouter dans un formulaire
|
|
// (pour le passage de paramètres par méthode get)
|
|
function formcaller()
|
|
{
|
|
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>
|
|
<input name='section' value='$section' type=hidden>
|
|
<input name='page' value='$page' type=hidden>";
|
|
} elseif ($modulepage != "") {
|
|
$formcaller = "<input name='theme' value='$theme' type=hidden>
|
|
<input name='modulepage' value='$modulepage' type=hidden>";
|
|
} else {
|
|
$formcaller = "<input name='theme' value='$theme' type=hidden>";
|
|
}
|
|
|
|
return $formcaller;
|
|
}
|
|
|
|
// formate un nombre pour stockage dans un fichier d'index
|
|
function splitchar($Number)
|
|
{
|
|
$byte = strval(dechex($Number));
|
|
switch (strlen($byte)) {
|
|
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 !!!!!!";
|
|
}
|
|
|
|
$string = sprintf("%c%c%c%c", hexdec($byte3), hexdec($byte2), hexdec($byte1), hexdec($byte0));
|
|
|
|
return $string;
|
|
}
|
|
|
|
// créé un fichier d'index
|
|
function strfile($FileName)
|
|
{
|
|
$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);
|
|
}
|
|
|
|
// lit un fichier d'index et renvoie l'index correspondant au numéro d'enregistrement
|
|
function unstr($FileName, $Num)
|
|
{
|
|
if (!file_exists("$FileName.dat")) {
|
|
strfile($FileName);
|
|
}
|
|
|
|
$indexfile = fopen("$FileName.dat", "r");
|
|
$total = hexdec(bin2hex(fread($indexfile, 4)));
|
|
// echo $total;
|
|
if ($Num > $total) {
|
|
$Num = $total;
|
|
}
|
|
fseek($indexfile, ($Num * 4) + 4);
|
|
$pos = hexdec(bin2hex(fread($indexfile, 4)));
|
|
fclose($indexfile);
|
|
return $pos;
|
|
}
|
|
|
|
// retourne le nombre d'enregistrement d'après le fichier d'index
|
|
function gettotal($FileName)
|
|
{
|
|
if (!file_exists("$FileName.dat")) {
|
|
strfile($FileName);
|
|
}
|
|
$indexfile = fopen("$FileName.dat", "r");
|
|
return hexdec(bin2hex(fread($indexfile, 4)));
|
|
}
|
|
|
|
// compte le nombre d'enregistrement d'un fichier csv
|
|
function countcsv($File)
|
|
{
|
|
$max = 0;
|
|
$fd = fopen("$File.csv", "r");
|
|
while (fgetcsv($fd, 10000, ",")) {
|
|
$max++;
|
|
}
|
|
fclose($fd);
|
|
return $max;
|
|
}
|
|
|
|
// créé un fichier
|
|
function createfile($FileName)
|
|
{
|
|
$fp = fopen($FileName, "w+");
|
|
fclose($fp);
|
|
}
|
|
|
|
// affiche une erreur 401
|
|
function err401($msg_err)
|
|
{
|
|
echo "
|
|
<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>";
|
|
|
|
exit();
|
|
}
|
|
|
|
// affiche une demande de mot de passe suivant le fichier password.txt
|
|
function password($folder)
|
|
{
|
|
//************** indentification de l'utilisateur *************
|
|
|
|
$fd = fopen("$folder/password.txt", "r");
|
|
$titre = fgetcsv($fd, 10000, ",");
|
|
|
|
while ($fd) {
|
|
$data = fgetcsv($fd, 10000, ",");
|
|
$login[$i] = $data[0];
|
|
$mdp[$i] = $data[1];
|
|
$bienvenue[$i] = parse_string(stripcslashes($data[2]));
|
|
}
|
|
fclose($fd);
|
|
|
|
// vide le cache
|
|
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date du passé
|
|
|
|
if (!isset($PHP_AUTH_USER)) {
|
|
header("WWW-Authenticate: Basic realm=\"iphp\" ");
|
|
err401("Action annulée");
|
|
} else {
|
|
|
|
if ($login[0] == $PHP_AUTH_USER) {
|
|
echo "bienvenue superuser !";
|
|
} else {
|
|
while (($login[$Cpt++] != $PHP_AUTH_USER) && ($mdp[$Cpt++] != $PHP_AUTH_PW));
|
|
echo "bienvenue user !";
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// créé un fichier de log
|
|
function addlog($url)
|
|
{
|
|
$File = "/logs/".str_replace("/", "_", $url).".log";
|
|
// si le fichier n'existe pas, on le crée:
|
|
if (!file_exists("$File.csv")) {
|
|
createfile("$File.csv");
|
|
}
|
|
|
|
$date = date_format(date_create(), "d/m/Y");
|
|
|
|
$string = sprintf("\"".$date."\",\"".iheure()."\",\"".$_SERVER["REMOTE_ADDR"]."\",\"".$_SERVER["HTTP_REFERER"]."\",\"".$_SERVER["HTTP_USER_AGENT"]."\"\n");
|
|
|
|
$fp = fopen("$File.csv", "a");
|
|
fwrite($fp, $string);
|
|
fclose($fp);
|
|
strfile($File);
|
|
}
|
|
|
|
// convertit les entités HTML en charactères spéciaux
|
|
function html2ascii($inputstring)
|
|
{
|
|
$outputstring = eregi_replace("é", "é", $inputstring);
|
|
$outputstring = eregi_replace("è", "è", $outputstring);
|
|
$outputstring = eregi_replace("à", "à", $outputstring);
|
|
$outputstring = eregi_replace("ù", "ù", $outputstring);
|
|
|
|
$outputstring = eregi_replace("ô", "ô", $outputstring);
|
|
$outputstring = eregi_replace("ê", "ê", $outputstring);
|
|
$outputstring = eregi_replace("î", "î", $outputstring);
|
|
$outputstring = eregi_replace("â", "â", $outputstring);
|
|
$outputstring = eregi_replace("û", "û", $outputstring);
|
|
|
|
$outputstring = eregi_replace("ï", "ï", $outputstring);
|
|
$outputstring = eregi_replace("ë", "ë", $outputstring);
|
|
$outputstring = eregi_replace("ç", "ç", $outputstring);
|
|
|
|
$outputstring = eregi_replace(" ", " ", $outputstring);
|
|
$outputstring = eregi_replace(""", "\"", $outputstring);
|
|
$outputstring = eregi_replace("&", "&", $outputstring);
|
|
|
|
|
|
return $outputstring;
|
|
}
|
|
|
|
// ------------------------------------------------------------------------- //
|
|
// 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
|
|
|
|
function nb_visiteurs_connecte($time, $filename = "/tmp/nbweb.dat")
|
|
{
|
|
$ip = getenv("REMOTE_ADDR");
|
|
$date = time();
|
|
|
|
$i = 0;
|
|
$ii = 0;
|
|
$bool = 0;
|
|
|
|
if (file_exists($filename)) {
|
|
if ($fichier = fopen($filename, "r")) {
|
|
while (!feof($fichier)) {
|
|
$ligne = fgets($fichier, 4096);
|
|
$tab = explode("|", $ligne);
|
|
|
|
if ($tab[1] > 0) {
|
|
$tab_de_tab[$i][0] = $tab[0];
|
|
$tab_de_tab[$i][1] = $tab[1];
|
|
|
|
$i++;
|
|
}
|
|
}
|
|
fclose($fichier);
|
|
}
|
|
}
|
|
|
|
for ($j = 0;$j < $i;$j++) {
|
|
if (($date - chop($tab_de_tab[$j][1])) > $time) {
|
|
//on ne fait rien
|
|
} else {
|
|
$tab_de_tab_actualise[$ii][0] = $tab_de_tab[$j][0];
|
|
$tab_de_tab_actualise[$ii][1] = chop($tab_de_tab[$j][1]);
|
|
$ii++;
|
|
}
|
|
}
|
|
|
|
for ($j = 0;$j < $ii;$j++) {
|
|
if ($tab_de_tab_actualise[$j][0] == $ip) {
|
|
$bool = 1;
|
|
}
|
|
}
|
|
|
|
if ($bool == 0) {
|
|
$tab_de_tab_actualise[$ii][0] = $ip;
|
|
$tab_de_tab_actualise[$ii][1] = $date;
|
|
$ii++;
|
|
}
|
|
|
|
if ($fichier = fopen($filename, "w")) {
|
|
for ($j = 0;$j < $ii;$j++) {
|
|
fputs($fichier, chop($tab_de_tab_actualise[$j][0]));
|
|
fputs($fichier, "|");
|
|
fputs($fichier, chop($tab_de_tab_actualise[$j][1]));
|
|
fputs($fichier, "\n");
|
|
}
|
|
|
|
fclose($fichier);
|
|
}
|
|
|
|
return $ii;
|
|
}
|