|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Extgallery; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* ExtGallery Class Manager |
|
7
|
|
|
* |
|
8
|
|
|
* You may not change or alter any portion of this comment or credits |
|
9
|
|
|
* of supporting developers from this source code or any supporting source code |
|
10
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
16
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
17
|
|
|
* @author Zoullou (http://www.zoullou.net) |
|
18
|
|
|
* @package ExtGallery |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
use XoopsModules\Extgallery; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class Extgallery\PublicPermHandler |
|
25
|
|
|
*/ |
|
26
|
|
|
class PublicPermHandler |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @return Extgallery\PublicPermHandler |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function getInstance() |
|
32
|
|
|
{ |
|
33
|
|
|
static $instance; |
|
34
|
|
|
if (null === $instance) { |
|
35
|
|
|
$instance = new static(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
return $instance; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param $user |
|
43
|
|
|
* |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getUserGroup($user) |
|
47
|
|
|
{ |
|
48
|
|
|
if ($user instanceof \XoopsUser) { |
|
49
|
|
|
return $user->getGroups(); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return XOOPS_GROUP_ANONYMOUS; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param string|\XoopsUser $user |
|
57
|
|
|
* @param $perm |
|
58
|
|
|
* |
|
59
|
|
|
* @return mixed |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getAuthorizedPublicCat($user, $perm) |
|
62
|
|
|
{ |
|
63
|
|
|
static $authorizedCat; |
|
64
|
|
|
$userId = $user ? $user->getVar('uid') : 0; |
|
65
|
|
|
if (!isset($authorizedCat[$perm][$userId])) { |
|
66
|
|
|
/** @var \XoopsGroupPermHandler $groupPermHandler */ |
|
67
|
|
|
$groupPermHandler = \xoops_getHandler('groupperm'); |
|
68
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
|
69
|
|
|
$moduleHandler = \xoops_getHandler('module'); |
|
70
|
|
|
$module = $moduleHandler->getByDirname('extgallery'); |
|
71
|
|
|
$authorizedCat[$perm][$userId] = $groupPermHandler->getItemIds($perm, $this->getUserGroup($user), $module->getVar('mid')); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $authorizedCat[$perm][$userId]; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param string|\XoopsUser $user |
|
79
|
|
|
* @param $perm |
|
80
|
|
|
* @param $catId |
|
81
|
|
|
* |
|
82
|
|
|
* @return bool |
|
83
|
|
|
*/ |
|
84
|
|
|
public function isAllowed($user, $perm, $catId) |
|
85
|
|
|
{ |
|
86
|
|
|
$autorizedCat = $this->getAuthorizedPublicCat($user, $perm); |
|
87
|
|
|
|
|
88
|
|
|
return \in_array($catId, $autorizedCat); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|