ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilFileSystemGUI Class Reference

File System Explorer GUI class. More...

+ Collaboration diagram for ilFileSystemGUI:

Public Member Functions

 __construct ($a_main_directory)
 
 setAllowedSuffixes ($a_suffixes)
 Set allowed Suffixes. More...
 
 getAllowedSuffixes ()
 Get allowed Suffixes. More...
 
 setForbiddenSuffixes ($a_suffixes)
 Set forbidden Suffixes. More...
 
 getForbiddenSuffixes ()
 Get Accepted Suffixes. More...
 
 isValidSuffix ($a_suffix)
 Is suffix valid? More...
 
 setAllowDirectories ($a_val)
 Set allow directories. More...
 
 getAllowDirectories ()
 Get allow directories. More...
 
 setPostDirPath ($a_val)
 Set post dir path. More...
 
 getPostDirPath ()
 Get post dir path. More...
 
 setTableId ($a_val)
 Set table id. More...
 
 getTableId ()
 Get table id. More...
 
 setTitle ($a_val)
 Set title. More...
 
 getTitle ()
 Get title. More...
 
 setUseUploadDirectory ($a_val)
 Set use upload directory. More...
 
 getUseUploadDirectory ()
 Get use upload directory. More...
 
 getLastPerformedCommand ()
 Get performed command. More...
 
 executeCommand ()
 execute command More...
 
 addCommand (&$a_obj, $a_func, $a_name, $a_single=true, $a_allow_dir=false)
 Add command. More...
 
 clearCommands ()
 Clear commands. More...
 
 labelFile ($a_file, $a_label)
 label a file More...
 
 activateLabels ($a_act, $a_label_header)
 activate file labels More...
 
 extCommand ($a_nr)
 call external command More...
 
 setAllowDirectoryCreation ($a_val)
 Set allowed directory creation. More...
 
 getAllowDirectoryCreation ()
 Get allowed directory creation. More...
 
 setAllowFileCreation ($a_val)
 Set allowed file creation. More...
 
 getAllowFileCreation ()
 Get allowed file creation. More...
 
 listFiles ()
 list files More...
 
 renameFileForm ($a_file)
 list files More...
 
 renameFile ()
 rename a file More...
 
 cancelRename ()
 cancel renaming a file More...
 
 createDirectory ()
 create directory More...
 
 uploadFile ()
 upload file More...
 
 confirmDeleteFile (array $a_files)
 Confirm file deletion. More...
 
 deleteFile ()
 delete object file More...
 
 unzipFile ($a_file=null)
 delete object file More...
 
 downloadFile ($a_file)
 delete object file More...
 
 getTabs (&$tabs_gui)
 get tabs More...
 

Data Fields

 $ctrl
 

Protected Member Functions

 setPerformedCommand ($command, $pars="")
 Set performed command. More...
 
 parseCurrentDirectory ()
 
 getFileList ($a_dir, $a_subdir=null)
 
 getIncomingFiles ()
 

Protected Attributes

 $use_upload_directory = false
 
 $allowed_suffixes = array()
 
 $forbidden_suffixes = array()
 

Detailed Description

File System Explorer GUI class.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 12 of file class.ilFileSystemGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileSystemGUI::__construct (   $a_main_directory)

Definition at line 28 of file class.ilFileSystemGUI.php.

29 {
30 global $lng, $ilCtrl, $tpl, $ilias;
31
32 $this->ctrl = $ilCtrl;
33 $this->lng = $lng;
34 $this->ilias = $ilias;
35 $this->tpl = $tpl;
36 $this->main_dir = $a_main_directory;
37 $this->post_dir_path = false;
38 $this->commands = array(
39 0 => array(
40 "object" => $this,
41 "method" => "downloadFile",
42 "name" => $lng->txt("download"),
43 "int" => true,
44 "single" => true
45 ),
46 1 => array(
47 "object" => $this,
48 "method" => "confirmDeleteFile",
49 "name" => $lng->txt("delete"),
50 "allow_dir" => true,
51 "int" => true
52 ),
53 2 => array(
54 "object" => $this,
55 "method" => "unzipFile",
56 "name" => $lng->txt("unzip"),
57 "int" => true,
58 "single" => true
59 ),
60 3 => array(
61 "object" => $this,
62 "method" => "renameFileForm",
63 "name" => $lng->txt("rename"),
64 "allow_dir" => true,
65 "int" => true,
66 "single" => true
67 ),
68 );
69
70 $this->file_labels = array();
71 $this->label_enable = false;
72 $this->ctrl->saveParameter($this, "cdir");
73 $lng->loadLanguageModule("content");
74 $this->setAllowDirectories(true);
75 $this->setAllowDirectoryCreation(true);
76 $this->setAllowFileCreation(true);
77//echo "<br>main_dir:".$this->main_dir.":";
78 }
global $tpl
Definition: ilias.php:8
setAllowDirectories($a_val)
Set allow directories.
setAllowFileCreation($a_val)
Set allowed file creation.
setAllowDirectoryCreation($a_val)
Set allowed directory creation.
global $ilCtrl
Definition: ilias.php:18
redirection script todo: (a better solution should control the processing via a xml file)
global $lng
Definition: privfeed.php:17

