PageRenderTime 16ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms 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
 1<?
 2defined('C5_EXECUTE') or die("Access Denied.");
 3
 4class Concrete5_Model_AddSubpagePagePermissionKey extends PagePermissionKey  {
 5	
 6	public function canAddExternalLink() {
 7		$u = new User();
 8		if ($u->isSuperUser()) {
 9			return true;
10		}
11		
12		$pae = $this->getPermissionAccessObject();
13		if (!is_object($pae)) {
14			return array();
15		}
16		
17		$accessEntities = $u->getUserAccessEntityObjects();
18		$accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
19		$list = $this->getAccessListItems(PagePermissionKey::ACCESS_TYPE_ALL, $accessEntities);
20		$canAddLinks = false;
21		foreach($list as $l) {
22			if (!$l->allowExternalLinks()) {
23				$canAddLinks = false;
24			} else {
25				$canAddLinks = true;
26			}
27		}
28		return $canAddLinks;
29	}
30	
31	protected function getAllowedPageTypeIDs() {
32
33		$u = new User();
34		$pae = $this->getPermissionAccessObject();
35		if (!is_object($pae)) {
36			return array();
37		}
38		
39		$accessEntities = $u->getUserAccessEntityObjects();
40		$accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
41		$list = $this->getAccessListItems(PagePermissionKey::ACCESS_TYPE_ALL, $accessEntities);
42		$list = PermissionDuration::filterByActive($list);
43		
44		$db = Loader::db();
45		$ctIDs = array();
46		if (count($list) > 0) {
47			$allCTIDs = $db->GetCol('select ctID from PageTypes where ctIsInternal = 0');
48			foreach($list as $l) {
49				if ($l->getPageTypesAllowedPermission() == 'N') {
50					$ctIDs = array();
51				}
52				if ($l->getPageTypesAllowedPermission() == 'C') {
53					if ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_EXCLUDE) {
54						$ctIDs = array_values(array_diff($ctIDs, $l->getPageTypesAllowedArray()));
55					} else { 
56						$ctIDs = array_unique(array_merge($ctIDs, $l->getPageTypesAllowedArray()));
57					}
58				}
59				if ($l->getPageTypesAllowedPermission() == 'A') {
60					$ctIDs = $allCTIDs;
61				}
62			}
63		}
64				
65		return $ctIDs;
66	}
67	
68	public function validate($ct = false) {
69		$u = new User();
70		if ($u->isSuperUser()) {
71			return true;
72		}
73
74		$types = $this->getAllowedPageTypeIDs();
75		if ($ct != false) {
76			return in_array($ct->getCollectionTypeID(), $types);
77		} else {
78			return count($types) > 0;
79		}
80	}
81	
82
83	
84}