ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilFileSystemGUI Class Reference

File System Explorer GUI class. More...

+ Inheritance diagram for ilFileSystemGUI:
+ 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 ($a_table_gui=null)
 List files. More...
 
 getTable ($a_dir, $a_subdir)
 Get table. 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...
 
 getActionCommands ()
 
 defineCommands ()
 Define commands available. More...
 

Data Fields

 $ctrl
 
const CDIR = "cdir"
 

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

Private Member Functions

 sanitizeCurrentDirectory ()
 

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)

Reimplemented in ilExAssignmentFileSystemGUI.

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

29 {
30 global $DIC;
31 $lng = $DIC['lng'];
32 $ilCtrl = $DIC['ilCtrl'];
33 $tpl = $DIC['tpl'];
34 $ilias = $DIC['ilias'];
35
36 $this->ctrl = $ilCtrl;
37 $this->lng = $lng;
38 $this->ilias = $ilias;
39 $this->tpl = $tpl;
40 $this->main_dir = $a_main_directory;
41 $this->post_dir_path = false;
42
43 $this->defineCommands();
44
45 $this->file_labels = array();
46 $this->label_enable = false;
47 $this->ctrl->saveParameter($this, self::CDIR);
48 $lng->loadLanguageModule("content");
49 $this->setAllowDirectories(true);
50 $this->setAllowDirectoryCreation(true);
51 $this->setAllowFileCreation(true);
52 //echo "<br>main_dir:".$this->main_dir.":";
53 }
$tpl
Definition: ilias.php:10
setAllowDirectories($a_val)
Set allow directories.
defineCommands()
Define commands available.
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 $DIC
Definition: saml.php:7
$lng

References $DIC, $ilCtrl, $lng, $tpl, defineCommands(), 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 308 of file class.ilFileSystemGUI.php.

309 {
310 $this->label_enable = $a_act;
311 $this->label_header = $a_label_header;
312 }

◆ addCommand()

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

Add command.

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

277 {
278 $i = count($this->commands);
279
280 $this->commands[$i]["object"] = $a_obj;
281 $this->commands[$i]["method"] = $a_func;
282 $this->commands[$i]["name"] = $a_name;
283 $this->commands[$i]["single"] = $a_single;
284 $this->commands[$i]["allow_dir"] = $a_allow_dir;
285
286 //$this->commands[] = $arr;
287 }
$i
Definition: disco.tpl.php:19

References $i.

◆ cancelRename()

ilFileSystemGUI::cancelRename ( )

cancel renaming a file

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

668 {
669 $this->ctrl->redirect($this, "listFiles");
670 }

◆ clearCommands()

ilFileSystemGUI::clearCommands ( )

Clear commands.

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

293 {
294 $this->commands = array();
295 }

◆ confirmDeleteFile()

ilFileSystemGUI::confirmDeleteFile ( array  $a_files)

Confirm file deletion.

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

781 {
782 global $DIC;
783 $ilCtrl = $DIC['ilCtrl'];
784 $tpl = $DIC['tpl'];
785 $lng = $DIC['lng'];
786
787 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
788 $cgui = new ilConfirmationGUI();
789 $cgui->setFormAction($ilCtrl->getFormAction($this));
790 $cgui->setHeaderText($lng->txt("info_delete_sure"));
791 $cgui->setCancel($lng->txt("cancel"), "listFiles");
792 $cgui->setConfirm($lng->txt("delete"), "deleteFile");
793
794 foreach ($a_files as $i) {
795 $cgui->addItem("file[]", $i, $i);
796 }
797
798 $tpl->setContent($cgui->getHTML());
799 }
Confirmation screen class.

References $DIC, $i, $ilCtrl, $lng, and $tpl.

◆ createDirectory()

ilFileSystemGUI::createDirectory ( )

create directory

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

