ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
ilFileDataForumDrafts Class Reference

This class handles all operations on files for the drafts of a forum object. More...

+ Inheritance diagram for ilFileDataForumDrafts:
+ Collaboration diagram for ilFileDataForumDrafts:

Public Member Functions

 __construct (int $obj_id, int $draft_id)
 
 getObjId ()
 
 setObjId (int $obj_id)
 
 getDraftId ()
 
 setDraftId (int $draft_id)
 
 getDraftsPath ()
 
 moveFilesOfDraft (string $forum_path, int $new_post_id)
 
 delete ()
 
 storeUploadedFile (array $files)
 
 unlinkFile (string $a_filename)
 
 getFileDataByMD5Filename (string $hashedFilename)
 
 unlinkFilesByMD5Filenames ($hashedFilenameOrFilenames)
 
 checkForumDraftsPath ()
 
 deliverFile (string $file)
 
 deliverZipFile ()
 
 createZipFile ()
 
- Public Member Functions inherited from ilFileData
 __construct ()
 
 checkPath (string $a_path)
 
 getPath ()
 
- Public Member Functions inherited from ilFile
 deleteTrailingSlash (string $a_path)
 delete trailing slash of path variables More...
 

Private Member Functions

 checkReadWrite ()
 
 initDirectory ()
 
 rotateFiles (string $a_path)
 

Private Attributes

int $obj_id
 
int $draft_id
 
string $drafts_path
 
ilLanguage $lng
 
ilErrorHandling $error
 
ilGlobalTemplateInterface $main_tpl
 

Additional Inherited Members

- Protected Attributes inherited from ilFile
string $path
 

Detailed Description

This class handles all operations on files for the drafts of a forum object.

Author
Nadia Matuschek nmatu.nosp@m.sche.nosp@m.k@dat.nosp@m.abay.nosp@m..de

Definition at line 26 of file class.ilFileDataForumDrafts.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileDataForumDrafts::__construct ( int  $obj_id,
int  $draft_id 
)

Definition at line 35 of file class.ilFileDataForumDrafts.php.

36 {
37 global $DIC;
38 $this->main_tpl = $DIC->ui()->mainTemplate();
39
40 $this->lng = $DIC->language();
41 $this->error = $DIC['ilErr'];
42
43 $this->obj_id = $obj_id;
44 $this->draft_id = $draft_id;
45
47 $this->drafts_path = $this->getPath() . '/forum/drafts';
48
49 if (!$this->checkForumDraftsPath()) {
50 $this->initDirectory();
51 }
52 }
error(string $a_errmsg)
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References $DIC, $draft_id, $obj_id, ILIAS\GlobalScreen\Provider\__construct(), checkForumDraftsPath(), error(), ilFileData\getPath(), initDirectory(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkForumDraftsPath()

ilFileDataForumDrafts::checkForumDraftsPath ( )

Definition at line 241 of file class.ilFileDataForumDrafts.php.

241 : bool
242 {
243 if (!is_dir($this->getDraftsPath() . '/' . $this->getDraftId())) {
244 return false;
245 }
246 $this->checkReadWrite();
247
248 return true;
249 }

References checkReadWrite(), getDraftId(), and getDraftsPath().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkReadWrite()

ilFileDataForumDrafts::checkReadWrite ( )
private

Definition at line 251 of file class.ilFileDataForumDrafts.php.

251 : void
252 {
253 if (
254 !is_writable($this->getDraftsPath() . '/' . $this->getDraftId()) ||
255 !is_readable($this->getDraftsPath() . '/' . $this->getDraftId())
256 ) {
257 $this->error->raiseError('Forum directory is not readable/writable by webserver', $this->error->FATAL);
258 }
259 }

References error(), getDraftId(), and getDraftsPath().

Referenced by checkForumDraftsPath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createZipFile()

ilFileDataForumDrafts::createZipFile ( )

Definition at line 305 of file class.ilFileDataForumDrafts.php.

305 : ?string
306 {
307 $filesOfDraft = $this->getFilesOfPost();
308 ilFileUtils::makeDirParents($this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId());
309 $tmp_dir = $this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId();
310
311 if (count($filesOfDraft)) {
312 ksort($filesOfDraft);
313
314 foreach ($filesOfDraft as $file) {
315 copy($file['path'], $tmp_dir . '/' . $file['name']);
316 }
317 }
318
319 $zip_file = null;
320 if (ilFileUtils::zip($tmp_dir, $this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId() . '.zip')) {
321 $zip_file = $this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId() . '.zip';
322 }
323
324 return $zip_file;
325 }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static zip(string $a_dir, string $a_file, bool $compress_content=false)
zips given directory/file into given zip.file

References getDraftId(), getDraftsPath(), ilFileUtils\makeDirParents(), and ilFileUtils\zip().

Referenced by deliverZipFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilFileDataForumDrafts::delete ( )

Definition at line 144 of file class.ilFileDataForumDrafts.php.

144 : bool
145 {
146 ilFileUtils::delDir($this->getDraftsPath() . '/' . $this->getDraftId());
147 return true;
148 }
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively

References ilFileUtils\delDir(), getDraftId(), and getDraftsPath().

+ Here is the call graph for this function:

◆ deliverFile()

ilFileDataForumDrafts::deliverFile ( string  $file)

Definition at line 279 of file class.ilFileDataForumDrafts.php.

279 : void
280 {
281 if (($path = $this->getFileDataByMD5Filename($file)) !== null) {
282 ilFileDelivery::deliverFileLegacy($path['path'], $path['clean_filename']);
283 } else {
284 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('error_reading_file'), true);
285 }
286 }
getFileDataByMD5Filename(string $hashedFilename)
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
string $path

