Passed
Push — master ( c2d8e3...289151 )
by Jeroen
06:06
created

elgg_user_account_page_handler()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 16
nc 5
nop 2
dl 0
loc 20
ccs 0
cts 15
cp 0
crap 30
rs 8.8571
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A elgg_get_registration_url() 0 4 1
A elgg_get_login_url() 0 4 1
1
<?php
2
/**
3
 * Elgg users
4
 * Functions to manage multiple or single users in an Elgg install
5
 *
6
 * @package Elgg.Core
7
 * @subpackage DataModel.User
8
 */
9
10
/**
11
 * Disables all of a user's entities
12
 *
13
 * @param int $owner_guid The owner GUID
14
 *
15
 * @return bool Depending on success
16
 */
17
function disable_user_entities($owner_guid) {
18
	try {
19 1
		$entity = get_entity($owner_guid);
20 1
		if (!$entity) {
21
			return false;
22
		}
23 1
		return _elgg_services()->entityTable->disableEntities($entity);
24
	} catch (DatabaseException $ex) {
25
		elgg_log($ex->getMessage(), 'ERROR');
26
27
		return false;
28
	}
29
}
30
31
/**
32
 * Get a user object from a GUID.
33
 *
34
 * This function returns an \ElggUser from a given GUID.
35
 *
36
 * @param int $guid The GUID
37
 *
38
 * @return \ElggUser|false
39
 */
40
function get_user($guid) {
41
	try {
42 162
		return _elgg_services()->entityTable->get($guid, 'user');
43
	} catch (InvalidParameterException $ex) {
44
		elgg_log($ex->getMessage(), 'ERROR');
45
46
		return false;
47
	} catch (ClassException $ex) {
48
		elgg_log($ex->getMessage(), 'ERROR');
49
50
		return false;
51
	}
52
}
53
54
/**
55
 * Get user by username
56
 *
57
 * @param string $username The user's username
58
 *
59
 * @return \ElggUser|false Depending on success
60
 */
61
function get_user_by_username($username) {
62 459
	return _elgg_services()->usersTable->getByUsername($username);
63
}
64
65
/**
66
 * Get user by persistent login password
67
 *
68
 * @param string $hash Hash of the persistent login password
69
 *
70
 * @return \ElggUser
71
 */
72
function get_user_by_code($hash) {
73
	return _elgg_services()->persistentLogin->getUserFromHash($hash);
0 ignored issues
show
Bug introduced by
Are you sure the usage of _elgg_services()->persis...>getUserFromHash($hash) targeting Elgg\PersistentLoginService::getUserFromHash() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
74
}
75
76
/**
77
 * Get an array of users from an email address
78
 *
79
 * @param string $email Email address.
80
 *
81
 * @return array
82
 */
83
function get_user_by_email($email) {
84 162
	return _elgg_services()->usersTable->getByEmail($email);
85
}
86
87
/**
88
 * Return users (or the number of them) who have been active within a recent period.
89
 *
90
 * @param array $options Array of options with keys:
91
 *
92
 *   seconds (int)  => Length of period (default 600 = 10min)
93
 *   limit   (int)  => Limit (default from settings)
94
 *   offset  (int)  => Offset (default 0)
95
 *   count   (bool) => Return a count instead of users? (default false)
96
 *
97
 * @return \ElggUser[]|int
98
 */
99
function find_active_users(array $options = []) {
100 1
	return _elgg_services()->usersTable->findActive($options);
101
}
102
103
/**
104
 * Generate and send a password request email to a given user's registered email address.
105
 *
106
 * @param int $user_guid User GUID
107
 *
108
 * @return bool
109
 */
110
function send_new_password_request($user_guid) {
111
	return _elgg_services()->passwords->sendNewPasswordRequest($user_guid);
112
}
113
114
/**
115
 * Low level function to reset a given user's password.
116
 *
117
 * This can only be called from execute_new_password_request().
118
 *
119
 * @param int    $user_guid The user.
120
 * @param string $password  Text (which will then be converted into a hash and stored)
121
 *
122
 * @return bool
123
 */
