delete.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. OCP\JSON::checkLoggedIn();
  3. OCP\JSON::callCheck();
  4. // "empty trash" command
  5. if (isset($_POST['allfiles']) and $_POST['allfiles'] === 'true'){
  6. $deleteAll = true;
  7. $folder = isset($_POST['dir']) ? $_POST['dir'] : '/';
  8. if ($folder === '/' || $folder === '') {
  9. OCA\Files_Trashbin\Trashbin::deleteAll();
  10. $list = array();
  11. } else {
  12. $dirname = dirname($folder);
  13. if ( $dirname !== '/' && $dirname !== '.' ) {
  14. $dirlisting = '1';
  15. } else {
  16. $dirlisting = '0';
  17. }
  18. $list[] = $folder;
  19. }
  20. }
  21. else {
  22. $deleteAll = false;
  23. $files = $_POST['files'];
  24. $dirlisting = $_POST['dirlisting'];
  25. $list = json_decode($files);
  26. }
  27. $error = array();
  28. $success = array();
  29. $i = 0;
  30. foreach ($list as $file) {
  31. if ( $dirlisting === '0') {
  32. $file = ltrim($file, '/');
  33. $delimiter = strrpos($file, '.d');
  34. $filename = substr($file, 0, $delimiter);
  35. $timestamp = substr($file, $delimiter+2);
  36. } else {
  37. $filename = $file;
  38. $timestamp = null;
  39. }
  40. OCA\Files_Trashbin\Trashbin::delete($filename, $timestamp);
  41. if (OCA\Files_Trashbin\Trashbin::file_exists($filename, $timestamp)) {
  42. $error[] = $filename;
  43. OC_Log::write('trashbin','can\'t delete ' . $filename . ' permanently.', OC_Log::ERROR);
  44. }
  45. // only list deleted files if not deleting everything
  46. else if (!$deleteAll) {
  47. $success[$i]['filename'] = $file;
  48. $success[$i]['timestamp'] = $timestamp;
  49. $i++;
  50. }
  51. }
  52. if ( $error ) {
  53. $filelist = '';
  54. foreach ( $error as $e ) {
  55. $filelist .= $e.', ';
  56. }
  57. $l = OC_L10N::get('files_trashbin');
  58. $message = $l->t("Couldn't delete %s permanently", array(rtrim($filelist, ', ')));
  59. OCP\JSON::error(array("data" => array("message" => $message,
  60. "success" => $success, "error" => $error)));
  61. } else {
  62. OCP\JSON::success(array("data" => array("success" => $success)));
  63. }