
Chad Hester
By: a guest on Oct 30th, 2009 | syntax:
PHP | size: 1.81 KB | hits: 193 | expires: Never
<?php
/**
* Implementation of theme_username()
* NOTE: Mad thanks (rb7) for this comment:
* http://drupal.org/node/47308#comment-832715
*/
function MYTHEME_username($object) {
if ($object->uid && $object->name) {
profile_load_profile($object);
$rewriteName = $object->name;
//Try to gather the First and Last Name pair
if ( !empty($object->profile_firstname)) {
$rewriteName = $object->profile_firstname;
if ( !empty($object->profile_lastname)) {
$rewriteName .= " " . $object->profile_lastname;
}
}
//Favor a Real Name field
if ( !empty($object->profile_realname)) {
$rewriteName = $object->profile_realname;
}
// Shorten the name when it is too long or it will break many tables.
if (drupal_strlen($rewriteName) > 20) {
$name = drupal_substr($rewriteName, 0, 15) .'...';
}
else {
$name = $rewriteName;
}
if (user_access('access user profiles')) {
$output = l
(check_plain
($name), 'user/'. $object->uid, array('attributes' => array('title' => t
('View user profile.'))));
}
else {
$output = check_plain($name);
}
}
else if ($object->name) {
// Sometimes modules display content composed by people who are
// not registered members of the site (e.g. mailing list or news
// aggregator modules). This clause enables modules to display
// the true author of the content.
if (!empty($object->homepage)) {
$output = l
($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow')));
}
else {
$output = check_plain($object->name);
}
$output .= ' ('. t('not verified') .')';
}
else {
$output = check_plain(variable_get('anonymous', t('Anonymous')));
}
return $output;
}