Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

mod/members/start.php (1 issue)

1
<?php
2
/**
3
 * Members plugin initialization
4
 */
5
6
/**
7
 * Initialize page handler and site menu item
8
 *
9
 * @return void
10
 */
11
function members_init() {
12 31
	elgg_register_page_handler('members', 'members_page_handler');
0 ignored issues
show
Deprecated Code introduced by Cash Costello
The function elgg_register_page_handler() has been deprecated: 3.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

12
	/** @scrutinizer ignore-deprecated */ elgg_register_page_handler('members', 'members_page_handler');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
13
14 31
	elgg_register_menu_item('site', [
15 31
		'name' => 'members',
16 31
		'text' => elgg_echo('members'),
17 31
		'href' => 'members',
18
	]);
19
20 31
	if (elgg_is_admin_logged_in()) {
21
		elgg_register_menu_item('title', [
22
			'name' => 'add_user',
23
			'text' => elgg_echo('admin:users:add'),
24
			'href' => 'admin/users/add',
25
			'context' => 'members',
26
			'link_class' => 'elgg-button elgg-button-action',
27
		]);
28
	}
29
	
30 31
	elgg_register_plugin_hook_handler('register', 'menu:filter:members', 'members_register_filter_menu');
31 31
}
32
33
/**
34
 * Registers members filter menu items
35
 *
36
 * @elgg_plugin_hook 'register', 'menu:filter:members'
37
 *
38
 * @param \Elgg\Hook $hook hook
39
 *
40
 * @return \ElggMenuItem[]
41
 */
42
function members_register_filter_menu(\Elgg\Hook $hook) {
43
	$result = (array) $hook->getValue();
44
	
45
	$result['newest'] = \ElggMenuItem::factory([
46
		'name' => 'newest',
47
		'text' => elgg_echo('sort:newest'),
48
		'href' => 'members/newest',
49
		'selected' => $hook->getParam('filter_value') == 'newest',
50
	]);
51
	$result['alpha'] =\ElggMenuItem::factory([
52
		'name' => 'alpha',
53
		'text' => elgg_echo('sort:alpha'),
54
		'href' => 'members/alpha',
55
	]);
56
	$result['popular'] = \ElggMenuItem::factory([
57
		'name' => 'popular',
58
		'text' => elgg_echo('sort:popular'),
59
		'href' => 'members/popular',
60
	]);
61
	$result['online'] = \ElggMenuItem::factory([
62
		'name' => 'online',
63
		'text' => elgg_echo('members:label:online'),
64
		'href' => 'members/online',
65
	]);
66
	
67
	return $result;
68
}
69
70
/**
71
 * Members page handler
72
 *
73
 * @param array $page url segments
74
 * @return void|true
75
 */
76
function members_page_handler($page) {
77
	if (empty($page[0])) {
78
		$page[0] = 'newest';
79
	}
80
	
81
	$resource = "members/{$page[0]}";
82
	if (elgg_view_exists("resources/{$resource}")) {
83
		echo elgg_view_resource($resource);
84
		return true;
85
	}
86
}
87
88
return function() {
89 18
	elgg_register_event_handler('init', 'system', 'members_init');
90
};
91