ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilFileDataForumDraftsLegacyImplementation Class Reference
+ Inheritance diagram for ilFileDataForumDraftsLegacyImplementation:
+ Collaboration diagram for ilFileDataForumDraftsLegacyImplementation:

Public Member Functions

 __construct (private readonly int $obj_id, private readonly int $draft_id)
 
 getObjId ()
 
 delete (array $posting_ids_to_delete=null)
 
 storeUploadedFile (array $files)
 
 unlinkFile (string $filename)
 
 getFileDataByMD5Filename (string $hashed_filename)
 
 unlinkFilesByMD5Filenames ($hashedFilenameOrFilenames)
 
 checkForumDraftsPath ()
 
 deliverFile (string $file)
 
 deliverZipFile ()
 
 getPosId ()
 
 setPosId (int $posting_id)
 
 getForumPath ()
 
 moveFilesOfPost (int $new_frm_id=0)
 
 ilClone (int $new_obj_id, int $new_posting_id)
 
 storeUploadedFiles ()
 
- 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...
 
- Public Member Functions inherited from ilFileDataForumInterface
 getFilesOfPost ()
 

Private Member Functions

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

Private Attributes

string $drafts_path
 
ilLanguage $lng
 
ilErrorHandling $error
 
ilGlobalTemplateInterface $main_tpl
 

Additional Inherited Members

- Protected Attributes inherited from ilFile
string $path
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilFileDataForumDraftsLegacyImplementation::__construct ( private readonly int  $obj_id,
private readonly int  $draft_id 
)

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

References $DIC, ILIAS\MetaData\Repository\Validation\Data\__construct(), checkForumDraftsPath(), ilFileData\getPath(), initDirectory(), and ILIAS\Repository\lng().

29  {
30  global $DIC;
31  $this->main_tpl = $DIC->ui()->mainTemplate();
32  $this->lng = $DIC->language();
33  $this->error = $DIC['ilErr'];
34 
36  $this->drafts_path = $this->getPath() . '/forum/drafts';
37 
38  if (!$this->checkForumDraftsPath()) {
39  $this->initDirectory();
40  }
41  }
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
+ Here is the call graph for this function:

Member Function Documentation

◆ checkForumDraftsPath()

ilFileDataForumDraftsLegacyImplementation::checkForumDraftsPath ( )

Definition at line 205 of file class.ilFileDataForumDraftsLegacyImplementation.php.

References checkReadWrite(), and getDraftsPath().

Referenced by __construct().

205  : bool
206  {
207  if (!is_dir($this->getDraftsPath() . '/' . $this->draft_id)) {
208  return false;
209  }
210  $this->checkReadWrite();
211 
212  return true;
213  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkReadWrite()

ilFileDataForumDraftsLegacyImplementation::checkReadWrite ( )
private

Definition at line 215 of file class.ilFileDataForumDraftsLegacyImplementation.php.

References getDraftsPath().

Referenced by checkForumDraftsPath().

215  : void
216  {
217  if (!is_writable($this->getDraftsPath() . '/' . $this->draft_id) ||
218  !is_readable($this->getDraftsPath() . '/' . $this->draft_id)) {
219  $this->error->raiseError('Forum directory is not readable/writable by webserver', $this->error->FATAL);
220  }
221  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createZipFile()

ilFileDataForumDraftsLegacyImplementation::createZipFile ( )
private

Definition at line 270 of file class.ilFileDataForumDraftsLegacyImplementation.php.

References getDraftsPath(), ilFileDataForumInterface\getFilesOfPost(), ilFileUtils\makeDirParents(), and ilFileUtils\zip().

Referenced by deliverZipFile().

270  : ?string
271  {
272  $filesOfDraft = $this->getFilesOfPost();
273  ilFileUtils::makeDirParents($this->getDraftsPath() . '/drafts_zip/' . $this->draft_id);
274  $tmp_dir = $this->getDraftsPath() . '/drafts_zip/' . $this->draft_id;
275 
276  if ($filesOfDraft !== []) {
277  ksort($filesOfDraft);
278 
279  foreach ($filesOfDraft as $file) {
280  copy($file['path'], $tmp_dir . '/' . $file['name']);
281  }
282  }
283 
284  $zip_file = null;
285  if (ilFileUtils::zip($tmp_dir, $this->getDraftsPath() . '/drafts_zip/' . $this->draft_id . '.zip')) {
286  $zip_file = $this->getDraftsPath() . '/drafts_zip/' . $this->draft_id . '.zip';
287  }
288 
289  return $zip_file;
290  }
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)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilFileDataForumDraftsLegacyImplementation::delete ( array  $posting_ids_to_delete = null)
Parameters
list<int>|null$posting_ids_to_delete

Implements ilFileDataForumInterface.

Definition at line 106 of file class.ilFileDataForumDraftsLegacyImplementation.php.

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

106  : bool
107  {
108  // Each element of $posting_ids_to_delete represents a "Draft Id", NOT a "Posting Id"
109  if ($posting_ids_to_delete === null) {
110  return true;
111  }
112 
113  foreach ($posting_ids_to_delete as $draft_id) {
114  ilFileUtils::delDir($this->getDraftsPath() . '/' . $draft_id);
115  }
116 
117  return true;
118  }
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
+ Here is the call graph for this function:

◆ deliverFile()

ilFileDataForumDraftsLegacyImplementation::deliverFile ( string  $file)

Implements ilFileDataForumInterface.

Definition at line 243 of file class.ilFileDataForumDraftsLegacyImplementation.php.

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

243  : void
244  {
245  if (($path = $this->getFileDataByMD5Filename($file)) !== null) {
246  ilFileDelivery::deliverFileLegacy($path['path'], $path['clean_filename']);
247  } else {
248  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('error_reading_file'), true);
249  }
250  }
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
+ Here is the call graph for this function:

