function _realname_make_name in Real Name 6
Helper function for 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.
4 calls to _realname_make_name()
- realname_make_name in ./
realname.module - Retreive calculated user name. Try static cache first, DB next and on failure call helper function to calculate realname and populate DB.
- realname_update_6102 in ./
realname.install - Implementation of hook_update_N().
- realname_user in ./
realname.module - Implements hook_user().
- _realname_rebuild_realnames in ./
realname.admin.inc - Batchable function used to rebuild realnames
File
- ./
realname.module, line 808
Code
function _realname_make_name(&$account) {
static $fields, $pattern_saved, $homepage, $use_theme, $type, $module, $module_info, $profile_privacy;
$links =& realname_static('links', array());
$edit =& realname_static('edit', array());
// Get our controlling variables (static makes it once per page load).
if (!isset($module)) {
$module = variable_get('realname_profile_module', NULL);
if ($module) {
$module_info = realname_supported_modules($module);
if (!$module_info || !module_exists($module)) {
unset($module_info);
$module = FALSE;
}
else {
if (isset($module_info['file'])) {
$path = !empty($module_info['path']) ? $module_info['path'] : drupal_get_path('module', $module);
require_once $path . '/' . $module_info['file'];
}
if (!isset($module_info['fields']) || $module_info['fields']) {
$fields = variable_get('realname_fields', array());
// Are there any fields assigned yet?
if (!$fields) {
// No, so just return the name.
return $account->name;
}
$pattern_saved = variable_get('realname_pattern', ' ');
}
else {
$fields = FALSE;
}
$homepage = variable_get('realname_homepage', '');
$use_theme = variable_get('realname_theme', TRUE);
if (isset($module_info['type']) && $module_info['type']) {
$type = variable_get('realname_profile_type', NULL);
}
else {
$type = FALSE;
}
$profile_privacy = module_exists('profile_privacy');
}
}
}
if (!$module) {
drupal_set_message(t('No module is available for RealName.'), 'error');
$string = $account->name;
}
else {
if (is_array($fields) && empty($fields)) {
$string = $account->name;
}
else {
if ($fields === FALSE) {
$string = module_invoke($module, 'realname_make', $account);
}
else {
if ($fields) {
$pattern = $pattern_saved;
// Has the profile been loaded?
if (!isset($account->{key($fields)})) {
$load_func = $module . '_load_profile';
if (!function_exists($load_func)) {
drupal_set_message(t('The profile load function (!module) was not found.', array(
'!module' => $load_func,
)), 'error');
return $account->name;
}
$load_func($account, $type);
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) {
if (is_array($account->{$name})) {
$stuff['%' . $i] = $account->{$name}[0]['view'];
}
else {
$stuff['%' . $i] = $account->{$name};
}
}
else {
// If there is no value, remove the pattern 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 (!empty($homepage) && !empty($account->{$homepage})) {
$links[$account->uid] = $account->{$homepage};
}
$string = trim(strtr($pattern, $stuff));
}
}
}
}
if (empty($string)) {
$string = $account->name;
}
// Removes double spaces in case they are generated by patterns with empty
// fields. See http://drupal.org/node/977430
$string = preg_replace('/ {2,}/', ' ', $string);
return html_entity_decode(filter_xss_admin($string));
}