profile_view_field

Versions
4.6 – 6
profile_view_field($user, $field)
7
profile_view_field($account, $field)

Code

modules/profile.module, line 176

<?php
function profile_view_field($user, $field) {
  // Only allow browsing of private fields for admins
  $browse = user_access('administer users') || $field->visibility != PROFILE_PRIVATE;

  if ($value = $user->{$field->name}) {
    switch ($field->type) {
      case 'textfield':
        return check_plain($value);
      case 'textarea':
        return check_output($value);
      case 'selection':
        return $browse ? l($value, "profile/$field->name/$value") : check_plain($value);
      case 'checkbox':
        return $browse ? l($field->title, "profile/$field->name") : check_plain($field->title);
      case 'url':
        return '<a href="'. check_url($value) .'">'. check_plain($value) .'</a>';
      case 'date':
        list($format) = explode(' - ', variable_get('date_format_short', 'm/d/Y - H:i'), 2);
        // Note: we avoid PHP's date() because it does not handle dates before
        // 1970 on Windows. This would make the date field useless for e.g.
        // birthdays.
        $replace = array('d' => sprintf('%02d', $value['day']),
                         'j' => $value['day'],
                         'm' => sprintf('%02d', $value['month']),
                         'M' => _profile_map_month($value['month']),
                         'Y' => $value['year']);
        return strtr($format, $replace);
      case 'list':
        $values = split("[,\n\r]", $value);
        $fields = array();
        foreach ($values as $value) {
          if ($value = trim($value)) {
            $fields[] = $browse ? l($value, "profile/". urlencode($field->name) ."/". urlencode($value)) : check_plain($value);
          }
        }
        return implode(', ', $fields);
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.