@@ -236,7 +236,7 @@ public function enabledShareFolder()
236236 *** File System ***
237237 ****************************/
238238
239- public function getDirectories ($ path )
239+ public function getDirectories ($ path, $ sort_type = 0 )
240240 {
241241 $ thumb_folder_name = config ('lfm.thumb_folder_name ' );
242242 $ all_directories = File::directories ($ path );
@@ -249,15 +249,22 @@ public function getDirectories($path)
249249 if ($ directory_name !== $ thumb_folder_name ) {
250250 $ arr_dir [] = (object )[
251251 'name ' => $ directory_name ,
252+ 'updated ' => filemtime ($ directory ),
252253 'path ' => $ this ->getInternalPath ($ directory )
253254 ];
254255 }
255256 }
256257
258+ if ($ sort_type == 0 ) {
259+ uasort ($ arr_dir , array ($ this , 'cmpDirAlpha ' ));
260+ } elseif ($ sort_type == 1 ) {
261+ uasort ($ arr_dir , array ($ this , 'cmpDirTime ' ));
262+ }
263+
257264 return $ arr_dir ;
258265 }
259266
260- public function getFilesWithInfo ($ path )
267+ public function getFilesWithInfo ($ path, $ sort_type = 0 )
261268 {
262269 $ arr_files = [];
263270
@@ -292,6 +299,12 @@ public function getFilesWithInfo($path)
292299 ];
293300 }
294301
302+ if ($ sort_type == 0 ) {
303+ uasort ($ arr_files , array ($ this , 'cmpAlpha ' ));
304+ } elseif ($ sort_type == 1 ) {
305+ uasort ($ arr_files , array ($ this , 'cmpTime ' ));
306+ }
307+
295308 return $ arr_files ;
296309 }
297310
@@ -318,6 +331,42 @@ public function fileIsImage($file)
318331 return starts_with ($ mime_type , 'image ' );
319332 }
320333
334+ private static function cmpDirAlpha ($ a , $ b )
335+ {
336+ $ cmp = strcmp ($ a ->name , $ b ->name );
337+
338+ if ($ cmp == 0 )
339+ return 0 ;
340+
341+ return ($ cmp > 0 ) ? 1 : -1 ;
342+ }
343+
344+ private static function cmpDirTime ($ a , $ b )
345+ {
346+ if ($ a ->updated == $ b ->updated )
347+ return 0 ;
348+
349+ return ($ a ->updated > $ b ->updated ) ? 1 : -1 ;
350+ }
351+
352+ private static function cmpAlpha ($ a , $ b )
353+ {
354+ $ cmp = strcmp ($ a ['name ' ], $ b ['name ' ]);
355+
356+ if ($ cmp == 0 )
357+ return 0 ;
358+
359+ return ($ cmp > 0 ) ? 1 : -1 ;
360+ }
361+
362+ private static function cmpTime ($ a , $ b )
363+ {
364+ if ($ a ['updated ' ] == $ b ['updated ' ])
365+ return 0 ;
366+
367+ return ($ a ['updated ' ] > $ b ['updated ' ]) ? 1 : -1 ;
368+ }
369+
321370
322371 /****************************
323372 *** Miscellaneouses ***
0 commit comments