ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 ($obj_id=0, $draft_id)
 
 getObjId ()
 
 setObjId ($obj_id)
 
 getDraftId ()
 
 setDraftId ($draft_id)
 
 getDraftsPath ()
 
 moveFilesOfDraft ($forum_path, $new_post_id)
 
 delete ()
 
 storeUploadedFile ($files)
 Store uploaded files in filesystem. More...
 
 unlinkFiles ($a_filenames)
 unlink files: expects an array of filenames e.g. More...
 
 unlinkFile ($a_filename)
 unlink one uploaded file expects a filename e.g 'foo' More...
 
 getAbsolutePath ($a_path)
 get absolute path of filename More...
 
 getFileDataByMD5Filename ($a_md5_filename)
 get file data of a specific attachment More...
 
 unlinkFilesByMD5Filenames ($a_md5_filename)
 get file data of a specific attachment More...
 
 checkFilesExist ($a_files)
 check if files exist More...
 
 __checkPath ()
 
 __checkReadWrite ()
 check if directory is writable overwritten method from base class @access private More...
 
 __initDirectory ()
 init directory overwritten method @access public More...
 
 __rotateFiles ($a_path)
 rotate files with same name recursive method More...
 
 deliverFile ($file)
 
 deliverZipFile ()
 
 createZipFile ()
 
- Public Member Functions inherited from ilFileData
 __construct ()
 Constructor class bas constructor and read path of directory from ilias.ini setup an mail object @access public. More...
 
 checkPath ($a_path)
 check if path exists and is writable More...
 
 getPath ()
 get Path @access public More...
 
- Public Member Functions inherited from ilFile
 __construct ()
 Constructor get ilias object @access public. More...
 
 deleteTrailingSlash ($a_path)
 delete trailing slash of path variables More...
 

Protected Attributes

 $obj_id = 0
 
 $draft_id = 0
 
 $drafts_path = ''
 

Private Attributes

 $lng
 
 $error
 

Additional Inherited Members

- Data Fields inherited from ilFile
 $path
 
 $ilias
 

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 11 of file class.ilFileDataForumDrafts.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileDataForumDrafts::__construct (   $obj_id = 0,
  $draft_id 
)

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

20 {
21 global $DIC;
22 $this->lng = $DIC->language();
23 $this->error = $DIC['ilErr'];
24
25 $this->obj_id = $obj_id;
26 $this->draft_id = $draft_id;
27
28 define('FORUM_DRAFTS_PATH', 'forum/drafts');
29 parent::__construct();
30 $this->drafts_path = parent::getPath() . "/" . FORUM_DRAFTS_PATH;
31
32 // IF DIRECTORY ISN'T CREATED CREATE IT
33 if (!$this->__checkPath()) {
34 $this->__initDirectory();
35 }
36 }
error($a_errmsg)
set error message @access public
__initDirectory()
init directory overwritten method @access public
global $DIC
Definition: saml.php:7

References $DIC, $draft_id, $obj_id, __checkPath(), __initDirectory(), and error().

+ Here is the call graph for this function:

Member Function Documentation

◆ __checkPath()

ilFileDataForumDrafts::__checkPath ( )

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

314 {
315 if (!@file_exists($this->getDraftsPath() . '/' . $this->getDraftId())) {
316 return false;
317 }
318 $this->__checkReadWrite();
319
320 return true;
321 }
__checkReadWrite()
check if directory is writable overwritten method from base class @access private

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 ( )

check if directory is writable overwritten method from base class @access private

Returns
bool

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

329 {
330 if (is_writable($this->getDraftsPath() . '/' . $this->getDraftId()) && is_readable($this->getDraftsPath() . '/' . $this->getDraftId())) {
331 return true;
332 } else {
333 $this->error->raiseError("Forum directory is not readable/writable by webserver", $this->error->FATAL);
334 }
335 }

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

Referenced by __checkPath().

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

◆ __initDirectory()

ilFileDataForumDrafts::__initDirectory ( )

init directory overwritten method @access public

Returns
string path

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

343 {
344 if (is_writable($this->getPath())) {
345 if (ilUtil::makeDirParents($this->getDraftsPath() . "/" . $this->getDraftId())) {
346 if (chmod($this->getDraftsPath() . "/" . $this->getDraftId(), 0755)) {
347 return true;
348 }
349 }
350 }
351 return false;
352 }
getPath()
get Path @access public
static makeDirParents($a_dir)
Create a new directory and all parent directories.

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

Referenced by __construct().

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

◆ __rotateFiles()

ilFileDataForumDrafts::__rotateFiles (   $a_path)

rotate files with same name recursive method

Parameters
stringfilename @access private
Returns
bool

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

361 {
362 if (file_exists($a_path)) {
363 $this->__rotateFiles($a_path . ".old");
364 return \ilFileUtils::rename($a_path, $a_path . '.old');
365 }
366 return true;
367 }
__rotateFiles($a_path)
rotate files with same name recursive method

