Reworked guid function.
This commit is contained in:
parent
35f623ae4f
commit
94302a7924
41
boot.php
41
boot.php
|
@ -1196,36 +1196,25 @@ if(! function_exists('check_plugins')) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_guid($size=16) {
|
function get_guid($size=16, $prefix = "") {
|
||||||
$exists = true; // assume by default that we don't have a unique guid
|
|
||||||
do {
|
|
||||||
$prefix = "";
|
|
||||||
while (strlen($prefix) < ($size - 13))
|
|
||||||
$prefix .= mt_rand();
|
|
||||||
|
|
||||||
$s = substr(uniqid($prefix), -$size);
|
if ($prefix == "") {
|
||||||
|
$a = get_app();
|
||||||
|
$prefix = hash("crc32", $a->get_hostname());
|
||||||
|
}
|
||||||
|
|
||||||
$r = q("select id from guid where guid = '%s' limit 1", dbesc($s));
|
while (strlen($prefix) < ($size - 13))
|
||||||
if(! count($r))
|
$prefix .= mt_rand();
|
||||||
$exists = false;
|
|
||||||
} while($exists);
|
if ($size >= 24) {
|
||||||
q("insert into guid (guid) values ('%s') ", dbesc($s));
|
$prefix = substr($prefix, 0, $size - 22);
|
||||||
return $s;
|
return(str_replace(".", "", uniqid($prefix, true)));
|
||||||
|
} else {
|
||||||
|
$prefix = substr($prefix, 0, $size - 13);
|
||||||
|
return(uniqid($prefix));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*function get_guid($size=16) {
|
|
||||||
$exists = true; // assume by default that we don't have a unique guid
|
|
||||||
do {
|
|
||||||
$s = random_string($size);
|
|
||||||
$r = q("select id from guid where guid = '%s' limit 1", dbesc($s));
|
|
||||||
if(! count($r))
|
|
||||||
$exists = false;
|
|
||||||
} while($exists);
|
|
||||||
q("insert into guid ( guid ) values ( '%s' ) ", dbesc($s));
|
|
||||||
return $s;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
// wrapper for adding a login box. If $register == true provide a registration
|
// wrapper for adding a login box. If $register == true provide a registration
|
||||||
// link. This will most always depend on the value of $a->config['register_policy'].
|
// link. This will most always depend on the value of $a->config['register_policy'].
|
||||||
// returns the complete html for inserting into the page
|
// returns the complete html for inserting into the page
|
||||||
|
|
|
@ -1210,8 +1210,8 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
|
||||||
$arr['attach'] = ((x($arr,'attach')) ? notags(trim($arr['attach'])) : '');
|
$arr['attach'] = ((x($arr,'attach')) ? notags(trim($arr['attach'])) : '');
|
||||||
$arr['app'] = ((x($arr,'app')) ? notags(trim($arr['app'])) : '');
|
$arr['app'] = ((x($arr,'app')) ? notags(trim($arr['app'])) : '');
|
||||||
$arr['origin'] = ((x($arr,'origin')) ? intval($arr['origin']) : 0 );
|
$arr['origin'] = ((x($arr,'origin')) ? intval($arr['origin']) : 0 );
|
||||||
$arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid(30));
|
|
||||||
$arr['network'] = ((x($arr,'network')) ? trim($arr['network']) : '');
|
$arr['network'] = ((x($arr,'network')) ? trim($arr['network']) : '');
|
||||||
|
$arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid(32, $arr['network']));
|
||||||
$arr['postopts'] = ((x($arr,'postopts')) ? trim($arr['postopts']) : '');
|
$arr['postopts'] = ((x($arr,'postopts')) ? trim($arr['postopts']) : '');
|
||||||
$arr['resource-id'] = ((x($arr,'resource-id')) ? trim($arr['resource-id']) : '');
|
$arr['resource-id'] = ((x($arr,'resource-id')) ? trim($arr['resource-id']) : '');
|
||||||
$arr['event-id'] = ((x($arr,'event-id')) ? intval($arr['event-id']) : 0 );
|
$arr['event-id'] = ((x($arr,'event-id')) ? intval($arr['event-id']) : 0 );
|
||||||
|
|
Loading…
Reference in New Issue
Block a user