ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 private More...
 
 __initDirectory ()
 init directory overwritten method public More...
 
 __rotateFiles ($a_path)
 rotate files with same name recursive method More...
 
 deliverFile ($file)
 
 createZipFile ()
 
- Public Member Functions inherited from ilFileData
 __construct ()
 Constructor class bas constructor and read path of directory from ilias.ini setup an mail object public. More...
 
 checkPath ($a_path)
 check if path exists and is writable More...
 
 getPath ()
 get Path public More...
 
- Public Member Functions inherited from ilFile
 __construct ()
 Constructor get ilias object public. More...
 
 deleteTrailingSlash ($a_path)
 delete trailing slash of path variables More...
 

Protected Attributes

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

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

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

21  {
22  $this->obj_id = $obj_id;
23  $this->draft_id = $draft_id;
24 
25  define('FORUM_DRAFTS_PATH', 'forum/drafts');
26  parent::__construct();
27  $this->drafts_path = parent::getPath()."/".FORUM_DRAFTS_PATH;
28 
29  // IF DIRECTORY ISN'T CREATED CREATE IT
30  if(!$this->__checkPath())
31  {
32  $this->__initDirectory();
33  }
34  }
__initDirectory()
init directory overwritten method public
+ Here is the call graph for this function:

Member Function Documentation

◆ __checkPath()

ilFileDataForumDrafts::__checkPath ( )

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

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

Referenced by __construct().

338  {
339  if(!@file_exists($this->getDraftsPath().'/'.$this->getDraftId()))
340  {
341  return false;
342  }
343  $this->__checkReadWrite();
344 
345  return true;
346  }
__checkReadWrite()
check if directory is writable overwritten method from base class private
+ 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 private

Returns
bool

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

References getDraftId(), and getDraftsPath().

Referenced by __checkPath().

