function hosting_client_sanitize in Hosting 6.2
Same name and namespace in other branches
- 7.4 client/hosting_client.module \hosting_client_sanitize()
- 7.3 client/hosting_client.module \hosting_client_sanitize()
Return a machine-usable name for a client.
This aims to be usable for unix group/user names and shells.
It adds a prefix configured in the frontend settings (defaulting to 'cl-'), and strips the total length of the string (including the prefix) to MAX_GROUP_LENGTH.
This can also be used to validate user-provided client unames, as it strips and readds the prefix and performs the same validation and corrections on the field.
This is inspired from the context sanitization stuff.
See also
5 calls to hosting_client_sanitize()
- hosting_client_insert in client/
hosting_client.module - Implementation of hook_insert().
- hosting_client_update in client/
hosting_client.module - Implementation of hook_update().
- hosting_client_update_6000 in client/
hosting_client.install - Cleanup the hosting_client fields
- hosting_client_validate in client/
hosting_client.module - Implementation of hook_validate() .
- hosting_client_validate_suggest in client/
hosting_client.module - Helper for hosting_client_validate to suggest a new client name.
File
- client/
hosting_client.module, line 1040
Code
function hosting_client_sanitize($title) {
$prefix = variable_get('hosting_client_prefix', '');
// remove anything but "word characters", dots and dashes
// remove the prefix in case we are validating an existing uname
// TODO: optimize in one call
$title = preg_replace("/[!\\W\\.\\-]/", "", preg_replace("/^{$prefix}/", "", $title));
return substr(strtolower($prefix . $title), 0, MAX_GROUP_LENGTH);
}