ILIAS  release_7 Revision v7.30-3-g800a261c036
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 28 of file class.ilFileSystemGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileSystemGUI::__construct (   $a_main_directory)

Reimplemented in ilExAssignmentFileSystemGUI.

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

46 {
47 global $DIC;
48 $lng = $DIC['lng'];
49 $ilCtrl = $DIC['ilCtrl'];
50 $tpl = $DIC['tpl'];
51 $ilias = $DIC['ilias'];
52
53 $this->ctrl = $ilCtrl;
54 $this->lng = $lng;
55 $this->ilias = $ilias;
56 $this->tpl = $tpl;
57 $this->main_dir = $a_main_directory;
58 $this->post_dir_path = false;
59
60 $this->defineCommands();
61
62 $this->file_labels = array();
63 $this->label_enable = false;
64 $this->ctrl->saveParameter($this, self::CDIR);
65 $lng->loadLanguageModule("content");
66 $this->setAllowDirectories(true);
67 $this->setAllowDirectoryCreation(true);
68 $this->setAllowFileCreation(true);
69 //echo "<br>main_dir:".$this->main_dir.":";
70 }
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 $DIC
Definition: goto.php:24
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
redirection script todo: (a better solution should control the processing via a xml file)
$lng

References $DIC, $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 325 of file class.ilFileSystemGUI.php.

326 {
327 $this->label_enable = $a_act;
328 $this->label_header = $a_label_header;
329 }

◆ addCommand()

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

Add command.

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

294 {
295 $i = count($this->commands);
296
297 $this->commands[$i]["object"] = $a_obj;
298 $this->commands[$i]["method"] = $a_func;
299 $this->commands[$i]["name"] = $a_name;
300 $this->commands[$i]["single"] = $a_single;
301 $this->commands[$i]["allow_dir"] = $a_allow_dir;
302
303 //$this->commands[] = $arr;
304 }
$i
Definition: metadata.php:24

References $i.

◆ cancelRename()

ilFileSystemGUI::cancelRename ( )

cancel renaming a file

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

691 {
692 $this->ctrl->redirect($this, "listFiles");
693 }

◆ clearCommands()

ilFileSystemGUI::clearCommands ( )

Clear commands.

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

310 {
311 $this->commands = array();
312 }

◆ confirmDeleteFile()

ilFileSystemGUI::confirmDeleteFile ( array  $a_files)

Confirm file deletion.

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

808 {
809 global $DIC;
810 $ilCtrl = $DIC['ilCtrl'];
811 $tpl = $DIC['tpl'];
812 $lng = $DIC['lng'];
813
814 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
815 $cgui = new ilConfirmationGUI();
816 $cgui->setFormAction($ilCtrl->getFormAction($this));
817 $cgui->setHeaderText($lng->txt("info_delete_sure"));
818 $cgui->setCancel($lng->txt("cancel"), "listFiles");
819 $cgui->setConfirm($lng->txt("delete"), "deleteFile");
820
821 foreach ($a_files as $i) {
822 $cgui->addItem("file[]", $i, $i);
823 }
824
825 $tpl->setContent($cgui->getHTML());
826 }
Confirmation screen class.

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

◆ createDirectory()

ilFileSystemGUI::createDirectory ( )

create directory

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

699 {
700 global $DIC;
701 $lng = $DIC['lng'];
702
703 // determine directory
704 $cur_subdir = $this->sanitizeCurrentDirectory();
705 $cur_dir = (!empty($cur_subdir))
706 ? $this->main_dir . "/" . $cur_subdir
707 : $this->main_dir;
708
709 $new_dir = str_replace(".", "", ilUtil::stripSlashes($_POST["new_dir"]));
710 $new_dir = str_replace("/", "", $new_dir);
711
712 if (!empty($new_dir)) {
713 ilUtil::makeDir($cur_dir . "/" . $new_dir);
714 if (is_dir($cur_dir . "/" . $new_dir)) {
715 ilUtil::sendSuccess($lng->txt("cont_dir_created"), true);
716 $this->setPerformedCommand("create_dir", array("name" => $new_dir));
717 }
718 } else {
719 ilUtil::sendFailure($lng->txt("cont_enter_a_dir_name"), true);
720 }
721 $this->ctrl->saveParameter($this, self::CDIR);
722 $this->ctrl->redirect($this, 'listFiles');
723 }
$_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 1005 of file class.ilFileSystemGUI.php.