References $ilCtrl, $lng, $tpl, setAllowDirectories(), setAllowDirectoryCreation(), and setAllowFileCreation().

+ Here is the call graph for this function:

Member Function Documentation

◆ activateLabels()

ilFileSystemGUI::activateLabels (   $a_act,
  $a_label_header 
)

activate file labels

Definition at line 335 of file class.ilFileSystemGUI.php.

336 {
337 $this->label_enable = $a_act;
338 $this->label_header = $a_label_header;
339 }

◆ addCommand()

ilFileSystemGUI::addCommand ( $a_obj,
  $a_func,
  $a_name,
  $a_single = true,
  $a_allow_dir = false 
)

Add command.

Definition at line 302 of file class.ilFileSystemGUI.php.

304 {
305 $i = count($this->commands);
306
307 $this->commands[$i]["object"] = $a_obj;
308 $this->commands[$i]["method"] = $a_func;
309 $this->commands[$i]["name"] = $a_name;
310 $this->commands[$i]["single"] = $a_single;
311 $this->commands[$i]["allow_dir"] = $a_allow_dir;
312
313 //$this->commands[] = $arr;
314 }

◆ cancelRename()

ilFileSystemGUI::cancelRename ( )

cancel renaming a file

Definition at line 705 of file class.ilFileSystemGUI.php.

706 {
707 $this->ctrl->redirect($this, "listFiles");
708 }

◆ clearCommands()

ilFileSystemGUI::clearCommands ( )

Clear commands.

Definition at line 319 of file class.ilFileSystemGUI.php.

320 {
321 $this->commands = array();
322 }

◆ confirmDeleteFile()

ilFileSystemGUI::confirmDeleteFile ( array  $a_files)

Confirm file deletion.

Definition at line 827 of file class.ilFileSystemGUI.php.

828 {
829 global $ilCtrl, $tpl, $lng;
830
831 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
832 $cgui = new ilConfirmationGUI();
833 $cgui->setFormAction($ilCtrl->getFormAction($this));
834 $cgui->setHeaderText($lng->txt("info_delete_sure"));
835 $cgui->setCancel($lng->txt("cancel"), "listFiles");
836 $cgui->setConfirm($lng->txt("delete"), "deleteFile");
837
838 foreach ($a_files as $i)
839 {
840 $cgui->addItem("file[]", $i, $i);
841 }
842
843 $tpl->setContent($cgui->getHTML());
844 }
Confirmation screen class.

References $ilCtrl, $lng, and $tpl.

◆ createDirectory()

ilFileSystemGUI::createDirectory ( )

create directory

Definition at line 713 of file class.ilFileSystemGUI.php.

714 {
715 global $lng;
716
717 // determine directory
718 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
719 $cur_dir = (!empty($cur_subdir))
720 ? $this->main_dir."/".$cur_subdir
721 : $this->main_dir;
722
723 $new_dir = str_replace(".", "", ilUtil::stripSlashes($_POST["new_dir"]));
724 $new_dir = str_replace("/", "", $new_dir);
725
726 if (!empty($new_dir))
727 {
728 ilUtil::makeDir($cur_dir."/".$new_dir);
729 if (is_dir($cur_dir."/".$new_dir))
730 {
731 ilUtil::sendSuccess($lng->txt("cont_dir_created"), true);
732 $this->setPerformedCommand("create_dir", array("name" => $new_dir));
733 }
734 }
735 else
736 {
737 ilUtil::sendFailure($lng->txt("cont_enter_a_dir_name"), true);
738 }
739 $this->ctrl->saveParameter($this, "cdir");
740 $this->ctrl->redirect($this, "listFiles");
741 }
$_GET["client_id"]
$_POST["username"]
setPerformedCommand($command, $pars="")
Set performed command.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...