References ilFile\$path, ilFileDelivery\deliverFileLegacy(), getFileDataByMD5Filename(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ deliverZipFile()

ilFileDataForumDrafts::deliverZipFile ( )

Definition at line 288 of file class.ilFileDataForumDrafts.php.

288 : bool
289 {
290 global $DIC;
291
292 $zip_file = $this->createZipFile();
293 if (!$zip_file) {
294 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('error_reading_file'), true);
295 return false;
296 }
297
299 ilFileDelivery::deliverFileLegacy($zip_file, $post->getPostSubject() . '.zip', '', false, true, false);
300 ilFileUtils::delDir($this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId());
301 $DIC->http()->close();
302 return true; // never
303 }
static newInstanceByDraftId(int $draft_id)
$post
Definition: ltitoken.php:49

References $DIC, $post, createZipFile(), ilFileUtils\delDir(), ilFileDelivery\deliverFileLegacy(), getDraftId(), getDraftsPath(), ILIAS\Repository\lng(), and ilForumPostDraft\newInstanceByDraftId().

+ Here is the call graph for this function:

◆ getDraftId()

ilFileDataForumDrafts::getDraftId ( )

Definition at line 64 of file class.ilFileDataForumDrafts.php.

64 : int
65 {
66 return $this->draft_id;
67 }

References $draft_id.

Referenced by checkForumDraftsPath(), checkReadWrite(), createZipFile(), delete(), deliverZipFile(), getFileDataByMD5Filename(), initDirectory(), storeUploadedFile(), unlinkFile(), and unlinkFilesByMD5Filenames().

+ Here is the caller graph for this function:

◆ getDraftsPath()

ilFileDataForumDrafts::getDraftsPath ( )

◆ getFileDataByMD5Filename()

ilFileDataForumDrafts::getFileDataByMD5Filename ( string  $hashedFilename)
Parameters
string$hashedFilename
Returns
array{path: string, filename: string, clean_filename: string}|null

Definition at line 199 of file class.ilFileDataForumDrafts.php.

