profile_view_field

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

▾ 2 functions call profile_view_field()

profile_view_profile in modules/profile.module
_profile_update_user_fields in modules/profile.module
Helper function: update an array of user fields by calling profile_view_field

Code

modules/profile.module, line 521

<?php
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 ($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);
    }
  }
}
?>
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.