References $_GET, $_POST, $lng, ilUtil\makeDir(), ilUtil\sendFailure(), ilUtil\sendSuccess(), setPerformedCommand(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ deleteFile()

ilFileSystemGUI::deleteFile ( )

delete object file

Definition at line 849 of file class.ilFileSystemGUI.php.

850 {
851 global $lng;
852
853 if (!isset($_POST["file"]))
854 {
855 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
856 }
857
858 foreach ($_POST["file"] as $post_file)
859 {
860 if (ilUtil::stripSlashes($post_file) == "..")
861 {
862 $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
863 break;
864 }
865
866 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
867 $cur_dir = (!empty($cur_subdir))
868 ? $this->main_dir."/".$cur_subdir
869 : $this->main_dir;
870 $pi = pathinfo($post_file);
871 $file = $cur_dir."/".ilUtil::stripSlashes($pi["basename"]);
872
873 if (@is_file($file))
874 {
875 unlink($file);
876 }
877
878 if (@is_dir($file))
879 {
880 $is_dir = true;
882 }
883 }
884
885 $this->ctrl->saveParameter($this, "cdir");
886 if ($is_dir)
887 {
888 ilUtil::sendSuccess($lng->txt("cont_dir_deleted"), true);
889 $this->setPerformedCommand("delete_dir",
890 array("name" => ilUtil::stripSlashes($post_file)));
891 }
892 else
893 {
894 ilUtil::sendSuccess($lng->txt("cont_file_deleted"), true);
895 $this->setPerformedCommand("delete_file",
896 array("name" => ilUtil::stripSlashes($post_file)));
897 }
898 $this->ctrl->redirect($this, "listFiles");
899 }
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file

References $_GET, $_POST, $file, $lng, ilUtil\delDir(), ilUtil\sendSuccess(), setPerformedCommand(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ downloadFile()

ilFileSystemGUI::downloadFile (   $a_file)

delete object file

Definition at line 994 of file class.ilFileSystemGUI.php.

995 {
996 $file = $this->main_dir."/".$a_file;
997
998 if (@is_file($file) && !(@is_dir($file)))
999 {
1000 ilUtil::deliverFile($file, basename($a_file));
1001 exit;
1002 }
1003 else
1004 {
1005 $this->ctrl->saveParameter($this, "cdir");
1006 $this->ctrl->redirect($this, "listFiles");
1007 }
1008 }
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.

References $file, ilUtil\deliverFile(), and exit.

+ Here is the call graph for this function:

◆ executeCommand()

ilFileSystemGUI::executeCommand ( )

execute command

Definition at line 275 of file class.ilFileSystemGUI.php.

276 {
277 $next_class = $this->ctrl->getNextClass($this);
278 $cmd = $this->ctrl->getCmd("listFiles");
279
280 switch($next_class)
281 {
282
283 default:
284 if (substr($cmd, 0, 11) == "extCommand_")
285 {
286 $ret = $this->extCommand(substr($cmd, 11, strlen($cmd) - 11));
287 }
288 else
289 {
290 $ret = $this->$cmd();
291 }
292 break;
293 }
294
295 return $ret;
296 }
extCommand($a_nr)
call external command
$ret
Definition: parser.php:6
$cmd
Definition: sahs_server.php:35

References $cmd, $ret, and extCommand().

+ Here is the call graph for this function:

◆ extCommand()

ilFileSystemGUI::extCommand (   $a_nr)

call external command

Definition at line 449 of file class.ilFileSystemGUI.php.

450 {
451 $selected = $this->getIncomingFiles();
452
453 if(!count($selected))
454 {
455 ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
456 $this->ctrl->redirect($this, "listFiles");
457 }
458
459 // check if only one item is select, if command does not allow multiple selection
460 if (count($selected) > 1 && $this->commands[$a_nr]["single"])
461 {
462 ilUtil::sendFailure($this->lng->txt("cont_select_max_one_item"), true);
463 $this->ctrl->redirect($this, "listFiles");
464 }
465
466 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
467
468 // collect files and
469 $files = array();
470 foreach ($selected as $file)
471 {
473 $file = (!empty($cur_subdir))
474 ? $cur_subdir."/".$file
475 : $file;
476
477 // check wether selected item is a directory
478 if (@is_dir($this->main_dir."/".$file) &&
479 !$this->commands[$a_nr]["allow_dir"])
480 {
481 ilUtil::sendFailure($this->lng->txt("select_a_file"), true);
482 $this->ctrl->redirect($this, "listFiles");
483 }
484
485 $files[] = $file;
486 }
487
488 if ($this->commands[$a_nr]["single"])
489 {
490 $files = array_shift($files);
491 }
492
493 $obj = $this->commands[$a_nr]["object"];
494 $method = $this->commands[$a_nr]["method"];
495
496 return $obj->$method($files);
497 }
$files
Definition: add-vimline.php:18
PHPExcel root directory.
Definition: PHPExcel.php:30

References $_GET, $file, $files, getIncomingFiles(), ilUtil\sendFailure(), and ilUtil\stripSlashes().

Referenced by executeCommand().

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

◆ getAllowDirectories()

ilFileSystemGUI::getAllowDirectories ( )

Get allow directories.

Returns
boolean allow directories

Definition at line 159 of file class.ilFileSystemGUI.php.

160 {
161 return $this->allow_directories;
162 }

Referenced by listFiles(), and unzipFile().

+ Here is the caller graph for this function:

◆ getAllowDirectoryCreation()

ilFileSystemGUI::getAllowDirectoryCreation ( )

Get allowed directory creation.

Definition at line 510 of file class.ilFileSystemGUI.php.

511 {
512 return $this->directory_creation;
513 }

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getAllowedSuffixes()

ilFileSystemGUI::getAllowedSuffixes ( )

Get allowed Suffixes.

Returns
array allowed Suffixes

Definition at line 95 of file class.ilFileSystemGUI.php.

References $allowed_suffixes.

Referenced by isValidSuffix().

+ Here is the caller graph for this function:

◆ getAllowFileCreation()

ilFileSystemGUI::getAllowFileCreation ( )

Get allowed file creation.

Definition at line 526 of file class.ilFileSystemGUI.php.

527 {
528 return $this->file_creation;
529 }

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getFileList()

ilFileSystemGUI::getFileList (   $a_dir,
  $a_subdir = null 
)
protected

Definition at line 379 of file class.ilFileSystemGUI.php.

380 {
381 $items = array();
382
383 $entries = (is_dir($a_dir))
384 ? ilUtil::getDir($a_dir)
385 : array(array("type" => "dir", "entry" => ".."));
386
387 $items = array();
388 foreach ($entries as $e)
389 {
390 if(($e["entry"] == ".") ||
391 ($e["entry"] == ".." && empty($a_subdir)))
392 {
393 continue;
394 }
395
396 $cfile = (!empty($a_subdir))
397 ? $a_subdir."/".$e["entry"]
398 : $e["entry"];
399
400 $items[] = array(
401 "file" => $cfile,
402 "entry" => $e["entry"],
403 "type" => $e["type"],
404 "size" => $e["size"],
405 "hash" => md5($e["entry"])
406 );
407 }
408
409 return $items;
410 }
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory

References ilUtil\getDir().

Referenced by getIncomingFiles().

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

◆ getForbiddenSuffixes()

ilFileSystemGUI::getForbiddenSuffixes ( )

Get Accepted Suffixes.

Returns
array forbidden Suffixes

Definition at line 115 of file class.ilFileSystemGUI.php.

References $forbidden_suffixes.

Referenced by isValidSuffix().

+ Here is the caller graph for this function:

◆ getIncomingFiles()

ilFileSystemGUI::getIncomingFiles ( )
protected

Definition at line 412 of file class.ilFileSystemGUI.php.

413 {
414 $sel_files = $hashes = array();
415 if (isset($_POST["file"]))
416 {
417 $hashes = $_POST["file"];
418 }
419 else if(isset($_GET["fhsh"]))
420 {
421 $hashes = array($_GET["fhsh"]);
422 }
423
424 if(sizeof($hashes))
425 {
426 $dir = $this->parseCurrentDirectory();
427 $all_files = $this->getFileList($dir["dir"], $dir["subdir"]);
428 foreach($hashes as $hash)
429 {
430 foreach($all_files as $file)
431 {
432 if($file["hash"] == $hash)
433 {
434 $sel_files[] = $this->getPostDirPath()
435 ? $file["file"]
436 : $file["entry"];
437 break;
438 }
439 }
440 }
441 }
442
443 return $sel_files;
444 }
getPostDirPath()
Get post dir path.
getFileList($a_dir, $a_subdir=null)

References $_GET, $_POST, $file, getFileList(), getPostDirPath(), and parseCurrentDirectory().

Referenced by extCommand().

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

◆ getLastPerformedCommand()

ilFileSystemGUI::getLastPerformedCommand ( )

Get performed command.

Returns
array command array

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

266 {
267 $ret = $_SESSION["fsys"]["lastcomm"];
268 $_SESSION["fsys"]["lastcomm"] = "none";
269 return $ret;
270 }
$_SESSION["AccountId"]

References $_SESSION, and $ret.

◆ getPostDirPath()

ilFileSystemGUI::getPostDirPath ( )

Get post dir path.

Returns
boolean post dir path

Definition at line 179 of file class.ilFileSystemGUI.php.

180 {
181 return $this->post_dir_path;
182 }

Referenced by getIncomingFiles(), and listFiles().

+ Here is the caller graph for this function:

◆ getTableId()

ilFileSystemGUI::getTableId ( )

Get table id.

Returns
string table id

Definition at line 199 of file class.ilFileSystemGUI.php.

200 {
201 return $this->table_id;
202 }

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getTabs()

ilFileSystemGUI::getTabs ( $tabs_gui)

get tabs

Definition at line 1013 of file class.ilFileSystemGUI.php.

1014 {
1015 global $ilCtrl;
1016
1017 $ilCtrl->setParameter($this, "resetoffset", 1);
1018 $tabs_gui->addTarget("cont_list_files",
1019 $this->ctrl->getLinkTarget($this, "listFiles"), "listFiles",
1020 get_class($this));
1021 $ilCtrl->setParameter($this, "resetoffset", "");
1022 }

References $ilCtrl.

◆ getTitle()

ilFileSystemGUI::getTitle ( )

Get title.

Returns
string title

Definition at line 219 of file class.ilFileSystemGUI.php.

220 {
221 return $this->title;
222 }

References $title.

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getUseUploadDirectory()

ilFileSystemGUI::getUseUploadDirectory ( )

Get use upload directory.

Returns
bool use upload directory

Definition at line 239 of file class.ilFileSystemGUI.php.

References $use_upload_directory.

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ isValidSuffix()

ilFileSystemGUI::isValidSuffix (   $a_suffix)

Is suffix valid?

Parameters
string$a_suffix
Returns
bool

Definition at line 126 of file class.ilFileSystemGUI.php.

127 {
128 if (is_array($this->getForbiddenSuffixes()) && in_array($a_suffix, $this->getForbiddenSuffixes()))
129 {
130 return false;
131 }
132 if (is_array($this->getAllowedSuffixes()) && in_array($a_suffix, $this->getAllowedSuffixes()))
133 {
134 return true;
135 }
136 if (!is_array($this->getAllowedSuffixes()) || count($this->getAllowedSuffixes()) == 0)
137 {
138 return true;
139 }
140 return false;
141 }
getAllowedSuffixes()
Get allowed Suffixes.
getForbiddenSuffixes()
Get Accepted Suffixes.

References getAllowedSuffixes(), and getForbiddenSuffixes().

Referenced by renameFile(), unzipFile(), and uploadFile().

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

◆ labelFile()

ilFileSystemGUI::labelFile (   $a_file,
  $a_label 
)

label a file

Definition at line 327 of file class.ilFileSystemGUI.php.

328 {
329 $this->file_labels[$a_file][] = $a_label;
330 }

◆ listFiles()

ilFileSystemGUI::listFiles ( )

list files

Definition at line 534 of file class.ilFileSystemGUI.php.

535 {
536 global $ilToolbar, $lng, $ilCtrl;
537
538 $dir = $this->parseCurrentDirectory();
539
540 $this->ctrl->setParameter($this, "cdir", $dir["subdir"]);
541
542 // toolbar for adding files/directories
543 $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
544 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
545
546 if ($this->getAllowDirectories() && $this->getAllowDirectoryCreation())
547 {
548 $ti = new ilTextInputGUI($this->lng->txt("cont_new_dir"), "new_dir");
549 $ti->setMaxLength(80);
550 $ti->setSize(10);
551 $ilToolbar->addInputItem($ti, true);
552 $ilToolbar->addFormButton($lng->txt("create"), "createDirectory");
553
554 $ilToolbar->addSeparator();
555 }
556
557 include_once("./Services/Form/classes/class.ilFileInputGUI.php");
558 if ($this->getAllowFileCreation())
559 {
560 $fi = new ilFileInputGUI($this->lng->txt("cont_new_file"), "new_file");
561 $fi->setSize(10);
562 $ilToolbar->addInputItem($fi, true);
563 $ilToolbar->addFormButton($lng->txt("upload"), "uploadFile");
564 }
565
566 include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
568 {
569 $ilToolbar->addSeparator();
571 $options[""] = $lng->txt("cont_select_from_upload_dir");
572 foreach($files as $file)
573 {
574 $file = htmlspecialchars($file, ENT_QUOTES, "utf-8");
576 }
577 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
578 $si = new ilSelectInputGUI($this->lng->txt("cont_uploaded_file"), "uploaded_file");
579 $si->setOptions($options);
580 $ilToolbar->addInputItem($si, true);
581 $ilToolbar->addFormButton($lng->txt("copy"), "uploadFile");
582 }
583
584 // load files templates
585 include_once("./Services/FileSystem/classes/class.ilFileSystemTableGUI.php");
586 $fs_table = new ilFileSystemTableGUI($this, "listFiles", $dir["dir"], $dir["subdir"],
587 $this->label_enable, $this->file_labels, $this->label_header, $this->commands,
588 $this->getPostDirPath(), $this->getTableId());
589 if ($this->getTitle() != "")
590 {
591 $fs_table->setTitle($this->getTitle());
592 }
593 if ($_GET["resetoffset"] == 1)
594 {
595 $fs_table->resetOffset();
596 }
597 $this->tpl->setContent($fs_table->getHTML());
598 }
This class represents a file property in a property form.
getUseUploadDirectory()
Get use upload directory.
getAllowDirectoryCreation()
Get allowed directory creation.
getAllowDirectories()
Get allow directories.
getTableId()
Get table id.
getAllowFileCreation()
Get allowed file creation.
TableGUI class for file system.
This class represents a selection list property in a property form.
This class represents a text property in a property form.
static _getUploadFiles()
Get a list of readable files in the upload directory.
static _getUploadDirectory()
Get the directory with uploaded files.
if(!is_array($argv)) $options

References $_GET, $file, $files, $ilCtrl, $lng, $options, $si, ilUploadFiles\_getUploadDirectory(), ilUploadFiles\_getUploadFiles(), getAllowDirectories(), getAllowDirectoryCreation(), getAllowFileCreation(), getPostDirPath(), getTableId(), getTitle(), getUseUploadDirectory(), and parseCurrentDirectory().

+ Here is the call graph for this function:

◆ parseCurrentDirectory()

ilFileSystemGUI::parseCurrentDirectory ( )
protected

Definition at line 343 of file class.ilFileSystemGUI.php.

344 {
345 // determine directory
346 // FIXME: I have to call stripSlashes here twice, because I could not
347 // determine where the second layer of slashes is added to the
348 // URL Parameter
349 $cur_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET["cdir"]));
350 $new_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET["newdir"]));
351
352 if($new_subdir == "..")
353 {
354 $cur_subdir = substr($cur_subdir, 0, strrpos($cur_subdir, "/"));
355 }
356 else
357 {
358 if (!empty($new_subdir))
359 {
360 if (!empty($cur_subdir))
361 {
362 $cur_subdir = $cur_subdir."/".$new_subdir;
363 }
364 else
365 {
366 $cur_subdir = $new_subdir;
367 }
368 }
369 }
370
371 $cur_subdir = str_replace("..", "", $cur_subdir);
372 $cur_dir = (!empty($cur_subdir))
373 ? $this->main_dir."/".$cur_subdir
374 : $this->main_dir;
375
376 return array("dir"=>$cur_dir, "subdir"=>$cur_subdir);
377 }