199 : ?array
200 {
201 $files = ilFileUtils::getDir($this->getDraftsPath() . '/' . $this->getDraftId());
202 foreach ($files as $file) {
203 if ($file['type'] === 'file' && md5($file['entry']) === $hashedFilename) {
204 return [
205 'path' => $this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $file['entry'],
206 'filename' => $file['entry'],
207 'clean_filename' => $file['entry']
208 ];
209 }
210 }
211
212 return null;
213 }
static getDir(string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
get directory

References ilFileUtils\getDir(), getDraftId(), and getDraftsPath().

Referenced by deliverFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getObjId()

ilFileDataForumDrafts::getObjId ( )

Definition at line 54 of file class.ilFileDataForumDrafts.php.

54 : int
55 {
56 return $this->obj_id;
57 }

References $obj_id.

◆ initDirectory()

ilFileDataForumDrafts::initDirectory ( )
private

Definition at line 261 of file class.ilFileDataForumDrafts.php.

261 : void
262 {
263 if (is_writable($this->getPath()) && ilFileUtils::makeDirParents($this->getDraftsPath() . '/' . $this->getDraftId()) && chmod(
264 $this->getDraftsPath() . '/' . $this->getDraftId(),
265 0755
266 )) {
267 // Empty, whyever @nmatuschek?
268 }
269 }

References getDraftId(), getDraftsPath(), ilFileData\getPath(), and ilFileUtils\makeDirParents().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ moveFilesOfDraft()

ilFileDataForumDrafts::moveFilesOfDraft ( string  $forum_path,
int  $new_post_id 
)

Definition at line 132 of file class.ilFileDataForumDrafts.php.

132 : bool
133 {
134 foreach ($this->getFilesOfPost() as $file) {
135 copy(
136 $file['path'],
137 $forum_path . '/' . $this->obj_id . '_' . $new_post_id . '_' . $file['name']
138 );
139 }
140
141 return true;
142 }

◆ rotateFiles()

ilFileDataForumDrafts::rotateFiles ( string  $a_path)
private

Definition at line 271 of file class.ilFileDataForumDrafts.php.

271 : void
272 {
273 if (is_file($a_path)) {
274 $this->rotateFiles($a_path . '.old');
275 ilFileUtils::rename($a_path, $a_path . '.old');
276 }
277 }
static rename(string $a_source, string $a_target)

References ilFileUtils\rename(), and rotateFiles().

Referenced by rotateFiles(), and storeUploadedFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDraftId()

ilFileDataForumDrafts::setDraftId ( int  $draft_id)

Definition at line 69 of file class.ilFileDataForumDrafts.php.

69 : void
70 {
71 $this->draft_id = $draft_id;
72 }

References $draft_id.

◆ setObjId()

ilFileDataForumDrafts::setObjId ( int  $obj_id)

Definition at line 59 of file class.ilFileDataForumDrafts.php.

59 : void
60 {
61 $this->obj_id = $obj_id;
62 }

References $obj_id.

◆ storeUploadedFile()

ilFileDataForumDrafts::storeUploadedFile ( array  $files)

Definition at line 150 of file class.ilFileDataForumDrafts.php.

150 : bool
151 {
152 if (isset($files['name']) && is_array($files['name'])) {
153 foreach ($files['name'] as $index => $name) {
154 $name = rtrim($name, '/');
156 $temp_name = $files['tmp_name'][$index];
157 $error = $files['error'][$index];
158
159 if ($filename !== '' && $temp_name !== '' && (int) $error === 0) {
160 $path = $this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $filename;
161
162 $this->rotateFiles($path);
164 }
165 }
166
167 return true;
168 }
169
170 if (isset($files['name']) && is_string($files['name'])) {
171 $files['name'] = rtrim($files['name'], '/');
173 $temp_name = $files['tmp_name'];
174
175 $path = $this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $filename;
176
177 $this->rotateFiles($path);
179
180 return true;
181 }
182
183 return false;
184 }
$filename
Definition: buildRTE.php:78
static _sanitizeFilemame(string $a_filename)
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
if($format !==null) $name
Definition: metadata.php:247
$index
Definition: metadata.php:145

References $error, $filename, $index, $name, ilFile\$path, ilFileUtils\_sanitizeFilemame(), getDraftId(), getDraftsPath(), ilFileUtils\moveUploadedFile(), and rotateFiles().

+ Here is the call graph for this function:

◆ unlinkFile()

ilFileDataForumDrafts::unlinkFile ( string  $a_filename)

Definition at line 186 of file class.ilFileDataForumDrafts.php.

186 : bool
187 {
188 if (is_file($this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $a_filename)) {
189 return unlink($this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $a_filename);
190 }
191
192 return false;
193 }

References getDraftId(), and getDraftsPath().

+ Here is the call graph for this function:

◆ unlinkFilesByMD5Filenames()

ilFileDataForumDrafts::unlinkFilesByMD5Filenames (   $hashedFilenameOrFilenames)
Parameters
string | string[]$hashedFilenameOrFilenames
Returns
bool

Definition at line 219 of file class.ilFileDataForumDrafts.php.

219 : bool
220 {
221 $files = ilFileUtils::getDir($this->getDraftsPath() . '/' . $this->getDraftId());
222 if (is_array($hashedFilenameOrFilenames)) {
223 foreach ($files as $file) {
224 if ($file['type'] === 'file' && in_array(md5($file['entry']), $hashedFilenameOrFilenames, true)) {
225 unlink($this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $file['entry']);
226 }
227 }
228
229 return true;
230 }
231
232 foreach ($files as $file) {
233 if ($file['type'] === 'file' && md5($file['entry']) === $hashedFilenameOrFilenames) {
234 return unlink($this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $file['entry']);
235 }
236 }
237
238 return false;
239 }

References ilFileUtils\getDir(), getDraftId(), and getDraftsPath().

+ Here is the call graph for this function:

Field Documentation

◆ $draft_id

int ilFileDataForumDrafts::$draft_id
private

Definition at line 29 of file class.ilFileDataForumDrafts.php.

Referenced by __construct(), getDraftId(), and setDraftId().

◆ $drafts_path

string ilFileDataForumDrafts::$drafts_path
private

Definition at line 30 of file class.ilFileDataForumDrafts.php.

Referenced by getDraftsPath().

◆ $error

ilErrorHandling ilFileDataForumDrafts::$error
private

Definition at line 32 of file class.ilFileDataForumDrafts.php.

Referenced by storeUploadedFile().

◆ $lng

ilLanguage ilFileDataForumDrafts::$lng
private

Definition at line 31 of file class.ilFileDataForumDrafts.php.

◆ $main_tpl

ilGlobalTemplateInterface ilFileDataForumDrafts::$main_tpl
private

Definition at line 33 of file class.ilFileDataForumDrafts.php.

◆ $obj_id

int ilFileDataForumDrafts::$obj_id
private

Definition at line 28 of file class.ilFileDataForumDrafts.php.

Referenced by __construct(), getObjId(), and setObjId().


The documentation for this class was generated from the following file: