@@ -55,27 +55,26 @@ public function __construct()
55
55
public function setFolder ($ folder )
56
56
{
57
57
if (app ('files ' )->exists ($ folder )) {
58
-
58
+
59
59
$ this ->folder = $ folder ;
60
- }
61
- else if (is_array ($ this ->storage_path )) {
62
-
60
+ } else if (is_array ($ this ->storage_path )) {
61
+
63
62
foreach ($ this ->storage_path as $ value ) {
64
-
63
+
65
64
$ logsPath = $ value . '/ ' . $ folder ;
66
-
65
+
67
66
if (app ('files ' )->exists ($ logsPath )) {
68
67
$ this ->folder = $ folder ;
69
68
break ;
70
69
}
71
70
}
72
71
} 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
+
79
78
}
80
79
}
81
80
@@ -101,11 +100,11 @@ public function pathToLogFile($file)
101
100
{
102
101
103
102
if (app ('files ' )->exists ($ file )) { // try the absolute path
104
-
103
+
105
104
return $ file ;
106
105
}
107
106
if (is_array ($ this ->storage_path )) {
108
-
107
+
109
108
foreach ($ this ->storage_path as $ folder ) {
110
109
if (app ('files ' )->exists ($ folder . '/ ' . $ file )) { // try the absolute path
111
110
$ file = $ folder . '/ ' . $ file ;
@@ -120,9 +119,9 @@ public function pathToLogFile($file)
120
119
$ file = $ logsPath . '/ ' . $ file ;
121
120
// check if requested file is really in the logs directory
122
121
if (dirname ($ file ) !== $ logsPath ) {
123
- throw new \Exception ('No such log file: ' . $ file );
122
+ throw new \Exception ('No such log file: ' . $ file );
124
123
}
125
-
124
+
126
125
return $ file ;
127
126
}
128
127
@@ -236,47 +235,47 @@ public function all()
236
235
}
237
236
238
237
/**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
+ */
245
244
public function foldersAndFiles ($ path = null )
246
245
{
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 ;
260
259
}
261
260
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
+ */
269
268
public function getFolders ($ folder = '' )
270
269
{
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 ;
280
279
}
281
280
282
281
@@ -297,77 +296,78 @@ public function getFolderFiles($basename = false)
297
296
public function getFiles ($ basename = false , $ folder = '' )
298
297
{
299
298
$ 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
+ );
302
306
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
+ }
307
311
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 );
313
313
314
+ return array_values ($ files );
314
315
}
315
316
316
317
/**
317
- * @return string
318
- */
318
+ * @return string
319
+ */
319
320
public function getStoragePath ()
320
321
{
321
- return $ this ->storage_path ;
322
+ return $ this ->storage_path ;
322
323
}
323
324
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
+ }
333
334
334
335
public static function directoryTreeStructure ($ storage_path , array $ array )
335
336
{
336
- foreach ($ array as $ k => $ v ) {
337
- if (is_dir ( $ k )) {
337
+ foreach ($ array as $ k => $ v ) {
338
+ if (is_dir ($ k )) {
338
339
339
- $ exploded = explode ( "\\" , $ k );
340
- $ show = last ( $ exploded );
340
+ $ exploded = explode ("\\" , $ k );
341
+ $ show = last ($ exploded );
341
342
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 ) . '">
344
345
<span> </span><span
345
- class="fa fa-folder"></span> '. $ show. '
346
+ class="fa fa-folder"></span> ' . $ show . '
346
347
</a>
347
348
</div> ' ;
348
349
349
- if ( is_array ( $ v ) ) {
350
- self ::directoryTreeStructure ( $ storage_path , $ v );
351
- }
350
+ if (is_array ($ v ) ) {
351
+ self ::directoryTreeStructure ($ storage_path , $ v );
352
+ }
352
353
353
- }
354
- else {
354
+ } else {
355
355
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 ;
360
360
361
361
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 ) . '">
364
364
<span> </span> <span
365
- class="fa fa-file"></span> '. $ show2. '
365
+ class="fa fa-file"></span> ' . $ show2 . '
366
366
</a>
367
367
</div> ' ;
368
368
369
- }
370
- }
369
+ }
370
+ }
371
371
372
372
return ;
373
373
}
0 commit comments