You are here

function profile_view_field in Drupal 6

Same name and namespace in other branches
  1. 4 modules/profile.module \profile_view_field()
  2. 5 modules/profile/profile.module \profile_view_field()
  3. 7 modules/profile/profile.module \profile_view_field()
2 calls to profile_view_field()
profile_view_profile in modules/profile/profile.module
_profile_update_user_fields in modules/profile/profile.module
Helper function: update an array of user fields by calling profile_view_field

File

modules/profile/profile.module, line 249
Support for configurable user profiles.

Code

function profile_view_field($user, $field) {

  // Only allow browsing of private fields for admins, if browsing is enabled,
  // and if a user has permission to view profiles. Note that this check is
  // necessary because a user may always see their own profile.
  $browse = user_access('access user profiles') && (user_access('administer users') || $field->visibility != PROFILE_PRIVATE) && !empty($field->page);
  if (isset($user->{$field->name}) && ($value = $user->{$field->name})) {
    switch ($field->type) {
      case 'textarea':
        return check_markup($value);
      case 'textfield':
      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':
        $format = substr(variable_get('date_format_short', 'm/d/Y - H:i'), 0, 5);

        // Note: 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' => map_month($value['month']),
          'Y' => $value['year'],
          'H:i' => NULL,
          'g:ia' => NULL,
        );
        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/' . $field->name . '/' . $value) : check_plain($value);
          }
        }
        return implode(', ', $fields);
    }
  }
}