Elgg  Version 5.0
userpicker.php
Go to the documentation of this file.
1 <?php
23 $name = elgg_extract('name', $vars, 'members', false);
24 
25 $guids = (array) elgg_extract('values', $vars, elgg_extract('value', $vars, []));
26 
27 $params = elgg_extract('options', $vars, []);
28 
29 $friends_only = (bool) elgg_extract('only_friends', $vars, false);
30 $show_friends = (bool) elgg_extract('show_friends', $vars, !$friends_only);
31 if ($friends_only) {
32  $params['friends_only'] = true;
33 }
34 
35 $params['include_banned'] = (bool) elgg_extract('include_banned', $vars, false);
36 
37 if (!empty($params)) {
38  ksort($params);
39 
40  // We sign custom parameters, so that plugins can validate
41  // that the request is unaltered, if needed
43  $params['mac'] = $mac->getToken();
44 }
45 
46 $handler = elgg_extract('handler', $vars, 'livesearch');
47 $params['view'] = 'json'; // force json viewtype
48 
50  'class' => elgg_extract_class($vars, ['elgg-user-picker']),
51  'data-limit' => (int) elgg_extract('limit', $vars, 0),
52  'data-name' => $name,
54 ];
55 
57  'type' => 'text',
58  'class' => 'elgg-input-user-picker',
59  'size' => 30,
60  'id' => elgg_extract('id', $vars),
61  'placeholder' => elgg_extract('placeholder', $vars),
62 ]);
63 
64 $picker .= elgg_view('input/hidden', ['name' => $name]);
65 
66 if ($show_friends) {
67  $picker .= elgg_view('input/checkbox', [
68  'name' => 'match_on',
69  'value' => 'friends',
70  'default' => elgg_extract('match_on', $vars, 'users', false),
71  'label' => elgg_echo('userpicker:only_friends'),
72  ]);
74  $wrapper_options['data-match-on'] = 'friends';
75 } else {
76  $wrapper_options['data-match-on'] = elgg_extract('match_on', $vars, 'users', false);
77 }
78 
79 $items = '';
80 foreach ($guids as $guid) {
81  $entity = get_entity((int) $guid);
82  if (!$entity instanceof \ElggEntity) {
83  continue;
84  }
85 
86  $items .= elgg_view('input/autocomplete/item', [
87  'entity' => $entity,
88  'input_name' => $name,
89  ]);
90 }
91 
92 $picker .= elgg_format_element('ul', ['class' => 'elgg-list elgg-user-picker-list'], $items);
93 
95 
96 ?>
97 <script>
98  require(['elgg/UserPicker'], function (UserPicker) {
99  var name = <?= json_encode($name) ?>;
100  UserPicker.setup('.elgg-user-picker[data-name="' + name + '"]');
101  });
102 </script>
$guids
Definition: userpicker.php:25
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$friends_only
Definition: userpicker.php:29
$picker
Definition: userpicker.php:56
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:276
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
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:254
$wrapper_options
Definition: userpicker.php:49
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:177
$entity
Definition: reset.php:8
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:67
elgg_http_add_url_query_elements(string $url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:181
$items
Definition: userpicker.php:79
if(!empty($params)) $handler
Definition: userpicker.php:46
$vars['head']
Definition: html.php:24
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
$params
Definition: userpicker.php:27
$show_friends
Definition: userpicker.php:30
elgg_build_hmac($data)
Get an HMAC token builder/validator object.
Definition: actions.php:56
$site name
Definition: settings.php:15
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
$name
User Picker.
Definition: userpicker.php:23