19 declare(strict_types=1);
29 public function __construct(
private readonly
int $obj_id = 0,
private int $pos_id = 0)
32 $this->main_tpl = $DIC->ui()->mainTemplate();
34 $this->error = $DIC[
'ilErr'];
37 $this->forum_path = $this->
getPath() .
'/' . self::FORUM_PATH;
54 public function setPosId(
int $posting_id): void
56 $this->pos_id = $posting_id;
67 public function getFiles(): array
69 $directory_iterator =
new DirectoryIterator($this->forum_path);
70 $filter_iterator =
new RegexIterator($directory_iterator,
"/^{$this->obj_id}_(.+)$/");
73 foreach ($filter_iterator as $file) {
75 if (!$file->isFile()) {
79 [$obj_id, $rest] = explode(
'_', $file->getFilename(), 2);
80 if ((
int) $obj_id === $this->obj_id) {
82 'path' => $file->getPathname(),
83 'md5' => md5($this->obj_id .
'_' . $rest),
85 'size' => $file->getSize(),
86 'ctime' => date(
'Y-m-d H:i:s', $file->getCTime())
99 $directory_iterator =
new DirectoryIterator($this->forum_path);
100 $filter_iterator =
new RegexIterator($directory_iterator,
"/^{$this->obj_id}_{$this->getPosId()}_(.+)$/");
103 foreach ($filter_iterator as $file) {
105 if (!$file->isFile()) {
109 [$obj_id, $pos_id, $rest] = explode(
'_', $file->getFilename(), 3);
110 if ((
int) $pos_id === $this->
getPosId()) {
112 'path' => $file->getPathname(),
113 'md5' => md5($this->obj_id .
'_' . $this->pos_id .
'_' . $rest),
115 'size' => $file->getSize(),
116 'ctime' => date(
'Y-m-d H:i:s', $file->getCTime())
126 if ($new_frm_id !== 0) {
127 $directory_iterator =
new DirectoryIterator($this->forum_path);
128 $filter_iterator =
new RegexIterator($directory_iterator,
"/^{$this->obj_id}_(\d+)_(.+)$/");
130 foreach ($filter_iterator as $file) {
132 if (!$file->isFile()) {
136 [$obj_id, $pos_id, $rest] = explode(
'_', $file->getFilename(), 3);
137 if ((
int) $obj_id !== $this->obj_id || (
int) $pos_id !== $this->
getPosId()) {
142 $file->getPathname(),
143 $this->forum_path .
'/' . $new_frm_id .
'_' . $this->pos_id .
'_' . $rest
153 public function ilClone(
int $new_obj_id,
int $new_posting_id): bool
157 $this->
getForumPath() .
'/' . $this->obj_id .
'_' . $this->pos_id .
'_' . $file[
'name'],
158 $this->
getForumPath() .
'/' . $new_obj_id .
'_' . $new_posting_id .
'_' . $file[
'name']
165 public function delete(array $posting_ids_to_delete = null):
bool 167 if ($posting_ids_to_delete === null) {
171 foreach ($this->getFiles() as $file) {
187 if (is_file($this->forum_path .
'/' . $this->obj_id .
'_' . $this->pos_id .
'_' . $filename)) {
188 return unlink($this->forum_path .
'/' . $this->obj_id .
'_' . $this->pos_id .
'_' . $filename);
200 foreach ($files as $file) {
201 if ($file[
'type'] ===
'file' && md5($file[
'entry']) === $hashed_filename) {
203 'path' => $this->forum_path .
'/' . $file[
'entry'],
204 'filename' => $file[
'entry'],
205 'clean_filename' => str_replace($this->obj_id .
'_' . $this->pos_id .
'_',
'', $file[
'entry'])
219 if (is_array($hashed_filename_or_filenames)) {
220 foreach ($files as $file) {
221 if ($file[
'type'] ===
'file' && in_array(md5($file[
'entry']), $hashed_filename_or_filenames,
true)) {
222 unlink($this->forum_path .
'/' . $file[
'entry']);
229 foreach ($files as $file) {
230 if ($file[
'type'] ===
'file' && md5($file[
'entry']) === $hashed_filename_or_filenames) {
231 return unlink($this->forum_path .
'/' . $file[
'entry']);
250 if (!is_writable($this->forum_path) || !is_readable($this->forum_path)) {
251 $this->error->raiseError(
'Forum directory is not readable/writable by webserver', $this->error->FATAL);
257 if (is_writable($this->
getPath()) && mkdir($this->
getPath() .
'/' . self::FORUM_PATH) && chmod(
258 $this->
getPath() .
'/' . self::FORUM_PATH,
261 $this->forum_path = $this->
getPath() .
'/' . self::FORUM_PATH;
272 $this->main_tpl->setOnScreenMessage(
'failure', $DIC->lanuage()->txt(
'error_reading_file'),
true);
282 $this->main_tpl->setOnScreenMessage(
'failure', $DIC->language()->txt(
'error_reading_file'),
true);
289 $DIC->http()->close();
301 foreach ($filesOfPost as $file) {
302 copy($file[
'path'], $tmp_dir .
'/' . $file[
'name']);
getFileDataByMD5Filename(string $hashed_filename)
unlinkFilesByMD5Filenames($hashed_filename_or_filenames)
__construct(private readonly int $obj_id=0, private int $pos_id=0)
ilClone(int $new_obj_id, int $new_posting_id)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
setPosId(int $posting_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getDir(string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
get directory
moveFilesOfPost(int $new_frm_id=0)
deliverFile(string $file)
Error Handling & global info handling.
ilGlobalTemplateInterface $main_tpl
static zip(string $a_dir, string $a_file, bool $compress_content=false)
static rename(string $a_source, string $a_target)
unlinkFile(string $filename)