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 @access private More...
 
 __initDirectory ()
 init directory overwritten method @access 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 @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 = ''
 

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.

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 @access public

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

+ Here is the call graph for this function:

Member Function Documentation

◆ __checkPath()

ilFileDataForumDrafts::__checkPath ( )

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

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

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)

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

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

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

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

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

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

+ Here is the call graph for this function:

◆ createZipFile()

ilFileDataForumDrafts::createZipFile ( )
Returns
null|string

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

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 zip($a_dir, $a_file, $compress_content=false)

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

+ Here is the call graph for this function:

◆ delete()

ilFileDataForumDrafts::delete ( )
Returns
bool

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

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

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

406 {
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 }
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.
global $lng
Definition: privfeed.php:17

References $lng, ilFile\$path, ilUtil\deliverFile(), getFileDataByMD5Filename(), 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 250 of file class.ilFileDataForumDrafts.php.

251 {
252 return $this->getDraftsPath().'/'.$this->getDraftId();
253 }

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

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

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

40 {
41 return $this->obj_id;
42 }

References $obj_id.

◆ moveFilesOfDraft()

ilFileDataForumDrafts::moveFilesOfDraft (   $forum_path,
  $new_post_id 
)

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

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 }

References $file.

◆ setDraftId()

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

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

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

References $draft_id.

◆ setObjId()

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

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

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

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

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 }
$error
Definition: Error.php:17
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static _sanitizeFilemame($a_filename)

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

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

238 {
239 if(file_exists($this->getDraftsPath().'/'.$this->getDraftId().'/'.$a_filename))
240 {
241 return unlink($this->getDraftsPath().'/'.$this->getDraftId().'/'.$a_filename);
242 }
243 }

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

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'

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

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 }

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

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