References $_GET, and ilUtil\stripSlashes().

Referenced by getIncomingFiles(), and listFiles().

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

◆ renameFile()

ilFileSystemGUI::renameFile ( )

rename a file

Definition at line 643 of file class.ilFileSystemGUI.php.

644 {
645 global $lng;
646
647 $new_name = str_replace("..", "", ilUtil::stripSlashes($_POST["new_name"]));
648 $new_name = str_replace("/", "", $new_name);
649 if ($new_name == "")
650 {
651 $this->ilias->raiseError($this->lng->txt("enter_new_name"),$this->ilias->error_obj->MESSAGE);
652 }
653
654 $pi = pathinfo($new_name);
655 $suffix = $pi["extension"];
656 if ($suffix != "" && !$this->isValidSuffix($suffix))
657 {
658 ilUtil::sendFailure($this->lng->txt("file_no_valid_file_type")." ($suffix)", true);
659 $this->ctrl->redirect($this, "listFiles");
660 }
661
662 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
663 $dir = (!empty($cur_subdir))
664 ? $this->main_dir."/".$cur_subdir."/"
665 : $this->main_dir."/";
666
667
668 if (is_dir($dir.ilUtil::stripSlashes($_GET["old_name"])))
669 {
670 rename($dir.ilUtil::stripSlashes($_GET["old_name"]), $dir.$new_name);
671 }
672 else
673 {
674 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
675
676 try
677 {
678 ilFileUtils::rename($dir . ilUtil::stripSlashes($_GET["old_name"]), $dir . $new_name);
679 } catch (ilException $e)
680 {
681 ilUtil::sendFailure($e->getMessage(), true);
682 $this->ctrl->redirect($this, "listFiles");
683 }
684 }
685
686 ilUtil::renameExecutables($this->main_dir);
687 if (@is_dir($dir.$new_name))
688 {
689 ilUtil::sendSuccess($lng->txt("cont_dir_renamed"), true);
690 $this->setPerformedCommand("rename_dir", array("old_name" => $_GET["old_name"],
691 "new_name" => $new_name));
692 }
693 else
694 {
695 ilUtil::sendSuccess($lng->txt("cont_file_renamed"), true);
696 $this->setPerformedCommand("rename_file", array("old_name" => $_GET["old_name"],
697 "new_name" => $new_name));
698 }
699 $this->ctrl->redirect($this, "listFiles");
700 }
Base class for ILIAS Exception handling.
isValidSuffix($a_suffix)
Is suffix valid?
static rename($a_source, $a_target)
Rename a file.
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.