References __rotateFiles().

Referenced by __rotateFiles(), and storeUploadedFile().

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

◆ checkFilesExist()

ilFileDataForumDrafts::checkFilesExist (   $a_files)

check if files exist

Parameters
arrayfilenames to check @access public
Returns
bool

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

300 {
301 if ($a_files) {
302 foreach ($a_files as $file) {
303 if (!file_exists($this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $file)) {
304 return false;
305 }
306 }
307 return true;
308 }
309 return true;
310 }

References getDraftId(), and getDraftsPath().

+ Here is the call graph for this function:

◆ createZipFile()

ilFileDataForumDrafts::createZipFile ( )
Returns
null|string

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

400 {
401 $filesOfDraft = $this->getFilesOfPost();
402 if (count($filesOfDraft)) {
403 ksort($filesOfDraft);
404
405 ilUtil::makeDirParents($this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId());
406 $tmp_dir = $this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId();
407 foreach ($filesOfDraft as $file) {
408 @copy($file['path'], $tmp_dir . '/' . $file['name']);
409 }
410 }
411
412 $zip_file = null;
413 if (ilUtil::zip($tmp_dir, $this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId() . '.zip')) {
414 $zip_file = $this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId() . '.zip';
415 }
416
417 return $zip_file;
418 }
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file

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

Referenced by deliverZipFile().

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

◆ delete()

ilFileDataForumDrafts::delete ( )
Returns
bool

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

150 {
151 ilUtil::delDir($this->getDraftsPath() . '/' . $this->getDraftId());
152 return true;
153 }
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively

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

+ Here is the call graph for this function:

◆ deliverFile()

ilFileDataForumDrafts::deliverFile (   $file)
Parameters
$file$_GET['file']
Returns
bool|void

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

374 {
375 if (!$path = $this->getFileDataByMD5Filename($file)) {
376 return ilUtil::sendFailure($this->lng->txt('error_reading_file'), true);
377 } else {
378 return ilUtil::deliverFile($path['path'], $path['clean_filename']);
379 }
380 }
getFileDataByMD5Filename($a_md5_filename)
get file data of a specific attachment
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.

References ilFile\$path, ilUtil\deliverFile(), getFileDataByMD5Filename(), and ilUtil\sendFailure().

+ Here is the call graph for this function:

◆ deliverZipFile()

ilFileDataForumDrafts::deliverZipFile ( )

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

383 {
384 $zip_file = $this->createZipFile();
385 if (!$zip_file) {
386 ilUtil::sendFailure($this->lng->txt('error_reading_file'), true);
387 return false;
388 } else {
390 ilUtil::deliverFile($zip_file, $post->getPostSubject() . '.zip', '', false, true, false);
391 ilUtil::delDir($this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId());
392 exit();
393 }
394 }
exit
Definition: backend.php:16
static newInstanceByDraftId($draft_id)
$post
Definition: post.php:34

References $post, createZipFile(), ilUtil\delDir(), ilUtil\deliverFile(), exit, getDraftId(), getDraftsPath(), ilForumPostDraft\newInstanceByDraftId(), and ilUtil\sendFailure().

+ Here is the call graph for this function:

◆ getAbsolutePath()

ilFileDataForumDrafts::getAbsolutePath (   $a_path)

get absolute path of filename

Parameters
stringrelative path @access public
Returns
string absolute path

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

239 {
240 return $this->getDraftsPath() . '/' . $this->getDraftId();
241 }

References getDraftId(), and getDraftsPath().

+ Here is the call graph for this function:

◆ getDraftId()

ilFileDataForumDrafts::getDraftId ( )

◆ getDraftsPath()

ilFileDataForumDrafts::getDraftsPath ( )

◆ getFileDataByMD5Filename()

ilFileDataForumDrafts::getFileDataByMD5Filename (   $a_md5_filename)

get file data of a specific attachment

Parameters
stringmd5 encrypted filename @access public
Returns
array filedata

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

250 {
251 $files = ilUtil::getDir($this->getDraftsPath() . '/' . $this->getDraftId());
252 foreach ((array) $files as $file) {
253 if ($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename) {
254 return array(
255 'path' => $this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $file['entry'],
256 'filename' => $file['entry'],
257 'clean_filename' => $file['entry']
258 );
259 }
260 }
261
262 return false;
263 }
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
$files
Definition: metarefresh.php:49

References $files, ilUtil\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 ( )
Returns
int

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

42 {
43 return $this->obj_id;
44 }

References $obj_id.

◆ moveFilesOfDraft()

ilFileDataForumDrafts::moveFilesOfDraft (   $forum_path,
  $new_post_id 
)

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