1006 {
1007 $this->commands = array(
1008 0 => array(
1009 "object" => $this,
1010 "method" => "downloadFile",
1011 "name" => $this->lng->txt("download"),
1012 "int" => true,
1013 "single" => true
1014 ),
1015 1 => array(
1016 "object" => $this,
1017 "method" => "confirmDeleteFile",
1018 "name" => $this->lng->txt("delete"),
1019 "allow_dir" => true,
1020 "int" => true
1021 ),
1022 2 => array(
1023 "object" => $this,
1024 "method" => "unzipFile",
1025 "name" => $this->lng->txt("unzip"),
1026 "int" => true,
1027 "single" => true
1028 ),
1029 3 => array(
1030 "object" => $this,
1031 "method" => "renameFileForm",
1032 "name" => $this->lng->txt("rename"),
1033 "allow_dir" => true,
1034 "int" => true,
1035 "single" => true
1036 ),
1037 );
1038 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ deleteFile()

ilFileSystemGUI::deleteFile ( )

delete object file

Reimplemented in ilExAssignmentFileSystemGUI.

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

832 {
833 global $DIC;
834 $lng = $DIC['lng'];
835
836 if (!isset($_POST["file"])) {
837 $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
838 }
839
840 foreach ($_POST["file"] as $post_file) {
841 if (ilUtil::stripSlashes($post_file) == "..") {
842 $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
843 break;
844 }
845
846 $cur_subdir = $this->sanitizeCurrentDirectory();
847 $cur_dir = (!empty($cur_subdir))
848 ? $this->main_dir . "/" . $cur_subdir
849 : $this->main_dir;
850 $pi = pathinfo($post_file);
851 $file = $cur_dir . "/" . ilUtil::stripSlashes($pi["basename"]);
852
853 if (@is_file($file)) {
854 unlink($file);
855 }
856
857 if (@is_dir($file)) {
858 $is_dir = true;
859 ilUtil::delDir($file);
860 }
861 }
862
863 $this->ctrl->saveParameter($this, self::CDIR);
864 if ($is_dir) {
865 ilUtil::sendSuccess($lng->txt("cont_dir_deleted"), true);
866 $this->setPerformedCommand(
867 "delete_dir",
868 array("name" => ilUtil::stripSlashes($post_file))
869 );
870 } else {
871 ilUtil::sendSuccess($lng->txt("cont_file_deleted"), true);
872 $this->setPerformedCommand(
873 "delete_file",
874 array("name" => ilUtil::stripSlashes($post_file))
875 );
876 }
877 $this->ctrl->redirect($this, 'listFiles');
878 }
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 963 of file class.ilFileSystemGUI.php.

964 {
965 $file = $this->main_dir . "/" . $a_file;
966
967 if (@is_file($file) && !(@is_dir($file))) {
968 ilUtil::deliverFile($file, basename($a_file));
969 exit;
970 } else {
971 $this->ctrl->saveParameter($this, self::CDIR);
972 $this->ctrl->redirect($this, "listFiles");
973 }
974 }
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
exit
Definition: login.php:29

References ilUtil\deliverFile(), and exit.

+ Here is the call graph for this function:

◆ executeCommand()

ilFileSystemGUI::executeCommand ( )

execute command

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

266 {
267 $next_class = $this->ctrl->getNextClass($this);
268 $cmd = $this->ctrl->getCmd("listFiles");
269
270 switch ($next_class) {
271
272 default:
273 if (substr($cmd, 0, 11) == "extCommand_") {
274 $ret = $this->extCommand(substr($cmd, 11, strlen($cmd) - 11));
275 } else {
276 $ret = $this->$cmd();
277 }
278 break;
279 }
280
281 return $ret;
282 }
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 423 of file class.ilFileSystemGUI.php.

424 {
425 $selected = $this->getIncomingFiles();
426
427 if (!count($selected)) {
428 ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
429 $this->ctrl->redirect($this, "listFiles");
430 }
431
432 // check if only one item is select, if command does not allow multiple selection
433 if (count($selected) > 1 && $this->commands[$a_nr]["single"]) {
434 ilUtil::sendFailure($this->lng->txt("cont_select_max_one_item"), true);
435 $this->ctrl->redirect($this, "listFiles");
436 }
437
438 $cur_subdir = $this->sanitizeCurrentDirectory();
439
440 // collect files and
441 $files = array();
442 foreach ($selected as $file) {
443 $file = ilUtil::stripSlashes($file);
444 $file = (!empty($cur_subdir))
445 ? $cur_subdir . "/" . $file
446 : $file;
447
448 // check wether selected item is a directory
449 if (@is_dir($this->main_dir . "/" . $file) &&
450 !$this->commands[$a_nr]["allow_dir"]) {
451 ilUtil::sendFailure($this->lng->txt("select_a_file"), true);
452 $this->ctrl->redirect($this, "listFiles");
453 }
454
455 $files[] = $file;
456 }
457
458 if ($this->commands[$a_nr]["single"]) {
459 $files = array_shift($files);
460 }
461
462 $obj = $this->commands[$a_nr]["object"];
463 $method = $this->commands[$a_nr]["method"];
464
465 return $obj->$method($files);
466 }

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

998 {
999 return $this->commands;
1000 }

◆ getAllowDirectories()

ilFileSystemGUI::getAllowDirectories ( )

Get allow directories.

Returns
boolean allow directories

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

149 {
150 return $this->allow_directories;
151 }

Referenced by listFiles(), and unzipFile().

+ Here is the caller graph for this function:

◆ getAllowDirectoryCreation()

ilFileSystemGUI::getAllowDirectoryCreation ( )

Get allowed directory creation.

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

480 {
481 return $this->directory_creation;
482 }

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getAllowedSuffixes()

ilFileSystemGUI::getAllowedSuffixes ( )

Get allowed Suffixes.

Returns
array allowed Suffixes

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

496 {
497 return $this->file_creation;
498 }

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getFileList()

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

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

363 {
364 $items = array();
365
366 $entries = (is_dir($a_dir))
367 ? ilUtil::getDir($a_dir)
368 : array(array("type" => "dir", "entry" => ".."));
369
370 $items = array();
371 foreach ($entries as $e) {
372 if (($e["entry"] == ".") ||
373 ($e["entry"] == ".." && empty($a_subdir))) {
374 continue;
375 }
376
377 $cfile = (!empty($a_subdir))
378 ? $a_subdir . "/" . $e["entry"]
379 : $e["entry"];
380
381 $items[] = array(
382 "file" => $cfile,
383 "entry" => $e["entry"],
384 "type" => $e["type"],
385 "size" => $e["size"],
386 "hash" => md5($e["entry"])
387 );
388 }
389
390 return $items;
391 }
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory

References Vendor\Package\$e, and 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 107 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 393 of file class.ilFileSystemGUI.php.

394 {
395 $sel_files = $hashes = array();
396 if (isset($_POST["file"])) {
397 $hashes = $_POST["file"];
398 } elseif (isset($_GET["fhsh"])) {
399 $hashes = array($_GET["fhsh"]);
400 }
401
402 if (sizeof($hashes)) {
403 $dir = $this->parseCurrentDirectory();
404 $all_files = $this->getFileList($dir["dir"], $dir["subdir"]);
405 foreach ($hashes as $hash) {
406 foreach ($all_files as $file) {
407 if ($file["hash"] == $hash) {
408 $sel_files[] = $this->getPostDirPath()
409 ? $file["file"]
410 : $file["entry"];
411 break;
412 }
413 }
414 }
415 }
416
417 return $sel_files;
418 }
$_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 255 of file class.ilFileSystemGUI.php.

256 {
257 $ret = $_SESSION["fsys"]["lastcomm"];
258 $_SESSION["fsys"]["lastcomm"] = "none";
259 return $ret;
260 }
$_SESSION["AccountId"]

References $_SESSION, and $ret.

◆ getPostDirPath()

ilFileSystemGUI::getPostDirPath ( )

Get post dir path.

Returns
boolean post dir path

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

169 {
170 return $this->post_dir_path;
171 }

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

573 {
574 include_once("./Services/FileSystem/classes/class.ilFileSystemTableGUI.php");
575 return new ilFileSystemTableGUI(
576 $this,
577 "listFiles",
578 $a_dir,
579 $a_subdir,
580 $this->label_enable,
581 $this->file_labels,
582 $this->label_header,
583 $this->commands,
584 $this->getPostDirPath(),
585 $this->getTableId()
586 );
587 }
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 188 of file class.ilFileSystemGUI.php.

189 {
190 return $this->table_id;
191 }

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

+ Here is the caller graph for this function:

◆ getTabs()

ilFileSystemGUI::getTabs ( $tabs_gui)

get tabs

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

980 {
981 global $DIC;
982 $ilCtrl = $DIC['ilCtrl'];
983
984 $ilCtrl->setParameter($this, "resetoffset", 1);
985 $tabs_gui->addTarget(
986 "cont_list_files",
987 $this->ctrl->getLinkTarget($this, "listFiles"),
988 "listFiles",
989 get_class($this)
990 );
991 $ilCtrl->setParameter($this, "resetoffset", "");
992 }

References $DIC.

◆ getTitle()

ilFileSystemGUI::getTitle ( )

Get title.

Returns
string title

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

209 {
210 return $this->title;
211 }

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

119 {
120 if (is_array($this->getForbiddenSuffixes()) && in_array($a_suffix, $this->getForbiddenSuffixes())) {
121 return false;
122 }
123 if (is_array($this->getAllowedSuffixes()) && in_array($a_suffix, $this->getAllowedSuffixes())) {
124 return true;
125 }
126 if (!is_array($this->getAllowedSuffixes()) || count($this->getAllowedSuffixes()) == 0) {
127 return true;
128 }
129 return false;
130 }
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 317 of file class.ilFileSystemGUI.php.

318 {
319 $this->file_labels[$a_file][] = $a_label;
320 }

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

507 {
508 global $DIC;
509 $ilToolbar = $DIC['ilToolbar'];
510 $lng = $DIC['lng'];
511 $ilCtrl = $DIC['ilCtrl'];
512
513 $dir = $this->parseCurrentDirectory();
514
515 $this->ctrl->setParameter($this, self::CDIR, $dir["subdir"]);
516
517 // toolbar for adding files/directories
518 $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
519 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
520
521 if ($this->getAllowDirectories() && $this->getAllowDirectoryCreation()) {
522 $ti = new ilTextInputGUI($this->lng->txt("cont_new_dir"), "new_dir");
523 $ti->setMaxLength(80);
524 $ti->setSize(10);
525 $ilToolbar->addInputItem($ti, true);
526 $ilToolbar->addFormButton($lng->txt("create"), "createDirectory");
527
528 $ilToolbar->addSeparator();
529 }
530
531 include_once("./Services/Form/classes/class.ilFileInputGUI.php");
532 if ($this->getAllowFileCreation()) {
533 $fi = new ilFileInputGUI($this->lng->txt("cont_new_file"), "new_file");
534 $fi->setSize(10);
535 $ilToolbar->addInputItem($fi, true);
536 $ilToolbar->addFormButton($lng->txt("upload"), "uploadFile");
537 }
538
539 include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
541 $ilToolbar->addSeparator();
543 $options[""] = $lng->txt("cont_select_from_upload_dir");
544 foreach ($files as $file) {
545 $file = htmlspecialchars($file, ENT_QUOTES, "utf-8");
546 $options[$file] = $file;
547 }
548 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
549 $si = new ilSelectInputGUI($this->lng->txt("cont_uploaded_file"), "uploaded_file");
550 $si->setOptions($options);
551 $ilToolbar->addInputItem($si, true);
552 $ilToolbar->addFormButton($lng->txt("copy"), "uploadFile");
553 }
554
555 $fs_table = $this->getTable($dir["dir"], $dir["subdir"]);
556
557 if ($this->getTitle() != "") {
558 $fs_table->setTitle($this->getTitle());
559 }
560 if ($_GET["resetoffset"] == 1) {
561 $fs_table->resetOffset();
562 }
563 $this->tpl->setContent($fs_table->getHTML());
564 }
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, $lng, $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 333 of file class.ilFileSystemGUI.php.

