0)
return "$weeks semaine" . ($weeks > 1 ? "s" : "");
if ($days > 0)
return "$days jour" . ($days > 1 ? "s" : "");
if ($hours > 0)
return "$hours heure" . ($hours > 1 ? "s" : "");
if ($mins > 0)
return "$mins min" . ($mins > 1 ? "s" : "");
return "< 1 min";
}
function buildTreeArray($files)
{
$ret = array();
foreach ($files as $k => $v)
{
$filename=$v['filename'];
$parts = preg_split('/\//', $filename, -1, PREG_SPLIT_NO_EMPTY);
$leaf = array_pop($parts);
// build parent structure
$parent = &$ret;
foreach ($parts as $part)
{
$parent = &$parent[$part];
}
if (empty($parent[$leaf]))
{
$v['filename']=$leaf;
$parent[$leaf] = $v;
}
}
return $ret;
}
function outputTree($files, $indent=1)
{
//echo "
$v)
{
$entry=isset($v['filename']) ? $v['filename'] : $k;
$size=$v['size'];
if($indent==0)
{
// root
$is_folder=true;
}
elseif(is_array($v) && (!array_key_exists('filename',$v) && !array_key_exists('size',$v)))
{
// normal node
$is_folder=true;
}
else
{
// leaf node, i.e. a file
$is_folder=false;
}
if($is_folder)
{
// we could output a folder icon here
}
else
{
// we could output an appropriate icon
// based on file extension here
$ext=pathinfo($entry,PATHINFO_EXTENSION);
}
// echo "";
echo $entry; // output folder name or filename
if(!$is_folder)
{
// if it’s not a folder, show file size
echo " (".makesize($size).")";
}
//echo " |
";
if(is_array($v) && $is_folder)
{
outputTree($v, ($indent+1));
}
}
//echo "
";
}
function unesc($x) {
if (get_magic_quotes_gpc())
return stripslashes($x);
return $x;
}
/*
function benc($str) //bencoding
{
if (is_string($str)) { //string
return strlen($str) . ':' . $str;
}
if (is_numeric($str)) { //integer
return 'i' . $str . 'e';
}
if (is_array($str)) {
$ret_str = ''; //the return string
$k = key($str); //we check the 1st key, if the key is 0 then is a list if not a dictionary
foreach($str as $var => $val) {
if ($k) { //is dictionary
$ret_str .= benc($var); //bencode the var
}
$ret_str .= benc($val); //we recursivly bencode the contents
}
if ($k) { //is dictionary
return 'd' . $ret_str . 'e';
}
return 'l' . $ret_str . 'e';
}
}
function bdec_file($f, $ms)
{
$fp = fopen($f, "rb");
if (!$fp)
return;
$e = fread($fp, $ms);
fclose($fp);
return bdec($e);
}
function bdec($str, &$_len = 0) //bdecoding
{
$type = substr($str, 0, 1);
if (is_numeric($type)) {
$type = 's';
}
switch ($type) {
case 'i': //integer
$p = strpos($str, 'e');
$_len = $p + 1; //lenght of bencoded data
return intval(substr($str, 1, $p - 1));
break;
case 's': //string
$p = strpos($str, ':');
$len = substr($str, 0, $p);
$_len = $len + $p + 1; //lenght of bencoded data
return substr($str, $p + 1, $len);
break;
case 'l': //list
$l = 1;
$ret_array = array();
while (substr($str, $l, 1) != 'e') {
$ret_array[] = bdec(substr($str, $l), $len);
$l += $len;
}
$_len = $l + 1; //lenght of bencoded data
return $ret_array;
break;
case 'd': //dictionary
$l = 1;
$ret_array = array();
while (substr($str, $l, 1) != 'e') {
$var = bdec(substr($str, $l), $len);
$l += $len;
$ret_array[$var] = bdec(substr($str, $l), $len);
$l += $len;
}
$_len = $l + 1; //lenght of bencoded data
return $ret_array;
break;
}
}
*/
function date_fr($format, $timestamp=false) {
if ( !$timestamp ) $date_en = date($format);
else $date_en = date($format,$timestamp);
$texte_en = array(
"Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday", "January",
"February", "March", "April", "May",
"June", "July", "August", "September",
"October", "November", "December"
);
$texte_fr = array(
"lundi", "mardi", "mercredi", "jeudi",
"vendredi", "samedi", "dimanche", "janvier",
"février", "mars", "avril", "mai",
"juin", "juillet", "août", "septembre",
"octobre", "novembre", "décembre"
);
$date_fr = str_replace($texte_en, $texte_fr, $date_en);
$texte_en = array(
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec"
);
$texte_fr = array(
"Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim",
"Jan", "Fév", "Mar", "Avr", "Mai", "Jui",
"Jui", "Aoû", "Sep", "Oct", "Nov", "Déc"
);
$date_fr = str_replace($texte_en, $texte_fr, $date_fr);
return $date_fr;
}
// ---------------------------------------------------------------------
// Générer un mot de passe aléatoire
// ---------------------------------------------------------------------
function fct_passwd( $chrs = "")
{
if( $chrs == "" ) $chrs = 10;
$chaine = "";
$list = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghkmnpqrstuvwxyz!=$";
mt_srand((double)microtime()*1000000);
$newstring="";
while( strlen( $newstring )< $chrs ) {
$newstring .= $list[mt_rand(0, strlen($list)-1)];
}
return $newstring;
}
function get_extension($nom) {
$nom = explode(".", $nom);
$nb = count($nom);
return strtolower($nom[$nb-1]);
}
define('REPLACE_FLAGS', ENT_COMPAT | ENT_XHTML);
function html($string) {
return htmlspecialchars($string, REPLACE_FLAGS, CHARSET);
}
function bbcode($input){
$input = strip_tags($input);
$input = html($input);
$search = array(
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/is',
'/\[url=(.*?)\](.*?)\[\/url\]/is',
'/\[color=(.*?)\](.*?)\[\/color\]/is',
'/\[size=(.*?)\](.*?)\[\/size\]/is',
'/\[code\](.*?)\[\/code\]/is',
'/\[quote\](.*?)\[\/quote\]/is',
'/\[center\](.*?)\[\/center\]/is',
'/\[right\](.*?)\[\/right\]/is',
'/\[justify\](.*?)\[\/justify\]/is'
);
$replace = array(
'$1',
'$1',
'$1',
'',
'$1',
'$2',
'$2',
'$1
',
'$1
',
'$1
',
'$1
',
'$1
'
);
return preg_replace($search,$replace,$input);
}
function write_log($message, $db) {
/*
// Check database connection
if(($db instanceof PDO) == false) {
return array(status => false, message => 'ERREUR : connexion MySQL non valide');
}
*/
// Check message
if($message == '') {
return array(status => false, message => 'Message vide');
}
// Get IP address
if( ($remote_addr = $_SERVER['REMOTE_ADDR']) == '') {
$remote_addr = "Adresse IP inconnue";
}
// Get requested script
if( ($request_uri = $_SERVER['REQUEST_URI']) == '') {
$request_uri = "Adresse inconnue";
}
// Mysql
$sql = "INSERT INTO blog_logs (remote_addr, request_uri, message) VALUES('$remote_addr', '$request_uri','$message')";
// Execute query and save data
$result = $db->query($sql);
if($result) {
return array(status => true, message => 'ok');
}
else {
return array(status => false, message => 'ERREUR : écriture impossible dans la base de données.');
}
}
?>