136 {
137 foreach ($this->getFilesOfPost() as $file) {
138 @copy(
139 $file['path'],
140 $forum_path . '/' . $this->obj_id . '_' . $new_post_id . '_' . $file['name']
141 );
142 }
143 return true;
144 }

◆ setDraftId()

ilFileDataForumDrafts::setDraftId (   $draft_id)
Parameters
int$draft_id

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

66 {
67 $this->draft_id = $draft_id;
68 }

References $draft_id.

◆ setObjId()

ilFileDataForumDrafts::setObjId (   $obj_id)
Parameters
int$obj_id

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

50 {
51 $this->obj_id = $obj_id;
52 }

References $obj_id.

◆ storeUploadedFile()

ilFileDataForumDrafts::storeUploadedFile (   $files)

Store uploaded files in filesystem.

Parameters
array$filesCopy of $_FILES array, @access public
Returns
bool

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

165 {
166 if (isset($files['name']) && is_array($files['name'])) {
167 foreach ($files['name'] as $index => $name) {
168 // remove trailing '/'
169 while (substr($name, -1) == '/') {
170 $name = substr($name, 0, -1);
171 }
173 $temp_name = $files['tmp_name'][$index];
174 $error = $files['error'][$index];
175
176 if (strlen($filename) && strlen($temp_name) && $error == 0) {
177 $path = $this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $filename;
178
179 $this->__rotateFiles($path);
180 ilUtil::moveUploadedFile($temp_name, $filename, $path);
181 }
182 }
183
184 return true;
185 } elseif (isset($files['name']) && is_string($files['name'])) {
186 // remove trailing '/'
187 while (substr($files['name'], -1) == '/') {
188 $files['name'] = substr($files['name'], 0, -1);
189 }
191 $temp_name = $files['tmp_name'];
192
193 $path = $this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $filename;
194
195 $this->__rotateFiles($path);
196 ilUtil::moveUploadedFile($temp_name, $filename, $path);
197
198 return true;
199 }
200
201 return false;
202 }
$filename
Definition: buildRTE.php:89
static _sanitizeFilemame($a_filename)
$index
Definition: metadata.php:60

References $error, $filename, $files, $index, $name, ilFile\$path, __rotateFiles(), ilUtil\_sanitizeFilemame(), getDraftId(), and getDraftsPath().

+ Here is the call graph for this function:

◆ unlinkFile()

ilFileDataForumDrafts::unlinkFile (   $a_filename)

unlink one uploaded file expects a filename e.g 'foo'

Parameters
stringfilename to delete @access public
Returns
bool

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

227 {
228 if (file_exists($this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $a_filename)) {
229 return unlink($this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $a_filename);
230 }
231 }

References getDraftId(), and getDraftsPath().

Referenced by unlinkFiles().

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

◆ unlinkFiles()

ilFileDataForumDrafts::unlinkFiles (   $a_filenames)

unlink files: expects an array of filenames e.g.

array('foo','bar')

Parameters
arrayfilenames to delete @access public
Returns
string error message with filename that couldn't be deleted

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

210 {
211 if (is_array($a_filenames)) {
212 foreach ($a_filenames as $file) {
213 if (!$this->unlinkFile($file)) {
214 return $file;
215 }
216 }
217 }
218 return '';
219 }
unlinkFile($a_filename)
unlink one uploaded file expects a filename e.g 'foo'

References unlinkFile().

+ Here is the call graph for this function:

◆ unlinkFilesByMD5Filenames()

ilFileDataForumDrafts::unlinkFilesByMD5Filenames (   $a_md5_filename)

get file data of a specific attachment

Parameters
string|arraymd5 encrypted filename or array of multiple md5 encrypted files @access public
Returns
boolean status

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

272 {
273 $files = ilUtil::getDir($this->getDraftsPath() . '/' . $this->getDraftId());
274 if (is_array($a_md5_filename)) {
275 foreach ((array) $files as $file) {
276 if ($file['type'] == 'file' && in_array(md5($file['entry']), $a_md5_filename)) {
277 unlink($this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $file['entry']);
278 }
279 }
280
281 return true;
282 } else {
283 foreach ((array) $files as $file) {
284 if ($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename) {
285 return unlink($this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $file['entry']);
286 }
287 }
288 }
289
290 return false;
291 }

References $files, ilUtil\getDir(), getDraftId(), and getDraftsPath().

+ Here is the call graph for this function:

Field Documentation

◆ $draft_id

ilFileDataForumDrafts::$draft_id = 0
protected

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

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

◆ $drafts_path

ilFileDataForumDrafts::$drafts_path = ''
protected

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

Referenced by getDraftsPath().

◆ $error

ilFileDataForumDrafts::$error
private

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

Referenced by storeUploadedFile().

◆ $lng

ilFileDataForumDrafts::$lng
private

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

◆ $obj_id

ilFileDataForumDrafts::$obj_id = 0
protected

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

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


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