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

Public Member Functions

 __construct (private readonly int $obj_id=0, private int $pos_id=0)
 
 getObjId ()
 
 getPosId ()
 
 setPosId (int $posting_id)
 
 getForumPath ()
 
 ilClone (int $new_obj_id, int $new_posting_id)
 
 delete (array $posting_ids_to_delete=null)
 
 storeUploadedFiles ()
 
 unlinkFile (string $filename)
 
 getFileDataByMD5Filename (string $hashed_filename)
 
 unlinkFilesByMD5Filenames ($hashed_filename_or_filenames)
 
 deliverFile (string $file)
 
 deliverZipFile ()
 
- 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 ()
 
 moveFilesOfPost (int $new_frm_id=0)
 

Private Member Functions

 checkForumPath ()
 
 checkReadWrite ()
 
 initDirectory ()
 
 createZipFile ()
 

Private Attributes

const FORUM_PATH = 'forum'
 
string $forum_path
 
ilErrorHandling $error
 
ilGlobalTemplateInterface $main_tpl
 

Additional Inherited Members

- Protected Attributes inherited from ilFile
string $path
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilFileDataForumLegacyImplementation::__construct ( private readonly int  $obj_id = 0,
private int  $pos_id = 0 
)

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

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

30  {
31  global $DIC;
32  $this->main_tpl = $DIC->ui()->mainTemplate();
33 
34  $this->error = $DIC['ilErr'];
35 
37  $this->forum_path = $this->getPath() . '/' . self::FORUM_PATH;
38 
39  if (!$this->checkForumPath()) {
40  $this->initDirectory();
41  }
42  }
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
+ Here is the call graph for this function:

Member Function Documentation

◆ checkForumPath()

ilFileDataForumLegacyImplementation::checkForumPath ( )
private

Definition at line 238 of file class.ilFileDataForumLegacyImplementation.php.

References checkReadWrite(), and getForumPath().

Referenced by __construct().

238  : bool
239  {
240  if (!is_dir($this->getForumPath())) {
241  return false;
242  }
243  $this->checkReadWrite();
244 
245  return true;
246  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkReadWrite()

ilFileDataForumLegacyImplementation::checkReadWrite ( )
private

Definition at line 248 of file class.ilFileDataForumLegacyImplementation.php.

Referenced by checkForumPath().

248  : void
249  {
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);
252  }
253  }
+ Here is the caller graph for this function:

◆ createZipFile()

ilFileDataForumLegacyImplementation::createZipFile ( )
private

Definition at line 294 of file class.ilFileDataForumLegacyImplementation.php.

References ilFileDataForumInterface\getFilesOfPost(), getForumPath(), getObjId(), getPosId(), ilFileUtils\makeDirParents(), and ilFileUtils\zip().

Referenced by deliverZipFile().

294  : ?string
295  {
296  $filesOfPost = $this->getFilesOfPost();
297  ksort($filesOfPost);
298 
299  ilFileUtils::makeDirParents($this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId());
300  $tmp_dir = $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId();
301  foreach ($filesOfPost as $file) {
302  copy($file['path'], $tmp_dir . '/' . $file['name']);
303  }
304 
305  $zip_file = null;
306  if (ilFileUtils::zip(
307  $tmp_dir,
308  $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId() . '.zip'
309  )) {
310  $zip_file = $this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId() . '.zip';
311  }
312 
313  return $zip_file;
314  }
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()

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

Implements ilFileDataForumInterface.

Definition at line 165 of file class.ilFileDataForumLegacyImplementation.php.

References getForumPath(), and getObjId().

165  : bool
166  {
167  if ($posting_ids_to_delete === null) {
168  return true;
169  }
170 
171  foreach ($this->getFiles() as $file) {
172  if (is_file($this->getForumPath() . '/' . $this->getObjId() . '_' . $file['name'])) {
173  unlink($this->getForumPath() . '/' . $this->getObjId() . '_' . $file['name']);
174  }
175  }
176 
177  return true;
178  }
+ Here is the call graph for this function:

◆ deliverFile()

ilFileDataForumLegacyImplementation::deliverFile ( string  $file)

Implements ilFileDataForumInterface.

Definition at line 265 of file class.ilFileDataForumLegacyImplementation.php.

References $DIC, ilFile\$path, ilFileDelivery\deliverFileLegacy(), and getFileDataByMD5Filename().

265  : void
266  {
267  global $DIC;
268 
269  if (($path = $this->getFileDataByMD5Filename($file)) !== null) {
270  ilFileDelivery::deliverFileLegacy($path['path'], $path['clean_filename']);
271  } else {
272  $this->main_tpl->setOnScreenMessage('failure', $DIC->lanuage()->txt('error_reading_file'), true);
273  }
274  }
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
string $path
+ Here is the call graph for this function:

◆ deliverZipFile()

ilFileDataForumLegacyImplementation::deliverZipFile ( )

Implements ilFileDataForumInterface.

Definition at line 276 of file class.ilFileDataForumLegacyImplementation.php.

References $DIC, $post, createZipFile(), ilFileUtils\delDir(), ilFileDelivery\deliverFileLegacy(), getForumPath(), getObjId(), and getPosId().