124
function force_user_password_reset($user_guid, $password) {
125
	return _elgg_services()->passwords->forcePasswordReset($user_guid, $password);
126
}
127
128
/**
129
 * Validate and change password for a user.
130
 *
131
 * @param int    $user_guid The user id
132
 * @param string $conf_code Confirmation code as sent in the request email.
133
 * @param string $password  Optional new password, if not randomly generated.
134
 *
135
 * @return bool True on success
136
 */
137
function execute_new_password_request($user_guid, $conf_code, $password = null) {
138
	return _elgg_services()->passwords->executeNewPasswordReset($user_guid, $conf_code, $password);
139
}
140
141
/**
142
 * Generate a random 12 character clear text password.
143
 *
144
 * @return string
145
 */
146
function generate_random_cleartext_password() {
147 154
	return _elgg_services()->crypto->getRandomString(12, \ElggCrypto::CHARS_PASSWORD);
148
}
149
150
/**
151
 * Simple function which ensures that a username contains only valid characters.
152
 *
153
 * This should only permit chars that are valid on the file system as well.
154
 *
155
 * @param string $username Username
156
 *
157
 * @return bool
158
 * @throws RegistrationException on invalid
159
 */
160
function validate_username($username) {
161 459
	$config = _elgg_config();
162
163
	// Basic, check length
164 459
	if (!isset($config->minusername)) {
165 2
		$config->minusername = 4;
166
	}
167
168 459
	if (strlen($username) < $config->minusername) {
169
		$msg = elgg_echo('registration:usernametooshort', [$config->minusername]);
170
		throw new \RegistrationException($msg);
171
	}
172
173
	// username in the database has a limit of 128 characters
174 459
	if (strlen($username) > 128) {
175
		$msg = elgg_echo('registration:usernametoolong', [128]);
176
		throw new \RegistrationException($msg);
177
	}
178
179
	// Blacklist for bad characters (partially nicked from mediawiki)
180
	$blacklist = '/[' .
181
		'\x{0080}-\x{009f}' . // iso-8859-1 control chars
182
		'\x{00a0}' .          // non-breaking space
183
		'\x{2000}-\x{200f}' . // various whitespace
184
		'\x{2028}-\x{202f}' . // breaks and control chars
185
		'\x{3000}' .          // ideographic space
186
		'\x{e000}-\x{f8ff}' . // private use
187 459
		']/u';
188
189 459
	if (preg_match($blacklist, $username)) {
190
		// @todo error message needs work
191
		throw new \RegistrationException(elgg_echo('registration:invalidchars'));
192
	}
193
194
	// Belts and braces
195
	// @todo Tidy into main unicode
196 459
	$blacklist2 = '\'/\\"*& ?#%^(){}[]~?<>;|¬`@+=';
197
198 459
	$blacklist2 = elgg_trigger_plugin_hook('username:character_blacklist', 'user',
199 459
		['blacklist' => $blacklist2], $blacklist2);
200
201 459
	for ($n = 0; $n < strlen($blacklist2); $n++) {
202 459
		if (strpos($username, $blacklist2[$n]) !== false) {
203
			$msg = elgg_echo('registration:invalidchars', [$blacklist2[$n], $blacklist2]);
204
			$msg = htmlspecialchars($msg, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
205
			throw new \RegistrationException($msg);
206
		}
207
	}
208
209 459
	$result = true;
210
211 459
	return elgg_trigger_plugin_hook('registeruser:validate:username', 'all',
212 459
		['username' => $username], $result);
213
}
214
215
/**
216
 * Simple validation of a password.
217
 *
218
 * @param string $password Clear text password
219
 *
220
 * @return bool
221
 * @throws RegistrationException on invalid
222
 */
223
function validate_password($password) {
224 162
	$config = _elgg_config();
225
226 162
	if (!isset($config->min_password_length)) {
227 9
		$config->min_password_length = 6;
228
	}
229
230 162
	if (strlen($password) < $config->min_password_length) {
231
		$msg = elgg_echo('registration:passwordtooshort', [$config->min_password_length]);
232
		throw new \RegistrationException($msg);
233
	}
234
235 162
	$result = true;
236
237 162
	return elgg_trigger_plugin_hook('registeruser:validate:password', 'all',
238 162
		['password' => $password], $result);
239
}
240
241
/**
242
 * Simple validation of a email.
243
 *
244
 * @param string $address Email address
245
 *
246
 * @throws RegistrationException on invalid
247
 * @return bool
248
 */
249
function validate_email_address($address) {
250 447
	if (!is_email_address($address)) {
251
		throw new \RegistrationException(elgg_echo('registration:notemail'));
252
	}
253
254
	// Got here, so lets try a hook (defaulting to ok)
255 447
	$result = true;
256
257 447
	return elgg_trigger_plugin_hook('registeruser:validate:email', 'all',
258 447
		['email' => $address], $result);
259
}
260
261
/**
262
 * Registers a user, returning false if the username already exists
263
 *
264
 * @param string $username              The username of the new user
265
 * @param string $password              The password
266
 * @param string $name                  The user's display name
267
 * @param string $email                 The user's email address
268
 * @param bool   $allow_multiple_emails Allow the same email address to be
269
 *                                      registered multiple times?
270
 * @param string $subtype               Subtype of the user entity
271
 *
272
 * @return int|false The new user's GUID; false on failure
273
 * @throws RegistrationException
274
 */
275
function register_user($username, $password, $name, $email, $allow_multiple_emails = false, $subtype = null) {
276 162
	return _elgg_services()->usersTable->register($username, $password, $name, $email, $allow_multiple_emails, $subtype);
277
}
278
279
/**
280
 * Generates a unique invite code for a user
281
 *
282
 * @param string $username The username of the user sending the invitation
283
 *
284
 * @return string Invite code
285
 * @see elgg_validate_invite_code()
286
 */
287
function generate_invite_code($username) {
288
	return _elgg_services()->usersTable->generateInviteCode($username);
289
}
290
291
/**
292
 * Validate a user's invite code
293
 *
294
 * @param string $username The username
295
 * @param string $code     The invite code
296
 *
297
 * @return bool
298
 * @see   generate_invite_code()
299
 * @since 1.10
300
 */
301
function elgg_validate_invite_code($username, $code) {
302
	return _elgg_services()->usersTable->validateInviteCode($username, $code);
303
}
304
305
/**
306
 * Returns site's registration URL
307
 * Triggers a 'registration_url', 'site' plugin hook that can be used by
308
 * plugins to alter the default registration URL and append query elements, such as
309
 * an invitation code and inviting user's guid
310
 *
311
 * @param array  $query    An array of query elements
312
 * @param string $fragment Fragment identifier
313
 * @return string
314
 */
315
function elgg_get_registration_url(array $query = [], $fragment = '') {
316
	$url = elgg_normalize_url(elgg_generate_url('account:register'));
317
	$url = elgg_http_add_url_query_elements($url, $query) . $fragment;
318
	return elgg_trigger_plugin_hook('registration_url', 'site', $query, $url);
319
}
320
321
/**
322
 * Returns site's login URL
323
 * Triggers a 'login_url', 'site' plugin hook that can be used by
324
 * plugins to alter the default login URL
325
 *
326
 * @param array  $query    An array of query elements
327
 * @param string $fragment Fragment identifier (e.g. #login-dropdown-box)
328
 * @return string
329
 */
330
function elgg_get_login_url(array $query = [], $fragment = '') {
331
	$url = elgg_normalize_url(elgg_generate_url('account:login'));
332
	$url = elgg_http_add_url_query_elements($url, $query) . $fragment;
333
	return elgg_trigger_plugin_hook('login_url', 'site', $query, $url);
334
}
335
336
/**
337
 * Set user avatar URL
338
 * Replaces user avatar URL with a public URL when walled garden is disabled
339
 *
340
 * @param string $hook   "entity:icon:url"
341
 * @param string $type   "user"
342
 * @param string $return Icon URL
343
 * @param array  $params Hook params
344
 * @return string
345
 * @access private
346
 */
347 1
function user_avatar_hook($hook, $type, $return, $params) {
348 1
	$user = elgg_extract('entity', $params);
349 1
	$size = elgg_extract('size', $params, 'medium');
350
351
	if (!$user instanceof ElggUser) {
352
		return;
353
	}
354
355
	if (_elgg_config()->walled_garden) {
356
		return;
357
	}
358
359
	if (!$user->hasIcon($size, 'icon')) {
360
		return;
361
	}
362
363
	$icon = $user->getIcon($size, 'icon');
364
	return elgg_get_inline_url($icon, false);
365
}
366
367
/**
368
 * Setup the default user hover menu
369
 *
370
 * @param string         $hook   'register'
371
 * @param string         $type   'menu:user_hover'
372
 * @param ElggMenuItem[] $return current return value
373
 * @param array          $params supplied params
374
 *
375
 * @return void|ElggMenuItem[]
376
 *
377
 * @access private
378
 */
379 1
function elgg_user_hover_menu($hook, $type, $return, $params) {
380 1
	$user = elgg_extract('entity', $params);
381
	/* @var \ElggUser $user */
382 1
383
	if (!$user instanceof \ElggUser) {
384
		return;
385
	}
386 1
387
	if (!elgg_is_logged_in()) {
388
		return;
389
	}
390 1
391 1
	if ($user->canEdit()) {
392
		$return[] = ElggMenuItem::factory([
393
			'name' => 'avatar:edit',
394
			'text' => elgg_echo('avatar:edit'),
395
			'icon' => 'image',
396
			'href' => elgg_generate_entity_url($user, 'edit', 'avatar'),
397
			'section' => (elgg_get_logged_in_user_guid() == $user->guid)? 'action' : 'admin',
398
		]);
399
	}
400
401
	// prevent admins from banning or deleting themselves
402
	if (elgg_get_logged_in_user_guid() == $user->guid) {
403
		return $return;
404
	}
405
406
	if (!elgg_is_admin_logged_in()) {
407
		return $return;
408
	}
409
410
	// following items are admin only
411 1
	if (!$user->isBanned()) {
412
		$return[] = ElggMenuItem::factory([
413
			'name' => 'ban',
414 1
			'text' => elgg_echo('ban'),
415
			'icon' => 'ban',
416
			'href' => "action/admin/user/ban?guid={$user->guid}",
417
			'confirm' => true,
418 1
			'section' => 'admin',
419 1
		]);
420
	} else {
421
		$return[] = ElggMenuItem::factory([
422
			'name' => 'unban',
423
			'text' => elgg_echo('unban'),
424
			'icon' => 'ban',
425
			'href' => "action/admin/user/unban?guid={$user->guid}",
426
			'confirm' => true,
427
			'section' => 'admin',
428
		]);
429
	}
430
431
	$return[] = ElggMenuItem::factory([
432
		'name' => 'delete',
433
		'text' => elgg_echo('delete'),
434
		'icon' => 'delete',
435
		'href' => "action/admin/user/delete?guid={$user->guid}",
436
		'confirm' => true,
437
		'section' => 'admin',
438
	]);
439
440
	$return[] = ElggMenuItem::factory([
441
		'name' => 'resetpassword',
442
		'text' => elgg_echo('resetpassword'),
443
		'icon' => 'refresh',
444
		'href' => "action/admin/user/resetpassword?guid={$user->guid}",
445
		'confirm' => true,
446
		'section' => 'admin',
447
	]);
448
449
	if (!$user->isAdmin()) {
450
		$return[] = ElggMenuItem::factory([
451
			'name' => 'makeadmin',
452
			'text' => elgg_echo('makeadmin'),
453
			'icon' => 'level-up',
454
			'href' => "action/admin/user/makeadmin?guid={$user->guid}",
455
			'confirm' => true,
456
			'section' => 'admin',
457
		]);
458
	} else {
459
		$return[] = ElggMenuItem::factory([
460
			'name' => 'removeadmin',
461
			'text' => elgg_echo('removeadmin'),
462
			'icon' => 'level-down',
463
			'href' => "action/admin/user/removeadmin?guid={$user->guid}",
464
			'confirm' => true,
465
			'section' => 'admin',
466
		]);
467
	}
468
469
	$return[] = ElggMenuItem::factory([
470
		'name' => 'settings:edit',
471
		'text' => elgg_echo('settings:edit'),
472
		'icon' => 'cogs',
473
		'href' => "settings/user/$user->username",
474
		'section' => 'admin',
475
	]);
476
477
	return $return;
478
}
479
480
/**
481
 * Register menu items for the page menu
482
 *
483
 * @param string         $hook   'register'
484
 * @param string         $type   'menu:page'
485
 * @param ElggMenuItem[] $return current return value
486
 * @param array          $params supplied params
487
 *
488
 * @return void|ElggMenuItem[]
489
 *
490
 * @access private
491
 * @since 3.0
492
 */
493
function _elgg_user_page_menu($hook, $type, $return, $params) {
494
495
	$owner = elgg_get_page_owner_entity();
496
	if (!$owner) {
497
		return;
498
	}
499
500
	$return[] = \ElggMenuItem::factory([
501
		'name' => 'edit_avatar',
502
		'href' => elgg_generate_entity_url($owner, 'edit', 'avatar'),
503
		'text' => elgg_echo('avatar:edit'),
504
		'section' => '1_profile',
505
		'contexts' => ['settings'],
506
	]);
507
508
	return $return;
509
}
510
511
/**
512
 * Register menu items for the topbar menu
513
 *
514
 * @param string         $hook   'register'
515
 * @param string         $type   'menu:topbar'
516
 * @param ElggMenuItem[] $return current return value
517
 * @param array          $params supplied params
518
 *
519
 * @return void|ElggMenuItem[]
520
 *
521
 * @access private
522
 * @since 3.0
523
 */
524
function _elgg_user_topbar_menu($hook, $type, $return, $params) {
525
526
	$viewer = elgg_get_logged_in_user_entity();
527
	if (!$viewer) {
528
		return;
529
	}
530
531
	$return[] = \ElggMenuItem::factory([
532
		'name' => 'account',
533
		'text' => elgg_echo('account'),
534
		'href' => $viewer->getURL(),
535
		'icon' => elgg_view('output/img', [
536
			'src' => $viewer->getIconURL('small'),
537
			'alt' => $viewer->getDisplayName(),
538
		]),
539
		'icon_alt' => 'angle-down',
540
		'priority' => 800,
541
		'section' => 'alt',
542
	]);
543
544
	$return[] = \ElggMenuItem::factory([
545
		'name' => 'usersettings',
546
		'parent_name' => 'account',
547
		'href' => "settings/user/{$viewer->username}",
548
		'text' => elgg_echo('settings'),
549
		'icon' => 'sliders',
550
		'priority' => 300,
551
		'section' => 'alt',
552
	]);
553
554
	if ($viewer->isAdmin()) {
555
		$return[] = \ElggMenuItem::factory([
556
			'name' => 'administration',
557
			'parent_name' => 'account',
558
			'href' => 'admin',
559
			'text' => elgg_echo('admin'),
560
			'icon' => 'cogs',
561
			'priority' => 800,
562
			'section' => 'alt',
563 1
		]);
564 1
	}
565
566
	$return[] = \ElggMenuItem::factory([
567
		'name' => 'logout',
568 1
		'parent_name' => 'account',
569 1
		'href' => 'action/logout',
570 1
		'text' => elgg_echo('logout'),
571 1
		'icon' => 'sign-out',
572 1
		'is_action' => true,
573
		'priority' => 900,
574
		'section' => 'alt',
575
	]);
576 1
577
	return $return;
578
}
579
580
/**
581
 * Set user icon file
582
 *
583
 * @param string    $hook   "entity:icon:file"
584
 * @param string    $type   "user"
585
 * @param \ElggIcon $icon   Icon file
586
 * @param array     $params Hook params
587
 * @return \ElggIcon
588
 */
589
function _elgg_user_set_icon_file($hook, $type, $icon, $params) {
590
591
	$entity = elgg_extract('entity', $params);
592
	$size = elgg_extract('size', $params, 'medium');
593
594 1
	$icon->owner_guid = $entity->guid;
595 1
	$icon->setFilename("profile/{$entity->guid}{$size}.jpg");
596 1
597
	return $icon;
598
}
599
600
/**
601
 * Add the user to the subscribers when (un)banning the account
602
 *
603
 * @param string $hook         'get'
604
 * @param string $type         'subscribers'
605
 * @param array  $return_value current subscribers
606
 * @param array  $params       supplied params
607
 *
608
 * @return void|array
609
 */
610
function _elgg_user_get_subscriber_unban_action($hook, $type, $return_value, $params) {
611
612
	if (!_elgg_config()->security_notify_user_ban) {
613
		return;
614
	}
615
616
	$event = elgg_extract('event', $params);
617
	if (!($event instanceof \Elgg\Notifications\Event)) {
618
		return;
619
	}
620
621
	if ($event->getAction() !== 'unban') {
622
		return;
623
	}
624
625
	$user = $event->getObject();
626
	if (!($user instanceof \ElggUser)) {
627
		return;
628
	}
629
630
	$return_value[$user->getGUID()] = ['email'];
631
632
	return $return_value;
633
}
634
635
/**
636
 * Send a notification to the user that the account was banned
637
 *
638
 * Note: this can't be handled by the delayed notification system as it won't send notifications to banned users
639
 *
640
 * @param string    $event 'ban'
641
 * @param string    $type  'user'
642
 * @param \ElggUser $user  the user being banned
643
 *
644
 * @return void
645
 */
646
function _elgg_user_ban_notification($event, $type, $user) {
647
648
	if (!_elgg_config()->security_notify_user_ban) {
649
		return;
650
	}
651
652
	if (!($user instanceof \ElggUser)) {
653
		return;
654
	}
655
656
	$site = elgg_get_site_entity();
657
	$language = $user->getLanguage();
658
659 1
	$subject = elgg_echo('user:notification:ban:subject', [$site->name], $language);
660 1
	$body = elgg_echo('user:notification:ban:body', [
661
		$user->name,
662 1
		$site->name,
663 1
		$site->getURL(),
664
	], $language);
665 1
666
	$params = [
667
		'action' => 'ban',
668
		'object' => $user,
669
	];
670
671
	notify_user($user->getGUID(), $site->getGUID(), $subject, $body, $params, ['email']);
672
}
673
674
/**
675
 * Prepare the notification content for the user being unbanned
676
 *
677
 * @param string                           $hook         'prepare'
678
 * @param string                           $type         'notification:unban:user:'
679
 * @param \Elgg\Notifications\Notification $return_value current notification content
680 2
 * @param array                            $params       supplied params
681 2
 *
682
 * @return void|\Elgg\Notifications\Notification
683
 */
684
function _elgg_user_prepare_unban_notification($hook, $type, $return_value, $params) {
685
686
	if (!($return_value instanceof \Elgg\Notifications\Notification)) {
687
		return;
688
	}
689
690
	$recipient = elgg_extract('recipient', $params);
691
	$object = elgg_extract('object', $params);
692
	$language = elgg_extract('language', $params);
693
694
	if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser)) {
695
		return;
696
	}