676 {
677 global $DIC;
678 $lng = $DIC['lng'];
679
680 // determine directory
681 $cur_subdir = $this->sanitizeCurrentDirectory();
682 $cur_dir = (!empty($cur_subdir))
683 ? $this->main_dir . "/" . $cur_subdir
684 : $this->main_dir;
685
686 $new_dir = str_replace(".", "", ilUtil::stripSlashes($_POST["new_dir"]));
687 $new_dir = str_replace("/", "", $new_dir);
688
689 if (!empty($new_dir)) {
690 ilUtil::makeDir($cur_dir . "/" . $new_dir);
691 if (is_dir($cur_dir . "/" . $new_dir)) {
692 ilUtil::sendSuccess($lng->txt("cont_dir_created"), true);
693 $this->setPerformedCommand("create_dir", array("name" => $new_dir));
694 }
695 } else {
696 ilUtil::sendFailure($lng->txt("cont_enter_a_dir_name"), true);
697 }
698 $this->ctrl->saveParameter($this, self::CDIR);
699 $this->ctrl->redirect($this, 'listFiles');
700 }
$_POST["username"]
setPerformedCommand($command, $pars="")
Set performed command.
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 $_POST, $DIC, $lng, ilUtil\makeDir(), sanitizeCurrentDirectory(), ilUtil\sendFailure(), setPerformedCommand(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ defineCommands()

ilFileSystemGUI::defineCommands ( )

Define commands available.

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

979 {
980 $this->commands = array(
981 0 => array(
982 "object" => $this,
983 "method" => "downloadFile",
984 "name" => $this->lng->txt("download"),
985 "int" => true,
986 "single" => true
987 ),
988 1 => array(
989 "object" => $this,
990 "method" => "confirmDeleteFile",
991 "name" => $this->lng->txt("delete"),
992 "allow_dir" => true,
993 "int" => true
994 ),
995 2 => array(
996 "object" => $this,
997 "method" => "unzipFile",
998 "name" => $this->lng->txt("unzip"),
999 "int" => true,
1000 "single" => true
1001 ),
1002 3 => array(
1003 "object" => $this,
1004 "method" => "renameFileForm",
1005 "name" => $this->lng->txt("rename"),
1006 "allow_dir" => true,
1007 "int" => true,
1008 "single" => true
1009 ),
1010 );
1011 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ deleteFile()

ilFileSystemGUI::deleteFile ( )

delete object file

Reimplemented in ilExAssignmentFileSystemGUI.

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

805 {
806 global $DIC;
807 $lng = $DIC['lng'];
808
809 if (!isset($_POST["file"])) {
810 $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
811 }
812
813 foreach ($_POST["file"] as $post_file) {
814 if (ilUtil::stripSlashes($post_file) == "..") {
815 $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
816 break;
817 }
818
819 $cur_subdir = $this->sanitizeCurrentDirectory();
820 $cur_dir = (!empty($cur_subdir))
821 ? $this->main_dir . "/" . $cur_subdir
822 : $this->main_dir;
823 $pi = pathinfo($post_file);
824 $file = $cur_dir . "/" . ilUtil::stripSlashes($pi["basename"]);
825
826 if (@is_file($file)) {
827 unlink($file);
828 }
829
830 if (@is_dir($file)) {
831 $is_dir = true;
832 ilUtil::delDir($file);
833 }
834 }
835
836 $this->ctrl->saveParameter($this, self::CDIR);
837 if ($is_dir) {
838 ilUtil::sendSuccess($lng->txt("cont_dir_deleted"), true);
839 $this->setPerformedCommand(
840 "delete_dir",
841 array("name" => ilUtil::stripSlashes($post_file))
842 );
843 } else {
844 ilUtil::sendSuccess($lng->txt("cont_file_deleted"), true);
845 $this->setPerformedCommand(
846 "delete_file",
847 array("name" => ilUtil::stripSlashes($post_file))
848 );
849 }
850 $this->ctrl->redirect($this, 'listFiles');
851 }
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively

References $_POST, $DIC, $lng, ilUtil\delDir(), sanitizeCurrentDirectory(), setPerformedCommand(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ downloadFile()

ilFileSystemGUI::downloadFile (   $a_file)

delete object file

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

937 {
938 $file = $this->main_dir . "/" . $a_file;
939
940 if (@is_file($file) && !(@is_dir($file))) {
941 ilUtil::deliverFile($file, basename($a_file));
942 exit;
943 } else {
944 $this->ctrl->saveParameter($this, self::CDIR);
945 $this->ctrl->redirect($this, "listFiles");
946 }
947 }
exit
Definition: backend.php:16
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.

References ilUtil\deliverFile(), and exit.

+ Here is the call graph for this function:

◆ executeCommand()

ilFileSystemGUI::executeCommand ( )

execute command

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

249 {
250 $next_class = $this->ctrl->getNextClass($this);
251 $cmd = $this->ctrl->getCmd("listFiles");
252
253 switch ($next_class) {
254
255 default:
256 if (substr($cmd, 0, 11) == "extCommand_") {
257 $ret = $this->extCommand(substr($cmd, 11, strlen($cmd) - 11));
258 } else {
259 $ret = $this->$cmd();
260 }
261 break;
262 }
263
264 return $ret;
265 }
extCommand($a_nr)
call external command
$ret
Definition: parser.php:6

References $ret, and extCommand().

+ Here is the call graph for this function:

◆ extCommand()

ilFileSystemGUI::extCommand (   $a_nr)

call external command

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

407 {
408 $selected = $this->getIncomingFiles();
409
410 if (!count($selected)) {
411 ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
412 $this->ctrl->redirect($this, "listFiles");
413 }
414
415 // check if only one item is select, if command does not allow multiple selection
416 if (count($selected) > 1 && $this->commands[$a_nr]["single"]) {
417 ilUtil::sendFailure($this->lng->txt("cont_select_max_one_item"), true);
418 $this->ctrl->redirect($this, "listFiles");
419 }
420
421 $cur_subdir = $this->sanitizeCurrentDirectory();
422
423 // collect files and
424 $files = array();
425 foreach ($selected as $file) {
426 $file = ilUtil::stripSlashes($file);
427 $file = (!empty($cur_subdir))
428 ? $cur_subdir . "/" . $file
429 : $file;
430
431 // check wether selected item is a directory
432 if (@is_dir($this->main_dir . "/" . $file) &&
433 !$this->commands[$a_nr]["allow_dir"]) {
434 ilUtil::sendFailure($this->lng->txt("select_a_file"), true);
435 $this->ctrl->redirect($this, "listFiles");
436 }
437
438 $files[] = $file;
439 }
440
441 if ($this->commands[$a_nr]["single"]) {
442 $files = array_shift($files);
443 }
444
445 $obj = $this->commands[$a_nr]["object"];
446 $method = $this->commands[$a_nr]["method"];
447
448 return $obj->$method($files);
449 }
$files
Definition: metarefresh.php:49

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

Referenced by executeCommand().

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

◆ getActionCommands()

ilFileSystemGUI::getActionCommands ( )
Returns
array of commands

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

971 {
972 return $this->commands;
973 }

◆ getAllowDirectories()

ilFileSystemGUI::getAllowDirectories ( )

Get allow directories.

Returns
boolean allow directories

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

132 {
133 return $this->allow_directories;
134 }

Referenced by listFiles(), and unzipFile().

+ Here is the caller graph for this function:

◆ getAllowDirectoryCreation()

ilFileSystemGUI::getAllowDirectoryCreation ( )

Get allowed directory creation.

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

463 {
464 return $this->directory_creation;
465 }

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getAllowedSuffixes()

ilFileSystemGUI::getAllowedSuffixes ( )

Get allowed Suffixes.

Returns
array allowed Suffixes

Definition at line 70 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 478 of file class.ilFileSystemGUI.php.

479 {
480 return $this->file_creation;
481 }

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getFileList()

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

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

346 {
347 $items = array();
348
349 $entries = (is_dir($a_dir))
350 ? ilUtil::getDir($a_dir)
351 : array(array("type" => "dir", "entry" => ".."));
352
353 $items = array();
354 foreach ($entries as $e) {
355 if (($e["entry"] == ".") ||
356 ($e["entry"] == ".." && empty($a_subdir))) {
357 continue;
358 }
359
360 $cfile = (!empty($a_subdir))
361 ? $a_subdir . "/" . $e["entry"]
362 : $e["entry"];
363
364 $items[] = array(
365 "file" => $cfile,
366 "entry" => $e["entry"],
367 "type" => $e["type"],
368 "size" => $e["size"],
369 "hash" => md5($e["entry"])
370 );
371 }
372
373 return $items;
374 }
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 90 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 376 of file class.ilFileSystemGUI.php.

377 {
378 $sel_files = $hashes = array();
379 if (isset($_POST["file"])) {
380 $hashes = $_POST["file"];
381 } elseif (isset($_GET["fhsh"])) {
382 $hashes = array($_GET["fhsh"]);
383 }
384
385 if (sizeof($hashes)) {
386 $dir = $this->parseCurrentDirectory();
387 $all_files = $this->getFileList($dir["dir"], $dir["subdir"]);
388 foreach ($hashes as $hash) {
389 foreach ($all_files as $file) {
390 if ($file["hash"] == $hash) {
391 $sel_files[] = $this->getPostDirPath()
392 ? $file["file"]
393 : $file["entry"];
394 break;
395 }
396 }
397 }
398 }
399
400 return $sel_files;
401 }
$_GET["client_id"]
getPostDirPath()
Get post dir path.
getFileList($a_dir, $a_subdir=null)

References $_GET, $_POST, 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 238 of file class.ilFileSystemGUI.php.

239 {
240 $ret = $_SESSION["fsys"]["lastcomm"];
241 $_SESSION["fsys"]["lastcomm"] = "none";
242 return $ret;
243 }
$_SESSION["AccountId"]

References $_SESSION, and $ret.

◆ getPostDirPath()

ilFileSystemGUI::getPostDirPath ( )

Get post dir path.

Returns
boolean post dir path

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

152 {
153 return $this->post_dir_path;
154 }

Referenced by getIncomingFiles(), ilExAssignmentFileSystemGUI\getTable(), and getTable().

+ Here is the caller graph for this function:

◆ getTable()

ilFileSystemGUI::getTable (   $a_dir,
  $a_subdir 
)

Get table.

Parameters

return

Reimplemented in ilExAssignmentFileSystemGUI.

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

556 {
557 include_once("./Services/FileSystem/classes/class.ilFileSystemTableGUI.php");
558 return new ilFileSystemTableGUI(
559 $this,
560 "listFiles",
561 $a_dir,
562 $a_subdir,
563 $this->label_enable,
564 $this->file_labels,
565 $this->label_header,
566 $this->commands,
567 $this->getPostDirPath(),
568 $this->getTableId()
569 );
570 }
getTableId()
Get table id.
TableGUI class for file system.

References getPostDirPath(), and getTableId().

Referenced by listFiles().

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

◆ getTableId()

ilFileSystemGUI::getTableId ( )

Get table id.

Returns
string table id

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

172 {
173 return $this->table_id;
174 }

Referenced by ilExAssignmentFileSystemGUI\getTable(), and getTable().

+ Here is the caller graph for this function:

◆ getTabs()

ilFileSystemGUI::getTabs ( $tabs_gui)

get tabs

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

953 {
954 global $DIC;
955 $ilCtrl = $DIC['ilCtrl'];
956
957 $ilCtrl->setParameter($this, "resetoffset", 1);
958 $tabs_gui->addTarget(
959 "cont_list_files",
960 $this->ctrl->getLinkTarget($this, "listFiles"),
961 "listFiles",
962 get_class($this)
963 );
964 $ilCtrl->setParameter($this, "resetoffset", "");
965 }

References $DIC, and $ilCtrl.

◆ getTitle()

ilFileSystemGUI::getTitle ( )

Get title.

Returns
string title

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

192 {
193 return $this->title;
194 }

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 211 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 101 of file class.ilFileSystemGUI.php.

102 {
103 if (is_array($this->getForbiddenSuffixes()) && in_array($a_suffix, $this->getForbiddenSuffixes())) {
104 return false;
105 }
106 if (is_array($this->getAllowedSuffixes()) && in_array($a_suffix, $this->getAllowedSuffixes())) {
107 return true;
108 }
109 if (!is_array($this->getAllowedSuffixes()) || count($this->getAllowedSuffixes()) == 0) {
110 return true;
111 }
112 return false;
113 }
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 300 of file class.ilFileSystemGUI.php.

301 {
302 $this->file_labels[$a_file][] = $a_label;
303 }

◆ listFiles()

ilFileSystemGUI::listFiles (   $a_table_gui = null)

List files.

Parameters
array$a_class_table_guiif we are here from a child class

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

490 {
491 global $DIC;
492 $ilToolbar = $DIC['ilToolbar'];
493 $lng = $DIC['lng'];
494 $ilCtrl = $DIC['ilCtrl'];
495
496 $dir = $this->parseCurrentDirectory();
497
498 $this->ctrl->setParameter($this, self::CDIR, $dir["subdir"]);
499
500 // toolbar for adding files/directories
501 $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
502 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
503
504 if ($this->getAllowDirectories() && $this->getAllowDirectoryCreation()) {
505 $ti = new ilTextInputGUI($this->lng->txt("cont_new_dir"), "new_dir");
506 $ti->setMaxLength(80);
507 $ti->setSize(10);
508 $ilToolbar->addInputItem($ti, true);
509 $ilToolbar->addFormButton($lng->txt("create"), "createDirectory");
510
511 $ilToolbar->addSeparator();
512 }
513
514 include_once("./Services/Form/classes/class.ilFileInputGUI.php");
515 if ($this->getAllowFileCreation()) {
516 $fi = new ilFileInputGUI($this->lng->txt("cont_new_file"), "new_file");
517 $fi->setSize(10);
518 $ilToolbar->addInputItem($fi, true);
519 $ilToolbar->addFormButton($lng->txt("upload"), "uploadFile");
520 }
521
522 include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
524 $ilToolbar->addSeparator();
526 $options[""] = $lng->txt("cont_select_from_upload_dir");
527 foreach ($files as $file) {
528 $file = htmlspecialchars($file, ENT_QUOTES, "utf-8");
529 $options[$file] = $file;
530 }
531 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
532 $si = new ilSelectInputGUI($this->lng->txt("cont_uploaded_file"), "uploaded_file");
533 $si->setOptions($options);
534 $ilToolbar->addInputItem($si, true);
535 $ilToolbar->addFormButton($lng->txt("copy"), "uploadFile");
536 }
537
538 $fs_table = $this->getTable($dir["dir"], $dir["subdir"]);
539
540 if ($this->getTitle() != "") {
541 $fs_table->setTitle($this->getTitle());
542 }
543 if ($_GET["resetoffset"] == 1) {
544 $fs_table->resetOffset();
545 }
546 $this->tpl->setContent($fs_table->getHTML());
547 }
This class represents a file property in a property form.
getUseUploadDirectory()
Get use upload directory.
getAllowDirectoryCreation()
Get allowed directory creation.
getTable($a_dir, $a_subdir)
Get table.
getAllowDirectories()
Get allow directories.
getAllowFileCreation()
Get allowed file creation.
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.

References $_GET, $DIC, $files, $ilCtrl, $lng, PHPMailer\PHPMailer\$options, $si, ilUploadFiles\_getUploadDirectory(), ilUploadFiles\_getUploadFiles(), getAllowDirectories(), getAllowDirectoryCreation(), getAllowFileCreation(), getTable(), getTitle(), getUseUploadDirectory(), and parseCurrentDirectory().

+ Here is the call graph for this function:

◆ parseCurrentDirectory()

ilFileSystemGUI::parseCurrentDirectory ( )
protected

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

317 {
318 // determine directory
319 // FIXME: I have to call stripSlashes here twice, because I could not
320 // determine where the second layer of slashes is added to the
321 // URL Parameter
322 $cur_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET[self::CDIR]));
323 $new_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET["newdir"]));
324
325 if ($new_subdir == "..") {
326 $cur_subdir = substr($cur_subdir, 0, strrpos($cur_subdir, "/"));
327 } else {
328 if (!empty($new_subdir)) {
329 if (!empty($cur_subdir)) {
330 $cur_subdir = $cur_subdir . "/" . $new_subdir;
331 } else {
332 $cur_subdir = $new_subdir;
333 }
334 }
335 }
336
337 $cur_subdir = str_replace("..", "", $cur_subdir);
338 $cur_dir = (!empty($cur_subdir))
339 ? $this->main_dir . "/" . $cur_subdir
340 : $this->main_dir;
341
342 return array("dir" => $cur_dir, "subdir" => $cur_subdir);
343 }

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