◆ deliverZipFile()

ilFileDataForumDraftsLegacyImplementation::deliverZipFile ( )

Implements ilFileDataForumInterface.

Definition at line 252 of file class.ilFileDataForumDraftsLegacyImplementation.php.

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

252  : bool
253  {
254  global $DIC;
255 
256  $zip_file = $this->createZipFile();
257  if (!$zip_file) {
258  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('error_reading_file'), true);
259  return false;
260  }
261 
263  ilFileDelivery::deliverFileLegacy($zip_file, $post->getPostSubject() . '.zip', '', false, true, false);
264  ilFileUtils::delDir($this->getDraftsPath() . '/drafts_zip/' . $this->draft_id);
265  $DIC->http()->close();
266 
267  return true; // never
268  }
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
global $DIC
Definition: feed.php:28
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static newInstanceByDraftId(int $draft_id)
$post
Definition: ltitoken.php:49
+ Here is the call graph for this function:

◆ getDraftsPath()

ilFileDataForumDraftsLegacyImplementation::getDraftsPath ( )
private

◆ getFileDataByMD5Filename()

ilFileDataForumDraftsLegacyImplementation::getFileDataByMD5Filename ( string  $hashed_filename)
Returns
array{path: string, filename: string, clean_filename: string}|null

Implements ilFileDataForumInterface.

Definition at line 164 of file class.ilFileDataForumDraftsLegacyImplementation.php.

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

Referenced by deliverFile().

