PluginProbe
WPIDE – File Manager & Code Editor / 3.5.5
WPIDE – File Manager & Code Editor v3.5.5
3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 3.4 All 54 releases
← All changes | App/Controllers/FileManager/FileController.php +24 -17 3.13.5.5 View file →
@@ -12,12 +12,12 @@
12 12 use WPIDE\App\Kernel\Request;
13 13 use WPIDE\App\Kernel\Response;
14 14 use WPIDE\App\Services\Archiver\ArchiverInterface;
15 15 use WPIDE\App\Services\Auth\AuthInterface;
16 -use WPIDE\App\Services\Session\SessionStorageInterface as Session;
16 +use WPIDE\App\Services\Transient\Transient;
17 17 use WPIDE\App\Services\Storage\Filesystem;
18 18 use WPIDE\App\Services\Storage\LocalFileSystem;
19 -use const WPIDE\Constants\CONTENT_DIR;
19 +use const WPIDE\Constants\WP_PATH;
20 20
21 21
22 22 /**
23 23 *
@@ -29,11 +29,11 @@
29 29 */
30 30 const SESSION_CWD = 'current_path';
31 31
32 32 /**
33 - * @var Session
33 + * @var Transient
34 34 */
35 - protected $session;
35 + protected $transient;
36 36
37 37 /**
38 38 * @var AuthInterface
39 39 */
@@ -55,15 +55,15 @@
55 55 protected $separator;
56 56
57 57 /**
58 58 * @param Config $config
59 - * @param Session $session
59 + * @param Transient $transient
60 60 * @param AuthInterface $auth
61 61 * @param Filesystem $storage
62 62 */
63 - public function __construct(Config $config, Session $session, AuthInterface $auth, Filesystem $storage)
63 + public function __construct(Config $config, Transient $transient, AuthInterface $auth, Filesystem $storage)
64 64 {
65 - $this->session = $session;
65 + $this->transient = $transient;
66 66 $this->config = $config;
67 67 $this->auth = $auth;
68 68
69 69 $user = $this->auth->user() ?: $this->auth->getGuest();
@@ -83,9 +83,9 @@
83 83 public function changeDirectory(Request $request, Response $response)
84 84 {
85 85 $path = $request->input('to', $this->separator);
86 86
87 - $this->session->set(self::SESSION_CWD, $path);
87 + $this->transient->set(self::SESSION_CWD, $path);
88 88
89 89 return $response->json($this->storage->getDirectoryCollection($path));
90 90 }
91 91
@@ -96,14 +96,19 @@
96 96 * @throws Exception
97 97 */
98 98 public function getDirectory(Request $request, Response $response)
99 99 {
100 - $path = $request->input('dir', $this->session->get(self::SESSION_CWD, $this->separator));
100 + $path = $request->input('dir', $this->transient->get(self::SESSION_CWD, $this->separator));
101 101 $root = $request->input('root', false);
102 + $filter = $request->enumInput('filter', ['image']);
102 103
103 - $storage = $root ? LocalFileSystem::load(CONTENT_DIR) : $this->storage;
104 + if($root) {
105 + $storage = LocalFileSystem::load(WP_PATH);
106 + }else{
107 + $storage = $this->storage;
108 + }
104 109
105 - $content = $storage->getDirectoryCollection($path);
110 + $content = $storage->getDirectoryCollection($path, false, $filter);
106 111
107 112 return $response->json($content);
108 113 }
109 114
@@ -114,9 +119,9 @@
114 119 * @throws Exception
115 120 */
116 121 public function getDirectorySize(Request $request, Response $response)
117 122 {
118 - $path = $request->input('dir', $this->session->get(self::SESSION_CWD, $this->separator));
123 + $path = $request->input('dir', $this->transient->get(self::SESSION_CWD, $this->separator));
119 124
120 125 $size = $this->storage->getDirSize($path);
121 126
122 127 return $response->json($size);
@@ -130,9 +135,9 @@
130 135 public function createNew(Request $request, Response $response)
131 136 {
132 137 $type = $request->input('type', 'file');
133 138 $name = $request->input('name');
134 - $path = $this->session->get(self::SESSION_CWD, $this->separator);
139 + $path = $request->input('destination', $this->transient->get(self::SESSION_CWD, $this->separator));
135 140
136 141 if(empty($name)) {
137 142 return $response->json(sprintf(__('%s name cannot be empty!', 'wpide'), ucfirst($type)), 422);
138 143 }
@@ -210,9 +215,8 @@
210 215 public function unzipItem(Request $request, Response $response, ArchiverInterface $archiver)
211 216 {
212 217 $source = $request->input('item');
213 218 $destination = $request->input('destination', $this->separator);
214 -
215 219 $archiver->uncompress($source, $destination, $this->storage);
216 220
217 221 return $response->json(true);
218 222 }
@@ -265,9 +269,9 @@
265 269
266 270 $item = $request->input('item');
267 271 $content = $request->input('content');
268 272
269 - $dir = !empty($item->dir) ? $item->dir : $this->session->get(self::SESSION_CWD, $this->separator);
273 + $dir = !empty($item->dir) ? $item->dir : $this->transient->get(self::SESSION_CWD, $this->separator);
270 274
271 275 $isImage = false;
272 276
273 277 // Check if data uri encoded image
@@ -280,9 +284,10 @@
280 284
281 285 if ($item->ext === 'php') {
282 286 try {
283 287 PhpValidator::validate($content);
284 - } catch (Error $error) {
288 + } catch (Error | Exception $error) {
289 +
285 290 $message = "Parse error: {$error->getMessage()}\n";
286 291 return $response->json($message, 422);
287 292 }
288 293 }
@@ -306,7 +311,9 @@
306 311
307 312 return $response->json(__('Failed saving file!', 'wpide'), 422);
308 313 }
309 314
310 - return $response->json(true);
315 + return $response->json([
316 + 'success' => true
317 + ]);
311 318 }
312 319 }