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.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* |
||
3 | You may not change or alter any portion of this comment or credits |
||
4 | of supporting developers from this source code or any supporting source code |
||
5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
6 | |||
7 | This program is distributed in the hope that it will be useful, |
||
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
10 | */ |
||
11 | |||
12 | use Xoops\Core\Kernel\XoopsObjectHandler; |
||
13 | use Xoops\Core\Kernel\Criteria; |
||
14 | use Xoops\Core\Kernel\CriteriaCompo; |
||
15 | |||
16 | /** |
||
17 | * Alumni class |
||
18 | * |
||
19 | * @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ |
||
20 | * @license GNU GPL V2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
||
21 | * @package Class |
||
22 | * @subpackage Handlers |
||
23 | * @since 1.0 |
||
24 | * @author trabis <[email protected]> |
||
25 | * @author The SmartFactory <www.smartfactory.ca> |
||
26 | * @version $Id$ |
||
27 | */ |
||
28 | |||
29 | include_once dirname(__DIR__) . '/include/common.php'; |
||
30 | |||
31 | /** |
||
32 | * Class AlumniPermissionHandler |
||
33 | */ |
||
34 | class AlumniPermissionHandler extends XoopsObjectHandler |
||
35 | { |
||
36 | /** |
||
37 | * @var Alumni |
||
38 | * @access public |
||
39 | */ |
||
40 | public $alumni = null; |
||
41 | |||
42 | /** |
||
43 | * constructor |
||
44 | */ |
||
45 | public function __construct() |
||
46 | { |
||
47 | $this->alumni = Alumni::getInstance(); |
||
48 | $this->db2 = \Xoops::getInstance()->db(); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Returns permissions for a certain type |
||
53 | * |
||
54 | * @param string $gperm_name "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
||
55 | * @param int $id id of the item (forum, topic or possibly post) to get permissions for |
||
56 | * |
||
57 | * @return array |
||
58 | */ |
||
59 | public function getGrantedGroupsById($gperm_name, $id) |
||
60 | { |
||
61 | static $items; |
||
62 | if (isset($items[$gperm_name][$id])) { |
||
63 | return $items[$gperm_name][$id]; |
||
64 | } |
||
65 | $groups = []; |
||
66 | $criteria = new CriteriaCompo(); |
||
67 | $criteria->add(new Criteria('gperm_modid', $this->alumni->getModule()->getVar('mid'))); |
||
68 | $criteria->add(new Criteria('gperm_name', $gperm_name)); |
||
69 | $criteria->add(new Criteria('gperm_itemid', $id)); |
||
70 | //Instead of calling groupperm handler and get objects, we will save some memory and do it our way |
||
71 | $qb = $this->db2->createXoopsQueryBuilder(); |
||
0 ignored issues
–
show
|
|||
72 | $qb->select('gperm_groupid')->fromPrefix('group_permission', ''); |
||
73 | $criteria->renderQb($qb); |
||
74 | $result = $qb->execute(); |
||
75 | |||
76 | while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) { |
||
77 | $groups[$myrow['gperm_groupid']] = $myrow['gperm_groupid']; |
||
78 | } |
||
79 | $items[$gperm_name][$id] = $groups; |
||
80 | return $groups; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Returns permissions for a certain type |
||
85 | * |
||
86 | * @param string $gperm_name "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | public function getGrantedItems($gperm_name) |
||
91 | { |
||
92 | static $items; |
||
93 | if (isset($items[$gperm_name])) { |
||
94 | return $items[$gperm_name]; |
||
95 | } |
||
96 | $ret = []; |
||
97 | //Instead of calling groupperm handler and get objects, we will save some memory and do it our way |
||
98 | $criteria = new CriteriaCompo(new Criteria('gperm_name', $gperm_name)); |
||
99 | $criteria->add(new Criteria('gperm_modid', $this->alumni->getModule()->getVar('mid'))); |
||
100 | |||
101 | //Get user's groups |
||
102 | $groups = \Xoops::getInstance()->getUserGroups(); |
||
103 | $criteria2 = new CriteriaCompo(); |
||
104 | foreach ($groups as $gid) { |
||
105 | $criteria2->add(new Criteria('gperm_groupid', $gid), 'OR'); |
||
106 | } |
||
107 | $criteria->add($criteria2); |
||
108 | |||
109 | $qb = $this->db2->createXoopsQueryBuilder(); |
||
0 ignored issues
–
show
|
|||
110 | $qb->select('gperm_itemid')->fromPrefix('group_permission', ''); |
||
111 | $criteria->renderQb($qb); |
||
112 | $result = $qb->execute(); |
||
113 | |||
114 | while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) { |
||
115 | $ret[$myrow['gperm_itemid']] = $myrow['gperm_itemid']; |
||
116 | } |
||
117 | $items[$gperm_name] = $ret; |
||
118 | return $ret; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * isGranted |
||
123 | * |
||
124 | * @param string $gperm_name permission name |
||
125 | * @param int $id item id |
||
126 | * |
||
127 | * @return bool |
||
128 | */ |
||
129 | public function isGranted($gperm_name, $id) |
||
130 | { |
||
131 | if (!$id) { |
||
132 | return false; |
||
133 | } |
||
134 | $permissions = $this->getGrantedItems($gperm_name); |
||
135 | if (!empty($permissions) && isset($permissions[$id])) { |
||
136 | return true; |
||
137 | } else { |
||
138 | return false; |
||
139 | } |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Saves permissions for the selected category |
||
144 | * saveCategory_Permissions() |
||
145 | * |
||
146 | * @param array $groups group with granted permission |
||
147 | * @param integer $itemid itemid on which we are setting permissions for Categories and Forums |
||
148 | * @param string $perm_name name of the permission |
||
149 | * |
||
150 | * @return boolean : TRUE if the no errors occured |
||
151 | * |
||
152 | * @todo is this used anywhere? |
||
153 | */ |
||
154 | public function saveItemPermissions($groups, $itemid, $perm_name) |
||
155 | { |
||
156 | $xoops = Xoops::getInstance(); |
||
157 | $result = true; |
||
158 | $module_id = $this->alumni->getModule()->getVar('mid'); |
||
159 | $gperm_handler = $xoops->getHandlerGroupPermission(); |
||
160 | // First, if the permissions are already there, delete them |
||
161 | $gperm_handler->deleteByModule($module_id, $perm_name, $itemid); |
||
162 | // Save the new permissions |
||
163 | if (count($groups) > 0) { |
||
164 | foreach ($groups as $group_id) { |
||
165 | echo $group_id . '-'; |
||
166 | echo $gperm_handler->addRight($perm_name, $itemid, $group_id, $module_id); |
||
167 | } |
||
168 | } |
||
169 | return $result; |
||
170 | } |
||
171 | |||
172 | /** |
||
173 | * Delete all permission for a specific item |
||
174 | * deletePermissions() |
||
175 | * |
||
176 | * @param integer $itemid id of the item for which to delete the permissions |
||
177 | * @param string $gperm_name permission name |
||
178 | * |
||
179 | * @return boolean : TRUE if the no errors occured |
||
180 | */ |
||
181 | public function deletePermissions($itemid, $gperm_name) |
||
182 | { |
||
183 | $xoops = Xoops::getInstance(); |
||
184 | $result = true; |
||
185 | $gperm_handler = $xoops->getHandlerGroupPermission(); |
||
186 | $gperm_handler->deleteByModule($this->alumni->getModule()->getVar('mid'), $gperm_name, $itemid); |
||
187 | return $result; |
||
188 | } |
||
189 | } |
||
190 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.