PageRenderTime 47ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/web/concrete/core/models/permission/keys/custom/add_block.php

https://github.com/glockops/concrete5
PHP | 62 lines | 53 code | 9 blank | 0 comment | 17 complexity | 1585c2ee65d960a927495709a41566b2 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, BSD-3-Clause
  1. <?
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. class Concrete5_Model_AddBlockBlockTypePermissionKey extends BlockTypePermissionKey {
  4. protected function getAllowedBlockTypeIDs() {
  5. $u = new User();
  6. $pae = $this->getPermissionAccessObject();
  7. if (!is_object($pae)) {
  8. return array();
  9. }
  10. $accessEntities = $u->getUserAccessEntityObjects();
  11. $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
  12. $list = $this->getAccessListItems(PermissionKey::ACCESS_TYPE_ALL, $accessEntities);
  13. $list = PermissionDuration::filterByActive($list);
  14. $db = Loader::db();
  15. $btIDs = array();
  16. if (count($list) > 0) {
  17. $dsh = Loader::helper('concrete/dashboard');
  18. if ($dsh->inDashboard()) {
  19. $allBTIDs = $db->GetCol('select btID from BlockTypes');
  20. } else {
  21. $allBTIDs = $db->GetCol('select btID from BlockTypes where btIsInternal = 0');
  22. }
  23. foreach($list as $l) {
  24. if ($l->getBlockTypesAllowedPermission() == 'N') {
  25. $btIDs = array();
  26. }
  27. if ($l->getBlockTypesAllowedPermission() == 'C') {
  28. if ($l->getAccessType() == PermissionKey::ACCESS_TYPE_EXCLUDE) {
  29. $btIDs = array_values(array_diff($btIDs, $l->getBlockTypesAllowedArray()));
  30. } else {
  31. $btIDs = array_unique(array_merge($btIDs, $l->getBlockTypesAllowedArray()));
  32. }
  33. }
  34. if ($l->getBlockTypesAllowedPermission() == 'A') {
  35. $btIDs = $allBTIDs;
  36. }
  37. }
  38. }
  39. return $btIDs;
  40. }
  41. public function validate($bt = false) {
  42. $u = new User();
  43. if ($u->isSuperUser()) {
  44. return true;
  45. }
  46. $types = $this->getAllowedBlockTypeIDs();
  47. if ($bt != false) {
  48. return in_array($bt->getBlockTypeID(), $types);
  49. } else {
  50. return count($types) > 0;
  51. }
  52. }
  53. }