port new_token from zap, fixes and more cleanup

This commit is contained in:
Mario
2022-01-02 20:45:25 +00:00
parent 0003e0b8a5
commit df8bb0596a
4 changed files with 24 additions and 46 deletions

View File

@@ -2586,7 +2586,7 @@ function xchan_query(&$items, $abook = true, $effective_uid = 0) {
$chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash
where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") and hubloc_primary = 1");
}
$xchans = q("select * from xchan where xchan_hash in (" . protect_sprintf(implode(',',$arr)) . ") and xchan_network in ('rss','unknown', 'anon')");
$xchans = q("select * from xchan where xchan_hash in (" . protect_sprintf(implode(',',$arr)) . ") and xchan_network in ('rss','unknown', 'anon', 'token')");
if(! $chans)
$chans = $xchans;
else
@@ -3888,6 +3888,26 @@ function array_path_exists($str,$arr) {
}
/**
* @brief provide psuedo random token (string) consisting entirely of US-ASCII letters/numbers
* and with possibly variable length
*
* @return string
*/
function new_token($minlen = 36, $maxlen = 48) {
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$str = EMPTY_STR;
$len = (($minlen === $maxlen) ? $minlen : mt_rand($minlen, $maxlen));
for ($a = 0; $a < $len; $a++) {
$str .= $chars[mt_rand(0, 62)];
}
return $str;
}
/**
* @brief Generate a random v4 UUID.
*