ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilFileSystemGUI Class Reference

File System Explorer GUI class. More...

+ Collaboration diagram for ilFileSystemGUI:

Public Member Functions

 ilFileSystemGUI ($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.

Member Function Documentation

◆ activateLabels()

ilFileSystemGUI::activateLabels (   $a_act,
  $a_label_header 
)

activate file labels

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

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

◆ addCommand()

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

Add command.

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

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

◆ cancelRename()

ilFileSystemGUI::cancelRename ( )

cancel renaming a file

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

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

◆ clearCommands()

ilFileSystemGUI::clearCommands ( )

Clear commands.

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

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

◆ confirmDeleteFile()

ilFileSystemGUI::confirmDeleteFile ( array  $a_files)

Confirm file deletion.

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

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

References $ilCtrl, $lng, and $tpl.

◆ createDirectory()

ilFileSystemGUI::createDirectory ( )

create directory

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

715 {
716 global $lng;
717
718 // determine directory
719 $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
720 $cur_dir = (!empty($cur_subdir))
721 ? $this->main_dir."/".$cur_subdir
722 : $this->main_dir;
723
724 $new_dir = str_replace(".", "", ilUtil::stripSlashes($_POST["new_dir"]));
725 $new_dir = str_replace("/", "", $new_dir);
726
727 if (!empty($new_dir))
728 {
729 ilUtil::makeDir($cur_dir."/".$new_dir);
730 if (is_dir($cur_dir."/".$new_dir))
731 {
732 ilUtil::sendSuccess($lng->txt("cont_dir_created"), true);
733 $this->setPerformedCommand("create_dir", array("name" => $new_dir));
734 }
735 }
736 else
737 {
738 ilUtil::sendFailure($lng->txt("cont_enter_a_dir_name"), true);
739 }
740 $this->ctrl->saveParameter($this, "cdir");
741 $this->ctrl->redirect($this, "listFiles");
742 }
$_GET["client_id"]
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 ...
$_POST['username']
Definition: cron.php:12

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

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

996 {
997 $file = $this->main_dir."/".$a_file;
998
999 if (@is_file($file) && !(@is_dir($file)))
1000 {
1001 ilUtil::deliverFile($file, basename($a_file));
1002 exit;
1003 }
1004 else
1005 {
1006 $this->ctrl->saveParameter($this, "cdir");
1007 $this->ctrl->redirect($this, "listFiles");
1008 }
1009 }
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:54

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

+ Here is the call graph for this function:

◆ executeCommand()

& ilFileSystemGUI::executeCommand ( )

execute command

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

277 {
278 $next_class = $this->ctrl->getNextClass($this);
279 $cmd = $this->ctrl->getCmd("listFiles");
280
281 switch($next_class)
282 {
283
284 default:
285 if (substr($cmd, 0, 11) == "extCommand_")
286 {
287 $ret =& $this->extCommand(substr($cmd, 11, strlen($cmd) - 11));
288 }
289 else
290 {
291 $ret =& $this->$cmd();
292 }
293 break;
294 }
295
296 return $ret;
297 }
extCommand($a_nr)
call external command
$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 450 of file class.ilFileSystemGUI.php.

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

References $_GET, $file, getIncomingFiles(), if, 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 160 of file class.ilFileSystemGUI.php.

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

Referenced by listFiles(), and unzipFile().

+ Here is the caller graph for this function:

◆ getAllowDirectoryCreation()

ilFileSystemGUI::getAllowDirectoryCreation ( )

Get allowed directory creation.

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

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

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getAllowedSuffixes()

ilFileSystemGUI::getAllowedSuffixes ( )

Get allowed Suffixes.

Returns
array allowed Suffixes

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

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

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getFileList()

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

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

381 {
382 $items = array();
383
384 $entries = (is_dir($a_dir))
385 ? ilUtil::getDir($a_dir)
386 : array(array("type" => "dir", "entry" => ".."));
387
388 $items = array();
389 foreach ($entries as $e)
390 {
391 if(($e["entry"] == ".") ||
392 ($e["entry"] == ".." && empty($a_subdir)))
393 {
394 continue;
395 }
396
397 $cfile = (!empty($a_subdir))
398 ? $a_subdir."/".$e["entry"]
399 : $e["entry"];
400
401 $items[] = array(
402 "file" => $cfile,
403 "entry" => $e["entry"],
404 "type" => $e["type"],
405 "size" => $e["size"],
406 "hash" => md5($e["entry"])
407 );
408 }
409
410 return $items;
411 }
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 116 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 413 of file class.ilFileSystemGUI.php.

414 {
415 $sel_files = $hashes = array();
416 if (isset($_POST["file"]))
417 {
418 $hashes = $_POST["file"];
419 }
420 else if(isset($_GET["fhsh"]))
421 {
422 $hashes = array($_GET["fhsh"]);
423 }
424
425 if(sizeof($hashes))
426 {
427 $dir = $this->parseCurrentDirectory();
428 $all_files = $this->getFileList($dir["dir"], $dir["subdir"]);
429 foreach($hashes as $hash)
430 {
431 foreach($all_files as $file)
432 {
433 if($file["hash"] == $hash)
434 {
435 $sel_files[] = $this->getPostDirPath()
436 ? $file["file"]
437 : $file["entry"];
438 break;
439 }
440 }
441 }
442 }
443
444 return $sel_files;
445 }
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 266 of file class.ilFileSystemGUI.php.

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

References $_SESSION, and $ret.

◆ getPostDirPath()

ilFileSystemGUI::getPostDirPath ( )

Get post dir path.

Returns
boolean post dir path

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

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

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

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

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ getTabs()

ilFileSystemGUI::getTabs ( $tabs_gui)

get tabs

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

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

References $ilCtrl.

◆ getTitle()

ilFileSystemGUI::getTitle ( )

Get title.

Returns
string title

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

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

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

References $use_upload_directory.

Referenced by listFiles().

+ Here is the caller graph for this function:

◆ ilFileSystemGUI()

ilFileSystemGUI::ilFileSystemGUI (   $a_main_directory)

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

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

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

+ Here is the call graph for this function:

◆ isValidSuffix()

ilFileSystemGUI::isValidSuffix (   $a_suffix)

Is suffix valid?

Parameters
string$a_suffix
Returns
bool

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

128 {
129 if (is_array($this->getForbiddenSuffixes()) && in_array($a_suffix, $this->getForbiddenSuffixes()))
130 {
131 return false;
132 }
133 if (is_array($this->getAllowedSuffixes()) && in_array($a_suffix, $this->getAllowedSuffixes()))
134 {
135 return true;
136 }
137 if (!is_array($this->getAllowedSuffixes()) || count($this->getAllowedSuffixes()) == 0)
138 {
139 return true;
140 }
141 return false;
142 }
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 328 of file class.ilFileSystemGUI.php.

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

◆ listFiles()

ilFileSystemGUI::listFiles ( )

list files

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

536 {
537 global $ilToolbar, $lng, $ilCtrl;
538
539 $dir = $this->parseCurrentDirectory();
540
541 $this->ctrl->setParameter($this, "cdir", $dir["subdir"]);
542
543 // toolbar for adding files/directories
544 $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
545 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
546
547 if ($this->getAllowDirectories() && $this->getAllowDirectoryCreation())
548 {
549 $ti = new ilTextInputGUI($this->lng->txt("cont_new_dir"), "new_dir");
550 $ti->setMaxLength(80);
551 $ti->setSize(10);
552 $ilToolbar->addInputItem($ti, true);
553 $ilToolbar->addFormButton($lng->txt("create"), "createDirectory");
554
555 $ilToolbar->addSeparator();
556 }
557
558 include_once("./Services/Form/classes/class.ilFileInputGUI.php");
559 if ($this->getAllowFileCreation())
560 {
561 $fi = new ilFileInputGUI($this->lng->txt("cont_new_file"), "new_file");
562 $fi->setSize(10);
563 $ilToolbar->addInputItem($fi, true);
564 $ilToolbar->addFormButton($lng->txt("upload"), "uploadFile");
565 }
566
567 include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
569 {
570 $ilToolbar->addSeparator();
572 $options[""] = $lng->txt("cont_select_from_upload_dir");
573 foreach($files as $file)
574 {
575 $file = htmlspecialchars($file, ENT_QUOTES, "utf-8");
577 }
578 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
579 $si = new ilSelectInputGUI($this->lng->txt("cont_uploaded_file"), "uploaded_file");
580 $si->setOptions($options);
581 $ilToolbar->addInputItem($si, true);
582 $ilToolbar->addFormButton($lng->txt("copy"), "uploadFile");
583 }
584
585 // load files templates
586 include_once("./Services/FileSystem/classes/class.ilFileSystemTableGUI.php");
587 $fs_table = new ilFileSystemTableGUI($this, "listFiles", $dir["dir"], $dir["subdir"],
588 $this->label_enable, $this->file_labels, $this->label_header, $this->commands,
589 $this->getPostDirPath(), $this->getTableId());
590 if ($this->getTitle() != "")
591 {
592 $fs_table->setTitle($this->getTitle());
593 }
594 if ($_GET["resetoffset"] == 1)
595 {
596 $fs_table->resetOffset();
597 }
598 $this->tpl->setContent($fs_table->getHTML());
599 }
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, $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 344 of file class.ilFileSystemGUI.php.

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

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

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

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

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

Referenced by ilFileSystemGUI().

+ Here is the caller graph for this function:

◆ setAllowDirectoryCreation()

ilFileSystemGUI::setAllowDirectoryCreation (   $a_val)

Set allowed directory creation.

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

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

Referenced by ilFileSystemGUI().

+ Here is the caller graph for this function:

◆ setAllowedSuffixes()

ilFileSystemGUI::setAllowedSuffixes (   $a_suffixes)

Set allowed Suffixes.

Parameters
array$a_suffixesallowed Suffixes

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

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

◆ setAllowFileCreation()

ilFileSystemGUI::setAllowFileCreation (   $a_val)

Set allowed file creation.

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

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

Referenced by ilFileSystemGUI().

+ Here is the caller graph for this function:

◆ setForbiddenSuffixes()

ilFileSystemGUI::setForbiddenSuffixes (   $a_suffixes)

Set forbidden Suffixes.

Parameters
array$a_suffixesforbidden Suffixes

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

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

◆ setPerformedCommand()

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

Set performed command.

Parameters
stringcommand
arrayparameter array

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

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

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

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

◆ setTableId()

ilFileSystemGUI::setTableId (   $a_val)

Set table id.

Parameters
stringtable id

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

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

◆ setTitle()

ilFileSystemGUI::setTitle (   $a_val)

Set title.

Parameters
stringtitle

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

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

◆ setUseUploadDirectory()

ilFileSystemGUI::setUseUploadDirectory (   $a_val)

Set use upload directory.

Parameters
bool$a_valuse upload directory

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

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

◆ unzipFile()

ilFileSystemGUI::unzipFile (   $a_file = null)

delete object file

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

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

References $_GET, $d, $file, $lng, $path, getAllowDirectories(), ilUtil\getDir(), if, 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 747 of file class.ilFileSystemGUI.php.

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