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

51 lines
1.3 KiB
PHP
Raw Normal View History

2022-12-04 15:32:11 +00:00
<?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
*/
2022-12-04 15:32:11 +00:00
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;
2022-12-04 15:32:11 +00:00
for ($n = 0; $n < strlen($index); $n++) {
$p[] = substr($passhash, $n, 1);
}
2022-12-04 15:32:11 +00:00
array_multisort($p, SORT_DESC, $i);
$index = implode($i);
2022-12-04 15:32:11 +00:00
$base = strlen($index);
2022-12-04 15:32:11 +00:00
$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);
2022-12-04 15:32:11 +00:00
return $out;
}
2022-12-04 15:32:11 +00:00
}