| @@ -15,9 +15,9 @@ | ||
| 15 | 15 | use WPIDE\App\Services\Auth\AuthInterface; |
| 16 | 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 | * |
| @@ -98,12 +98,17 @@ | ||
| 98 | 98 | public function getDirectory(Request $request, Response $response) |
| 99 | 99 | { |
| 100 | 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 | |
| @@ -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->transient->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 | } |
| @@ -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 | } |