697
698
	if ($recipient->getGUID() !== $object->getGUID()) {
699
		return;
700
	}
701
702
	$site = elgg_get_site_entity();
703
704
	$return_value->subject = elgg_echo('user:notification:unban:subject', [$site->name], $language);
705
	$return_value->body = elgg_echo('user:notification:unban:body', [
706
		$recipient->name,
707
		$site->name,
708
		$site->getURL(),
709
	], $language);
710
711
	$return_value->url = $recipient->getURL();
712
713
	return $return_value;
714
}
715
716 71
/**
717 71
 * Register menu items to the user:unvalidated menu
718
 *
719
 * @elgg_plugin_hook register menu:user:unvalidated
720
 *
721
 * @param \Elgg\Hook $hook the plugin hook 'register' 'menu:user:unvalidated'
722
 *
723
 * @return void|ElggMenuItem[]
724
 *
725
 * @since 3.0
726
 * @internal
727
 */
728
function _elgg_user_unvalidated_menu(\Elgg\Hook $hook) {
729
	
730
	if (!elgg_is_admin_logged_in()) {
731
		return;
732
	}
733
	
734
	$entity = $hook->getEntityParam();
735
	if (!$entity instanceof ElggUser) {
736
		return;
737
	}
738
	
739
	$return = $hook->getValue();
740
	
741
	$return[] = ElggMenuItem::factory([
742
		'name' => 'validate',
743
		'text' => elgg_echo('validate'),
744
		'href' => elgg_http_add_url_query_elements('action/admin/user/validate', [
745
			'user_guid' => $entity->guid,
746
		]),
747
		'confirm' => true,
748
		'priority' => 400,
749
	]);
750
	
751
	$return[] = ElggMenuItem::factory([
752
		'name' => 'delete',
753
		'text' => elgg_echo('delete'),
754
		'href' => elgg_http_add_url_query_elements('action/admin/user/delete', [
755
			'guid' => $entity->guid,
756
		]),
757
		'confirm' => elgg_echo('deleteconfirm'),
758
		'priority' => 500,
759
	]);
760
	
761
	return $return;
762
}
763
764
/**
765
 * Users initialisation function, which establishes the page handler
766
 *
767
 * @return void
768
 * @access private
769
 */
