Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php defined('_JEXEC') or die ;
- class TestHelper
- {
- protected static $actions = null;
- public static function authorise($action, $asset = 'com_test')
- {
- // We should cache this
- if(is_null(self::$actions)){
- self::$actions = JAccess::getActionsFromFile(JPATH_COMPONENT_ADMINISTRATOR.'/access.xml');
- }
- $user = JFactory::getUser();
- $result = $user->authorize($action, $asset);
- $actionObj = null;
- // Check if we inherit from something
- if(is_null($result)) {
- $filter = array_filter(self::$actions,
- function ($var) use ($action) {
- return ($var->name == $action);
- }
- );
- $actionObj = array_shift($filter);
- }
- // Now loop down the hierarchy to see if we have a match somewhere
- while(is_null($result) && $actionObj->inherit != '') {
- $action = $actionObj->inherit;
- $filter = array_filter(self::$actions,
- function ($var) use ($action) {
- return ($var->name == $action);
- }
- );
- $actionObj = array_shift($filter);
- $result = $user->authorize($action, $asset);
- }
- return $result;
- }
- }
Add Comment
Please, Sign In to add comment