ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilFileSystemGUI.php
Go to the documentation of this file.
1 <?php
19 
29 {
30  use SecureString; // This is just for those legacy classes which will be removed soon anyway.
31  public $ctrl;
32 
33  protected $use_upload_directory = false;
34  const CDIR = "cdir";
38  protected $allowed_suffixes = array();
39 
43  protected $forbidden_suffixes = array();
44 
45  public function __construct($a_main_directory)
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  }
71 
77  public function setAllowedSuffixes($a_suffixes)
78  {
79  $this->allowed_suffixes = $a_suffixes;
80  }
81 
87  public function getAllowedSuffixes()
88  {
90  }
91 
97  public function setForbiddenSuffixes($a_suffixes)
98  {
99  $this->forbidden_suffixes = $a_suffixes;
100  }
101 
107  public function getForbiddenSuffixes()
108  {
110  }
111 
118  public function isValidSuffix($a_suffix)
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  }
131 
132 
138  public function setAllowDirectories($a_val)
139  {
140  $this->allow_directories = $a_val;
141  }
142 
148  public function getAllowDirectories()
149  {
150  return $this->allow_directories;
151  }
152 
158  public function setPostDirPath($a_val)
159  {
160  $this->post_dir_path = $a_val;
161  }
162 
168  public function getPostDirPath()
169  {
170  return $this->post_dir_path;
171  }
172 
178  public function setTableId($a_val)
179  {
180  $this->table_id = $a_val;
181  }
182 
188  public function getTableId()
189  {
190  return $this->table_id;
191  }
192 
198  public function setTitle($a_val)
199  {
200  $this->title = $a_val;
201  }
202 
208  public function getTitle()
209  {
210  return $this->title;
211  }
212 
218  public function setUseUploadDirectory($a_val)
219  {
220  $this->use_upload_directory = $a_val;
221  }
222 
228  public function getUseUploadDirectory()
229  {
231  }
232 
239  protected function setPerformedCommand($command, $pars = "")
240  {
241  if (!is_array($pars)) {
242  $pars = array();
243  }
244  $_SESSION["fsys"]["lastcomm"] = array_merge(
245  array("cmd" => $command),
246  $pars
247  );
248  }
249 
255  public function getLastPerformedCommand()
256  {
257  $ret = $_SESSION["fsys"]["lastcomm"];
258  $_SESSION["fsys"]["lastcomm"] = "none";
259  return $ret;
260  }
261 
265  public function executeCommand()
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  }
283 
284 
288  public function addCommand(
289  &$a_obj,
290  $a_func,
291  $a_name,
292  $a_single = true,
293  $a_allow_dir = false
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  }
305 
309  public function clearCommands()
310  {
311  $this->commands = array();
312  }
313 
317  public function labelFile($a_file, $a_label)
318  {
319  $this->file_labels[$a_file][] = $a_label;
320  }
321 
325  public function activateLabels($a_act, $a_label_header)
326  {
327  $this->label_enable = $a_act;
328  $this->label_header = $a_label_header;
329  }
330 
331 
332 
333  protected function parseCurrentDirectory()
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  }
361 
362  protected function getFileList($a_dir, $a_subdir = null)
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  }
392 
393  protected function getIncomingFiles()
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  }
419 
423  public function extCommand($a_nr)
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  }
467 
471  public function setAllowDirectoryCreation($a_val)
472  {
473  $this->directory_creation = $a_val;
474  }
475 
479  public function getAllowDirectoryCreation()
480  {
481  return $this->directory_creation;
482  }
483 
487  public function setAllowFileCreation($a_val)
488  {
489  $this->file_creation = $a_val;
490  }
491 
495  public function getAllowFileCreation()
496  {
497  return $this->file_creation;
498  }
499 
506  public function listFiles($a_table_gui = null)
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  }
565 
572  public function getTable($a_dir, $a_subdir)
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  }
588 
592  public function renameFileForm($a_file)
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  }
627 
631  public function renameFile()
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  }
686 
690  public function cancelRename()
691  {
692  $this->ctrl->redirect($this, "listFiles");
693  }
694 
698  public function createDirectory()
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  }
724 
729  public function uploadFile()
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  }
803 
807  public function confirmDeleteFile(array $a_files)
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  }
827 
831  public function deleteFile()
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  }
879 
883  public function unzipFile($a_file = null)
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  }
959 
963  public function downloadFile($a_file)
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  }
975 
979  public function getTabs(&$tabs_gui)
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  }
993 
997  public function getActionCommands()
998  {
999  return $this->commands;
1000  }
1001 
1005  public function defineCommands()
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  }
1039 
1040 
1044  private function sanitizeCurrentDirectory()
1045  {
1046  global $DIC;
1047 
1048  return str_replace("..", "", ilUtil::stripSlashes($DIC->http()->request()->getQueryParams()[self::CDIR]));
1049  }
1050 }
downloadFile($a_file)
delete object file
listFiles($a_table_gui=null)
List files.
exit
Definition: login.php:29
setTitle($a_val)
Set title.
$_SESSION["AccountId"]
activateLabels($a_act, $a_label_header)
activate file labels
This class represents a property form user interface.
getTableId()
Get table id.
setPostDirPath($a_val)
Set post dir path.
$_GET["client_id"]
This class represents a file property in a property form.
setAllowDirectories($a_val)
Set allow directories.
renameFileForm($a_file)
list files
getAllowDirectoryCreation()
Get allowed directory creation.
getForbiddenSuffixes()
Get Accepted Suffixes.
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
addCommand(&$a_obj, $a_func, $a_name, $a_single=true, $a_allow_dir=false)
Add command.
static _getUploadDirectory()
Get the directory with uploaded files.
static _getUploadFiles()
Get a list of readable files in the upload directory.
getAllowedSuffixes()
Get allowed Suffixes.
setSize($a_size)
Set Size.
setUseUploadDirectory($a_val)
Set use upload directory.
getLastPerformedCommand()
Get performed command.
getTable($a_dir, $a_subdir)
Get table.
createDirectory()
create directory
clearCommands()
Clear commands.
static rename($a_source, $a_target)
Rename a file.
static getMimeType($a_file='', $a_filename='', $a_mime='')
setTableId($a_val)
Set table id.
if($format !==null) $name
Definition: metadata.php:230
setForbiddenSuffixes($a_suffixes)
Set forbidden Suffixes.
executeCommand()
execute command
getTabs(&$tabs_gui)
get tabs
extCommand($a_nr)
call external command
deleteFile()
delete object file
$lng
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
getUseUploadDirectory()
Get use upload directory.
cancelRename()
cancel renaming a file
global $DIC
Definition: goto.php:24
setAllowedSuffixes($a_suffixes)
Set allowed Suffixes.
renameFile()
rename a file
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
redirection script todo: (a better solution should control the processing via a xml file) ...
getAllowDirectories()
Get allow directories.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
isValidSuffix($a_suffix)
Is suffix valid?
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
setAllowDirectoryCreation($a_val)
Set allowed directory creation.
__construct($a_main_directory)
defineCommands()
Define commands available.
uploadFile()
Upload file.
getPostDirPath()
Get post dir path.
getFileList($a_dir, $a_subdir=null)
setAllowFileCreation($a_val)
Set allowed file creation.
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
getAllowFileCreation()
Get allowed file creation.
$ret
Definition: parser.php:6
confirmDeleteFile(array $a_files)
Confirm file deletion.
setPerformedCommand($command, $pars="")
Set performed command.
$url
static recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
static _checkUploadFile($a_file)
Check if a file exists in the upload directory and is readable.
File System Explorer GUI class.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
labelFile($a_file, $a_label)
label a file
static _copyUploadFile($a_file, $a_target, $a_raise_errors=true)
copy an uploaded file to the target directory (including virus check)
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
unzipFile($a_file=null)
delete object file
$_POST["username"]
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
$i
Definition: metadata.php:24
Confirmation screen class.
TableGUI class for file system.