References $_GET, $_POST, $lng, isValidSuffix(), ilFileUtils\rename(), ilUtil\renameExecutables(), ilUtil\sendFailure(), ilUtil\sendSuccess(), setPerformedCommand(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ renameFileForm()

ilFileSystemGUI::renameFileForm (   $a_file)

list files

Definition at line 603 of file class.ilFileSystemGUI.php.

604 {
605 global $lng, $ilCtrl;
606
607 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
608 $file = $this->main_dir."/".$a_file;
609
610 $this->ctrl->setParameter($this, "old_name", basename($a_file));
611 $this->ctrl->setParameter($this, "cdir", ilUtil::stripSlashes($_GET["cdir"]));
612
613 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
614 $form = new ilPropertyFormGUI();
615
616 // file/dir name
617 $ti = new ilTextInputGUI($this->lng->txt("name"), "new_name");
618 $ti->setMaxLength(200);
619 $ti->setSize(40);
620 $ti->setValue(basename($a_file));
621 $form->addItem($ti);
622
623 // save and cancel commands
624 $form->addCommandButton("renameFile", $lng->txt("rename"));
625 $form->addCommandButton("cancelRename", $lng->txt("cancel"));
626 $form->setFormAction($ilCtrl->getFormAction($this, "renameFile"));
627
628 if (@is_dir($file))
629 {
630 $form->setTitle($this->lng->txt("cont_rename_dir"));
631 }
632 else
633 {
634 $form->setTitle($this->lng->txt("rename_file"));
635 }
636
637 $this->tpl->setContent($form->getHTML());
638 }
This class represents a property form user interface.

References $_GET, $file, $ilCtrl, $lng, and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ setAllowDirectories()

ilFileSystemGUI::setAllowDirectories (   $a_val)

Set allow directories.

Parameters
booleanallow directories

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

150 {
151 $this->allow_directories = $a_val;
152 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setAllowDirectoryCreation()

ilFileSystemGUI::setAllowDirectoryCreation (   $a_val)

Set allowed directory creation.

Definition at line 502 of file class.ilFileSystemGUI.php.

503 {
504 $this->directory_creation = $a_val;
505 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setAllowedSuffixes()

ilFileSystemGUI::setAllowedSuffixes (   $a_suffixes)

Set allowed Suffixes.

Parameters
array$a_suffixesallowed Suffixes

Definition at line 85 of file class.ilFileSystemGUI.php.

86 {
87 $this->allowed_suffixes = $a_suffixes;
88 }

◆ setAllowFileCreation()

ilFileSystemGUI::setAllowFileCreation (   $a_val)

Set allowed file creation.

Definition at line 518 of file class.ilFileSystemGUI.php.

519 {
520 $this->file_creation = $a_val;
521 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setForbiddenSuffixes()

ilFileSystemGUI::setForbiddenSuffixes (   $a_suffixes)

Set forbidden Suffixes.

Parameters
array$a_suffixesforbidden Suffixes

Definition at line 105 of file class.ilFileSystemGUI.php.

106 {
107 $this->forbidden_suffixes = $a_suffixes;
108 }

◆ setPerformedCommand()

ilFileSystemGUI::setPerformedCommand (   $command,
  $pars = "" 
)
protected

Set performed command.

Parameters
stringcommand
arrayparameter array

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

251 {
252 if (!is_array($pars))
253 {
254 $pars = array();
255 }
256 $_SESSION["fsys"]["lastcomm"] = array_merge(
257 array("cmd" => $command), $pars);
258 }

References $_SESSION.

Referenced by createDirectory(), deleteFile(), renameFile(), unzipFile(), and uploadFile().

+ Here is the caller graph for this function:

◆ setPostDirPath()

ilFileSystemGUI::setPostDirPath (   $a_val)

Set post dir path.

Parameters
booleanpost dir path

Definition at line 169 of file class.ilFileSystemGUI.php.

170 {
171 $this->post_dir_path = $a_val;
172 }

◆ setTableId()

ilFileSystemGUI::setTableId (   $a_val)

Set table id.

Parameters
stringtable id

Definition at line 189 of file class.ilFileSystemGUI.php.

190 {
191 $this->table_id = $a_val;
192 }

◆ setTitle()

ilFileSystemGUI::setTitle (   $a_val)

Set title.

Parameters
stringtitle

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

210 {
211 $this->title = $a_val;
212 }

◆ setUseUploadDirectory()

ilFileSystemGUI::setUseUploadDirectory (   $a_val)

Set use upload directory.

Parameters
bool$a_valuse upload directory

Definition at line 229 of file class.ilFileSystemGUI.php.

230 {
231 $this->use_upload_directory = $a_val;
232 }

◆ unzipFile()

ilFileSystemGUI::unzipFile (   $a_file = null)

delete object file

Definition at line 904 of file class.ilFileSystemGUI.php.

905 {
906 global $lng;
907
908 // #17470 - direct unzip call (after upload)
909 if(!$a_file &&
910 isset($_GET["upfile"]))
911 {
912 $a_file = basename($_GET["upfile"]);
913 }
914
915 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
916 $cur_dir = (!empty($cur_subdir))
917 ? $this->main_dir."/".$cur_subdir
918 : $this->main_dir;
919 $a_file = $this->main_dir."/".$a_file;
920
921 if (@is_file($a_file))
922 {
923 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
924 $cur_files = array_keys(ilUtil::getDir($cur_dir));
925 $cur_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
926
927 if ($this->getAllowDirectories())
928 {
929 ilUtil::unzip($a_file, true);
930 }
931 else
932 {
933 ilUtil::unzip($a_file, true, true);
934 }
935
936 $new_files = array_keys(ilUtil::getDir($cur_dir));
937 $new_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
938
939 $diff = array_diff($new_files, $cur_files);
940 $diff_r = array_diff($new_files_r, $cur_files_r);
941
942 // unlink forbidden file types
943 foreach ($diff_r as $f => $d)
944 {
945 $pi = pathinfo($f);
946 if (!is_dir($f) && !$this->isValidSuffix(strtolower($pi["extension"])))
947 {
948 ilUtil::sendFailure($lng->txt("file_some_invalid_file_types_removed")." (".$pi["extension"].")", true);
949 unlink($f);
950 }
951 }
952
953 if(sizeof($diff))
954 {
955 if ($this->getAllowDirectories())
956 {
957 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
958 $new_files = array();
959
960 foreach($diff as $new_item)
961 {
962 if(is_dir($cur_dir."/".$new_item))
963 {
964 ilFileUtils::recursive_dirscan($cur_dir."/".$new_item, $new_files);
965 }
966 }
967
968 if(is_array($new_files["path"]))
969 {
970 foreach($new_files["path"] as $idx => $path)
971 {
972 $path = substr($path, strlen($this->main_dir)+1);
973 $diff[] = $path.$new_files["file"][$idx];
974 }
975 }
976 }
977
978 $this->setPerformedCommand("unzip_file",
979 array("name" => substr($file, strlen($this->main_dir)+1),
980 "added" => $diff));
981 }
982 }
983
984 ilUtil::renameExecutables($this->main_dir);
985
986 $this->ctrl->saveParameter($this, "cdir");
987 ilUtil::sendSuccess($lng->txt("cont_file_unzipped"), true);
988 $this->ctrl->redirect($this, "listFiles");
989 }
for($col=0; $col< 50; $col++) $d
$path
Definition: aliased.php:25
static recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file

References $_GET, $d, $file, $lng, $path, getAllowDirectories(), ilUtil\getDir(), isValidSuffix(), ilFileUtils\recursive_dirscan(), ilUtil\renameExecutables(), ilUtil\sendFailure(), ilUtil\sendSuccess(), setPerformedCommand(), ilUtil\stripSlashes(), and ilUtil\unzip().

+ Here is the call graph for this function:

◆ uploadFile()

ilFileSystemGUI::uploadFile ( )

upload file

Definition at line 746 of file class.ilFileSystemGUI.php.

747 {
748 global $lng;
749
750 // determine directory
751 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
752 $cur_dir = (!empty($cur_subdir))
753 ? $this->main_dir."/".$cur_subdir
754 : $this->main_dir;
755
756 $tgt_file = null;
757
758 $pi = pathinfo($_FILES["new_file"]["name"]);
759 $suffix = $pi["extension"];
760 if (!$this->isValidSuffix($suffix))
761 {
762 ilUtil::sendFailure($this->lng->txt("file_no_valid_file_type")." ($suffix)", true);
763 $this->ctrl->redirect($this, "listFiles");
764 }
765
766 if (is_file($_FILES["new_file"]["tmp_name"]))
767 {
768 $name = ilUtil::stripSlashes($_FILES["new_file"]["name"]);
769 $tgt_file = $cur_dir."/".$name;
770
771 ilUtil::moveUploadedFile($_FILES["new_file"]["tmp_name"], $name, $tgt_file);
772
773 }
774 elseif ($_POST["uploaded_file"])
775 {
776 include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
777
778 // check if the file is in the ftp directory and readable
779 if (ilUploadFiles::_checkUploadFile($_POST["uploaded_file"]))
780 {
781 $tgt_file = $cur_dir."/".ilUtil::stripSlashes($_POST["uploaded_file"]);
782
783 // copy uploaded file to data directory
784 ilUploadFiles::_copyUploadFile($_POST["uploaded_file"], $tgt_file);
785 }
786 }
787 else if (trim($_FILES["new_file"]["name"]) == "")
788 {
789 ilUtil::sendFailure($lng->txt("cont_enter_a_file"), true);
790 }
791
792 if($tgt_file && is_file($tgt_file))
793 {
794 $unzip = null;
795
796 // extract zip?
797 include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
798 if(ilMimeTypeUtil::getMimeType($tgt_file) == "application/zip")
799 {
800 $this->ctrl->setParameter($this, "upfile", basename($tgt_file));
801 $url = $this->ctrl->getLinkTarget($this, "unzipFile");
802 $this->ctrl->setParameter($this, "upfile", "");
803
804 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
805 $unzip = ilLinkButton::getInstance();
806 $unzip->setCaption("unzip");
807 $unzip->setUrl($url);
808 $unzip = " ".$unzip->render();
809 }
810
811 ilUtil::sendSuccess($lng->txt("cont_file_created").$unzip, true);
812
813 $this->setPerformedCommand("create_file",
814 array("name" => substr($tgt_file, strlen($this->main_dir)+1)));
815 }
816
817 $this->ctrl->saveParameter($this, "cdir");
818
819 ilUtil::renameExecutables($this->main_dir);
820
821 $this->ctrl->redirect($this, "listFiles");
822 }
static getInstance()
Factory.
static getMimeType($a_file='', $a_filename='', $a_mime='')
static _copyUploadFile($a_file, $a_target, $a_raise_errors=true)
copy an uploaded file to the target directory (including virus check)
static _checkUploadFile($a_file)
Check if a file exists in the upload directory and is readable.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
$url
Definition: shib_logout.php:72

References $_GET, $_POST, $lng, $url, ilUploadFiles\_checkUploadFile(), ilUploadFiles\_copyUploadFile(), ilLinkButton\getInstance(), ilMimeTypeUtil\getMimeType(), isValidSuffix(), ilUtil\moveUploadedFile(), ilUtil\renameExecutables(), ilUtil\sendFailure(), ilUtil\sendSuccess(), setPerformedCommand(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

Field Documentation

◆ $allowed_suffixes

ilFileSystemGUI::$allowed_suffixes = array()
protected

Definition at line 21 of file class.ilFileSystemGUI.php.

Referenced by getAllowedSuffixes().

◆ $ctrl

ilFileSystemGUI::$ctrl

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

◆ $forbidden_suffixes

ilFileSystemGUI::$forbidden_suffixes = array()
protected

Definition at line 26 of file class.ilFileSystemGUI.php.

Referenced by getForbiddenSuffixes().

◆ $use_upload_directory

ilFileSystemGUI::$use_upload_directory = false
protected

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

Referenced by getUseUploadDirectory().


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