334 {
335 // determine directory
336 // FIXME: I have to call stripSlashes here twice, because I could not
337 // determine where the second layer of slashes is added to the
338 // URL Parameter
339 $cur_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET[self::CDIR]));
340 $new_subdir = ilUtil::stripSlashes(ilUtil::stripSlashes($_GET["newdir"]));
341
342 if ($new_subdir == "..") {
343 $cur_subdir = substr($cur_subdir, 0, strrpos($cur_subdir, "/"));
344 } else {
345 if (!empty($new_subdir)) {
346 if (!empty($cur_subdir)) {
347 $cur_subdir = $cur_subdir . "/" . $new_subdir;
348 } else {
349 $cur_subdir = $new_subdir;
350 }
351 }
352 }
353
354 $cur_subdir = str_replace("..", "", $cur_subdir);
355 $cur_dir = (!empty($cur_subdir))
356 ? $this->main_dir . "/" . $cur_subdir
357 : $this->main_dir;
358
359 return array("dir" => $cur_dir, "subdir" => $cur_subdir);
360 }

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

632 {
633 global $DIC;
634 $lng = $DIC['lng'];
635
636 $new_name = str_replace("..", "", ilUtil::stripSlashes($_POST["new_name"]));
637 $new_name = str_replace("/", "", $new_name);
638 if ($new_name == "") {
639 $this->ilias->raiseError($this->lng->txt("enter_new_name"), $this->ilias->error_obj->MESSAGE);
640 }
641
642 $pi = pathinfo($new_name);
643 $suffix = $pi["extension"];
644 if ($suffix != "" && !$this->isValidSuffix($suffix)) {
645 ilUtil::sendFailure($this->lng->txt("file_no_valid_file_type") . " ($suffix)", true);
646 $this->ctrl->redirect($this, "listFiles");
647 }
648
649 $cur_subdir = $this->sanitizeCurrentDirectory();
650 $dir = (!empty($cur_subdir))
651 ? $this->main_dir . "/" . $cur_subdir . "/"
652 : $this->main_dir . "/";
653
654 // check if this path is inside $dir
655 $old_name = ilUtil::stripSlashes($_GET["old_name"]);
656 $realpath = realpath($dir . $old_name);
657 if (strpos($realpath, realpath($dir)) !== 0) {
658 $this->ilias->raiseError($this->lng->txt("no_permission"), $this->ilias->error_obj->MESSAGE);
659 }
660
661 if (is_dir($dir . $old_name)) {
662 rename($dir . $old_name, $dir . $new_name);
663 } else {
664 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
665
666 try {
667 ilFileUtils::rename($dir . $old_name, $dir . $new_name);
668 } catch (ilException $e) {
669 ilUtil::sendFailure($e->getMessage(), true);
670 $this->ctrl->redirect($this, "listFiles");
671 }
672 }
673
674 ilUtil::renameExecutables($this->main_dir);
675 if (@is_dir($dir . $new_name)) {
676 ilUtil::sendSuccess($lng->txt("cont_dir_renamed"), true);
677 $this->setPerformedCommand("rename_dir", array("old_name" => $_GET["old_name"],
678 "new_name" => $new_name));
679 } else {
680 ilUtil::sendSuccess($lng->txt("cont_file_renamed"), true);
681 $this->setPerformedCommand("rename_file", array("old_name" => $_GET["old_name"],
682 "new_name" => $new_name));
683 }
684 $this->ctrl->redirect($this, "listFiles");
685 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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, Vendor\Package\$e, $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 592 of file class.ilFileSystemGUI.php.

593 {
594 global $DIC;
595 $lng = $DIC['lng'];
596 $ilCtrl = $DIC['ilCtrl'];
597
598 $cur_subdir = $this->sanitizeCurrentDirectory();
599 $file = $this->main_dir . "/" . $a_file;
600
601 $this->ctrl->setParameter($this, "old_name", basename($a_file));
602 $this->ctrl->setParameter($this, self::CDIR, ilUtil::stripSlashes($_GET[self::CDIR]));
603
604 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
605 $form = new ilPropertyFormGUI();
606
607 // file/dir name
608 $ti = new ilTextInputGUI($this->lng->txt("name"), "new_name");
609 $ti->setMaxLength(200);
610 $ti->setSize(40);
611 $ti->setValue(basename($a_file));
612 $form->addItem($ti);
613
614 // save and cancel commands
615 $form->addCommandButton("renameFile", $lng->txt("rename"));
616 $form->addCommandButton("cancelRename", $lng->txt("cancel"));
617 $form->setFormAction($ilCtrl->getFormAction($this, "renameFile"));
618
619 if (@is_dir($file)) {
620 $form->setTitle($this->lng->txt("cont_rename_dir"));
621 } else {
622 $form->setTitle($this->lng->txt("rename_file"));
623 }
624
625 $this->tpl->setContent($form->getHTML());
626 }
This class represents a property form user interface.

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

+ Here is the call graph for this function:

◆ sanitizeCurrentDirectory()

ilFileSystemGUI::sanitizeCurrentDirectory ( )
private
Returns
string

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

1045 {
1046 global $DIC;
1047
1048 return str_replace("..", "", ilUtil::stripSlashes($DIC->http()->request()->getQueryParams()[self::CDIR]));
1049 }

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

139 {
140 $this->allow_directories = $a_val;
141 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setAllowDirectoryCreation()

ilFileSystemGUI::setAllowDirectoryCreation (   $a_val)

Set allowed directory creation.

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

472 {
473 $this->directory_creation = $a_val;
474 }

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

78 {
79 $this->allowed_suffixes = $a_suffixes;
80 }

◆ setAllowFileCreation()

ilFileSystemGUI::setAllowFileCreation (   $a_val)

Set allowed file creation.

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

488 {
489 $this->file_creation = $a_val;
490 }

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

98 {
99 $this->forbidden_suffixes = $a_suffixes;
100 }

◆ setPerformedCommand()

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

Set performed command.

Parameters
stringcommand
arrayparameter array

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

240 {
241 if (!is_array($pars)) {
242 $pars = array();
243 }
244 $_SESSION["fsys"]["lastcomm"] = array_merge(
245 array("cmd" => $command),
246 $pars
247 );
248 }

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

159 {
160 $this->post_dir_path = $a_val;
161 }

◆ setTableId()

ilFileSystemGUI::setTableId (   $a_val)

Set table id.

Parameters
stringtable id

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

179 {
180 $this->table_id = $a_val;
181 }

◆ setTitle()

ilFileSystemGUI::setTitle (   $a_val)

Set title.

Parameters
stringtitle

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

199 {
200 $this->title = $a_val;
201 }

◆ setUseUploadDirectory()

ilFileSystemGUI::setUseUploadDirectory (   $a_val)

Set use upload directory.

Parameters
bool$a_valuse upload directory

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

219 {
220 $this->use_upload_directory = $a_val;
221 }

◆ unzipFile()

ilFileSystemGUI::unzipFile (   $a_file = null)

delete object file

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

884 {
885 global $DIC;
886 $lng = $DIC['lng'];
887
888 // #17470 - direct unzip call (after upload)
889 if (!$a_file &&
890 isset($_GET["upfile"])) {
891 $a_file = basename($_GET["upfile"]);
892 }
893
894 $cur_subdir = $this->sanitizeCurrentDirectory();
895 $cur_dir = (!empty($cur_subdir))
896 ? $this->main_dir . "/" . $cur_subdir
897 : $this->main_dir;
898 $a_file = $this->main_dir . "/" . $a_file;
899
900 if (@is_file($a_file)) {
901 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
902 $cur_files = array_keys(ilUtil::getDir($cur_dir));
903 $cur_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
904
905 if ($this->getAllowDirectories()) {
906 ilUtil::unzip($a_file, true);
907 } else {
908 ilUtil::unzip($a_file, true, true);
909 }
910
911 $new_files = array_keys(ilUtil::getDir($cur_dir));
912 $new_files_r = iterator_to_array(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cur_dir)));
913
914 $diff = array_diff($new_files, $cur_files);
915 $diff_r = array_diff($new_files_r, $cur_files_r);
916
917 // unlink forbidden file types
918 foreach ($diff_r as $f => $d) {
919 $pi = pathinfo($f);
920 if (!is_dir($f) && !$this->isValidSuffix(strtolower($pi["extension"]))) {
921 ilUtil::sendFailure($lng->txt("file_some_invalid_file_types_removed") . " (" . $pi["extension"] . ")", true);
922 unlink($f);
923 }
924 }
925
926 if (sizeof($diff)) {
927 if ($this->getAllowDirectories()) {
928 include_once("./Services/Utilities/classes/class.ilFileUtils.php");
929 $new_files = array();
930
931 foreach ($diff as $new_item) {
932 if (is_dir($cur_dir . "/" . $new_item)) {
933 ilFileUtils::recursive_dirscan($cur_dir . "/" . $new_item, $new_files);
934 }
935 }
936
937 if (is_array($new_files["path"])) {
938 foreach ($new_files["path"] as $idx => $path) {
939 $path = substr($path, strlen($this->main_dir) + 1);
940 $diff[] = $path . $new_files["file"][$idx];
941 }
942 }
943 }
944
945 $this->setPerformedCommand(
946 "unzip_file",
947 array("name" => substr($file, strlen($this->main_dir) + 1),
948 "added" => $diff)
949 );
950 }
951 }
952
953 ilUtil::renameExecutables($this->main_dir);
954
955 $this->ctrl->saveParameter($this, self::CDIR);
956 ilUtil::sendSuccess($lng->txt("cont_file_unzipped"), true);
957 $this->ctrl->redirect($this, "listFiles");
958 }
static recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296

