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/standard.inc.php
2023-04-30 21:50:11 +02:00

462 lines
18 KiB
PHP

<?php
//require('./class.jabber2.php');
// 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,$striphtml="no")
{
include_once "include/theme.inc.php";
$traite = $chaine;
if ($striphtml == "yes")
{
$traite = str_replace(">", "&gt;", $traite);
$traite = str_replace("<", "&lt;", $traite);
}
// wiki syntax
$traite = ereg_replace("!!!(('?[^\n'])*)!!!","<h3>\\1</h3>",$traite);
$traite = ereg_replace("!!(('?[^\n'])*)!!","<h2>\\1</h2>",$traite);
$traite = ereg_replace("!(('?[^\n'])*)!","<h1>\\1</h1>",$traite);
$traite = ereg_replace("\*\*(('?[^\n'])*)\*\*", "<b>\\1</b>", $traite);
$traite = ereg_replace("''(('?[^\n'])*)''", "<i>\\1</i>", $traite);
$traite = ereg_replace("__(('?[^\n'])*)__", "<u>\\1</u>", $traite);
$traite = ereg_replace("::(('?[^\n'])*)::", "<div align='center'>\\1</div>", $traite);
$traite = str_replace("---", "<hr />", $traite);
$traite = eregi_replace("\[([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)\]", "<a href='mailto:\\1'>\\1</a>", $traite);
$traite = ereg_replace("\[(.*)\&gt;([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])\]", "<a href='\\2://\\3\\4' target='_blank' rel='nofollow'>\\1</a>", $traite);
$traite = ereg_replace("\[(.*)>([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])\]", "<a href='\\2://\\3\\4\' target='_blank' rel='nofollow'>\\1</a>", $traite);
$traite = eregi_replace("\[([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])\]", "<a href='\\1://\\2\\3' target='_blank' rel='nofollow'>\\1://\\2\\3</a>", $traite);
//$traite = ereg_replace( "\[(.*>[A-Z][a-z]+\)]", "<a href='\\1'>\\2</a>", $traite);
$traite = ereg_replace( "\[(.*)\&gt;(.*)\]", "<a href='\\2' rel='nofollow'>\\1</a>", $traite);
$traite = ereg_replace( "\[(.*)>(.*)\]", "<a href='\\2' rel='nofollow'>\\1</a>", $traite);
$traite = ereg_replace( "\[(.*)\]", "<a href='\\1' rel='nofollow'>\\1</a>", $traite);
$traite = ereg_replace( "\{\{(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\}\}", "<img src='\\1' alt='\\2'/ height='\\3/ width='\\4' align='\\5' valign='\\6' />", $traite);
$traite = ereg_replace( "\{\{(.*)\|(.*)\|(.*)\|(.*)\|(.*)\}\}", "<img src='\\1' alt='\\2'/ height='\\3' width='\\4' align='\\5' />", $traite);
$traite = ereg_replace( "\{\{(.*)\|(.*)\|(.*)\|(.*)\}\}", "<img src='\\1' alt='\\2' height='\\3' width='\\4' />", $traite);
$traite = ereg_replace( "\{\{(.*)\|(.*)\|(.*)\}\}", "<img src='\\1' alt='\\2' height='\\3' />", $traite);
$traite = ereg_replace( "\{\{(.*)\|(.*)\}\}", "<img src='\\1' alt='\\2' />", $traite);
// smileys
global $souriez;
$traite = str_replace($souriez[0][0], "<img src='modules/share/".$souriez[0][1]."' border='0' alt='|:-&#41;' />", $traite);
$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);
$traite = str_replace("\n","<br />",$traite);
return $traite;
}
function mailalert($to, $subject, $from_name, $from_mail, $from_subject, $from_text)
{
$email = "";
if ($from_name != "")
$email .= "Auteur:".$from_name;
if ($from_mail != "")
$email .= "<".$from_mail.">";
if ($from_subject != "")
$email .= "\nTitre:".$from_subject;
if ($from_subject != "")
$email .= "\nTexte:".$from_text;
$subject = "[Tourmentine] ".$subject;
//mail($to, $subject, $email);
mail($to, $subject, $from_text, "From: ".$from_name." <".$from_mail.">\r\nX-Mailer: PHP/" . phpversion());
}
// 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 = "?section=$section&amp;page=$page&amp;theme=$theme";
else if ($modulepage != "")
$liencaller = "?modulepage=$modulepage&amp;theme=$theme";
else
$liencaller = "?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='section' value='$section' type='hidden' />
<input name='page' value='$page' type='hidden' />";
else if ($modulepage != "")
$formcaller = "
<input name='modulepage' value='$modulepage' type='hidden' />";
else
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;
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)));
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,$typefile="file")
{
if ($typefile == "db")
{
global $sqltimegen;
$sqlstartgen = microtime(true);
$db = sqlite_open("modules/db.sqlite");
$line = sqlite_query($db, "SELECT * FROM news ORDER BY id DESC LIMIT 1 OFFSET 0");
$row = sqlite_fetch_array($line);
$total_records = $row["id"];
sqlite_close($db);
$sqlendgen = microtime(true);
$sqltimegen += $sqlendgen - $sqlstartgen;
}
else
{
if (!file_exists("$FileName.dat"))
strfile($FileName);
$indexfile = fopen("$FileName.dat","r");
$total_records = hexdec(bin2hex(fread($indexfile,4)));
fclose($indexfile);
}
return $total_records;
}
// 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();
}
// 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 = strftime ("%d/%m/%Y", time());
$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("&eacute;","é",$inputstring);
$outputstring = eregi_replace("&egrave;","è",$outputstring);
$outputstring = eregi_replace("&agrave;","à",$outputstring);
$outputstring = eregi_replace("&ugrave;","ù",$outputstring);
$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);
$outputstring = eregi_replace("&iuml;","ï",$outputstring);
$outputstring = eregi_replace("&euml;","ë",$outputstring);
$outputstring = eregi_replace("&ccedil;","ç",$outputstring);
$outputstring = eregi_replace("&nbsp;"," ",$outputstring);
$outputstring = eregi_replace("&quot;","\"",$outputstring);
$outputstring = eregi_replace("&amp;","&",$outputstring);
return $outputstring;
}
function wiki_help($lang)
{
if ($lang == "fr")
return "
<table class='wikihelp' id='wikihelp'>
<tr><td>Gras</td><td>**texte**</td><td><b>texte</b></td></tr>
<tr><td>Italique</td><td>''texte''</td><td><i>texte</i></td></tr>
<tr><td>Souligné</td><td>__texte__</td><td><u>texte</u></td></tr>
<tr><td>Centré</td><td>::texte::</td><td><div align='center'>texte</div></td></tr>
<tr><td>Lien interne</td><td>[fichier]</td><td><a href='fichier'>fichier</a></td></tr>
<tr><td>Lien interne nommé</td><td>[lien>fichier]</td><td><a href='fichier'>lien</a></td></tr>
<tr><td>Lien externe</td><td>[http://serveur/fichier]</td><td><a href='http://serveur/fichier' target='_blank'>http://serveur/fichier</a></td></tr>
<tr><td>Lien externe nommé</td><td>[lien>http://serveur/fichier]</td><td><a href='http://serveur/fichier' target='_blank'>lien</a></td></tr>
<tr><td>Adr. e-mail</td><td>[nom@serveur]</td><td><a href='mailto:nom@serveur'>nom@serveur</a></td></tr>
<tr><td>Saut de ligne</td><td>___</td><td><hr /></td></tr>
<tr><td>Images</td><td>{{http://serveur/image|nom}}</td><td><img src='http://tourmentine.com/favicon.ico' alt='nom' /></td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>Les tags HTML ne sont pas authorisés.</td><td>Pour afficher le symbole &euro;, vous devez taper « &amp;euro; ».</td></tr>
</table>
";
else
return"
<table class='wikihelp' id='wikihelp'>
<tr><td>Bold</td><td>**text**</td><td><b>text</b></td></tr>
<tr><td>Italic</td><td>''text''</td><td><i>text</i></td></tr>
<tr><td>Underline</td><td>__text__</td><td><u>text</u></td></tr>
<tr><td>Centered</td><td>::text::</td><td><div align='center'>text</div></td></tr>
<tr><td>Internal link</td><td>[file]</td><td><a href='file'>file</a></td></tr>
<tr><td>Named internal link</td><td>[link>file]</td><td><a href='file'>link</a></td></tr>
<tr><td>External link</td><td>[http://server/file]</td><td><a href='http://server/file' target='_blank'>http://server/file</a></td></tr>
<tr><td>Named external link</td><td>[lien>http://server/file]</td><td><a href='http://server/file' target='_blank'>link</a></td></tr>
<tr><td>e-mail Adr.</td><td>[name@server]</td><td><a href='mailto:name@server'>name@server</a></td></tr>
<tr><td>New line</td><td>___</td><td><hr /></td></tr>
<tr><td>Images</td><td>{{http://server/picture|name}}</td><td><img src='http://tourmentine.com/favicon.ico' alt='name' /></td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>HTML tags are not allowed.</td><td>You have to put « &amp;euro; » to print the &euro; symbol.</td></tr>
</table>
";
}
function fmtime(&$item,$key,$cache)
{
return (filemtime($cache) > filemtime($item));
}
function cache($cachefile, $getfile, $dep)
{
// $cachefile = "tmp/titres.cache.php";
$FileNews = "modules/news/news";
$totalnews = gettotal($FileNews);
if (file_exists($cachefile))
{
if (array_walk ($dep, 'fmtime',$cachefile))
return "success";
else
return "failed";
}
else return "$cachefile not found";
echo "coucou!";
/*
if (!file_exists($cachefile) || (filemtime($cachefile) < filemtime("modules/news/news.dat")))
{
$cachecontent = "\n\n<!-- Partie mise en cache (".date("d/m/Y@H:i:s").")-->\n\n";
$cachecontent .= file_get_contents("http://".$_SERVER["SERVER_NAME"]."/modules/magicbox.php?module=affnews&titleonly=1&BoxNbMaxNews=$totalnews&NbMaxNews=$totalnews&cropdate=10&bodyclass=centerbody&start=$totalnews&titre=Les%20nouvelles%20anciennes%20de%20la%20Tourmentine");
$cachecontent .= "\n<!-- fin Partie mise en cache -->\n\n";
$cachecontent = str_replace("<!--NOCACHE","<?php",$cachecontent);
$cachecontent = str_replace("NOCACHE-->","?>",$cachecontent);
$fp = fopen($cachefile,"w");
fwrite($fp,$cachecontent);
fclose($fp);
}
include $cachefile;a*/
}
//echo cache("../tmp/titres.cache.php","http://".$_SERVER["SERVER_NAME"]."/modules/magicbox.php?module=affnews&titleonly=1&BoxNbMaxNews=$totalnews&NbMaxNews=$totalnews&cropdate=10&bodyclass=centerbody&start=$totalnews&titre=Les%20nouvelles%20anciennes%20de%20la%20Tourmentine",array ("modules/news/news.dat"));
/**
* Check if the browser is on a mobile device
*
* Adapted from the example code at url below
*
* @link http://www.brainhandles.com/2007/10/15/detecting-mobile-browsers/#code
*/
function clientismobile(){
if(isset($_SERVER['HTTP_X_WAP_PROFILE'])) return true;
if(preg_match('/wap\.|\.wap/i',$_SERVER['HTTP_ACCEPT'])) return true;
if(!isset($_SERVER['HTTP_USER_AGENT'])) return false;
$uamatches = 'midp|j2me|avantg|docomo|novarra|palmos|palmsource|240x320|opwv|chtml|pda|windows ce|mmp\/|blackberry|mib\/|symbian|wireless|nokia|hand|mobi|phone|cdm|up\.b|audio|SIE\-|SEC\-|samsung|HTC|mot\-|mitsu|sagem|sony|alcatel|lg|erics|vx|NEC|philips|mmm|xx|panasonic|sharp|wap|sch|rover|pocket|benq|java|pt|pg|vox|amoi|bird|compal|kg|voda|sany|kdd|dbt|sendo|sgh|gradi|jb|\d\d\di|moto';
if(preg_match("/$uamatches/i",$_SERVER['HTTP_USER_AGENT'])) return true;
return false;
}
?>