PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/glockops/concrete5
PHP | 84 lines | 70 code | 14 blank | 0 comment | 19 complexity | b2e0fb65b50acf7970a992a4372080d4 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_AddSubpagePagePermissionKey extends PagePermissionKey {
  4. public function canAddExternalLink() {
  5. $u = new User();
  6. if ($u->isSuperUser()) {
  7. return true;
  8. }
  9. $pae = $this->getPermissionAccessObject();
  10. if (!is_object($pae)) {
  11. return array();
  12. }
  13. $accessEntities = $u->getUserAccessEntityObjects();
  14. $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
  15. $list = $this->getAccessListItems(PagePermissionKey::ACCESS_TYPE_ALL, $accessEntities);
  16. $canAddLinks = false;
  17. foreach($list as $l) {
  18. if (!$l->allowExternalLinks()) {
  19. $canAddLinks = false;
  20. } else {
  21. $canAddLinks = true;
  22. }
  23. }
  24. return $canAddLinks;
  25. }
  26. protected function getAllowedPageTypeIDs() {
  27. $u = new User();
  28. $pae = $this->getPermissionAccessObject();
  29. if (!is_object($pae)) {
  30. return array();
  31. }
  32. $accessEntities = $u->getUserAccessEntityObjects();
  33. $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
  34. $list = $this->getAccessListItems(PagePermissionKey::ACCESS_TYPE_ALL, $accessEntities);
  35. $list = PermissionDuration::filterByActive($list);
  36. $db = Loader::db();
  37. $ctIDs = array();
  38. if (count($list) > 0) {
  39. $allCTIDs = $db->GetCol('select ctID from PageTypes where ctIsInternal = 0');
  40. foreach($list as $l) {
  41. if ($l->getPageTypesAllowedPermission() == 'N') {
  42. $ctIDs = array();
  43. }
  44. if ($l->getPageTypesAllowedPermission() == 'C') {
  45. if ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_EXCLUDE) {
  46. $ctIDs = array_values(array_diff($ctIDs, $l->getPageTypesAllowedArray()));
  47. } else {
  48. $ctIDs = array_unique(array_merge($ctIDs, $l->getPageTypesAllowedArray()));
  49. }
  50. }
  51. if ($l->getPageTypesAllowedPermission() == 'A') {
  52. $ctIDs = $allCTIDs;
  53. }
  54. }
  55. }
  56. return $ctIDs;
  57. }
  58. public function validate($ct = false) {
  59. $u = new User();
  60. if ($u->isSuperUser()) {
  61. return true;
  62. }
  63. $types = $this->getAllowedPageTypeIDs();
  64. if ($ct != false) {
  65. return in_array($ct->getCollectionTypeID(), $types);
  66. } else {
  67. return count($types) > 0;
  68. }
  69. }
  70. }