-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.php
More file actions
executable file
·57 lines (47 loc) · 1.69 KB
/
Copy pathhelpers.php
File metadata and controls
executable file
·57 lines (47 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
if (!function_exists('hasPermission')) {
function hasPermission()
{
list($permission, $resource, $resource_id) = call_user_func_array('processPermission', func_get_args());
return Lock::can($permission, $resource, $resource_id);
}
}
if (!function_exists('processPermission')) {
function processPermission()
{
$resource_id = null;
if (func_num_args() === 1) {
// explode the permission
list($permission, $resource) = explode('@', func_get_arg(0));
// check if there is an identifier in there
if (strpos($resource, ':') !== false) {
list($resource, $resource_id) = explode(':', $resource);
}
} elseif (func_num_args() === 3) {
list($permission, $resource, $resource_id) = func_get_args();
} elseif (func_num_args() === 2) {
list($permission, $resource) = func_get_args();
} else {
return [];
}
if ($resource_id !== null) {
$resource_id = (int) $resource_id;
}
return [$permission, $resource, $resource_id];
}
}
if (!function_exists('checkForMentions')) {
function checkForMentions($body)
{
$usernameValidation = config('cms.auth.config.users.username_validator', '\w+');
preg_match_all('/\@('.$usernameValidation.')/', $body, $matches);
return array_get($matches, '1', []);
}
}
if (!function_exists('replaceMentions')) {
function replaceMentions($body)
{
$usernameValidation = config('cms.auth.config.users.username_validator', '\w+');
return preg_replace('/\@('.$usernameValidation.')/', '[\\0](/user/\\1)', $body);
}
}