Skip to content

Commit 649a111

Browse files
committed
server-php: Added back missing .shortcuts.json parsing
1 parent 62ef408 commit 649a111

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/server/php/Modules/VFS/Filesystem.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,23 @@ final protected static function _getRealPath($path) {
105105
return str_replace(array_keys($replacements), array_values($replacements), $path);
106106
}
107107

108+
final protected static function _scanShortcuts($scandir, $opt) {
109+
$filename = is_string($opt) ? str_replace('/', '', $opt) : '.shortcuts.json';
110+
$path = preg_replace('/\/?$/', '/' . $filename, $scandir);
111+
$result = [];
112+
113+
if ( file_exists($path) ) {
114+
try {
115+
$json = json_decode(file_get_contents($path), true);
116+
if ( is_array($json) ) {
117+
$result = $json;
118+
}
119+
} catch ( Exception $e ) {}
120+
}
121+
122+
return $result;
123+
}
124+
108125
final public static function exists(Request $request, Array $arguments = []) {
109126
return file_exists(self::_getRealPath($arguments['path']));
110127
}
@@ -276,16 +293,25 @@ final public static function fileinfo(Request $request, Array $arguments = []) {
276293
}
277294

278295
final public static function scandir(Request $request, Array $arguments = []) {
296+
$opts = isset($arguments['options']) ? $arguments['options'] : [];
279297
$path = self::_getRealPath($arguments['path']);
298+
280299
if ( !file_exists($path) || !is_dir($path) ) {
281300
throw new Exception("Directory does not exist");
282301
}
283302

284-
return array_values(array_map(function($iter) use($arguments, $path) {
303+
$result = array_values(array_map(function($iter) use($arguments, $path) {
285304
return self::_getFileMetadata($iter, $arguments['path'], $path . '/' . $iter);
286305
}, array_filter(scandir($path), function($iter) {
287306
return !in_array($iter, ['.', '..']);
288307
})));
308+
309+
$shortcuts = isset($opts['shortcuts']) ? (is_string($opts['shortcuts']) || $opts['shortcuts'] === true) : true;
310+
if ( $shortcuts ) {
311+
$result = array_merge($result, self::_scanShortcuts($path, $shortcuts));
312+
}
313+
314+
return $result;
289315
}
290316

291317
final public static function freeSpace(Request $request, Array $arguments = []) {

0 commit comments

Comments
 (0)