Reimplemented in ilExAssignmentFileSystemGUI.

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

615 {
616 global $DIC;
617 $lng = $DIC['lng'];
618
619 $new_name = str_replace("..", "", ilUtil::stripSlashes($_POST["new_name"]));
620 $new_name = str_replace("/", "", $new_name);
621 if ($new_name == "") {
622 $this->ilias->raiseError($this->lng->txt("enter_new_name"), $this->ilias->error_obj->MESSAGE);
623 }
624
625 $pi = pathinfo($new_name);
626 $suffix = $pi["extension"];
627 if ($suffix != "" && !$this->isValidSuffix($suffix)) {
628 ilUtil::sendFailure($this->lng->txt("file_no_valid_file_type") . " ($suffix)", true);
629 $this->ctrl->redirect($this, "listFiles");
630 }
631
632 $cur_subdir = $this->sanitizeCurrentDirectory();
633 $dir = (!empty($cur_subdir))
634 ? $this->main_dir . "/" . $cur_subdir . "/"
635 : $this->main_dir . "/";
636
637
638 if (is_dir($dir . ilUtil::stripSlashes($_GET["old_name"]))) {
639 rename($dir . ilUtil::stripSlashes($_GET["old_name"]), $dir . $new_name);
640 } else {
641 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
642
643 try {
644 ilFileUtils::rename($dir . ilUtil::stripSlashes($_GET["old_name"]), $dir . $new_name);
645 } catch (ilException $e) {
646 ilUtil::sendFailure($e->getMessage(), true);
647 $this->ctrl->redirect($this, "listFiles");
648 }
649 }
650
651 ilUtil::renameExecutables($this->main_dir);
652 if (@is_dir($dir . $new_name)) {
653 ilUtil::sendSuccess($lng->txt("cont_dir_renamed"), true);
654 $this->setPerformedCommand("rename_dir", array("old_name" => $_GET["old_name"],
655 "new_name" => $new_name));
656 } else {
657 ilUtil::sendSuccess($lng->txt("cont_file_renamed"), true);
658 $this->setPerformedCommand("rename_file", array("old_name" => $_GET["old_name"],
659 "new_name" => $new_name));
660 }
661 $this->ctrl->redirect($this, "listFiles");
662 }
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, $DIC, $lng, isValidSuffix(), ilFileUtils\rename(), ilUtil\renameExecutables(), sanitizeCurrentDirectory(), ilUtil\sendFailure(), setPerformedCommand(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ renameFileForm()

ilFileSystemGUI::renameFileForm (   $a_file)

list files

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

576 {
577 global $DIC;
578 $lng = $DIC['lng'];
579 $ilCtrl = $DIC['ilCtrl'];
580
581 $cur_subdir = $this->sanitizeCurrentDirectory();
582 $file = $this->main_dir . "/" . $a_file;
583
584 $this->ctrl->setParameter($this, "old_name", basename($a_file));
585 $this->ctrl->setParameter($this, self::CDIR, ilUtil::stripSlashes($_GET[self::CDIR]));
586
587 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
588 $form = new ilPropertyFormGUI();
589
590 // file/dir name
591 $ti = new ilTextInputGUI($this->lng->txt("name"), "new_name");
592 $ti->setMaxLength(200);
593 $ti->setSize(40);
594 $ti->setValue(basename($a_file));
595 $form->addItem($ti);
596
597 // save and cancel commands
598 $form->addCommandButton("renameFile", $lng->txt("rename"));
599 $form->addCommandButton("cancelRename", $lng->txt("cancel"));
600 $form->setFormAction($ilCtrl->getFormAction($this, "renameFile"));
601
602 if (@is_dir($file)) {
603 $form->setTitle($this->lng->txt("cont_rename_dir"));
604 } else {
605 $form->setTitle($this->lng->txt("rename_file"));
606 }
607
608 $this->tpl->setContent($form->getHTML());
609 }
This class represents a property form user interface.
if(isset($_POST['submit'])) $form

References $_GET, $DIC, $form, $ilCtrl, $lng, sanitizeCurrentDirectory(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ sanitizeCurrentDirectory()

ilFileSystemGUI::sanitizeCurrentDirectory ( )
private
Returns
string

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

1018 {
1019 global $DIC;
1020
1021 return str_replace("..", "", ilUtil::stripSlashes($DIC->http()->request()->getQueryParams()[self::CDIR]));
1022 }

References $DIC, and ilUtil\stripSlashes().

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

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

◆ setAllowDirectories()

ilFileSystemGUI::setAllowDirectories (   $a_val)

Set allow directories.

Parameters
booleanallow directories

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

122 {
123 $this->allow_directories = $a_val;
124 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setAllowDirectoryCreation()

ilFileSystemGUI::setAllowDirectoryCreation (   $a_val)

Set allowed directory creation.

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

455 {
456 $this->directory_creation = $a_val;
457 }

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 60 of file class.ilFileSystemGUI.php.

61 {
62 $this->allowed_suffixes = $a_suffixes;
63 }

◆ setAllowFileCreation()

ilFileSystemGUI::setAllowFileCreation (   $a_val)

Set allowed file creation.

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

471 {
472 $this->file_creation = $a_val;
473 }

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 80 of file class.ilFileSystemGUI.php.

81 {
82 $this->forbidden_suffixes = $a_suffixes;
83 }

◆ setPerformedCommand()

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

Set performed command.

Parameters
stringcommand
arrayparameter array

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

223 {
224 if (!is_array($pars)) {
225 $pars = array();
226 }
227 $_SESSION["fsys"]["lastcomm"] = array_merge(
228 array("cmd" => $command),
229 $pars
230 );
231 }

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 141 of file class.ilFileSystemGUI.php.

142 {
143 $this->post_dir_path = $a_val;
144 }

◆ setTableId()

ilFileSystemGUI::setTableId (   $a_val)

Set table id.

Parameters
stringtable id

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

162 {
163 $this->table_id = $a_val;
164 }

◆ setTitle()

ilFileSystemGUI::setTitle (   $a_val)

Set title.

Parameters
stringtitle

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

182 {
183 $this->title = $a_val;
184 }

◆ setUseUploadDirectory()

ilFileSystemGUI::setUseUploadDirectory (   $a_val)

Set use upload directory.

Parameters
bool$a_valuse upload directory

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

202 {
203 $this->use_upload_directory = $a_val;
204 }

◆ unzipFile()

ilFileSystemGUI::unzipFile (   $a_file = null)

delete object file

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

857 {
858 global $DIC;
859 $lng = $DIC['lng'];
860
861 // #17470 - direct unzip call (after upload)
862 if (!$a_file &&
863 isset($_GET["upfile"])) {
864 $a_file = basename($_GET["upfile"]);
865 }
866
867 $cur_subdir = $this->sanitizeCurrentDirectory();
868 $cur_dir = (!empty($cur_subdir))
869 ? $this->main_dir . "/" . $cur_subdir
870 : $this->main_dir;
871 $a_file = $this->main_dir . "/" . $a_file;
872
873 if (@is_file($a_file)) {
874 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
875 $cur_files = array_keys(ilUtil::getDir($cur_dir));
876 $cur_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
877
878 if ($this->getAllowDirectories()) {
879 ilUtil::unzip($a_file, true);
880 } else {
881 ilUtil::unzip($a_file, true, true);
882 }
883
884 $new_files = array_keys(ilUtil::getDir($cur_dir));
885 $new_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
886
887 $diff = array_diff($new_files, $cur_files);
888 $diff_r = array_diff($new_files_r, $cur_files_r);
889
890 // unlink forbidden file types
891 foreach ($diff_r as $f => $d) {
892 $pi = pathinfo($f);
893 if (!is_dir($f) && !$this->isValidSuffix(strtolower($pi["extension"]))) {
894 ilUtil::sendFailure($lng->txt("file_some_invalid_file_types_removed") . " (" . $pi["extension"] . ")", true);
895 unlink($f);
896 }
897 }
898
899 if (sizeof($diff)) {
900 if ($this->getAllowDirectories()) {
901 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
902 $new_files = array();
903
904 foreach ($diff as $new_item) {
905 if (is_dir($cur_dir . "/" . $new_item)) {
906 ilFileUtils::recursive_dirscan($cur_dir . "/" . $new_item, $new_files);
907 }
908 }
909
910 if (is_array($new_files["path"])) {
911 foreach ($new_files["path"] as $idx => $path) {
912 $path = substr($path, strlen($this->main_dir) + 1);
913 $diff[] = $path . $new_files["file"][$idx];
914 }
915 }
916 }
917
918 $this->setPerformedCommand(
919 "unzip_file",
920 array("name" => substr($file, strlen($this->main_dir) + 1),
921 "added" => $diff)
922 );
923 }
924 }
925
926 ilUtil::renameExecutables($this->main_dir);
927
928 $this->ctrl->saveParameter($this, self::CDIR);
929 ilUtil::sendSuccess($lng->txt("cont_file_unzipped"), true);
930 $this->ctrl->redirect($this, "listFiles");
931 }
$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
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296

References $_GET, $d, $DIC, $f, $lng, $path, getAllowDirectories(), ilUtil\getDir(), isValidSuffix(), ilFileUtils\recursive_dirscan(), ilUtil\renameExecutables(), sanitizeCurrentDirectory(), ilUtil\sendFailure(), setPerformedCommand(), and ilUtil\unzip().

+ Here is the call graph for this function:

◆ uploadFile()

ilFileSystemGUI::uploadFile ( )

Upload file.

Reimplemented in ilExAssignmentFileSystemGUI.

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

707 {
708 global $DIC;
709 $lng = $DIC['lng'];
710
711 // determine directory
712 $cur_subdir = $this->sanitizeCurrentDirectory();
713 $cur_dir = (!empty($cur_subdir))
714 ? $this->main_dir . "/" . $cur_subdir
715 : $this->main_dir;
716
717 $tgt_file = null;
718
719 $pi = pathinfo($_FILES["new_file"]["name"]);
720 $suffix = $pi["extension"];
721 if (!$this->isValidSuffix($suffix)) {
722 ilUtil::sendFailure($this->lng->txt("file_no_valid_file_type") . " ($suffix)", true);
723 $this->ctrl->redirect($this, "listFiles");
724 }
725
726 if (is_file($_FILES["new_file"]["tmp_name"])) {
727 $name = ilUtil::stripSlashes($_FILES["new_file"]["name"]);
728 $tgt_file = $cur_dir . "/" . $name;
729
730 ilUtil::moveUploadedFile($_FILES["new_file"]["tmp_name"], $name, $tgt_file);
731 } elseif ($_POST["uploaded_file"]) {
732 include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
733
734 // check if the file is in the ftp directory and readable
735 if (ilUploadFiles::_checkUploadFile($_POST["uploaded_file"])) {
736 $tgt_file = $cur_dir . "/" . ilUtil::stripSlashes($_POST["uploaded_file"]);
737
738 // copy uploaded file to data directory
739 ilUploadFiles::_copyUploadFile($_POST["uploaded_file"], $tgt_file);
740 }
741 } elseif (trim($_FILES["new_file"]["name"]) == "") {
742 ilUtil::sendFailure($lng->txt("cont_enter_a_file"), true);
743 }
744
745 if ($tgt_file && is_file($tgt_file)) {
746 $unzip = null;
747
748 // extract zip?
749 include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
750 if (ilMimeTypeUtil::getMimeType($tgt_file) == "application/zip") {
751 $this->ctrl->setParameter($this, "upfile", basename($tgt_file));
752 $url = $this->ctrl->getLinkTarget($this, "unzipFile");
753 $this->ctrl->setParameter($this, "upfile", "");
754
755 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
756 $unzip = ilLinkButton::getInstance();
757 $unzip->setCaption("unzip");
758 $unzip->setUrl($url);
759 $unzip = " " . $unzip->render();
760 }
761
762 ilUtil::sendSuccess($lng->txt("cont_file_created") . $unzip, true);
763
764 $this->setPerformedCommand(
765 "create_file",
766 array("name" => substr($tgt_file, strlen($this->main_dir) + 1))
767 );
768 }
769
770 $this->ctrl->saveParameter($this, self::CDIR);
771
772 ilUtil::renameExecutables($this->main_dir);
773
774 $this->ctrl->redirect($this, 'listFiles');
775 }
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.
$url

References $_POST, $DIC, $lng, $name, $url, ilUploadFiles\_checkUploadFile(), ilUploadFiles\_copyUploadFile(), ilLinkButton\getInstance(), ilMimeTypeUtil\getMimeType(), isValidSuffix(), ilUtil\renameExecutables(), sanitizeCurrentDirectory(), ilUtil\sendFailure(), 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

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

◆ CDIR

const ilFileSystemGUI::CDIR = "cdir"

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


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