PageRenderTime 58ms CodeModel.GetById 50ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

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

https://github.com/glockops/concrete5
PHP | 50 lines | 40 code | 10 blank | 0 comment | 11 complexity | 979b77ae47925a305c41e582f14b0cca MD5 | raw file
 1<?
 2defined('C5_EXECUTE') or die("Access Denied.");
 3
 4class Concrete5_Model_AddFileFileSetPermissionKey extends FileSetPermissionKey  {
 5
 6	public function getAllowedFileExtensions() {
 7		$u = new User();
 8
 9		$extensions = array();
10		if ($u->isSuperUser()) {
11			$extensions = Loader::helper('concrete/file')->getAllowedFileExtensions();
12			return $extensions;
13		}
14
15		$pae = $this->getPermissionAccessObject();
16		if (!is_object($pae)) {
17			return array();
18		}
19	
20		$accessEntities = $u->getUserAccessEntityObjects();
21		$accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
22		$list = $this->getAccessListItems(FileSetPermissionKey::ACCESS_TYPE_ALL, $accessEntities);
23		$list = PermissionDuration::filterByActive($list);
24
25		foreach($list as $l) {
26			if ($l->getFileTypesAllowedPermission() == 'N') {
27				$extensions = array();
28			}
29			if ($l->getFileTypesAllowedPermission() == 'C') {
30				$extensions = array_unique(array_merge($extensions, $l->getFileTypesAllowedArray()));
31			}
32			if ($l->getFileTypesAllowedPermission() == 'A') {
33				$extensions = Loader::helper('concrete/file')->getAllowedFileExtensions();
34			}
35		}
36		
37		return $extensions;
38	}
39	
40	public function validate($extension = false) {
41		$extensions = $this->getAllowedFileExtensions();
42		if ($ext != false) {
43			return in_array($extension, $extensions);
44		} else {
45			return count($extensions) > 0;
46		}
47	}
48	
49
50}