Guest User

Untitled

a guest
Oct 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. <?php defined('_JEXEC') or die ;
  2.  
  3. class TestHelper
  4. {
  5. protected static $actions = null;
  6.  
  7. public static function authorise($action, $asset = 'com_test')
  8. {
  9. // We should cache this
  10. if(is_null(self::$actions)){
  11. self::$actions = JAccess::getActionsFromFile(JPATH_COMPONENT_ADMINISTRATOR.'/access.xml');
  12. }
  13.  
  14. $user = JFactory::getUser();
  15. $result = $user->authorize($action, $asset);
  16. $actionObj = null;
  17.  
  18. // Check if we inherit from something
  19. if(is_null($result)) {
  20. $filter = array_filter(self::$actions,
  21. function ($var) use ($action) {
  22. return ($var->name == $action);
  23. }
  24. );
  25. $actionObj = array_shift($filter);
  26. }
  27.  
  28. // Now loop down the hierarchy to see if we have a match somewhere
  29. while(is_null($result) && $actionObj->inherit != '') {
  30. $action = $actionObj->inherit;
  31. $filter = array_filter(self::$actions,
  32. function ($var) use ($action) {
  33. return ($var->name == $action);
  34. }
  35. );
  36. $actionObj = array_shift($filter);
  37. $result = $user->authorize($action, $asset);
  38. }
  39.  
  40. return $result;
  41. }
  42. }
Add Comment
Please, Sign In to add comment