1
0

delete.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Björn Schießle <schiessle@owncloud.com>
  5. * @author Lukas Reschke <lukas@owncloud.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <icewind@owncloud.com>
  8. * @author Vincent Petry <pvince81@owncloud.com>
  9. *
  10. * @copyright Copyright (c) 2015, ownCloud, Inc.
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. OCP\JSON::checkLoggedIn();
  27. OCP\JSON::callCheck();
  28. \OC::$server->getSession()->close();
  29. $folder = isset($_POST['dir']) ? $_POST['dir'] : '/';
  30. // "empty trash" command
  31. if (isset($_POST['allfiles']) && (string)$_POST['allfiles'] === 'true'){
  32. $deleteAll = true;
  33. if ($folder === '/' || $folder === '') {
  34. OCA\Files_Trashbin\Trashbin::deleteAll();
  35. $list = array();
  36. } else {
  37. $list[] = $folder;
  38. $folder = dirname($folder);
  39. }
  40. }
  41. else {
  42. $deleteAll = false;
  43. $files = (string)$_POST['files'];
  44. $list = json_decode($files);
  45. }
  46. $folder = rtrim($folder, '/') . '/';
  47. $error = array();
  48. $success = array();
  49. $i = 0;
  50. foreach ($list as $file) {
  51. if ($folder === '/') {
  52. $file = ltrim($file, '/');
  53. $delimiter = strrpos($file, '.d');
  54. $filename = substr($file, 0, $delimiter);
  55. $timestamp = substr($file, $delimiter+2);
  56. } else {
  57. $filename = $folder . '/' . $file;
  58. $timestamp = null;
  59. }
  60. OCA\Files_Trashbin\Trashbin::delete($filename, \OCP\User::getUser(), $timestamp);
  61. if (OCA\Files_Trashbin\Trashbin::file_exists($filename, $timestamp)) {
  62. $error[] = $filename;
  63. OC_Log::write('trashbin','can\'t delete ' . $filename . ' permanently.', OC_Log::ERROR);
  64. }
  65. // only list deleted files if not deleting everything
  66. else if (!$deleteAll) {
  67. $success[$i]['filename'] = $file;
  68. $success[$i]['timestamp'] = $timestamp;
  69. $i++;
  70. }
  71. }
  72. if ( $error ) {
  73. $filelist = '';
  74. foreach ( $error as $e ) {
  75. $filelist .= $e.', ';
  76. }
  77. $l = \OC::$server->getL10N('files_trashbin');
  78. $message = $l->t("Couldn't delete %s permanently", array(rtrim($filelist, ', ')));
  79. OCP\JSON::error(array("data" => array("message" => $message,
  80. "success" => $success, "error" => $error)));
  81. } else {
  82. OCP\JSON::success(array("data" => array("success" => $success)));
  83. }