ILIAS  release_8 Revision v8.24
class.ilFilePreviewRenderer.php
Go to the documentation of this file.
1<?php
27{
33 final public function getSupportedRepositoryTypes(): array
34 {
35 return ["file"];
36 }
37
44 public function supports(\ilPreview $preview): bool
45 {
46 // let parent check first
47 if (!parent::supports($preview)) {
48 return false;
49 }
50
51 // legacy
52 if (null === $preview->getObjId()) {
53 // bugfix mantis 23293
54 if (isset($_FILES['file']['name'])) {
55 $filename = $_FILES['file']['name'];
56 } elseif (isset($_FILES['upload_files']['name'])) {
57 $filename = $_FILES['upload_files']['name'];
58 }
59 if (empty($filename)) {
60 return false;
61 }
62
63 // contains that extension?
65 return in_array($ext, $this->getSupportedFileFormats(), true);
66 }
67
68 try {
69 $obj = new ilObjFile($preview->getObjId(), false);
70 } catch (Exception $e) {
71 return false;
72 }
73
74 if (empty($obj->getResourceId())) {
75 return false;
76 }
77
78 return in_array($obj->getFileExtension(), $this->getSupportedFileFormats(), true);
79 }
80
89 public function prepareFileForExec(string $filepath): string
90 {
91 $filepath = ilFileUtils::getValidFilename($filepath);
92
93 $pos = strrpos($filepath, "/");
94 $name = $pos !== false ? substr($filepath, $pos + 1) : $filepath;
95
96 // if the file path contains any characters that could cause problems
97 // we copy the file to a temporary file
98 // $normName = preg_replace("/[^A-Za-z0-9.\- +_&]/", "", $name);
99 // if ($normName != $name)
100 // {
101 // $tempPath = ilUtil::ilTempnam();
102 // if (copy($filepath, $tempPath))
103 // return $tempPath;
104 // }
105 //
106 return $filepath;
107 }
108
114 abstract public function getSupportedFileFormats(): array;
115}
$filename
Definition: buildRTE.php:78
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getSupportedRepositoryTypes()
Gets an array containing the repository types (e.g.
supports(\ilPreview $preview)
Determines whether the specified preview object is supported by the renderer.
getSupportedFileFormats()
Gets an array containing the file formats that are supported by the renderer.
prepareFileForExec(string $filepath)
Checks whether the specified file path can be used with exec() commands.
static getValidFilename(string $a_filename)
static _getFileExtension(string $a_file_name)
Gets the file extension of the specified file name.
Class ilObjFile.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$preview
Definition: imgupload.php:81
if($format !==null) $name
Definition: metadata.php:247