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

expages_public()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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 a page handler, so we can have nice URLs
14 31
	elgg_register_page_handler('about', 'expages_page_handler');
0 ignored issues
show
Deprecated Code introduced by
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

14
	/** @scrutinizer ignore-deprecated */ elgg_register_page_handler('about', 'expages_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...
15 31
	elgg_register_page_handler('terms', 'expages_page_handler');
0 ignored issues
show
Deprecated Code introduced by
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

15
	/** @scrutinizer ignore-deprecated */ elgg_register_page_handler('terms', 'expages_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...
16 31
	elgg_register_page_handler('privacy', 'expages_page_handler');
0 ignored issues
show
Deprecated Code introduced by
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

16
	/** @scrutinizer ignore-deprecated */ elgg_register_page_handler('privacy', 'expages_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...
17 31
	elgg_register_page_handler('expages', 'expages_page_handler');
0 ignored issues
show
Deprecated Code introduced by
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

17
	/** @scrutinizer ignore-deprecated */ elgg_register_page_handler('expages', 'expages_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...
18
19
	// Register public external pages
20 31
	elgg_register_plugin_hook_handler('public_pages', 'walled_garden', 'expages_public');
21
22 31
	elgg_register_plugin_hook_handler('register', 'menu:expages', 'expages_menu_register_hook');
23
24
	// add a menu item for the admin edit page
25 31
	elgg_register_menu_item('page', [
26 31
		'name' => 'configure_utilities:expages',
27 31
		'text' => elgg_echo('admin:configure_utilities:expages'),
28 31
		'href' => 'admin/configure_utilities/expages',
29 31
		'section' => 'configure',
30 31
		'parent_name' => 'configure_utilities',
31 31
		'context' => 'admin',
32
	]);
33
34
	// add footer links
35 31
	expages_setup_footer_menu();
36 31
}
37
38
/**
39
 * Extend the public pages range
40
 *
41
 * @param string $hook    'public_pages'
42
 * @param string $handler 'walled_garden'
43
 * @param array  $return  current return value
44
 * @param mixed  $params  supplied params
45
 *
46
 * @return array
47
 */
48
function expages_public($hook, $handler, $return, $params) {
2 ignored issues
show
Unused Code introduced by
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

48
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
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

48
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
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

48
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...
49
	$pages = ['about', 'terms', 'privacy'];
50
	return array_merge($pages, $return);
51
}
52
53
/**
54
 * Setup the links to site pages
55
 *
56
 * @return void
57
 */
58
function expages_setup_footer_menu() {
59 31
	$pages = ['about', 'terms', 'privacy'];
60 31
	foreach ($pages as $page) {
61 31
		elgg_register_menu_item('walled_garden', [
62 31
			'name' => $page,
63 31
			'text' => elgg_echo("expages:$page"),
64 31
			'href' => $page,
65
		]);
66
67 31
		elgg_register_menu_item('footer', [
68 31
			'name' => $page,
69 31
			'text' => elgg_echo("expages:$page"),
70 31
			'href' => $page,
71 31
			'section' => 'meta',
72
		]);
73
	}
74 31
}
75
76
/**
77
 * External pages page handler
78
 *
79
 * @param array  $page    URL segements
80
 * @param string $handler Handler identifier
81
 * @return bool
82
 */
83
function expages_page_handler($page, $handler) {
84
	if ($handler == 'expages') {
85
		forward($page[1]);
86
	}
87
	$type = strtolower($handler);
88
89
	$title = elgg_echo("expages:$type");
90
91
	$object = elgg_get_entities([
92
		'type' => 'object',
93
		'subtype' => $type,
94
		'limit' => 1,
95
	]);
96
	
97
	$description = $object ? $object[0]->description : elgg_echo('expages:notset');
98
	$description = elgg_view('output/longtext', ['value' => $description]);
99
	
100
	$content = elgg_view('expages/wrapper', [
101
		'content' => $description,
102
	]);
103
	
104
	if (elgg_is_admin_logged_in()) {
105
		elgg_register_menu_item('title', [
106
			'name' => 'edit',
107
			'text' => elgg_echo('edit'),
108
			'href' => "admin/configure_utilities/expages?type=$type",
109
			'link_class' => 'elgg-button elgg-button-action',
110
		]);
111
	}
112
	
113
	$shell = 'default';
114
	if (elgg_get_config('walled_garden') && !elgg_is_logged_in()) {
115
		$shell = 'walled_garden';
116
	}
117
	$body = elgg_view_layout('default', [
118
		'content' => $content,
119
		'title' => $title,
120
		'sidebar' => false,
121
	]);
122
	echo elgg_view_page($title, $body, $shell);
123
	
124
	return true;
125
}
126
127
/**
128
 * Adds menu items to the expages edit form
129
 *
130
 * @param string $hook   'register'
131
 * @param string $type   'menu:expages'
132
 * @param array  $return current menu items
133
 * @param array  $params parameters
134
 *
135
 * @return array
136
 */
137
function expages_menu_register_hook($hook, $type, $return, $params) {
2 ignored issues
show
Unused Code introduced by
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

137
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...
Unused Code introduced by
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

137
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...
138
	$type = elgg_extract('type', $params);
139
		
140
	$pages = ['about', 'terms', 'privacy'];
141
	foreach ($pages as $page) {
142
		$return[] = ElggMenuItem::factory([
143
			'name' => $page,
144
			'text' => elgg_echo("expages:$page"),
145
			'href' => "admin/configure_utilities/expages?type=$page",
146
			'selected' => $page === $type,
147
		]);
148
	}
149
	return $return;
150
}
151
152
return function() {
153 18
	elgg_register_event_handler('init', 'system', 'expages_init');
154
};
155