Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
permissions | |
0.00% |
0 / 24 |
|
0.00% |
0 / 10 |
272 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
get_categories | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_category_lang | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_types | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_type_lang | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
get_permissions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_permission_category | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
category_defined | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
permission_defined | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_permission_lang | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb; |
15 | |
16 | class permissions |
17 | { |
18 | /** |
19 | * Event dispatcher object |
20 | * @var \phpbb\event\dispatcher_interface |
21 | */ |
22 | protected $dispatcher; |
23 | |
24 | /** |
25 | * User object |
26 | * @var \phpbb\user |
27 | */ |
28 | protected $user; |
29 | |
30 | /** |
31 | * Constructor |
32 | * |
33 | * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher |
34 | * @param \phpbb\user $user User Object |
35 | */ |
36 | public function __construct(\phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\user $user) |
37 | { |
38 | $this->dispatcher = $phpbb_dispatcher; |
39 | $this->user = $user; |
40 | |
41 | $categories = $this->categories; |
42 | $types = $this->types; |
43 | $permissions = $this->permissions; |
44 | |
45 | /** |
46 | * Allows to specify additional permission categories, types and permissions |
47 | * |
48 | * @event core.permissions |
49 | * @var array types Array with permission types (a_, u_, m_, etc.) |
50 | * @var array categories Array with permission categories (pm, post, settings, misc, etc.) |
51 | * @var array permissions Array with permissions. Each Permission has the following layout: |
52 | * '<type><permission>' => array( |
53 | * 'lang' => 'Language Key with a Short description', // Optional, if not set, |
54 | * // the permissions identifier '<type><permission>' is used with |
55 | * // all uppercase. |
56 | * 'cat' => 'Identifier of the category, the permission should be displayed in', |
57 | * ), |
58 | * Example: |
59 | * 'u_viewprofile' => array( |
60 | * 'lang' => 'ACL_U_VIEWPROFILE', |
61 | * 'cat' => 'profile', |
62 | * ), |
63 | * @since 3.1.0-a1 |
64 | */ |
65 | $vars = array('types', 'categories', 'permissions'); |
66 | extract($this->dispatcher->trigger_event('core.permissions', compact($vars))); |
67 | |
68 | $this->categories = $categories; |
69 | $this->types = $types; |
70 | $this->permissions = $permissions; |
71 | } |
72 | |
73 | /** |
74 | * Returns an array with all the permission categories (pm, post, settings, misc, etc.) |
75 | * |
76 | * @return array Layout: cat-identifier => Language key |
77 | */ |
78 | public function get_categories() |
79 | { |
80 | return $this->categories; |
81 | } |
82 | |
83 | /** |
84 | * Returns the language string of a permission category |
85 | * |
86 | * @param string $category Identifier of the category |
87 | * @return string Language string |
88 | */ |
89 | public function get_category_lang($category) |
90 | { |
91 | return $this->user->lang($this->categories[$category]); |
92 | } |
93 | |
94 | /** |
95 | * Returns an array with all the permission types (a_, u_, m_, etc.) |
96 | * |
97 | * @return array Layout: type-identifier => Language key |
98 | */ |
99 | public function get_types() |
100 | { |
101 | return $this->types; |
102 | } |
103 | |
104 | /** |
105 | * Returns the language string of a permission type |
106 | * |
107 | * @param string $type Identifier of the type |
108 | * @param mixed $scope Scope of the type (should be 'global', 'local' or false) |
109 | * @return string Language string |
110 | */ |
111 | public function get_type_lang($type, $scope = false) |
112 | { |
113 | if ($scope && isset($this->types[$scope][$type])) |
114 | { |
115 | $lang_key = $this->types[$scope][$type]; |
116 | } |
117 | else if (isset($this->types[$type])) |
118 | { |
119 | $lang_key = $this->types[$type]; |
120 | } |
121 | else |
122 | { |
123 | $lang_key = 'ACL_TYPE_' . strtoupper(($scope) ? $scope . '_' . $type : $type); |
124 | } |
125 | |
126 | return $this->user->lang($lang_key); |
127 | } |
128 | |
129 | /** |
130 | * Returns an array with all the permissions. |
131 | * Each Permission has the following layout: |
132 | * '<type><permission>' => array( |
133 | * 'lang' => 'Language Key with a Short description', // Optional, if not set, |
134 | * // the permissions identifier '<type><permission>' is used with |
135 | * // all uppercase. |
136 | * 'cat' => 'Identifier of the category, the permission should be displayed in', |
137 | * ), |
138 | * Example: |
139 | * 'u_viewprofile' => array( |
140 | * 'lang' => 'ACL_U_VIEWPROFILE', |
141 | * 'cat' => 'profile', |
142 | * ), |
143 | * |
144 | * @return array |
145 | */ |
146 | public function get_permissions() |
147 | { |
148 | return $this->permissions; |
149 | } |
150 | |
151 | /** |
152 | * Returns the category of a permission |
153 | * |
154 | * @param string $permission Identifier of the permission |
155 | * @return string Returns the category identifier of the permission |
156 | */ |
157 | public function get_permission_category($permission) |
158 | { |
159 | return (isset($this->permissions[$permission]['cat'])) ? $this->permissions[$permission]['cat'] : 'misc'; |
160 | } |
161 | |
162 | /** |
163 | * Checks if a category has been defined |
164 | * |
165 | * @param string $category Identifier of the category |
166 | * @return bool True if the category is defined, false otherwise |
167 | */ |
168 | public function category_defined($category) |
169 | { |
170 | return isset($this->categories[$category]); |
171 | } |
172 | |
173 | /** |
174 | * Checks if a permission has been defined |
175 | * |
176 | * @param string $permission Identifier of the permission |
177 | * @return bool True if the permission is defined, false otherwise |
178 | */ |
179 | public function permission_defined($permission) |
180 | { |
181 | return isset($this->permissions[$permission]); |
182 | } |
183 | |
184 | /** |
185 | * Returns the language string of a permission |
186 | * |
187 | * @param string $permission Identifier of the permission |
188 | * @return string Language string |
189 | */ |
190 | public function get_permission_lang($permission) |
191 | { |
192 | return (isset($this->permissions[$permission]['lang'])) ? $this->user->lang($this->permissions[$permission]['lang']) : $this->user->lang('ACL_' . strtoupper($permission)); |
193 | } |
194 | |
195 | protected $types = array( |
196 | 'u_' => 'ACL_TYPE_U_', |
197 | 'a_' => 'ACL_TYPE_A_', |
198 | 'm_' => 'ACL_TYPE_M_', |
199 | 'f_' => 'ACL_TYPE_F_', |
200 | 'global' => array( |
201 | 'm_' => 'ACL_TYPE_GLOBAL_M_', |
202 | ), |
203 | ); |
204 | |
205 | protected $categories = array( |
206 | 'actions' => 'ACL_CAT_ACTIONS', |
207 | 'content' => 'ACL_CAT_CONTENT', |
208 | 'forums' => 'ACL_CAT_FORUMS', |
209 | 'misc' => 'ACL_CAT_MISC', |
210 | 'permissions' => 'ACL_CAT_PERMISSIONS', |
211 | 'pm' => 'ACL_CAT_PM', |
212 | 'polls' => 'ACL_CAT_POLLS', |
213 | 'post' => 'ACL_CAT_POST', |
214 | 'post_actions' => 'ACL_CAT_POST_ACTIONS', |
215 | 'posting' => 'ACL_CAT_POSTING', |
216 | 'profile' => 'ACL_CAT_PROFILE', |
217 | 'settings' => 'ACL_CAT_SETTINGS', |
218 | 'topic_actions' => 'ACL_CAT_TOPIC_ACTIONS', |
219 | 'user_group' => 'ACL_CAT_USER_GROUP', |
220 | ); |
221 | |
222 | protected $permissions = array( |
223 | // User Permissions |
224 | 'u_viewprofile' => array('lang' => 'ACL_U_VIEWPROFILE', 'cat' => 'profile'), |
225 | 'u_chgname' => array('lang' => 'ACL_U_CHGNAME', 'cat' => 'profile'), |
226 | 'u_chgpasswd' => array('lang' => 'ACL_U_CHGPASSWD', 'cat' => 'profile'), |
227 | 'u_chgemail' => array('lang' => 'ACL_U_CHGEMAIL', 'cat' => 'profile'), |
228 | 'u_chgavatar' => array('lang' => 'ACL_U_CHGAVATAR', 'cat' => 'profile'), |
229 | 'u_chggrp' => array('lang' => 'ACL_U_CHGGRP', 'cat' => 'profile'), |
230 | 'u_chgprofileinfo' => array('lang' => 'ACL_U_CHGPROFILEINFO', 'cat' => 'profile'), |
231 | |
232 | 'u_attach' => array('lang' => 'ACL_U_ATTACH', 'cat' => 'post'), |
233 | 'u_download' => array('lang' => 'ACL_U_DOWNLOAD', 'cat' => 'post'), |
234 | 'u_mention' => array('lang' => 'ACL_U_MENTION', 'cat' => 'post'), |
235 | 'u_savedrafts' => array('lang' => 'ACL_U_SAVEDRAFTS', 'cat' => 'post'), |
236 | 'u_chgcensors' => array('lang' => 'ACL_U_CHGCENSORS', 'cat' => 'post'), |
237 | 'u_sig' => array('lang' => 'ACL_U_SIG', 'cat' => 'post'), |
238 | 'u_emoji' => array('lang' => 'ACL_U_EMOJI', 'cat' => 'post'), |
239 | |
240 | 'u_sendpm' => array('lang' => 'ACL_U_SENDPM', 'cat' => 'pm'), |
241 | 'u_masspm' => array('lang' => 'ACL_U_MASSPM', 'cat' => 'pm'), |
242 | 'u_masspm_group'=> array('lang' => 'ACL_U_MASSPM_GROUP', 'cat' => 'pm'), |
243 | 'u_readpm' => array('lang' => 'ACL_U_READPM', 'cat' => 'pm'), |
244 | 'u_pm_edit' => array('lang' => 'ACL_U_PM_EDIT', 'cat' => 'pm'), |
245 | 'u_pm_delete' => array('lang' => 'ACL_U_PM_DELETE', 'cat' => 'pm'), |
246 | 'u_pm_forward' => array('lang' => 'ACL_U_PM_FORWARD', 'cat' => 'pm'), |
247 | 'u_pm_emailpm' => array('lang' => 'ACL_U_PM_EMAILPM', 'cat' => 'pm'), |
248 | 'u_pm_printpm' => array('lang' => 'ACL_U_PM_PRINTPM', 'cat' => 'pm'), |
249 | 'u_pm_attach' => array('lang' => 'ACL_U_PM_ATTACH', 'cat' => 'pm'), |
250 | 'u_pm_download' => array('lang' => 'ACL_U_PM_DOWNLOAD', 'cat' => 'pm'), |
251 | 'u_pm_bbcode' => array('lang' => 'ACL_U_PM_BBCODE', 'cat' => 'pm'), |
252 | 'u_pm_smilies' => array('lang' => 'ACL_U_PM_SMILIES', 'cat' => 'pm'), |
253 | 'u_pm_img' => array('lang' => 'ACL_U_PM_IMG', 'cat' => 'pm'), |
254 | |
255 | 'u_sendemail' => array('lang' => 'ACL_U_SENDEMAIL', 'cat' => 'misc'), |
256 | 'u_sendim' => array('lang' => 'ACL_U_SENDIM', 'cat' => 'misc'), |
257 | 'u_ignoreflood' => array('lang' => 'ACL_U_IGNOREFLOOD', 'cat' => 'misc'), |
258 | 'u_hideonline' => array('lang' => 'ACL_U_HIDEONLINE', 'cat' => 'misc'), |
259 | 'u_viewonline' => array('lang' => 'ACL_U_VIEWONLINE', 'cat' => 'misc'), |
260 | 'u_search' => array('lang' => 'ACL_U_SEARCH', 'cat' => 'misc'), |
261 | |
262 | // Forum Permissions |
263 | 'f_list' => array('lang' => 'ACL_F_LIST', 'cat' => 'actions'), |
264 | 'f_list_topics' => array('lang' => 'ACL_F_LIST_TOPICS', 'cat' => 'actions'), |
265 | 'f_read' => array('lang' => 'ACL_F_READ', 'cat' => 'actions'), |
266 | 'f_search' => array('lang' => 'ACL_F_SEARCH', 'cat' => 'actions'), |
267 | 'f_subscribe' => array('lang' => 'ACL_F_SUBSCRIBE', 'cat' => 'actions'), |
268 | 'f_print' => array('lang' => 'ACL_F_PRINT', 'cat' => 'actions'), |
269 | 'f_email' => array('lang' => 'ACL_F_EMAIL', 'cat' => 'actions'), |
270 | 'f_bump' => array('lang' => 'ACL_F_BUMP', 'cat' => 'actions'), |
271 | 'f_user_lock' => array('lang' => 'ACL_F_USER_LOCK', 'cat' => 'actions'), |
272 | 'f_download' => array('lang' => 'ACL_F_DOWNLOAD', 'cat' => 'actions'), |
273 | 'f_report' => array('lang' => 'ACL_F_REPORT', 'cat' => 'actions'), |
274 | |
275 | 'f_post' => array('lang' => 'ACL_F_POST', 'cat' => 'post'), |
276 | 'f_sticky' => array('lang' => 'ACL_F_STICKY', 'cat' => 'post'), |
277 | 'f_announce' => array('lang' => 'ACL_F_ANNOUNCE', 'cat' => 'post'), |
278 | 'f_announce_global' => array('lang' => 'ACL_F_ANNOUNCE_GLOBAL', 'cat' => 'post'), |
279 | 'f_mention' => array('lang' => 'ACL_F_MENTION', 'cat' => 'post'), |
280 | 'f_reply' => array('lang' => 'ACL_F_REPLY', 'cat' => 'post'), |
281 | 'f_edit' => array('lang' => 'ACL_F_EDIT', 'cat' => 'post'), |
282 | 'f_delete' => array('lang' => 'ACL_F_DELETE', 'cat' => 'post'), |
283 | 'f_softdelete' => array('lang' => 'ACL_F_SOFTDELETE', 'cat' => 'post'), |
284 | 'f_ignoreflood' => array('lang' => 'ACL_F_IGNOREFLOOD', 'cat' => 'post'), |
285 | 'f_postcount' => array('lang' => 'ACL_F_POSTCOUNT', 'cat' => 'post'), |
286 | 'f_noapprove' => array('lang' => 'ACL_F_NOAPPROVE', 'cat' => 'post'), |
287 | |
288 | 'f_attach' => array('lang' => 'ACL_F_ATTACH', 'cat' => 'content'), |
289 | 'f_icons' => array('lang' => 'ACL_F_ICONS', 'cat' => 'content'), |
290 | 'f_bbcode' => array('lang' => 'ACL_F_BBCODE', 'cat' => 'content'), |
291 | 'f_img' => array('lang' => 'ACL_F_IMG', 'cat' => 'content'), |
292 | 'f_sigs' => array('lang' => 'ACL_F_SIGS', 'cat' => 'content'), |
293 | 'f_smilies' => array('lang' => 'ACL_F_SMILIES', 'cat' => 'content'), |
294 | |
295 | 'f_poll' => array('lang' => 'ACL_F_POLL', 'cat' => 'polls'), |
296 | 'f_vote' => array('lang' => 'ACL_F_VOTE', 'cat' => 'polls'), |
297 | 'f_votechg' => array('lang' => 'ACL_F_VOTECHG', 'cat' => 'polls'), |
298 | |
299 | // Moderator Permissions |
300 | 'm_edit' => array('lang' => 'ACL_M_EDIT', 'cat' => 'post_actions'), |
301 | 'm_delete' => array('lang' => 'ACL_M_DELETE', 'cat' => 'post_actions'), |
302 | 'm_approve' => array('lang' => 'ACL_M_APPROVE', 'cat' => 'post_actions'), |
303 | 'm_report' => array('lang' => 'ACL_M_REPORT', 'cat' => 'post_actions'), |
304 | 'm_chgposter' => array('lang' => 'ACL_M_CHGPOSTER', 'cat' => 'post_actions'), |
305 | 'm_info' => array('lang' => 'ACL_M_INFO', 'cat' => 'post_actions'), |
306 | 'm_softdelete' => array('lang' => 'ACL_M_SOFTDELETE', 'cat' => 'post_actions'), |
307 | |
308 | 'm_move' => array('lang' => 'ACL_M_MOVE', 'cat' => 'topic_actions'), |
309 | 'm_lock' => array('lang' => 'ACL_M_LOCK', 'cat' => 'topic_actions'), |
310 | 'm_split' => array('lang' => 'ACL_M_SPLIT', 'cat' => 'topic_actions'), |
311 | 'm_merge' => array('lang' => 'ACL_M_MERGE', 'cat' => 'topic_actions'), |
312 | |
313 | 'm_warn' => array('lang' => 'ACL_M_WARN', 'cat' => 'misc'), |
314 | 'm_pm_report' => array('lang' => 'ACL_M_PM_REPORT', 'cat' => 'misc'), |
315 | 'm_ban' => array('lang' => 'ACL_M_BAN', 'cat' => 'misc'), |
316 | |
317 | // Admin Permissions |
318 | 'a_board' => array('lang' => 'ACL_A_BOARD', 'cat' => 'settings'), |
319 | 'a_server' => array('lang' => 'ACL_A_SERVER', 'cat' => 'settings'), |
320 | 'a_jabber' => array('lang' => 'ACL_A_JABBER', 'cat' => 'settings'), |
321 | 'a_phpinfo' => array('lang' => 'ACL_A_PHPINFO', 'cat' => 'settings'), |
322 | |
323 | 'a_forum' => array('lang' => 'ACL_A_FORUM', 'cat' => 'forums'), |
324 | 'a_forumadd' => array('lang' => 'ACL_A_FORUMADD', 'cat' => 'forums'), |
325 | 'a_forumdel' => array('lang' => 'ACL_A_FORUMDEL', 'cat' => 'forums'), |
326 | 'a_prune' => array('lang' => 'ACL_A_PRUNE', 'cat' => 'forums'), |
327 | |
328 | 'a_icons' => array('lang' => 'ACL_A_ICONS', 'cat' => 'posting'), |
329 | 'a_words' => array('lang' => 'ACL_A_WORDS', 'cat' => 'posting'), |
330 | 'a_bbcode' => array('lang' => 'ACL_A_BBCODE', 'cat' => 'posting'), |
331 | 'a_attach' => array('lang' => 'ACL_A_ATTACH', 'cat' => 'posting'), |
332 | |
333 | 'a_user' => array('lang' => 'ACL_A_USER', 'cat' => 'user_group'), |
334 | 'a_userdel' => array('lang' => 'ACL_A_USERDEL', 'cat' => 'user_group'), |
335 | 'a_group' => array('lang' => 'ACL_A_GROUP', 'cat' => 'user_group'), |
336 | 'a_groupadd' => array('lang' => 'ACL_A_GROUPADD', 'cat' => 'user_group'), |
337 | 'a_groupdel' => array('lang' => 'ACL_A_GROUPDEL', 'cat' => 'user_group'), |
338 | 'a_ranks' => array('lang' => 'ACL_A_RANKS', 'cat' => 'user_group'), |
339 | 'a_profile' => array('lang' => 'ACL_A_PROFILE', 'cat' => 'user_group'), |
340 | 'a_names' => array('lang' => 'ACL_A_NAMES', 'cat' => 'user_group'), |
341 | 'a_ban' => array('lang' => 'ACL_A_BAN', 'cat' => 'user_group'), |
342 | |
343 | 'a_viewauth' => array('lang' => 'ACL_A_VIEWAUTH', 'cat' => 'permissions'), |
344 | 'a_authgroups' => array('lang' => 'ACL_A_AUTHGROUPS', 'cat' => 'permissions'), |
345 | 'a_authusers' => array('lang' => 'ACL_A_AUTHUSERS', 'cat' => 'permissions'), |
346 | 'a_fauth' => array('lang' => 'ACL_A_FAUTH', 'cat' => 'permissions'), |
347 | 'a_mauth' => array('lang' => 'ACL_A_MAUTH', 'cat' => 'permissions'), |
348 | 'a_aauth' => array('lang' => 'ACL_A_AAUTH', 'cat' => 'permissions'), |
349 | 'a_uauth' => array('lang' => 'ACL_A_UAUTH', 'cat' => 'permissions'), |
350 | 'a_roles' => array('lang' => 'ACL_A_ROLES', 'cat' => 'permissions'), |
351 | 'a_switchperm' => array('lang' => 'ACL_A_SWITCHPERM', 'cat' => 'permissions'), |
352 | |
353 | 'a_storage' => array('lang' => 'ACL_A_STORAGE', 'cat' => 'misc'), |
354 | 'a_styles' => array('lang' => 'ACL_A_STYLES', 'cat' => 'misc'), |
355 | 'a_extensions' => array('lang' => 'ACL_A_EXTENSIONS', 'cat' => 'misc'), |
356 | 'a_viewlogs' => array('lang' => 'ACL_A_VIEWLOGS', 'cat' => 'misc'), |
357 | 'a_clearlogs' => array('lang' => 'ACL_A_CLEARLOGS', 'cat' => 'misc'), |
358 | 'a_modules' => array('lang' => 'ACL_A_MODULES', 'cat' => 'misc'), |
359 | 'a_language' => array('lang' => 'ACL_A_LANGUAGE', 'cat' => 'misc'), |
360 | 'a_email' => array('lang' => 'ACL_A_EMAIL', 'cat' => 'misc'), |
361 | 'a_bots' => array('lang' => 'ACL_A_BOTS', 'cat' => 'misc'), |
362 | 'a_reasons' => array('lang' => 'ACL_A_REASONS', 'cat' => 'misc'), |
363 | 'a_backup' => array('lang' => 'ACL_A_BACKUP', 'cat' => 'misc'), |
364 | 'a_search' => array('lang' => 'ACL_A_SEARCH', 'cat' => 'misc'), |
365 | ); |
366 | } |