function hosting_client_sanitize

7.x-3.x hosting_client.module hosting_client_sanitize($title)

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 HOSTING_CLIENT_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

HOSTING_CLIENT_MAX_GROUP_LENGTH

5 calls to hosting_client_sanitize()
hosting_client_insert in client/hosting_client.module
Implements hook_insert().
hosting_client_update in client/hosting_client.module
Implements hook_update().
hosting_client_update_6000 in client/hosting_client.install
Implements hook_update_N().
hosting_client_validate in client/hosting_client.module
Implements 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 1161
Allow clients to be created and granted permissions over sites, tasks etc.

Code

function hosting_client_sanitize($title) {
  $prefix = variable_get('hosting_client_prefix', '');

  // Remove anything but "word characters", dots and dashes.
  $title = preg_replace("/^$prefix/", "", $title);

  // Remove the prefix in case we are validating an existing uname.
  $title = preg_replace("/[!\W\.\-]/", "", $title);

  return substr(strtolower($prefix . $title), 0, HOSTING_CLIENT_MAX_GROUP_LENGTH);
}