Guest

Chad Hester

By: a guest on Oct 30th, 2009  |  syntax: PHP  |  size: 1.81 KB  |  hits: 193  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. <?php
  2.  
  3. /**
  4. * Implementation of theme_username()
  5. * NOTE:  Mad thanks (rb7) for this comment:
  6. * http://drupal.org/node/47308#comment-832715
  7. */
  8. function MYTHEME_username($object) {
  9.  
  10.   if ($object->uid && $object->name) {
  11.     profile_load_profile($object);
  12.     $rewriteName = $object->name;
  13.     //Try to gather the First and Last Name pair
  14.     if ( !empty($object->profile_firstname)) {
  15.       $rewriteName = $object->profile_firstname;
  16.       if ( !empty($object->profile_lastname)) {
  17.         $rewriteName .= " " . $object->profile_lastname;
  18.       }
  19.     }
  20.    
  21.     //Favor a Real Name field
  22.     if ( !empty($object->profile_realname)) {
  23.       $rewriteName = $object->profile_realname;
  24.     }
  25.    
  26.     // Shorten the name when it is too long or it will break many tables.
  27.     if (drupal_strlen($rewriteName) > 20) {
  28.       $name = drupal_substr($rewriteName, 0, 15) .'...';
  29.     }
  30.     else {
  31.       $name = $rewriteName;
  32.     }
  33.  
  34.     if (user_access('access user profiles')) {
  35.       $output = l(check_plain($name), 'user/'. $object->uid, array('attributes' => array('title' => t('View user profile.'))));
  36.     }
  37.     else {
  38.       $output = check_plain($name);
  39.     }
  40.   }
  41.   else if ($object->name) {
  42.     // Sometimes modules display content composed by people who are
  43.     // not registered members of the site (e.g. mailing list or news
  44.     // aggregator modules). This clause enables modules to display
  45.     // the true author of the content.
  46.     if (!empty($object->homepage)) {
  47.       $output = l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow')));
  48.     }
  49.     else {
  50.       $output = check_plain($object->name);
  51.     }
  52.  
  53.     $output .= ' ('. t('not verified') .')';
  54.   }
  55.   else {
  56.     $output = check_plain(variable_get('anonymous', t('Anonymous')));
  57.   }
  58.  
  59.   return $output;
  60. }