filesAlias/inc/lib.files.alias.tools.php

50 lines
1.3 KiB
PHP

<?php
/**
* @brief filesAlias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class PallazzoTools
{
public static function rand_uniqid()
{
$index = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$in = time();
$passKey = md5(uniqid((string) rand(), true));
for ($n = 0; $n < strlen($index); $n++) {
$i[] = substr($index, $n, 1);
}
$passhash = hash('sha256', $passKey);
$passhash = (strlen($passhash) < strlen($index))
? hash('sha512', $passKey)
: $passhash;
for ($n = 0; $n < strlen($index); $n++) {
$p[] = substr($passhash, $n, 1);
}
array_multisort($p, SORT_DESC, $i);
$index = implode($i);
$base = strlen($index);
$out = '';
for ($t = floor(log($in, $base)); $t >= 0; $t--) {
$bcp = pow($base, $t);
$a = floor($in / $bcp) % $base;
$out = $out . substr($index, $a, 1);
$in = $in - ($a * $bcp);
}
$out = strrev($out);
return $out;
}
}