354  {
355  if(is_writable($this->getDraftsPath().'/'.$this->getDraftId()) && is_readable($this->getDraftsPath().'/'.$this->getDraftId()))
356  {
357  return true;
358  }
359  else
360  {
361  $this->ilias->raiseError("Forum directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
362  }
363  }
redirection script todo: (a better solution should control the processing via a xml file) ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __initDirectory()

ilFileDataForumDrafts::__initDirectory ( )

init directory overwritten method public

Returns
string path

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

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

Referenced by __construct().

371  {
372  if(is_writable($this->getPath()))
373  {
374  if(ilUtil::makeDirParents($this->getDraftsPath()."/".$this->getDraftId()))
375  {
376  if(chmod($this->getDraftsPath()."/".$this->getDraftId(),0755))
377  {
378  return true;
379  }
380  }
381  }
382  return false;
383  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
getPath()
get Path public
+ 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 private
Returns
bool

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

Referenced by storeUploadedFile().

392  {
393  if(file_exists($a_path))
394  {
395  $this->__rotateFiles($a_path.".old");
396  return \ilFileUtils::rename($a_path, $a_path . '.old');
397  }
398  return true;
399  }
__rotateFiles($a_path)
rotate files with same name recursive method
+ Here is the caller graph for this function:

◆ checkFilesExist()

ilFileDataForumDrafts::checkFilesExist (   $a_files)

check if files exist

Parameters
arrayfilenames to check public
Returns
bool

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

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

321  {
322  if($a_files)
323  {
324  foreach($a_files as $file)
325  {
326  if(!file_exists($this->getDraftsPath().'/'.$this->getDraftId().'/'.$file))
327  {
328  return false;
329  }
330  }
331  return true;
332  }
333  return true;
334  }
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

◆ createZipFile()

ilFileDataForumDrafts::createZipFile ( )
Returns
null|string

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

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

Referenced by deliverFile().

444  {
445  $filesOfDraft = $this->getFilesOfPost();
446  if(count($filesOfDraft))
447  {
448  ksort($filesOfDraft);
449 
450  ilUtil::makeDirParents($this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId());
451  $tmp_dir = $this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId();
452  foreach($filesOfDraft as $file)
453  {
454  @copy($file['path'], $tmp_dir . '/' . $file['name']);
455  }
456  }
457 
458  $zip_file = null;
459  if(ilUtil::zip($tmp_dir, $this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId() . '.zip'))
460  {
461  $zip_file = $this->getDraftsPath() . '/drafts_zip/' . $this->getDraftId() . '.zip';
462  }
463 
464  return $zip_file;
465  }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilFileDataForumDrafts::delete ( )
Returns
bool

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

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

Referenced by ilObjForumGUI\deleteSelectedDraft(), and ilObjForumGUI\deleteThreadDraftsObject().

151  {
152  ilUtil::delDir($this->getDraftsPath().'/'.$this->getDraftId());
153  return true;
154  }
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deliverFile()

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

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

References $file, $ilUser, $lng, ilFile\$path, createZipFile(), ilUtil\delDir(), ilUtil\deliverFile(), exit, getDraftId(), getDraftsPath(), getFileDataByMD5Filename(), and ilUtil\sendFailure().

406  {
407  if(!$path = $this->getFileDataByMD5Filename($file))
408  {
409  global $lng;
410  return ilUtil::sendFailure($lng->txt('error_reading_file'), true);
411  }
412  else
413  {
414  return ilUtil::deliverFile($path['path'], $path['clean_filename']);
415  }
416  }
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
getFileDataByMD5Filename($a_md5_filename)
get file data of a specific attachment
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $lng
Definition: privfeed.php:17
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

◆ getAbsolutePath()

ilFileDataForumDrafts::getAbsolutePath (   $a_path)

get absolute path of filename

Parameters
stringrelative path public
Returns
string absolute path

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

References getDraftId(), and getDraftsPath().

251  {
252  return $this->getDraftsPath().'/'.$this->getDraftId();
253  }
+ Here is the call graph for this function:

◆ getDraftId()

ilFileDataForumDrafts::getDraftId ( )

◆ getDraftsPath()

ilFileDataForumDrafts::getDraftsPath ( )
Returns
string

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

References $drafts_path, $file, $files, array, date, and getDraftId().

Referenced by __checkPath(), __checkReadWrite(), __initDirectory(), checkFilesExist(), createZipFile(), delete(), deliverFile(), getAbsolutePath(), getFileDataByMD5Filename(), storeUploadedFile(), unlinkFile(), and unlinkFilesByMD5Filenames().

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

◆ getFileDataByMD5Filename()

ilFileDataForumDrafts::getFileDataByMD5Filename (   $a_md5_filename)

get file data of a specific attachment

Parameters
stringmd5 encrypted filename public
Returns
array filedata

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

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

Referenced by deliverFile().

262  {
263  $files = ilUtil::getDir( $this->getDraftsPath().'/'.$this->getDraftId() );
264  foreach((array)$files as $file)
265  {
266  if($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename)
267  {
268  return array(
269  'path' => $this->getDraftsPath().'/'.$this->getDraftId().'/'.$file['entry'],
270  'filename' => $file['entry'],
271  'clean_filename' => $file['entry']
272  );
273  }
274  }
275 
276  return false;
277  }
$files
Definition: add-vimline.php:18
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
Create styles array
The data for the language used.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getObjId()

ilFileDataForumDrafts::getObjId ( )
Returns
int

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

References $obj_id.

◆ moveFilesOfDraft()

ilFileDataForumDrafts::moveFilesOfDraft (   $forum_path,
  $new_post_id 
)

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

References $file.

138  {
139  foreach($this->getFilesOfPost() as $file)
140  {
141  @copy($file['path'],
142  $forum_path.'/'.$this->obj_id.'_'.$new_post_id.'_'.$file['name']);
143  }
144  return true;
145  }
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file

◆ setDraftId()

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

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

References $draft_id.

64  {
65  $this->draft_id = $draft_id;
66  }

◆ setObjId()

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

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

References $obj_id.

48  {
49  $this->obj_id = $obj_id;
50  }

◆ storeUploadedFile()

ilFileDataForumDrafts::storeUploadedFile (   $files)

Store uploaded files in filesystem.

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

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

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

Referenced by ilObjForumGUI\restoreFromHistoryObject().

166  {
167  if(isset($files['name']) && is_array($files['name']))
168  {
169  foreach($files['name'] as $index => $name)
170  {
171  // remove trailing '/'
172  while(substr($name, -1) == '/')
173  {
174  $name = substr($name, 0, -1);
175  }
177  $temp_name = $files['tmp_name'][$index];
178  $error = $files['error'][$index];
179 
180  if(strlen($filename) && strlen($temp_name) && $error == 0)
181  {
182  $path = $this->getDraftsPath().'/'.$this->getDraftId().'/'.$filename;
183 
184  $this->__rotateFiles($path);
186  }
187  }
188 
189  return true;
190  }
191  else if(isset($files['name']) && is_string($files['name']))
192  {
193  // remove trailing '/'
194  while(substr($files['name'], -1) == '/')
195  {
196  $files['name'] = substr($files['name'], 0, -1);
197  }
199  $temp_name = $files['tmp_name'];
200 
201  $path = $this->getDraftsPath().'/'.$this->getDraftId().'/'.$filename;
202 
203  $this->__rotateFiles($path);
205 
206  return true;
207  }
208 
209  return false;
210  }
$files
Definition: add-vimline.php:18
$error
Definition: Error.php:17
static _sanitizeFilemame($a_filename)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
__rotateFiles($a_path)
rotate files with same name recursive method
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlinkFile()

ilFileDataForumDrafts::unlinkFile (   $a_filename)

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

Parameters
stringfilename to delete public
Returns
bool

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

References getDraftId(), and getDraftsPath().

Referenced by unlinkFiles().

238  {
239  if(file_exists($this->getDraftsPath().'/'.$this->getDraftId().'/'.$a_filename))
240  {
241  return unlink($this->getDraftsPath().'/'.$this->getDraftId().'/'.$a_filename);
242  }
243  }
+ 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 public
Returns
string error message with filename that couldn't be deleted

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

References $file, and unlinkFile().

218  {
219  if(is_array($a_filenames))
220  {
221  foreach($a_filenames as $file)
222  {
223  if(!$this->unlinkFile($file))
224  {
225  return $file;
226  }
227  }
228  }
229  return '';
230  }
unlinkFile($a_filename)
unlink one uploaded file expects a filename e.g 'foo'
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ 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 public
Returns
boolean status

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

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

286  {
287  $files = ilUtil::getDir( $this->getDraftsPath().'/'.$this->getDraftId() );
288  if(is_array($a_md5_filename))
289  {
290  foreach((array)$files as $file)
291  {
292  if($file['type'] == 'file' && in_array(md5($file['entry']), $a_md5_filename))
293  {
294  unlink( $this->getDraftsPath().'/'.$this->getDraftId().'/'.$file['entry'] );
295  }
296  }
297 
298  return true;
299  }
300  else
301  {
302  foreach((array)$files as $file)
303  {
304  if($file['type'] == 'file' && md5($file['entry']) == $a_md5_filename)
305  {
306  return unlink( $this->getDraftsPath().'/'.$this->getDraftId().'/'.$file['entry'] );
307  }
308  }
309  }
310 
311  return false;
312  }
$files
Definition: add-vimline.php:18
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
Create styles array
The data for the language used.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ 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().

◆ $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: