Passed
Push — master ( 739723...ddf37a )
by Jeroen
05:42
created

expages_init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 19
ccs 11
cts 11
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Plugin for creating web pages for your site
4
 */
5
6
/**
7
 * External pages init
8
 *
9
 * @return void
10
 */
11
function expages_init() {
12
13
	// Register public external pages
14 31
	elgg_register_plugin_hook_handler('public_pages', 'walled_garden', 'expages_public');
15 31
16 31
	elgg_register_plugin_hook_handler('register', 'menu:expages', 'expages_menu_register_hook');
17 31
18
	// add a menu item for the admin edit page
19
	elgg_register_menu_item('page', [
20 31
		'name' => 'configure_utilities:expages',
21
		'text' => elgg_echo('admin:configure_utilities:expages'),
22 31
		'href' => 'admin/configure_utilities/expages',
23
		'section' => 'configure',
24
		'parent_name' => 'configure_utilities',
25 31
		'context' => 'admin',
26 31
	]);
27 31
28 31
	// add footer links
29 31
	expages_setup_footer_menu();
30 31
}
31 31
32
/**
33
 * Extend the public pages range
34
 *
35 31
 * @param string $hook    'public_pages'
36 31
 * @param string $handler 'walled_garden'
37
 * @param array  $return  current return value
38
 * @param mixed  $params  supplied params
39
 *
40
 * @return array
41
 */
42
function expages_public($hook, $handler, $return, $params) {
0 ignored issues
show
Unused Code introduced by Ismayil Khayredinov
The parameter $handler is not used and could be removed. ( Ignorable by Annotation )

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

42
function expages_public($hook, /** @scrutinizer ignore-unused */ $handler, $return, $params) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by Ismayil Khayredinov
The parameter $params is not used and could be removed. ( Ignorable by Annotation )

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

42
function expages_public($hook, $handler, $return, /** @scrutinizer ignore-unused */ $params) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by Ismayil Khayredinov
The parameter $hook is not used and could be removed. ( Ignorable by Annotation )

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

42
function expages_public(/** @scrutinizer ignore-unused */ $hook, $handler, $return, $params) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
	$pages = ['about', 'terms', 'privacy'];
44
	return array_merge($pages, $return);
45
}
46
47
/**
48
 * Setup the links to site pages
49
 *
50
 * @return void
51
 */
52
function expages_setup_footer_menu() {
53
	$pages = ['about', 'terms', 'privacy'];
54
	foreach ($pages as $page) {
55
		elgg_register_menu_item('walled_garden', [
56
			'name' => $page,
57
			'text' => elgg_echo("expages:$page"),
58
			'href' => $page,
59 31
		]);
60 31
61 31
		elgg_register_menu_item('footer', [
62 31
			'name' => $page,
63 31
			'text' => elgg_echo("expages:$page"),
64 31
			'href' => $page,
65
			'section' => 'meta',
66
		]);
67 31
	}
68 31
}
69 31
70 31
/**
71 31
 * Adds menu items to the expages edit form
72
 *
73
 * @param string $hook   'register'
74 31
 * @param string $type   'menu:expages'
75
 * @param array  $return current menu items
76
 * @param array  $params parameters
77
 *
78
 * @return array
79
 */
80
function expages_menu_register_hook($hook, $type, $return, $params) {
0 ignored issues
show
Unused Code introduced by Jeroen Dalsem
The parameter $hook is not used and could be removed. ( Ignorable by Annotation )

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

80
function expages_menu_register_hook(/** @scrutinizer ignore-unused */ $hook, $type, $return, $params) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by Jeroen Dalsem
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

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

80
function expages_menu_register_hook($hook, /** @scrutinizer ignore-unused */ $type, $return, $params) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
	$type = elgg_extract('type', $params);
82
		
83
	$pages = ['about', 'terms', 'privacy'];
84
	foreach ($pages as $page) {
85
		$return[] = ElggMenuItem::factory([
86
			'name' => $page,
87
			'text' => elgg_echo("expages:$page"),
88
			'href' => "admin/configure_utilities/expages?type=$page",
89
			'selected' => $page === $type,
90
		]);
91
	}
92
	return $return;
93
}
94
95
return function() {
96
	elgg_register_event_handler('init', 'system', 'expages_init');
97
};
98