|
1
|
|
|
<?php namespace XoopsModules\Smartfaq; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Module: SmartFAQ |
|
5
|
|
|
* Author: The SmartFactory <www.smartfactory.ca> |
|
6
|
|
|
* Credits: Mithrandir |
|
7
|
|
|
* Licence: GNU |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
use XoopsModules\Smartfaq; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class PermissionHandler |
|
14
|
|
|
* @package XoopsModules\Smartfaq |
|
15
|
|
|
*/ |
|
16
|
|
|
class PermissionHandler extends \XoopsObjectHandler |
|
17
|
|
|
{ |
|
18
|
|
|
/* |
|
19
|
|
|
* Returns permissions for a certain type |
|
20
|
|
|
* |
|
21
|
|
|
* @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
|
22
|
|
|
* @param int $id id of the item (forum, topic or possibly post) to get permissions for |
|
23
|
|
|
* |
|
24
|
|
|
* @return array |
|
25
|
|
|
*/ |
|
26
|
|
|
/** |
|
27
|
|
|
* @param string $type |
|
28
|
|
|
* @param null $id |
|
29
|
|
|
* @return array |
|
30
|
|
|
*/ |
|
31
|
|
|
public function getPermissions($type = 'category', $id = null) |
|
32
|
|
|
{ |
|
33
|
|
|
global $xoopsUser; |
|
|
|
|
|
|
34
|
|
|
static $permissions; |
|
35
|
|
|
|
|
36
|
|
|
if (!isset($permissions[$type]) || (null !== $id && !isset($permissions[$type][$id]))) { |
|
37
|
|
|
$smartModule = Smartfaq\Utility::getModuleInfo(); |
|
38
|
|
|
//Get group permissions handler |
|
39
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
|
40
|
|
|
//Get user's groups |
|
41
|
|
|
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
42
|
|
|
|
|
43
|
|
|
switch ($type) { |
|
44
|
|
|
case 'category': |
|
45
|
|
|
$gperm_name = 'category_read'; |
|
46
|
|
|
break; |
|
47
|
|
|
|
|
48
|
|
|
case 'item': |
|
49
|
|
|
$gperm_name = 'item_read'; |
|
50
|
|
|
break; |
|
51
|
|
|
|
|
52
|
|
|
case 'moderation': |
|
53
|
|
|
$gperm_name = 'category_moderation'; |
|
54
|
|
|
$groups = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
//Get all allowed item ids in this module and for this user's groups |
|
58
|
|
|
$userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
|
|
|
|
|
59
|
|
|
$permissions[$type] = $userpermissions; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
//Return the permission array |
|
63
|
|
|
return isset($permissions[$type]) ? $permissions[$type] : []; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state