276  : bool
277  {
278  global $DIC;
279 
280  $zip_file = $this->createZipFile();
281  if (!$zip_file) {
282  $this->main_tpl->setOnScreenMessage('failure', $DIC->language()->txt('error_reading_file'), true);
283  return false;
284  }
285 
286  $post = new ilForumPost($this->getPosId());
287  ilFileDelivery::deliverFileLegacy($zip_file, $post->getSubject() . '.zip', '', false, true, false);
288  ilFileUtils::delDir($this->getForumPath() . '/zip/' . $this->getObjId() . '_' . $this->getPosId());
289  $DIC->http()->close();
290 
291  return true; // never
292  }
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
$post
Definition: ltitoken.php:49
+ Here is the call graph for this function:

◆ getFileDataByMD5Filename()

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

Implements ilFileDataForumInterface.

Definition at line 197 of file class.ilFileDataForumLegacyImplementation.php.

References ilFileUtils\getDir().

Referenced by deliverFile().

197  : ?array
198  {
199  $files = ilFileUtils::getDir($this->forum_path);
200  foreach ($files as $file) {
201  if ($file['type'] === 'file' && md5($file['entry']) === $hashed_filename) {
202  return [
203  'path' => $this->forum_path . '/' . $file['entry'],
204  'filename' => $file['entry'],
205  'clean_filename' => str_replace($this->obj_id . '_' . $this->pos_id . '_', '', $file['entry'])
206  ];
207  }
208  }
209 
210  return null;
211  }
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()

ilFileDataForumLegacyImplementation::getForumPath ( )

◆ getObjId()

ilFileDataForumLegacyImplementation::getObjId ( )

Implements ilFileDataForumInterface.

Definition at line 44 of file class.ilFileDataForumLegacyImplementation.php.

Referenced by createZipFile(), delete(), and deliverZipFile().

44  : int
45  {
46  return $this->obj_id;
47  }
+ Here is the caller graph for this function:

◆ getPosId()

ilFileDataForumLegacyImplementation::getPosId ( )

Implements ilFileDataForumInterface.

Definition at line 49 of file class.ilFileDataForumLegacyImplementation.php.

Referenced by createZipFile(), deliverZipFile(), and getForumPath().

49  : int
50  {
51  return $this->pos_id;
52  }
+ Here is the caller graph for this function:

◆ ilClone()

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

Implements ilFileDataForumInterface.

Definition at line 153 of file class.ilFileDataForumLegacyImplementation.php.

References ilFileDataForumInterface\getFilesOfPost(), and getForumPath().

153  : bool
154  {
155  foreach ($this->getFilesOfPost() as $file) {
156  copy(
157  $this->getForumPath() . '/' . $this->obj_id . '_' . $this->pos_id . '_' . $file['name'],
158  $this->getForumPath() . '/' . $new_obj_id . '_' . $new_posting_id . '_' . $file['name']
159  );
160  }
161 
162  return true;
163  }
+ Here is the call graph for this function:

◆ initDirectory()

ilFileDataForumLegacyImplementation::initDirectory ( )
private

Definition at line 255 of file class.ilFileDataForumLegacyImplementation.php.

References ilFileData\getPath().

Referenced by __construct().

255  : void
256  {
257  if (is_writable($this->getPath()) && mkdir($this->getPath() . '/' . self::FORUM_PATH) && chmod(
258  $this->getPath() . '/' . self::FORUM_PATH,
259  0755
260  )) {
261  $this->forum_path = $this->getPath() . '/' . self::FORUM_PATH;
262  }
263  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPosId()

ilFileDataForumLegacyImplementation::setPosId ( int  $posting_id)

Implements ilFileDataForumInterface.

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

54  : void
55  {
56  $this->pos_id = $posting_id;
57  }

◆ storeUploadedFiles()

ilFileDataForumLegacyImplementation::storeUploadedFiles ( )

Implements ilFileDataForumInterface.

Definition at line 180 of file class.ilFileDataForumLegacyImplementation.php.

180  : bool
181  {
182  throw new DomainException('Not implemented');
183  }

◆ unlinkFile()

ilFileDataForumLegacyImplementation::unlinkFile ( string  $filename)

Implements ilFileDataForumInterface.

Definition at line 185 of file class.ilFileDataForumLegacyImplementation.php.

185  : bool
186  {
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);
189  }
190 
191  return false;
192  }
$filename
Definition: buildRTE.php:78

◆ unlinkFilesByMD5Filenames()

ilFileDataForumLegacyImplementation::unlinkFilesByMD5Filenames (   $hashed_filename_or_filenames)
Parameters
string|string[]$hashed_filename_or_filenames

Implements ilFileDataForumInterface.

Definition at line 216 of file class.ilFileDataForumLegacyImplementation.php.

References ilFileUtils\getDir().

216  : bool
217  {
218  $files = ilFileUtils::getDir($this->forum_path);
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']);
223  }
224  }
225 
226  return true;
227  }
228 
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']);
232  }
233  }
234 
235  return false;
236  }
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

◆ $error

ilErrorHandling ilFileDataForumLegacyImplementation::$error
private

◆ $forum_path

string ilFileDataForumLegacyImplementation::$forum_path
private

Definition at line 25 of file class.ilFileDataForumLegacyImplementation.php.

Referenced by getForumPath().

◆ $main_tpl

ilGlobalTemplateInterface ilFileDataForumLegacyImplementation::$main_tpl
private

◆ FORUM_PATH

const ilFileDataForumLegacyImplementation::FORUM_PATH = 'forum'
private

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