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

mod/reportedcontent/start.php (1 issue)

1
<?php
2
/**
3
 * Elgg Reported content.
4
 *
5
 * @package ElggReportedContent
6
 */
7
8
/**
9
 * Initialize the plugin
10
 *
11
 * @return void
12
 */
13
function reportedcontent_init() {
14
15
	// Register a page handler, so we can have nice URLs
16 31
	elgg_register_page_handler('reportedcontent', 'reportedcontent_page_handler');
0 ignored issues
show
Deprecated Code introduced by Evan Winslow
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('reportedcontent', 'reportedcontent_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
18
	// Extend CSS
19 31
	elgg_extend_view('elgg.css', 'reportedcontent/css');
20 31
	elgg_extend_view('admin.css', 'reportedcontent/admin_css');
21
22
23 31
	if (elgg_is_logged_in()) {
24
		// Extend footer with report content link
25
		elgg_register_menu_item('footer', [
26
			'name' => 'report_this',
27
			'href' => 'reportedcontent/add',
28
			'title' => elgg_echo('reportedcontent:this:tooltip'),
29
			'text' => elgg_echo('reportedcontent:this'),
30
			'icon' => 'exclamation-triangle',
31
			'priority' => 500,
32
			'section' => 'default',
33
			'link_class' => 'elgg-lightbox',
34
			'deps' => 'elgg/reportedcontent',
35
		]);
36
	}
37
38 31
	elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'reportedcontent_user_hover_menu');
39
40 31
	elgg_register_menu_item('page', [
41 31
		'name' => 'administer_utilities:reportedcontent',
42 31
		'text' => elgg_echo('admin:administer_utilities:reportedcontent'),
43 31
		'href' => 'admin/administer_utilities/reportedcontent',
44 31
		'section' => 'administer',
45 31
		'parent_name' => 'administer_utilities',
46 31
		'context' => 'admin',
47
	]);
48 31
}
49
50
/**
51
 * Reported content page handler
52
 *
53
 * Serves the add report page
54
 *
55
 * @param array $page Array of page routing elements
56
 * @return bool
57
 */
58
function reportedcontent_page_handler($page) {
59
	// only logged in users can report things
60
	elgg_gatekeeper();
61
62
	if (elgg_extract(0, $page) === 'add' && elgg_is_xhr()) {
63
		echo elgg_view_resource('reportedcontent/add_form');
64
		return true;
65
	}
66
67
	echo elgg_view_resource('reportedcontent/add');
68
	return true;
69
}
70
71
/**
72
 * Add report user link to hover menu
73
 *
74
 * @param string         $hook   'register'
75
 * @param string         $type   'menu:user_hover'
76
 * @param ElggMenuItem[] $return current return value
77
 * @param array          $params supplied params
78
 *
79
 * @return void|ElggMenuItem[]
80
 */
81
function reportedcontent_user_hover_menu($hook, $type, $return, $params) {
82
	
83 1
	if (!elgg_is_logged_in()) {
84 1
		return;
85
	}
86
	
87
	$user = elgg_extract('entity', $params);
88
	if (!$user instanceof ElggUser) {
89
		return;
90
	}
91
	
92
	if (elgg_get_logged_in_user_guid() == $user->guid) {
93
		return;
94
	}
95
	
96
	$href = elgg_http_add_url_query_elements('reportedcontent/add', [
97
		'address' => $user->getURL(),
98
		'title' => $user->name,
99
	]);
100
	
101
	$return[] = \ElggMenuItem::factory([
102
		'name' => 'reportuser',
103
		'text' => elgg_echo('reportedcontent:user'),
104
		'icon' => 'exclamation-triangle',
105
		'href' => $href,
106
		'section' => 'action',
107
		'link_class' => 'elgg-lightbox',
108
		'deps' => 'elgg/reportedcontent',
109
	]);
110
111
	return $return;
112
}
113
114
return function() {
115 18
	elgg_register_event_handler('init', 'system', 'reportedcontent_init');
116
};
117