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

Language PHP Lines 85
MD5 Hash b2e0fb65b50acf7970a992a4372080d4 Estimated Cost $5,642 (why?)
Repository https://github.com/glockops/concrete5.git View Raw File
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?
defined('C5_EXECUTE') or die("Access Denied.");

class Concrete5_Model_AddSubpagePagePermissionKey extends PagePermissionKey  {
	
	public function canAddExternalLink() {
		$u = new User();
		if ($u->isSuperUser()) {
			return true;
		}
		
		$pae = $this->getPermissionAccessObject();
		if (!is_object($pae)) {
			return array();
		}
		
		$accessEntities = $u->getUserAccessEntityObjects();
		$accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
		$list = $this->getAccessListItems(PagePermissionKey::ACCESS_TYPE_ALL, $accessEntities);
		$canAddLinks = false;
		foreach($list as $l) {
			if (!$l->allowExternalLinks()) {
				$canAddLinks = false;
			} else {
				$canAddLinks = true;
			}
		}
		return $canAddLinks;
	}
	
	protected function getAllowedPageTypeIDs() {

		$u = new User();
		$pae = $this->getPermissionAccessObject();
		if (!is_object($pae)) {
			return array();
		}
		
		$accessEntities = $u->getUserAccessEntityObjects();
		$accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
		$list = $this->getAccessListItems(PagePermissionKey::ACCESS_TYPE_ALL, $accessEntities);
		$list = PermissionDuration::filterByActive($list);
		
		$db = Loader::db();
		$ctIDs = array();
		if (count($list) > 0) {
			$allCTIDs = $db->GetCol('select ctID from PageTypes where ctIsInternal = 0');
			foreach($list as $l) {
				if ($l->getPageTypesAllowedPermission() == 'N') {
					$ctIDs = array();
				}
				if ($l->getPageTypesAllowedPermission() == 'C') {
					if ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_EXCLUDE) {
						$ctIDs = array_values(array_diff($ctIDs, $l->getPageTypesAllowedArray()));
					} else { 
						$ctIDs = array_unique(array_merge($ctIDs, $l->getPageTypesAllowedArray()));
					}
				}
				if ($l->getPageTypesAllowedPermission() == 'A') {
					$ctIDs = $allCTIDs;
				}
			}
		}
				
		return $ctIDs;
	}
	
	public function validate($ct = false) {
		$u = new User();
		if ($u->isSuperUser()) {
			return true;
		}

		$types = $this->getAllowedPageTypeIDs();
		if ($ct != false) {
			return in_array($ct->getCollectionTypeID(), $types);
		} else {
			return count($types) > 0;
		}
	}
	

	
}
Back to Top