|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package File manager |
|
5
|
|
|
* @author Iurii Makukh <[email protected]> |
|
6
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh <[email protected]> |
|
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace gplcart\modules\file_manager\handlers\commands; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Contains methods for "delete" command |
|
14
|
|
|
*/ |
|
15
|
|
|
class Delete extends Command |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Whether the command is allowed for the file |
|
20
|
|
|
* @param \SplFileInfo $file |
|
21
|
|
|
* @return bool |
|
22
|
|
|
*/ |
|
23
|
|
|
public function allowed($file) |
|
24
|
|
|
{ |
|
25
|
|
|
return in_array($file->getType(), array('file', 'dir')) && !$this->isInitialPath($file); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Returns an array of data used to display the command |
|
30
|
|
|
* @param \SplFileInfo $file |
|
31
|
|
|
* @return array |
|
32
|
|
|
*/ |
|
33
|
|
|
public function view($file) |
|
34
|
|
|
{ |
|
35
|
|
|
return array( |
|
36
|
|
|
'file_manager|commands/delete' => array( |
|
37
|
|
|
'path' => $this->getRelativePath($file->getRealPath()) |
|
38
|
|
|
)); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Delete file(s) |
|
43
|
|
|
* @param \gplcart\core\Controller $controller |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
|
|
public function submit($controller) |
|
47
|
|
|
{ |
|
48
|
|
|
set_time_limit(0); |
|
49
|
|
|
|
|
50
|
|
|
$path = null; |
|
51
|
|
|
$errors = $success = 0; |
|
52
|
|
|
|
|
53
|
|
|
/* @var $file \SplFileInfo */ |
|
54
|
|
|
foreach ($controller->getSubmitted('files', array()) as $file) { |
|
55
|
|
|
$path = $file->getRealPath(); |
|
56
|
|
|
gplcart_file_delete_recursive($path, $errors, $success); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$query = array( |
|
60
|
|
|
'cmd' => 'list', |
|
61
|
|
|
'path' => isset($path) ? $this->getRelativeDirectory($path) : '' |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
$vars = array('@num_success' => $success, '@num_errors' => $errors); |
|
65
|
|
|
|
|
66
|
|
|
return array( |
|
67
|
|
|
'redirect' => $controller->url('', $query), |
|
68
|
|
|
'severity' => empty($errors) ? 'success' : 'warning', |
|
69
|
|
|
'message' => $this->translation->text('Deleted @num_success, errors: @num_errors', $vars) |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|