@@ -55,27 +55,26 @@ public function __construct()
5555 public function setFolder ($ folder )
5656 {
5757 if (app ('files ' )->exists ($ folder )) {
58-
58+
5959 $ this ->folder = $ folder ;
60- }
61- else if (is_array ($ this ->storage_path )) {
62-
60+ } else if (is_array ($ this ->storage_path )) {
61+
6362 foreach ($ this ->storage_path as $ value ) {
64-
63+
6564 $ logsPath = $ value . '/ ' . $ folder ;
66-
65+
6766 if (app ('files ' )->exists ($ logsPath )) {
6867 $ this ->folder = $ folder ;
6968 break ;
7069 }
7170 }
7271 } else {
73-
74- $ logsPath = $ this ->storage_path . '/ ' . $ folder ;
75- if (app ('files ' )->exists ($ logsPath )) {
76- $ this ->folder = $ folder ;
77- }
78-
72+
73+ $ logsPath = $ this ->storage_path . '/ ' . $ folder ;
74+ if (app ('files ' )->exists ($ logsPath )) {
75+ $ this ->folder = $ folder ;
76+ }
77+
7978 }
8079 }
8180
@@ -101,11 +100,11 @@ public function pathToLogFile($file)
101100 {
102101
103102 if (app ('files ' )->exists ($ file )) { // try the absolute path
104-
103+
105104 return $ file ;
106105 }
107106 if (is_array ($ this ->storage_path )) {
108-
107+
109108 foreach ($ this ->storage_path as $ folder ) {
110109 if (app ('files ' )->exists ($ folder . '/ ' . $ file )) { // try the absolute path
111110 $ file = $ folder . '/ ' . $ file ;
@@ -120,9 +119,9 @@ public function pathToLogFile($file)
120119 $ file = $ logsPath . '/ ' . $ file ;
121120 // check if requested file is really in the logs directory
122121 if (dirname ($ file ) !== $ logsPath ) {
123- throw new \Exception ('No such log file: ' . $ file );
122+ throw new \Exception ('No such log file: ' . $ file );
124123 }
125-
124+
126125 return $ file ;
127126 }
128127
@@ -236,47 +235,47 @@ public function all()
236235 }
237236
238237 /**Creates a multidimensional array
239- * of subdirectories and files
240- *
241- * @param null $path
242- *
243- * @return array
244- */
238+ * of subdirectories and files
239+ *
240+ * @param null $path
241+ *
242+ * @return array
243+ */
245244 public function foldersAndFiles ($ path = null )
246245 {
247- $ contents = array ();
248- $ dir = $ path ? $ path : $ this ->storage_path ;
249- foreach (scandir ($ dir ) as $ node ) {
250- if ($ node == '. ' || $ node == '.. ' ) continue ;
251- $ path = $ dir . '\\' . $ node ;
252- if (is_dir ($ path )) {
253- $ contents [$ path ] = $ this ->foldersAndFiles ($ path );
254- } else {
255- $ contents [] = $ path ;
256- }
257- }
258-
259- return $ contents ;
246+ $ contents = array ();
247+ $ dir = $ path ? $ path : $ this ->storage_path ;
248+ foreach (scandir ($ dir ) as $ node ) {
249+ if ($ node == '. ' || $ node == '.. ' ) continue ;
250+ $ path = $ dir . '\\' . $ node ;
251+ if (is_dir ($ path )) {
252+ $ contents [$ path ] = $ this ->foldersAndFiles ($ path );
253+ } else {
254+ $ contents [] = $ path ;
255+ }
256+ }
257+
258+ return $ contents ;
260259 }
261260
262- /**Returns an array of
263- * all subdirectories of specified directory
264- *
265- * @param string $folder
266- *
267- * @return array
268- */
261+ /**Returns an array of
262+ * all subdirectories of specified directory
263+ *
264+ * @param string $folder
265+ *
266+ * @return array
267+ */
269268 public function getFolders ($ folder = '' )
270269 {
271- $ folders = [];
272- $ listObject = new \RecursiveIteratorIterator (
273- new \RecursiveDirectoryIterator ($ this ->storage_path . '/ ' . $ folder , \RecursiveDirectoryIterator::SKIP_DOTS ),
274- \RecursiveIteratorIterator::CHILD_FIRST
275- );
276- foreach ($ listObject as $ fileinfo ) {
277- if ($ fileinfo ->isDir ()) $ folders [] = $ fileinfo ->getRealPath ();
278- }
279- return $ folders ;
270+ $ folders = [];
271+ $ listObject = new \RecursiveIteratorIterator (
272+ new \RecursiveDirectoryIterator ($ this ->storage_path . '/ ' . $ folder , \RecursiveDirectoryIterator::SKIP_DOTS ),
273+ \RecursiveIteratorIterator::CHILD_FIRST
274+ );
275+ foreach ($ listObject as $ fileinfo ) {
276+ if ($ fileinfo ->isDir ()) $ folders [] = $ fileinfo ->getRealPath ();
277+ }
278+ return $ folders ;
280279 }
281280
282281
@@ -297,77 +296,78 @@ public function getFolderFiles($basename = false)
297296 public function getFiles ($ basename = false , $ folder = '' )
298297 {
299298 $ files = [];
300- $ pattern = function_exists ('config ' ) ? config ('logviewer.pattern ' , '*.log ' ) : '*.log ' ;
301- $ fullPath = $ this ->storage_path .'/ ' .$ folder ;
299+ $ pattern = function_exists ('config ' ) ? config ('logviewer.pattern ' , '*.log ' ) : '*.log ' ;
300+ $ fullPath = $ this ->storage_path . '/ ' . $ folder ;
301+
302+ $ listObject = new \RecursiveIteratorIterator (
303+ new \RecursiveDirectoryIterator ($ fullPath , \RecursiveDirectoryIterator::SKIP_DOTS ),
304+ \RecursiveIteratorIterator::CHILD_FIRST
305+ );
302306
303- $ listObject = new \ RecursiveIteratorIterator (
304- new \ RecursiveDirectoryIterator ( $ fullPath , \RecursiveDirectoryIterator:: SKIP_DOTS ),
305- \RecursiveIteratorIterator:: CHILD_FIRST
306- );
307+ foreach ( $ listObject as $ fileinfo ) {
308+ if (! $ fileinfo -> isDir () && strtolower ( pathinfo ( $ fileinfo -> getRealPath (), PATHINFO_EXTENSION )) == explode ( ' . ' , $ pattern )[ 1 ])
309+ $ files [] = $ basename ? basename ( $ fileinfo -> getRealPath ()) : $ fileinfo -> getRealPath ();
310+ }
307311
308- foreach ($ listObject as $ fileinfo ) {
309- if (!$ fileinfo ->isDir () && strtolower (pathinfo ($ fileinfo ->getRealPath (), PATHINFO_EXTENSION )) == explode ('. ' , $ pattern )[1 ])
310- $ files [] = $ basename ? basename ($ fileinfo ->getRealPath ()) : $ fileinfo ->getRealPath ();
311- }
312- return $ files ;
312+ arsort ($ files );
313313
314+ return array_values ($ files );
314315 }
315316
316317 /**
317- * @return string
318- */
318+ * @return string
319+ */
319320 public function getStoragePath ()
320321 {
321- return $ this ->storage_path ;
322+ return $ this ->storage_path ;
322323 }
323324
324- /**
325- * @param $path
326- *
327- * @return void
328- */
329- public function setStoragePath ($ path )
330- {
331- $ this ->storage_path = $ path ;
332- }
325+ /**
326+ * @param $path
327+ *
328+ * @return void
329+ */
330+ public function setStoragePath ($ path )
331+ {
332+ $ this ->storage_path = $ path ;
333+ }
333334
334335 public static function directoryTreeStructure ($ storage_path , array $ array )
335336 {
336- foreach ($ array as $ k => $ v ) {
337- if (is_dir ( $ k )) {
337+ foreach ($ array as $ k => $ v ) {
338+ if (is_dir ($ k )) {
338339
339- $ exploded = explode ( "\\" , $ k );
340- $ show = last ( $ exploded );
340+ $ exploded = explode ("\\" , $ k );
341+ $ show = last ($ exploded );
341342
342- echo '<div class="list-group folder">
343- <a href="?f= ' . \Illuminate \Support \Facades \Crypt::encrypt ($ k ). '">
343+ echo '<div class="list-group folder">
344+ <a href="?f= ' . \Illuminate \Support \Facades \Crypt::encrypt ($ k ) . '">
344345 <span> </span><span
345- class="fa fa-folder"></span> '. $ show. '
346+ class="fa fa-folder"></span> ' . $ show . '
346347 </a>
347348 </div> ' ;
348349
349- if ( is_array ( $ v ) ) {
350- self ::directoryTreeStructure ( $ storage_path , $ v );
351- }
350+ if (is_array ($ v ) ) {
351+ self ::directoryTreeStructure ($ storage_path , $ v );
352+ }
352353
353- }
354- else {
354+ } else {
355355
356- $ exploded = explode ( "\\" , $ v );
357- $ show2 = last ( $ exploded );
358- $ folder = str_replace ( $ storage_path , "" , rtrim ( str_replace ( $ show2 , "" , $ v ), "\\" ) );
359- $ file = $ v ;
356+ $ exploded = explode ("\\" , $ v );
357+ $ show2 = last ($ exploded );
358+ $ folder = str_replace ($ storage_path , "" , rtrim (str_replace ($ show2 , "" , $ v ), "\\" ) );
359+ $ file = $ v ;
360360
361361
362- echo '<div class="list-group">
363- <a href="?l= '. \Illuminate \Support \Facades \Crypt::encrypt ($ file ). '&f= ' . \Illuminate \Support \Facades \Crypt::encrypt ($ folder ). '">
362+ echo '<div class="list-group">
363+ <a href="?l= ' . \Illuminate \Support \Facades \Crypt::encrypt ($ file ) . '&f= ' . \Illuminate \Support \Facades \Crypt::encrypt ($ folder ) . '">
364364 <span> </span> <span
365- class="fa fa-file"></span> '. $ show2. '
365+ class="fa fa-file"></span> ' . $ show2 . '
366366 </a>
367367 </div> ' ;
368368
369- }
370- }
369+ }
370+ }
371371
372372 return ;
373373 }
0 commit comments