Skip to content

Commit db43685

Browse files
committed
Fixed scan dir json that included some files twice
1 parent 1f9d8eb commit db43685

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

admin/controller/editor/code.php

+13-23
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use function Vvveb\__;
2626
use Vvveb\Controller\Base;
2727
use function Vvveb\sanitizeFileName;
28-
use Vvveb\System\Core\View;
2928

3029
class Code extends Base {
3130
function dirForType($type) {
@@ -53,16 +52,15 @@ function dirForType($type) {
5352
}
5453

5554
function index() {
56-
$type = $this->request->get['type'];
57-
$admin_path = \Vvveb\adminPath();
58-
$controllerPath = $admin_path . 'index.php?module=editor/code';
55+
$type = $this->request->get['type'];
56+
$admin_path = \Vvveb\adminPath();
57+
$controllerPath = $admin_path . 'index.php?module=editor/code';
5958

60-
$this->view->scanUrl = "$controllerPath&action=scan&type=$type";
61-
$this->view->uploadUrl = "$controllerPath&action=upload&type=$type";
62-
$this->view->saveUrl = "$controllerPath&action=save&type=$type";
63-
$this->view->loadFileUrl = "$controllerPath&action=loadFile&type=$type";
64-
$this->view->saveUrl = "$controllerPath&action=save&type=$type";
65-
$this->view->type = $type;
59+
$this->view->scanUrl = "$controllerPath&action=scan&type=$type";
60+
$this->view->uploadUrl = "$controllerPath&action=upload&type=$type";
61+
$this->view->loadFileUrl = "$controllerPath&action=loadFile&type=$type";
62+
$this->view->saveUrl = "$controllerPath&action=save&type=$type";
63+
$this->view->type = $type;
6664

6765
if ($type) {
6866
$this->view->mediaPath = str_replace('/media', "/$type", $this->view->mediaPath);
@@ -161,10 +159,10 @@ function scan() {
161159
// Is there actually such a folder/file?
162160
163161
if (file_exists($dir)) {
164-
$files = @scandir($dir);
162+
$listdir = @scandir($dir);
165163

166-
if ($files) {
167-
foreach ($files as $f) {
164+
if ($listdir) {
165+
foreach ($listdir as $f) {
168166
if (! $f || $f[0] == '.' || $f == 'node_modules' || $f == 'vendor') {
169167
continue; // Ignore hidden files
170168
}
@@ -198,20 +196,12 @@ function scan() {
198196
$response = $scan($scandir);
199197

200198
// Output the directory listing as JSON
201-
$view = View::getInstance();
202-
$view->noJson = true;
203-
204-
header('Content-type: application/json');
205-
206-
echo json_encode([
199+
$this->response->setType('json');
200+
$this->response->output([
207201
'name' => '',
208202
'type' => 'folder',
209203
'path' => '',
210204
'items' => $response,
211205
]);
212-
213-
die();
214-
215-
return false;
216206
}
217207
}

0 commit comments

Comments
 (0)