mambax7 /
newbb5
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace XoopsModules\Newbb; |
||||
| 4 | |||||
| 5 | /** |
||||
| 6 | * NewBB 5.0x, the forum module for XOOPS project |
||||
| 7 | * |
||||
| 8 | * @copyright XOOPS Project (https://xoops.org) |
||||
| 9 | * @license GNU GPL 2 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 | * @package module::newbb |
||||
| 13 | */ |
||||
| 14 | |||||
| 15 | use XoopsModules\Newbb; |
||||
| 16 | |||||
| 17 | /** |
||||
| 18 | * Class CategoryHandler |
||||
| 19 | */ |
||||
| 20 | class CategoryHandler extends \XoopsPersistableObjectHandler |
||||
| 21 | { |
||||
| 22 | /** |
||||
| 23 | * @param null|\XoopsDatabase $db |
||||
| 24 | */ |
||||
| 25 | public function __construct(\XoopsDatabase $db = null) |
||||
| 26 | { |
||||
| 27 | parent::__construct($db, 'newbb_categories', Category::class, 'cat_id', 'cat_title'); |
||||
| 28 | } |
||||
| 29 | |||||
| 30 | /** |
||||
| 31 | * @param string $perm |
||||
| 32 | * @return mixed |
||||
| 33 | */ |
||||
| 34 | public function getIdsByPermission($perm = 'access') |
||||
| 35 | { |
||||
| 36 | /** var Newbb\PermissionHandler $permHandler */ |
||||
| 37 | $permHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Permission'); |
||||
| 38 | |||||
| 39 | return $permHandler->getCategories($perm); |
||||
| 40 | } |
||||
| 41 | |||||
| 42 | /** |
||||
| 43 | * @param string $permission |
||||
| 44 | * @param null $tags |
||||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||||
| 45 | * @param bool $asObject |
||||
| 46 | * @return array |
||||
| 47 | */ |
||||
| 48 | public function &getByPermission($permission = 'access', $tags = null, $asObject = true) |
||||
| 49 | { |
||||
| 50 | $categories = []; |
||||
| 51 | if (!$valid_ids = $this->getIdsByPermission($permission)) { |
||||
| 52 | return $categories; |
||||
| 53 | } |
||||
| 54 | $criteria = new \Criteria('cat_id', '(' . \implode(', ', $valid_ids) . ')', 'IN'); |
||||
| 55 | $criteria->setSort('cat_order'); |
||||
| 56 | $categories = $this->getAll($criteria, $tags, $asObject); |
||||
| 57 | |||||
| 58 | return $categories; |
||||
| 59 | } |
||||
| 60 | |||||
| 61 | /** |
||||
| 62 | * @param \XoopsObject $category |
||||
| 63 | * @param bool $force |
||||
| 64 | * @return mixed |
||||
| 65 | */ |
||||
| 66 | public function insert(\XoopsObject $category, $force = true) |
||||
| 67 | { |
||||
| 68 | $className = Category::class; |
||||
| 69 | if (!($category instanceof $className)) { |
||||
| 70 | return false; |
||||
| 71 | } |
||||
| 72 | parent::insert($category, $force); |
||||
| 73 | if ($category->isNew()) { |
||||
| 74 | $this->applyPermissionTemplate($category); |
||||
| 75 | } |
||||
| 76 | |||||
| 77 | return $category->getVar('cat_id'); |
||||
| 78 | } |
||||
| 79 | |||||
| 80 | /** |
||||
| 81 | * @param \XoopsObject $category |
||||
| 82 | * @param bool $force |
||||
| 83 | * @return bool|mixed |
||||
| 84 | * @internal param Category $category |
||||
| 85 | */ |
||||
| 86 | public function delete(\XoopsObject $category, $force = false)//delete(Category $category) |
||||
| 87 | { |
||||
| 88 | $className = Category::class; |
||||
| 89 | if (!($category instanceof $className)) { |
||||
| 90 | return false; |
||||
| 91 | } |
||||
| 92 | /** @var Newbb\ForumHandler $forumHandler */ |
||||
| 93 | $forumHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Forum'); |
||||
| 94 | $forumHandler->deleteAll(new \Criteria('cat_id', $category->getVar('cat_id')), true, true); |
||||
|
0 ignored issues
–
show
It seems like
$category->getVar('cat_id') can also be of type array and array; however, parameter $value of Criteria::__construct() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 95 | $result = parent::delete($category); |
||||
| 96 | if ($result) { |
||||
| 97 | // Delete group permissions |
||||
| 98 | return $this->deletePermission($category); |
||||
| 99 | } |
||||
| 100 | $category->setErrors('delete category error'); |
||||
| 101 | |||||
| 102 | return false; |
||||
| 103 | } |
||||
| 104 | |||||
| 105 | /** |
||||
| 106 | * Check permission for a category |
||||
| 107 | * |
||||
| 108 | * @param Category|int $category object or id |
||||
| 109 | * @param string $perm permission name |
||||
| 110 | * |
||||
| 111 | * @return bool |
||||
| 112 | */ |
||||
| 113 | public function getPermission($category, $perm = 'access') |
||||
| 114 | { |
||||
| 115 | if ($GLOBALS['xoopsUserIsAdmin'] && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) { |
||||
| 116 | return true; |
||||
| 117 | } |
||||
| 118 | |||||
| 119 | $cat_id = \is_object($category) ? $category->getVar('cat_id') : (int)$category; |
||||
| 120 | /** @var PermissionHandler $permHandler */ |
||||
| 121 | $permHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Permission'); |
||||
| 122 | |||||
| 123 | return $permHandler->getPermission('category', $perm, $cat_id); |
||||
| 124 | } |
||||
| 125 | |||||
| 126 | /** |
||||
| 127 | * @param Category $category |
||||
| 128 | * @return mixed |
||||
| 129 | */ |
||||
| 130 | public function deletePermission(Category $category) |
||||
| 131 | { |
||||
| 132 | /** @var PermissionHandler $permHandler */ |
||||
| 133 | $permHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Permission'); |
||||
| 134 | |||||
| 135 | return $permHandler->deleteByCategory($category->getVar('cat_id')); |
||||
| 136 | } |
||||
| 137 | |||||
| 138 | /** |
||||
| 139 | * @param Category $category |
||||
| 140 | * @return mixed |
||||
| 141 | */ |
||||
| 142 | public function applyPermissionTemplate(Category $category) |
||||
| 143 | { |
||||
| 144 | /** @var PermissionHandler $permHandler */ |
||||
| 145 | $permHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Permission'); |
||||
| 146 | |||||
| 147 | return $permHandler->setCategoryPermission($category->getVar('cat_id')); |
||||
| 148 | } |
||||
| 149 | |||||
| 150 | /** |
||||
| 151 | * @param mixed $object |
||||
| 152 | * @return bool |
||||
| 153 | */ |
||||
| 154 | public function synchronization($object = null) |
||||
|
0 ignored issues
–
show
The parameter
$object is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 155 | { |
||||
| 156 | return true; |
||||
| 157 | } |
||||
| 158 | } |
||||
| 159 |