delete.php 1.7 KB

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