References $_GET, $d, $DIC, Vendor\Package\$f, $lng, 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 729 of file class.ilFileSystemGUI.php.

730 {
731 global $DIC;
732 $lng = $DIC['lng'];
733
734 // determine directory
735 $cur_subdir = $this->sanitizeCurrentDirectory();
736 $cur_dir = (!empty($cur_subdir))
737 ? $this->main_dir . "/" . $cur_subdir
738 : $this->main_dir;
739
740 $tgt_file = null;
741
742 $pi = pathinfo($_FILES["new_file"]["name"]);
743 $suffix = $pi["extension"];
744 if (!$this->isValidSuffix($suffix)) {
745 ilUtil::sendFailure($this->lng->txt("file_no_valid_file_type") . " ($suffix)", true);
746 $this->ctrl->redirect($this, "listFiles");
747 }
748
749 if (is_file($_FILES["new_file"]["tmp_name"])) {
750 $name = $this->secure(ilUtil::stripSlashes($_FILES["new_file"]["name"]));
751 $tgt_file = $cur_dir . "/" . $name;
752 try {
753 ilUtil::moveUploadedFile($_FILES["new_file"]["tmp_name"], $name, $tgt_file);
754 } catch (ilException $e) {
755 ilUtil::sendFailure($e->getMessage(), true);
756 $this->ctrl->redirect($this, "listFiles");
757 }
758 } elseif ($_POST["uploaded_file"]) {
759 include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
760
761 // check if the file is in the ftp directory and readable
762 if (ilUploadFiles::_checkUploadFile($_POST["uploaded_file"])) {
763 $tgt_file = $cur_dir . "/" . ilUtil::stripSlashes($_POST["uploaded_file"]);
764
765 // copy uploaded file to data directory
766 ilUploadFiles::_copyUploadFile($_POST["uploaded_file"], $tgt_file);
767 }
768 } elseif (trim($_FILES["new_file"]["name"]) == "") {
769 ilUtil::sendFailure($lng->txt("cont_enter_a_file"), true);
770 }
771
772 if ($tgt_file && is_file($tgt_file)) {
773 $unzip = null;
774
775 // extract zip?
776 include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
777 if (ilMimeTypeUtil::getMimeType($tgt_file) == "application/zip") {
778 $this->ctrl->setParameter($this, "upfile", basename($tgt_file));
779 $url = $this->ctrl->getLinkTarget($this, "unzipFile");
780 $this->ctrl->setParameter($this, "upfile", "");
781
782 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
783 $unzip = ilLinkButton::getInstance();
784 $unzip->setCaption("unzip");
785 $unzip->setUrl($url);
786 $unzip = " " . $unzip->render();
787 }
788
789 ilUtil::sendSuccess($lng->txt("cont_file_created") . $unzip, true);
790
791 $this->setPerformedCommand(
792 "create_file",
793 array("name" => substr($tgt_file, strlen($this->main_dir) + 1))
794 );
795 }
796
797 $this->ctrl->saveParameter($this, self::CDIR);
798
799 ilUtil::renameExecutables($this->main_dir);
800
801 $this->ctrl->redirect($this, 'listFiles');
802 }
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
if($format !==null) $name
Definition: metadata.php:230
$url

References $_POST, $DIC, Vendor\Package\$e, $lng, $name, $url, ilUploadFiles\_checkUploadFile(), ilUploadFiles\_copyUploadFile(), ilLinkButton\getInstance(), ilMimeTypeUtil\getMimeType(), isValidSuffix(), ilUtil\moveUploadedFile(), 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 38 of file class.ilFileSystemGUI.php.

Referenced by getAllowedSuffixes().

◆ $ctrl

ilFileSystemGUI::$ctrl

◆ $forbidden_suffixes

ilFileSystemGUI::$forbidden_suffixes = array()
protected

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

Referenced by getForbiddenSuffixes().

◆ $use_upload_directory

ilFileSystemGUI::$use_upload_directory = false
protected

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

Referenced by getUseUploadDirectory().

◆ CDIR

const ilFileSystemGUI::CDIR = "cdir"

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


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