You are here

function profile_view_field in Drupal 7

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. 6 modules/profile/profile.module \profile_view_field()
2 calls to profile_view_field()
profile_user_view in modules/profile/profile.module
Implements hook_user_view().
_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 278
Support for configurable user profiles.

Code

function profile_view_field($account, $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($account->{$field->name}) && ($value = $account->{$field->name})) {
    switch ($field->type) {
      case 'textarea':
        return check_markup($value, filter_default_format($account), '', TRUE);
      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 = preg_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);
    }
  }
}