Skip to content

Commit 4bad317

Browse files
committed
Fix magic number and psr-2 format on file and directory sort
1 parent 3c669ee commit 4bad317

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

public/js/script.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var show_list;
2-
var sort_type = 0;
2+
var sort_type = 'alpha';
33

44
$(document).ready(function () {
55
bootbox.setDefaults({locale:lang['locale-bootbox']});
@@ -76,12 +76,12 @@ $('#list-display').click(function () {
7676
});
7777

7878
$('#list-sort-alpha').click(function() {
79-
sort_type = 0;
79+
sort_type = 'alpha';
8080
loadItems();
8181
});
8282

8383
$('#list-sort-time').click(function() {
84-
sort_type = 1;
84+
sort_type = 'time';
8585
loadItems();
8686
});
8787

src/controllers/UploadController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public function upload()
3131
} elseif ($new_filename == 'invalid') {
3232
array_push($error_bag, $response);
3333
}
34-
3534
}
3635

3736
if (is_array($files)) {

src/traits/LfmHelpers.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function enabledShareFolder()
236236
*** File System ***
237237
****************************/
238238

239-
public function getDirectories($path, $sort_type = 0)
239+
public function getDirectories($path, $sort_type = 'alpha')
240240
{
241241
$thumb_folder_name = config('lfm.thumb_folder_name');
242242
$all_directories = File::directories($path);
@@ -255,16 +255,16 @@ public function getDirectories($path, $sort_type = 0)
255255
}
256256
}
257257

258-
if ($sort_type == 0) {
259-
uasort($arr_dir, array($this, 'cmpDirAlpha'));
260-
} elseif ($sort_type == 1) {
261-
uasort($arr_dir, array($this, 'cmpDirTime'));
258+
if ($sort_type == 'alpha') {
259+
uasort($arr_dir, array($this, 'compareDirAlpha'));
260+
} elseif ($sort_type == 'time') {
261+
uasort($arr_dir, array($this, 'compareDirTime'));
262262
}
263263

264264
return $arr_dir;
265265
}
266266

267-
public function getFilesWithInfo($path, $sort_type = 0)
267+
public function getFilesWithInfo($path, $sort_type = 'alpha')
268268
{
269269
$arr_files = [];
270270

@@ -299,10 +299,10 @@ public function getFilesWithInfo($path, $sort_type = 0)
299299
];
300300
}
301301

302-
if ($sort_type == 0) {
303-
uasort($arr_files, array($this, 'cmpAlpha'));
304-
} elseif ($sort_type == 1) {
305-
uasort($arr_files, array($this, 'cmpTime'));
302+
if ($sort_type == 'alpha') {
303+
uasort($arr_files, array($this, 'compareFileAlpha'));
304+
} elseif ($sort_type == 'time') {
305+
uasort($arr_files, array($this, 'compareFileTime'));
306306
}
307307

308308
return $arr_files;
@@ -331,38 +331,42 @@ public function fileIsImage($file)
331331
return starts_with($mime_type, 'image');
332332
}
333333

334-
private static function cmpDirAlpha($a, $b)
334+
private static function compareDirAlpha($a, $b)
335335
{
336336
$cmp = strcmp($a->name, $b->name);
337337

338-
if ($cmp == 0)
338+
if ($cmp == 0) {
339339
return 0;
340+
}
340341

341342
return ($cmp > 0) ? 1 : -1;
342343
}
343344

344-
private static function cmpDirTime($a, $b)
345+
private static function compareDirTime($a, $b)
345346
{
346-
if ($a->updated == $b->updated)
347+
if ($a->updated == $b->updated) {
347348
return 0;
349+
}
348350

349351
return ($a->updated > $b->updated) ? 1 : -1;
350352
}
351353

352-
private static function cmpAlpha($a, $b)
354+
private static function compareFileAlpha($a, $b)
353355
{
354356
$cmp = strcmp($a['name'], $b['name']);
355357

356-
if ($cmp == 0)
358+
if ($cmp == 0) {
357359
return 0;
360+
}
358361

359362
return ($cmp > 0) ? 1 : -1;
360363
}
361364

362-
private static function cmpTime($a, $b)
365+
private static function compareFileTime($a, $b)
363366
{
364-
if ($a['updated'] == $b['updated'])
367+
if ($a['updated'] == $b['updated']) {
365368
return 0;
369+
}
366370

367371
return ($a['updated'] > $b['updated']) ? 1 : -1;
368372
}

0 commit comments

Comments
 (0)