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