164  : ?array
165  {
166  $files = ilFileUtils::getDir($this->getDraftsPath() . '/' . $this->draft_id);
167  foreach ($files as $file) {
168  if ($file['type'] === 'file' && md5($file['entry']) === $hashed_filename) {
169  return [
170  'path' => $this->getDraftsPath() . '/' . $this->draft_id . '/' . $file['entry'],
171  'filename' => $file['entry'],
172  'clean_filename' => $file['entry']
173  ];
174  }
175  }
176 
177  return null;
178  }
static getDir(string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
get directory
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getForumPath()

ilFileDataForumDraftsLegacyImplementation::getForumPath ( )

Implements ilFileDataForumInterface.

Definition at line 301 of file class.ilFileDataForumDraftsLegacyImplementation.php.

301  : string
302  {
303  return '';
304  }

◆ getObjId()

ilFileDataForumDraftsLegacyImplementation::getObjId ( )

Implements ilFileDataForumInterface.

Definition at line 43 of file class.ilFileDataForumDraftsLegacyImplementation.php.

43  : int
44  {
45  return $this->obj_id;
46  }

◆ getPosId()

ilFileDataForumDraftsLegacyImplementation::getPosId ( )

Implements ilFileDataForumInterface.

Definition at line 292 of file class.ilFileDataForumDraftsLegacyImplementation.php.

292  : int
293  {
294  return $this->draft_id;
295  }

◆ ilClone()

ilFileDataForumDraftsLegacyImplementation::ilClone ( int  $new_obj_id,
int  $new_posting_id 
)

Implements ilFileDataForumInterface.

Definition at line 311 of file class.ilFileDataForumDraftsLegacyImplementation.php.

311  : bool
312  {
313  return true;
314  }

◆ initDirectory()

ilFileDataForumDraftsLegacyImplementation::initDirectory ( )
private

Definition at line 223 of file class.ilFileDataForumDraftsLegacyImplementation.php.

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

Referenced by __construct().

223  : void
224  {
225  if (is_writable($this->getPath()) && ilFileUtils::makeDirParents(
226  $this->getDraftsPath() . '/' . $this->draft_id
227  ) && chmod(
228  $this->getDraftsPath() . '/' . $this->draft_id,
229  0755
230  )) {
231  // Empty, whyever @nmatuschek?
232  }
233  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ moveFilesOfPost()

ilFileDataForumDraftsLegacyImplementation::moveFilesOfPost ( int  $new_frm_id = 0)

Implements ilFileDataForumInterface.

Definition at line 306 of file class.ilFileDataForumDraftsLegacyImplementation.php.

306  : bool
307  {
308  return true;
309  }

◆ rotateFiles()

ilFileDataForumDraftsLegacyImplementation::rotateFiles ( string  $a_path)
private

Definition at line 235 of file class.ilFileDataForumDraftsLegacyImplementation.php.

References ilFileUtils\rename().

Referenced by storeUploadedFile().

235  : void
236  {
237  if (is_file($a_path)) {
238  $this->rotateFiles($a_path . '.old');
239  ilFileUtils::rename($a_path, $a_path . '.old');
240  }
241  }
static rename(string $a_source, string $a_target)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPosId()

ilFileDataForumDraftsLegacyImplementation::setPosId ( int  $posting_id)

Implements ilFileDataForumInterface.

Definition at line 297 of file class.ilFileDataForumDraftsLegacyImplementation.php.

297  : void
298  {
299  }

◆ storeUploadedFile()

ilFileDataForumDraftsLegacyImplementation::storeUploadedFile ( array  $files)

Definition at line 120 of file class.ilFileDataForumDraftsLegacyImplementation.php.

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

120  : bool
121  {
122  if (isset($files['name']) && is_array($files['name'])) {
123  foreach ($files['name'] as $index => $name) {
124  $name = rtrim($name, '/');
126  $temp_name = $files['tmp_name'][$index];
127  $error = $files['error'][$index];
128 
129  if ($filename !== '' && $temp_name !== '' && (int) $error === 0) {
130  $path = $this->getDraftsPath() . '/' . $this->draft_id . '/' . $filename;
131 
132  $this->rotateFiles($path);
134  }
135  }
136 
137  return true;
138  }
139 
140  if (isset($files['name']) && is_string($files['name'])) {
141  $files['name'] = rtrim($files['name'], '/');
142  $filename = ilFileUtils::_sanitizeFilemame($files['name']);
143  $temp_name = $files['tmp_name'];
144 
145  $path = $this->getDraftsPath() . '/' . $this->draft_id . '/' . $filename;
146 
147  $this->rotateFiles($path);
149 
150  return true;
151  }
152 
153  return false;
154  }
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
static _sanitizeFilemame(string $a_filename)
$filename
Definition: buildRTE.php:78
string $path
+ Here is the call graph for this function:

◆ storeUploadedFiles()

ilFileDataForumDraftsLegacyImplementation::storeUploadedFiles ( )

Implements ilFileDataForumInterface.

Definition at line 316 of file class.ilFileDataForumDraftsLegacyImplementation.php.

316  : bool
317  {
318  throw new DomainException('Not implemented');
319  }

◆ unlinkFile()

ilFileDataForumDraftsLegacyImplementation::unlinkFile ( string  $filename)

Implements ilFileDataForumInterface.

Definition at line 156 of file class.ilFileDataForumDraftsLegacyImplementation.php.

156  : bool
157  {
158  throw new DomainException('Not implemented');
159  }

◆ unlinkFilesByMD5Filenames()

ilFileDataForumDraftsLegacyImplementation::unlinkFilesByMD5Filenames (   $hashedFilenameOrFilenames)
Parameters
string|string[]$hashedFilenameOrFilenames

Implements ilFileDataForumInterface.

Definition at line 183 of file class.ilFileDataForumDraftsLegacyImplementation.php.

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

183  : bool
184  {
185  $files = ilFileUtils::getDir($this->getDraftsPath() . '/' . $this->draft_id);
186  if (is_array($hashedFilenameOrFilenames)) {
187  foreach ($files as $file) {
188  if ($file['type'] === 'file' && in_array(md5($file['entry']), $hashedFilenameOrFilenames, true)) {
189  unlink($this->getDraftsPath() . '/' . $this->draft_id . '/' . $file['entry']);
190  }
191  }
192 
193  return true;
194  }
195 
196  foreach ($files as $file) {
197  if ($file['type'] === 'file' && md5($file['entry']) === $hashedFilenameOrFilenames) {
198  return unlink($this->getDraftsPath() . '/' . $this->draft_id . '/' . $file['entry']);
199  }
200  }
201 
202  return false;
203  }
static getDir(string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
get directory
+ Here is the call graph for this function:

Field Documentation

◆ $drafts_path

string ilFileDataForumDraftsLegacyImplementation::$drafts_path
private

Definition at line 23 of file class.ilFileDataForumDraftsLegacyImplementation.php.

Referenced by getDraftsPath().

◆ $error

ilErrorHandling ilFileDataForumDraftsLegacyImplementation::$error
private

◆ $lng

ilLanguage ilFileDataForumDraftsLegacyImplementation::$lng
private

◆ $main_tpl

ilGlobalTemplateInterface ilFileDataForumDraftsLegacyImplementation::$main_tpl
private

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