55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
|
<?php
|
||
|
# -- BEGIN LICENSE BLOCK ----------------------------------
|
||
|
#
|
||
|
# This file is part of filesAlias, a plugin for Dotclear 2.
|
||
|
#
|
||
|
# Copyright (c) 2009-2015 Osku & Pierre Van Glabeke
|
||
|
#
|
||
|
# Licensed under the GPL version 2.0 license.
|
||
|
# A copy of this license is available in LICENSE file or at
|
||
|
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||
|
#
|
||
|
# -- END LICENSE BLOCK ------------------------------------
|
||
|
|
||
|
/**
|
||
|
* Adapted from Enrico Pallazzo class
|
||
|
**/
|
||
|
class PallazzoTools
|
||
|
{
|
||
|
public static function rand_uniqid()
|
||
|
{
|
||
|
$index = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||
|
$in = time();
|
||
|
$passKey = md5(uniqid(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;
|
||
|
}
|
||
|
}
|