|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Newbb; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* NewBB, the forum module for XOOPS project |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
9
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
10
|
|
|
* @author Taiwen Jiang (phppp or D.J.) <[email protected]> |
|
11
|
|
|
* @since 4.00 |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
use XoopsModules\Newbb\{ |
|
15
|
|
|
Category |
|
|
|
|
|
|
16
|
|
|
}; |
|
17
|
|
|
|
|
18
|
|
|
//defined("NEWBB_HANDLER_PERMISSION") || require_once __DIR__ .'/permission.php'; |
|
19
|
|
|
//define("NEWBB_HANDLER_PERMISSION_CATEGORY", 1); |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class PermissionCategoryHandler |
|
23
|
|
|
*/ |
|
24
|
|
|
class PermissionCategoryHandler extends PermissionHandler |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @param \XoopsDatabase|null $db |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(\XoopsDatabase $db = null) |
|
30
|
|
|
{ |
|
31
|
|
|
// $this->PermissionHandler($db); |
|
32
|
|
|
parent::__construct($db); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param int $mid |
|
37
|
|
|
* @param int $id |
|
38
|
|
|
* @return array |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getValidItems(int $mid, int $id = 0): array |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$full_items = []; |
|
43
|
|
|
if (empty($mid)) { |
|
44
|
|
|
return $full_items; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$full_items[] = "'category_access'"; |
|
48
|
|
|
|
|
49
|
|
|
return $full_items; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param int $cat_id |
|
54
|
|
|
* @return bool |
|
55
|
|
|
*/ |
|
56
|
|
|
public function deleteByCategory(int $cat_id): bool |
|
57
|
|
|
{ |
|
58
|
|
|
$cat_id = (int)$cat_id; |
|
59
|
|
|
if (empty($cat_id)) { |
|
60
|
|
|
return false; |
|
61
|
|
|
} |
|
62
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
|
63
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm'); |
|
64
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'))); |
|
65
|
|
|
$criteria->add(new \Criteria('gperm_name', 'category_access')); |
|
66
|
|
|
$criteria->add(new \Criteria('gperm_itemid', $cat_id)); |
|
67
|
|
|
|
|
68
|
|
|
return $grouppermHandler->deleteAll($criteria); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param int $category |
|
73
|
|
|
* @param array $groups |
|
74
|
|
|
* @return bool |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setCategoryPermission(int $category, array $groups = []): bool |
|
77
|
|
|
{ |
|
78
|
|
|
if (\is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) { |
|
79
|
|
|
$mid = $GLOBALS['xoopsModule']->getVar('mid'); |
|
80
|
|
|
} else { |
|
81
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
|
82
|
|
|
$moduleHandler = \xoops_getHandler('module'); |
|
83
|
|
|
$newbb = $moduleHandler->getByDirname('newbb'); |
|
84
|
|
|
$mid = $newbb->getVar('mid'); |
|
85
|
|
|
} |
|
86
|
|
|
if (empty($groups)) { |
|
87
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
|
88
|
|
|
$memberHandler = \xoops_getHandler('member'); |
|
89
|
|
|
$glist = $memberHandler->getGroupList(); |
|
90
|
|
|
$groups = \array_keys($glist); |
|
91
|
|
|
} |
|
92
|
|
|
$ids = $this->getGroupIds('category_access', $category, $mid); |
|
93
|
|
|
$ids_add = \array_diff($groups, $ids); |
|
94
|
|
|
$ids_rmv = \array_diff($ids, $groups); |
|
95
|
|
|
foreach ($ids_add as $group) { |
|
96
|
|
|
$this->addRight('category_access', $category, $group, $mid); |
|
97
|
|
|
} |
|
98
|
|
|
foreach ($ids_rmv as $group) { |
|
99
|
|
|
$this->deleteRight('category_access', $category, $group, $mid); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return true; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: