1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Cadmium\System\Modules\Filemanager |
5
|
|
|
* @author Anton Romanov |
6
|
|
|
* @copyright Copyright (c) 2015-2017, Anton Romanov |
7
|
|
|
* @link http://cadmium-cms.com |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Modules\Filemanager\Utils { |
11
|
|
|
|
12
|
|
|
use Frames, Modules\Filemanager, Utils\Popup, Utils\View, Ajax, Language, Request, Template; |
13
|
|
|
|
14
|
|
|
abstract class Handler extends Frames\Admin\Area\Panel { |
15
|
|
|
|
16
|
|
|
protected $parent = null, $entity = null, $link = '', $forms = [], $controllers = []; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Get the contents block |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
private function getContents() : Template\Block { |
23
|
|
|
|
24
|
|
|
$contents = View::get(static::$view); |
25
|
|
|
|
26
|
|
|
# Set origin and title |
27
|
|
|
|
28
|
|
|
$contents->origin = static::$origin; $contents->title = Language::get(static::$title); |
|
|
|
|
29
|
|
|
|
30
|
|
|
# Set breadcrumbs |
31
|
|
|
|
32
|
|
|
$contents->breadcrumbs = $this->parent->getBreadcrumbs(); |
|
|
|
|
33
|
|
|
|
34
|
|
|
# Set parent |
35
|
|
|
|
36
|
|
|
$contents->parent = $this->parent->getPath(); |
|
|
|
|
37
|
|
|
|
38
|
|
|
# Set name |
39
|
|
|
|
40
|
|
|
$contents->name = $this->entity->getName(); |
|
|
|
|
41
|
|
|
|
42
|
|
|
# Set editor mode |
43
|
|
|
|
44
|
|
|
$contents->mode = Mime::getMode($this->entity->getExtension()); |
|
|
|
|
45
|
|
|
|
46
|
|
|
# Implement forms |
47
|
|
|
|
48
|
|
|
foreach ($this->forms as $form) $form->implement($contents); |
49
|
|
|
|
50
|
|
|
# Process info block |
51
|
|
|
|
52
|
|
|
$this->processInfo($contents->getBlock('info')); |
53
|
|
|
|
54
|
|
|
# ------------------------ |
55
|
|
|
|
56
|
|
|
return $contents; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Handle the ajax request |
61
|
|
|
*/ |
62
|
|
|
|
63
|
|
|
private function handleAjax() : Ajax\Response { |
64
|
|
|
|
65
|
|
|
$ajax = Ajax::createResponse(); |
66
|
|
|
|
67
|
|
|
# Create parent |
68
|
|
|
|
69
|
|
|
$this->parent = new static::$container_class(Request::get('parent')); |
70
|
|
|
|
71
|
|
|
# Create entity |
72
|
|
|
|
73
|
|
|
$this->entity = Filemanager::get($this->parent, Request::get('name')); |
74
|
|
|
|
75
|
|
|
# Init entity |
76
|
|
|
|
77
|
|
|
if (!$this->entity->isInited()) { |
78
|
|
|
|
79
|
|
|
return $ajax->setError(Language::get(static::$message_error_remove)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
# Process remove action |
83
|
|
|
|
84
|
|
View Code Duplication |
if ((Request::post('action') === 'remove')) { |
|
|
|
|
85
|
|
|
|
86
|
|
|
if (!static::$permissions['manage'] || !$this->entity->remove()) { |
87
|
|
|
|
88
|
|
|
return $ajax->setError(Language::get(static::$message_error_remove)); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
# ------------------------ |
93
|
|
|
|
94
|
|
|
return $ajax; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Handle the request |
99
|
|
|
* |
100
|
|
|
* @return Template\Block|Ajax\Response : a block object if the ajax param was set to false, otherwise an ajax response |
101
|
|
|
*/ |
102
|
|
|
|
103
|
|
|
protected function handle(bool $ajax = false) { |
104
|
|
|
|
105
|
|
|
# Handle ajax request |
106
|
|
|
|
107
|
|
|
if ($ajax) return $this->handleAjax(); |
108
|
|
|
|
109
|
|
|
# Create parent |
110
|
|
|
|
111
|
|
|
$this->parent = new static::$container_class(Request::get('parent')); |
112
|
|
|
|
113
|
|
|
# Create entity |
114
|
|
|
|
115
|
|
|
$this->entity = Filemanager::get($this->parent, Request::get('name')); |
116
|
|
|
|
117
|
|
|
# Redirect if entity not found |
118
|
|
|
|
119
|
|
|
if (!$this->entity->isInited()) { |
120
|
|
|
|
121
|
|
|
$query = (('' !== $this->parent->getPath()) ? ('?parent=' . $this->parent->getPath()) : ''); |
122
|
|
|
|
123
|
|
|
Request::redirect(INSTALL_PATH . '/admin/content/filemanager/' . static::$origin . '/' . $query); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
# Create rename form |
127
|
|
|
|
128
|
|
|
$this->forms['rename'] = new Filemanager\Form\Rename($this->entity, static::$permissions['manage']); |
129
|
|
|
|
130
|
|
|
$this->controllers['rename'] = new Filemanager\Controller\Rename($this->entity); |
131
|
|
|
|
132
|
|
|
# Create edit form |
133
|
|
|
|
134
|
|
|
if ($this->entity->isFile() && static::$permissions['edit']) { |
135
|
|
|
|
136
|
|
|
$this->forms['edit'] = new Filemanager\Form\Edit($this->entity); |
137
|
|
|
|
138
|
|
|
$this->controllers['edit'] = new Filemanager\Controller\Edit($this->entity); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
# Handle form |
142
|
|
|
|
143
|
|
|
foreach ($this->forms as $name => $form) if ($form->handle($this->controllers[$name], true)) { |
144
|
|
|
|
145
|
|
|
Request::redirect(INSTALL_PATH . '/admin/content/filemanager/' . static::$origin . '/' . static::$type . |
146
|
|
|
|
147
|
|
|
'?parent=' . $this->parent->getPath() . '&name=' . $this->entity->getName() . '&submitted=' . $name); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
# Display success message |
151
|
|
|
|
152
|
|
|
if (Request::get('submitted') === 'rename') Popup::set('positive', Language::get(static::$message_success_rename)); |
153
|
|
|
|
154
|
|
|
else if (Request::get('submitted') === 'edit') Popup::set('positive', Language::get(static::$message_success_edit)); |
155
|
|
|
|
156
|
|
|
# ------------------------ |
157
|
|
|
|
158
|
|
|
return $this->getContents(); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.