function realname_make_name in Real Name 5
Same name and namespace in other branches
- 6 realname.module \realname_make_name()
Using selected fields, build the "real name" field in the object.
Parameters
$account - the user object to update.:
Return value
The constructed "real name" string.
8 calls to realname_make_name()
- phptemplate_username in ./
realname_theme.inc - Format a username. (copied from theme.inc)
- realname_comment in ./
realname.module - Implementation of hook_comment().
- realname_form_alter in ./
realname.module - Implementation of hook_form_alter(). Intercepts the contact forms to show the realname.
- realname_nodeapi in ./
realname.module - Implementation of hook_nodeapi().
- realname_privatemsg_autocomplete in ./
realname.module - Intercept Privatemsg autocomplete results for usernames.
File
- ./
realname.module, line 327 - The RealName module allows the admin to choose fields from the user profile that will be used to add a "realname" element (method) to a user object. Hook_user is used to automatically add this to any user object that is loaded.
Code
function realname_make_name(&$account) {
// For some strange reason, using a static variable with "theme" in the name sends D5 into a stupor.
static $fields, $pattern_saved, $homepage, $use_theme, $profile_privacy;
static $users = array();
static $links = array();
static $edit = array();
if (isset($users[$account->uid])) {
$account->homepage = isset($links[$account->uid]) ? $links[$account->uid] : NULL;
return $users[$account->uid];
}
// Get our controlling variables (static makes it once per page load).
if (!isset($fields)) {
$fields = variable_get('realname_fields', array());
$pattern_saved = variable_get('realname_pattern', ' ');
$homepage = variable_get('realname_homepage', NULL);
$use_theme = variable_get('realname_theme', TRUE);
$profile_privacy = module_exists('profile_privacy');
}
$pattern = $pattern_saved;
// Has the profile been loaded?
if (!isset($account->{key($fields)})) {
profile_load_profile($account);
if ($profile_privacy) {
profile_privacy_user('load', $edit, $account);
}
}
$stuff = array();
$i = 0;
foreach ($fields as $name => $weight) {
++$i;
$private = 'private_' . $name;
// This will let you see that a user is using Profile Privacy.
// if (isset($account->{$private})) {
// drupal_set_message("$account->name ($account->uid) has marked the $name field as private.");
// }
$private_field = isset($account->{$private}) ? $account->{$private} : FALSE;
if (isset($account->{$name}) && !empty($account->{$name}) && !$private_field) {
$stuff['%' . $i] = $account->{$name};
}
else {
// If there is no value, remove the patterm piece, except the first.
$pattern = str_replace('%' . $i, NULL, $pattern);
}
}
// If no fields set, use username.
if (count($stuff) == 0) {
$stuff['%1'] = $account->name;
$pattern = '%1';
}
if ($homepage && $account->{$homepage}) {
$links[$account->uid] = $account->homepage = $account->{$homepage};
}
$string = trim(strtr($pattern, $stuff));
// $string = drupal_validate_utf8($string) ? htmlspecialchars($string, ENT_COMPAT) : '';
$users[$account->uid] = $string;
return $string;
}