ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 14 of file class.ilFileDataForumDrafts.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

23 {
24 global $DIC;
25 $this->lng = $DIC->language();
26 $this->error = $DIC['ilErr'];
27
28 $this->obj_id = $obj_id;
29 $this->draft_id = $draft_id;
30
31 define('FORUM_DRAFTS_PATH', 'forum/drafts');
32 parent::__construct();
33 $this->drafts_path = parent::getPath() . "/" . FORUM_DRAFTS_PATH;
34
35 // IF DIRECTORY ISN'T CREATED CREATE IT
36 if (!$this->__checkPath()) {
37 $this->__initDirectory();
38 }
39 }
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 316 of file class.ilFileDataForumDrafts.php.

317 {
318 if (!@file_exists($this->getDraftsPath() . '/' . $this->getDraftId())) {
319 return false;
320 }
321 $this->__checkReadWrite();
322
323 return true;
324 }
__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 331 of file class.ilFileDataForumDrafts.php.

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

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

346 {
347 if (is_writable($this->getPath())) {
348 if (ilUtil::makeDirParents($this->getDraftsPath() . "/" . $this->getDraftId())) {
349 if (chmod($this->getDraftsPath() . "/" . $this->getDraftId(), 0755)) {
350 return true;
351 }
352 }
353 }
354 return false;
355 }
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 363 of file class.ilFileDataForumDrafts.php.

364 {
365 if (file_exists($a_path)) {
366 $this->__rotateFiles($a_path . ".old");
367 return \ilFileUtils::rename($a_path, $a_path . '.old');
368 }
369 return true;
370 }
__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 302 of file class.ilFileDataForumDrafts.php.

303 {
304 if ($a_files) {
305 foreach ($a_files as $file) {
306 if (!file_exists($this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $file)) {
307 return false;
308 }
309 }
310 return true;
311 }
312 return true;
313 }
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file

References $file, getDraftId(), and getDraftsPath().

+ Here is the call graph for this function:

◆ createZipFile()

ilFileDataForumDrafts::createZipFile ( )
Returns
null|string

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

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

References $file, 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 152 of file class.ilFileDataForumDrafts.php.

153 {
154 ilUtil::delDir($this->getDraftsPath() . '/' . $this->getDraftId());
155 return true;
156 }
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 376 of file class.ilFileDataForumDrafts.php.

377 {
378 if (!$path = $this->getFileDataByMD5Filename($file)) {
379 return ilUtil::sendFailure($this->lng->txt('error_reading_file'), true);
380 } else {
381 return ilUtil::deliverFile($path['path'], $path['clean_filename']);
382 }
383 }
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 385 of file class.ilFileDataForumDrafts.php.

386 {
387 $zip_file = $this->createZipFile();
388 if (!$zip_file) {
389 ilUtil::sendFailure($this->lng->txt('error_reading_file'), true);
390 return false;
391 } else {
393 ilUtil::deliverFile($zip_file, $post->getPostSubject() . '.zip', '', false, true, false);
394 ilUtil::delDir($this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId());
395 exit();
396 }
397 }
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 241 of file class.ilFileDataForumDrafts.php.

242 {
243 return $this->getDraftsPath() . '/' . $this->getDraftId();
244 }

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

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

References $file, $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 44 of file class.ilFileDataForumDrafts.php.

45 {
46 return $this->obj_id;
47 }

References $obj_id.

◆ moveFilesOfDraft()

ilFileDataForumDrafts::moveFilesOfDraft (   $forum_path,
  $new_post_id 
)

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

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

References $file.

◆ setDraftId()

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

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

69 {
70 $this->draft_id = $draft_id;
71 }

References $draft_id.

◆ setObjId()

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

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

53 {
54 $this->obj_id = $obj_id;
55 }

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

168 {
169 if (isset($files['name']) && is_array($files['name'])) {
170 foreach ($files['name'] as $index => $name) {
171 // remove trailing '/'
172 while (substr($name, -1) == '/') {
173 $name = substr($name, 0, -1);
174 }
176 $temp_name = $files['tmp_name'][$index];
177 $error = $files['error'][$index];
178
179 if (strlen($filename) && strlen($temp_name) && $error == 0) {
180 $path = $this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $filename;
181
182 $this->__rotateFiles($path);
183 ilUtil::moveUploadedFile($temp_name, $filename, $path);
184 }
185 }
186
187 return true;
188 } elseif (isset($files['name']) && is_string($files['name'])) {
189 // remove trailing '/'
190 while (substr($files['name'], -1) == '/') {
191 $files['name'] = substr($files['name'], 0, -1);
192 }
194 $temp_name = $files['tmp_name'];
195
196 $path = $this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $filename;
197
198 $this->__rotateFiles($path);
199 ilUtil::moveUploadedFile($temp_name, $filename, $path);
200
201 return true;
202 }
203
204 return false;
205 }
static _sanitizeFilemame($a_filename)
if($format !==null) $name
Definition: metadata.php:146
$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 229 of file class.ilFileDataForumDrafts.php.

230 {
231 if (file_exists($this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $a_filename)) {
232 return unlink($this->getDraftsPath() . '/' . $this->getDraftId() . '/' . $a_filename);
233 }
234 }

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

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

References $file, and 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 274 of file class.ilFileDataForumDrafts.php.

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

References $file, $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 17 of file class.ilFileDataForumDrafts.php.

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

◆ $drafts_path

ilFileDataForumDrafts::$drafts_path = ''
protected

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

Referenced by getDraftsPath().

◆ $error

ilFileDataForumDrafts::$error
private

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

Referenced by storeUploadedFile().

◆ $lng

ilFileDataForumDrafts::$lng
private

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

◆ $obj_id

ilFileDataForumDrafts::$obj_id = 0
protected

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

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


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