Elgg  Version master
profile.php
Go to the documentation of this file.
1 <?php
9 $entity = elgg_extract('entity', $vars);
10 if (!$entity instanceof \ElggUser) {
11  return;
12 }
13 
14 $fields = elgg()->fields->get('user', 'user');
15 if (empty($fields)) {
16  echo elgg_view_no_results(elgg_echo('admin:users:details:profile:no_fields'));
17  return;
18 }
19 
21  'mobile' => 'tel p-tel',
22  'phone' => 'tel p-tel',
23  'website' => 'url u-url',
24  'contactemail' => 'email u-email',
25 ];
26 $microformats = array_merge($microformats, (array) elgg_extract('microformats', $vars, []));
27 
28 $output = '';
29 foreach ($fields as $field) {
30  $shortname = $field['name'];
31  $valtype = $field['#type'];
32 
33  $value = $entity->getProfileData($shortname);
34  if (elgg_is_empty($value)) {
35  continue;
36  }
37 
38  // validate urls
39  if ($valtype === 'url' && is_string($value) && !preg_match('~^https?\://~i', $value)) {
40  $value = "http://{$value}";
41  }
42 
43  $output .= elgg_view('object/elements/field', [
44  'label' => elgg_extract('#label', $field),
45  'value' => elgg_format_element('span', [
46  'class' => elgg_extract($shortname, $microformats),
47  ], elgg_view("output/{$valtype}", [
48  'value' => $value,
49  ])),
50  'name' => $shortname,
51  ]);
52 }
53 
54 if (empty($output)) {
55  echo elgg_view_no_results(elgg_echo('admin:users:details:profile:no_information'));
56  return;
57 }
58 
59 echo elgg_format_element('div', ['class' => 'elgg-profile-fields'], $output);
$vars
Definition: theme.php:3
if(elgg_extract('input_type', $vars)) if(elgg_extract('required', $vars)) if(elgg_extract('disabled', $vars)) $field
Definition: field.php:42
elgg()
Bootstrapping and helper procedural code available for use in Elgg core and plugins.
Definition: elgglib.php:12
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:240
elgg_is_empty($value)
Check if a value isn't empty, but allow 0 and '0'.
Definition: input.php:176
$value
Definition: generic.php:51
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_view_no_results(string $text='')
Helper function to display a no results view.
Definition: views.php:1475
elgg_view(string $view, array $vars=[], string $viewtype='')
Return a parsed view.
Definition: views.php:156
elgg_format_element(string $tag_name, array $attributes=[], string $text='', array $options=[])
Format an HTML element.
Definition: output.php:145
if(empty($fields)) $microformats
Definition: profile.php:20
$output
Definition: profile.php:28
$entity
Show user profile information in admin listings.
Definition: profile.php:9
if(! $entity instanceof \ElggUser) $fields
Definition: profile.php:14