ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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, $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 return ($this->hasTitleForbiddenChars($title) === false)
79 && ($this->hasInvalidPrefixInTitle($title) === false);
80 }
81
88 public function hasTitleForbiddenChars(string $title) : bool
89 {
90 foreach (str_split('\\<>/:*?"|#') as $forbidden_character) {
91 if (strpos($title, $forbidden_character) !== false) {
92 return true;
93 }
94 }
95
96 return false;
97 }
98
106 public function hasInvalidPrefixInTitle(string $title)
107 {
108 $prefix = substr($title, 0, 1);
109 return $prefix === '.';
110 }
111
119 public function createDAVObjectForRefId(int $ref_id, string $type = '') : ilObjectDAV
120 {
121 if ($type == '') {
122 $type = $this->repo_helper->getObjectTypeFromRefId($ref_id);
123 }
124
125 if ($this->repo_helper->objectWithRefIdExists($ref_id)) {
126 switch ($type) {
127 case 'cat':
128 return new ilObjCategoryDAV(new ilObjCategory($ref_id, true), $this->repo_helper, $this);
129
130 case 'crs':
131 return new ilObjCourseDAV(new ilObjCourse($ref_id, true), $this->repo_helper, $this);
132
133 case 'grp':
134 return new ilObjGroupDAV(new ilObjGroup($ref_id, true), $this->repo_helper, $this);
135
136 case 'fold':
137 return new ilObjFolderDAV(new ilObjFolder($ref_id, true), $this->repo_helper, $this);
138
139 case 'file':
140 return new ilObjFileDAV(new ilObjFile($ref_id, true), $this->repo_helper, $this);
141 }
142 }
143 throw new BadRequest('Unknown filetype');
144 }
145
146
152 public function isValidFileNameWithValidFileExtension(string $a_title) : bool
153 {
154 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
155 return $a_title == ilFileUtils::getValidFilename($a_title) && $this->isDAVableObjTitle($a_title);
156 }
157}
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)
isDAVableObject($id, $is_reference=true, $do_name_check=true)
Check if given object (either obj_id or ref_id) is compatible to be represented as a WebDAV object.
createDAVObjectForRefId(int $ref_id, string $type='')
Creates a DAV Object for the given ref id.
__construct(ilWebDAVRepositoryHelper $repo_helper)
ilWebDAVObjDAVHelper constructor.
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.
if(!array_key_exists('StateId', $_REQUEST)) $id
$type