ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilWebDAVObjDAVHelper.php
Go to the documentation of this file.
1<?php
2
13{
15 protected $repo_helper;
16
23 {
24 $this->repo_helper = $repo_helper;
25 }
26
34 public function isDAVableObject($id, $is_reference = true, bool $do_name_check = true)
35 {
36 $obj_id = $is_reference ? $this->repo_helper->getObjectIdFromRefId($id) : $id;
37
38 $type = $this->repo_helper->getObjectTypeFromObjId($obj_id);
39 $title = $this->repo_helper->getObjectTitleFromObjId($obj_id);
40
41 if($do_name_check) {
42 $is_davable = $this->isDAVableObjType($type) && $this->isDAVableObjTitle($title);
43 } else {
44 $is_davable = $this->isDAVableObjType($type);
45 }
46
47 return $is_davable;
48 }
49
56 public function isDAVableObjType(string $type) : bool
57 {
58 switch ($type) {
59 case 'cat':
60 case 'crs':
61 case 'grp':
62 case 'fold':
63 case 'file':
64 return true;
65
66 default:
67 return false;
68 }
69 }
70
76 public function isDAVableObjTitle(string $title) : bool
77 {
78 if ($this->hasTitleForbiddenChars($title)) {
79 return false;
80 }
81 if ($this->hasInvalidPrefixInTitle($title)) {
82 return false;
83 }
84 return true;
85 }
86
93 public function hasTitleForbiddenChars(string $title) : bool
94 {
95 foreach (str_split('\\<>/:*?"|#') as $forbidden_character) {
96 if (strpos($title, $forbidden_character) !== false) {
97 return true;
98 }
99 }
100
101 return false;
102 }
103
111 public function hasInvalidPrefixInTitle(string $title)
112 {
113 $prefix = substr($title, 0, 1);
114 return $prefix === '.';
115 }
116
124 public function createDAVObjectForRefId(int $ref_id, string $type = '') : ilObjectDAV
125 {
126 if ($type == '') {
127 $type = $this->repo_helper->getObjectTypeFromRefId($ref_id);
128 }
129
130 if ($this->repo_helper->objectWithRefIdExists($ref_id)) {
131 switch ($type) {
132 case 'cat':
133 return new ilObjCategoryDAV(new ilObjCategory($ref_id, true), $this->repo_helper, $this);
134
135 case 'crs':
136 return new ilObjCourseDAV(new ilObjCourse($ref_id, true), $this->repo_helper, $this);
137
138 case 'grp':
139 return new ilObjGroupDAV(new ilObjGroup($ref_id, true), $this->repo_helper, $this);
140
141 case 'fold':
142 return new ilObjFolderDAV(new ilObjFolder($ref_id, true), $this->repo_helper, $this);
143
144 case 'file':
145 return new ilObjFileDAV(new ilObjFile($ref_id, true), $this->repo_helper, $this);
146 }
147 }
148 throw new BadRequest('Unknown filetype');
149 }
150
151
157 public function isValidFileNameWithValidFileExtension(string $a_title) : bool
158 {
159 return $a_title == ilFileUtils::getValidFilename($a_title) && $this->isDAVableObjTitle($a_title);
160 }
161}
An exception for terminatinating execution or to throw for unit testing.
static getValidFilename($a_filename)
Get valid filename.
Class ilObjCategoryDAV.
Class ilObjCategory.
Class ilObjCourseDAV.
Class ilObjCourse.
Class ilObjFileDAV.
Class ilObjFile.
Class ilObjFolderDAV.
Class ilObjFolder.
Class ilObjGroupDAV.
Class ilObjGroup.
Class ilObjectDAV.
Class ilWebDAVObjDAVHelper.
isValidFileNameWithValidFileExtension(string $a_title)
createDAVObjectForRefId(int $ref_id, string $type='')
Creates a DAV Object for the given ref id.
__construct(ilWebDAVRepositoryHelper $repo_helper)
ilWebDAVObjDAVHelper constructor.
isDAVableObject($id, $is_reference=true, bool $do_name_check=true)
Check if given object (either obj_id or ref_id) is compatible to be represented as a WebDAV object.
hasTitleForbiddenChars(string $title)
Check for forbidden chars in title that are making trouble if displayed in WebDAV.
isDAVableObjTitle(string $title)
Check if title is displayable in WebDAV.
isDAVableObjType(string $type)
Check if the given object type is compatible to be represented as a WebDAV object.
hasInvalidPrefixInTitle(string $title)
Forbidden are titles that begin with a single dot.
Class ilWebDAVRepositoryHelper.
$type