770
function users_init() {
771
772
	elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'elgg_user_hover_menu');
773
	elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_user_page_menu');
774
	elgg_register_plugin_hook_handler('register', 'menu:topbar', '_elgg_user_topbar_menu');
775
	elgg_register_plugin_hook_handler('register', 'menu:user:unvalidated', '_elgg_user_unvalidated_menu');
776
777
	elgg_register_action('login', '', 'public');
778
	elgg_register_action('logout');
779
	elgg_register_action('register', '', 'public');
780
	elgg_register_action('useradd', '', 'admin');
781
	elgg_register_action('avatar/upload');
782
	elgg_register_action('avatar/crop');
783
	elgg_register_action('avatar/remove');
784
785
	elgg_register_plugin_hook_handler('entity:icon:url', 'user', 'user_avatar_hook');
786
787
	elgg_register_action('user/changepassword', '', 'public');
788
	elgg_register_action('user/requestnewpassword', '', 'public');
789
790
	// Register the user type
791
	elgg_register_entity_type('user', '');
792 31
793 31
	elgg_register_plugin_hook_handler('entity:icon:file', 'user', '_elgg_user_set_icon_file');
794 31
795 31
	elgg_register_notification_event('user', '', ['unban']);
796 31
	elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_user_get_subscriber_unban_action');
797 31
	elgg_register_event_handler('ban', 'user', '_elgg_user_ban_notification');
798
	elgg_register_plugin_hook_handler('prepare', 'notification:unban:user:', '_elgg_user_prepare_unban_notification');
799 31
800 31
}
801 31
802
/**
803 31
 * @see \Elgg\Application::loadCore Do not do work here. Just register for events.
804 31
 */
805 31
return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
806 31
	$events->registerHandler('init', 'system', 'users_init', 0);
807
};
808