function shurly_generate_random in ShURLy 7
Same name and namespace in other branches
- 8 shurly.module \shurly_generate_random()
- 6 shurly.module \shurly_generate_random()
Generate a random short URL Pretty much unused at this point this method could take a LOOOONG time on a site with lots of URLs
File
- ./
shurly.module, line 993 - description http://www.youtube.com/watch?v=Qo7qoonzTCE
Code
function shurly_generate_random($len = NULL) {
if ($len == NULL) {
$len = variable_get('shurly_length', 4);
}
$charset = "abcdefghijklmnopqrstuvwxyz123456789";
$charlen = strlen($charset) - 1;
do {
$str = '';
for ($i = 0; $i < $len; $i++) {
$str .= $charset[mt_rand(0, $charlen)];
}
// check that this string hasn't been used already
// check that the string is a valid (available) path
} while (shurly_url_exists($str) || !shurly_path_available($str));
// allow extra operations
module_invoke_all('shurly_shorturl_extra', $str);
return $str;
}